Android Open Source - cwac-loaderex Shared Preferences Demo






From Project

Back to project page cwac-loaderex.

License

The source code is released under:

Apache License

If you think the Android project cwac-loaderex listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* Copyright (c) 2011-2012 -- CommonsWare, LLC
//from   www .  ja  v  a  2s .  c o m
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package com.commonsware.cwac.loaderex.demo;

import android.app.Activity;
import android.app.LoaderManager;
import android.content.Loader;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
import com.commonsware.cwac.loaderex.SharedPreferencesLoader;

public class SharedPreferencesDemo extends Activity implements
    LoaderManager.LoaderCallbacks<SharedPreferences> {
  private static final String KEY="sample";
  private TextView tv;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.prefs);

    tv=(TextView)findViewById(R.id.pref);
    getLoaderManager().initLoader(0, null, this);
  }

  @Override
  public Loader<SharedPreferences> onCreateLoader(int id, Bundle args) {
    return(new SharedPreferencesLoader(this));
  }

  @Override
  public void onLoadFinished(Loader<SharedPreferences> loader,
                             SharedPreferences prefs) {
    int value=prefs.getInt(KEY, 0);

    value+=1;
    tv.setText(String.valueOf(value));

    SharedPreferences.Editor editor=prefs.edit();

    editor.putInt(KEY, value);

    SharedPreferencesLoader.persist(editor);
  }

  @Override
  public void onLoaderReset(Loader<SharedPreferences> arg0) {
    // unused
  }
}




Java Source Code List

com.commonsware.cwac.loaderex.AbstractCursorLoader.java
com.commonsware.cwac.loaderex.ContentChangingTask.java
com.commonsware.cwac.loaderex.SQLCipherCursorLoader.java
com.commonsware.cwac.loaderex.SQLCipherUtils.java
com.commonsware.cwac.loaderex.SQLiteCursorLoader.java
com.commonsware.cwac.loaderex.SQLiteDeleteTask.java
com.commonsware.cwac.loaderex.SQLiteInsertTask.java
com.commonsware.cwac.loaderex.SharedPreferencesLoader.java
com.commonsware.cwac.loaderex.acl.AbstractCursorLoader.java
com.commonsware.cwac.loaderex.acl.ContentChangingTask.java
com.commonsware.cwac.loaderex.acl.SQLCipherCursorLoader.java
com.commonsware.cwac.loaderex.acl.SQLiteCursorLoader.java
com.commonsware.cwac.loaderex.acl.SharedPreferencesLoader.java
com.commonsware.cwac.loaderex.demo.ConstantsBrowserACL.java
com.commonsware.cwac.loaderex.demo.ConstantsBrowser.java
com.commonsware.cwac.loaderex.demo.DatabaseHelper.java
com.commonsware.cwac.loaderex.demo.SharedPreferencesACLDemo.java
com.commonsware.cwac.loaderex.demo.SharedPreferencesDemo.java