From dd8fe5c26c61b0b70527bc00ea14424e895df2b4 Mon Sep 17 00:00:00 2001 From: Clark Scheff Date: Fri, 25 Apr 2014 18:29:54 -0700 Subject: [PATCH 1/4] Reduce memory leaks by removing all views. Change-Id: I64b95981425840d101c8122421281976d0251bae --- .../systemui/statusbar/phone/PhoneStatusBar.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 830d791c526b..20b6ecbfbd56 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -3983,6 +3983,8 @@ private void recreateStatusBar(boolean recreateNavigationBar) { iconSlots.add(iconView.getStatusBarSlot()); } + removeAllViews(mStatusBarWindow); + // extract notifications. int nNotifs = mNotificationData.size(); ArrayList> notifications = @@ -4023,6 +4025,17 @@ private void recreateStatusBar(boolean recreateNavigationBar) { mRecreating = false; } + private void removeAllViews(ViewGroup parent) { + int N = parent.getChildCount(); + for (int i = 0; i < N; i++) { + View child = parent.getChildAt(i); + if (child instanceof ViewGroup) { + removeAllViews((ViewGroup) child); + } + } + parent.removeAllViews(); + } + /** * Reload some of our resources when the configuration changes. * From 5a985857602f2808b69394ed6b29667209f5fa8f Mon Sep 17 00:00:00 2001 From: Jubakuba Date: Mon, 19 May 2014 04:57:20 -0600 Subject: [PATCH 2/4] SystemUI: Pimp-up QuickRecord Tile Change-Id: Iafef30a7f75b7131cc8779784bff1ef9f7042fac --- .../quicksettings/QuickRecordingsDialog.java | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/quicksettings/QuickRecordingsDialog.java b/packages/SystemUI/src/com/android/systemui/quicksettings/QuickRecordingsDialog.java index 30c7b7c679fa..3f0abdbd779d 100644 --- a/packages/SystemUI/src/com/android/systemui/quicksettings/QuickRecordingsDialog.java +++ b/packages/SystemUI/src/com/android/systemui/quicksettings/QuickRecordingsDialog.java @@ -26,7 +26,6 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; -import android.widget.TextView; import java.io.File; import java.io.FilenameFilter; @@ -42,8 +41,6 @@ public class QuickRecordingsDialog extends Activity { private static final String RECORDING_NAME = "QuickRecord "; private static final String RECORDING_TYPE = ".3gp"; - private int mItems; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -63,37 +60,23 @@ public void onResume() { } } - mItems = recordings.length; - ListView list = new ListView(this); list.setAdapter(new ArrayAdapter (this, android.R.layout.select_dialog_item, dialogEntries)); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView arg0, View view, int item, long id) { - if (recordings[item] != null) { - Intent intent = new Intent(PLAY_RECORDING); - intent.putExtra("file", recordings[item].getAbsolutePath()); - QuickRecordingsDialog.this.sendBroadcast(intent); - } + Intent intent = new Intent(PLAY_RECORDING); + intent.putExtra("file", recordings[item].getAbsolutePath()); + QuickRecordingsDialog.this.sendBroadcast(intent); } }); list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView arg0, View view, int item, long id) { - if (recordings[item] != null) { - recordings[item].delete(); - TextView textView = (TextView) view; - textView.setText(R.string.quick_settings_quick_record_deleted); - Intent intent = new Intent(PLAY_RECORDING); - QuickRecordingsDialog.this.sendBroadcast(intent); - recordings[item] = null; - mItems--; - if (mItems <= 0) { - QuickRecordingsDialog.this.finish(); - } - return true; - } else { - return false; - } + recordings[item].delete(); + Intent intent = new Intent(PLAY_RECORDING); + QuickRecordingsDialog.this.sendBroadcast(intent); + QuickRecordingsDialog.this.finish(); + return true; } }); AlertDialog.Builder action = new AlertDialog.Builder(this); From be9c9c44127a818191929ba7bd6fae92889c8b6f Mon Sep 17 00:00:00 2001 From: gwindlord Date: Thu, 13 Mar 2014 14:25:11 +0100 Subject: [PATCH 3/4] [1/2] frameworks: porting BatteryBar to kk4.4 Adding missing parts Change-Id: I383e068b4618c432a907471dfcfcea3c23ed6b7f --- core/java/android/provider/Settings.java | 26 ++ .../SystemUI/res/layout/navigation_bar.xml | 20 ++ packages/SystemUI/res/layout/status_bar.xml | 6 + packages/SystemUI/res/values/attrs.xml | 4 + .../systemui/statusbar/policy/BatteryBar.java | 264 ++++++++++++++++++ .../policy/BatteryBarController.java | 258 +++++++++++++++++ .../systemui/statusbar/policy/Prefs.java | 11 + 7 files changed, 589 insertions(+) create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBar.java create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBarController.java diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 16f0216904ad..b8926014a4c3 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2792,6 +2792,32 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean */ public static final String POINTER_SPEED = "pointer_speed"; + /** + * Whether to show the battery bar + * @hide + */ + public static final String STATUSBAR_BATTERY_BAR = "statusbar_battery_bar"; + + /** + * @hide + */ + public static final String STATUSBAR_BATTERY_BAR_COLOR = "statusbar_battery_bar_color"; + + /** + * @hide + */ + public static final String STATUSBAR_BATTERY_BAR_THICKNESS = "statusbar_battery_bar_thickness"; + + /** + * @hide + */ + public static final String STATUSBAR_BATTERY_BAR_STYLE = "statusbar_battery_bar_style"; + + /** + * @hide + */ + public static final String STATUSBAR_BATTERY_BAR_ANIMATE = "statusbar_battery_bar_animate"; + /** * I am the lolrus. *

