Browse Source

Settings should utilize .apply() instead of .commit()

master
Anthony Restaino 10 years ago
parent
commit
7f8253b470
  1. 10
      src/acr/browser/lightning/AdvancedSettingsActivity.java
  2. 16
      src/acr/browser/lightning/DisplaySettingsActivity.java
  3. 22
      src/acr/browser/lightning/GeneralSettingsActivity.java
  4. 12
      src/acr/browser/lightning/PrivacySettingsActivity.java
  5. 32
      src/acr/browser/lightning/SettingsActivity.java

10
src/acr/browser/lightning/AdvancedSettingsActivity.java

@ -24,8 +24,6 @@ import android.widget.TextView; @@ -24,8 +24,6 @@ import android.widget.TextView;
public class AdvancedSettingsActivity extends ActionBarActivity {
// mPreferences variables
private static final int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences mPreferences;
private SharedPreferences.Editor mEditPrefs;
private CheckBox cbAllowPopups, cbAllowCookies, cbAllowIncognitoCookies, cbRestoreTabs;
@ -119,7 +117,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity { @@ -119,7 +117,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.POPUPS, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -131,7 +129,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity { @@ -131,7 +129,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.COOKIES, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -143,7 +141,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity { @@ -143,7 +141,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.INCOGNITO_COOKIES, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -155,7 +153,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity { @@ -155,7 +153,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.RESTORE_LOST_TABS, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});

16
src/acr/browser/lightning/DisplaySettingsActivity.java

@ -4,7 +4,6 @@ @@ -4,7 +4,6 @@
package acr.browser.lightning;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -22,11 +21,9 @@ import android.widget.RelativeLayout; @@ -22,11 +21,9 @@ import android.widget.RelativeLayout;
public class DisplaySettingsActivity extends ActionBarActivity {
// mPreferences variables
private static final int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences mPreferences;
private SharedPreferences.Editor mEditPrefs;
private CheckBox cbHideStatusBar, cbFullScreen, cbWideViewPort, cbOverView, cbTextReflow;
private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -49,7 +46,6 @@ public class DisplaySettingsActivity extends ActionBarActivity { @@ -49,7 +46,6 @@ public class DisplaySettingsActivity extends ActionBarActivity {
// commit() or apply() call
mEditPrefs = mPreferences.edit();
mContext = this;
initialize();
}
@ -101,7 +97,7 @@ public class DisplaySettingsActivity extends ActionBarActivity { @@ -101,7 +97,7 @@ public class DisplaySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.HIDE_STATUS_BAR, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -113,7 +109,7 @@ public class DisplaySettingsActivity extends ActionBarActivity { @@ -113,7 +109,7 @@ public class DisplaySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.FULL_SCREEN, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -126,7 +122,7 @@ public class DisplaySettingsActivity extends ActionBarActivity { @@ -126,7 +122,7 @@ public class DisplaySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.USE_WIDE_VIEWPORT, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -138,7 +134,7 @@ public class DisplaySettingsActivity extends ActionBarActivity { @@ -138,7 +134,7 @@ public class DisplaySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.OVERVIEW_MODE, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -150,7 +146,7 @@ public class DisplaySettingsActivity extends ActionBarActivity { @@ -150,7 +146,7 @@ public class DisplaySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.TEXT_REFLOW, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
}
@ -229,7 +225,7 @@ public class DisplaySettingsActivity extends ActionBarActivity { @@ -229,7 +225,7 @@ public class DisplaySettingsActivity extends ActionBarActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.TEXT_SIZE, which + 1);
mEditPrefs.commit();
mEditPrefs.apply();
}
});

22
src/acr/browser/lightning/GeneralSettingsActivity.java

@ -187,7 +187,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -187,7 +187,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.SEARCH, which);
mEditPrefs.commit();
mEditPrefs.apply();
switch (which) {
case 0:
searchUrlPicker();
@ -255,7 +255,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -255,7 +255,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
public void onClick(DialogInterface dialog, int which) {
String text = getSearchUrl.getText().toString();
mEditPrefs.putString(PreferenceConstants.SEARCH_URL, text);
mEditPrefs.commit();
mEditPrefs.apply();
mSearchText.setText(getResources().getString(R.string.custom_url) + ": "
+ text);
}
@ -277,7 +277,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -277,7 +277,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.USER_AGENT, which + 1);
mEditPrefs.commit();
mEditPrefs.apply();
switch (which + 1) {
case 1:
mAgentTextView.setText(getResources().getString(
@ -337,7 +337,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -337,7 +337,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
public void onClick(DialogInterface dialog, int which) {
String text = getAgent.getText().toString();
mEditPrefs.putString(PreferenceConstants.USER_AGENT_STRING, text);
mEditPrefs.commit();
mEditPrefs.apply();
mAgentTextView.setText(getResources().getString(R.string.agent_custom));
}
});
@ -372,7 +372,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -372,7 +372,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
mEditPrefs.putString(
PreferenceConstants.DOWNLOAD_DIRECTORY,
Environment.DIRECTORY_DOWNLOADS);
mEditPrefs.commit();
mEditPrefs.apply();
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/'
+ Environment.DIRECTORY_DOWNLOADS);
break;
@ -415,7 +415,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -415,7 +415,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
public void onClick(DialogInterface dialog, int which) {
String text = getHome.getText().toString();
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, text);
mEditPrefs.commit();
mEditPrefs.apply();
mHomepageText.setText(text);
}
});
@ -461,7 +461,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -461,7 +461,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
public void onClick(DialogInterface dialog, int which) {
String text = getDownload.getText().toString();
mEditPrefs.putString(PreferenceConstants.DOWNLOAD_DIRECTORY, text);
mEditPrefs.commit();
mEditPrefs.apply();
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/' + text);
}
});
@ -498,21 +498,21 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -498,21 +498,21 @@ public class GeneralSettingsActivity extends ActionBarActivity {
case 1:
mEditPrefs.putString(PreferenceConstants.HOMEPAGE,
"about:home");
mEditPrefs.commit();
mEditPrefs.apply();
mHomepageText.setText(getResources().getString(
R.string.action_homepage));
break;
case 2:
mEditPrefs.putString(PreferenceConstants.HOMEPAGE,
"about:blank");
mEditPrefs.commit();
mEditPrefs.apply();
mHomepageText.setText(getResources().getString(
R.string.action_blank));
break;
case 3:
mEditPrefs.putString(PreferenceConstants.HOMEPAGE,
"about:bookmarks");
mEditPrefs.commit();
mEditPrefs.apply();
mHomepageText.setText(getResources().getString(
R.string.action_bookmarks));
@ -544,7 +544,7 @@ public class GeneralSettingsActivity extends ActionBarActivity { @@ -544,7 +544,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});

