當前位置: 首頁>>代碼示例>>Java>>正文


Java Activity.getPreferences方法代碼示例

本文整理匯總了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();
    }
 
開發者ID:marc-urschick,項目名稱:a_whattobuy,代碼行數:21,代碼來源:SettingsService.java

示例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);


    }
}
 
開發者ID:jboss-outreach,項目名稱:lead-management-android,代碼行數:26,代碼來源:SettingsFragment.java

示例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());
    }
}
 
開發者ID:marc-urschick,項目名稱:a_whattobuy,代碼行數:10,代碼來源:SettingsService.java

示例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;
}
 
開發者ID:ericberman,項目名稱:MyFlightbookAndroid,代碼行數:15,代碼來源:MFBFlightListener.java

示例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();
}
 
開發者ID:dmtan90,項目名稱:Sense-Hub-Android-Things,代碼行數:39,代碼來源:StorageUtils.java

示例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();
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:15,代碼來源:OAuth2Helper.java

示例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;
}
 
開發者ID:tejashah88,項目名稱:LiterWrite,代碼行數:8,代碼來源:LocalDatabase.java

示例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";
	}
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:16,代碼來源:WebViewDialog.java

示例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);

        }
    }
 
開發者ID:mcr222,項目名稱:pass_the_bomb,代碼行數:46,代碼來源:InstructionsActivity.java

示例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);
}
 
開發者ID:ericberman,項目名稱:MyFlightbookAndroid,代碼行數:5,代碼來源:MFBFlightListener.java


注:本文中的android.app.Activity.getPreferences方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。