diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 1c656177be677..8db1ee7657ea8 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -1216,6 +1216,17 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) { public static final String LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED = "lock_pattern_tactile_feedback_enabled"; + /** + * Whether to use statusbar music control + * @hide + */ + public static final String STATUSBAR_MUSIC_CONTROLS = "statusbar_music_controls"; + + /** + * Whether to use statusbar music control + * @hide + */ + public static final String STATUSBAR_ALWAYS_MUSIC_CONTROLS = "statusbar_always_music_controls"; /** * A formatted string of the next alarm that is set, or the empty string @@ -2156,6 +2167,12 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) { */ public static final String TRACKBALL_UNLOCK_SCREEN = "trackball_unlock_screen"; + /** + * Whether to unlock the screen with the HOLD key. The value is boolean (1 or 0). + * @hide + */ + public static final String HOLD_UNLOCK_SCREEN = "hold_unlock_screen"; + /** * Pulse the Trackball with Screen On. The value is boolean (1 or 0). * @hide @@ -2223,13 +2240,13 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) { public static final String NOTIF_BAR_CUSTOM = "notif_bar_custom"; /** - * Whether to use custom notification bar + * Whether to use lockscreen music controls * @hide */ public static final String LOCKSCREEN_MUSIC_CONTROLS = "lockscreen_music_controls"; /** - * Whether to use custom notification bar + * Whether to always show lockscreen music controls * @hide */ public static final String LOCKSCREEN_ALWAYS_MUSIC_CONTROLS = "lockscreen_always_music_controls"; @@ -4514,4 +4531,4 @@ public static CharSequence getTitle(Context context, Cursor cursor) { public static String getGTalkDeviceId(long androidId) { return "android-" + Long.toHexString(androidId); } -} +} \ No newline at end of file diff --git a/core/res/res/layout/status_bar_expanded.xml b/core/res/res/layout/status_bar_expanded.xml index 8cb81c4e6da57..c8737fb807594 100644 --- a/core/res/res/layout/status_bar_expanded.xml +++ b/core/res/res/layout/status_bar_expanded.xml @@ -38,7 +38,7 @@ android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center_vertical" - > + > + > + > + > + android:background="@drawable/stat_power_bg" + > + > + > + > + + + + + + + + + mUsedPowerButtons = new HashMap(); private boolean mHideOnPowerButtonChange = false; + // statusbar music controls + private AudioManager am; + private boolean mIsMusicActive; + private ImageButton mPlayIcon; + private ImageButton mPauseIcon; + private ImageButton mRewindIcon; + private ImageButton mForwardIcon; + private LinearLayout mStatusbarMusicControls; + private LinearLayout mCarrierBox; + private boolean mStatusMusicControls; + private boolean mStatusAlwaysMusic; + /** * Construct the service, add the status bar view to the window manager */ @@ -348,7 +361,6 @@ private void makeStatusBarView(Context context) { mIcons = (LinearLayout)sb.findViewById(R.id.icons); mTickerView = sb.findViewById(R.id.ticker); - mExpandedDialog = new ExpandedDialog(context); mExpandedView = expanded; mExpandedContents = expanded.findViewById(R.id.notificationLinearLayout); @@ -359,11 +371,19 @@ private void makeStatusBarView(Context context) { mNoNotificationsTitle = (TextView)expanded.findViewById(R.id.noNotificationsTitle); mClearButton = (TextView)expanded.findViewById(R.id.clear_all_button); mClearButton.setOnClickListener(mClearButtonListener); + mCarrierBox = (LinearLayout)expanded.findViewById(R.id.carrierBox); mSpnLabel = (TextView)expanded.findViewById(R.id.spnLabel); mPlmnLabel = (TextView)expanded.findViewById(R.id.plmnLabel); mScrollView = (ScrollView)expanded.findViewById(R.id.scroll); mNotificationLinearLayout = expanded.findViewById(R.id.notificationLinearLayout); + // music controls + mPlayIcon = (ImageButton) expanded.findViewById(R.id.music_control_play); + mPauseIcon = (ImageButton) expanded.findViewById(R.id.music_control_pause); + mRewindIcon = (ImageButton) expanded.findViewById(R.id.music_control_previous); + mForwardIcon = (ImageButton) expanded.findViewById(R.id.music_control_next); + mStatusbarMusicControls = (LinearLayout) expanded.findViewById(R.id.exp_music_control); + if (custExpBar) { mExpandedView.findViewById(R.id.exp_view_lin_layout). setBackgroundDrawable(expBarHeadDrawable); @@ -406,6 +426,7 @@ private void makeStatusBarView(Context context) { // set the inital view visibility setAreThereNotifications(); mDateView.setVisibility(View.INVISIBLE); + mCarrierBox.setVisibility(View.VISIBLE); // before we register for broadcasts mPlmnLabel.setText(R.string.lockscreen_carrier_default); @@ -451,6 +472,13 @@ public void systemReady() { setVisibility(View.GONE); } + // music controls + mStatusMusicControls = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.STATUSBAR_MUSIC_CONTROLS, 1) == 1; + mStatusAlwaysMusic = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.STATUSBAR_ALWAYS_MUSIC_CONTROLS, 1) == 1; + setupMusicControls(); + WindowManagerImpl.getDefault().addView(view, lp); } @@ -1129,6 +1157,7 @@ private void makeExpandedVisible() { if (mExpandedVisible) { return; } + refreshMusicStatus(); mExpandedVisible = true; panelSlightlyVisible(true); @@ -1919,6 +1948,80 @@ public void onClick(View v) { } }; + /** Music Control **/ + private View.OnClickListener mPlayListener = new View.OnClickListener() { + public void onClick(View v) { + refreshMusicStatus(); + mPlayIcon.setVisibility(View.GONE); + mPauseIcon.setVisibility(View.VISIBLE); + sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); + } + }; + + private View.OnClickListener mPauseListener = new View.OnClickListener() { + public void onClick(View v) { + refreshMusicStatus(); + mPauseIcon.setVisibility(View.GONE); + mPlayIcon.setVisibility(View.VISIBLE); + sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); + } + }; + + private View.OnClickListener mRewindListener = new View.OnClickListener() { + public void onClick(View v) { + sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PREVIOUS); + } + }; + + private View.OnClickListener mForwardListener = new View.OnClickListener() { + public void onClick(View v) { + sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_NEXT); + } + }; + + private void sendMediaButtonEvent(int code) { + long eventtime = SystemClock.uptimeMillis(); + + Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); + KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0); + downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent); + mContext.sendOrderedBroadcast(downIntent, null); + + Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); + KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, code, 0); + upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent); + mContext.sendOrderedBroadcast(upIntent, null); + } + + private void setupMusicControls() { + am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + refreshMusicStatus(); + mPlayIcon.setOnClickListener(mPlayListener); + mPauseIcon.setOnClickListener(mPauseListener); + mRewindIcon.setOnClickListener(mRewindListener); + mForwardIcon.setOnClickListener(mForwardListener); + } + + private void refreshMusicStatus() { + mIsMusicActive = am.isMusicActive(); + if (mStatusMusicControls && (mIsMusicActive || mStatusAlwaysMusic)) { + mCarrierBox.setVisibility(View.GONE); + mStatusbarMusicControls.setVisibility(View.VISIBLE); + if (mIsMusicActive) { + mPauseIcon.setVisibility(View.VISIBLE); + mPlayIcon.setVisibility(View.GONE); + } else { + mPlayIcon.setVisibility(View.VISIBLE); + mPauseIcon.setVisibility(View.GONE); + } + } else { + mStatusbarMusicControls.setVisibility(View.GONE); + mCarrierBox.setVisibility(View.VISIBLE); + mPlayIcon.setVisibility(View.VISIBLE); + mPauseIcon.setVisibility(View.GONE); + } + } + /** Power Widget **/ private View.OnLongClickListener mPowerLongListener = new View.OnLongClickListener() { @@ -2347,6 +2450,14 @@ public void observe() { resolver.registerContentObserver( Settings.System.getUriFor(Settings.System.TORCH_STATE), false, this); + + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.STATUSBAR_MUSIC_CONTROLS), + false, this); + + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.STATUSBAR_ALWAYS_MUSIC_CONTROLS), + false, this); } @Override @@ -2396,6 +2507,20 @@ public void update(Uri uri) { mExpandedView.findViewById(R.id.exp_power_stat). setVisibility(View.VISIBLE); } + } else if (uri.equals(Settings.System.getUriFor(Settings.System.STATUSBAR_MUSIC_CONTROLS)) || + uri.equals(Settings.System.getUriFor(Settings.System.STATUSBAR_ALWAYS_MUSIC_CONTROLS))) { + mStatusMusicControls = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.STATUSBAR_MUSIC_CONTROLS, 1) == 1; + mStatusAlwaysMusic = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.STATUSBAR_ALWAYS_MUSIC_CONTROLS, 1) == 1; + mIsMusicActive = am.isMusicActive(); + if(!mStatusMusicControls || (!mStatusAlwaysMusic && !mIsMusicActive)) { + mStatusbarMusicControls.setVisibility(View.GONE); + mCarrierBox.setVisibility(View.VISIBLE); + } else if (mStatusMusicControls && mStatusAlwaysMusic) { + mStatusbarMusicControls.setVisibility(View.VISIBLE); + mCarrierBox.setVisibility(View.GONE); + } } updateWidget(); }