当前位置: 首页>>代码示例>>Java>>正文


Java PreferenceManager类代码示例

本文整理汇总了Java中android.preference.PreferenceManager的典型用法代码示例。如果您正苦于以下问题:Java PreferenceManager类的具体用法?Java PreferenceManager怎么用?Java PreferenceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PreferenceManager类属于android.preference包,在下文中一共展示了PreferenceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

import android.preference.PreferenceManager; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    int reminderId = intent.getIntExtra("NOTIFICATION_ID", 0);

    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("checkBoxNagging", false)) {
        Intent alarmIntent = new Intent(context, NagReceiver.class);
        AlarmUtil.cancelAlarm(context, alarmIntent, reminderId);
    }

    // Close notification tray
    Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    context.sendBroadcast(closeIntent);

    Intent snoozeIntent = new Intent(context, SnoozeDialogActivity.class);
    snoozeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    snoozeIntent.putExtra("NOTIFICATION_ID", reminderId);
    context.startActivity(snoozeIntent);
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:19,代码来源:SnoozeActionReceiver.java

示例2: areNotificationsEnabled

import android.preference.PreferenceManager; //导入依赖的package包/类
/**
 * Returns true if the user prefers to see notifications from Sunshine, false otherwise. This
 * preference can be changed by the user within the SettingsFragment.
 *
 * @param context Used to access SharedPreferences
 * @return true if the user prefers to see notifications, false otherwise
 */
public static boolean areNotificationsEnabled(Context context) {
    /* Key for accessing the preference for showing notifications */
    String displayNotificationsKey = context.getString(R.string.pref_enable_notifications_key);

    /*
     * In Sunshine, the user has the ability to say whether she would like notifications
     * enabled or not. If no preference has been chosen, we want to be able to determine
     * whether or not to show them. To do this, we reference a bool stored in bools.xml.
     */
    boolean shouldDisplayNotificationsByDefault = context
            .getResources()
            .getBoolean(R.bool.show_notifications_by_default);

    /* As usual, we use the default SharedPreferences to access the user's preferences */
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    /* If a value is stored with the key, we extract it here. If not, use a default. */
    boolean shouldDisplayNotifications = sp
            .getBoolean(displayNotificationsKey, shouldDisplayNotificationsByDefault);

    return shouldDisplayNotifications;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:30,代码来源:SunshinePreferences.java

示例3: GetText

import android.preference.PreferenceManager; //导入依赖的package包/类
private String GetText(float res) {

        if (!PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("DECIMAL_USE", true)) {
            DecimalFormat decimalFormat = new DecimalFormat("###############");
            return decimalFormat.format(res);
        } else {
            switch (Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("ROUNDIND_INFO", "0"))) {
                case 0:
                    return String.valueOf(res);
                case 1:
                    DecimalFormat single = new DecimalFormat("########.#");
                    return single.format(res);
                case 2:
                    DecimalFormat Double = new DecimalFormat("########.##");
                    return Double.format(res);
                case 3:
                    DecimalFormat triple = new DecimalFormat("########.###");
                    return triple.format(res);
                default:
                    return String.valueOf(res);
            }
        }
    }
 
开发者ID:coder3101,项目名称:Matrix-Calculator-for-Android,代码行数:24,代码来源:ViewMatrixFragment.java

示例4: getLocationCoordinates

import android.preference.PreferenceManager; //导入依赖的package包/类
/**
 * Returns the location coordinates associated with the location. Note that there is a
 * possibility that these coordinates may not be set, which results in (0,0) being returned.
 * Interestingly, (0,0) is in the middle of the ocean off the west coast of Africa.
 *
 * @param context used to access SharedPreferences
 * @return an array containing the two coordinate values for the user's preferred location
 */
