Merge "QS: Long-press on usage-based tiles to hide." into lmp-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5cde5c616a
@@ -911,4 +911,12 @@
|
||||
<!-- Screen pinning negative response. -->
|
||||
<string name="screen_pinning_negative">No thanks</string>
|
||||
|
||||
<!-- Hide quick settings tile confirmation title -->
|
||||
<string name="quick_settings_reset_confirmation_title">Hide <xliff:g id="tile_label" example="Hotspot">%1$s</xliff:g>?</string>
|
||||
|
||||
<!-- Hide quick settings tile confirmation message -->
|
||||
<string name="quick_settings_reset_confirmation_message">It will reappear the next time you turn it on in settings.</string>
|
||||
|
||||
<!-- Hide quick settings tile confirmation button -->
|
||||
<string name="quick_settings_reset_confirmation_button">Hide</string>
|
||||
</resources>
|
||||
|
||||
@@ -296,7 +296,14 @@ public class QSPanel extends ViewGroup {
|
||||
r.tile.secondaryClick();
|
||||
}
|
||||
};
|
||||
r.tileView.init(click, clickSecondary);
|
||||
final View.OnLongClickListener longClick = new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
r.tile.longClick();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
r.tileView.init(click, clickSecondary, longClick);
|
||||
r.tile.setListening(mListening);
|
||||
callback.onStateChanged(r.tile.getState());
|
||||
r.tile.refreshState();
|
||||
|
||||
@@ -112,6 +112,10 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
mHandler.sendEmptyMessage(H.SECONDARY_CLICK);
|
||||
}
|
||||
|
||||
public void longClick() {
|
||||
mHandler.sendEmptyMessage(H.LONG_CLICK);
|
||||
}
|
||||
|
||||
public void showDetail(boolean show) {
|
||||
mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0).sendToTarget();
|
||||
}
|
||||
@@ -155,6 +159,10 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
// optional
|
||||
}
|
||||
|
||||
protected void handleLongClick() {
|
||||
// optional
|
||||
}
|
||||
|
||||
protected void handleRefreshState(Object arg) {
|
||||
handleUpdateState(mTmpState, arg);
|
||||
final boolean changed = mTmpState.copyTo(mState);
|
||||
@@ -216,12 +224,13 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
private static final int SET_CALLBACK = 1;
|
||||
private static final int CLICK = 2;
|
||||
private static final int SECONDARY_CLICK = 3;
|
||||
private static final int REFRESH_STATE = 4;
|
||||
private static final int SHOW_DETAIL = 5;
|
||||
private static final int USER_SWITCH = 6;
|
||||
private static final int TOGGLE_STATE_CHANGED = 7;
|
||||
private static final int SCAN_STATE_CHANGED = 8;
|
||||
private static final int DESTROY = 9;
|
||||
private static final int LONG_CLICK = 4;
|
||||
private static final int REFRESH_STATE = 5;
|
||||
private static final int SHOW_DETAIL = 6;
|
||||
private static final int USER_SWITCH = 7;
|
||||
private static final int TOGGLE_STATE_CHANGED = 8;
|
||||
private static final int SCAN_STATE_CHANGED = 9;
|
||||
private static final int DESTROY = 10;
|
||||
|
||||
private H(Looper looper) {
|
||||
super(looper);
|
||||
@@ -241,6 +250,9 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
} else if (msg.what == SECONDARY_CLICK) {
|
||||
name = "handleSecondaryClick";
|
||||
handleSecondaryClick();
|
||||
} else if (msg.what == LONG_CLICK) {
|
||||
name = "handleLongClick";
|
||||
handleLongClick();
|
||||
} else if (msg.what == REFRESH_STATE) {
|
||||
name = "handleRefreshState";
|
||||
handleRefreshState(msg.obj);
|
||||
|
||||
@@ -63,6 +63,7 @@ public class QSTileView extends ViewGroup {
|
||||
private boolean mDual;
|
||||
private OnClickListener mClickPrimary;
|
||||
private OnClickListener mClickSecondary;
|
||||
private OnLongClickListener mLongClick;
|
||||
private Drawable mTileBackground;
|
||||
private RippleDrawable mRipple;
|
||||
|
||||
@@ -190,6 +191,7 @@ public class QSTileView extends ViewGroup {
|
||||
mTopBackgroundView.setOnClickListener(null);
|
||||
mTopBackgroundView.setClickable(false);
|
||||
setOnClickListener(mClickPrimary);
|
||||
setOnLongClickListener(mLongClick);
|
||||
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
|
||||
setBackground(mTileBackground);
|
||||
}
|
||||
@@ -206,9 +208,11 @@ public class QSTileView extends ViewGroup {
|
||||
}
|
||||
}
|
||||
|
||||
public void init(OnClickListener clickPrimary, OnClickListener clickSecondary) {
|
||||
public void init(OnClickListener clickPrimary, OnClickListener clickSecondary,
|
||||
OnLongClickListener longClick) {
|
||||
mClickPrimary = clickPrimary;
|
||||
mClickSecondary = clickSecondary;
|
||||
mLongClick = longClick;
|
||||
}
|
||||
|
||||
protected View createIcon() {
|
||||
|
||||
@@ -18,10 +18,13 @@ package com.android.systemui.qs;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialog;
|
||||
import com.android.systemui.statusbar.policy.Listenable;
|
||||
|
||||
public class UsageTracker implements Listenable {
|
||||
@@ -65,6 +68,25 @@ public class UsageTracker implements Listenable {
|
||||
getSharedPrefs().edit().remove(mPrefKey).commit();
|
||||
}
|
||||
|
||||
public void showResetConfirmation(String title, final Runnable onConfirmed) {
|
||||
final SystemUIDialog d = new SystemUIDialog(mContext);
|
||||
d.setTitle(title);
|
||||
d.setMessage(mContext.getString(R.string.quick_settings_reset_confirmation_message));
|
||||
d.setNegativeButton(android.R.string.cancel, null);
|
||||
d.setPositiveButton(R.string.quick_settings_reset_confirmation_button,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
reset();
|
||||
if (onConfirmed != null) {
|
||||
onConfirmed.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
d.setCanceledOnTouchOutside(true);
|
||||
d.show();
|
||||
}
|
||||
|
||||
private SharedPreferences getSharedPrefs() {
|
||||
return mContext.getSharedPreferences(mContext.getPackageName(), 0);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,19 @@ public class ColorInversionTile extends QSTile<QSTile.BooleanState> {
|
||||
mDisable.setAllowAnimation(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleLongClick() {
|
||||
if (mState.value) return; // don't allow usage reset if inversion is active
|
||||
final String title = mContext.getString(R.string.quick_settings_reset_confirmation_title,
|
||||
mState.label);
|
||||
mUsageTracker.showResetConfirmation(title, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
refreshState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleUpdateState(BooleanState state, Object arg) {
|
||||
final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue();
|
||||
|
||||
@@ -64,6 +64,19 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
|
||||
mController.setHotspotEnabled(!isEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleLongClick() {
|
||||
if (mState.value) return; // don't allow usage reset if hotspot is active
|
||||
final String title = mContext.getString(R.string.quick_settings_reset_confirmation_title,
|
||||
mState.label);
|
||||
mUsageTracker.showResetConfirmation(title, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
refreshState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleUpdateState(BooleanState state, Object arg) {
|
||||
state.visible = mController.isHotspotSupported() && mUsageTracker.isRecentlyUsed()
|
||||
|
||||
@@ -39,6 +39,8 @@ public class IntentTile extends QSTile<QSTile.State> {
|
||||
|
||||
private PendingIntent mOnClick;
|
||||
private String mOnClickUri;
|
||||
private PendingIntent mOnLongClick;
|
||||
private String mOnLongClickUri;
|
||||
private int mCurrentUserId;
|
||||
|
||||
private IntentTile(Host host, String action) {
|
||||
@@ -80,15 +82,24 @@ public class IntentTile extends QSTile<QSTile.State> {
|
||||
|
||||
@Override
|
||||
protected void handleClick() {
|
||||
sendIntent("click", mOnClick, mOnClickUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleLongClick() {
|
||||
sendIntent("long-click", mOnLongClick, mOnLongClickUri);
|
||||
}
|
||||
|
||||
private void sendIntent(String type, PendingIntent pi, String uri) {
|
||||
try {
|
||||
if (mOnClick != null) {
|
||||
mOnClick.send();
|
||||
} else if (mOnClickUri != null) {
|
||||
final Intent intent = Intent.parseUri(mOnClickUri, Intent.URI_INTENT_SCHEME);
|
||||
if (pi != null) {
|
||||
pi.send();
|
||||
} else if (uri != null) {
|
||||
final Intent intent = Intent.parseUri(uri, Intent.URI_INTENT_SCHEME);
|
||||
mContext.sendBroadcastAsUser(intent, new UserHandle(mCurrentUserId));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "Error sending click intent", t);
|
||||
Log.w(TAG, "Error sending " + type + " intent", t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +131,8 @@ public class IntentTile extends QSTile<QSTile.State> {
|
||||
}
|
||||
mOnClick = intent.getParcelableExtra("onClick");
|
||||
mOnClickUri = intent.getStringExtra("onClickUri");
|
||||
mOnLongClick = intent.getParcelableExtra("onLongClick");
|
||||
mOnLongClickUri = intent.getStringExtra("onLongClickUri");
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
|
||||
Reference in New Issue
Block a user