当前位置: 首页>>代码示例>>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;未经允许,请勿转载。