Fix initialization error in LauncherState

This commit is contained in:
paphonb
2019-06-28 11:05:31 +07:00
parent 9e0a1b22f9
commit a2b3ba962f
3 changed files with 14 additions and 24 deletions

View File

@@ -20,6 +20,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import ch.deletescape.lawnchair.LawnchairLauncher;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager;
@@ -50,7 +51,7 @@ public class BackButtonAlphaHandler implements LauncherStateManager.StateHandler
return;
}
float fromAlpha = mOverviewInteractionState.getBackButtonAlpha();
float toAlpha = toState.hideBackButton ? 0 : 1;
float toAlpha = toState.hideBackButton && !UiFactory.hasBackGesture(mLauncher) ? 0 : 1;
if (Float.compare(fromAlpha, toAlpha) != 0) {
ValueAnimator anim = ValueAnimator.ofFloat(fromAlpha, toAlpha);
anim.setDuration(config.duration);

View File

@@ -107,7 +107,8 @@ public class UiFactory {
public static void onLauncherStateOrFocusChanged(Launcher launcher) {
boolean shouldBackButtonBeHidden = launcher != null
&& launcher.getStateManager().getState().hideBackButton
&& launcher.hasWindowFocus();
&& launcher.hasWindowFocus()
&& !hasBackGesture(launcher);
if (shouldBackButtonBeHidden) {
// Show the back button if there is a floating view visible.
shouldBackButtonBeHidden = AbstractFloatingView.getTopOpenViewWithType(launcher,
@@ -117,6 +118,14 @@ public class UiFactory {
.setBackButtonAlpha(shouldBackButtonBeHidden ? 0 : 1, true /* animate */);
}
public static boolean hasBackGesture(Launcher launcher) {
if (launcher instanceof LawnchairLauncher) {
return ((LawnchairLauncher) launcher).getGestureController().getHasBackGesture();
} else {
return false;
}
}
public static void resetOverview(Launcher launcher) {
RecentsView recents = launcher.getOverviewPanel();
recents.reset();

View File

@@ -25,8 +25,6 @@ import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
import android.graphics.Rect;
import android.view.animation.Interpolator;
import ch.deletescape.lawnchair.LawnchairLauncher;
import ch.deletescape.lawnchair.LawnchairPreferences;
import ch.deletescape.lawnchair.states.HomeState;
import ch.deletescape.lawnchair.states.OptionsState;
import com.android.launcher3.states.SpringLoadedState;
@@ -37,13 +35,12 @@ import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;
/**
* Base state for various states used for the Launcher
*/
public class LauncherState implements LawnchairPreferences.OnPreferenceChangeListener {
public class LauncherState {
/**
@@ -155,12 +152,10 @@ public class LauncherState implements LawnchairPreferences.OnPreferenceChangeLis
* True if the back button should be hidden when in this state (assuming no floating views are
* open, launcher has window focus, etc).
*/
public boolean hideBackButton;
public final boolean hideBackButton;
public final boolean hasSysUiScrim;
private LawnchairLauncher mLauncher;
public LauncherState(int id, int containerType, int transitionDuration, int flags) {
this.containerType = containerType;
this.transitionDuration = transitionDuration;
@@ -178,25 +173,10 @@ public class LauncherState implements LawnchairPreferences.OnPreferenceChangeLis
this.hideBackButton = (flags & FLAG_HIDE_BACK_BUTTON) != 0;
this.hasSysUiScrim = (flags & FLAG_HAS_SYS_UI_SCRIM) != 0;
if (id == 0 && hideBackButton) {
mLauncher = ((LawnchairLauncher) LauncherAppState.getInstanceNoCreate()
.getLauncher());
Utilities.getLawnchairPrefs(mLauncher)
.addOnPreferenceChangeListener("pref_gesture_press_back", this);
}
this.ordinal = id;
sAllStates[id] = this;
}
@Override
public void onValueChanged(@NotNull String key, @NotNull LawnchairPreferences prefs,
boolean force) {
if ("pref_gesture_press_back".equals(key)) {
hideBackButton = !mLauncher.getGestureController().getHasBackGesture();
}
}
public static LauncherState[] values() {
return Arrays.copyOf(sAllStates, sAllStates.length);
}