Skip to content

Commit 5a6675e

Browse files
mkodekarAnik1199
authored andcommitted
OnTheSpot: Shake to clear Recent Apps and Notifications
Inspired by :- SudaMod/android_frameworks_base@cee4510 and Paranoid android Setting Confirmation helper. Signed-off-by: Anik1199 <[email protected]> Conflicts: core/java/android/provider/Settings.java packages/SystemUI/res/values/metallium_strings.xml packages/SystemUI/res/values/styles.xml packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
1 parent 54a77c8 commit 5a6675e

File tree

9 files changed

+142
-7
lines changed

9 files changed

+142
-7
lines changed

core/java/android/provider/Settings.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,8 +3623,28 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
36233623
*/
36243624
public static final String NAVIGATION_BAR_SHOW = "navigation_bar_show";
36253625

3626-
/**
3627-
* Navigation bar height when it is on protrait
3626+
/**
3627+
* Shake to clean recents app screen
3628+
* @hide
3629+
*
3630+
*/
3631+
public static final String SHAKE_TO_CLEAN_RECENTS = "shake_to_clean_recents";
3632+
3633+
/**
3634+
* Shake to clean notifications
3635+
* @hide
3636+
*
3637+
*/
3638+
public static final String SHAKE_TO_CLEAN_NOTIFICATIONS = "shake_to_clean_notifications";
3639+
3640+
/**
3641+
* Settings to backup. This is here so that it's in the same place as the settings
3642+
* keys and easy to update.
3643+
*
3644+
* NOTE: Settings are backed up and restored in the order they appear
3645+
* in this array. If you have one setting depending on another,
3646+
* make sure that they are ordered appropriately.
3647+
*
36283648
* @hide
36293649
*/
36303650
public static final String NAVIGATION_BAR_HEIGHT = "navigation_bar_height";
@@ -3645,7 +3665,14 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
36453665
* Position of gesture anywhere trigger. Value is either Gravity.LEFT or Gravity.RIGHT
36463666
* @hide
36473667
*/
3648-
public static final String NAVBAR_LEFT_IN_LANDSCAPE = "navigation_bar_left";
3668+
public static final String[] SETTINGS_TO_RESET = {
3669+
QUICK_SETTINGS_QUICK_PULL_DOWN,
3670+
SAFE_HEADSET_VOLUME,
3671+
SHAKE_TO_CLEAN_RECENTS,
3672+
SHAKE_TO_CLEAN_NOTIFICATIONS
3673+
};
3674+
3675+
// Settings moved to Settings.Secure
36493676

