mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
Merge "Removing code duplication for getting swipe-up setting" into ub-launcher3-master
This commit is contained in:
committed by
Android (Google) Code Review
commit
431ec79c99
@@ -22,7 +22,6 @@ import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@@ -51,10 +50,6 @@ public class OverviewInteractionState {
|
||||
private static final String TAG = "OverviewFlags";
|
||||
|
||||
private static final String HAS_ENABLED_QUICKSTEP_ONCE = "launcher.has_enabled_quickstep_once";
|
||||
private static final String SWIPE_UP_SETTING_AVAILABLE_RES_NAME =
|
||||
"config_swipe_up_gesture_setting_available";
|
||||
private static final String SWIPE_UP_ENABLED_DEFAULT_RES_NAME =
|
||||
"config_swipe_up_gesture_default";
|
||||
|
||||
// We do not need any synchronization for this variable as its only written on UI thread.
|
||||
public static final MainThreadInitializedObject<OverviewInteractionState> INSTANCE =
|
||||
@@ -88,13 +83,13 @@ public class OverviewInteractionState {
|
||||
mUiHandler = new Handler(this::handleUiMessage);
|
||||
mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage);
|
||||
|
||||
if (getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME)) {
|
||||
if (SwipeUpSetting.isSwipeUpSettingAvailable()) {
|
||||
mSwipeUpSettingObserver = new SwipeUpGestureEnabledSettingObserver(mUiHandler,
|
||||
context.getContentResolver());
|
||||
mSwipeUpSettingObserver.register();
|
||||
} else {
|
||||
mSwipeUpSettingObserver = null;
|
||||
mSwipeUpEnabled = getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
|
||||
mSwipeUpEnabled = SwipeUpSetting.isSwipeUpEnabledDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +194,7 @@ public class OverviewInteractionState {
|
||||
super(handler);
|
||||
mHandler = handler;
|
||||
mResolver = resolver;
|
||||
defaultValue = getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME) ? 1 : 0;
|
||||
defaultValue = SwipeUpSetting.isSwipeUpEnabledDefaultValue() ? 1 : 0;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
@@ -221,18 +216,6 @@ public class OverviewInteractionState {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getSystemBooleanRes(String resName) {
|
||||
Resources res = Resources.getSystem();
|
||||
int resId = res.getIdentifier(resName, "bool", "android");
|
||||
|
||||
if (resId != 0) {
|
||||
return res.getBoolean(resId);
|
||||
} else {
|
||||
Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void resetHomeBounceSeenOnQuickstepEnabledFirstTime() {
|
||||
if (mSwipeUpEnabled && !Utilities.getPrefs(mContext).getBoolean(
|
||||
HAS_ENABLED_QUICKSTEP_ONCE, true)) {
|
||||
|
||||
50
quickstep/src/com/android/quickstep/SwipeUpSetting.java
Normal file
50
quickstep/src/com/android/quickstep/SwipeUpSetting.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.quickstep;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
|
||||
public final class SwipeUpSetting {
|
||||
private static final String TAG = "SwipeUpSetting";
|
||||
|
||||
private static final String SWIPE_UP_SETTING_AVAILABLE_RES_NAME =
|
||||
"config_swipe_up_gesture_setting_available";
|
||||
|
||||
private static final String SWIPE_UP_ENABLED_DEFAULT_RES_NAME =
|
||||
"config_swipe_up_gesture_default";
|
||||
|
||||
private static boolean getSystemBooleanRes(String resName) {
|
||||
Resources res = Resources.getSystem();
|
||||
int resId = res.getIdentifier(resName, "bool", "android");
|
||||
|
||||
if (resId != 0) {
|
||||
return res.getBoolean(resId);
|
||||
} else {
|
||||
Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSwipeUpSettingAvailable() {
|
||||
return getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME);
|
||||
}
|
||||
|
||||
public static boolean isSwipeUpEnabledDefaultValue() {
|
||||
return getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ include $(BUILD_PACKAGE)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, tapl)
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, tapl) \
|
||||
../quickstep/src/com/android/quickstep/SwipeUpSetting.java
|
||||
|
||||
LOCAL_SDK_VERSION := current
|
||||
LOCAL_MODULE := ub-launcher-aosp-tapl
|
||||
|
||||
@@ -22,7 +22,6 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.UiAutomation;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -35,6 +34,8 @@ import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.Until;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.android.quickstep.SwipeUpSetting;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@@ -78,10 +79,6 @@ public final class LauncherInstrumentation {
|
||||
private static final String WIDGETS_RES_ID = "widgets_list_view";
|
||||
static final String LAUNCHER_PKG = "com.google.android.apps.nexuslauncher";
|
||||
static final int WAIT_TIME_MS = 60000;
|
||||
private static final String SWIPE_UP_SETTING_AVAILABLE_RES_NAME =
|
||||
"config_swipe_up_gesture_setting_available";
|
||||
private static final String SWIPE_UP_ENABLED_DEFAULT_RES_NAME =
|
||||
"config_swipe_up_gesture_default";
|
||||
private static final String SYSTEMUI_PACKAGE = "com.android.systemui";
|
||||
|
||||
private static WeakReference<VisibleContainer> sActiveContainer = new WeakReference<>(null);
|
||||
@@ -95,8 +92,8 @@ public final class LauncherInstrumentation {
|
||||
public LauncherInstrumentation(UiDevice device) {
|
||||
mDevice = device;
|
||||
final boolean swipeUpEnabledDefault =
|
||||
!getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME) ||
|
||||
getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
|
||||
!SwipeUpSetting.isSwipeUpSettingAvailable() ||
|
||||
SwipeUpSetting.isSwipeUpEnabledDefaultValue();
|
||||
mSwipeUpEnabled = Settings.Secure.getInt(
|
||||
InstrumentationRegistry.getTargetContext().getContentResolver(),
|
||||
"swipe_up_to_switch_apps_enabled",
|
||||
@@ -104,13 +101,6 @@ public final class LauncherInstrumentation {
|
||||
assertTrue("Device must run in a test harness", ActivityManager.isRunningInTestHarness());
|
||||
}
|
||||
|
||||
private boolean getSystemBooleanRes(String resName) {
|
||||
final Resources res = Resources.getSystem();
|
||||
final int resId = res.getIdentifier(resName, "bool", "android");
|
||||
assertTrue("Resource not found: " + resName, resId != 0);
|
||||
return res.getBoolean(resId);
|
||||
}
|
||||
|
||||
void setActiveContainer(VisibleContainer container) {
|
||||
sActiveContainer = new WeakReference<>(container);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user