java类android.preference.PreferenceManager的实例源码

GcmMessageHandler.java 文件源码 项目:Android_watch_magpie 阅读 30 收藏 0 点赞 0 评论 0
private void processSubscriptionRequest(Bundle data) {

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        long pubId = preferences.getLong(MobileClient.PUBLISHER_ID, 0);

        // The id must be parsed, as it is in fact a String
        long subId = Long.parseLong(data.getString(SUBSCRIBER_ID));
        String subUsername = data.getString(SUBSCRIBER_USERNAME);
        int notificationId = 1;

        // Pending Intent for the Reject action
        PendingIntent rejectPendingIntent = createPendingIntentForActions(
                NotificationProcessorReceiver.ACTION_REJECT, pubId, subId, subUsername, notificationId);

        // Pending Intent for the Accept action
        PendingIntent acceptPendingIntent = createPendingIntentForActions(
                NotificationProcessorReceiver.ACTION_ACCEPT, pubId, subId, subUsername, notificationId);

        Notification.Builder notificationBuilder = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("MAGPIE Notification")
                .setContentText("Subscription request from " + subUsername)
                .addAction(R.drawable.abc_ic_clear_material, "Reject", rejectPendingIntent)
                .addAction(R.drawable.ic_done_black_24dp, "Accept", acceptPendingIntent);

        Notification notification = notificationBuilder.build();
        notification.flags |= Notification.FLAG_NO_CLEAR;

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationId, notification);
    }
SystemWebView.java 文件源码 项目:firefox-tv 阅读 25 收藏 0 点赞 0 评论 0
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        TelemetryAutofillCallback.INSTANCE.register(getContext());
    }
}
RxPreferences_Demo.java 文件源码 项目:Go-RxJava 阅读 21 收藏 0 点赞 0 评论 0
@Override
protected void init() {
    super.init();
    btn_submit.setText("查看变量");
    editText=new EditText(getActivity());
    checkBox=new CheckBox(getActivity());
    checkBox.setText("是否为男性");
    container.addView(checkBox);
    container.addView(editText);
    //创建实例
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    RxSharedPreferences rxPreferences = RxSharedPreferences.create(preferences);

    //创建个人
    pre_username = rxPreferences.getString("username");
    pre_sex= rxPreferences.getBoolean("sex", true);

    //绑定
    RxCompoundButton.checkedChanges(checkBox)
            .subscribe(pre_sex.asAction());

    RxTextView.textChanges(editText)
            .flatMap(new Func1<CharSequence, Observable<String>>() {
                @Override
                public Observable<String> call(final CharSequence charSequence) {
                    return Observable.create(new Observable.OnSubscribe<String>() {
                        @Override
                        public void call(Subscriber<? super String> subscriber) {
                            subscriber.onNext(charSequence.toString());
                            subscriber.onCompleted();
                        }
                    });
                }
            })
        .subscribe(pre_username.asAction());
}
ServiceTileLockdown.java 文件源码 项目:MKAPP 阅读 19 收藏 0 点赞 0 评论 0
private void update() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean lockdown = prefs.getBoolean("lockdown", false);
    Tile tile = getQsTile();
    if (tile != null) {
        tile.setState(lockdown ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
        tile.updateTile();
    }
}
SettingsActivity.java 文件源码 项目:MuslimMateAndroid 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    locationInfo = ConfigPreferences.getLocationConfig(getActivity());
    //disable and enable praying notification related setting
    if (ConfigPreferences.getPrayingNotification(getActivity()) == false) {
        getPreferenceScreen().findPreference("silent").setEnabled(false);
        getPreferenceScreen().findPreference("vibration").setEnabled(false);
        getPreferenceScreen().findPreference("led").setEnabled(false);
    }

    //disable or enable silent related settings
    if(ConfigPreferences.getSilentMood(getActivity()) == false){
        getPreferenceScreen().findPreference("vibration").setEnabled(false);
    }

    if (locationInfo != null) {
        Log.i("DATA_SETTING" ,"locationInfo.dls : "+(locationInfo.dls > 0));
        CheckBoxPreference checked = (CheckBoxPreference) getPreferenceScreen().findPreference("day_light");
        checked.setChecked(locationInfo.dls > 0);
        ListPreference wayPref = (ListPreference) getPreferenceScreen().findPreference("calculations");
        Log.i("DATA_SETTING" ,"locationInfo.way : "+locationInfo.way);
        wayPref.setValueIndex(locationInfo.way);
        ListPreference mazhapPref = (ListPreference) getPreferenceScreen().findPreference("mazhab");
        mazhapPref.setValueIndex(locationInfo.mazhab);
        Log.i("DATA_SETTING" ,"locationInfo.mazhab : "+locationInfo.mazhab);
    }

    listPreference = (ListPreference) findPreference("language");
    String lang = ConfigPreferences.getApplicationLanguage(getActivity()).equalsIgnoreCase("en") ? "English" : "العربية";
    listPreference.setSummary(getString(R.string.language_summary)
            + "  (" + lang + ") ");

}
UISettings.java 文件源码 项目:Phoenix-for-VK 阅读 23 收藏 0 点赞 0 评论 0
@NightMode
@Override
public int getNightMode() {
    String mode = PreferenceManager.getDefaultSharedPreferences(app)
            .getString("night_switch", String.valueOf(NightMode.DISABLE));
    //noinspection ResourceType
    return Integer.parseInt(mode);
}
MainActivity.java 文件源码 项目:Weather365 阅读 16 收藏 0 点赞 0 评论 0
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getString("weather", null) != null) {
        Intent intent = new Intent(this, WeatherActivity.class);
        startActivity(intent);
        finish();
    }
}
EditorView.java 文件源码 项目:Auto.js 阅读 32 收藏 0 点赞 0 评论 0
public void selectEditorTheme() {
    String[] themes = mEditor.getAvailableThemes();
    int i = Arrays.asList(themes).indexOf(mEditor.getTheme());
    new MaterialDialog.Builder(getContext())
            .title(R.string.text_editor_theme)
            .items((CharSequence[]) themes)
            .itemsCallbackSingleChoice(i, (dialog, itemView, which, text) -> {
                PreferenceManager.getDefaultSharedPreferences(getContext()).edit()
                        .putString(KEY_EDITOR_THEME, text.toString())
                        .apply();
                setTheme(text.toString());
                return true;
            })
            .show();
}
FileExplorerActivity.java 文件源码 项目:android-project-gallery 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 设置根目录回调
 */
@Override
public void onActivityResult(int request_code, int result_code, Intent intent)
{
    if (request_code == RC_SET_FILE_ROOT)
    {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        boolean value = preferences.getBoolean("list_folders_first", true);
        if (value != foldersUp)
        {
            showDirectoryContents(currentPath);
        }
    }
}
KeyboardAwareLinearLayout.java 文件源码 项目:Nird2 阅读 18 收藏 0 点赞 0 评论 0
private int getKeyboardPortraitHeight() {
    SharedPreferences prefs =
            PreferenceManager.getDefaultSharedPreferences(getContext());
    int keyboardHeight = prefs.getInt("keyboard_height_portrait",
            defaultCustomKeyboardSize);
    return clamp(keyboardHeight, minCustomKeyboardSize,
            getRootView().getHeight() - minCustomKeyboardTopMargin);
}


问题


面经


文章

微信
公众号

扫码关注公众号