Java 类android.support.v7.preference.PreferenceManager 实例源码

项目:underlx    文件:NotifPreferenceFragment.java   
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    final String key = preference.getKey();
    if (preference instanceof MultiSelectListPreference) {
        Set<String> summary = SharedPreferencesCompat.getStringSet(
                PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
                key, new HashSet<String>());
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
    } else if (preference instanceof SeekBarPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
    } else {
        String value = PreferenceManager
                .getDefaultSharedPreferences(preference.getContext())
                .getString(key, "");
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
    }
}
项目:IslamicLibraryAndroid    文件:ReadingActivity.java   
@Override
protected void onResume() {
    super.onResume();
    SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean newIsNightMode = DisplayPreferenceUtilities.getDisplayPreference(

            SettingsFragment.KEY_IS_THEME_NIGHT_MODE,
            AppConstants.DISPLAY_PREFERENCES_DEFAULTS.IS_THEME_NIGHT_MODE,
            defaultSharedPreferences,
            mUserDataDBHelper);
    if (newIsNightMode != isThemeNightMode)
        restartOnThemeChange();
    int newZoom = getDisplayZoom();
    zoomUpdatedByValue(newZoom);
    Util.restartIfLocaleChanged(this, mIsArabic);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    boolean keepScreenOn = sharedPreferences.
            getBoolean(SettingsFragment.PREF_KEEP_SCREEN_ON, false);
    if (keepScreenOn)
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    else
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

}
项目:Neuronizer    文件:RadioDialogs.java   
public static void showSortingDialog(final Fragment fragment) {

        RadioDialogCallback callback = new RadioDialogCallback() {
            @Override
            public void which(int position) {
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(fragment.getContext());
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putInt(KEY_PREF_SORTING, position);
                editor.apply();

                SortingDialogCallback fragmentCallback = (SortingDialogCallback) fragment;
                fragmentCallback.sortBy(Sortation.parse(position));
            }
        };

        CharSequence[] items = new CharSequence[]{
                getString(fragment, R.string.sort_most_used),
                getString(fragment, R.string.sort_last_change),
                getString(fragment, R.string.sort_creation),
                getString(fragment, R.string.sort_alphabetically)
        };
        showRadioDialog(fragment.getContext(), getString(fragment, R.string.sort_dialog), items, callback);
    }
项目:Neuronizer    文件:RadioDialogs.java   
public static void showRepositoryDialog(final FragmentActivity activity) {

        final CharSequence[] repositoryNames = RepositoryManager.readRepositoryNames(activity.getApplicationContext().getFilesDir());
        RadioDialogCallback callback = new RadioDialogCallback() {
            @Override
            public void which(int position) {
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putString(KEY_PREF_ACTIVE_REPO, repositoryNames[position].toString());
                editor.apply();

                Toast.makeText(activity, activity.getResources().getString(R.string.switched_database, repositoryNames[position]), Toast.LENGTH_SHORT).show();
            }
        };
        showRadioDialog(activity, getString(activity, R.string.switch_database), repositoryNames, callback);
    }
项目:IslamicLibraryAndroid    文件:SettingsFragment.java   
/**
 * Binds a preference's summary to its value. More specifically, when the
 * preference's value is changed, its summary (line of text below the
 * preference title) is updated to reflect the value. The summary is also
 * immediately updated upon calling this method. The exact display format is
 * dependent on the type of preference.
 *
 * @see #sBindPreferenceSummaryToValueListener
 */
private static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    final String key = preference.getKey();
    if (preference instanceof MultiSelectListPreference) {
        Set<String> summary = SharedPreferencesCompat.getStringSet(
                PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
                key,
                new HashSet<>());
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
    } else if (preference instanceof ColorPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((ColorPreference) preference).getColor());
    } else if (preference instanceof SeekBarPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
    } else {
        String value = PreferenceManager
                .getDefaultSharedPreferences(preference.getContext())
                .getString(key, "");
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
    }
}
项目:Neuronizer    文件:NoteFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
    mPresenter = new DisplayNotePresenterImpl(
            ThreadExecutor.getInstance(),
            MainThreadImpl.getInstance(),
            this,
            new RepositoryImpl(repositoryName)
    );

    Bundle bundle = getArguments();
    if (bundle != null) {
        uuid = bundle.getString(KEY_UUID);
        title = bundle.getString(KEY_TITLE);
    }
}
项目:Neuronizer    文件:TodoListFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());

    Bundle bundle = getArguments();
    if (bundle != null) {
        uuid = bundle.getString(KEY_UUID);
        title = bundle.getString(KEY_TITLE);
    }

    String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
    // create a presenter for this view
    mPresenter = new DisplayTodoListPresenterImpl(
            ThreadExecutor.getInstance(),
            MainThreadImpl.getInstance(),
            this,
            new RepositoryImpl(repositoryName)
    );
}
项目:Neuronizer    文件:IntroActivity.java   
@Override
public void onDonePressed(Fragment currentFragment) {
    super.onDonePressed(currentFragment);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    switch (type) {
        case KEY_PREVIEW:
            editor.putBoolean(KEY_PREF_PREVIEW_INTRO_SHOWN, true);
            break;
        case KEY_TODO_LIST:
            editor.putBoolean(KEY_PREF_TODO_LIST_INTRO_SHOWN, true);
            break;
        default:
            throw new IllegalArgumentException(String.format("Unknown type %s", type));
    }
    editor.apply();

    startActivity(MainActivity.newInstace(this, type, uuid, title));
    finish();
}
项目:FakeLock    文件:SettingsFragment.java   
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

    settingsPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());

    // Load the Preferences from the XML file
    addPreferencesFromResource(R.xml.settings_preferences);

    Preference backgroundPreference = (Preference) findPreference(SettingsPreferencesKeys.
            BACKGROUND_PREFERENCE_KEY);
    backgroundPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"),
                    PICK_IMAGE_REQUEST);
            return true;
        }
    });
}
项目:Camera-warner    文件:MapsActivity.java   
private void redrawLocationOnMap()
{
    if(locationMarker!=null)
    {
        LatLng markerLocation = locationMarker.getPosition();

        if (!followed) {
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(markerLocation, 15));
            followed = true;
        }

        locationMarker = mMap.addMarker(new MarkerOptions().position(markerLocation).title("Your location"));

        if (radiusCircle != null) {
            radiusCircle.remove();
        }
        radiusCircle = mMap.addCircle(new CircleOptions().center(locationMarker.getPosition()).radius(Double.parseDouble(PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default)))).fillColor(Color.argb(195, 102, 147, 173)));
    }
    else
    {
        Log.d("MapsActivity", "redrawLocationOnMap called with null==locationMarker");
    }
}
项目:Camera-warner    文件:MapsActivity.java   
private void updateLocationOnMap(@NonNull Location location) {
    if (locationMarker != null) {
        locationMarker.remove();
    }

    LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());
    if (!followed) {
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 15));
        followed = true;
    }

    locationMarker = mMap.addMarker(new MarkerOptions().position(userLocation).title("Your location"));

    if (radiusCircle != null) {
        radiusCircle.remove();
    }
    radiusCircle = mMap.addCircle(new CircleOptions().center(locationMarker.getPosition()).radius(Double.parseDouble(PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default)))).fillColor(Color.argb(195, 102, 147, 173)));
}
项目:IslamicLibraryAndroid    文件:BookPageFragment.java   
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getArguments();
    bookId = args.getInt(BooksInformationDBContract.BooksAuthors.COLUMN_NAME_BOOK_ID, 0);
    pageId = args.getInt(BookDatabaseContract.TitlesEntry.COLUMN_NAME_PAGE_ID, 0);
    mPagerPosition = args.getInt(KEY_PAGER_POSITION, 0);
    userDataDBHelper = UserDataDBHelper.getInstance(getContext(), bookId);
    BookDatabaseHelper bookDatabaseHelperInstance = BookDatabaseHelper.getInstance(getContext(), bookId);
    mSharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
    page_content = bookDatabaseHelperInstance.getPageContentByPageId(pageId);
    mPageCitation = bookDatabaseHelperInstance.getCitationInformation(pageId);
    mPageCitation.setResources(getResources());
    pageInfo = mPageCitation.pageInfo;

    setHasOptionsMenu(false);

}
项目:Remindy    文件:SharedPreferenceUtil.java   
public static TriggerMinutesBeforeNotificationType getTriggerMinutesBeforeNotification(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String tmPref = preferences.getString(context.getResources().getString(R.string.settings_trigger_minutes_before_notification_key), null);
    TriggerMinutesBeforeNotificationType pref;
    try {
        pref = TriggerMinutesBeforeNotificationType.valueOf(tmPref);
    } catch (Exception e) {
        pref = null;
    }

    if(pref == null) {
        Log.d("SharedPreferenceUtil", "getTriggerMinutesBeforeNotification() found null, setting 5 minutes");
        TriggerMinutesBeforeNotificationType tm = TriggerMinutesBeforeNotificationType.MINUTES_5;
        setTriggerMinutesBeforeNotification(tm, context);
        return tm;
    }
    else return pref;
}
项目:ActivityDiary    文件:MainActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        if(mCurrentPhotoPath != null && mCurrentDiaryUri != null) {
            Uri photoURI = FileProvider.getUriForFile(MainActivity.this,
                    BuildConfig.APPLICATION_ID + ".fileprovider",
                    new File(mCurrentPhotoPath));

            ContentValues values = new ContentValues();
            values.put(ActivityDiaryContract.DiaryImage.URI, photoURI.toString());
            values.put(ActivityDiaryContract.DiaryImage.DIARY_ID, mCurrentDiaryUri.getLastPathSegment());

            mQHandler.startInsert(0,
                    null,
                    ActivityDiaryContract.DiaryImage.CONTENT_URI,
                    values);

            if(PreferenceManager
                    .getDefaultSharedPreferences(ActivityDiaryApplication.getAppContext())
                    .getBoolean(SettingsActivity.KEY_PREF_TAG_IMAGES, true)) {
                try {
                    ExifInterface exifInterface = new ExifInterface(mCurrentPhotoPath);
                    if (mCurrentActivity != null) {
                        /* TODO: #24: when using hierarchical activities tag them all here, seperated with comma */
                        /* would be great to use IPTC keywords instead of EXIF UserComment, but
                         * at time of writing (2017-11-24) it is hard to find a library able to write IPTC
                         * to JPEG for android.
                         * pixymeta-android or apache/commons-imaging could be interesting for this.
                         * */
                        exifInterface.setAttribute(ExifInterface.TAG_USER_COMMENT, mCurrentActivity.getName());
                        exifInterface.saveAttributes();
                    }
                } catch (IOException e) {
                    Log.e(TAG, "writing exif data to " + mCurrentPhotoPath + " failed");
                }
            }
        }
    }
}
项目:ActivityDiary    文件:SettingsActivity.java   
private void updateTagImageSummary() {
    if(PreferenceManager
            .getDefaultSharedPreferences(ActivityDiaryApplication.getAppContext())
            .getBoolean(KEY_PREF_TAG_IMAGES, true)){
        tagImagesPref.setSummary(getResources().getString(R.string.setting_tag_yes));
    }else{
        tagImagesPref.setSummary(getResources().getString(R.string.setting_tag_no));
    }
}
项目:ActivityDiary    文件:SettingsActivity.java   
private void updateStorageFolderSummary() {
    String dir = PreferenceManager
            .getDefaultSharedPreferences(ActivityDiaryApplication.getAppContext())
            .getString(KEY_PREF_STORAGE_FOLDER, "ActivityDiary");

    storageFolderPref.setSummary(getResources().getString(R.string.setting_storage_folder_summary, dir));
}
项目:BatteryModPercentage    文件:NotifService.java   
@Override
protected String doInBackground(String... params) {
    String result = "99";
    String status = "Full";

    while (!Quit_Task) {
        Sleep(1000);
        result = MainActivity.getCapacity().trim();
        status = MainActivity.getdata(MainActivity.gb_battery + "status");
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

        if (!result.equals("-1") && sharedPrefs.getBoolean("notif", true)) {
            if (!result.equals(oldres) || !status.equals(oldsts)) {
                b.setContentTitle("Battery Mod: " + result + "%")
                        .setContentText(status);

                nm.notify(1, b.build());
                oldres = result;
                oldsts = status;
            }

        }else {
            Quit_Task = true;
            nm.cancel(1);
            return "-1";
        }

    }
    return "0";
}
项目:LaravelNewsApp    文件:Notify.java   
public static void showNewPostNotifications(){
    if (!Prefs.NotificationsEnabled()){
        return;
    }
    notificationPosts = PostRepository.getUnSeen();
    android.support.v4.app.NotificationCompat.InboxStyle inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle();
        for(Post post : notificationPosts){
            inboxStyle.addLine(post.getTitle());
        }
    //Notification sound
    SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(App.getAppContext());
    String strRingtonePreference = preference.getString("notifications_new_message_ringtone", "DEFAULT_SOUND");
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(App.getAppContext());
    mBuilder.setSmallIcon(R.drawable.ic_notifications)
            .setColor(App.getAppContext().getResources().getColor(R.color.brandColor))
            .setSound(Uri.parse(strRingtonePreference))
            .setAutoCancel(true)
            .setContentTitle("Laravel News")
            .setContentText(getSummaryMessage())
            .setContentIntent(getNotificationIntent())
            .setStyle(inboxStyle)
            .setGroup("LNA_NOTIFICATIONS_GROUP");

    //Check the vibrate
    if(Prefs.NotificationVibrateEnabled()){
        mBuilder.setVibrate(new long[]  {1000,1000});
    }

    Notification notification = mBuilder.build();
    // Issue the group notification
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(App.getAppContext());
    notificationManager.notify(1, notification);
}
项目:Cluttr    文件:Media.java   
public static void setAlbumSortType(Context context, AlbumSortType type, boolean ascending) {
    sortType = type;
    sortAscending=ascending;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit()
            .putInt(ALBUM_SORT_KEY,sortType.ordinal())
            .putBoolean(ALBUM_SORT_KEY_ASC,sortAscending)
            .apply();
}
项目:IslamicLibraryAndroid    文件:SplashActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    if (intent.getBooleanExtra(SettingsActivity.KEY_KILL_APP, false)) {
        finish();
        System.exit(0);
    }
    PreferenceManager.setDefaultValues(this, R.xml.pref_general, false);
    ((IslamicLibraryApplication) getApplication()).refreshLocale(this, false);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    mProgressBar = findViewById(R.id.progressBar1);
    mTextView = findViewById(R.id.progressTextView);
    checkStorage();
}
项目:Cluttr    文件:SecurityConfigDialog.java   
@OnClick(R.id.security_dialog_apply)
public void apply() {
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
    editor.putString(Util.PASSWORD_KEY, editText.getText().toString());
    editor.putBoolean("hidden_secure", switchToggle.isChecked());
    editor.apply();
    dismiss();
}
项目:Cluttr    文件:ExcludedFoldersDialog.java   
private void updatePrefString() {
    prefString="";
    for (String f : folders) {
        if (!prefString.isEmpty()) {
            prefString+=":";
        }
        prefString+=f;
    }
    PreferenceManager.getDefaultSharedPreferences(getContext()).edit().putString("excluded_folders",prefString).commit();
}
项目:IslamicLibraryAndroid    文件:StorageUtils.java   
public static void setAppCustomLocation(String location, Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(DownloadFileConstants.PREF_APP_LOCATION, location);
    editor.commit();

}
项目:BatteryModPercentage    文件:ModManagerBroadcastReceiver.java   
public void onReceive(Context context , Intent intent) {
    String action = intent.getAction();

    if(action.equals(ACTION_MOD_ATTACH)) {
        if (!MainActivity.getCapacity().trim().equals("-1")) {
            Toast t = Toast.makeText(context, "Battery Mod: " + MainActivity.getCapacity() + "%", Toast.LENGTH_SHORT);
            SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

            if (sharedPrefs.getBoolean("notif", true)) {
                t.show();
                context.startService(new Intent(context, NotifService.class));
            }
        }
    }
}
项目:Cluttr    文件:MediaLoader.java   
public static Observable<Boolean> init() {
    return Observable
            .create(new Observable.OnSubscribe<Boolean>() {
                @Override
                public void call(Subscriber<? super Boolean> subscriber) {
                    long time = System.currentTimeMillis();

                    String prefString = PreferenceManager.getDefaultSharedPreferences(Cluttr.getApplication()).getString("excluded_folders","");
                    if (prefString.isEmpty()) {
                        excluded = new ArrayList<>();
                    } else {
                        excluded = new ArrayList<>(Arrays.asList(prefString.split(":")));
                    }


                    boolean result = true;
                    try {
                        for (File root : listStorages()) {
                            recursiveLoadAlbums(root);
                        }
                    } catch (Exception ex) {
                        Log.e(Util.LOG_TAG, "A fatal error has occured during media loading, cache will be wiped", ex);
                        //TODO: WIPE CACHE
                        result = false;
                    }
                    Log.d(Util.LOG_TAG, "Indexing all media took " + (System.currentTimeMillis() - time) + "ms");
                    subscriber.onNext(result);
                    subscriber.onCompleted();
                }
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io());
}
项目:immersify    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    // Set up toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Create adapter which returns the fragments
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // Set up the TabLayout with the view pager
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    // Check for WRITE_SECURE_SETTINGS permission
    mSecureSettingsState = ImmersiveModeUtils.hasSecureSettingsPermission(this);

    // Initialize default preferences
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Ensure that the notification is created if applicable
    ToggleNotification.ensureShown(this);
}
项目:Neuronizer    文件:TodoListDialogs.java   
private static TodoListPresenter instantiatePresenterUsing(Fragment fragment) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(fragment.getActivity());
    String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
    return new TodoListPresenterImpl(
            ThreadExecutor.getInstance(),
            MainThreadImpl.getInstance(),
            (TodoListPresenter.View) fragment,
            new RepositoryImpl(repositoryName));
}
项目:Neuronizer    文件:NoteDialogs.java   
private static NotePresenter instantiatePresenterUsing(Fragment fragment) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(fragment.getActivity());
    String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
    return new NotePresenterImpl(
            ThreadExecutor.getInstance(),
            MainThreadImpl.getInstance(),
            (NotePresenter.View) fragment,
            new RepositoryImpl(repositoryName));
}
项目:Neuronizer    文件:ItemFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
    mPresenter = new ItemPresenterImpl(
            ThreadExecutor.getInstance(),
            MainThreadImpl.getInstance(),
            this,
            new RepositoryImpl(repositoryName)
    );
}
项目:Neuronizer    文件:TodoListAppWidgetProvider.java   
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

    for (int appWidgetId : appWidgetIds) {
        String realmName = sharedPreferences.getString(KEY_PREF_WIDGET_REALM_PREFIX + appWidgetId, FALLBACK_REALM);
        String uuid = sharedPreferences.getString(KEY_PREF_WIDGET_UUID_PREFIX + appWidgetId, "");
        updateAppWidget(appWidgetManager, context, appWidgetId, realmName, uuid);
    }
}
项目:Melophile    文件:AuthActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_auth);
    ButterKnife.bind(this);
    firebaseAnalytics=FirebaseAnalytics.getInstance(this);
    SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(this);
    String jsonToken= sharedPreferences.getString(Constants.EXTRA_TOKEN,null);
    if(!TextUtils.isEmpty(jsonToken)){
        Bundle bundle=new Bundle();
        bundle.putString(FirebaseAnalytics.Param.ITEM_ID,jsonToken);
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE,"access token json");
        firebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN,bundle);
        Token token=BundleUtils.convertFromJsonString(jsonToken,new TypeToken<Token>(){}.getType());
        if(token!=null){
            welcome(token);
            return;
        }
    }
    findViewById(R.id.log_in)
            .animate()
            .scaleX(1)
            .scaleY(1)
            .setStartDelay(300)
            .setDuration(300)
            .start();
}
项目:Neuronizer    文件:TodoListAppWidgetConfigure.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setResult(RESULT_CANCELED);
    setContentView(R.layout.activity_widget_configure);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
    List<TodoList> list = new TodoListRepositoryImpl(repositoryName).getAll();

    radioGroup = findViewById(R.id.widget_config_radio_group);
    todoLists = list.toArray(new TodoList[list.size()]);
    radioButtons = new RadioButton[todoLists.length];
    createRadioButtons();
}
项目:Neuronizer    文件:TodoListAppWidgetConfigure.java   
private void saveWidgetToSharedPrefs(int appWidgetId, String uuid) {
    // add widget id's to sharedPrefs
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(KEY_PREF_WIDGET_REALM_PREFIX + appWidgetId,
            sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM));
    editor.putString(KEY_PREF_WIDGET_UUID_PREFIX + appWidgetId, uuid);
    editor.apply();
}
项目:OneMoreRepFitness    文件:MainActivity.java   
@Override
protected void onDestroy() {
    super.onDestroy();
    // Unregister the Activity as an OnPreferenceChangedListener to avoid any memory leaks.
    PreferenceManager.getDefaultSharedPreferences(this)
            .unregisterOnSharedPreferenceChangeListener(this);
}
项目:RetroMusicPlayer    文件:SettingsActivity.java   
public void setLangRecreate(String langval) {
    Locale locale = new Locale(langval);
    Locale.setDefault(locale);
    Configuration configuration = new Configuration();
    configuration.setLocale(locale);

    getActivity().getBaseContext().getResources().updateConfiguration(configuration,
            getActivity().getBaseContext().getResources().getDisplayMetrics());

    PreferenceManager.getDefaultSharedPreferences(getContext()).edit().putString("LANG", langval).apply();
    getActivity().recreate();
}
项目:MyCalendar    文件:SettingsActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    setupActionBar();
    mPref = PreferenceManager.getDefaultSharedPreferences(this);
    mSetting = new Setting(this);
}
项目:OddLauncher    文件:HomeActivity.java   
private void setupSharedPreferences() {
    // Get all of the values from shared preferences to set it up
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    loadColorFromPreferences(sharedPreferences);
    loadSizeFromSharedPreferences(sharedPreferences);
    loadAlphaFromSharedPreferences(sharedPreferences);
    loadAlphaSearchButton(sharedPreferences);
    changeUrl(sharedPreferences);
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
项目:Camera-warner    文件:LocationService.java   
@Override
public void onCreate() {
    super.onCreate();

    Log.d("LocationService", "onCreate");

    manager = new DataProviderManager();
    manager.addObserver(this);

    mClient = LocationServices.getFusedLocationProviderClient(this);

    //implementation of the location update callback
    //what happens when the service receives the user location is defined here
    callback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            lastLocation = locationResult.getLastLocation();
            Log.d("LocationService", "new location received");
            notifyUIOfNewPosition();
            //update the location providers with the new location
            manager.onLocationChanged(lastLocation);

            if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(getString(R.string.pref_active_key), getResources().getBoolean(R.bool.pref_active_default))
                    && manager.isCameraNearerThan(Float.parseFloat(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default))), lastLocation)) {
                enableCameraWarning();
            } else {
                disableCameraWarning();
            }

        }
    };

    //build the notification for @see {@link #startForeground()} to keep the service from being killed
    startForeground(CAMERA_FOREGROUND_SERVICE_NOTIFICATION_ID, buildForegroundNotification());
}
项目:Nird2    文件:ScreenFilterMonitorImpl.java   
@Inject
ScreenFilterMonitorImpl(AndroidExecutor executor, Application app) {
    this.androidExecutor = executor;
    this.appContext = app;
    pm = appContext.getPackageManager();
    prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
    shownApps = getShownScreenFilterApps();
}
项目:Nird2    文件:SplashScreenActivity.java   
private void setPreferencesDefaults() {
    androidExecutor.runOnBackgroundThread(new Runnable() {
        @Override
        public void run() {
            PreferenceManager.setDefaultValues(SplashScreenActivity.this,
                    R.xml.panic_preferences, false);
        }
    });
}