Merge "Removing code duplication for getting swipe-up setting" into ub-launcher3-master

This commit is contained in:
TreeHugger Robot
2018-08-09 19:49:20 +00:00
committed by Android (Google) Code Review
4 changed files with 59 additions and 35 deletions

View File

@@ -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)) {

View 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);
}
}