12
src/acr/browser/lightning/PrivacySettingsActivity.java

@ -188,7 +188,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -188,7 +188,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.LOCATION, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -200,7 +200,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -200,7 +200,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.SAVE_PASSWORDS, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -212,7 +212,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -212,7 +212,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -224,7 +224,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -224,7 +224,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -236,7 +236,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -236,7 +236,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -248,7 +248,7 @@ public class PrivacySettingsActivity extends ActionBarActivity { @@ -248,7 +248,7 @@ public class PrivacySettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});

32
src/acr/browser/lightning/SettingsActivity.java

@ -88,7 +88,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -88,7 +88,7 @@ public class SettingsActivity extends ActionBarActivity {
if (API >= 19) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
mEditPrefs.commit();
mEditPrefs.apply();
}
int flashNum = mPreferences.getInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
boolean imagesBool = mPreferences.getBoolean(PreferenceConstants.BLOCK_IMAGES, false);
@ -204,7 +204,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -204,7 +204,7 @@ public class SettingsActivity extends ActionBarActivity {
getFlashChoice();
} else {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
mEditPrefs.commit();
mEditPrefs.apply();
}
boolean flashInstalled = false;
@ -223,7 +223,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -223,7 +223,7 @@ public class SettingsActivity extends ActionBarActivity {
.getString(R.string.dialog_adobe_not_installed));
buttonView.setChecked(false);
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
mEditPrefs.commit();
mEditPrefs.apply();
} else if ((API >= 17) && isChecked) {
Utils.createInformativeDialog(SettingsActivity.this,
@ -238,7 +238,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -238,7 +238,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_ADS, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -247,7 +247,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -247,7 +247,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_IMAGES, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
@ -257,7 +257,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -257,7 +257,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.JAVASCRIPT, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
@ -272,7 +272,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -272,7 +272,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
@ -282,7 +282,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -282,7 +282,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.ENABLE_COLOR_MODE, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
@ -299,7 +299,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -299,7 +299,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onClick(DialogInterface dialog, int id) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 1);
mEditPrefs.commit();
mEditPrefs.apply();
}
})
.setNegativeButton(getResources().getString(R.string.action_auto),
@ -308,14 +308,14 @@ public class SettingsActivity extends ActionBarActivity { @@ -308,14 +308,14 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 2);
mEditPrefs.commit();
mEditPrefs.apply();
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
mEditPrefs.commit();
mEditPrefs.apply();
}
});
@ -333,7 +333,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -333,7 +333,7 @@ public class SettingsActivity extends ActionBarActivity {
n = 1;
}
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, n);
mEditPrefs.commit();
mEditPrefs.apply();
boolean flashInstalled = false;
try {
PackageManager pm = getPackageManager();
@ -350,7 +350,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -350,7 +350,7 @@ public class SettingsActivity extends ActionBarActivity {
.getString(R.string.dialog_adobe_not_installed));
buttonView.setChecked(false);
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
mEditPrefs.commit();
mEditPrefs.apply();
} else if ((API > 17) && isChecked) {
Utils.createInformativeDialog(SettingsActivity.this,
@ -365,7 +365,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -365,7 +365,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_IMAGES, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
@ -375,7 +375,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -375,7 +375,7 @@ public class SettingsActivity extends ActionBarActivity {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.JAVASCRIPT, isChecked);
mEditPrefs.commit();
mEditPrefs.apply();
}
@ -396,7 +396,7 @@ public class SettingsActivity extends ActionBarActivity { @@ -396,7 +396,7 @@ public class SettingsActivity extends ActionBarActivity {
public void onClick(DialogInterface dialog, int which) {
String text = getAgent.getText().toString();
mEditPrefs.putString(PreferenceConstants.USER_AGENT_STRING, text);
mEditPrefs.commit();
mEditPrefs.apply();
getAgent.setText(getResources().getString(R.string.agent_custom));
}
});

Loading…
Cancel
Save