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


Java SharedPreferences.OnSharedPreferenceChangeListener方法代码示例

本文整理汇总了Java中android.content.SharedPreferences.OnSharedPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.OnSharedPreferenceChangeListener方法的具体用法?Java SharedPreferences.OnSharedPreferenceChangeListener怎么用?Java SharedPreferences.OnSharedPreferenceChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.SharedPreferences的用法示例。


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

示例1: onCreate

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

    persistence = new Persistence(getActivity().getApplicationContext());

    SharedPreferences.OnSharedPreferenceChangeListener spChanged = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            // If the buy schedule has changed, cancel and recreate the alarms.
            if (key.equals("preference_frequency")) {
                try {
                    persistence.setLastBuyTime(0);
                    BuyScheduler.setAlarm(getActivity().getApplicationContext());
                } catch (Exception e) {
                    //
                }
            }
        }
    };

    PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()).registerOnSharedPreferenceChangeListener(spChanged);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
}
 
开发者ID:aomega08,项目名称:Keep-HODLing,代码行数:27,代码来源:SettingsFragment.java

示例2: testRegisterListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void testRegisterListener(View view) {
  String testValue = "myTestString";
  final String testKey = "testR";

  final SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

      Assert.assertEquals(testKey, key);

      showSuccess();
    }
  };
  getPreferences().registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);

  getPreferences().edit().putString(testKey, testValue).apply();

  getPreferences().unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
}
 
开发者ID:marius-bardan,项目名称:encryptedprefs,代码行数:20,代码来源:MainActivity.java

示例3: onCreate

import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
    addPreferencesFromResource(R.xml.board_preferences);

    mBoardTitlePreference = (EditTextPreference) findPreference(BoardUtils.BOARD_TITLE_KEY);

    setBoardTitlePreference();

    mListenerOptions = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

            switch (key) {
                case BoardUtils.BOARD_TITLE_KEY:
                    updateBoardTitlePreferenceSummary();
                    break;
                case BoardUtils.CUSTOM_APP_KEY:
                    manageCustomAppPreference();
                    break;
            }
        }
    };

    mCustomAppPreference = findPreference(BoardUtils.CUSTOM_APP_PREF_KEY);
    manageCustomAppPreference();
    mCustomAppPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), MultiSelectRecyclerViewActivity.class);
            getActivity().startActivity(intent);
            return false;
        }
    });
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:37,代码来源:BoardActivity.java

示例4: onCreate

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

         // Carrega preferences a partir de um XML
         addPreferencesFromResource(R.xml.user_prefs);

         // pega a Preference especifica do username
         mUserNamePreference = (Preference) getPreferenceManager()
                 .findPreference(USERNAME);

         // Define um listener para atualizar descricao ao modificar preferences
         mListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
             @Override
             public void onSharedPreferenceChanged(
                     SharedPreferences sharedPreferences, String key) {
                 mUserNamePreference.setSummary(sharedPreferences.getString(
                         USERNAME, "Nada ainda"));
             }
         };

         // Pega objeto SharedPreferences gerenciado pelo PreferenceManager para este Fragmento
         SharedPreferences prefs = getPreferenceManager()
                 .getSharedPreferences();

         // Registra listener no objeto SharedPreferences
         prefs.registerOnSharedPreferenceChangeListener(mListener);

         // Invoca callback manualmente para exibir username atual
         //mListener.onSharedPreferenceChanged(prefs, USERNAME);
/**/


     }
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:35,代码来源:PrefsMenuActivity.java

示例5: registerOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerOnSharedPreferenceChangeListener() {
            SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
                @Override
                public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
                    boolean notifIsOn = sharedPreferences.getBoolean(getString(R.string.pref_title_new_message_notifications), true);
                    // TODO
//                    SwitchPreference notifSwitchPreference = (SwitchPreference) getFragmentManager().
                    if (notifIsOn) {
                    } else {

                    }
                }
            };
        }
 
开发者ID:Chan4077,项目名称:StudyBuddy,代码行数:15,代码来源:SettingsActivity.java

示例6: unregisterOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
    delegate.unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
}
 
开发者ID:schul-cloud,项目名称:schulcloud-mobile-android,代码行数:5,代码来源:ObscuredSharedPreferences.java

示例7: registerListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    androidSharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:4,代码来源:SharedPreferencesUtil.java

示例8: unregisterOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    _sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener);
}
 
开发者ID:CoryCharlton,项目名称:BittrexApi,代码行数:4,代码来源:Settings.java

示例9: unregisterPreferenceChangedListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void unregisterPreferenceChangedListener(final SharedPreferences pref, SharedPreferences.OnSharedPreferenceChangeListener value) {
    pref.unregisterOnSharedPreferenceChangeListener(value);
}
 
开发者ID:gsantner,项目名称:memetastic,代码行数:4,代码来源:AppSettingsBase.java

示例10: registerPreferenceChangedListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerPreferenceChangedListener(final SharedPreferences pref, SharedPreferences.OnSharedPreferenceChangeListener value) {
    pref.registerOnSharedPreferenceChangeListener(value);
}
 
开发者ID:gsantner,项目名称:markor,代码行数:4,代码来源:AppSettingsBase.java

示例11: unregisterListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void unregisterListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    prefs.unregisterOnSharedPreferenceChangeListener(listener);
}
 
开发者ID:Genius,项目名称:genius-groupie,代码行数:4,代码来源:Prefs.java

示例12: registerOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
 * Register SharedPreferences change listener
 *
 * @param listener listener object of OnSharedPreferenceChangeListener
 */
public void registerOnSharedPreferenceChangeListener(
        SharedPreferences.OnSharedPreferenceChangeListener listener) {

    preferences.registerOnSharedPreferenceChangeListener(listener);
}
 
开发者ID:IdeaTrackerPlus,项目名称:IdeaTrackerPlus,代码行数:11,代码来源:TinyDB.java

示例13: registerOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    _sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}
 
开发者ID:CoryCharlton,项目名称:BittrexApi,代码行数:4,代码来源:Settings.java

示例14: registerOnSharedPreferenceChangedListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerOnSharedPreferenceChangedListener(SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
    mPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:4,代码来源:PreferenceUtil.java

示例15: registerListener

import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    prefs.registerOnSharedPreferenceChangeListener(listener);
}
 
开发者ID:Genius,项目名称:genius-groupie,代码行数:4,代码来源:Prefs.java


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