summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabian Kozynski <kozynski@google.com> 2018-10-03 15:04:56 -0400
committer Fabian Kozynski <kozynski@google.com> 2018-10-04 12:16:38 -0400
commit407ddb2f206d36adc514cd0295b780bcf176eb26 (patch)
tree997e15ecce5829edc56d0b39d2bb2973b1916c37
parent75d2c1f13a2a452ccd8096bef591f590e84a126a (diff)
Page in PagedTileLayout only changes when needed
Made sure that pages are not changed unnecesarily on events that do not modify the page structure. Saves current page on destruction, to be restored later. In particular in the case of switching to Dark theme on entering battery saver mode (it destroys QSFragment). Test: manual && runtest Change-Id: I941f0a7728139257d5c5dd3646df16aaf1805470 Fixes: 117171669
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java39
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSFragment.java6
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSPanel.java6
3 files changed, 48 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
index 4b5ab2a640ff..c68172eec1c6 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
@@ -6,7 +6,9 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
+import android.content.res.Configuration;
import android.content.res.Resources;
+import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
@@ -29,6 +31,7 @@ import java.util.Set;
public class PagedTileLayout extends ViewPager implements QSTileLayout {
private static final boolean DEBUG = false;
+ private static final String CURRENT_PAGE = "current_page";
private static final String TAG = "PagedTileLayout";
private static final int REVEAL_SCROLL_DURATION_MILLIS = 750;
@@ -54,6 +57,9 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
private AnimatorSet mBounceAnimatorSet;
private float mLastExpansion;
private boolean mDistributeTiles = false;
+ private int mPageToRestore = -1;
+ private int mLayoutOrientation;
+ private int mLayoutDirection;
public PagedTileLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -61,13 +67,37 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
setAdapter(mAdapter);
setOnPageChangeListener(mOnPageChangeListener);
setCurrentItem(0, false);
+ mLayoutOrientation = getResources().getConfiguration().orientation;
+ mLayoutDirection = getLayoutDirection();
+ }
+
+ public void saveInstanceState(Bundle outState) {
+ outState.putInt(CURRENT_PAGE, getCurrentItem());
+ }
+
+ public void restoreInstanceState(Bundle savedInstanceState) {
+ // There's only 1 page at this point. We want to restore the correct page once the
+ // pages have been inflated
+ mPageToRestore = savedInstanceState.getInt(CURRENT_PAGE, -1);
+ }
+
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ if (mLayoutOrientation != newConfig.orientation) {
+ mLayoutOrientation = newConfig.orientation;
+ setCurrentItem(0, false);
+ }
}
@Override
public void onRtlPropertiesChanged(int layoutDirection) {
super.onRtlPropertiesChanged(layoutDirection);
- setAdapter(mAdapter);
- setCurrentItem(0, false);
+ if (mLayoutDirection != layoutDirection) {
+ mLayoutDirection = layoutDirection;
+ setAdapter(mAdapter);
+ setCurrentItem(0, false);
+ }
}
@Override
@@ -218,7 +248,10 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
mPageIndicator.setNumPages(mPages.size());
setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
- setCurrentItem(0, false);
+ if (mPageToRestore != -1) {
+ setCurrentItem(mPageToRestore, false);
+ mPageToRestore = -1;
+ }
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
index 79e508611750..42dfceed1e0d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
@@ -103,6 +103,9 @@ public class QSFragment extends Fragment implements QS, CommandQueue.Callbacks {
setListening(savedInstanceState.getBoolean(EXTRA_LISTENING));
setEditLocation(view);
mQSCustomizer.restoreInstanceState(savedInstanceState);
+ if (mQsExpanded) {
+ mQSPanel.getTileLayout().restoreInstanceState(savedInstanceState);
+ }
}
SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this);
}
@@ -127,6 +130,9 @@ public class QSFragment extends Fragment implements QS, CommandQueue.Callbacks {
outState.putBoolean(EXTRA_EXPANDED, mQsExpanded);
outState.putBoolean(EXTRA_LISTENING, mListening);
mQSCustomizer.saveInstanceState(outState);
+ if (mQsExpanded) {
+ mQSPanel.getTileLayout().saveInstanceState(outState);
+ }
}
@VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index e98ef4c09667..cf63e478312c 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.metrics.LogMaker;
+import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.service.quicksettings.Tile;
@@ -666,6 +667,11 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
}
public interface QSTileLayout {
+
+ default void saveInstanceState(Bundle outState) {}
+
+ default void restoreInstanceState(Bundle savedInstanceState) {}
+
void addTile(TileRecord tile);
void removeTile(TileRecord tile);