diff --git a/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java b/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java index b6a55e39..18dc693c 100644 --- a/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java +++ b/src/org/lineageos/setupwizard/BaseSetupWizardActivity.java @@ -31,7 +31,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.net.wifi.WifiManager; import android.os.Bundle; @@ -61,11 +60,6 @@ public abstract class BaseSetupWizardActivity extends AppCompatActivity implemen 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 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() { nextAction(RESULT_OK); } @@ -242,10 +229,6 @@ public abstract class BaseSetupWizardActivity extends AppCompatActivity implemen } } - public void onNavigateBack() { - getOnBackPressedDispatcher().onBackPressed(); - } - public void onNavigateNext() { 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() { WifiManager wifiManager = getSystemService(WifiManager.class); return wifiManager.setWifiEnabled(true); diff --git a/src/org/lineageos/setupwizard/BiometricActivity.java b/src/org/lineageos/setupwizard/BiometricActivity.java index 08f7f349..40eb3a85 100644 --- a/src/org/lineageos/setupwizard/BiometricActivity.java +++ b/src/org/lineageos/setupwizard/BiometricActivity.java @@ -23,8 +23,6 @@ import android.content.Intent; public class BiometricActivity extends SubBaseActivity { - public static final String TAG = BiometricActivity.class.getSimpleName(); - @Override protected void onStartSubactivity() { Intent intent = new Intent(ACTION_SETUP_BIOMETRIC); diff --git a/src/org/lineageos/setupwizard/DateTimeActivity.java b/src/org/lineageos/setupwizard/DateTimeActivity.java index b45f4633..32c85307 100644 --- a/src/org/lineageos/setupwizard/DateTimeActivity.java +++ b/src/org/lineageos/setupwizard/DateTimeActivity.java @@ -37,6 +37,7 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.TimePicker; +import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; import com.android.settingslib.datetime.ZoneGetter; @@ -44,7 +45,6 @@ import com.android.settingslib.datetime.ZoneGetter; import org.lineageos.setupwizard.util.SetupWizardUtils; import java.util.Calendar; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -53,15 +53,10 @@ import java.util.TimeZone; public class DateTimeActivity extends BaseSetupWizardActivity implements 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_DISPLAYNAME = "name"; // 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 XMLTAG_TIMEZONE = "timezone"; - - private static final int HOURS_1 = 60 * 60000; private TimeZone mCurrentTimeZone; private TextView mDateTextView; @@ -207,14 +202,13 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements final TimeZoneComparator comparator = new TimeZoneComparator(KEY_OFFSET); final List> sortedList = ZoneGetter.getZonesList(context); - Collections.sort(sortedList, comparator); - final SimpleAdapter adapter = new SimpleAdapter(context, + sortedList.sort(comparator); + + return new SimpleAdapter(context, sortedList, R.layout.date_time_setup_custom_list_item_2, from, to); - - return adapter; } private static int getTimeZoneIndex(SimpleAdapter adapter, TimeZone tz) { @@ -259,16 +253,12 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements } private static class TimeZoneComparator implements Comparator> { - private String mSortingKey; + private final String mSortingKey; public TimeZoneComparator(String sortingKey) { mSortingKey = sortingKey; } - public void setSortingKey(String sortingKey) { - mSortingKey = sortingKey; - } - public int compare(Map map1, Map map2) { Object value1 = map1.get(mSortingKey); Object value2 = map2.get(mSortingKey); @@ -287,7 +277,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements } 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(); public static TimePickerFragment newInstance() { - TimePickerFragment frag = new TimePickerFragment(); - return frag; + return new TimePickerFragment(); } @Override @@ -306,6 +295,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements ((DateTimeActivity) getActivity()).onTimeSet(view, hourOfDay, minute); } + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Calendar calendar = Calendar.getInstance(); @@ -324,8 +314,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements private static final String TAG = DatePickerFragment.class.getSimpleName(); public static DatePickerFragment newInstance() { - DatePickerFragment frag = new DatePickerFragment(); - return frag; + return new DatePickerFragment(); } @Override @@ -333,6 +322,7 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements ((DateTimeActivity) getActivity()).onDateSet(view, year, month, day); } + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Calendar calendar = Calendar.getInstance(); diff --git a/src/org/lineageos/setupwizard/FinishActivity.java b/src/org/lineageos/setupwizard/FinishActivity.java index 0e71ccb7..30b7eabe 100644 --- a/src/org/lineageos/setupwizard/FinishActivity.java +++ b/src/org/lineageos/setupwizard/FinishActivity.java @@ -81,7 +81,7 @@ public class FinishActivity extends BaseSetupWizardActivity { if (LOGV) { Log.v(TAG, "onReceive intent=" + intent); } - if (intent != null && intent.getAction() == ACTION_FINISHED) { + if (intent != null && intent.getAction().equals(ACTION_FINISHED)) { unregisterReceiver(mIntentReceiver); completeSetup(); } @@ -96,7 +96,7 @@ public class FinishActivity extends BaseSetupWizardActivity { logActivityState("onCreate savedInstanceState=" + savedInstanceState); } mSetupWizardApp = (SetupWizardApp) getApplication(); - mBackground = (ImageView) findViewById(R.id.background); + mBackground = findViewById(R.id.background); setNextText(R.string.start); // Edge-to-edge. Needed for the background view to fill the full screen. @@ -231,7 +231,7 @@ public class FinishActivity extends BaseSetupWizardActivity { try { overlayManager.setEnabledExclusiveInCategory(selectedNavMode, USER_CURRENT); - } catch (Exception e) { + } catch (Exception ignored) { } } } diff --git a/src/org/lineageos/setupwizard/LineageSettingsActivity.java b/src/org/lineageos/setupwizard/LineageSettingsActivity.java index 808cbd43..5cf5adbb 100644 --- a/src/org/lineageos/setupwizard/LineageSettingsActivity.java +++ b/src/org/lineageos/setupwizard/LineageSettingsActivity.java @@ -34,8 +34,6 @@ import lineageos.providers.LineageSettings; public class LineageSettingsActivity extends BaseSetupWizardActivity { - public static final String TAG = LineageSettingsActivity.class.getSimpleName(); - private SetupWizardApp mSetupWizardApp; private CheckBox mMetrics; diff --git a/src/org/lineageos/setupwizard/LocaleActivity.java b/src/org/lineageos/setupwizard/LocaleActivity.java index c68f538d..3fdf9d1b 100644 --- a/src/org/lineageos/setupwizard/LocaleActivity.java +++ b/src/org/lineageos/setupwizard/LocaleActivity.java @@ -51,8 +51,6 @@ import java.util.concurrent.Executors; public class LocaleActivity extends BaseSetupWizardActivity { - public static final String TAG = LocaleActivity.class.getSimpleName(); - private ArrayAdapter mLocaleAdapter; private Locale mCurrentLocale; private int[] mAdapterIndices; @@ -89,9 +87,7 @@ public class LocaleActivity extends BaseSetupWizardActivity { mLanguagePicker.setNextRight(getNextButton().getId()); mLanguagePicker.requestFocus(); if (getResources().getBoolean(R.bool.config_isLargeNoTouch)) { - mLanguagePicker.setOnClickListener((View v) -> { - getNextButton().performClick(); - }); + mLanguagePicker.setOnClickListener((View v) -> getNextButton().performClick()); } loadLanguages(); } diff --git a/src/org/lineageos/setupwizard/LocationSettingsActivity.java b/src/org/lineageos/setupwizard/LocationSettingsActivity.java index 24e26690..b2764901 100644 --- a/src/org/lineageos/setupwizard/LocationSettingsActivity.java +++ b/src/org/lineageos/setupwizard/LocationSettingsActivity.java @@ -27,9 +27,6 @@ import android.widget.CheckBox; public class LocationSettingsActivity extends BaseSetupWizardActivity { - public static final String TAG = - LocationSettingsActivity.class.getSimpleName().substring(0, 22); - private CheckBox mLocationAccess; private CheckBox mLocationAgpsAccess; @@ -47,14 +44,12 @@ public class LocationSettingsActivity extends BaseSetupWizardActivity { mLocationManager = getSystemService(LocationManager.class); mUserManager = getSystemService(UserManager.class); View locationAccessView = findViewById(R.id.location); - locationAccessView.setOnClickListener(v -> { - mLocationAccess.setChecked(!mLocationAccess.isChecked()); - }); + locationAccessView.setOnClickListener( + v -> mLocationAccess.setChecked(!mLocationAccess.isChecked())); View locationAgpsAccessView = findViewById(R.id.location_agps); if (mUserManager.isMainUser()) { - locationAgpsAccessView.setOnClickListener(v -> { - mLocationAgpsAccess.setChecked(!mLocationAgpsAccess.isChecked()); - }); + locationAgpsAccessView.setOnClickListener( + v -> mLocationAgpsAccess.setChecked(!mLocationAgpsAccess.isChecked())); } else { locationAgpsAccessView.setVisibility(View.GONE); } diff --git a/src/org/lineageos/setupwizard/NavigationLayout.java b/src/org/lineageos/setupwizard/NavigationLayout.java index ed5edbf5..b109dfd8 100644 --- a/src/org/lineageos/setupwizard/NavigationLayout.java +++ b/src/org/lineageos/setupwizard/NavigationLayout.java @@ -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"); * 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. */ public interface NavigationBarListener { - void onNavigateBack(); - void onNavigateNext(); void onSkip(); diff --git a/src/org/lineageos/setupwizard/NavigationSettingsActivity.java b/src/org/lineageos/setupwizard/NavigationSettingsActivity.java index 035df834..e810713e 100644 --- a/src/org/lineageos/setupwizard/NavigationSettingsActivity.java +++ b/src/org/lineageos/setupwizard/NavigationSettingsActivity.java @@ -34,7 +34,6 @@ import android.view.View; import android.widget.CheckBox; import android.widget.RadioButton; import android.widget.RadioGroup; -import android.widget.RadioGroup.OnCheckedChangeListener; import com.airbnb.lottie.LottieAnimationView; @@ -44,8 +43,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils; public class NavigationSettingsActivity extends BaseSetupWizardActivity { - public static final String TAG = NavigationSettingsActivity.class.getSimpleName(); - private SetupWizardApp mSetupWizardApp; private boolean mIsTaskbarEnabled; diff --git a/src/org/lineageos/setupwizard/NetworkSetupActivity.java b/src/org/lineageos/setupwizard/NetworkSetupActivity.java index 7e777de1..4c9d5157 100644 --- a/src/org/lineageos/setupwizard/NetworkSetupActivity.java +++ b/src/org/lineageos/setupwizard/NetworkSetupActivity.java @@ -30,8 +30,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils; public class NetworkSetupActivity extends SubBaseActivity { - public static final String TAG = NetworkSetupActivity.class.getSimpleName(); - @Override protected void onStartSubactivity() { if (SetupWizardUtils.isOwner()) { diff --git a/src/org/lineageos/setupwizard/ScreenLockActivity.java b/src/org/lineageos/setupwizard/ScreenLockActivity.java index 3498d270..87f0528c 100644 --- a/src/org/lineageos/setupwizard/ScreenLockActivity.java +++ b/src/org/lineageos/setupwizard/ScreenLockActivity.java @@ -23,8 +23,6 @@ import android.content.Intent; public class ScreenLockActivity extends SubBaseActivity { - public static final String TAG = ScreenLockActivity.class.getSimpleName(); - @Override protected void onStartSubactivity() { Intent intent = new Intent(ACTION_SETUP_LOCKSCREEN); diff --git a/src/org/lineageos/setupwizard/SetupWizardApp.java b/src/org/lineageos/setupwizard/SetupWizardApp.java index 538c1db7..97cc8b3a 100644 --- a/src/org/lineageos/setupwizard/SetupWizardApp.java +++ b/src/org/lineageos/setupwizard/SetupWizardApp.java @@ -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_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_ACTION_ID = "actionId"; public static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode"; @@ -94,17 +91,6 @@ public class SetupWizardApp extends Application { return sStatusBarManager; } - public boolean isRadioReady() { - return mIsRadioReady; - } - - public void setRadioReady(boolean radioReady) { - if (!mIsRadioReady && radioReady) { - mHandler.removeCallbacks(mRadioTimeoutRunnable); - } - mIsRadioReady = radioReady; - } - public boolean ignoreSimLocale() { return mIgnoreSimLocale; } diff --git a/src/org/lineageos/setupwizard/SimMissingActivity.java b/src/org/lineageos/setupwizard/SimMissingActivity.java index 4336fdca..dff41b3c 100644 --- a/src/org/lineageos/setupwizard/SimMissingActivity.java +++ b/src/org/lineageos/setupwizard/SimMissingActivity.java @@ -23,8 +23,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils; public class SimMissingActivity extends BaseSetupWizardActivity { - public static final String TAG = SimMissingActivity.class.getSimpleName(); - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/org/lineageos/setupwizard/SubBaseActivity.java b/src/org/lineageos/setupwizard/SubBaseActivity.java index 66376e30..b1f262a5 100644 --- a/src/org/lineageos/setupwizard/SubBaseActivity.java +++ b/src/org/lineageos/setupwizard/SubBaseActivity.java @@ -38,10 +38,6 @@ public abstract class SubBaseActivity extends BaseSetupWizardActivity { protected abstract void onStartSubactivity(); - protected void onSubactivityCanceled(Intent data) { - // Do nothing. - } - @Override protected void onCreate(Bundle savedInstanceState) { if (LOGV) { diff --git a/src/org/lineageos/setupwizard/ThemeSettingsActivity.java b/src/org/lineageos/setupwizard/ThemeSettingsActivity.java index fe0c2bdd..8c00463b 100644 --- a/src/org/lineageos/setupwizard/ThemeSettingsActivity.java +++ b/src/org/lineageos/setupwizard/ThemeSettingsActivity.java @@ -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"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ import android.widget.RadioGroup; import androidx.annotation.Nullable; public class ThemeSettingsActivity extends BaseSetupWizardActivity { - public static final String TAG = ThemeSettingsActivity.class.getSimpleName(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/src/org/lineageos/setupwizard/UpdateRecoveryActivity.java b/src/org/lineageos/setupwizard/UpdateRecoveryActivity.java index 52a0177e..7ba5c110 100644 --- a/src/org/lineageos/setupwizard/UpdateRecoveryActivity.java +++ b/src/org/lineageos/setupwizard/UpdateRecoveryActivity.java @@ -53,9 +53,8 @@ public class UpdateRecoveryActivity extends BaseSetupWizardActivity { mRecoveryUpdateCheckbox = findViewById(R.id.update_recovery_checkbox); View cbView = findViewById(R.id.update_recovery_checkbox_view); - cbView.setOnClickListener(v -> { - mRecoveryUpdateCheckbox.setChecked(!mRecoveryUpdateCheckbox.isChecked()); - }); + cbView.setOnClickListener( + v -> mRecoveryUpdateCheckbox.setChecked(!mRecoveryUpdateCheckbox.isChecked())); // Allow overriding the default checkbox state if (sFirstTime) { diff --git a/src/org/lineageos/setupwizard/WelcomeActivity.java b/src/org/lineageos/setupwizard/WelcomeActivity.java index 10ea618b..17719702 100644 --- a/src/org/lineageos/setupwizard/WelcomeActivity.java +++ b/src/org/lineageos/setupwizard/WelcomeActivity.java @@ -33,8 +33,6 @@ import org.lineageos.setupwizard.util.SetupWizardUtils; public class WelcomeActivity extends SubBaseActivity { - public static final String TAG = WelcomeActivity.class.getSimpleName(); - @Override protected void onStartSubactivity() { } diff --git a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java index 7b15533e..92cfd347 100644 --- a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java +++ b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java @@ -18,7 +18,6 @@ package org.lineageos.setupwizard.util; 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_ENABLED; import static android.content.pm.PackageManager.DONT_KILL_APP; @@ -137,18 +136,6 @@ public class SetupWizardUtils { 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() { return UserHandle.myUserId() == 0; } @@ -335,7 +322,7 @@ public class SetupWizardUtils { 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), COMPONENT_ENABLED_STATE_DISABLED); } @@ -345,16 +332,6 @@ public class SetupWizardUtils { 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, int enabledState) { context.getPackageManager().setComponentEnabledSetting(componentName, @@ -370,7 +347,7 @@ public class SetupWizardUtils { public static List getComponentSets(Context context, int flags) { int i = 0; - List componentNames = new ArrayList(); + List componentNames = new ArrayList<>(); try { PackageInfo allInfo = context.getPackageManager() .getPackageInfo(context.getPackageName(), flags); @@ -394,7 +371,7 @@ public class SetupWizardUtils { } } } - } catch (PackageManager.NameNotFoundException e) { + } catch (PackageManager.NameNotFoundException ignored) { } return componentNames; } diff --git a/src/org/lineageos/setupwizard/widget/LocalePicker.java b/src/org/lineageos/setupwizard/widget/LocalePicker.java index 2a19e322..99bcac9c 100644 --- a/src/org/lineageos/setupwizard/widget/LocalePicker.java +++ b/src/org/lineageos/setupwizard/widget/LocalePicker.java @@ -27,7 +27,6 @@ import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.icu.text.DecimalFormatSymbols; import android.os.Bundle; import android.text.InputFilter; import android.text.InputType; @@ -153,58 +152,6 @@ public class LocalePicker extends LinearLayout { */ 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. */ @@ -295,15 +242,10 @@ public class LocalePicker extends LinearLayout { */ 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. */ - private final SparseArray mSelectorIndexToStringCache = new SparseArray(); + private final SparseArray mSelectorIndexToStringCache = new SparseArray<>(); /** * The selector indices whose value are show by the selector. @@ -674,14 +616,12 @@ public class LocalePicker extends LinearLayout { // input text mInputText = findViewById(R.id.localepicker_input); - mInputText.setOnFocusChangeListener(new OnFocusChangeListener() { - public void onFocusChange(View v, boolean hasFocus) { - if (hasFocus) { - mInputText.selectAll(); - } else { - mInputText.setSelection(0, 0); - validateInputTextView(v); - } + mInputText.setOnFocusChangeListener((v, hasFocus) -> { + if (hasFocus) { + mInputText.selectAll(); + } else { + mInputText.setSelection(0, 0); + validateInputTextView(v); } }); mInputText.setFilters(new InputFilter[]{ @@ -803,49 +743,47 @@ public class LocalePicker extends LinearLayout { return false; } final int action = event.getActionMasked(); - switch (action) { - case MotionEvent.ACTION_DOWN: { - removeAllCallbacks(); - mInputText.setVisibility(View.INVISIBLE); - mLastDownOrMoveEventY = mLastDownEventY = event.getY(); - mLastDownEventTime = event.getEventTime(); - mIngonreMoveEvents = false; - mShowSoftInputOnTap = false; - // Handle pressed state before any state change. - if (mLastDownEventY < mTopSelectionDividerTop) { - if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { - mPressedStateHelper.buttonPressDelayed( - PressedStateHelper.BUTTON_DECREMENT); - } - } else if (mLastDownEventY > mBottomSelectionDividerBottom) { - if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { - mPressedStateHelper.buttonPressDelayed( - PressedStateHelper.BUTTON_INCREMENT); - } + if (action == MotionEvent.ACTION_DOWN) { + removeAllCallbacks(); + mInputText.setVisibility(View.INVISIBLE); + mLastDownOrMoveEventY = mLastDownEventY = event.getY(); + mLastDownEventTime = event.getEventTime(); + mIngonreMoveEvents = false; + mShowSoftInputOnTap = false; + // Handle pressed state before any state change. + if (mLastDownEventY < mTopSelectionDividerTop) { + if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { + mPressedStateHelper.buttonPressDelayed( + PressedStateHelper.BUTTON_DECREMENT); } - // 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(); + } else if (mLastDownEventY > mBottomSelectionDividerBottom) { + if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { + mPressedStateHelper.buttonPressDelayed( + PressedStateHelper.BUTTON_INCREMENT); } - 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; } @@ -1127,35 +1065,15 @@ public class LocalePicker extends LinearLayout { mOnScrollListener = onScrollListener; } - /** - * Set the formatter to be used for formatting the current value. - *

- * Note: If you have provided alternative values for the values this formatter is never - * invoked. - *

- * - * @param formatter The formatter object. If formatter is null, {@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. *

- * 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 false the current value is set to the - * {@link LocalePicker#getMinValue()} value. + * getMinValue() value. *

*

- * 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 true the current value is set to the * {@link LocalePicker#getMaxValue()} value. *

@@ -1167,12 +1085,11 @@ public class LocalePicker extends LinearLayout { *

* If the argument is less than the {@link LocalePicker#getMaxValue()} and {@link * LocalePicker#getWrapSelectorWheel()} is true the current value is set to the - * {@link LocalePicker#getMinValue()} value. + * getMinValue() value. *

* * @param value The current value. * @see #setWrapSelectorWheel(boolean) - * @see #setMinValue(int) * @see #setMaxValue(int) */ public void setValue(int value) { @@ -1239,8 +1156,8 @@ public class LocalePicker extends LinearLayout { maxTextWidth = (int) (numberOfDigits * maxDigitWidth); } else { final int valueCount = mDisplayedValues.length; - for (int i = 0; i < valueCount; i++) { - final float textWidth = mSelectorWheelPaint.measureText(mDisplayedValues[i]); + for (String displayedValue : mDisplayedValues) { + final float textWidth = mSelectorWheelPaint.measureText(displayedValue); if (textWidth > maxTextWidth) { maxTextWidth = (int) textWidth; } @@ -1248,11 +1165,7 @@ public class LocalePicker extends LinearLayout { } maxTextWidth += mInputText.getPaddingLeft() + mInputText.getPaddingRight(); if (mMaxWidth != maxTextWidth) { - if (maxTextWidth > mMinWidth) { - mMaxWidth = maxTextWidth; - } else { - mMaxWidth = mMinWidth; - } + mMaxWidth = Math.max(maxTextWidth, mMinWidth); invalidate(); } } @@ -1261,7 +1174,6 @@ public class LocalePicker extends LinearLayout { * Gets whether the selector wheel wraps when reaching the min/max value. * * @return True if the selector wheel wraps. - * @see #getMinValue() * @see #getMaxValue() */ 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 - * LocalePicker#getMinValue()} and {@link LocalePicker#getMaxValue()} values. + * Sets whether the selector wheel shown during flinging/scrolling should wrap around the + * getMinValue() and {@link LocalePicker#getMaxValue()} values. *

* 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. *

*

* Note: 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 * method is a NOP. *

@@ -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. - *

- * The default value is 300 ms. - *

- * - * @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. * @@ -1323,35 +1221,6 @@ public class LocalePicker extends LinearLayout { return mMinValue; } - /** - * Sets the min value of the picker. - * - * @param minValue The min value inclusive. - * - * Note: 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. * @@ -1365,11 +1234,11 @@ public class LocalePicker extends LinearLayout { * Sets the max value of the picker. * * @param maxValue The max value inclusive. - * + *

* Note: 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. + * selectable numbers which is equal to {@link #getMaxValue()} - + * getMinValue() + 1. */ public void setMaxValue(int maxValue) { if (mMaxValue == maxValue) { @@ -1390,23 +1259,14 @@ public class LocalePicker extends LinearLayout { 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. * * @param displayedValues The displayed values. - * + *

* Note: The length of the displayed values array * 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) { if (mDisplayedValues == displayedValues) { @@ -1446,7 +1306,7 @@ public class LocalePicker extends LinearLayout { super.onDraw(canvas); return; } - float x = (mRight - mLeft) / 2; + float x = (float) (mRight - mLeft) / 2; float y = mCurrentScrollOffset; // 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 mode = MeasureSpec.getMode(measureSpec); - switch (mode) { - case MeasureSpec.EXACTLY: - return measureSpec; - case MeasureSpec.AT_MOST: - return MeasureSpec.makeMeasureSpec(Math.min(size, maxSize), MeasureSpec.EXACTLY); - case MeasureSpec.UNSPECIFIED: - return MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.EXACTLY); - default: - throw new IllegalArgumentException("Unknown measure mode: " + mode); - } + return switch (mode) { + case MeasureSpec.EXACTLY -> measureSpec; + case MeasureSpec.AT_MOST -> MeasureSpec.makeMeasureSpec(Math.min(size, maxSize), + MeasureSpec.EXACTLY); + case MeasureSpec.UNSPECIFIED -> MeasureSpec.makeMeasureSpec(maxSize, + MeasureSpec.EXACTLY); + 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 - * corresponding to the index specified by the current value will be returned. Otherwise, the - * formatter specified in {@link #setFormatter} will be used to format the number. + * corresponding to the index specified by the current value will be returned. * * @return Whether the text was updated. */ @@ -1879,13 +1736,8 @@ public class LocalePicker extends LinearLayout { * @return The selected index given its displayed value. */ private int getSelectedPos(String value) { - if (mDisplayedValues == null) { - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { - // Ignore as if it's not a number we don't care - } - } else { + // Ignore as if it's not a number we don't care + if (mDisplayedValues != null) { for (int i = 0; i < mDisplayedValues.length; i++) { // Don't force the user to type in jan when ja will do 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. * 10 instead of OCT so support that too. */ - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { - - // Ignore as if it's not a number we don't care - } + } + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + // Ignore as if it's not a number we don't care } return mMinValue; } @@ -1930,11 +1781,11 @@ public class LocalePicker extends LinearLayout { // Latin digits are the common case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // Arabic-Indic - '\u0660', '\u0661', '\u0662', '\u0663', '\u0664', '\u0665', '\u0666', '\u0667', '\u0668' - , '\u0669', + '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨' + , '٩', // 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 + dest.subSequence(dend, dest.length()); - if ("".equals(result)) { + if (result.isEmpty()) { return result; } int val = getSelectedPos(result); @@ -2131,13 +1982,13 @@ public class LocalePicker extends LinearLayout { @Override public void run() { 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 CustomEditText(Context context, AttributeSet attrs) { @@ -2185,27 +2036,25 @@ public class LocalePicker extends LinearLayout { @Override public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { - switch (virtualViewId) { - case View.NO_ID: - return createAccessibilityNodeInfoForNumberPicker(mScrollX, mScrollY, - mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop)); - case VIRTUAL_VIEW_ID_DECREMENT: - return createAccessibilityNodeInfoForVirtualButton(VIRTUAL_VIEW_ID_DECREMENT, - getVirtualDecrementButtonText(), mScrollX, mScrollY, - mScrollX + (mRight - mLeft), - mTopSelectionDividerTop + mSelectionDividerHeight); - case VIRTUAL_VIEW_ID_INPUT: - return createAccessibiltyNodeInfoForInputText(mScrollX, - mTopSelectionDividerTop + mSelectionDividerHeight, - mScrollX + (mRight - mLeft), - mBottomSelectionDividerBottom - mSelectionDividerHeight); - case VIRTUAL_VIEW_ID_INCREMENT: - return createAccessibilityNodeInfoForVirtualButton(VIRTUAL_VIEW_ID_INCREMENT, - getVirtualIncrementButtonText(), mScrollX, - mBottomSelectionDividerBottom - mSelectionDividerHeight, - mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop)); - } - return super.createAccessibilityNodeInfo(virtualViewId); + return switch (virtualViewId) { + case View.NO_ID -> createAccessibilityNodeInfoForNumberPicker(mScrollX, mScrollY, + mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop)); + case VIRTUAL_VIEW_ID_DECREMENT -> createAccessibilityNodeInfoForVirtualButton( + VIRTUAL_VIEW_ID_DECREMENT, + getVirtualDecrementButtonText(), mScrollX, mScrollY, + mScrollX + (mRight - mLeft), + mTopSelectionDividerTop + mSelectionDividerHeight); + case VIRTUAL_VIEW_ID_INPUT -> createAccessibiltyNodeInfoForInputText(mScrollX, + mTopSelectionDividerTop + mSelectionDividerHeight, + mScrollX + (mRight - mLeft), + mBottomSelectionDividerBottom - mSelectionDividerHeight); + case VIRTUAL_VIEW_ID_INCREMENT -> createAccessibilityNodeInfoForVirtualButton( + VIRTUAL_VIEW_ID_INCREMENT, + getVirtualIncrementButtonText(), mScrollX, + mBottomSelectionDividerBottom - mSelectionDividerHeight, + mScrollX + (mRight - mLeft), mScrollY + (mBottom - mTop)); + default -> super.createAccessibilityNodeInfo(virtualViewId); + }; } @Override @@ -2215,7 +2064,7 @@ public class LocalePicker extends LinearLayout { return Collections.emptyList(); } String searchedLowerCase = searched.toLowerCase(); - List result = new ArrayList(); + List result = new ArrayList<>(); switch (virtualViewId) { case View.NO_ID: { findAccessibilityNodeInfosByTextInChild(searchedLowerCase, @@ -2494,11 +2343,10 @@ public class LocalePicker extends LinearLayout { Rect boundsInParent = mTempRect; boundsInParent.set(left, top, right, bottom); info.setVisibleToUser(isVisibleToUser(boundsInParent)); - Rect boundsInScreen = boundsInParent; int[] locationOnScreen = mTempArray; getLocationOnScreen(locationOnScreen); - boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]); - info.setBoundsInScreen(boundsInScreen); + boundsInParent.offset(locationOnScreen[0], locationOnScreen[1]); + info.setBoundsInScreen(boundsInParent); return info; } @@ -2516,11 +2364,10 @@ public class LocalePicker extends LinearLayout { Rect boundsInParent = mTempRect; boundsInParent.set(left, top, right, bottom); info.setVisibleToUser(isVisibleToUser(boundsInParent)); - Rect boundsInScreen = boundsInParent; int[] locationOnScreen = mTempArray; getLocationOnScreen(locationOnScreen); - boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]); - info.setBoundsInScreen(boundsInScreen); + boundsInParent.offset(locationOnScreen[0], locationOnScreen[1]); + info.setBoundsInScreen(boundsInParent); if (mAccessibilityFocusedView != virtualViewId) { info.addAction(AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS); @@ -2563,12 +2410,11 @@ public class LocalePicker extends LinearLayout { info.setVisibleToUser(isVisibleToUser()); - Rect boundsInScreen = boundsInParent; int[] locationOnScreen = mTempArray; getLocationOnScreen(locationOnScreen); - boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]); - boundsInScreen.scale(applicationScale); - info.setBoundsInScreen(boundsInScreen); + boundsInParent.offset(locationOnScreen[0], locationOnScreen[1]); + boundsInParent.scale(applicationScale); + info.setBoundsInScreen(boundsInParent); if (mAccessibilityFocusedView != View.NO_ID) { info.addAction(AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS); diff --git a/src/org/lineageos/setupwizard/wizardmanager/WizardAction.java b/src/org/lineageos/setupwizard/wizardmanager/WizardAction.java index a9a56be3..bd545dce 100644 --- a/src/org/lineageos/setupwizard/wizardmanager/WizardAction.java +++ b/src/org/lineageos/setupwizard/wizardmanager/WizardAction.java @@ -141,7 +141,7 @@ public class WizardAction implements Parcelable { if (resultCode == null) { transitions.setDefaultAction(action); } else { - transitions.put(Integer.valueOf(resultCode).intValue(), action); + transitions.put(Integer.parseInt(resultCode), action); } } diff --git a/src/org/lineageos/setupwizard/wizardmanager/WizardManager.java b/src/org/lineageos/setupwizard/wizardmanager/WizardManager.java index 127fecf4..bcb53c06 100644 --- a/src/org/lineageos/setupwizard/wizardmanager/WizardManager.java +++ b/src/org/lineageos/setupwizard/wizardmanager/WizardManager.java @@ -44,7 +44,7 @@ public class WizardManager extends Activity { private static final String TAG = WizardManager.class.getSimpleName(); - private static final HashMap sWizardScripts = new HashMap(); + private static final HashMap sWizardScripts = new HashMap<>(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -185,8 +185,8 @@ public class WizardManager extends Activity { } private static boolean isIntentAvailable(Context context, Intent intent) { - return context.getPackageManager().queryIntentActivities(intent, - PackageManager.MATCH_DEFAULT_ONLY).size() > 0; + return !context.getPackageManager().queryIntentActivities(intent, + PackageManager.MATCH_DEFAULT_ONLY).isEmpty(); } private static WizardScript getWizardScript(Context context, String scriptUri) { diff --git a/src/org/lineageos/setupwizard/wizardmanager/WizardScript.java b/src/org/lineageos/setupwizard/wizardmanager/WizardScript.java index 5521be2f..12bd389c 100644 --- a/src/org/lineageos/setupwizard/wizardmanager/WizardScript.java +++ b/src/org/lineageos/setupwizard/wizardmanager/WizardScript.java @@ -1,6 +1,6 @@ /* * 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"); * 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) { dest.writeString(this.mFirstActionId); - dest.writeTypedList(new ArrayList(this.mActions.values())); + dest.writeTypedList(new ArrayList<>(this.mActions.values())); } - public static final Creator CREATOR = new Creator() { + public static final Creator CREATOR = new Creator<>() { public WizardScript createFromParcel(Parcel source) { String firstActionId = source.readString(); - HashMap actions = new HashMap(); - ArrayList actionList = new ArrayList(); + HashMap actions = new HashMap<>(); + ArrayList actionList = new ArrayList<>(); source.readTypedList(actionList, WizardAction.CREATOR); for (WizardAction action : actionList) { actions.put(action.getId(), action); @@ -135,7 +135,6 @@ public class WizardScript implements Parcelable { public static WizardScript loadFromUri(Context context, String uriString) { XmlPullParser xmlPullParser; - WizardScript wizardScript = null; try { ContentResolver.OpenResourceIdResult openResourceIdResult = context.getContentResolver().getResourceId(Uri @@ -163,15 +162,15 @@ public class WizardScript implements Parcelable { } catch (XmlPullParserException e) { Log.e(TAG, "Ill-formatted wizard_script: " + uriString); Log.e(TAG, e.getMessage()); - return wizardScript; + return null; } catch (FileNotFoundException fnfe) { Log.e(TAG, "Cannot find file: " + uriString); Log.e(TAG, fnfe.getMessage()); - return wizardScript; + return null; } catch (IOException ioe) { Log.e(TAG, "Unable to read wizard_script: " + uriString); 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"); } - HashMap wizardActions = new HashMap(); + HashMap wizardActions = new HashMap<>(); int type; final int depth = parser.getDepth(); 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 (TAG_WIZARD_ACTION.equals(parser.getName())) { WizardAction action = WizardAction.parseWizardAction(parser); - if (action != null) { - wizardActions.put(action.getId(), action); - } + wizardActions.put(action.getId(), action); } else { XmlUtils.skipCurrentTag(parser); } diff --git a/src/org/lineageos/setupwizard/wizardmanager/WizardTransitions.java b/src/org/lineageos/setupwizard/wizardmanager/WizardTransitions.java index 8ad853d0..cd0d98cf 100644 --- a/src/org/lineageos/setupwizard/wizardmanager/WizardTransitions.java +++ b/src/org/lineageos/setupwizard/wizardmanager/WizardTransitions.java @@ -24,6 +24,8 @@ import android.os.Parcelable; import android.util.Log; import android.util.SparseArray; +import androidx.annotation.NonNull; + import java.util.Objects; public class WizardTransitions extends SparseArray implements Parcelable { @@ -69,6 +71,7 @@ public class WizardTransitions extends SparseArray implements Parcelable super.put(key, value); } + @NonNull public String toString() { return super.toString() + " mDefaultAction: " + mDefaultAction; } @@ -95,7 +98,7 @@ public class WizardTransitions extends SparseArray implements Parcelable public void writeToParcel(Parcel dest, int flags) { dest.writeString(mDefaultAction); int size = size(); - SparseArray sparseArray = new SparseArray<>(size); + SparseArray sparseArray = new SparseArray<>(size); for (int i = 0; i < size; i++) { sparseArray.put(keyAt(i), valueAt(i)); }