36503677
/**
36513678
* Enable HW keys

packages/SystemUI/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224

225225
<activity android:name=".recent.RecentsActivity"
226226
android:label="@string/accessibility_desc_recent_apps"
227-
android:theme="@style/RecentsStyle"
227+
android:theme="@style/RecentsTheme.Wallpaper"
228228
android:excludeFromRecents="true"
229229
android:launchMode="singleInstance"
230230
android:resumeWhilePausing="true"
4.83 KB
Loading
3.5 KB
Loading

packages/SystemUI/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</style>
2222

2323
<style name="RecentsTheme" parent="@android:style/Theme.Material.Wallpaper">
24+
<style name="RecentsTheme" parent="@android:style/Theme.DeviceDefault">
2425
<!-- NoTitle -->
2526
<item name="android:windowNoTitle">true</item>
2627
<!-- Misc -->

packages/SystemUI/res/values/tr_strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,12 @@
7373
<!-- Title shown in recents popup for showing app launch in floating mode -->
7474
<string name="recent_float_mode_title">Floating mode</string>
7575

76+
<!-- Shake to clear Recents apps -->
77+
<string name="shake_to_clean_recents_title">Shake To Clear Recents applications</string>
78+
<string name="shake_to_clean_recents_message">Would you like to clear the Running applications shown in recents screen by shaking the phone? Enabling it might drain your battery!</string>
79+
80+
<!-- Shake to clear notifications -->
81+
<string name="shake_to_clean_notifications_title">Shake To Clear Notifications</string>
82+
<string name="shake_to_clean_notifications_message">Would you like to clear the Expanded Notifications by shaking the phone? Enabling it might drain your battery!</string>
83+
7684
</resources>

packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ public FinishRecentsRunnable(Intent launchIntent, ActivityOptions opts) {
109109
}
110110

111111
@Override
112-
public void run() {
112+
public void run() {
113113
// Finish Recents
114114
if (mLaunchIntent != null) {
115115
if (mLaunchOpts != null) {
116116
startActivityAsUser(mLaunchIntent, mLaunchOpts.toBundle(), UserHandle.CURRENT);
117+
mRecentsView.enableShake(false);
117118
} else {
118119
startActivityAsUser(mLaunchIntent, UserHandle.CURRENT);
119120
}
@@ -226,6 +227,7 @@ void updateRecentsTasks(Intent launchIntent) {
226227
int taskStackCount = stacks.size();
227228
if (mConfig.launchedToTaskId != -1) {
228229
for (int i = 0; i < taskStackCount; i++) {
230+
mRecentsView.enableShake(true);
229231
TaskStack stack = stacks.get(i);
230232
ArrayList<Task> tasks = stack.getTasks();
231233
int taskCount = tasks.size();
@@ -244,6 +246,8 @@ void updateRecentsTasks(Intent launchIntent) {
244246
if (mEmptyView == null) {
245247
mEmptyView = mEmptyViewStub.inflate();
246248
}
249+
250+
mRecentsView.enableShake(false);
247251
mEmptyView.setVisibility(View.VISIBLE);
248252
mEmptyView.setOnClickListener(new View.OnClickListener() {
249253
@Override
@@ -259,6 +263,8 @@ public void onClick(View view) {
259263
mEmptyView.setOnClickListener(null);
260264
}
261265
findViewById(R.id.floating_action_button).setVisibility(View.VISIBLE);
266+
mRecentsView.enableShake(true);
267+
findViewById(R.id.clear_recents).setVisibility(View.VISIBLE);
262268
boolean showSearchBar = Settings.System.getInt(getContentResolver(),
263269
Settings.System.RECENTS_SHOW_SEARCH_BAR, 1) == 1;
264270
if (mRecentsView.hasSearchBar()) {
@@ -469,6 +475,8 @@ protected void onStart() {
469475
// Update the recent tasks
470476
updateRecentsTasks(getIntent());
471477

478+
479+
472480
// If this is a new instance from a configuration change, then we have to manually trigger
473481
// the enter animation state
474482
if (mConfig.launchedHasConfigurationChanged) {

packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import android.util.EventLog;
3939
import android.view.ViewAnimationUtils;
4040
import android.view.Gravity;
41+
import android.util.SettingConfirmationHelper;
4142
import android.view.LayoutInflater;
4243
import android.view.View;
4344
import android.view.WindowInsets;
@@ -52,6 +53,7 @@
5253
import com.android.systemui.recents.model.RecentsTaskLoader;
5354
import com.android.systemui.recents.model.Task;
5455
import com.android.systemui.recents.model.TaskStack;
56+
import com.android.systemui.doze.ShakeSensorManager;
5557

5658
import com.android.systemui.R;
5759
import com.android.systemui.EventLogTags;
@@ -68,7 +70,7 @@
6870
* to their SpaceNode bounds.
6971
*/
7072
public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks,
71-
RecentsPackageMonitor.PackageCallbacks {
73+
RecentsPackageMonitor.PackageCallbacks, ShakeSensorManager.ShakeListener {
7274

7375
/** The RecentsView callbacks */
7476
public interface RecentsViewCallbacks {
@@ -94,6 +96,10 @@ public interface RecentsViewCallbacks {
9496
private ActivityManager mAm;
9597
private int mTotalMem;
9698

99+
private ShakeSensorManager mShakeSensorManager;
100+
private boolean enableShakeCleanByUser;
101+
private boolean enableShakeClean;
102+
97103
public RecentsView(Context context) {
98104
super(context);
99105
}
@@ -112,6 +118,22 @@ public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int de
112118
mInflater = LayoutInflater.from(context);
113119
mAm = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
114120
mTotalMem = getTotalMemory();
121+
mShakeSensorManager = new ShakeSensorManager(mContext, this);
122+
123+
}
124+
125+
@Override
126+
public synchronized void onShake() {
127+
startHideClearRecentsButtonAnimation();
128+
dismissAllTasksAnimated();
129+
}
130+
131+
public void enableShake (boolean enableShakeClean) {
132+
if (enableShakeClean && enableShakeCleanByUser) {
133+
mShakeSensorManager.enable(20);
134+
} else {
135+
mShakeSensorManager.disable();
136+
}
115137
}
116138

117139
/** Sets the callbacks */
@@ -228,6 +250,7 @@ public boolean launchPreviousTask() {
228250

229251
// Find the launch task in the stack
230252
if (!tasks.isEmpty()) {
253+
enableShake(false);
231254
int taskCount = tasks.size();
232255
for (int j = 0; j < taskCount; j++) {
233256
if (tasks.get(j).isLaunchTarget) {
@@ -298,6 +321,9 @@ public void startHideClearRecentsButtonAnimation() {
298321
public void run() {
299322
mFloatingButton.setVisibility(View.GONE);
300323
mFloatingButton.setAlpha(1f);
324+
enableShake(false);
325+
mClearRecents.setVisibility(View.GONE);
326+
mClearRecents.setAlpha(1f);
301327
}
302328
})
303329
.start();
@@ -363,6 +389,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
363389
boolean showClearAllRecents = Settings.System.getInt(resolver,
364390
Settings.System.SHOW_CLEAR_ALL_RECENTS, 1) == 1;
365391

392+
enableShakeCleanByUser = Settings.System.getInt(mContext.getContentResolver(),
393+
Settings.System.SHAKE_TO_CLEAN_RECENTS, 0) == 1;
366394
Rect taskStackBounds = new Rect();
367395
mConfig.getTaskStackBounds(width, height, mConfig.systemInsets.top,
368396
mConfig.systemInsets.right, taskStackBounds);
@@ -520,6 +548,20 @@ public void onClick(View v) {
520548
});
521549
mMemText = (TextView) ((View)getParent()).findViewById(R.id.recents_memory_text);
522550
mMemBar = (ProgressBar) ((View)getParent()).findViewById(R.id.recents_memory_bar);
551+
552+
mClearRecents.setOnLongClickListener(new View.OnLongClickListener() {
553+
public boolean onLongClick(View v) {
554+
SettingConfirmationHelper helper = new SettingConfirmationHelper();
555+
helper.showConfirmationDialogForSetting(
556+
mContext,
557+
mContext.getString(R.string.shake_to_clean_recents_title),
558+
mContext.getString(R.string.shake_to_clean_recents_message),
559+
mContext.getResources().getDrawable(R.drawable.shake_to_clean_recents),
560+
Settings.System.SHAKE_TO_CLEAN_RECENTS,
561+
null);
562+
return true;
563+
}
564+
});
523565
}
524566

525567
/**
@@ -785,6 +827,7 @@ public void onAllTaskViewsDismissed() {
785827

786828
/** Final callback after Recents is finally hidden. */
787829
public void onRecentsHidden() {
830+
enableShake(false);
788831
// Notify each task stack view
789832
int childCount = getChildCount();
790833
for (int i = 0; i < childCount; i++) {
@@ -831,6 +874,7 @@ public void onTaskStackUnfilterTriggered() {
831874
public void onPackagesChanged(RecentsPackageMonitor monitor, String packageName, int userId) {
832875
// Propagate this event down to each task stack view
833876
int childCount = getChildCount();
877+
enableShake(true);
834878
for (int i = 0; i < childCount; i++) {
835879
View child = getChildAt(i);
836880
if (child != mSearchBar) {

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import android.util.EventLog;
108108
import android.util.Log;
109109
import android.util.Pair;
110+
import android.util.SettingConfirmationHelper;
110111
import android.view.Display;
111112
import android.view.Gravity;
112113
import android.view.HardwareCanvas;
@@ -156,6 +157,7 @@
156157
import com.android.systemui.cm.UserContentObserver;
157158
import com.android.systemui.doze.DozeHost;
158159
import com.android.systemui.doze.DozeLog;
160+
import com.android.systemui.doze.ShakeSensorManager;
159161
import com.android.systemui.keyguard.KeyguardViewMediator;
160162
import com.android.systemui.qs.QSPanel;
161163
import com.android.systemui.recent.ScreenPinningRequest;
@@ -220,7 +222,7 @@
220222
import java.util.Map;
221223

222224
public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
223-
DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener {
225+
DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener, ShakeSensorManager.ShakeListener {
224226
static final String TAG = "PhoneStatusBar";
225227
public static final boolean DEBUG = BaseStatusBar.DEBUG;
226228
public static final boolean SPEW = false;
@@ -325,6 +327,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
325327
private boolean mScreenOnComingFromTouch;
326328
private PointF mScreenOnTouchLocation;
327329

330+
private ShakeSensorManager mShakeSensorManager;
331+
private boolean enableShakeCleanByUser;
332+
private boolean enableShakeClean;
333+
328334
int mPixelFormat;
329335
Object mQueueLock = new Object();
330336

@@ -559,6 +565,9 @@ protected void observe() {
559565
Settings.System.APP_SIDEBAR_POSITION),
560566
false, this, UserHandle.USER_ALL);
561567
update();
568+
Settings.System.DEV_FORCE_SHOW_NAVBAR), false, this);
569+
resolver.registerContentObserver(Settings.System.getUriFor(
570+
Settings.System.SHAKE_TO_CLEAN_NOTIFICATIONS), false, this);
562571
}
563572

564573
@Override
@@ -1093,13 +1102,32 @@ public void start() {
10931102
updateCustomRecentsLongPressHandler(true);
10941103
}
10951104

1105+
@Override
1106+
public synchronized void onShake() {
1107+
ContentResolver resolver = mContext.getContentResolver();
1108+
enableShakeCleanByUser = Settings.System.getIntForUser(
1109+
resolver, Settings.System.SHAKE_TO_CLEAN_NOTIFICATIONS, 0, UserHandle.USER_CURRENT) == 2;
1110+
clearAllNotifications();
1111+
}
1112+
1113+
public void enableShake(boolean enableShakeClean) {
1114+
if (enableShakeClean && mScreenOnFromKeyguard) {
1115+
mShakeSensorManager.enable(20);
1116+
} else {
1117+
mShakeSensorManager.disable();
1118+
}
1119+
}
1120+
10961121
// ================================================================================
10971122
// Constructing the view
10981123
// ================================================================================
10991124
@ChaosLab(name="GestureAnywhere", classification=Classification.CHANGE_CODE)
11001125
protected PhoneStatusBarView makeStatusBarView() {
11011126
final Context context = mContext;
11021127

1128+
mShakeSensorManager = new ShakeSensorManager(mContext, this);
1129+
mShakeSensorManager.enable(20);
1130+
11031131
Resources res = context.getResources();
11041132

11051133
mScreenWidth = (float) context.getResources().getDisplayMetrics().widthPixels;
@@ -1113,6 +1141,14 @@ protected PhoneStatusBarView makeStatusBarView() {
11131141

11141142
mStatusBarWindowContent = (FrameLayout) View.inflate(context,
11151143
R.layout.super_status_bar, null);
1144+
if (isMSim()) {
1145+
mStatusBarWindowContent = (FrameLayout) View.inflate(context,
1146+
R.layout.msim_super_status_bar, null);
1147+
} else {
1148+
mStatusBarWindowContent = (FrameLayout) View.inflate(context,
1149+
R.layout.super_status_bar, null);
1150+
}
1151+
11161152
mStatusBarWindowContent.setOnTouchListener(new View.OnTouchListener() {
11171153
@Override
11181154
public boolean onTouch(View v, MotionEvent event) {
@@ -1228,9 +1264,18 @@ public boolean onTouch(View v, MotionEvent event) {
12281264
mDismissView.setOnButtonClickListener(new View.OnClickListener() {
12291265
@Override
12301266
public void onClick(View v) {
1267+
SettingConfirmationHelper helper = new SettingConfirmationHelper();
1268+
helper.showConfirmationDialogForSetting(
1269+
mContext,
1270+
mContext.getString(R.string.shake_to_clean_notifications_title),
1271+
mContext.getString(R.string.shake_to_clean_notifications_message),
1272+
mContext.getResources().getDrawable(R.drawable.shake_to_clean_notifications),
1273+
Settings.System.SHAKE_TO_CLEAN_NOTIFICATIONS,
1274+
null);
12311275
clearAllNotifications();
12321276
}
12331277
});
1278+
12341279
mStackScroller.setDismissView(mDismissView);
12351280
mExpandedContents = mStackScroller;
12361281

@@ -3058,6 +3103,7 @@ void makeExpandedVisible(boolean force) {
30583103
}
30593104

30603105
mExpandedVisible = true;
3106+
enableShake(true);
30613107
if (mNavigationBarView != null)
30623108
mNavigationBarView.setSlippery(true);
30633109

@@ -3250,6 +3296,7 @@ void makeExpandedInvisible() {
32503296
mNotificationPanel.closeQs();
32513297

32523298
mExpandedVisible = false;
3299+
enableShake(false);
32533300
if (mNavigationBarView != null)
32543301
mNavigationBarView.setSlippery(false);
32553302
visibilityChanged(false);

0 commit comments

Comments
 (0)