summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/setupwizard/setup
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2015-03-11 17:13:05 -0700
committercretin45 <cretin45@gmail.com>2015-03-11 17:14:22 -0700
commitf66c56b62f03e0a090607043f2c28efae0589123 (patch)
tree8cf69708d6eed866e29539ca5a4c0f92b1452b04 /src/com/cyanogenmod/setupwizard/setup
parent77fce341b1baa2a88f3eb83d85956eb6eead171b (diff)
downloadpackages_apps_SetupWizard-f66c56b62f03e0a090607043f2c28efae0589123.zip
packages_apps_SetupWizard-f66c56b62f03e0a090607043f2c28efae0589123.tar.gz
packages_apps_SetupWizard-f66c56b62f03e0a090607043f2c28efae0589123.tar.bz2
SetupWizard: Only update network state when resumed
Change-Id: Id018bf0ed4d9c54a1d6d57d53749c265b1d0e269
Diffstat (limited to 'src/com/cyanogenmod/setupwizard/setup')
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java149
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/MobileDataPage.java99
2 files changed, 131 insertions, 117 deletions
diff --git a/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java b/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java
index 7fc9ee8..f531c0e 100644
--- a/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java
@@ -86,6 +86,8 @@ public class ChooseDataSimPage extends SetupPage {
private SparseArray<ServiceState> mServiceStates;
private SparseArray<PhoneStateListener> mPhoneStateListeners;
+ private boolean mIsAttached = false;
+
private View.OnClickListener mSetDataSimClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -121,12 +123,6 @@ public class ChooseDataSimPage extends SetupPage {
mPhoneStateListeners.put(i, createPhoneStateListener(subInfoRecord));
mPageView.addView(inflater.inflate(R.layout.divider, null));
}
- mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
- for (int i = 0; i < mPhoneStateListeners.size(); i++) {
- mPhone.listen(mPhoneStateListeners.get(i),
- PhoneStateListener.LISTEN_SERVICE_STATE
- | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
- }
updateSignalStrengths();
updateCurrentDataSub();
}
@@ -139,16 +135,24 @@ public class ChooseDataSimPage extends SetupPage {
@Override
public void onResume() {
super.onResume();
+ mIsAttached = true;
+ mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
+ for (int i = 0; i < mPhoneStateListeners.size(); i++) {
+ mPhone.listen(mPhoneStateListeners.get(i),
+ PhoneStateListener.LISTEN_SERVICE_STATE
+ | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
+ }
updateSignalStrengths();
updateCurrentDataSub();
}
@Override
- public void onDetach() {
+ public void onPause() {
+ super.onPause();
+ mIsAttached = false;
for (int i = 0; i < mPhoneStateListeners.size(); i++) {
mPhone.listen(mPhoneStateListeners.get(i), PhoneStateListener.LISTEN_NONE);
}
- super.onDetach();
}
private PhoneStateListener createPhoneStateListener(final SubInfoRecord subInfoRecord) {
@@ -156,98 +160,105 @@ public class ChooseDataSimPage extends SetupPage {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
- if (isDetached()) return;
- mSignalStrengths.put(subInfoRecord.slotId, signalStrength);
- updateSignalStrength(subInfoRecord);
+ if (mIsAttached) {
+ mSignalStrengths.put(subInfoRecord.slotId, signalStrength);
+ updateSignalStrength(subInfoRecord);
+ }
}
@Override
public void onServiceStateChanged(ServiceState state) {
- if (isDetached()) return;
- mServiceStates.put(subInfoRecord.slotId, state);
- updateSignalStrength(subInfoRecord);
+ if (mIsAttached) {
+ mServiceStates.put(subInfoRecord.slotId, state);
+ updateSignalStrength(subInfoRecord);
+ }
}
};
}
private void updateSignalStrengths() {
- if (isDetached()) return;
- for (int i = 0; i < mSubInfoRecords.size(); i++) {
- updateSignalStrength(mSubInfoRecords.get(i));
+ if (mIsAttached) {
+ for (int i = 0; i < mSubInfoRecords.size(); i++) {
+ updateSignalStrength(mSubInfoRecords.get(i));
+ }
}
}
private void setDataSubChecked(SubInfoRecord subInfoRecord) {
- if (isDetached()) return;
- for (int i = 0; i < mCheckBoxes.size(); i++) {
- if (subInfoRecord.slotId == i) {
- mCheckBoxes.get(i).setChecked(true);
- SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
- SetupStats.Action.PREFERRED_DATA_SIM,
- SetupStats.Label.SLOT, String.valueOf(i + 1));
- } else {
- mCheckBoxes.get(i).setChecked(false);
- }
+ if (mIsAttached) {
+ for (int i = 0; i < mCheckBoxes.size(); i++) {
+ if (subInfoRecord.slotId == i) {
+ mCheckBoxes.get(i).setChecked(true);
+ SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
+ SetupStats.Action.PREFERRED_DATA_SIM,
+ SetupStats.Label.SLOT, String.valueOf(i + 1));
+ } else {
+ mCheckBoxes.get(i).setChecked(false);
+ }
+ }
}
}
private void updateCurrentDataSub() {
- if (isDetached()) return;
- for (int i = 0; i < mSubInfoRecords.size(); i++) {
- SubInfoRecord subInfoRecord = mSubInfoRecords.get(i);
- mCheckBoxes.get(i).setChecked(SubscriptionManager.getDefaultDataSubId()
- == subInfoRecord.subId);
+ if (mIsAttached) {
+ for (int i = 0; i < mSubInfoRecords.size(); i++) {
+ SubInfoRecord subInfoRecord = mSubInfoRecords.get(i);
+ mCheckBoxes.get(i).setChecked(SubscriptionManager.getDefaultDataSubId()
+ == subInfoRecord.subId);
+ }
}
}
private void updateCarrierText(SubInfoRecord subInfoRecord) {
- if (isDetached()) return;
- String name = mPhone.getNetworkOperatorName(subInfoRecord.subId);
- ServiceState serviceState = mServiceStates.get(subInfoRecord.slotId);
- if (TextUtils.isEmpty(name)) {
- if (serviceState != null && serviceState.isEmergencyOnly()) {
- name = getString(R.string.setup_mobile_data_emergency_only);
- } else {
- name = getString(R.string.setup_mobile_data_no_service);
+ if (mIsAttached) {
+ String name = mPhone.getNetworkOperatorName(subInfoRecord.subId);
+ ServiceState serviceState = mServiceStates.get(subInfoRecord.slotId);
+ if (TextUtils.isEmpty(name)) {
+ if (serviceState != null && serviceState.isEmergencyOnly()) {
+ name = getString(R.string.setup_mobile_data_emergency_only);
+ } else {
+ name = getString(R.string.setup_mobile_data_no_service);
+ }
}
+ String formattedName =
+ getString(R.string.data_sim_name, subInfoRecord.slotId + 1, name);
+ mNameViews.get(subInfoRecord.slotId).setText(formattedName);
}
- String formattedName =
- getString(R.string.data_sim_name, subInfoRecord.slotId + 1, name);
- mNameViews.get(subInfoRecord.slotId).setText(formattedName);
}
private void updateSignalStrength(SubInfoRecord subInfoRecord) {
- if (isDetached()) return;
- ImageView signalView = mSignalViews.get(subInfoRecord.slotId);
- SignalStrength signalStrength = mSignalStrengths.get(subInfoRecord.slotId);
- if (!hasService(subInfoRecord)) {
- signalView.setImageResource(R.drawable.ic_signal_no_signal);
- } else {
- if (signalStrength != null) {
- int resId;
- switch (signalStrength.getLevel()) {
- case 4:
- resId = R.drawable.ic_signal_4;
- break;
- case 3:
- resId = R.drawable.ic_signal_3;
- break;
- case 2:
- resId = R.drawable.ic_signal_2;
- break;
- case 1:
- resId = R.drawable.ic_signal_1;
- break;
- default:
- resId = R.drawable.ic_signal_0;
- break;
+ if (mIsAttached) {
+ ImageView signalView = mSignalViews.get(subInfoRecord.slotId);
+ SignalStrength signalStrength = mSignalStrengths.get(subInfoRecord.slotId);
+ if (!hasService(subInfoRecord)) {
+ signalView.setImageResource(R.drawable.ic_signal_no_signal);
+ } else {
+ if (signalStrength != null) {
+ int resId;
+ switch (signalStrength.getLevel()) {
+ case 4:
+ resId = R.drawable.ic_signal_4;
+ break;
+ case 3:
+ resId = R.drawable.ic_signal_3;
+ break;
+ case 2:
+ resId = R.drawable.ic_signal_2;
+ break;
+ case 1:
+ resId = R.drawable.ic_signal_1;
+ break;
+ default:
+ resId = R.drawable.ic_signal_0;
+ break;
+ }
+ signalView.setImageResource(resId);
}
- signalView.setImageResource(resId);
}
+ updateCarrierText(subInfoRecord);
}
- updateCarrierText(subInfoRecord);
}
private boolean hasService(SubInfoRecord subInfoRecord) {
diff --git a/src/com/cyanogenmod/setupwizard/setup/MobileDataPage.java b/src/com/cyanogenmod/setupwizard/setup/MobileDataPage.java
index de43188..2d4fecb 100644
--- a/src/com/cyanogenmod/setupwizard/setup/MobileDataPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/MobileDataPage.java
@@ -16,7 +16,6 @@
package com.cyanogenmod.setupwizard.setup;
-import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
@@ -79,21 +78,25 @@ public class MobileDataPage extends SetupPage {
private SignalStrength mSignalStrength;
private ServiceState mServiceState;
+ private boolean mIsAttached = false;
+
private PhoneStateListener mPhoneStateListener =
new PhoneStateListener(SubscriptionManager.getDefaultDataSubId()) {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
- if (isDetached()) return;
- mSignalStrength = signalStrength;
- updateSignalStrength();
+ if (mIsAttached) {
+ mSignalStrength = signalStrength;
+ updateSignalStrength();
+ }
}
@Override
public void onServiceStateChanged(ServiceState state) {
- if (isDetached()) return;
- mServiceState = state;
- updateSignalStrength();
+ if (mIsAttached) {
+ mServiceState = state;
+ updateSignalStrength();
+ }
}
};
@@ -129,66 +132,66 @@ public class MobileDataPage extends SetupPage {
@Override
public void onResume() {
super.onResume();
- updateDataConnectionStatus();
- updateSignalStrength();
- }
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
+ mIsAttached = true;
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
mPhone.listen(mPhoneStateListener,
PhoneStateListener.LISTEN_SERVICE_STATE
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
+ updateDataConnectionStatus();
+ updateSignalStrength();
}
@Override
- public void onDetach() {
+ public void onPause() {
+ super.onPause();
+ mIsAttached = false;
mPhone.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
- super.onDetach();
}
private void updateCarrierText() {
- if (isDetached()) return;
- String name = mPhone.getNetworkOperatorName(SubscriptionManager.getDefaultDataSubId());
- if (TextUtils.isEmpty(name)) {
- if (mServiceState != null && mServiceState.isEmergencyOnly()) {
- name = getString(R.string.setup_mobile_data_emergency_only);
- } else {
- name = getString(R.string.setup_mobile_data_no_service);
+ if (mIsAttached) {
+ String name =
+ mPhone.getNetworkOperatorName(SubscriptionManager.getDefaultDataSubId());
+ if (TextUtils.isEmpty(name)) {
+ if (mServiceState != null && mServiceState.isEmergencyOnly()) {
+ name = getString(R.string.setup_mobile_data_emergency_only);
+ } else {
+ name = getString(R.string.setup_mobile_data_no_service);
+ }
}
+ mNameView.setText(name);
}
- mNameView.setText(name);
}
private void updateSignalStrength() {
- if (isDetached()) return;
- if (!hasService()) {
- mSignalView.setImageResource(R.drawable.ic_signal_no_signal);
- } else {
- if (mSignalStrength != null) {
- int resId;
- switch (mSignalStrength.getLevel()) {
- case 4:
- resId = R.drawable.ic_signal_4;
- break;
- case 3:
- resId = R.drawable.ic_signal_3;
- break;
- case 2:
- resId = R.drawable.ic_signal_2;
- break;
- case 1:
- resId = R.drawable.ic_signal_1;
- break;
- default:
- resId = R.drawable.ic_signal_0;
- break;
+ if (mIsAttached) {
+ if (!hasService()) {
+ mSignalView.setImageResource(R.drawable.ic_signal_no_signal);
+ } else {
+ if (mSignalStrength != null) {
+ int resId;
+ switch (mSignalStrength.getLevel()) {
+ case 4:
+ resId = R.drawable.ic_signal_4;
+ break;
+ case 3:
+ resId = R.drawable.ic_signal_3;
+ break;
+ case 2:
+ resId = R.drawable.ic_signal_2;
+ break;
+ case 1:
+ resId = R.drawable.ic_signal_1;
+ break;
+ default:
+ resId = R.drawable.ic_signal_0;
+ break;
+ }
+ mSignalView.setImageResource(resId);
}
- mSignalView.setImageResource(resId);
}
+ updateCarrierText();
}
- updateCarrierText();
}
private void updateDataConnectionStatus() {