Change Magnification Mode Settings UI
To support new settings UI, we change the UI from scrollview to listview to simplify UI initialization. Bug: 182118397 Test: atest MagnificationSettingsFragmentTest and manual test. Change-Id: Ib65dc139ba54f2281e5cb7e2dc55b3574ad2c733
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.ItemInfoArrayAdapter.ItemInfo;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
@@ -29,15 +31,20 @@ import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
@@ -47,6 +54,8 @@ import com.android.settings.utils.AnnotationSpan;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for creating the edit dialog.
|
||||
@@ -61,15 +70,13 @@ public class AccessibilityEditDialogUtils {
|
||||
@IntDef({
|
||||
DialogType.EDIT_SHORTCUT_GENERIC,
|
||||
DialogType.EDIT_SHORTCUT_MAGNIFICATION,
|
||||
DialogType.EDIT_MAGNIFICATION_MODE,
|
||||
DialogType.EDIT_MAGNIFICATION_SWITCH_SHORTCUT,
|
||||
})
|
||||
|
||||
private @interface DialogType {
|
||||
int EDIT_SHORTCUT_GENERIC = 0;
|
||||
int EDIT_SHORTCUT_MAGNIFICATION = 1;
|
||||
int EDIT_MAGNIFICATION_MODE = 2;
|
||||
int EDIT_MAGNIFICATION_SWITCH_SHORTCUT = 3;
|
||||
int EDIT_MAGNIFICATION_SWITCH_SHORTCUT = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,23 +113,6 @@ public class AccessibilityEditDialogUtils {
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to show the magnification mode dialog in Magnification.
|
||||
*
|
||||
* @param context A valid context
|
||||
* @param dialogTitle The title of magnify mode dialog
|
||||
* @param listener The listener to determine the action of magnify mode dialog
|
||||
* @return A magnification mode dialog in Magnification
|
||||
*/
|
||||
public static AlertDialog showMagnificationModeDialog(Context context,
|
||||
CharSequence dialogTitle, DialogInterface.OnClickListener listener) {
|
||||
final AlertDialog alertDialog = createDialog(context,
|
||||
DialogType.EDIT_MAGNIFICATION_MODE, dialogTitle, listener);
|
||||
alertDialog.show();
|
||||
setScrollIndicators(alertDialog);
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to show the magnification edit shortcut dialog in Magnification.
|
||||
*
|
||||
@@ -163,11 +153,21 @@ public class AccessibilityEditDialogUtils {
|
||||
*/
|
||||
private static void setScrollIndicators(AlertDialog dialog) {
|
||||
final ScrollView scrollView = dialog.findViewById(R.id.container_layout);
|
||||
scrollView.setScrollIndicators(
|
||||
setScrollIndicators(scrollView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scroll indicators for dialog view. The indicators appear while content view is
|
||||
* out of vision for vertical scrolling.
|
||||
*
|
||||
* @param view The view contains customized dialog content. Usually it is {@link ScrollView} or
|
||||
* {@link AbsListView}
|
||||
*/
|
||||
private static void setScrollIndicators(@NonNull View view) {
|
||||
view.setScrollIndicators(
|
||||
View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM,
|
||||
View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM);
|
||||
}
|
||||
|
||||
private static void setEditShortcutButtonsListener(AlertDialog dialog,
|
||||
View.OnClickListener listener) {
|
||||
final View contentView = dialog.findViewById(R.id.container_layout);
|
||||
@@ -212,12 +212,6 @@ public class AccessibilityEditDialogUtils {
|
||||
initMagnifyShortcut(context, contentView);
|
||||
initAdvancedWidget(contentView);
|
||||
break;
|
||||
case DialogType.EDIT_MAGNIFICATION_MODE:
|
||||
contentView = inflater.inflate(
|
||||
R.layout.accessibility_edit_magnification_mode, null);
|
||||
initMagnifyFullScreen(context, contentView);
|
||||
initMagnifyWindowScreen(context, contentView);
|
||||
break;
|
||||
case DialogType.EDIT_MAGNIFICATION_SWITCH_SHORTCUT:
|
||||
contentView = inflater.inflate(
|
||||
R.layout.accessibility_edit_magnification_shortcut, null);
|
||||
@@ -229,25 +223,6 @@ public class AccessibilityEditDialogUtils {
|
||||
return contentView;
|
||||
}
|
||||
|
||||
private static void initMagnifyFullScreen(Context context, View view) {
|
||||
final View dialogView = view.findViewById(R.id.magnify_full_screen);
|
||||
final CharSequence title = context.getText(
|
||||
R.string.accessibility_magnification_area_settings_full_screen);
|
||||
setupShortcutWidget(dialogView, title, R.drawable.accessibility_magnification_full_screen);
|
||||
}
|
||||
|
||||
private static void initMagnifyWindowScreen(Context context, View view) {
|
||||
final View dialogView = view.findViewById(R.id.magnify_window_screen);
|
||||
final CharSequence title = context.getText(
|
||||
R.string.accessibility_magnification_area_settings_window_screen);
|
||||
setupShortcutWidget(dialogView, title,
|
||||
R.drawable.accessibility_magnification_window_screen);
|
||||
}
|
||||
|
||||
private static void setupShortcutWidget(View view, CharSequence titleText, int imageResId) {
|
||||
setupShortcutWidget(view, titleText, null, imageResId);
|
||||
}
|
||||
|
||||
private static void setupShortcutWidget(View view, CharSequence titleText,
|
||||
CharSequence summaryText, int imageResId) {
|
||||
final CheckBox checkBox = view.findViewById(R.id.checkbox);
|
||||
@@ -345,7 +320,6 @@ public class AccessibilityEditDialogUtils {
|
||||
spannableMessage.setSpan(
|
||||
imageSpan, indexIconStart, indexIconEnd,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
return spannableMessage;
|
||||
}
|
||||
|
||||
@@ -368,4 +342,52 @@ public class AccessibilityEditDialogUtils {
|
||||
typedArray.recycle();
|
||||
return colorResId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a dialog with the given view.
|
||||
*
|
||||
* @param context A valid context
|
||||
* @param dialogTitle The title of the dialog
|
||||
* @param customView The customized view
|
||||
* @param listener This listener will be invoked when the positive button in the dialog is
|
||||
* clicked
|
||||
* @return the {@link Dialog} with the given view
|
||||
*/
|
||||
public static Dialog createCustomDialog(Context context, CharSequence dialogTitle,
|
||||
View customView, DialogInterface.OnClickListener listener) {
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(context)
|
||||
.setView(customView)
|
||||
.setTitle(dialogTitle)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.save, listener)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create();
|
||||
if (customView instanceof ScrollView || customView instanceof AbsListView) {
|
||||
setScrollIndicators(customView);
|
||||
}
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a single choice {@link ListView} with given {@link ItemInfo} list.
|
||||
*
|
||||
* @param context A context.
|
||||
* @param itemInfoList A {@link ItemInfo} list.
|
||||
* @param itemListener The listener will be invoked when the item is clicked.
|
||||
*/
|
||||
@NonNull
|
||||
public static ListView createSingleChoiceListView(@NonNull Context context,
|
||||
@NonNull List<? extends ItemInfo> itemInfoList,
|
||||
@Nullable AdapterView.OnItemClickListener itemListener) {
|
||||
final ListView list = new ListView(context);
|
||||
// Set an id to save its state.
|
||||
list.setId(android.R.id.list);
|
||||
list.setDivider(/* divider= */ null);
|
||||
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
final ItemInfoArrayAdapter
|
||||
adapter = new ItemInfoArrayAdapter(context, itemInfoList);
|
||||
list.setAdapter(adapter);
|
||||
list.setOnItemClickListener(itemListener);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user