diff --git a/packages/SystemUI/res/layout/navigation_bar.xml b/packages/SystemUI/res/layout/navigation_bar.xml index 63e35e695fe6..cdac7457c2dc 100644 --- a/packages/SystemUI/res/layout/navigation_bar.xml +++ b/packages/SystemUI/res/layout/navigation_bar.xml @@ -31,6 +31,26 @@ android:layout_width="match_parent" > + + + + + + + + + + diff --git a/packages/SystemUI/res/values/attrs.xml b/packages/SystemUI/res/values/attrs.xml index 047570f08898..fb5fb987612d 100644 --- a/packages/SystemUI/res/values/attrs.xml +++ b/packages/SystemUI/res/values/attrs.xml @@ -47,5 +47,9 @@ + + + + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBar.java new file mode 100644 index 000000000000..bedb0f7646ae --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBar.java @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2012 Slimroms & CyanogenMod + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.BroadcastReceiver; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.database.ContentObserver; +import android.graphics.drawable.Animatable; +import android.os.BatteryManager; +import android.os.Handler; +import android.provider.Settings; +import android.util.AttributeSet; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.View; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.Animation; +import android.view.animation.TranslateAnimation; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; + +public class BatteryBar extends RelativeLayout implements Animatable { + + private static final String TAG = BatteryBar.class.getSimpleName(); + + // Total animation duration + private static final int ANIM_DURATION = 1000; // 5 seconds + + private boolean mAttached = false; + private int mBatteryLevel = 0; + private int mChargingLevel = -1; + private boolean mBatteryCharging = false; + private boolean shouldAnimateCharging = true; + private boolean isAnimating = false; + + private SettingsObserver mSettingsObserver; + + LinearLayout mBatteryBarLayout; + View mBatteryBar; + + LinearLayout mChargerLayout; + View mCharger; + + public static final int STYLE_REGULAR = 0; + public static final int STYLE_SYMMETRIC = 1; + + boolean vertical = false; + + class SettingsObserver extends ContentObserver { + public SettingsObserver(Handler handler) { + super(handler); + } + + void observe() { + ContentResolver resolver = mContext.getContentResolver(); + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.STATUSBAR_BATTERY_BAR_COLOR), + false, this); + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE), + false, this); + } + + @Override + public void onChange(boolean selfChange) { + updateSettings(); + } + } + + public BatteryBar(Context context) { + this(context, null); + } + + public BatteryBar(Context context, boolean isCharging, int currentCharge) { + this(context, null); + mBatteryLevel = currentCharge; + mBatteryCharging = isCharging; + } + + public BatteryBar(Context context, boolean isCharging, int currentCharge, boolean isVertical) { + this(context, null); + mBatteryLevel = currentCharge; + mBatteryCharging = isCharging; + vertical = isVertical; + } + + public BatteryBar(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public BatteryBar(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (!mAttached) { + mAttached = true; + + mBatteryBarLayout = new LinearLayout(mContext); + addView(mBatteryBarLayout, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT)); + + mBatteryBar = new View(mContext); + mBatteryBarLayout.addView(mBatteryBar, new LinearLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + + DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); + float dp = 4f; + int pixels = (int) (metrics.density * dp + 0.5f); + + // Charger + mChargerLayout = new LinearLayout(mContext); + + if (vertical) { + addView(mChargerLayout, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, + pixels)); + } else { + addView(mChargerLayout, new RelativeLayout.LayoutParams(pixels, + LayoutParams.MATCH_PARENT)); + } + + mCharger = new View(mContext); + mChargerLayout.setVisibility(View.GONE); + mChargerLayout.addView(mCharger, new LinearLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_BATTERY_CHANGED); + filter.addAction(Intent.ACTION_SCREEN_OFF); + filter.addAction(Intent.ACTION_SCREEN_ON); + getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); + + mSettingsObserver = new SettingsObserver(new Handler()); + mSettingsObserver.observe(); + updateSettings(); + } + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + if (mAttached) { + mAttached = false; + getContext().unregisterReceiver(mIntentReceiver); + getContext().getContentResolver().unregisterContentObserver(mSettingsObserver); + } + } + + private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + + if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { + mBatteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); + mBatteryCharging = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0) == BatteryManager.BATTERY_STATUS_CHARGING; + if (mBatteryCharging && mBatteryLevel < 100) { + start(); + } else { + stop(); + } + setProgress(mBatteryLevel); + } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { + stop(); + } else if (Intent.ACTION_SCREEN_ON.equals(action)) { + if (mBatteryCharging && mBatteryLevel < 100) { + start(); + } + } + } + }; + + private void updateSettings() { + ContentResolver resolver = getContext().getContentResolver(); + + int color = Settings.System.getInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_COLOR, + 0xFF33B5E5); + + shouldAnimateCharging = Settings.System.getInt(resolver, + Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE, 0) == 1; + + if (mBatteryCharging && mBatteryLevel < 100 && shouldAnimateCharging) { + start(); + } else { + stop(); + } + setProgress(mBatteryLevel); + mBatteryBar.setBackgroundColor(color); + mCharger.setBackgroundColor(color); + } + + private void setProgress(int n) { + if (vertical) { + int w = (int) (((getHeight() / 100.0) * n) + 0.5); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mBatteryBarLayout + .getLayoutParams(); + params.height = w; + mBatteryBarLayout.setLayoutParams(params); + } else { + int w = (int) (((getWidth() / 100.0) * n) + 0.5); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mBatteryBarLayout + .getLayoutParams(); + params.width = w; + mBatteryBarLayout.setLayoutParams(params); + } + } + + @Override + public void start() { + if (!shouldAnimateCharging) { + return; + } + + if (vertical) { + TranslateAnimation a = new TranslateAnimation(getX(), getX(), getHeight(), + mBatteryBarLayout.getHeight()); + a.setInterpolator(new AccelerateInterpolator()); + a.setDuration(ANIM_DURATION); + a.setRepeatCount(Animation.INFINITE); + mChargerLayout.startAnimation(a); + mChargerLayout.setVisibility(View.VISIBLE); + } else { + TranslateAnimation a = new TranslateAnimation(getWidth(), mBatteryBarLayout.getWidth(), + getTop(), getTop()); + a.setInterpolator(new AccelerateInterpolator()); + a.setDuration(ANIM_DURATION); + a.setRepeatCount(Animation.INFINITE); + mChargerLayout.startAnimation(a); + mChargerLayout.setVisibility(View.VISIBLE); + } + isAnimating = true; + } + + @Override + public void stop() { + mChargerLayout.clearAnimation(); + mChargerLayout.setVisibility(View.GONE); + isAnimating = false; + } + + @Override + public boolean isRunning() { + return isAnimating; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBarController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBarController.java new file mode 100644 index 000000000000..7186c75c60e7 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryBarController.java @@ -0,0 +1,258 @@ + /* + * Copyright (C) 2012 Slimroms & CyanogenMod + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.BroadcastReceiver; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.res.Configuration; +import android.database.ContentObserver; +import android.os.BatteryManager; +import android.os.Handler; +import android.provider.Settings; +import android.util.AttributeSet; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import java.util.ArrayList; + +public class BatteryBarController extends LinearLayout { + + private static final String TAG = "BatteryBarController"; + + BatteryBar mainBar; + BatteryBar alternateStyleBar; + GlobalSettingsObserver mSettingsObserver; + + public static final int STYLE_REGULAR = 0; + public static final int STYLE_SYMMETRIC = 1; + + static int mStyle = STYLE_REGULAR; + static int mLocation = 0; + + protected final static int CURRENT_LOC = 1; + int mLocationToLookFor = 0; + + private int mBatteryLevel = 0; + private boolean mBatteryCharging = false; + + boolean isAttached = false; + boolean isVertical = false; + + static class GlobalSettingsObserver extends ContentObserver { + private static GlobalSettingsObserver sInstance; + private ArrayList mBatteryBarControllers = new ArrayList(); + private Context mContext; + + public GlobalSettingsObserver(Handler handler, Context context) { + super(handler); + mContext = context.getApplicationContext(); + } + + static GlobalSettingsObserver getInstance(Context context) { + if (sInstance == null) { + sInstance = new GlobalSettingsObserver(new Handler(), context); + } + return sInstance; + } + + void attach(BatteryBarController bbc) { + if (mBatteryBarControllers.isEmpty()) { + observe(); + } + mBatteryBarControllers.add(bbc); + } + + void detach(BatteryBarController bbc) { + mBatteryBarControllers.remove(bbc); + if (mBatteryBarControllers.isEmpty()) { + unobserve(); + } + } + + void observe() { + ContentResolver resolver = mContext.getContentResolver(); + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.STATUSBAR_BATTERY_BAR), false, this); + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.STATUSBAR_BATTERY_BAR_STYLE), false, + this); + resolver.registerContentObserver( + Settings.System.getUriFor(Settings.System.STATUSBAR_BATTERY_BAR_THICKNESS), + false, this); + } + + void unobserve() { + mContext.getContentResolver().unregisterContentObserver(this); + } + + @Override + public void onChange(boolean selfChange) { + this.updateSettings(); + } + + void updateSettings() { + mStyle = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.STATUSBAR_BATTERY_BAR_STYLE, 0); + mLocation = Settings.System.getInt(mContext.getContentResolver(), + Settings.System.STATUSBAR_BATTERY_BAR, 0); + + for (BatteryBarController bbc : mBatteryBarControllers) { + if (bbc.mLocationToLookFor == mLocation) { + bbc.removeBars(); + bbc.addBars(); + bbc.setVisibility(View.VISIBLE); + } else { + bbc.removeBars(); + bbc.setVisibility(View.GONE); + } + } + } + } + + public BatteryBarController(Context context, AttributeSet attrs) { + super(context, attrs); + + if (attrs != null) { + String ns = "http://schemas.android.com/apk/res/com.android.systemui"; + mLocationToLookFor = attrs.getAttributeIntValue(ns, "viewLocation", 0); + } + mSettingsObserver = GlobalSettingsObserver.getInstance(context); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (!isAttached) { + isVertical = (getLayoutParams().height == LayoutParams.MATCH_PARENT); + + isAttached = true; + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_BATTERY_CHANGED); + getContext().registerReceiver(mIntentReceiver, filter); + + mSettingsObserver.attach(this); + updateSettings(); + } + } + + private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + + if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { + mBatteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); + mBatteryCharging = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0) == BatteryManager.BATTERY_STATUS_CHARGING; + Prefs.setLastBatteryLevel(context, mBatteryLevel); + } + } + }; + + @Override + protected void onDetachedFromWindow() { + if (isAttached) { + isAttached = false; + removeBars(); + mSettingsObserver.detach(this); + } + super.onDetachedFromWindow(); + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if (isAttached) { + getHandler().postDelayed(new Runnable() { + @Override + public void run() { + updateSettings(); + } + }, 500); + } + } + + public void addBars() { + // Set heights + DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); + float dp = (float) Settings.System.getInt(getContext().getContentResolver(), + Settings.System.STATUSBAR_BATTERY_BAR_THICKNESS, 1); + int pixels = (int) ((metrics.density * dp) + 0.5); + ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) getLayoutParams(); + + if (isVertical) { + params.width = pixels; + } else { + params.height = pixels; + } + + setLayoutParams(params); + mBatteryLevel = Prefs.getLastBatteryLevel(getContext()); + + if (mStyle == STYLE_REGULAR) { + addView(new BatteryBar(mContext, mBatteryCharging, mBatteryLevel, isVertical), + new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT, 1)); + } else if (mStyle == STYLE_SYMMETRIC) { + BatteryBar bar1 = new BatteryBar(mContext, mBatteryCharging, mBatteryLevel, isVertical); + BatteryBar bar2 = new BatteryBar(mContext, mBatteryCharging, mBatteryLevel, isVertical); + + if (isVertical) { + bar2.setRotationY(180f); + addView(bar2, (new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT, 1))); + addView(bar1, (new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT, 1))); + } else { + bar1.setRotationY(180f); + addView(bar1, (new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT, 1))); + addView(bar2, (new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT, 1))); + } + } + } + + public void removeBars() { + removeAllViews(); + } + + public void updateSettings() { + mStyle = Settings.System.getInt(getContext().getContentResolver(), + Settings.System.STATUSBAR_BATTERY_BAR_STYLE, 0); + mLocation = Settings.System.getInt(getContext().getContentResolver(), + Settings.System.STATUSBAR_BATTERY_BAR, 0); + + if (isLocationValid(mLocation)) { + removeBars(); + addBars(); + setVisibility(View.VISIBLE); + } else { + removeBars(); + setVisibility(View.GONE); + } + } + + protected boolean isLocationValid(int location) { + return mLocationToLookFor == location; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java index f339401dce18..573c40a6c022 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java @@ -22,6 +22,8 @@ public class Prefs { private static final String SHARED_PREFS_NAME = "status_bar"; + public static final String LAST_BATTERY_LEVEL = "last_battery_level"; + public static SharedPreferences read(Context context) { return context.getSharedPreferences(Prefs.SHARED_PREFS_NAME, Context.MODE_PRIVATE); } @@ -29,4 +31,13 @@ public static SharedPreferences read(Context context) { public static SharedPreferences.Editor edit(Context context) { return context.getSharedPreferences(Prefs.SHARED_PREFS_NAME, Context.MODE_PRIVATE).edit(); } + + public static void setLastBatteryLevel(Context context, int level) { + edit(context).putInt(LAST_BATTERY_LEVEL, level).commit(); + } + + public static int getLastBatteryLevel(Context context) { + return read(context).getInt(LAST_BATTERY_LEVEL, 50); + } + } From 878acd15336b778d22ba6088778643e6e1a523f6 Mon Sep 17 00:00:00 2001 From: BigBrother1984 Date: Fri, 6 Jun 2014 20:03:16 +0200 Subject: [PATCH 4/4] HOVER [1/2] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notifications refined: The way you handle with the incoming notifications defines how much you enjoy your device. Hover shows you those notifications when you need them in a beautiful card that briefly appears on your screen. For a detailed look of the notification, you can swipe down to expand some more info, or you can tap it to open the related app using PA’s floating mode. Introducing Hover: https://plus.google.com/107979589566958860409/posts/DC4KyDd1cDC https://plus.google.com/107979589566958860409/posts/BtWoGpNd8Fq This is revision 4 of the original base by @D4rKn3sSyS . Hover works by moving the notification view from statusBar container to Hover’s one and re-themes notifications in the process. When hover is active it is the owner of the view, special care must be taken to not manipulate the statusbar reference while hoveris active. Hover’s view state is managed by a handler based timer. When any touch event is received or a gesture completed the timer is restarted, upon expiration of the timer hover is hidden or will show next notification in the list if there is one (or more) to show. The timer along with animation listeners regulates the rate at which Hover can process new notifications, acting as a spam filter for noisy applications. Upon first run a dialog is displayed explaining Hover to new users. More infos in code’s documentation. Todo: - Swipe up to dismiss only the hover window not the notification in status bar. - Transparent support has been tweaked a bit but needs a more proper solution - Edge gap fix for Theme Engine themes overriding notifications draws - Long press action(s) - MInor tweaks noted in the code’s comments CONTRIBUTORS: @D4rKn3sSyS @BigBrother1984 @Anu6is @beerbong @aaronpoweruser @David96 @linuxman94 Drawables by @arzbhatia Signed-off-by: Jesus David Signed-off-by: Carlo Savignano Signed-off-by: Curtis Mayers Signed-off-by: Yamil Ghazi Signed-off-by: Aaron Gascoigne Signed-off-by: David L.-W. Signed-off-by: Evan Anderson Conflicts: core/java/android/app/INotificationManager.aidl packages/SystemUI/res/layout/status_bar_expanded_header.xml packages/SystemUI/res/values/pa_dimens.xml packages/SystemUI/res/values/pa_strings.xml packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationHelper.java packages/SystemUI/src/com/android/systemui/statusbar/notification/Peek.java packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java services/input/InputWindow.cpp services/java/com/android/server/NotificationManagerService.java Change-Id: I9c2adbf1045665f9d42cd276498e45af21c91042 HOVER: Fix a couple of things: - Handle Ticker properly. Update mTicking, call related statements and disable ticker for blacklisted apps only when hover is off. - Remove a bad patch when you release your finger, there is no need and along with showCurrentNotification() call at setNotification() can even be a bad call. - Notification removal is already done at BaseStatusBar. Remove useless code. Signed-off-by: Carlo Savignano Conflicts: packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java Change-Id: I56627735307833020bd37b645c8d5bda4e6cddbd Conflicts: packages/SystemUI/res/values/slim_dimens.xml --- .../android/app/INotificationManager.aidl | 5 +- core/java/android/provider/Settings.java | 12 + .../drawable-hdpi/ic_notify_hover_normal.png | Bin 0 -> 309 bytes .../drawable-hdpi/ic_notify_hover_pressed.png | Bin 0 -> 292 bytes .../drawable-xhdpi/ic_notify_hover_normal.png | Bin 0 -> 443 bytes .../ic_notify_hover_pressed.png | Bin 0 -> 441 bytes .../ic_notify_hover_normal.png | Bin 0 -> 762 bytes .../ic_notify_hover_pressed.png | Bin 0 -> 711 bytes packages/SystemUI/res/layout/hover_cling.xml | 67 ++ .../SystemUI/res/layout/hover_container.xml | 28 + .../res/layout/status_bar_expanded_header.xml | 14 +- packages/SystemUI/res/values/slim_arrays.xml | 23 + packages/SystemUI/res/values/slim_dimens.xml | 5 + packages/SystemUI/res/values/slim_strings.xml | 3 + .../com/android/systemui/ExpandHelper.java | 6 +- .../systemui/statusbar/BaseStatusBar.java | 129 ++- .../statusbar/notification/Hover.java | 845 ++++++++++++++++++ .../statusbar/notification/HoverCling.java | 300 +++++++ .../statusbar/notification/HoverLayout.java | 235 +++++ .../notification/HoverNotification.java | 103 +++ .../notification/NotificationHelper.java | 354 ++++++++ .../statusbar/phone/PhoneStatusBar.java | 111 ++- .../policy/HeadsUpNotificationView.java | 2 +- .../systemui/statusbar/tv/TvStatusBar.java | 6 + services/input/InputWindow.cpp | 3 +- .../server/NotificationManagerService.java | 180 +++- 26 files changed, 2372 insertions(+), 59 deletions(-) create mode 100644 packages/SystemUI/res/drawable-hdpi/ic_notify_hover_normal.png create mode 100644 packages/SystemUI/res/drawable-hdpi/ic_notify_hover_pressed.png create mode 100644 packages/SystemUI/res/drawable-xhdpi/ic_notify_hover_normal.png create mode 100644 packages/SystemUI/res/drawable-xhdpi/ic_notify_hover_pressed.png create mode 100644 packages/SystemUI/res/drawable-xxhdpi/ic_notify_hover_normal.png create mode 100644 packages/SystemUI/res/drawable-xxhdpi/ic_notify_hover_pressed.png create mode 100644 packages/SystemUI/res/layout/hover_cling.xml create mode 100644 packages/SystemUI/res/layout/hover_container.xml create mode 100644 packages/SystemUI/res/values/slim_arrays.xml create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/Hover.java create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/HoverCling.java create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/HoverLayout.java create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/HoverNotification.java create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationHelper.java diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 9f933ca66c21..f18c18a651b6 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -48,4 +48,7 @@ interface INotificationManager void cancelAllNotificationsFromListener(in INotificationListener token); StatusBarNotification[] getActiveNotificationsFromListener(in INotificationListener token); -} \ No newline at end of file + + void setHoverBlacklistStatus(String pkg, boolean status); + boolean isPackageAllowedForHover(String pkg); +} diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index b8926014a4c3..6bc958e4a606 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2006 The Android Open Source Project + * This code has been modified. Portions copyright (C) 2014, ParanoidAndroid Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -3953,6 +3954,14 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean */ public static final String RECENT_PANEL_SHOW_TOPMOST = "recent_panel_show_topmost"; + /** + * Hover, default is 0 (off). + * 0 = disabled + * 1 = enabled + * @hide + */ + public static final String HOVER_STATE = "hover_state"; + /** * Settings to backup. This is here so that it's in the same place as the settings * keys and easy to update. @@ -6146,6 +6155,9 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val /** @hide */ public static final String IMMERSIVE_MODE_CONFIRMATIONS = "immersive_mode_confirmations"; + /** @hide */ + public static final String HOVER_FIRST_TIME = "hover_first_time"; + /** * This is the query URI for finding a print service to install. * diff --git a/packages/SystemUI/res/drawable-hdpi/ic_notify_hover_normal.png b/packages/SystemUI/res/drawable-hdpi/ic_notify_hover_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..209d5d7ce5e7e1a814cb93c42459cd594937f475 GIT binary patch literal 309 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmUKs7M+SzC{oH>NS%G}c0*}aI z1_r)EAj~ML;ne^XlqzwJC<)F_D=AMbN@WO0%*-p%^K%VRC^ObG)iX47|LkNARJGC5 z#W5tq`R#OTuEPc*ETzluoGd>zw@Cdcx7N0Rhx}{e9!cJCOE7Mh+Rb=C{!;b*uD7OF z`Zn5s(A<{0LN@tR)79N_27Qk_ZrN~jC})0FQ0QB7wzDL)ey{YZj4NnGYeEopc Tzvm|a9nawD>gTe~DWM4f&3$r+ literal 0 HcmV?d00001 diff --git a/packages/SystemUI/res/drawable-hdpi/ic_notify_hover_pressed.png b/packages/SystemUI/res/drawable-hdpi/ic_notify_hover_pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..668e6bcf14f3fb3454d661886a15a1dbd827cfbb GIT binary patch literal 292 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmUKs7M+SzC{oH>NS%G}c0*}aI z1_r)EAj~ML;ne^XlqzwJC<)F_D=AMbN@WO0%*-p%^K%VRC^ObG)iX47|LkNARJFj< z#W5tq`R(+BoDBv7ESD$S-UOoHFADwDPZD|FxXo<*%W;b5=Mg3b`z62F)R()MxP z!!lvI6;>1s;*b z3=DjSK$uZf!>a)(C{^MbQ4*Y=R#Ki=l*$m0n3-3i=jR%tP-d)Ws%L2E{@KZ#fq~K7 z)5S5QBJS<1gS>|Vc${~$25(?Jyip)}L-5aOH4bgwF8rLe{-;hBJ;}c)CTa#W_D90~ z@2_Y5{;>0xMd`Gk+n!n0C~6N5Ml6i^>bP0l+XkKCWoy~ literal 0 HcmV?d00001 diff --git a/packages/SystemUI/res/drawable-xhdpi/ic_notify_hover_pressed.png b/packages/SystemUI/res/drawable-xhdpi/ic_notify_hover_pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..122bd588ba11b810162aba8af857d976071e036e GIT binary patch literal 441 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Ea{HEjtmSN`?>!lvI6;>1s;*b z3=DjSK$uZf!>a)(C{^MbQ4*Y=R#Ki=l*$m0n3-3i=jR%tP-d)Ws%L2E{@KZ#fq~J~ z)5S5QBJS5wc**YZ~%M)vX<{pqg z_j!-LZTstY#Z}XOZv0{!!$1GBa&e2V2G}v0&Ny~aB*A4@f$OlY+eDa(>Sm=_hR2hW7di*KxYOvxZhqRo1D(|VFl1_iy8X2 zxmq7PC-NW==pZ*nx!mrup1GO_76U!<=99duI^3!Gq6Kg5-5D7k+%J}~f6>oz&TiRZ REnsjkc)I$ztaD0e0s#9|t+4q|3=B*eo-U3d6>)E;8LpBE5IFqpU;62}W)fFy0_wi$0pKAw~ZfKrZ!*yG6lJ$*) z9(Jv71y0JoNl=-8sI21&Uzx!q|3qt-B6e$ulgl^AD(!5R?RgS>gKy%UgM4nEG;`WL z-X*Xr{}kEgtWr)jV?Iw^X?5e^&r>0?Zywa7uHq{z*avld7T8mNlRc w;0iz7u7L+6)>HrtM@W(ZrkjuacJuc$mW!|U?5WlSrc4G;S3j3^P6q|3=B+Wo-U3d6>)E;8LpBE5IFqpU;62}W)fF;H1_{$JFwZ|st8-?XUXIq z!($R4;s^iFy8ZRf&QDs^%zI9IrPYlGdj^^baoGFB{Og3AlJMk@$Th{HcL~iCKLvqmRQC8_WpP7WEeQRmQ9P1k+SCPf~C9e{iKYOj>GsDJ&rT~fLKh5W#>q~uZ VJIke-;15h^44$rjF6*2UngAOGKqvqJ literal 0 HcmV?d00001 diff --git a/packages/SystemUI/res/layout/hover_cling.xml b/packages/SystemUI/res/layout/hover_cling.xml new file mode 100644 index 000000000000..23d62e589177 --- /dev/null +++ b/packages/SystemUI/res/layout/hover_cling.xml @@ -0,0 +1,67 @@ + + + + + + + + + + +