Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ab4d838 authored by Winson Chung's avatar Winson Chung
Browse files

Saving the stack state when you rotate.

- Saving the focus and stack scroll, along with
  the history visibility on configuration change.

Change-Id: I788fa06de9af8f7769de26442c804e27daa7e627
parent 9a74290a
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
    private final static String TAG = "RecentsActivity";
    private final static boolean DEBUG = false;

    private final static String KEY_SAVED_STATE_HISTORY_VISIBLE =
            "saved_instance_state_history_visible";

    public final static int EVENT_BUS_PRIORITY = Recents.EVENT_BUS_PRIORITY + 1;

    private RecentsPackageMonitor mPackageMonitor;
@@ -499,6 +502,25 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        EventBus.getDefault().unregister(mScrimViews);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(KEY_SAVED_STATE_HISTORY_VISIBLE,
                (mHistoryView != null) && mHistoryView.isVisible());
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        if (savedInstanceState.getBoolean(KEY_SAVED_STATE_HISTORY_VISIBLE, false)) {
            ReferenceCountedTrigger postHideStackAnimationTrigger =
                    new ReferenceCountedTrigger(this);
            postHideStackAnimationTrigger.increment();
            EventBus.getDefault().send(new ShowHistoryEvent(postHideStackAnimationTrigger));
            postHideStackAnimationTrigger.decrement();
        }
    }

    @Override
    public void onTrimMemory(int level) {
        RecentsTaskLoader loader = Recents.getTaskLoader();
+25 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.IntProperty;
import android.util.Log;
import android.util.Property;
@@ -91,6 +92,12 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    private final static String TAG = "TaskStackView";
    private final static boolean DEBUG = false;

    private final static String KEY_SAVED_STATE_SUPER = "saved_instance_state_super";
    private final static String KEY_SAVED_STATE_LAYOUT_FOCUSED_STATE =
            "saved_instance_state_layout_focused_state";
    private final static String KEY_SAVED_STATE_LAYOUT_STACK_SCROLL =
            "saved_instance_state_layout_stack_scroll";

    // The thresholds at which to show/hide the history button.
    private static final float SHOW_HISTORY_BUTTON_SCROLL_THRESHOLD = 0.3f;
    private static final float HIDE_HISTORY_BUTTON_SCROLL_THRESHOLD = 0.3f;
@@ -827,6 +834,24 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        }
    }

    @Override
    protected Parcelable onSaveInstanceState() {
        Bundle savedState = new Bundle();
        savedState.putParcelable(KEY_SAVED_STATE_SUPER, super.onSaveInstanceState());
        savedState.putFloat(KEY_SAVED_STATE_LAYOUT_FOCUSED_STATE, mLayoutAlgorithm.getFocusState());
        savedState.putFloat(KEY_SAVED_STATE_LAYOUT_STACK_SCROLL, mStackScroller.getStackScroll());
        return super.onSaveInstanceState();
    }

    @Override
    protected void onRestoreInstanceState(Parcelable state) {
        Bundle savedState = (Bundle) state;
        super.onRestoreInstanceState(savedState.getParcelable(KEY_SAVED_STATE_SUPER));

        mLayoutAlgorithm.setFocusState(savedState.getFloat(KEY_SAVED_STATE_LAYOUT_FOCUSED_STATE));
        mStackScroller.setStackScroll(savedState.getFloat(KEY_SAVED_STATE_LAYOUT_STACK_SCROLL));
    }

    @Override
    public CharSequence getAccessibilityClassName() {
        return TaskStackView.class.getName();