Merge "Disables the Gesture nav option if 3P launcher is default" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cad67cdc0a
@@ -21,6 +21,10 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVE
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
|
||||
|
||||
import static com.android.settings.widget.RadioButtonPreferenceWithExtraWidget.EXTRA_WIDGET_VISIBILITY_GONE;
|
||||
import static com.android.settings.widget.RadioButtonPreferenceWithExtraWidget.EXTRA_WIDGET_VISIBILITY_INFO;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -29,7 +33,6 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -41,6 +44,7 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
import com.android.settings.widget.RadioButtonPreference;
|
||||
import com.android.settings.widget.RadioButtonPreferenceWithExtraWidget;
|
||||
import com.android.settings.widget.VideoPreference;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
@@ -94,8 +98,25 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addStaticPreferences(PreferenceScreen screen) {
|
||||
public void updateCandidates() {
|
||||
final String defaultKey = getDefaultKey();
|
||||
final String systemDefaultKey = getSystemDefaultKey();
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
screen.removeAll();
|
||||
screen.addPreference(mVideoPreference);
|
||||
|
||||
final List<? extends CandidateInfo> candidateList = getCandidates();
|
||||
if (candidateList == null) {
|
||||
return;
|
||||
}
|
||||
for (CandidateInfo info : candidateList) {
|
||||
RadioButtonPreferenceWithExtraWidget pref =
|
||||
new RadioButtonPreferenceWithExtraWidget(getPrefContext());
|
||||
bindPreference(pref, info.getKey(), info, defaultKey);
|
||||
bindPreferenceExtra(pref, info.getKey(), info, defaultKey, systemDefaultKey);
|
||||
screen.addPreference(pref);
|
||||
}
|
||||
mayCheckOnlyRadioButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,6 +156,13 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment {
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
final Context c = getContext();
|
||||
if (key == KEY_SYSTEM_NAV_GESTURAL &&
|
||||
!SystemNavigationPreferenceController.isGestureNavSupportedByDefaultLauncher(c)) {
|
||||
// This should not happen since the preference is disabled. Return to be safe.
|
||||
return false;
|
||||
}
|
||||
|
||||
setCurrentSystemNavigationMode(mOverlayManager, key);
|
||||
setIllustrationVideo(mVideoPreference, key);
|
||||
return true;
|
||||
@@ -196,10 +224,36 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment {
|
||||
@Override
|
||||
public void bindPreferenceExtra(RadioButtonPreference pref,
|
||||
String key, CandidateInfo info, String defaultKey, String systemDefaultKey) {
|
||||
if (info instanceof NavModeCandidateInfo) {
|
||||
pref.setSummary(((NavModeCandidateInfo) info).loadSummary());
|
||||
pref.setAppendixVisibility(View.GONE);
|
||||
if (!(info instanceof NavModeCandidateInfo)
|
||||
|| !(pref instanceof RadioButtonPreferenceWithExtraWidget)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pref.setSummary(((NavModeCandidateInfo) info).loadSummary());
|
||||
|
||||
RadioButtonPreferenceWithExtraWidget p = (RadioButtonPreferenceWithExtraWidget) pref;
|
||||
if (info.getKey() == KEY_SYSTEM_NAV_GESTURAL
|
||||
&& !SystemNavigationPreferenceController.isGestureNavSupportedByDefaultLauncher(
|
||||
getContext())) {
|
||||
p.setEnabled(false);
|
||||
p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_INFO);
|
||||
p.setExtraWidgetOnClickListener((v) -> {
|
||||
showGestureNavDisabledDialog();
|
||||
});
|
||||
} else {
|
||||
p.setExtraWidgetVisibility(EXTRA_WIDGET_VISIBILITY_GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void showGestureNavDisabledDialog() {
|
||||
final String defaultHomeAppName = SystemNavigationPreferenceController
|
||||
.getDefaultHomeAppName(getContext());
|
||||
final String message = getString(R.string.gesture_not_supported_dialog_message,
|
||||
defaultHomeAppName);
|
||||
AlertDialog d = new AlertDialog.Builder(getContext())
|
||||
.setMessage(message)
|
||||
.setPositiveButton(R.string.okay, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
static class NavModeCandidateInfo extends CandidateInfo {
|
||||
|
@@ -22,11 +22,14 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SystemNavigationPreferenceController extends BasePreferenceController {
|
||||
|
||||
static final String PREF_KEY_SYSTEM_NAVIGATION = "gesture_system_navigation";
|
||||
@@ -98,4 +101,31 @@ public class SystemNavigationPreferenceController extends BasePreferenceControll
|
||||
return NAV_BAR_MODE_GESTURAL == context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_navBarInteractionMode);
|
||||
}
|
||||
|
||||
static boolean isGestureNavSupportedByDefaultLauncher(Context context) {
|
||||
final ComponentName cn = context.getPackageManager().getHomeActivities(new ArrayList<>());
|
||||
if (cn == null) {
|
||||
// There is no default home app set for the current user, don't make any changes yet.
|
||||
return true;
|
||||
}
|
||||
ComponentName recentsComponentName = ComponentName.unflattenFromString(context.getString(
|
||||
com.android.internal.R.string.config_recentsComponentName));
|
||||
return recentsComponentName.getPackageName().equals(cn.getPackageName());
|
||||
}
|
||||
|
||||
static String getDefaultHomeAppName(Context context) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
final ComponentName cn = pm.getHomeActivities(new ArrayList<>());
|
||||
if (cn != null) {
|
||||
try {
|
||||
ApplicationInfo ai = pm.getApplicationInfo(cn.getPackageName(), 0);
|
||||
if (ai != null) {
|
||||
return pm.getApplicationLabel(ai).toString();
|
||||
}
|
||||
} catch (final PackageManager.NameNotFoundException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RadioButtonPreferenceWithExtraWidget extends RadioButtonPreference {
|
||||
public static final int EXTRA_WIDGET_VISIBILITY_GONE = 0;
|
||||
public static final int EXTRA_WIDGET_VISIBILITY_INFO = 1;
|
||||
|
||||
private View mExtraWidgetDivider;
|
||||
private ImageView mExtraWidget;
|
||||
|
||||
private int mExtraWidgetVisibility = EXTRA_WIDGET_VISIBILITY_GONE;
|
||||
private View.OnClickListener mExtraWidgetOnClickListener;
|
||||
|
||||
public RadioButtonPreferenceWithExtraWidget(Context context) {
|
||||
super(context, null);
|
||||
setLayoutResource(R.layout.preference_radio_with_extra_widget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
|
||||
mExtraWidget = (ImageView) view.findViewById(R.id.radio_extra_widget);
|
||||
mExtraWidgetDivider = view.findViewById(R.id.radio_extra_widget_divider);
|
||||
setExtraWidgetVisibility(mExtraWidgetVisibility);
|
||||
|
||||
if (mExtraWidgetOnClickListener != null) {
|
||||
setExtraWidgetOnClickListener(mExtraWidgetOnClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void setExtraWidgetVisibility(int visibility) {
|
||||
mExtraWidgetVisibility = visibility;
|
||||
if (mExtraWidget == null || mExtraWidgetDivider == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (visibility == EXTRA_WIDGET_VISIBILITY_GONE) {
|
||||
mExtraWidget.setClickable(false);
|
||||
mExtraWidget.setVisibility(View.GONE);
|
||||
mExtraWidgetDivider.setVisibility(View.GONE);
|
||||
} else {
|
||||
mExtraWidget.setClickable(true);
|
||||
mExtraWidget.setVisibility(View.VISIBLE);
|
||||
mExtraWidgetDivider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setExtraWidgetOnClickListener(View.OnClickListener listener) {
|
||||
mExtraWidgetOnClickListener = listener;
|
||||
if (mExtraWidget != null) {
|
||||
mExtraWidget.setEnabled(true);
|
||||
mExtraWidget.setOnClickListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user