本文整理匯總了Java中android.app.Activity.getPreferences方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.getPreferences方法的具體用法?Java Activity.getPreferences怎麽用?Java Activity.getPreferences使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Activity
的用法示例。
在下文中一共展示了Activity.getPreferences方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveSettings
import android.app.Activity; //導入方法依賴的package包/類
public void saveSettings(Activity c) {
SharedPreferences pref = c.getPreferences(Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = pref.edit();
for (Map.Entry<String, Object> e : settings.entrySet()) {
Log.d("Settings", e.getKey() + ": " + e.getValue());
editor.putString(e.getKey(), e.getValue().toString());
}
// editor.commit();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
editor.commit();
}
}, "settings-saver");
t.setDaemon(true);
t.start();
}
示例2: onCreatePreferences
import android.app.Activity; //導入方法依賴的package包/類
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.settings_preferences);
if(getActivity()!=null) {
Activity mActivity = getActivity();
final SharedPreferences sharedPref = mActivity.getPreferences(Context.MODE_PRIVATE);
final String currentServer = sharedPref.getString(getString(R.string.saved_server_ip), "https://github.com/jboss-outreach");
final EditTextPreference mPreference = (EditTextPreference) findPreference("server_location");
final SwitchPreference mToggleMode = (SwitchPreference) findPreference("dark_theme");
mToggleMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mActivity.startActivity(new Intent(mActivity, MainActivity.class));
mActivity.finish();
return true;
}
});
mPreference.setSummary(currentServer);
mPreference.setText(currentServer);
}
}
示例3: loadSettings
import android.app.Activity; //導入方法依賴的package包/類
public void loadSettings(Activity c) {
SharedPreferences sp = c.getPreferences(Context.MODE_PRIVATE);
Map<String, ?> all = sp.getAll();
for (Map.Entry<String, ?> e : all.entrySet()) {
settings.put(e.getKey(), e.getValue());
}
}
示例4: saveCurrentFlightId
import android.app.Activity; //導入方法依賴的package包/類
public long saveCurrentFlightId(Activity a) {
long i = -1;
if (a == null) // shouldn't ever be, but sometimes is.
return i;
if (m_leNewFlight != null && m_leNewFlight.IsNewFlight()) {
SharedPreferences mPrefs = a.getPreferences(Activity.MODE_PRIVATE);
SharedPreferences.Editor ed = mPrefs.edit();
ed.putLong(keyInProgressId, m_leNewFlight.idLocalDB);
i = m_leNewFlight.idLocalDB;
ed.apply();
}
return i;
}
示例5: storeIrCodeData
import android.app.Activity; //導入方法依賴的package包/類
public static boolean storeIrCodeData(Context context, Rm3IrCodeData mIrCode){
Activity activity = (Activity) context;
SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
String mCmdPwrOn = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrPwrOn().getIrCodeData()),
Base64.NO_WRAP);
String mCmdPwrOff = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrPwrOff().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp16 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp16().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp18 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp18().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp20 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp20().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp22 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp22().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp24 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp24().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp26 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp26().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp28 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp28().getIrCodeData()),
Base64.NO_WRAP);
String mCmdTemp30 = Base64.encodeToString(PacketData.ConvertToByteArray(mIrCode.getIrTemp30().getIrCodeData()),
Base64.NO_WRAP);
editor.putString("AIR_CONDITIONER_CMD_PWR_ON", mCmdPwrOn);
editor.putString("AIR_CONDITIONER_CMD_PWR_OFF", mCmdPwrOff);
editor.putString("AIR_CONDITIONER_CMD_TMP_16", mCmdTemp16);
editor.putString("AIR_CONDITIONER_CMD_TMP_18", mCmdTemp18);
editor.putString("AIR_CONDITIONER_CMD_TMP_20", mCmdTemp20);
editor.putString("AIR_CONDITIONER_CMD_TMP_22", mCmdTemp22);
editor.putString("AIR_CONDITIONER_CMD_TMP_24", mCmdTemp24);
editor.putString("AIR_CONDITIONER_CMD_TMP_26", mCmdTemp26);
editor.putString("AIR_CONDITIONER_CMD_TMP_28", mCmdTemp28);
editor.putString("AIR_CONDITIONER_CMD_TMP_30", mCmdTemp30);
return editor.commit();
}
示例6: resetAccountCredential
import android.app.Activity; //導入方法依賴的package包/類
/**
* Forget the account name and authToken. With no account name the app will prompt
* the user to select a new account. This method is mostly used for testing purposes.
*
* @param activity
*/
public static void resetAccountCredential(Activity activity) {
Log.i(TAG, "Reset credentials");
SharedPreferences settings = activity.getPreferences(Activity.MODE_PRIVATE);
SharedPreferences.Editor editor2 = settings.edit();
editor2.remove(PREF_AUTH_TOKEN);
editor2.remove(PREF_ACCOUNT_NAME);
editor2.commit();
}
示例7: loadInfo
import android.app.Activity; //導入方法依賴的package包/類
public void loadInfo(Activity act) {
sharedPrefs = act.getPreferences(MODE_PRIVATE);
originLang = sharedPrefs.getString("origin-lang", "english");
destLang = sharedPrefs.getString("dest-lang", "english");
firstTime = sharedPrefs.getBoolean("first-time", true);
infoLoaded = true;
}
示例8: checkVersionAndShowWhatsNewIfNeeded
import android.app.Activity; //導入方法依賴的package包/類
public static String checkVersionAndShowWhatsNewIfNeeded(Activity activity) {
try {
PackageInfo info = Utils.getPackageInfo(activity);
SharedPreferences preferences = activity.getPreferences(0);
int newVersionCode = info.versionCode;
int oldVersionCode = preferences.getInt("versionCode", -1);
if (newVersionCode > oldVersionCode) {
preferences.edit().putInt("versionCode", newVersionCode).commit();
showWhatsNew(activity);
}
return "v. "+info.versionName;
} catch(Exception ex) {
return "Free";
}
}
示例9: showInstructions
import android.app.Activity; //導入方法依賴的package包/類
/**
* Shows the instructions overlay over the activity specified if they have not been showed before
* @param activity activity onto which to overlay instructions
*/
public static void showInstructions(Activity activity) {
//this is a global variable that is stored with the app memory in the phone forever in order to know
//whether instructions have been shown before or not, as we do not want to show instructions
//all the time the app is started
String preferenceKeyword = "RanBefore_" + activity.getLocalClassName();
System.out.println(preferenceKeyword);
SharedPreferences preferences = activity.getPreferences(MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean(preferenceKeyword, false);
//TODO: remove this
// String mode;
// if(activity.getClass().equals(MainActivity.class)) {
// mode = INSTRUCTION_MAIN;
// } else {
// mode = INSTRUCTION_NEW;
// }
System.out.println(mainAlready);
System.out.println(newAlready);
//TODO: change de if with the commented if below when ready to deploy app
if (!ranBefore) {
//if((mode.equals(INSTRUCTION_MAIN) && !mainAlready) || (mode.equals(INSTRUCTION_NEW) && !newAlready) ) {
//sets the value of the long term variable to true (meaning that instructions have been
//shown already for the specific activity).
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(preferenceKeyword, true);
editor.commit();
Intent intent = new Intent(activity.getApplicationContext(), InstructionsActivity.class);
if (activity.getClass().equals(MainActivity.class)) {
intent.putExtra(INSTRUCTION, INSTRUCTION_MAIN);
mainAlready = true;
} else {
intent.putExtra(INSTRUCTION, INSTRUCTION_NEW);
newAlready = true;
}
//start instructions activity
activity.startActivity(intent);
}
}
示例10: getInProgressFlightId
import android.app.Activity; //導入方法依賴的package包/類
private static long getInProgressFlightId(Activity a) {
SharedPreferences mPrefs = a.getPreferences(Activity.MODE_PRIVATE);
return mPrefs.getLong(keyInProgressId, LogbookEntry.ID_NEW_FLIGHT);
}