Fix various java warnings

Change-Id: I4c4381e1755831df2c4f41279800fd6af173e4ed
This commit is contained in:
Oliver Scott
2024-01-10 18:39:27 -05:00
committed by Michael Bestas
parent 7664461e5f
commit fd0fdb8a49
23 changed files with 156 additions and 444 deletions

View File

@@ -31,7 +31,6 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
@@ -61,11 +60,6 @@ public abstract class BaseSetupWizardActivity extends AppCompatActivity implemen
public static final String TAG = BaseSetupWizardActivity.class.getSimpleName(); public static final String TAG = BaseSetupWizardActivity.class.getSimpleName();
protected static final int TRANSITION_ID_NONE = -1;
protected static final int TRANSITION_ID_DEFAULT = 1;
protected static final int TRANSITION_ID_SLIDE = 2;
protected static final int TRANSITION_ID_FADE = 3;
private NavigationLayout mNavigationBar; private NavigationLayout mNavigationBar;
private final BroadcastReceiver finishReceiver = new BroadcastReceiver() { private final BroadcastReceiver finishReceiver = new BroadcastReceiver() {
@@ -204,13 +198,6 @@ public abstract class BaseSetupWizardActivity extends AppCompatActivity implemen
} }
} }
protected boolean isNextAllowed() {
if (mNavigationBar != null) {
mNavigationBar.getNextButton().isEnabled();
}
return false;
}
protected void onNextPressed() { protected void onNextPressed() {
nextAction(RESULT_OK); nextAction(RESULT_OK);
} }
@@ -242,10 +229,6 @@ public abstract class BaseSetupWizardActivity extends AppCompatActivity implemen
} }
} }
public void onNavigateBack() {
getOnBackPressedDispatcher().onBackPressed();
}
public void onNavigateNext() { public void onNavigateNext() {
onNextPressed(); onNextPressed();
} }
@@ -337,44 +320,6 @@ public abstract class BaseSetupWizardActivity extends AppCompatActivity implemen
} }
} }
protected final void applyForwardTransition(int transitionId) {
if (transitionId == TRANSITION_ID_SLIDE) {
overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, R.anim.sud_slide_next_in,
R.anim.sud_slide_next_out);
} else if (transitionId == TRANSITION_ID_FADE) {
overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, android.R.anim.fade_in,
android.R.anim.fade_out);
} else if (transitionId == TRANSITION_ID_DEFAULT) {
TypedArray typedArray = obtainStyledAttributes(android.R.style.Animation_Activity,
new int[]{android.R.attr.activityOpenEnterAnimation,
android.R.attr.activityOpenExitAnimation});
overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, typedArray.getResourceId(0, 0),
typedArray.getResourceId(1, 0));
typedArray.recycle();
} else if (transitionId == TRANSITION_ID_NONE) {
overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, 0, 0);
}
}
protected final void applyBackwardTransition(int transitionId) {
if (transitionId == TRANSITION_ID_SLIDE) {
overrideActivityTransition(OVERRIDE_TRANSITION_CLOSE, R.anim.sud_slide_back_in,
R.anim.sud_slide_back_out);
} else if (transitionId == TRANSITION_ID_FADE) {
overrideActivityTransition(OVERRIDE_TRANSITION_CLOSE, android.R.anim.fade_in,
android.R.anim.fade_out);
} else if (transitionId == TRANSITION_ID_DEFAULT) {
TypedArray typedArray = obtainStyledAttributes(android.R.style.Animation_Activity,
new int[]{android.R.attr.activityCloseEnterAnimation,
android.R.attr.activityCloseExitAnimation});
overrideActivityTransition(OVERRIDE_TRANSITION_CLOSE, typedArray.getResourceId(0, 0),
typedArray.getResourceId(1, 0));
typedArray.recycle();
} else if (transitionId == TRANSITION_ID_NONE) {
overrideActivityTransition(OVERRIDE_TRANSITION_CLOSE, 0, 0);
}
}
protected final boolean tryEnablingWifi() { protected final boolean tryEnablingWifi() {
WifiManager wifiManager = getSystemService(WifiManager.class); WifiManager wifiManager = getSystemService(WifiManager.class);
return wifiManager.setWifiEnabled(true); return wifiManager.setWifiEnabled(true);

View File

@@ -23,8 +23,6 @@ import android.content.Intent;
public class BiometricActivity extends SubBaseActivity { public class BiometricActivity extends SubBaseActivity {
public static final String TAG = BiometricActivity.class.getSimpleName();
@Override @Override
protected void onStartSubactivity() { protected void onStartSubactivity() {
Intent intent = new Intent(ACTION_SETUP_BIOMETRIC); Intent intent = new Intent(ACTION_SETUP_BIOMETRIC);

View File

@@ -37,6 +37,7 @@ import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import com.android.settingslib.datetime.ZoneGetter; import com.android.settingslib.datetime.ZoneGetter;
@@ -44,7 +45,6 @@ import com.android.settingslib.datetime.ZoneGetter;
import org.lineageos.setupwizard.util.SetupWizardUtils; import org.lineageos.setupwizard.util.SetupWizardUtils;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -53,15 +53,10 @@ import java.util.TimeZone;
public class DateTimeActivity extends BaseSetupWizardActivity implements public class DateTimeActivity extends BaseSetupWizardActivity implements
TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener { TimePickerDialog.OnTimeSetListener, DatePickerDialog.OnDateSetListener {
public static final String TAG = DateTimeActivity.class.getSimpleName();
private static final String KEY_ID = "id"; // value: String private static final String KEY_ID = "id"; // value: String
private static final String KEY_DISPLAYNAME = "name"; // value: String private static final String KEY_DISPLAYNAME = "name"; // value: String
private static final String KEY_GMT = "gmt"; // value: String private static final String KEY_GMT = "gmt"; // value: String
private static final String KEY_OFFSET = "offset"; // value: int (Integer) private static final String KEY_OFFSET = "offset"; // value: int (Integer)
private static final String XMLTAG_TIMEZONE = "timezone";
private static final int HOURS_1 = 60 * 60000;
private TimeZone mCurrentTimeZone; private TimeZone mCurrentTimeZone;
private TextView mDateTextView; private TextView mDateTextView;
@@ -207,14 +202,13 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
final TimeZoneComparator comparator = new TimeZoneComparator(KEY_OFFSET); final TimeZoneComparator comparator = new TimeZoneComparator(KEY_OFFSET);
final List<Map<String, Object>> sortedList = ZoneGetter.getZonesList(context); final List<Map<String, Object>> sortedList = ZoneGetter.getZonesList(context);
Collections.sort(sortedList, comparator); sortedList.sort(comparator);
final SimpleAdapter adapter = new SimpleAdapter(context,
return new SimpleAdapter(context,
sortedList, sortedList,
R.layout.date_time_setup_custom_list_item_2, R.layout.date_time_setup_custom_list_item_2,
from, from,
to); to);
return adapter;
} }
private static int getTimeZoneIndex(SimpleAdapter adapter, TimeZone tz) { private static int getTimeZoneIndex(SimpleAdapter adapter, TimeZone tz) {
@@ -259,16 +253,12 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
} }
private static class TimeZoneComparator implements Comparator<Map<?, ?>> { private static class TimeZoneComparator implements Comparator<Map<?, ?>> {
private String mSortingKey; private final String mSortingKey;
public TimeZoneComparator(String sortingKey) { public TimeZoneComparator(String sortingKey) {
mSortingKey = sortingKey; mSortingKey = sortingKey;
} }
public void setSortingKey(String sortingKey) {
mSortingKey = sortingKey;
}
public int compare(Map<?, ?> map1, Map<?, ?> map2) { public int compare(Map<?, ?> map1, Map<?, ?> map2) {
Object value1 = map1.get(mSortingKey); Object value1 = map1.get(mSortingKey);
Object value2 = map2.get(mSortingKey); Object value2 = map2.get(mSortingKey);
@@ -287,7 +277,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
} }
private boolean isComparable(Object value) { private boolean isComparable(Object value) {
return (value != null) && (value instanceof Comparable); return (value instanceof Comparable);
} }
} }
@@ -297,8 +287,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
private static final String TAG = TimePickerFragment.class.getSimpleName(); private static final String TAG = TimePickerFragment.class.getSimpleName();
public static TimePickerFragment newInstance() { public static TimePickerFragment newInstance() {
TimePickerFragment frag = new TimePickerFragment(); return new TimePickerFragment();
return frag;
} }
@Override @Override
@@ -306,6 +295,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
((DateTimeActivity) getActivity()).onTimeSet(view, hourOfDay, minute); ((DateTimeActivity) getActivity()).onTimeSet(view, hourOfDay, minute);
} }
@NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();
@@ -324,8 +314,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
private static final String TAG = DatePickerFragment.class.getSimpleName(); private static final String TAG = DatePickerFragment.class.getSimpleName();
public static DatePickerFragment newInstance() { public static DatePickerFragment newInstance() {
DatePickerFragment frag = new DatePickerFragment(); return new DatePickerFragment();
return frag;
} }
@Override @Override
@@ -333,6 +322,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
((DateTimeActivity) getActivity()).onDateSet(view, year, month, day); ((DateTimeActivity) getActivity()).onDateSet(view, year, month, day);
} }
@NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();

View File

@@ -81,7 +81,7 @@ public class FinishActivity extends BaseSetupWizardActivity {
if (LOGV) { if (LOGV) {
Log.v(TAG, "onReceive intent=" + intent); Log.v(TAG, "onReceive intent=" + intent);
} }
if (intent != null && intent.getAction() == ACTION_FINISHED) { if (intent != null && intent.getAction().equals(ACTION_FINISHED)) {
unregisterReceiver(mIntentReceiver); unregisterReceiver(mIntentReceiver);
completeSetup(); completeSetup();
} }
@@ -96,7 +96,7 @@ public class FinishActivity extends BaseSetupWizardActivity {
logActivityState("onCreate savedInstanceState=" + savedInstanceState); logActivityState("onCreate savedInstanceState=" + savedInstanceState);
} }
mSetupWizardApp = (SetupWizardApp) getApplication(); mSetupWizardApp = (SetupWizardApp) getApplication();
mBackground = (ImageView) findViewById(R.id.background); mBackground = findViewById(R.id.background);
setNextText(R.string.start); setNextText(R.string.start);
// Edge-to-edge. Needed for the background view to fill the full screen. // Edge-to-edge. Needed for the background view to fill the full screen.
@@ -231,7 +231,7 @@ public class FinishActivity extends BaseSetupWizardActivity {
try { try {
overlayManager.setEnabledExclusiveInCategory(selectedNavMode, USER_CURRENT); overlayManager.setEnabledExclusiveInCategory(selectedNavMode, USER_CURRENT);
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
} }

View File

@@ -34,8 +34,6 @@ import lineageos.providers.LineageSettings;
public class LineageSettingsActivity extends BaseSetupWizardActivity { public class LineageSettingsActivity extends BaseSetupWizardActivity {
public static final String TAG = LineageSettingsActivity.class.getSimpleName();
private SetupWizardApp mSetupWizardApp; private SetupWizardApp mSetupWizardApp;
private CheckBox mMetrics; private CheckBox mMetrics;

View File

@@ -51,8 +51,6 @@ import java.util.concurrent.Executors;
public class LocaleActivity extends BaseSetupWizardActivity { public class LocaleActivity extends BaseSetupWizardActivity {
public static final String TAG = LocaleActivity.class.getSimpleName();
private ArrayAdapter<com.android.internal.app.LocalePicker.LocaleInfo> mLocaleAdapter; private ArrayAdapter<com.android.internal.app.LocalePicker.LocaleInfo> mLocaleAdapter;
private Locale mCurrentLocale; private Locale mCurrentLocale;
private int[] mAdapterIndices; private int[] mAdapterIndices;
@@ -89,9 +87,7 @@ public class LocaleActivity extends BaseSetupWizardActivity {
mLanguagePicker.setNextRight(getNextButton().getId()); mLanguagePicker.setNextRight(getNextButton().getId());
mLanguagePicker.requestFocus(); mLanguagePicker.requestFocus();
if (getResources().getBoolean(R.bool.config_isLargeNoTouch)) { if (getResources().getBoolean(R.bool.config_isLargeNoTouch)) {
mLanguagePicker.setOnClickListener((View v) -> { mLanguagePicker.setOnClickListener((View v) -> getNextButton().performClick());
getNextButton().performClick();
});
} }
loadLanguages(); loadLanguages();
} }

View File

@@ -27,9 +27,6 @@ import android.widget.CheckBox;
public class LocationSettingsActivity extends BaseSetupWizardActivity { public class LocationSettingsActivity extends BaseSetupWizardActivity {
public static final String TAG =
LocationSettingsActivity.class.getSimpleName().substring(0, 22);
private CheckBox mLocationAccess; private CheckBox mLocationAccess;
private CheckBox mLocationAgpsAccess; private CheckBox mLocationAgpsAccess;
@@ -47,14 +44,12 @@ public class LocationSettingsActivity extends BaseSetupWizardActivity {
mLocationManager = getSystemService(LocationManager.class); mLocationManager = getSystemService(LocationManager.class);
mUserManager = getSystemService(UserManager.class); mUserManager = getSystemService(UserManager.class);
View locationAccessView = findViewById(R.id.location); View locationAccessView = findViewById(R.id.location);
locationAccessView.setOnClickListener(v -> { locationAccessView.setOnClickListener(
mLocationAccess.setChecked(!mLocationAccess.isChecked()); v -> mLocationAccess.setChecked(!mLocationAccess.isChecked()));
});
View locationAgpsAccessView = findViewById(R.id.location_agps); View locationAgpsAccessView = findViewById(R.id.location_agps);
if (mUserManager.isMainUser()) { if (mUserManager.isMainUser()) {
locationAgpsAccessView.setOnClickListener(v -> { locationAgpsAccessView.setOnClickListener(
mLocationAgpsAccess.setChecked(!mLocationAgpsAccess.isChecked()); v -> mLocationAgpsAccess.setChecked(!mLocationAgpsAccess.isChecked()));
});
} else { } else {
locationAgpsAccessView.setVisibility(View.GONE); locationAgpsAccessView.setVisibility(View.GONE);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The LineageOS Project * Copyright (C) 2021-2024 The LineageOS Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -31,8 +31,6 @@ public class NavigationLayout extends RelativeLayout {
* namely when the user clicks on the back or next button. * namely when the user clicks on the back or next button.
*/ */
public interface NavigationBarListener { public interface NavigationBarListener {
void onNavigateBack();
void onNavigateNext(); void onNavigateNext();
void onSkip(); void onSkip();

View File

@@ -34,7 +34,6 @@ import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import com.airbnb.lottie.LottieAnimationView; import com.airbnb.lottie.LottieAnimationView;
@@ -44,8 +43,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils;
public class NavigationSettingsActivity extends BaseSetupWizardActivity { public class NavigationSettingsActivity extends BaseSetupWizardActivity {
public static final String TAG = NavigationSettingsActivity.class.getSimpleName();
private SetupWizardApp mSetupWizardApp; private SetupWizardApp mSetupWizardApp;
private boolean mIsTaskbarEnabled; private boolean mIsTaskbarEnabled;

View File

@@ -30,8 +30,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils;
public class NetworkSetupActivity extends SubBaseActivity { public class NetworkSetupActivity extends SubBaseActivity {
public static final String TAG = NetworkSetupActivity.class.getSimpleName();
@Override @Override
protected void onStartSubactivity() { protected void onStartSubactivity() {
if (SetupWizardUtils.isOwner()) { if (SetupWizardUtils.isOwner()) {

View File

@@ -23,8 +23,6 @@ import android.content.Intent;
public class ScreenLockActivity extends SubBaseActivity { public class ScreenLockActivity extends SubBaseActivity {
public static final String TAG = ScreenLockActivity.class.getSimpleName();
@Override @Override
protected void onStartSubactivity() { protected void onStartSubactivity() {
Intent intent = new Intent(ACTION_SETUP_LOCKSCREEN); Intent intent = new Intent(ACTION_SETUP_LOCKSCREEN);

View File

@@ -45,9 +45,6 @@ public class SetupWizardApp extends Application {
public static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL"; public static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL";
public static final String ACTION_LOAD = "com.android.wizard.LOAD"; public static final String ACTION_LOAD = "com.android.wizard.LOAD";
public static final String EXTRA_HAS_MULTIPLE_USERS = "hasMultipleUsers";
public static final String EXTRA_TITLE = "title";
public static final String EXTRA_DETAILS = "details";
public static final String EXTRA_SCRIPT_URI = "scriptUri"; public static final String EXTRA_SCRIPT_URI = "scriptUri";
public static final String EXTRA_ACTION_ID = "actionId"; public static final String EXTRA_ACTION_ID = "actionId";
public static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode"; public static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
@@ -94,17 +91,6 @@ public class SetupWizardApp extends Application {
return sStatusBarManager; return sStatusBarManager;
} }
public boolean isRadioReady() {
return mIsRadioReady;
}
public void setRadioReady(boolean radioReady) {
if (!mIsRadioReady && radioReady) {
mHandler.removeCallbacks(mRadioTimeoutRunnable);
}
mIsRadioReady = radioReady;
}
public boolean ignoreSimLocale() { public boolean ignoreSimLocale() {
return mIgnoreSimLocale; return mIgnoreSimLocale;
} }

View File

@@ -23,8 +23,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils;
public class SimMissingActivity extends BaseSetupWizardActivity { public class SimMissingActivity extends BaseSetupWizardActivity {
public static final String TAG = SimMissingActivity.class.getSimpleName();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

View File

@@ -38,10 +38,6 @@ public abstract class SubBaseActivity extends BaseSetupWizardActivity {
protected abstract void onStartSubactivity(); protected abstract void onStartSubactivity();
protected void onSubactivityCanceled(Intent data) {
// Do nothing.
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
if (LOGV) { if (LOGV) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2023 The LineageOS Project * Copyright (C) 2023-2024 The LineageOS Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import android.widget.RadioGroup;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class ThemeSettingsActivity extends BaseSetupWizardActivity { public class ThemeSettingsActivity extends BaseSetupWizardActivity {
public static final String TAG = ThemeSettingsActivity.class.getSimpleName();
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {

View File

@@ -53,9 +53,8 @@ public class UpdateRecoveryActivity extends BaseSetupWizardActivity {
mRecoveryUpdateCheckbox = findViewById(R.id.update_recovery_checkbox); mRecoveryUpdateCheckbox = findViewById(R.id.update_recovery_checkbox);
View cbView = findViewById(R.id.update_recovery_checkbox_view); View cbView = findViewById(R.id.update_recovery_checkbox_view);
cbView.setOnClickListener(v -> { cbView.setOnClickListener(
mRecoveryUpdateCheckbox.setChecked(!mRecoveryUpdateCheckbox.isChecked()); v -> mRecoveryUpdateCheckbox.setChecked(!mRecoveryUpdateCheckbox.isChecked()));
});
// Allow overriding the default checkbox state // Allow overriding the default checkbox state
if (sFirstTime) { if (sFirstTime) {

View File

@@ -33,8 +33,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils;
public class WelcomeActivity extends SubBaseActivity { public class WelcomeActivity extends SubBaseActivity {
public static final String TAG = WelcomeActivity.class.getSimpleName();
@Override @Override
protected void onStartSubactivity() { protected void onStartSubactivity() {
} }

View File

@@ -18,7 +18,6 @@
package org.lineageos.setupwizard.util; package org.lineageos.setupwizard.util;
import static android.content.Context.MODE_PRIVATE; import static android.content.Context.MODE_PRIVATE;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.PackageManager.DONT_KILL_APP; import static android.content.pm.PackageManager.DONT_KILL_APP;
@@ -137,18 +136,6 @@ public class SetupWizardUtils {
return !featureHidden; return !featureHidden;
} }
public static boolean isRadioReady(Context context, ServiceState state) {
final SetupWizardApp setupWizardApp = (SetupWizardApp) context.getApplicationContext();
if (setupWizardApp.isRadioReady()) {
return true;
} else {
final boolean ready = state != null
&& state.getState() != ServiceState.STATE_POWER_OFF;
setupWizardApp.setRadioReady(ready);
return ready;
}
}
public static boolean isOwner() { public static boolean isOwner() {
return UserHandle.myUserId() == 0; return UserHandle.myUserId() == 0;
} }
@@ -335,7 +322,7 @@ public class SetupWizardUtils {
COMPONENT_ENABLED_STATE_DISABLED); COMPONENT_ENABLED_STATE_DISABLED);
} }
public static void disableComponent(Context context, Class cls) { public static void disableComponent(Context context, Class<?> cls) {
setComponentEnabledState(context, new ComponentName(context, cls), setComponentEnabledState(context, new ComponentName(context, cls),
COMPONENT_ENABLED_STATE_DISABLED); COMPONENT_ENABLED_STATE_DISABLED);
} }
@@ -345,16 +332,6 @@ public class SetupWizardUtils {
COMPONENT_ENABLED_STATE_ENABLED); COMPONENT_ENABLED_STATE_ENABLED);
} }
public static void resetComponentSets(Context context, int flags) {
setComponentListEnabledState(context, getComponentSets(context, flags),
COMPONENT_ENABLED_STATE_DEFAULT);
}
public static void resetComponent(Context context, Class<?> cls) {
setComponentEnabledState(context, new ComponentName(context, cls),
COMPONENT_ENABLED_STATE_DEFAULT);
}
public static void setComponentEnabledState(Context context, ComponentName componentName, public static void setComponentEnabledState(Context context, ComponentName componentName,
int enabledState) { int enabledState) {
context.getPackageManager().setComponentEnabledSetting(componentName, context.getPackageManager().setComponentEnabledSetting(componentName,
@@ -370,7 +347,7 @@ public class SetupWizardUtils {
public static List<ComponentName> getComponentSets(Context context, int flags) { public static List<ComponentName> getComponentSets(Context context, int flags) {
int i = 0; int i = 0;
List<ComponentName> componentNames = new ArrayList(); List<ComponentName> componentNames = new ArrayList<>();
try { try {
PackageInfo allInfo = context.getPackageManager() PackageInfo allInfo = context.getPackageManager()
.getPackageInfo(context.getPackageName(), flags); .getPackageInfo(context.getPackageName(), flags);
@@ -394,7 +371,7 @@ public class SetupWizardUtils {
} }
} }
} }
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException ignored) {
} }
return componentNames; return componentNames;
} }

View File

@@ -27,7 +27,6 @@ import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.icu.text.DecimalFormatSymbols;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
@@ -153,58 +152,6 @@ public class LocalePicker extends LinearLayout {
*/ */
private static final int SIZE_UNSPECIFIED = -1; private static final int SIZE_UNSPECIFIED = -1;
/**
* Use a custom NumberPicker formatting callback to use two-digit minutes strings like "01".
* Keeping a static formatter etc. is the most efficient way to do this; it avoids creating
* temporary objects on every call to format().
*/
private static class TwoDigitFormatter implements LocalePicker.Formatter {
final StringBuilder mBuilder = new StringBuilder();
char mZeroDigit;
java.util.Formatter mFmt;
final Object[] mArgs = new Object[1];
TwoDigitFormatter() {
final Locale locale = Locale.getDefault();
init(locale);
}
private void init(Locale locale) {
mFmt = createFormatter(locale);
mZeroDigit = getZeroDigit(locale);
}
public String format(int value) {
final Locale currentLocale = Locale.getDefault();
if (mZeroDigit != getZeroDigit(currentLocale)) {
init(currentLocale);
}
mArgs[0] = value;
mBuilder.delete(0, mBuilder.length());
mFmt.format("%02d", mArgs);
return mFmt.toString();
}
private static char getZeroDigit(Locale locale) {
return DecimalFormatSymbols.getInstance(locale).getZeroDigit();
}
private java.util.Formatter createFormatter(Locale locale) {
return new java.util.Formatter(mBuilder, locale);
}
}
private static final TwoDigitFormatter sTwoDigitFormatter = new TwoDigitFormatter();
/**
* @hide
*/
public static Formatter getTwoDigitFormatter() {
return sTwoDigitFormatter;
}
/** /**
* The increment button. * The increment button.
*/ */
@@ -295,15 +242,10 @@ public class LocalePicker extends LinearLayout {
*/ */
private Formatter mFormatter; private Formatter mFormatter;
/**
* The speed for updating the value form long press.
*/
private long mLongPressUpdateInterval = DEFAULT_LONG_PRESS_UPDATE_INTERVAL;
/** /**
* Cache for the string representation of selector indices. * Cache for the string representation of selector indices.
*/ */
private final SparseArray<String> mSelectorIndexToStringCache = new SparseArray<String>(); private final SparseArray<String> mSelectorIndexToStringCache = new SparseArray<>();
/** /**
* The selector indices whose value are show by the selector. * The selector indices whose value are show by the selector.
@@ -674,14 +616,12 @@ public class LocalePicker extends LinearLayout {
// input text // input text
mInputText = findViewById(R.id.localepicker_input); mInputText = findViewById(R.id.localepicker_input);
mInputText.setOnFocusChangeListener(new OnFocusChangeListener() { mInputText.setOnFocusChangeListener((v, hasFocus) -> {
public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) {
if (hasFocus) { mInputText.selectAll();
mInputText.selectAll(); } else {
} else { mInputText.setSelection(0, 0);
mInputText.setSelection(0, 0); validateInputTextView(v);
validateInputTextView(v);
}
} }
}); });
mInputText.setFilters(new InputFilter[]{ mInputText.setFilters(new InputFilter[]{
@@ -803,49 +743,47 @@ public class LocalePicker extends LinearLayout {
return false; return false;
} }
final int action = event.getActionMasked(); final int action = event.getActionMasked();
switch (action) { if (action == MotionEvent.ACTION_DOWN) {
case MotionEvent.ACTION_DOWN: { removeAllCallbacks();
removeAllCallbacks(); mInputText.setVisibility(View.INVISIBLE);
mInputText.setVisibility(View.INVISIBLE); mLastDownOrMoveEventY = mLastDownEventY = event.getY();
mLastDownOrMoveEventY = mLastDownEventY = event.getY(); mLastDownEventTime = event.getEventTime();
mLastDownEventTime = event.getEventTime(); mIngonreMoveEvents = false;
mIngonreMoveEvents = false; mShowSoftInputOnTap = false;
mShowSoftInputOnTap = false; // Handle pressed state before any state change.
// Handle pressed state before any state change. if (mLastDownEventY < mTopSelectionDividerTop) {
if (mLastDownEventY < mTopSelectionDividerTop) { if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { mPressedStateHelper.buttonPressDelayed(
mPressedStateHelper.buttonPressDelayed( PressedStateHelper.BUTTON_DECREMENT);
PressedStateHelper.BUTTON_DECREMENT);
}
} else if (mLastDownEventY > mBottomSelectionDividerBottom) {
if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
mPressedStateHelper.buttonPressDelayed(
PressedStateHelper.BUTTON_INCREMENT);
}
} }
// Make sure we support flinging inside scrollables. } else if (mLastDownEventY > mBottomSelectionDividerBottom) {
getParent().requestDisallowInterceptTouchEvent(true); if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
if (!mFlingScroller.isFinished()) { mPressedStateHelper.buttonPressDelayed(
mFlingScroller.forceFinished(true); PressedStateHelper.BUTTON_INCREMENT);
mAdjustScroller.forceFinished(true);
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
} else if (!mAdjustScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
} else if (mLastDownEventY < mTopSelectionDividerTop) {
hideSoftInput();
postChangeCurrentByOneFromLongPress(
false, ViewConfiguration.getLongPressTimeout());
} else if (mLastDownEventY > mBottomSelectionDividerBottom) {
hideSoftInput();
postChangeCurrentByOneFromLongPress(
true, ViewConfiguration.getLongPressTimeout());
} else {
mShowSoftInputOnTap = true;
postBeginSoftInputOnLongPressCommand();
} }
return true;
} }
// Make sure we support flinging inside scrollables.
getParent().requestDisallowInterceptTouchEvent(true);
if (!mFlingScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
} else if (!mAdjustScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
} else if (mLastDownEventY < mTopSelectionDividerTop) {
hideSoftInput();
postChangeCurrentByOneFromLongPress(
false, ViewConfiguration.getLongPressTimeout());
} else if (mLastDownEventY > mBottomSelectionDividerBottom) {
hideSoftInput();
postChangeCurrentByOneFromLongPress(
true, ViewConfiguration.getLongPressTimeout());
} else {
mShowSoftInputOnTap = true;
postBeginSoftInputOnLongPressCommand();
}
return true;
} }
return false; return false;
} }
@@ -1127,35 +1065,15 @@ public class LocalePicker extends LinearLayout {
mOnScrollListener = onScrollListener; mOnScrollListener = onScrollListener;
} }
/**
* Set the formatter to be used for formatting the current value.
* <p>
* Note: If you have provided alternative values for the values this formatter is never
* invoked.
* </p>
*
* @param formatter The formatter object. If formatter is <code>null</code>, {@link
* String#valueOf(int)} will be used.
* @see #setDisplayedValues(String[])
*/
public void setFormatter(Formatter formatter) {
if (formatter == mFormatter) {
return;
}
mFormatter = formatter;
initializeSelectorWheelIndices();
updateInputTextView();
}
/** /**
* Set the current value for the number picker. * Set the current value for the number picker.
* <p> * <p>
* If the argument is less than the {@link LocalePicker#getMinValue()} and {@link * If the argument is less than the getMinValue() and {@link
* LocalePicker#getWrapSelectorWheel()} is <code>false</code> the current value is set to the * LocalePicker#getWrapSelectorWheel()} is <code>false</code> the current value is set to the
* {@link LocalePicker#getMinValue()} value. * getMinValue() value.
* </p> * </p>
* <p> * <p>
* If the argument is less than the {@link LocalePicker#getMinValue()} and {@link * If the argument is less than the getMinValue() and {@link
* LocalePicker#getWrapSelectorWheel()} is <code>true</code> the current value is set to the * LocalePicker#getWrapSelectorWheel()} is <code>true</code> the current value is set to the
* {@link LocalePicker#getMaxValue()} value. * {@link LocalePicker#getMaxValue()} value.
* </p> * </p>
@@ -1167,12 +1085,11 @@ public class LocalePicker extends LinearLayout {
* <p> * <p>
* If the argument is less than the {@link LocalePicker#getMaxValue()} and {@link * If the argument is less than the {@link LocalePicker#getMaxValue()} and {@link
* LocalePicker#getWrapSelectorWheel()} is <code>true</code> the current value is set to the * LocalePicker#getWrapSelectorWheel()} is <code>true</code> the current value is set to the
* {@link LocalePicker#getMinValue()} value. * getMinValue() value.
* </p> * </p>
* *
* @param value The current value. * @param value The current value.
* @see #setWrapSelectorWheel(boolean) * @see #setWrapSelectorWheel(boolean)
* @see #setMinValue(int)
* @see #setMaxValue(int) * @see #setMaxValue(int)
*/ */
public void setValue(int value) { public void setValue(int value) {
@@ -1239,8 +1156,8 @@ public class LocalePicker extends LinearLayout {
maxTextWidth = (int) (numberOfDigits * maxDigitWidth); maxTextWidth = (int) (numberOfDigits * maxDigitWidth);
} else { } else {
final int valueCount = mDisplayedValues.length; final int valueCount = mDisplayedValues.length;
for (int i = 0; i < valueCount; i++) { for (String displayedValue : mDisplayedValues) {
final float textWidth = mSelectorWheelPaint.measureText(mDisplayedValues[i]); final float textWidth = mSelectorWheelPaint.measureText(displayedValue);
if (textWidth > maxTextWidth) { if (textWidth > maxTextWidth) {
maxTextWidth = (int) textWidth; maxTextWidth = (int) textWidth;
} }
@@ -1248,11 +1165,7 @@ public class LocalePicker extends LinearLayout {
} }
maxTextWidth += mInputText.getPaddingLeft() + mInputText.getPaddingRight(); maxTextWidth += mInputText.getPaddingLeft() + mInputText.getPaddingRight();
if (mMaxWidth != maxTextWidth) { if (mMaxWidth != maxTextWidth) {
if (maxTextWidth > mMinWidth) { mMaxWidth = Math.max(maxTextWidth, mMinWidth);
mMaxWidth = maxTextWidth;
} else {
mMaxWidth = mMinWidth;
}
invalidate(); invalidate();
} }
} }
@@ -1261,7 +1174,6 @@ public class LocalePicker extends LinearLayout {
* Gets whether the selector wheel wraps when reaching the min/max value. * Gets whether the selector wheel wraps when reaching the min/max value.
* *
* @return True if the selector wheel wraps. * @return True if the selector wheel wraps.
* @see #getMinValue()
* @see #getMaxValue() * @see #getMaxValue()
*/ */
public boolean getWrapSelectorWheel() { public boolean getWrapSelectorWheel() {
@@ -1269,15 +1181,15 @@ public class LocalePicker extends LinearLayout {
} }
/** /**
* Sets whether the selector wheel shown during flinging/scrolling should wrap around the {@link * Sets whether the selector wheel shown during flinging/scrolling should wrap around the
* LocalePicker#getMinValue()} and {@link LocalePicker#getMaxValue()} values. * getMinValue() and {@link LocalePicker#getMaxValue()} values.
* <p> * <p>
* By default if the range (max - min) is more than the number of items shown on the selector * By default if the range (max - min) is more than the number of items shown on the selector
* wheel the selector wheel wrapping is enabled. * wheel the selector wheel wrapping is enabled.
* </p> * </p>
* <p> * <p>
* <strong>Note:</strong> If the number of items, i.e. the range ( * <strong>Note:</strong> If the number of items, i.e. the range (
* {@link #getMaxValue()} - {@link #getMinValue()}) is less than the number of items shown on * {@link #getMaxValue()} - getMinValue()) is less than the number of items shown on
* the selector wheel, the selector wheel will not wrap. Hence, in such a case calling this * the selector wheel, the selector wheel will not wrap. Hence, in such a case calling this
* method is a NOP. * method is a NOP.
* </p> * </p>
@@ -1291,20 +1203,6 @@ public class LocalePicker extends LinearLayout {
} }
} }
/**
* Sets the speed at which the numbers be incremented and decremented when the up and down
* buttons are long pressed respectively.
* <p>
* The default value is 300 ms.
* </p>
*
* @param intervalMillis The speed (in milliseconds) at which the numbers will be incremented
* and decremented.
*/
public void setOnLongPressUpdateInterval(long intervalMillis) {
mLongPressUpdateInterval = intervalMillis;
}
/** /**
* Returns the value of the picker. * Returns the value of the picker.
* *
@@ -1323,35 +1221,6 @@ public class LocalePicker extends LinearLayout {
return mMinValue; return mMinValue;
} }
/**
* Sets the min value of the picker.
*
* @param minValue The min value inclusive.
*
* <strong>Note:</strong> The length of the displayed values array
* set via {@link #setDisplayedValues(String[])} must be equal to the range of
* selectable numbers which is equal to {@link #getMaxValue()} - {@link
* #getMinValue()} + 1.
*/
public void setMinValue(int minValue) {
if (mMinValue == minValue) {
return;
}
if (minValue < 0) {
throw new IllegalArgumentException("minValue must be >= 0");
}
mMinValue = minValue;
if (mMinValue > mValue) {
mValue = mMinValue;
}
boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length;
setWrapSelectorWheel(wrapSelectorWheel);
initializeSelectorWheelIndices();
updateInputTextView();
tryComputeMaxWidth();
invalidate();
}
/** /**
* Returns the max value of the picker. * Returns the max value of the picker.
* *
@@ -1365,11 +1234,11 @@ public class LocalePicker extends LinearLayout {
* Sets the max value of the picker. * Sets the max value of the picker.
* *
* @param maxValue The max value inclusive. * @param maxValue The max value inclusive.
* * <p>
* <strong>Note:</strong> The length of the displayed values array * <strong>Note:</strong> The length of the displayed values array
* set via {@link #setDisplayedValues(String[])} must be equal to the range of * set via {@link #setDisplayedValues(String[])} must be equal to the range of
* selectable numbers which is equal to {@link #getMaxValue()} - {@link * selectable numbers which is equal to {@link #getMaxValue()} -
* #getMinValue()} + 1. * getMinValue() + 1.
*/ */
public void setMaxValue(int maxValue) { public void setMaxValue(int maxValue) {
if (mMaxValue == maxValue) { if (mMaxValue == maxValue) {
@@ -1390,23 +1259,14 @@ public class LocalePicker extends LinearLayout {
invalidate(); invalidate();
} }
/**
* Gets the values to be displayed instead of string values.
*
* @return The displayed values.
*/
public String[] getDisplayedValues() {
return mDisplayedValues;
}
/** /**
* Sets the values to be displayed. * Sets the values to be displayed.
* *
* @param displayedValues The displayed values. * @param displayedValues The displayed values.
* * <p>
* <strong>Note:</strong> The length of the displayed values array * <strong>Note:</strong> The length of the displayed values array
* must be equal to the range of selectable numbers which is equal to * must be equal to the range of selectable numbers which is equal to
* {@link #getMaxValue()} - {@link #getMinValue()} + 1. * {@link #getMaxValue()} - getMinValue() + 1.
*/ */
public void setDisplayedValues(String[] displayedValues) { public void setDisplayedValues(String[] displayedValues) {
if (mDisplayedValues == displayedValues) { if (mDisplayedValues == displayedValues) {
@@ -1446,7 +1306,7 @@ public class LocalePicker extends LinearLayout {
super.onDraw(canvas); super.onDraw(canvas);
return; return;
} }
float x = (mRight - mLeft) / 2; float x = (float) (mRight - mLeft) / 2;
float y = mCurrentScrollOffset; float y = mCurrentScrollOffset;
// draw the virtual buttons pressed state if needed // draw the virtual buttons pressed state if needed
@@ -1530,16 +1390,14 @@ public class LocalePicker extends LinearLayout {
} }
final int size = MeasureSpec.getSize(measureSpec); final int size = MeasureSpec.getSize(measureSpec);
final int mode = MeasureSpec.getMode(measureSpec); final int mode = MeasureSpec.getMode(measureSpec);
switch (mode) { return switch (mode) {
case MeasureSpec.EXACTLY: case MeasureSpec.EXACTLY -> measureSpec;
return measureSpec; case MeasureSpec.AT_MOST -> MeasureSpec.makeMeasureSpec(Math.min(size, maxSize),
case MeasureSpec.AT_MOST: MeasureSpec.EXACTLY);
return MeasureSpec.makeMeasureSpec(Math.min(size, maxSize), MeasureSpec.EXACTLY); case MeasureSpec.UNSPECIFIED -> MeasureSpec.makeMeasureSpec(maxSize,
case MeasureSpec.UNSPECIFIED: MeasureSpec.EXACTLY);
return MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.EXACTLY); default -> throw new IllegalArgumentException("Unknown measure mode: " + mode);
default: };
throw new IllegalArgumentException("Unknown measure mode: " + mode);
}
} }
/** /**
@@ -1784,8 +1642,7 @@ public class LocalePicker extends LinearLayout {
/** /**
* Updates the view of this NumberPicker. If displayValues were specified in the string * Updates the view of this NumberPicker. If displayValues were specified in the string
* corresponding to the index specified by the current value will be returned. Otherwise, the * corresponding to the index specified by the current value will be returned.
* formatter specified in {@link #setFormatter} will be used to format the number.
* *
* @return Whether the text was updated. * @return Whether the text was updated.
*/ */
@@ -1879,13 +1736,8 @@ public class LocalePicker extends LinearLayout {
* @return The selected index given its displayed <code>value</code>. * @return The selected index given its displayed <code>value</code>.
*/ */
private int getSelectedPos(String value) { private int getSelectedPos(String value) {
if (mDisplayedValues == null) { // Ignore as if it's not a number we don't care
try { if (mDisplayedValues != null) {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
// Ignore as if it's not a number we don't care
}
} else {
for (int i = 0; i < mDisplayedValues.length; i++) { for (int i = 0; i < mDisplayedValues.length; i++) {
// Don't force the user to type in jan when ja will do // Don't force the user to type in jan when ja will do
value = value.toLowerCase(); value = value.toLowerCase();
@@ -1898,12 +1750,11 @@ public class LocalePicker extends LinearLayout {
* The user might have typed in a number into the month field i.e. * The user might have typed in a number into the month field i.e.
* 10 instead of OCT so support that too. * 10 instead of OCT so support that too.
*/ */
try { }
return Integer.parseInt(value); try {
} catch (NumberFormatException e) { return Integer.parseInt(value);
} catch (NumberFormatException e) {
// Ignore as if it's not a number we don't care // Ignore as if it's not a number we don't care
}
} }
return mMinValue; return mMinValue;
} }
@@ -1930,11 +1781,11 @@ public class LocalePicker extends LinearLayout {
// Latin digits are the common case // Latin digits are the common case
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
// Arabic-Indic // Arabic-Indic
'\u0660', '\u0661', '\u0662', '\u0663', '\u0664', '\u0665', '\u0666', '\u0667', '\u0668' '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨'
, '\u0669', , '٩',
// Extended Arabic-Indic // Extended Arabic-Indic
'\u06f0', '\u06f1', '\u06f2', '\u06f3', '\u06f4', '\u06f5', '\u06f6', '\u06f7', '\u06f8' '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸'
, '\u06f9' , '۹'
}; };
/** /**
@@ -1966,7 +1817,7 @@ public class LocalePicker extends LinearLayout {
String result = String.valueOf(dest.subSequence(0, dstart)) + filtered String result = String.valueOf(dest.subSequence(0, dstart)) + filtered
+ dest.subSequence(dend, dest.length()); + dest.subSequence(dend, dest.length());
if ("".equals(result)) { if (result.isEmpty()) {
return result; return result;
} }
int val = getSelectedPos(result); int val = getSelectedPos(result);
@@ -2131,13 +1982,13 @@ public class LocalePicker extends LinearLayout {
@Override @Override
public void run() { public void run() {
changeValueByOne(mIncrement); changeValueByOne(mIncrement);
postDelayed(this, mLongPressUpdateInterval); /**
* The speed for updating the value form long press.
*/
postDelayed(this, DEFAULT_LONG_PRESS_UPDATE_INTERVAL);
} }
} }
/**
* @hide
*/
public static class CustomEditText extends EditText { public static class CustomEditText extends EditText {
public CustomEditText(Context context, AttributeSet attrs) { public CustomEditText(Context context, AttributeSet attrs) {
@@ -2185,27 +2036,25 @@ public class LocalePicker extends LinearLayout {
@Override @Override
public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
switch (virtualViewId) { return switch (virtualViewId) {
case View.NO_ID: case View.NO_ID -> createAccessibilityNodeInfoForNumberPicker(mScrollX, mScrollY,
return createAccessibilityNodeInfoForNumberPicker(mScrollX, mScrollY, mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop));
mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop)); case VIRTUAL_VIEW_ID_DECREMENT -> createAccessibilityNodeInfoForVirtualButton(
case VIRTUAL_VIEW_ID_DECREMENT: VIRTUAL_VIEW_ID_DECREMENT,
return createAccessibilityNodeInfoForVirtualButton(VIRTUAL_VIEW_ID_DECREMENT, getVirtualDecrementButtonText(), mScrollX, mScrollY,
getVirtualDecrementButtonText(), mScrollX, mScrollY, mScrollX + (mRight - mLeft),
mScrollX + (mRight - mLeft), mTopSelectionDividerTop + mSelectionDividerHeight);
mTopSelectionDividerTop + mSelectionDividerHeight); case VIRTUAL_VIEW_ID_INPUT -> createAccessibiltyNodeInfoForInputText(mScrollX,
case VIRTUAL_VIEW_ID_INPUT: mTopSelectionDividerTop + mSelectionDividerHeight,
return createAccessibiltyNodeInfoForInputText(mScrollX, mScrollX + (mRight - mLeft),
mTopSelectionDividerTop + mSelectionDividerHeight, mBottomSelectionDividerBottom - mSelectionDividerHeight);
mScrollX + (mRight - mLeft), case VIRTUAL_VIEW_ID_INCREMENT -> createAccessibilityNodeInfoForVirtualButton(
mBottomSelectionDividerBottom - mSelectionDividerHeight); VIRTUAL_VIEW_ID_INCREMENT,
case VIRTUAL_VIEW_ID_INCREMENT: getVirtualIncrementButtonText(), mScrollX,
return createAccessibilityNodeInfoForVirtualButton(VIRTUAL_VIEW_ID_INCREMENT, mBottomSelectionDividerBottom - mSelectionDividerHeight,
getVirtualIncrementButtonText(), mScrollX, mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop));
mBottomSelectionDividerBottom - mSelectionDividerHeight, default -> super.createAccessibilityNodeInfo(virtualViewId);
mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop)); };
}
return super.createAccessibilityNodeInfo(virtualViewId);
} }
@Override @Override
@@ -2215,7 +2064,7 @@ public class LocalePicker extends LinearLayout {
return Collections.emptyList(); return Collections.emptyList();
} }
String searchedLowerCase = searched.toLowerCase(); String searchedLowerCase = searched.toLowerCase();
List<AccessibilityNodeInfo> result = new ArrayList<AccessibilityNodeInfo>(); List<AccessibilityNodeInfo> result = new ArrayList<>();
switch (virtualViewId) { switch (virtualViewId) {
case View.NO_ID: { case View.NO_ID: {
findAccessibilityNodeInfosByTextInChild(searchedLowerCase, findAccessibilityNodeInfosByTextInChild(searchedLowerCase,
@@ -2494,11 +2343,10 @@ public class LocalePicker extends LinearLayout {
Rect boundsInParent = mTempRect; Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom); boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(isVisibleToUser(boundsInParent)); info.setVisibleToUser(isVisibleToUser(boundsInParent));
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray; int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen); getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]); boundsInParent.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen); info.setBoundsInScreen(boundsInParent);
return info; return info;
} }
@@ -2516,11 +2364,10 @@ public class LocalePicker extends LinearLayout {
Rect boundsInParent = mTempRect; Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom); boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(isVisibleToUser(boundsInParent)); info.setVisibleToUser(isVisibleToUser(boundsInParent));
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray; int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen); getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]); boundsInParent.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen); info.setBoundsInScreen(boundsInParent);
if (mAccessibilityFocusedView != virtualViewId) { if (mAccessibilityFocusedView != virtualViewId) {
info.addAction(AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS); info.addAction(AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS);
@@ -2563,12 +2410,11 @@ public class LocalePicker extends LinearLayout {
info.setVisibleToUser(isVisibleToUser()); info.setVisibleToUser(isVisibleToUser());
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray; int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen); getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]); boundsInParent.offset(locationOnScreen[0], locationOnScreen[1]);
boundsInScreen.scale(applicationScale); boundsInParent.scale(applicationScale);
info.setBoundsInScreen(boundsInScreen); info.setBoundsInScreen(boundsInParent);
if (mAccessibilityFocusedView != View.NO_ID) { if (mAccessibilityFocusedView != View.NO_ID) {
info.addAction(AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS); info.addAction(AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS);

View File

@@ -141,7 +141,7 @@ public class WizardAction implements Parcelable {
if (resultCode == null) { if (resultCode == null) {
transitions.setDefaultAction(action); transitions.setDefaultAction(action);
} else { } else {
transitions.put(Integer.valueOf(resultCode).intValue(), action); transitions.put(Integer.parseInt(resultCode), action);
} }
} }

View File

@@ -44,7 +44,7 @@ public class WizardManager extends Activity {
private static final String TAG = WizardManager.class.getSimpleName(); private static final String TAG = WizardManager.class.getSimpleName();
private static final HashMap<String, WizardScript> sWizardScripts = new HashMap(); private static final HashMap<String, WizardScript> sWizardScripts = new HashMap<>();
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -185,8 +185,8 @@ public class WizardManager extends Activity {
} }
private static boolean isIntentAvailable(Context context, Intent intent) { private static boolean isIntentAvailable(Context context, Intent intent) {
return context.getPackageManager().queryIntentActivities(intent, return !context.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY).size() > 0; PackageManager.MATCH_DEFAULT_ONLY).isEmpty();
} }
private static WizardScript getWizardScript(Context context, String scriptUri) { private static WizardScript getWizardScript(Context context, String scriptUri) {

View File

@@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016 The CyanogenMod Project * Copyright (C) 2016 The CyanogenMod Project
* Copyright (C) 2017 The LineageOS Project * Copyright (C) 2017-2024 The LineageOS Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -113,14 +113,14 @@ public class WizardScript implements Parcelable {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.mFirstActionId); dest.writeString(this.mFirstActionId);
dest.writeTypedList(new ArrayList(this.mActions.values())); dest.writeTypedList(new ArrayList<>(this.mActions.values()));
} }
public static final Creator<WizardScript> CREATOR = new Creator<WizardScript>() { public static final Creator<WizardScript> CREATOR = new Creator<>() {
public WizardScript createFromParcel(Parcel source) { public WizardScript createFromParcel(Parcel source) {
String firstActionId = source.readString(); String firstActionId = source.readString();
HashMap<String, WizardAction> actions = new HashMap(); HashMap<String, WizardAction> actions = new HashMap<>();
ArrayList<WizardAction> actionList = new ArrayList(); ArrayList<WizardAction> actionList = new ArrayList<>();
source.readTypedList(actionList, WizardAction.CREATOR); source.readTypedList(actionList, WizardAction.CREATOR);
for (WizardAction action : actionList) { for (WizardAction action : actionList) {
actions.put(action.getId(), action); actions.put(action.getId(), action);
@@ -135,7 +135,6 @@ public class WizardScript implements Parcelable {
public static WizardScript loadFromUri(Context context, String uriString) { public static WizardScript loadFromUri(Context context, String uriString) {
XmlPullParser xmlPullParser; XmlPullParser xmlPullParser;
WizardScript wizardScript = null;
try { try {
ContentResolver.OpenResourceIdResult openResourceIdResult = ContentResolver.OpenResourceIdResult openResourceIdResult =
context.getContentResolver().getResourceId(Uri context.getContentResolver().getResourceId(Uri
@@ -163,15 +162,15 @@ public class WizardScript implements Parcelable {
} catch (XmlPullParserException e) { } catch (XmlPullParserException e) {
Log.e(TAG, "Ill-formatted wizard_script: " + uriString); Log.e(TAG, "Ill-formatted wizard_script: " + uriString);
Log.e(TAG, e.getMessage()); Log.e(TAG, e.getMessage());
return wizardScript; return null;
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException fnfe) {
Log.e(TAG, "Cannot find file: " + uriString); Log.e(TAG, "Cannot find file: " + uriString);
Log.e(TAG, fnfe.getMessage()); Log.e(TAG, fnfe.getMessage());
return wizardScript; return null;
} catch (IOException ioe) { } catch (IOException ioe) {
Log.e(TAG, "Unable to read wizard_script: " + uriString); Log.e(TAG, "Unable to read wizard_script: " + uriString);
Log.e(TAG, ioe.getMessage()); Log.e(TAG, ioe.getMessage());
return wizardScript; return null;
} }
} }
@@ -189,7 +188,7 @@ public class WizardScript implements Parcelable {
throw new XmlPullParserException("WizardScript must define a firstAction"); throw new XmlPullParserException("WizardScript must define a firstAction");
} }
HashMap wizardActions = new HashMap(); HashMap<String, WizardAction> wizardActions = new HashMap<>();
int type; int type;
final int depth = parser.getDepth(); final int depth = parser.getDepth();
while (((type = parser.next()) != XmlPullParser.END_TAG || while (((type = parser.next()) != XmlPullParser.END_TAG ||
@@ -198,9 +197,7 @@ public class WizardScript implements Parcelable {
if (next != XmlPullParser.END_TAG || next != XmlPullParser.TEXT) { if (next != XmlPullParser.END_TAG || next != XmlPullParser.TEXT) {
if (TAG_WIZARD_ACTION.equals(parser.getName())) { if (TAG_WIZARD_ACTION.equals(parser.getName())) {
WizardAction action = WizardAction.parseWizardAction(parser); WizardAction action = WizardAction.parseWizardAction(parser);
if (action != null) { wizardActions.put(action.getId(), action);
wizardActions.put(action.getId(), action);
}
} else { } else {
XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser);
} }

View File

@@ -24,6 +24,8 @@ import android.os.Parcelable;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import androidx.annotation.NonNull;
import java.util.Objects; import java.util.Objects;
public class WizardTransitions extends SparseArray<String> implements Parcelable { public class WizardTransitions extends SparseArray<String> implements Parcelable {
@@ -69,6 +71,7 @@ public class WizardTransitions extends SparseArray<String> implements Parcelable
super.put(key, value); super.put(key, value);
} }
@NonNull
public String toString() { public String toString() {
return super.toString() + " mDefaultAction: " + mDefaultAction; return super.toString() + " mDefaultAction: " + mDefaultAction;
} }
@@ -95,7 +98,7 @@ public class WizardTransitions extends SparseArray<String> implements Parcelable
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mDefaultAction); dest.writeString(mDefaultAction);
int size = size(); int size = size();
SparseArray sparseArray = new SparseArray<>(size); SparseArray<String> sparseArray = new SparseArray<>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
sparseArray.put(keyAt(i), valueAt(i)); sparseArray.put(keyAt(i), valueAt(i));
} }