Merge "QS: Only put visible tiles in listening state" into nyc-dev am: 8768f68713
am: e696c8465b
* commit 'e696c8465b599fdbc560ec18a7497f90d0a3efbe':
QS: Only put visible tiles in listening state
Change-Id: If91dcf13524c6d63cf99946639163c45bae15739
This commit is contained in:
@@ -31,6 +31,10 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
private View mDecorGroup;
|
private View mDecorGroup;
|
||||||
private PageListener mPageListener;
|
private PageListener mPageListener;
|
||||||
|
|
||||||
|
private int mPosition;
|
||||||
|
private boolean mOffPage;
|
||||||
|
private boolean mListening;
|
||||||
|
|
||||||
public PagedTileLayout(Context context, AttributeSet attrs) {
|
public PagedTileLayout(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
setAdapter(mAdapter);
|
setAdapter(mAdapter);
|
||||||
@@ -48,6 +52,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
public void onPageScrolled(int position, float positionOffset,
|
public void onPageScrolled(int position, float positionOffset,
|
||||||
int positionOffsetPixels) {
|
int positionOffsetPixels) {
|
||||||
if (mPageIndicator == null) return;
|
if (mPageIndicator == null) return;
|
||||||
|
setCurrentPage(position, positionOffset != 0);
|
||||||
mPageIndicator.setLocation(position + positionOffset);
|
mPageIndicator.setLocation(position + positionOffset);
|
||||||
if (mPageListener != null) {
|
if (mPageListener != null) {
|
||||||
mPageListener.onPageChanged(positionOffsetPixels == 0 &&
|
mPageListener.onPageChanged(positionOffsetPixels == 0 &&
|
||||||
@@ -77,6 +82,52 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
super.setCurrentItem(item, smoothScroll);
|
super.setCurrentItem(item, smoothScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setListening(boolean listening) {
|
||||||
|
if (mListening == listening) return;
|
||||||
|
mListening = listening;
|
||||||
|
if (mListening) {
|
||||||
|
mPages.get(mPosition).setListening(listening);
|
||||||
|
if (mOffPage) {
|
||||||
|
mPages.get(mPosition + 1).setListening(listening);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Make sure no pages are listening.
|
||||||
|
for (int i = 0; i < mPages.size(); i++) {
|
||||||
|
mPages.get(i).setListening(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets individual pages to listening or not. If offPage it will set
|
||||||
|
* the next page after position to listening as well since we are in between
|
||||||
|
* pages.
|
||||||
|
*/
|
||||||
|
private void setCurrentPage(int position, boolean offPage) {
|
||||||
|
if (mPosition == position && mOffPage == offPage) return;
|
||||||
|
if (mListening) {
|
||||||
|
if (mPosition != position) {
|
||||||
|
// Clear out the last pages from listening.
|
||||||
|
mPages.get(mPosition).setListening(false);
|
||||||
|
if (mOffPage) {
|
||||||
|
mPages.get(mPosition + 1).setListening(false);
|
||||||
|
}
|
||||||
|
// Set the new pages to listening
|
||||||
|
mPages.get(position).setListening(true);
|
||||||
|
if (offPage) {
|
||||||
|
mPages.get(position + 1).setListening(true);
|
||||||
|
}
|
||||||
|
} else if (mOffPage != offPage) {
|
||||||
|
// Whether we are showing position + 1 has changed.
|
||||||
|
mPages.get(mPosition + 1).setListening(offPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Save the current state.
|
||||||
|
mPosition = position;
|
||||||
|
mOffPage = offPage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasOverlappingRendering() {
|
public boolean hasOverlappingRendering() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class QSContainer extends FrameLayout {
|
|||||||
private QSAnimator mQSAnimator;
|
private QSAnimator mQSAnimator;
|
||||||
private QSCustomizer mQSCustomizer;
|
private QSCustomizer mQSCustomizer;
|
||||||
private NotificationPanelView mPanelView;
|
private NotificationPanelView mPanelView;
|
||||||
|
private boolean mListening;
|
||||||
|
|
||||||
public QSContainer(Context context, AttributeSet attrs) {
|
public QSContainer(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -209,6 +210,7 @@ public class QSContainer extends FrameLayout {
|
|||||||
public void setExpanded(boolean expanded) {
|
public void setExpanded(boolean expanded) {
|
||||||
if (DEBUG) Log.d(TAG, "setExpanded " + expanded);
|
if (DEBUG) Log.d(TAG, "setExpanded " + expanded);
|
||||||
mQsExpanded = expanded;
|
mQsExpanded = expanded;
|
||||||
|
mQSPanel.setListening(mListening && mQsExpanded);
|
||||||
updateQsState();
|
updateQsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,8 +229,9 @@ public class QSContainer extends FrameLayout {
|
|||||||
|
|
||||||
public void setListening(boolean listening) {
|
public void setListening(boolean listening) {
|
||||||
if (DEBUG) Log.d(TAG, "setListening " + listening);
|
if (DEBUG) Log.d(TAG, "setListening " + listening);
|
||||||
mQSPanel.setListening(listening);
|
mListening = listening;
|
||||||
mHeader.setListening(listening);
|
mHeader.setListening(listening);
|
||||||
|
mQSPanel.setListening(mListening && mQsExpanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQsExpansion(float expansion, float headerTranslation) {
|
public void setQsExpansion(float expansion, float headerTranslation) {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback {
|
|||||||
private int mPanelPaddingBottom;
|
private int mPanelPaddingBottom;
|
||||||
private int mBrightnessPaddingTop;
|
private int mBrightnessPaddingTop;
|
||||||
private boolean mExpanded;
|
private boolean mExpanded;
|
||||||
private boolean mListening;
|
protected boolean mListening;
|
||||||
|
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private BrightnessController mBrightnessController;
|
private BrightnessController mBrightnessController;
|
||||||
@@ -102,6 +102,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback {
|
|||||||
protected void setupTileLayout() {
|
protected void setupTileLayout() {
|
||||||
mTileLayout = (QSTileLayout) LayoutInflater.from(mContext).inflate(
|
mTileLayout = (QSTileLayout) LayoutInflater.from(mContext).inflate(
|
||||||
R.layout.qs_paged_tile_layout, this, false);
|
R.layout.qs_paged_tile_layout, this, false);
|
||||||
|
mTileLayout.setListening(mListening);
|
||||||
addView((View) mTileLayout);
|
addView((View) mTileLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,8 +229,8 @@ public class QSPanel extends LinearLayout implements Tunable, Callback {
|
|||||||
public void setListening(boolean listening) {
|
public void setListening(boolean listening) {
|
||||||
if (mListening == listening) return;
|
if (mListening == listening) return;
|
||||||
mListening = listening;
|
mListening = listening;
|
||||||
for (TileRecord r : mRecords) {
|
if (mTileLayout != null) {
|
||||||
r.tile.setListening(mListening);
|
mTileLayout.setListening(listening);
|
||||||
}
|
}
|
||||||
mFooter.setListening(mListening);
|
mFooter.setListening(mListening);
|
||||||
if (mListening) {
|
if (mListening) {
|
||||||
@@ -341,7 +342,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
r.tileView.init(click, longClick);
|
r.tileView.init(click, longClick);
|
||||||
r.tile.setListening(mListening);
|
|
||||||
callback.onStateChanged(r.tile.getState());
|
callback.onStateChanged(r.tile.getState());
|
||||||
r.tile.refreshState();
|
r.tile.refreshState();
|
||||||
mRecords.add(r);
|
mRecords.add(r);
|
||||||
@@ -531,5 +531,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback {
|
|||||||
void removeTile(TileRecord tile);
|
void removeTile(TileRecord tile);
|
||||||
int getOffsetTop(TileRecord tile);
|
int getOffsetTop(TileRecord tile);
|
||||||
boolean updateResources();
|
boolean updateResources();
|
||||||
|
|
||||||
|
void setListening(boolean listening);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -63,7 +64,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|||||||
* handleUpdateState. Callbacks affecting state should use refreshState to trigger another
|
* handleUpdateState. Callbacks affecting state should use refreshState to trigger another
|
||||||
* state update pass on tile looper.
|
* state update pass on tile looper.
|
||||||
*/
|
*/
|
||||||
public abstract class QSTile<TState extends State> implements Listenable {
|
public abstract class QSTile<TState extends State> {
|
||||||
protected final String TAG = "Tile." + getClass().getSimpleName();
|
protected final String TAG = "Tile." + getClass().getSimpleName();
|
||||||
protected static final boolean DEBUG = Log.isLoggable("Tile", Log.DEBUG);
|
protected static final boolean DEBUG = Log.isLoggable("Tile", Log.DEBUG);
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
|||||||
protected final Context mContext;
|
protected final Context mContext;
|
||||||
protected final H mHandler;
|
protected final H mHandler;
|
||||||
protected final Handler mUiHandler = new Handler(Looper.getMainLooper());
|
protected final Handler mUiHandler = new Handler(Looper.getMainLooper());
|
||||||
|
private final ArraySet<Object> mListeners = new ArraySet<>();
|
||||||
|
|
||||||
private final ArrayList<Callback> mCallbacks = new ArrayList<>();
|
private final ArrayList<Callback> mCallbacks = new ArrayList<>();
|
||||||
protected TState mState = newTileState();
|
protected TState mState = newTileState();
|
||||||
@@ -97,6 +99,24 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
|||||||
mHandler = new H(host.getLooper());
|
mHandler = new H(host.getLooper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds or removes a listening client for the tile. If the tile has one or more
|
||||||
|
* listening client it will go into the listening state.
|
||||||
|
*/
|
||||||
|
public void setListening(Object listener, boolean listening) {
|
||||||
|
if (listening) {
|
||||||
|
if (mListeners.add(listener) && mListeners.size() == 1) {
|
||||||
|
if (DEBUG) Log.d(TAG, "setListening " + true);
|
||||||
|
mHandler.obtainMessage(H.SET_LISTENING, 1, 0).sendToTarget();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mListeners.remove(listener) && mListeners.size() == 0) {
|
||||||
|
if (DEBUG) Log.d(TAG, "setListening " + false);
|
||||||
|
mHandler.obtainMessage(H.SET_LISTENING, 0, 0).sendToTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getTileSpec() {
|
public String getTileSpec() {
|
||||||
return mTileSpec;
|
return mTileSpec;
|
||||||
}
|
}
|
||||||
@@ -279,6 +299,8 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
|||||||
handleRefreshState(null);
|
handleRefreshState(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void setListening(boolean listening);
|
||||||
|
|
||||||
protected void handleDestroy() {
|
protected void handleDestroy() {
|
||||||
setListening(false);
|
setListening(false);
|
||||||
mCallbacks.clear();
|
mCallbacks.clear();
|
||||||
@@ -312,6 +334,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
|||||||
private static final int DESTROY = 10;
|
private static final int DESTROY = 10;
|
||||||
private static final int CLEAR_STATE = 11;
|
private static final int CLEAR_STATE = 11;
|
||||||
private static final int REMOVE_CALLBACKS = 12;
|
private static final int REMOVE_CALLBACKS = 12;
|
||||||
|
private static final int SET_LISTENING = 13;
|
||||||
|
|
||||||
private H(Looper looper) {
|
private H(Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
@@ -364,6 +387,9 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
|||||||
} else if (msg.what == CLEAR_STATE) {
|
} else if (msg.what == CLEAR_STATE) {
|
||||||
name = "handleClearState";
|
name = "handleClearState";
|
||||||
handleClearState();
|
handleClearState();
|
||||||
|
} else if (msg.what == SET_LISTENING) {
|
||||||
|
name = "setListening";
|
||||||
|
setListening(msg.arg1 != 0);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unknown msg: " + msg.what);
|
throw new IllegalArgumentException("Unknown msg: " + msg.what);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public class QuickQSPanel extends QSPanel {
|
|||||||
removeView((View) mTileLayout);
|
removeView((View) mTileLayout);
|
||||||
}
|
}
|
||||||
mTileLayout = new HeaderTileLayout(context);
|
mTileLayout = new HeaderTileLayout(context);
|
||||||
|
mTileLayout.setListening(mListening);
|
||||||
addView((View) mTileLayout, 1 /* Between brightness and footer */);
|
addView((View) mTileLayout, 1 /* Between brightness and footer */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +147,7 @@ public class QuickQSPanel extends QSPanel {
|
|||||||
private static class HeaderTileLayout extends LinearLayout implements QSTileLayout {
|
private static class HeaderTileLayout extends LinearLayout implements QSTileLayout {
|
||||||
|
|
||||||
protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
|
protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
|
||||||
|
private boolean mListening;
|
||||||
|
|
||||||
public HeaderTileLayout(Context context) {
|
public HeaderTileLayout(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -155,6 +157,15 @@ public class QuickQSPanel extends QSPanel {
|
|||||||
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setListening(boolean listening) {
|
||||||
|
if (mListening == listening) return;
|
||||||
|
mListening = listening;
|
||||||
|
for (TileRecord record : mRecords) {
|
||||||
|
record.tile.setListening(this, mListening);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTile(TileRecord tile) {
|
public void addTile(TileRecord tile) {
|
||||||
if (getChildCount() != 0) {
|
if (getChildCount() != 0) {
|
||||||
@@ -163,6 +174,7 @@ public class QuickQSPanel extends QSPanel {
|
|||||||
}
|
}
|
||||||
addView(tile.tileView, getChildCount(), generateLayoutParams());
|
addView(tile.tileView, getChildCount(), generateLayoutParams());
|
||||||
mRecords.add(tile);
|
mRecords.add(tile);
|
||||||
|
tile.tile.setListening(this, mListening);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LayoutParams generateSpaceParams() {
|
private LayoutParams generateSpaceParams() {
|
||||||
@@ -190,6 +202,7 @@ public class QuickQSPanel extends QSPanel {
|
|||||||
removeViewAt(childIndex);
|
removeViewAt(childIndex);
|
||||||
}
|
}
|
||||||
mRecords.remove(tile);
|
mRecords.remove(tile);
|
||||||
|
tile.tile.setListening(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getChildIndex(QSTileBaseView tileView) {
|
private int getChildIndex(QSTileBaseView tileView) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
|||||||
|
|
||||||
protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
|
protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
|
||||||
private int mCellMarginTop;
|
private int mCellMarginTop;
|
||||||
|
private boolean mListening;
|
||||||
|
|
||||||
public TileLayout(Context context) {
|
public TileLayout(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -41,18 +42,32 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
|||||||
return getTop();
|
return getTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setListening(boolean listening) {
|
||||||
|
if (mListening == listening) return;
|
||||||
|
mListening = listening;
|
||||||
|
for (TileRecord record : mRecords) {
|
||||||
|
record.tile.setListening(this, mListening);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addTile(TileRecord tile) {
|
public void addTile(TileRecord tile) {
|
||||||
mRecords.add(tile);
|
mRecords.add(tile);
|
||||||
|
tile.tile.setListening(this, mListening);
|
||||||
addView(tile.tileView);
|
addView(tile.tileView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeTile(TileRecord tile) {
|
public void removeTile(TileRecord tile) {
|
||||||
mRecords.remove(tile);
|
mRecords.remove(tile);
|
||||||
|
tile.tile.setListening(this, false);
|
||||||
removeView(tile.tileView);
|
removeView(tile.tileView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllViews() {
|
public void removeAllViews() {
|
||||||
|
for (TileRecord record : mRecords) {
|
||||||
|
record.tile.setListening(this, false);
|
||||||
|
}
|
||||||
mRecords.clear();
|
mRecords.clear();
|
||||||
super.removeAllViews();
|
super.removeAllViews();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ public class TileQueryHelper {
|
|||||||
if (tile == null || !tile.isAvailable()) {
|
if (tile == null || !tile.isAvailable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tile.setListening(true);
|
tile.setListening(this, true);
|
||||||
tile.clearState();
|
tile.clearState();
|
||||||
tile.refreshState();
|
tile.refreshState();
|
||||||
tile.setListening(false);
|
tile.setListening(this, false);
|
||||||
qsHandler.post(new Runnable() {
|
qsHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
Reference in New Issue
Block a user