public static double[] getLocationCoordinates(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    double[] preferredCoordinates = new double[2];

    /*
     * This is a hack we have to resort to since you can't store doubles in SharedPreferences.
     *
     * Double.doubleToLongBits returns an integer corresponding to the bits of the given
     * IEEE 754 double precision value.
     *
     * Double.longBitsToDouble does the opposite, converting a long (that represents a double)
     * into the double itself.
     */
    preferredCoordinates[0] = Double
             .longBitsToDouble(sp.getLong(PREF_COORD_LAT, Double.doubleToRawLongBits(0.0)));
    preferredCoordinates[1] = Double
            .longBitsToDouble(sp.getLong(PREF_COORD_LONG, Double.doubleToRawLongBits(0.0)));

    return preferredCoordinates;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:30,代码来源:SunshinePreferences.java

示例5: onCreate

import android.preference.PreferenceManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    frameLayout = (FrameLayout) getActivity().findViewById(R.id.content_frame);

    try {
        mahEncryptor = MAHEncryptor.newInstance(sharedPref.getString("saved_key", ""));
    } catch (Exception e) {
        e.printStackTrace();
        Snackbar.make(frameLayout, getString(R.string.toast_error), Snackbar.LENGTH_LONG).show();
    }

    addPreferencesFromResource(R.xml.user_settings_data);
    addBackup_dbListener();
    addWhiteListListener();
}
 
开发者ID:JaeNuguid,项目名称:Kids-Portal-Android,代码行数:19,代码来源:Activity_settings_data.java

示例6: onCreate

import android.preference.PreferenceManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Sets up  user interface elements.
    setContentView(R.layout.main);

    mCustomConfig = (CheckBox) findViewById(R.id.custom_app_limits);
    final boolean customChecked =
            PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
                    CUSTOM_CONFIG_KEY, false);
    if (customChecked) mCustomConfig.setChecked(true);

    mMultiEntryValue = (TextView) findViewById(R.id.multi_entry_id);
    mChoiceEntryValue = (TextView) findViewById(R.id.choice_entry_id);
    mBooleanEntryValue = (TextView) findViewById(R.id.boolean_entry_id);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:18,代码来源:MainActivity.java

示例7: readNetworkType

import android.preference.PreferenceManager; //导入依赖的package包/类
protected void readNetworkType(String fileName) {
  NetworkType defaultNetworkType;
  File directory = RobotConfigFileManager.CONFIG_FILES_DIR;
  File networkTypeFile = new File(directory, fileName);
  if (!networkTypeFile.exists()) {
    if (Build.MODEL.equals(Device.MODEL_410C)) {
      defaultNetworkType = NetworkType.SOFTAP;
    } else {
      defaultNetworkType = NetworkType.WIFIDIRECT;
    }
    writeNetworkTypeFile(NETWORK_TYPE_FILENAME, defaultNetworkType.toString());
  }

  String fileContents = readFile(networkTypeFile);
  networkType = NetworkConnectionFactory.getTypeFromString(fileContents);
  programmingModeController.setCurrentNetworkType(networkType);

  // update the preferences
  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
  SharedPreferences.Editor editor = preferences.edit();
  editor.putString(NetworkConnectionFactory.NETWORK_CONNECTION_TYPE, networkType.toString());
  editor.commit();
}
 
开发者ID:TheBigBombman,项目名称:RobotIGS,代码行数:24,代码来源:FtcRobotControllerActivity.java

示例8: getUserName

import android.preference.PreferenceManager; //导入依赖的package包/类
public String getUserName() {

        String ret = "";
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
        String userstring = sharedPreferences.getString("trakt_user", "");
        try {
            JSONObject trakt_user = new JSONObject(userstring);
            ret = trakt_user.getJSONObject("user").getString("username");


        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ret;


    }
 
开发者ID:ad-on-is,项目名称:chilly,代码行数:18,代码来源:Chilly.java

示例9: getLastNotificationTimeInMillis

import android.preference.PreferenceManager; //导入依赖的package包/类
/**
 * Returns the last time that a notification was shown (in UNIX time)
 *
 * @param context Used to access SharedPreferences
 * @return UNIX time of when the last notification was shown
 */
public static long getLastNotificationTimeInMillis(Context context) {
    /* Key for accessing the time at which Sunshine last displayed a notification */
    String lastNotificationKey = context.getString(R.string.pref_last_notification);

    /* As usual, we use the default SharedPreferences to access the user's preferences */
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    /*
     * Here, we retrieve the time in milliseconds when the last notification was shown. If
     * SharedPreferences doesn't have a value for lastNotificationKey, we return 0. The reason
     * we return 0 is because we compare the value returned from this method to the current
     * system time. If the difference between the last notification time and the current time
     * is greater than one day, we will show a notification again. When we compare the two
     * values, we subtract the last notification time from the current system time. If the
     * time of the last notification was 0, the difference will always be greater than the
     * number of milliseconds in a day and we will show another notification.
     */
    long lastNotificationTime = sp.getLong(lastNotificationKey, 0);

    return lastNotificationTime;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:28,代码来源:SunshinePreferences.java

示例10: onCreate

import android.preference.PreferenceManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    // Here, this is the current activity
    PreferenceManager.setDefaultValues(this, R.xml.pref_settings, false);
    if (!permissionGranted()) {
        requestPermissions();
    } else {
        if (systemInstalled()) {
            startMainActivity();
        } else {
            installSystem();
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:SplashScreenActivity.java

示例11: onCreateView

import android.preference.PreferenceManager; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_lists, container, false);
    setHasOptionsMenu(true);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    editText = (EditText) getActivity().findViewById(R.id.editText);
    listBar = (TextView) getActivity().findViewById(R.id.listBar);
    listView = (ListView)rootView.findViewById(R.id.list);
    viewPager = (class_CustomViewPager) getActivity().findViewById(R.id.viewpager);

    //calling Notes_DbAdapter
    db = new DbAdapter_Reports(getActivity());
    db.open();

    return rootView;

}
 
开发者ID:JaeNuguid,项目名称:Kids-Portal-Android,代码行数:22,代码来源:Fragment_Reports.java

示例12: setStringValue

import android.preference.PreferenceManager; //导入依赖的package包/类
/** 设置Key对应的String值 */
public static boolean setStringValue(Context context,String key, String value) {
	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
	Editor editor = prefs.edit();
	editor.putString(key, value);
	return editor.commit();
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:8,代码来源:PreferencesUtil.java

示例13: onCreate

import android.preference.PreferenceManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceManager.setDefaultValues(this, R.xml.main_preferences, false);
    getFragmentManager().beginTransaction()
            .replace(android.R.id.content, new SettingsFragment())
            .commit();
}
 
开发者ID:rootkiwi,项目名称:an2linuxclient,代码行数:9,代码来源:MainSettingsActivity.java

示例14: putLocation

import android.preference.PreferenceManager; //导入依赖的package包/类
/**
 * Saves location co-ordinates as string
 * @param context ¯\_(ツ)_/¯
 * @param longitude Longitude to be saved
 * @param latitude Latitude to be saved
 */
public static void putLocation(Context context, double longitude, double latitude) {
    PreferenceManager.getDefaultSharedPreferences(context)
            .edit()
            .putString(Constants.LAST_LOC_LONGITUDE, "" + longitude)
            .putString(Constants.LAST_LOC_LATITUDE, "" + latitude)
            .apply();
}
 
开发者ID:corphish,项目名称:NightLight,代码行数:14,代码来源:PreferenceHelper.java

示例15: isLocationLatLonAvailable

import android.preference.PreferenceManager; //导入依赖的package包/类
/**
 * Returns true if the latitude and longitude values are available. The latitude and
 * longitude will not be available until the lesson where the PlacePicker API is taught.
 *
 * @param context used to get the SharedPreferences
 * @return true if lat/long are saved in SharedPreferences
 */
public static boolean isLocationLatLonAvailable(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    boolean spContainLatitude = sp.contains(PREF_COORD_LAT);
    boolean spContainLongitude = sp.contains(PREF_COORD_LONG);

    boolean spContainBothLatitudeAndLongitude = false;
    if (spContainLatitude && spContainLongitude) {
        spContainBothLatitudeAndLongitude = true;
    }

    return spContainBothLatitudeAndLongitude;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:21,代码来源:SunshinePreferences.java


注:本文中的android.preference.PreferenceManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。