Commit 2236d291 authored by Michael W's avatar Michael W
Browse files

SUW: (Not-really-)Spring Cleanup

* Remove unused imports
* Fix a few line length issues
* Convert a few anonymous classes to lambda expressions
* Convert a few global vars to locals
* Remove unused methods
* Add a small local method in MobileDataActivity to shorten repeated calls

Change-Id: Ia10be8b8c98ef3956949f913ddb6bddc185cf1a5
parent e5741b0e
......@@ -67,24 +67,18 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity {
private final Handler mHandler = new Handler();
private final Runnable mRadioReadyRunnable = new Runnable() {
@Override
public void run() {
// If we timeout out waiting for the radio, Oh well.
if (!mRadioReady) {
mRadioReady = true;
checkForRadioReady();
}
private final Runnable mRadioReadyRunnable = () -> {
// If we timeout out waiting for the radio, Oh well.
if (!mRadioReady) {
mRadioReady = true;
checkForRadioReady();
}
};
private View.OnClickListener mSetDataSimClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
SubscriptionInfo subInfoRecord = (SubscriptionInfo)view.getTag();
if (subInfoRecord != null) {
changeDataSub(subInfoRecord);
}
private View.OnClickListener mSetDataSimClickListener = view -> {
SubscriptionInfo subInfoRecord = (SubscriptionInfo)view.getTag();
if (subInfoRecord != null) {
changeDataSub(subInfoRecord);
}
};
......@@ -455,10 +449,12 @@ public class ChooseDataSimActivity extends BaseSetupWizardActivity {
if (serviceState != null) {
if (LOGV) {
Log.v(TAG, "hasService{" +
"serviceState.getVoiceRegState()='" + serviceState.getVoiceRegState() + '\'' +
"serviceState.getVoiceRegState()='" + serviceState.getVoiceRegState() + '\'' +
", subInfoRecord.getSimSlotIndex() =" + subInfoRecord.getSimSlotIndex() +
'}');
"serviceState.getVoiceRegState()='" + serviceState.getVoiceRegState()
+ '\''
+ "serviceState.getVoiceRegState()='" + serviceState.getVoiceRegState()
+ '\''
+ ", subInfoRecord.getSimSlotIndex() =" + subInfoRecord.getSimSlotIndex()
+ '}');
}
// Consider the device to be in service if either voice or data service is available.
// Some SIM cards are marketed as data-only and do not support voice service, and on
......
......@@ -34,7 +34,6 @@ import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
......@@ -67,8 +66,6 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
private static final int HOURS_1 = 60 * 60000;
private TimeZone mCurrentTimeZone;
private View mDateView;
private View mTimeView;
private TextView mDateTextView;
private TextView mTimeTextView;
......@@ -90,68 +87,54 @@ public class DateTimeActivity extends BaseSetupWizardActivity implements
final Spinner spinner = (Spinner) findViewById(R.id.timezone_list);
final SimpleAdapter adapter = constructTimezoneAdapter(this, false);
mCurrentTimeZone = TimeZone.getDefault();
mDateView = findViewById(R.id.date_item);
mDateView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDatePicker();
}
});
mTimeView = findViewById(R.id.time_item);
mTimeView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showTimePicker();
}
});
View dateView = findViewById(R.id.date_item);
dateView.setOnClickListener((view) -> showDatePicker());
View timeView = findViewById(R.id.time_item);
timeView.setOnClickListener((view) -> showTimePicker());
mDateTextView = (TextView)findViewById(R.id.date_text);
mTimeTextView = (TextView)findViewById(R.id.time_text);
// Pre-select current/default timezone
mHandler.post(new Runnable() {
@Override
public void run() {
int tzIndex = getTimeZoneIndex(adapter, mCurrentTimeZone);
spinner.setAdapter(adapter);
if (tzIndex != -1) {
spinner.setSelection(tzIndex);
}
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
final Map<?, ?> map = (Map<?, ?>) adapterView.getItemAtPosition(position);
final String tzId = (String) map.get(KEY_ID);
if (mCurrentTimeZone != null && !mCurrentTimeZone.getID().equals(tzId)) {
// Update the system timezone value
final AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setTimeZone(tzId);
mCurrentTimeZone = TimeZone.getTimeZone(tzId);
}
mHandler.post(() -> {
int tzIndex = getTimeZoneIndex(adapter, mCurrentTimeZone);
spinner.setAdapter(adapter);
if (tzIndex != -1) {
spinner.setSelection(tzIndex);
}
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position,
long id) {
final Map<?, ?> map = (Map<?, ?>) adapterView.getItemAtPosition(position);
final String tzId = (String) map.get(KEY_ID);
if (mCurrentTimeZone != null && !mCurrentTimeZone.getID().equals(tzId)) {
// Update the system timezone value
final AlarmManager alarm =
(AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setTimeZone(tzId);
mCurrentTimeZone = TimeZone.getTimeZone(tzId);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
});
// Pre-select current/default date if epoch
mHandler.post(new Runnable() {
@Override
public void run() {
final Calendar calendar = Calendar.getInstance();
final boolean isEpoch = calendar.get(Calendar.YEAR) == 1970;
if (isEpoch) {
// If epoch, set date to build date
long timestamp = SetupWizardUtils.getBuildDateTimestamp();
if (timestamp > 0) {
calendar.setTimeInMillis(timestamp * 1000);
setDate(DateTimeActivity.this, calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
} else {
// no build date available, use a sane default
setDate(DateTimeActivity.this, 2017, Calendar.JANUARY, 1);
}
mHandler.post(() -> {
final Calendar calendar = Calendar.getInstance();
final boolean isEpoch = calendar.get(Calendar.YEAR) == 1970;
if (isEpoch) {
// If epoch, set date to build date
long timestamp = SetupWizardUtils.getBuildDateTimestamp();
if (timestamp > 0) {
calendar.setTimeInMillis(timestamp * 1000);
setDate(DateTimeActivity.this, calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
} else {
// no build date available, use a sane default
setDate(DateTimeActivity.this, 2017, Calendar.JANUARY, 1);
}
}
});
......
......@@ -38,12 +38,7 @@ public class FingerprintActivity extends SubBaseActivity {
@Override
protected void onStartSubactivity() {
setNextAllowed(true);
findViewById(R.id.setup_fingerprint).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
launchFingerprintSetup();
}
});
findViewById(R.id.setup_fingerprint).setOnClickListener(view -> launchFingerprintSetup());
}
@Override
......
......@@ -37,10 +37,7 @@ import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.android.setupwizardlib.util.WizardManagerHelper;
......
......@@ -38,7 +38,6 @@ import android.view.IWindowManager;
import android.view.View;
import android.view.WindowManagerGlobal;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.setupwizardlib.util.WizardManagerHelper;
......@@ -56,40 +55,28 @@ public class LineageSettingsActivity extends BaseSetupWizardActivity {
private SetupWizardApp mSetupWizardApp;
private View mMetricsRow;
private View mNavKeysRow;
private View mPrivacyGuardRow;
private CheckBox mMetrics;
private CheckBox mNavKeys;
private CheckBox mPrivacyGuard;
private boolean mHideNavKeysRow = false;
private View.OnClickListener mMetricsClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !mMetrics.isChecked();
mMetrics.setChecked(checked);
mSetupWizardApp.getSettingsBundle().putBoolean(KEY_SEND_METRICS, checked);
}
private View.OnClickListener mMetricsClickListener = view -> {
boolean checked = !mMetrics.isChecked();
mMetrics.setChecked(checked);
mSetupWizardApp.getSettingsBundle().putBoolean(KEY_SEND_METRICS, checked);
};
private View.OnClickListener mNavKeysClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !mNavKeys.isChecked();
mNavKeys.setChecked(checked);
mSetupWizardApp.getSettingsBundle().putBoolean(DISABLE_NAV_KEYS, checked);
}
private View.OnClickListener mNavKeysClickListener = view -> {
boolean checked = !mNavKeys.isChecked();
mNavKeys.setChecked(checked);
mSetupWizardApp.getSettingsBundle().putBoolean(DISABLE_NAV_KEYS, checked);
};
private View.OnClickListener mPrivacyGuardClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !mPrivacyGuard.isChecked();
mPrivacyGuard.setChecked(checked);
mSetupWizardApp.getSettingsBundle().putBoolean(KEY_PRIVACY_GUARD, checked);
}
private View.OnClickListener mPrivacyGuardClickListener = view -> {
boolean checked = !mPrivacyGuard.isChecked();
mPrivacyGuard.setChecked(checked);
mSetupWizardApp.getSettingsBundle().putBoolean(KEY_PRIVACY_GUARD, checked);
};
@Override
......@@ -121,8 +108,8 @@ public class LineageSettingsActivity extends BaseSetupWizardActivity {
privacyPolicy.setMovementMethod(LinkMovementMethod.getInstance());
privacyPolicy.setText(ss);
mMetricsRow = findViewById(R.id.metrics);
mMetricsRow.setOnClickListener(mMetricsClickListener);
View metricsRow = findViewById(R.id.metrics);
metricsRow.setOnClickListener(mMetricsClickListener);
String metricsHelpImproveLineage =
getString(R.string.services_help_improve_cm, getString(R.string.os_name));
String metricsSummary = getString(R.string.services_metrics_label,
......@@ -134,8 +121,8 @@ public class LineageSettingsActivity extends BaseSetupWizardActivity {
metrics.setText(metricsSpan);
mMetrics = (CheckBox) findViewById(R.id.enable_metrics_checkbox);
mNavKeysRow = findViewById(R.id.nav_keys);
mNavKeysRow.setOnClickListener(mNavKeysClickListener);
View navKeysRow = findViewById(R.id.nav_keys);
navKeysRow.setOnClickListener(mNavKeysClickListener);
mNavKeys = (CheckBox) findViewById(R.id.nav_keys_checkbox);
boolean needsNavBar = true;
try {
......@@ -145,14 +132,14 @@ public class LineageSettingsActivity extends BaseSetupWizardActivity {
}
mHideNavKeysRow = hideKeyDisabler(this);
if (mHideNavKeysRow || needsNavBar) {
mNavKeysRow.setVisibility(View.GONE);
navKeysRow.setVisibility(View.GONE);
} else {
boolean navKeysDisabled = isKeyDisablerActive(this);
mNavKeys.setChecked(navKeysDisabled);
}
mPrivacyGuardRow = findViewById(R.id.privacy_guard);
mPrivacyGuardRow.setOnClickListener(mPrivacyGuardClickListener);
View privacyGuardRow = findViewById(R.id.privacy_guard);
privacyGuardRow.setOnClickListener(mPrivacyGuardClickListener);
mPrivacyGuard = (CheckBox) findViewById(R.id.privacy_guard_checkbox);
mPrivacyGuard.setChecked(LineageSettings.Secure.getInt(getContentResolver(),
LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) == 1);
......
......@@ -30,16 +30,12 @@ import android.os.Handler;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.telephony.MccTable;
import com.android.internal.telephony.TelephonyIntents;
import com.android.setupwizardlib.util.WizardManagerHelper;
import org.lineageos.setupwizard.R;
import org.lineageos.setupwizard.widget.LocalePicker;
......@@ -151,17 +147,11 @@ public class LocaleActivity extends BaseSetupWizardActivity {
mLanguagePicker.setMaxValue(labels.length - 1);
mLanguagePicker.setValue(currentLocaleIndex);
mLanguagePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
mLanguagePicker.setOnValueChangedListener(new LocalePicker.OnValueChangeListener() {
public void onValueChange(LocalePicker picker, int oldVal, int newVal) {
setLocaleFromPicker();
}
});
mLanguagePicker.setOnScrollListener(new LocalePicker.OnScrollListener() {
@Override
public void onScrollStateChange(LocalePicker view, int scrollState) {
if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
((SetupWizardApp)getApplication()).setIgnoreSimLocale(true);
}
mLanguagePicker.setOnValueChangedListener((pkr, oldVal, newVal) -> setLocaleFromPicker());
mLanguagePicker.setOnScrollListener((view, scrollState) -> {
if (scrollState == NumberPicker.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
((SetupWizardApp)getApplication()).setIgnoreSimLocale(true);
}
});
}
......@@ -169,7 +159,8 @@ public class LocaleActivity extends BaseSetupWizardActivity {
private void setLocaleFromPicker() {
((SetupWizardApp)getApplication()).setIgnoreSimLocale(true);
int i = mAdapterIndices[mLanguagePicker.getValue()];
final com.android.internal.app.LocalePicker.LocaleInfo localLocaleInfo = mLocaleAdapter.getItem(i);
final com.android.internal.app.LocalePicker.LocaleInfo localLocaleInfo =
mLocaleAdapter.getItem(i);
onLocaleChanged(localLocaleInfo.getLocale());
}
......
......@@ -28,7 +28,6 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;
......@@ -61,19 +60,9 @@ public class MobileDataActivity extends BaseSetupWizardActivity {
private final Handler mHandler = new Handler();
private final Runnable mRadioReadyRunnable = new Runnable() {
@Override
public void run() {
hideWaitForRadio();
}
};
private final Runnable mRadioReadyRunnable = this::hideWaitForRadio;
private final Runnable mDataConnectionReadyRunnable = new Runnable() {
@Override
public void run() {
onDataStateReady();
}
};
private final Runnable mDataConnectionReadyRunnable = this::onDataStateReady;
private PhoneMonitor.SubscriptionStateListener mSubscriptionStateListener =
new PhoneMonitor.SubscriptionStateListener() {
......@@ -231,9 +220,9 @@ public class MobileDataActivity extends BaseSetupWizardActivity {
private void updateCarrierText() {
if (mIsAttached) {
String name = mPhone.getSimOperatorName(SubscriptionManager.getDefaultSubscriptionId());
String name = mPhone.getSimOperatorName(getDefaultSubscriptionId());
if (TextUtils.isEmpty(name)) {
name = mPhone.getNetworkOperatorName(SubscriptionManager.getDefaultSubscriptionId());
name = mPhone.getNetworkOperatorName(getDefaultSubscriptionId());
}
if (TextUtils.isEmpty(name)) {
if (mServiceState != null && mServiceState.isEmergencyOnly()) {
......@@ -292,7 +281,7 @@ public class MobileDataActivity extends BaseSetupWizardActivity {
boolean retVal;
if (mServiceState == null) {
mServiceState = TelephonyManager.from(this)
.getServiceStateForSubscriber(SubscriptionManager.getDefaultSubscriptionId());
.getServiceStateForSubscriber(getDefaultSubscriptionId());
}
if (mServiceState != null) {
// Consider the device to be in service if either voice or data service is available.
......@@ -331,4 +320,7 @@ public class MobileDataActivity extends BaseSetupWizardActivity {
return R.drawable.ic_mobile_data;
}
private int getDefaultSubscriptionId() {
return SubscriptionManager.getDefaultSubscriptionId();
}
}
......@@ -26,7 +26,6 @@ import android.util.Log;
import org.lineageos.setupwizard.util.NetworkMonitor;
import org.lineageos.setupwizard.util.PhoneMonitor;
import org.lineageos.setupwizard.util.SetupWizardUtils;
import org.lineageos.setupwizard.wizardmanager.WizardManager;
public class SetupWizardApp extends Application {
......@@ -80,12 +79,7 @@ public class SetupWizardApp extends Application {
private final Bundle mSettingsBundle = new Bundle();
private final Handler mHandler = new Handler();
private final Runnable mRadioTimeoutRunnable = new Runnable() {
@Override
public void run() {
mIsRadioReady = true;
}
};
private final Runnable mRadioTimeoutRunnable = () -> mIsRadioReady = true;
@Override
public void onCreate() {
......
......@@ -30,7 +30,6 @@ import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public abstract class SubBaseActivity extends BaseSetupWizardActivity {
......
......@@ -39,12 +39,9 @@ public class WelcomeActivity extends BaseSetupWizardActivity {
setBackDrawable(null);
mEnableAccessibilityController =
EnableAccessibilityController.getInstance(getApplicationContext());
mRootView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mEnableAccessibilityController.onTouchEvent(event);
}
});
mRootView.setOnTouchListener((v, event) ->
mEnableAccessibilityController.onTouchEvent(event));
}
@Override
......
......@@ -18,7 +18,6 @@
package org.lineageos.setupwizard;
import static org.lineageos.setupwizard.SetupWizardApp.ACTION_SETUP_WIFI;
import static org.lineageos.setupwizard.SetupWizardApp.EXTRA_MATERIAL_LIGHT;
import static org.lineageos.setupwizard.SetupWizardApp.REQUEST_CODE_SETUP_WIFI;
import android.content.Intent;
......
......@@ -27,8 +27,6 @@ import android.net.NetworkInfo;
import android.os.Handler;
import android.util.Log;
import org.lineageos.setupwizard.SetupWizardApp;
public class NetworkMonitor {
public static final String TAG = NetworkMonitor.class.getSimpleName();
......@@ -80,20 +78,14 @@ public class NetworkMonitor {
}
public boolean isWifiConnected() {
boolean wifiConnected = (!mNetworkConnected || mNetworkInfo == null) ?
false :
mNetworkInfo.getType() == 1;
boolean wifiConnected = (mNetworkConnected && mNetworkInfo != null &&
mNetworkInfo.getType() == 1);
if (LOGV) {
Log.v(TAG, "isWifiConnected() returns " + wifiConnected);
}
return wifiConnected;
}
public boolean checkIsNetworkConnected() {
updateNetworkStatus(mContext);
return isNetworkConnected();
}
private void onNetworkConnected(NetworkInfo ni) {
if (LOGV) {
Log.v(TAG, "onNetworkConnected()");
......
......@@ -51,7 +51,6 @@ import android.provider.Settings;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import org.lineageos.setupwizard.BluetoothSetupActivity;
......@@ -68,8 +67,6 @@ import org.lineageos.internal.util.PackageManagerUtils;
import java.util.ArrayList;
import java.util.List;
import lineageos.providers.LineageSettings;
public class SetupWizardUtils {
private static final String TAG = SetupWizardUtils.class.getSimpleName();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment