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


Java PreferenceManager類代碼示例

本文整理匯總了Java中android.support.v7.preference.PreferenceManager的典型用法代碼示例。如果您正苦於以下問題:Java PreferenceManager類的具體用法?Java PreferenceManager怎麽用?Java PreferenceManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PreferenceManager類屬於android.support.v7.preference包,在下文中一共展示了PreferenceManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bindPreferenceSummaryToValue

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
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);
    }
}
 
開發者ID:gbl08ma,項目名稱:underlx,代碼行數:22,代碼來源:NotifPreferenceFragment.java

示例2: onResume

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
@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);

}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:26,代碼來源:ReadingActivity.java

示例3: showSortingDialog

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
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);
    }
 
開發者ID:djuelg,項目名稱:Neuronizer,代碼行數:24,代碼來源:RadioDialogs.java

示例4: showRepositoryDialog

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
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);
    }
 
開發者ID:djuelg,項目名稱:Neuronizer,代碼行數:17,代碼來源:RadioDialogs.java

示例5: bindPreferenceSummaryToValue

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:34,代碼來源:SettingsFragment.java

示例6: onCreate

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:djuelg,項目名稱:Neuronizer,代碼行數:21,代碼來源:NoteFragment.java

示例7: onCreate

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
@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)
    );
}
 
開發者ID:djuelg,項目名稱:Neuronizer,代碼行數:22,代碼來源:TodoListFragment.java

示例8: onDonePressed

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
@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();
}
 
開發者ID:djuelg,項目名稱:Neuronizer,代碼行數:21,代碼來源:IntroActivity.java

示例9: onCreatePreferences

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
@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;
        }
    });
}
 
開發者ID:varunon9,項目名稱:FakeLock,代碼行數:23,代碼來源:SettingsFragment.java

示例10: redrawLocationOnMap

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
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");
    }
}
 
開發者ID:Jugendhackt,項目名稱:Camera-warner,代碼行數:24,代碼來源:MapsActivity.java

示例11: updateLocationOnMap

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
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)));
}
 
開發者ID:Jugendhackt,項目名稱:Camera-warner,代碼行數:19,代碼來源:MapsActivity.java

示例12: onCreate

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
@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);

}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:20,代碼來源:BookPageFragment.java

示例13: getTriggerMinutesBeforeNotification

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
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;
}
 
開發者ID:abicelis,項目名稱:Remindy,代碼行數:19,代碼來源:SharedPreferenceUtil.java

示例14: onActivityResult

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
@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");
                }
            }
        }
    }
}
 
開發者ID:ramack,項目名稱:ActivityDiary,代碼行數:40,代碼來源:MainActivity.java

示例15: updateTagImageSummary

import android.support.v7.preference.PreferenceManager; //導入依賴的package包/類
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));
    }
}
 
開發者ID:ramack,項目名稱:ActivityDiary,代碼行數:10,代碼來源:SettingsActivity.java


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