Java Code Examples for android.content.SharedPreferences

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.

Source file: MainActivity.java

  18 
vote

@Override public void onResume(){
  super.onResume();
  SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
  String username=sp.getString("username","");
  String password=sp.getString("password","");
  if (username.equals("") || password.equals("")) {
    Toast.makeText(this,"Username or password empty",3);
    startActivityForResult(new Intent(this,SetupWizard.class),1);
  }
  refreshData();
  reciever=new UpdateReciever(this);
  registerReceiver(reciever,new IntentFilter(UpdateWidgetService.NEWDATA));
}
 

Example 2

From project Absolute-Android-RSS, under directory /src/com/AA/Recievers/.

Source file: AAWidgetProvider.java

  18 
vote

/** 
 * This method handles when a widget or multiple widgets are removed from the homescreen(or some other embedded location)
 */
@Override public void onDeleted(Context context,int[] appWidgetIds){
  SharedPreferences settings=context.getSharedPreferences("settings",0);
  Editor edit=settings.edit();
  edit.putInt("widgetCount",settings.getInt("widgetCount",0) - 1);
  for (int i=0; i < appWidgetIds.length; i++) {
    edit.remove("" + appWidgetIds[i]);
  }
  edit.commit();
  if (settings.getInt("widgetCount",0) <= 0)   AlarmReceiver.stopAlarm(context);
}
 

Example 3

From project Airports, under directory /src/com/nadmm/airports/afd/.

Source file: NearbyActivity.java

  18 
vote

protected void requestLocationUpdates(){
  if (mLocationManager != null) {
    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,30 * DateUtils.SECOND_IN_MILLIS,0.5f * GeoUtils.METERS_PER_STATUTE_MILE,mLocationListener);
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
    boolean useGps=prefs.getBoolean(PreferencesActivity.KEY_LOCATION_USE_GPS,false);
    if (useGps) {
      mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,30 * DateUtils.SECOND_IN_MILLIS,0.5f * GeoUtils.METERS_PER_STATUTE_MILE,mLocationListener);
    }
  }
}
 

Example 4

From project AlarmApp-Android, under directory /src/com/google/android/c2dm/.

Source file: C2DMessaging.java

  18 
vote

static void setBackoff(Context context,long backoff){
  final SharedPreferences prefs=context.getSharedPreferences(PREFERENCE,Context.MODE_PRIVATE);
  Editor editor=prefs.edit();
  editor.putLong(BACKOFF,backoff);
  editor.commit();
}
 

Example 5

From project and-bible, under directory /AndBible/src/net/bible/android/control/page/.

Source file: CurrentPageManager.java

  18 
vote

/** 
 * restore current page and document state 
 */
private void restoreState(){
  try {
    Log.i(TAG,"Restore instance state");
    SharedPreferences settings=getAppStateSharedPreferences();
    restoreState(settings);
  }
 catch (  Exception e) {
    Log.e(TAG,"Restore error",e);
  }
}
 

Example 6

From project andlytics, under directory /src/com/github/andlyticsproject/.

Source file: Main.java

  18 
vote

/** 
 * checks if the app is started for the first time (after an update).
 * @return <code>true</code> if this is the first start (after an update)else <code>false</code>
 */
private boolean isUpdate(){
  final int versionCode=Utils.getActualVersionCode(this);
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  final long lastVersionCode=prefs.getLong(LAST_VERSION_CODE_KEY,0);
  if (versionCode != lastVersionCode) {
    Log.i(TAG,"versionCode " + versionCode + " is different from the last known version "+ lastVersionCode);
    return true;
  }
 else {
    Log.i(TAG,"versionCode " + versionCode + " is already known");
    return false;
  }
}
 

Example 7

From project android-api-demos, under directory /src/com/mobeelizer/demos/activities/.

Source file: CreateSessionCodeActivity.java

  18 
vote

/** 
 * {@inheritDoc}
 */
@Override protected void onPostExecute(final String result){
  if (result != null) {
    mSessionCode=result;
    mSessionCodeTextView.setText(result);
    SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    sp.edit().putString(BaseActivity.SESSION_CODE,result).putString(BaseActivity.USER_TYPE,UserType.A.name()).commit();
    mCreatingSessionLayout.setVisibility(View.GONE);
    mSessionCreatedLayout.setVisibility(View.VISIBLE);
  }
}
 

Example 8

From project android-bankdroid, under directory /src/com/liato/bankdroid/appwidget/.

Source file: AutoRefreshService.java

  18 
vote

private boolean InsideUpdatePeriod(){
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  int start=prefs.getInt("refresh_start_minutes",0);
  int stop=prefs.getInt("refresh_stop_minutes",0);
  if (start >= stop)   return true;
  Date now=new Date();
  int minutesSinceMidnight=now.getHours() * 60 + now.getMinutes();
  return minutesSinceMidnight > start && minutesSinceMidnight < stop;
}
 

Example 9

From project android-context, under directory /defunct/.

Source file: PrefsActivity.java

  18 
vote

public static int getDecimalPlaces(Context ctx){
  SharedPreferences settings=PreferenceManager.getDefaultSharedPreferences(ctx);
  String s=settings.getString(PREFS_DECIMAL_PLACES,new Integer(PREFS_DECIMAL_PLACES_DEFAULT).toString());
  int i;
  try {
    i=Integer.parseInt(s);
  }
 catch (  Exception e) {
    i=PREFS_DECIMAL_PLACES_DEFAULT;
  }
  return i;
}
 

Example 10

From project Android-Flashcards, under directory /src/com/secretsockssoftware/androidflashcards/.

Source file: CardRunner.java

  18 
vote

@Override protected void onStop(){
  super.onStop();
  SharedPreferences settings=getSharedPreferences(lprefname,0);
  SharedPreferences.Editor editor=settings.edit();
  editor.putBoolean("switch_front_back",switch_front_back);
  editor.commit();
}
 

Example 11

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: BeepManager.java

  18 
vote

public void updatePrefs(){
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(activity);
  playBeep=shouldBeep(prefs,activity);
  if (playBeep && mediaPlayer == null) {
    activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mediaPlayer=buildMediaPlayer(activity);
  }
}
 

Example 12

From project Android-Simple-Social-Sharing, under directory /SimpleSocialSharing/src/com/nostra13/socialsharing/facebook/.

Source file: FacebookSessionStore.java

  18 
vote

public static boolean restore(Facebook session,Context context){
  SharedPreferences savedSession=context.getSharedPreferences(Preferences.FACEBOOK_KEY,Context.MODE_PRIVATE);
  session.setAccessToken(savedSession.getString(Preferences.FACEBOOK_TOKEN,null));
  session.setAccessExpires(savedSession.getLong(Preferences.FACEBOOK_EXPIRES,0));
  return session.isSessionValid();
}
 

Example 13

From project Android-Terminal-Emulator, under directory /src/jackpal/androidterm/.

Source file: RemoteInterface.java

  18 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  mSettings=new TermSettings(getResources(),prefs);
  Intent TSIntent=new Intent(this,TermService.class);
  startService(TSIntent);
  if (!bindService(TSIntent,mTSConnection,BIND_AUTO_CREATE)) {
    Log.e(TermDebug.LOG_TAG,"bind to service failed!");
    finish();
  }
}
 

Example 14

From project android-tether, under directory /c2dm/com/google/android/c2dm/.

Source file: C2DMessaging.java

  18 
vote

static void setBackoff(Context context,long backoff){
  final SharedPreferences prefs=context.getSharedPreferences(PREFERENCE,Context.MODE_PRIVATE);
  Editor editor=prefs.edit();
  editor.putLong(BACKOFF,backoff);
  editor.commit();
}
 

Example 15

From project android-thaiime, under directory /latinime/src/com/android/inputmethod/deprecated/voice/.

Source file: Hints.java

  18 
vote

private boolean shouldShowSwipeHint(){
  final SharedPreferences prefs=mPrefs;
  int numUniqueDaysShown=prefs.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN,0);
  if (numUniqueDaysShown < mSwipeHintMaxDaysToShow) {
    long lastTimeVoiceWasUsed=prefs.getLong(PREF_VOICE_INPUT_LAST_TIME_USED,0);
    if (!isFromToday(lastTimeVoiceWasUsed)) {
      return true;
    }
  }
  return false;
}
 

Example 16

From project android-xbmcremote, under directory /src/org/xbmc/android/remote/business/receiver/.

Source file: AutoStartReceiver.java

  18 
vote

@Override public void onReceive(Context context,Intent intent){
  Log.d(TAG,"onReceiveIntent");
  SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(context);
  boolean startupOnBoot=sharedPreferences.getBoolean("setting_startup_onboot",false);
  if (startupOnBoot) {
    Intent activityIntent=new Intent(context,HomeActivity.class);
    activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(activityIntent);
  }
}
 

Example 17

From project android-xbmcremote-sandbox, under directory /src/org/xbmc/android/remotesandbox/ui/phone/.

Source file: DashboardFragment.java

  18 
vote

/** 
 * Adds all our menu items to the grid.
 * @param menuGrid
 */
private void setupDashboardItems(GridView menuGrid){
  final ArrayList<HomeItem> homeItems=new ArrayList<HomeItem>();
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
  if (prefs.getBoolean("setting_show_home_music",true)) {
    homeItems.add(new HomeItem(HOME_ACTION_MUSIC,R.drawable.home_ic_music,"Music","Listen to"));
  }
  menuGrid.setAdapter(new HomeAdapter(getActivity(),homeItems));
  menuGrid.setOnItemClickListener(mHomeMenuOnClickListener);
  menuGrid.setSelected(true);
  menuGrid.setSelection(0);
}
 

Example 18

From project AndroidBillingLibrary, under directory /AndroidBillingLibrary/src/net/robotmedia/billing/helper/.

Source file: AbstractBillingObserver.java

  18 
vote

public void onTransactionsRestored(){
  final SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(activity);
  final Editor editor=preferences.edit();
  editor.putBoolean(KEY_TRANSACTIONS_RESTORED,true);
  editor.commit();
}
 

Example 19

From project abalone-android, under directory /src/com/bytopia/abalone/.

Source file: SelectLayoutActivity.java

  17 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  layouts=new ArrayList<Layout>();
  for (  String layout : getResources().getStringArray(R.array.game_layouts)) {
    String tempAi="com.bytopia.abalone.mechanics." + layout;
    try {
      Class layoutClass=Class.forName(tempAi);
      Layout l=(Layout)layoutClass.newInstance();
      layouts.add(l);
    }
 catch (    Exception e1) {
      e1.printStackTrace();
    }
  }
  setContentView(R.layout.layout_selecting);
  boardView=new BoardView(getApplicationContext()){
    @Override public boolean onTouchEvent(    MotionEvent e){
      if (e.getAction() == MotionEvent.ACTION_UP) {
        String name=layouts.get(index).getClass().getName();
        SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        preferences.edit().putString("layout",name).commit();
        finish();
      }
      return true;
    }
  }
;
  prev=(Button)findViewById(R.id.slect_layout_prev);
  next=(Button)findViewById(R.id.slect_layout_next);
  refrashLayout();
  LinearLayout linearLayout=(LinearLayout)findViewById(R.id.layout_selecting_layout);
  linearLayout.addView(boardView);
}
 

Example 20

From project android-client_1, under directory /src/com/buddycloud/.

Source file: BuddycloudService.java

  17 
vote

@Override public void onTrasportServiceConnect(IXmppTransportService service){
  try {
    service.enableFeature("http://jabber.org/protocol/geoloc");
    service.enableFeature("http://jabber.org/protocol/geoloc-next");
    service.enableFeature("http://jabber.org/protocol/geoloc-prev");
    service.enableFeature("http://jabber.org/protocol/geoloc+notify");
    service.enableFeature("http://jabber.org/protocol/geoloc-next+notify");
    service.enableFeature("http://jabber.org/protocol/geoloc-prev+notify");
    SharedPreferences preferences=getApplicationContext().getSharedPreferences("buddycloud",0);
    for (    String jid : client.getAllAccountJids(true)) {
      if (preferences.getString("main_jid","").length() == 0) {
        preferences.edit().putString("main_jid",jid).commit();
      }
      Log.d("BC","SYNC " + jid);
      new ChannelSync(client,jid,getApplicationContext().getContentResolver());
    }
    String jids[]=client.getAllAccountJids(false);
    for (    String jid : jids) {
      ContentValues values=new ContentValues();
      values.put(Roster.SELF,1);
      getApplicationContext().getContentResolver().update(Roster.CONTENT_URI,values,"jid=?",new String[]{"/user/" + jid + "/channel"});
    }
    sendDirectedPresence();
  }
 catch (  RemoteException e) {
    e.printStackTrace();
  }
}
 

Example 21

From project android-client_2, under directory /src/org/mifos/androidclient/main/.

Source file: ClientMainActivity.java

  17 
vote

/** 
 * Checks whether the Mifos server address has been specified or not and displays a dialog prompting for it in the latter case.
 */
private void checkForServerAddress(){
  final SharedPreferences settings=getSharedPreferences(ApplicationConstants.MIFOS_APPLICATION_PREFERENCES,MODE_PRIVATE);
  if (!settings.contains(ApplicationConstants.MIFOS_SERVER_ADDRESS_KEY)) {
    mUIUtils.promptForTextInput(getString(R.string.dialog_server_address),getString(R.string.server_name_template),new UIUtils.DialogCallbacks(){
      @Override public void onCommit(      Object inputData){
        SharedPreferences.Editor editor=settings.edit();
        editor.putString(ApplicationConstants.MIFOS_SERVER_ADDRESS_KEY,(String)inputData);
        editor.commit();
        mUIUtils.displayLongMessage(getString(R.string.toast_first_address_set));
      }
      @Override public void onCancel(){
        mUIUtils.displayLongMessage(getString(R.string.toast_first_address_canceled));
      }
    }
);
  }
}
 

Example 22

From project android-flash-cards, under directory /src/org/thomasamsler/android/flashcards/activity/.

Source file: MainActivity.java

  17 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  mDataSource=new DataSource(this);
  mMainApplication=(MainApplication)getApplication();
  mMainApplication.initActionBusListener();
  mMainApplication.registerAction(this,ACTION_SHOW_CARD_SETS,ACTION_SHOW_CARDS,ACTION_SHOW_HELP,ACTION_SHOW_SETUP,ACTION_SHOW_ABOUT,ACTION_GET_EXTERNAL_CARD_SETS,ACTION_SET_HELP_CONTEXT,ACTION_SHOW_ADD_CARD,ACTION_ADD_CARD_SET,ACTION_FONT_SIZE_CHANGE,ACTION_SEND_FEEDBACK,ACTION_RESHUFFLE_CARDS);
  SharedPreferences sharedPreferences=getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
  boolean runConversion=sharedPreferences.getBoolean(PREFERENCE_RUN_CONVERSION,PREFERENCE_RUN_CONVERSION_DEFAULT);
  if (runConversion) {
    FileToDbConversion conversion=new FileToDbConversion();
    conversion.convert(this,mDataSource);
    SharedPreferences.Editor editor=sharedPreferences.edit();
    editor.putBoolean(PREFERENCE_RUN_CONVERSION,false);
    editor.commit();
  }
  int fontSizePreference=sharedPreferences.getInt(PREFERENCE_FONT_SIZE,PREFERENCE_NORMAL_FONT_SIZE);
  mFontSize=getFontSizePreference(fontSizePreference);
  mFragmentContainer=(LinearLayout)findViewById(R.id.fragmentContainer);
  mViewPager=(ViewPager)findViewById(R.id.viewpager);
  showCardSetsFragment(false);
}
 

Example 23

From project android-gltron, under directory /GlTron/src/com/glTron/Game/.

Source file: UserPrefs.java

  17 
vote

public void ReloadPrefs(){
  int cameraType;
  int gridIndex;
  int speedIndex;
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(mContext);
  cameraType=Integer.valueOf(prefs.getString("cameraPref",C_DEFAULT_CAM_TYPE));
switch (cameraType) {
case C_PREF_FOLLOW_CAM:
    mCameraType=Camera.CamType.E_CAM_TYPE_FOLLOW;
  break;
case C_PREF_FOLLOW_CAM_FAR:
mCameraType=Camera.CamType.E_CAM_TYPE_FOLLOW_FAR;
break;
case C_PREF_FOLLOW_CAM_CLOSE:
mCameraType=Camera.CamType.E_CAM_TYPE_FOLLOW_CLOSE;
break;
case C_PREF_BIRD_CAM:
mCameraType=Camera.CamType.E_CAM_TYPE_BIRD;
break;
default :
mCameraType=Camera.CamType.E_CAM_TYPE_FOLLOW;
break;
}
mMusic=prefs.getBoolean("musicOption",true);
mSFX=prefs.getBoolean("sfxOption",true);
mFPS=prefs.getBoolean("fpsOption",false);
mNumOfPlayers=Integer.valueOf(prefs.getString("playerNumber","4"));
gridIndex=Integer.valueOf(prefs.getString("arenaSize","1"));
mGridSize=C_GRID_SIZES[gridIndex];
speedIndex=Integer.valueOf(prefs.getString("gameSpeed","1"));
mSpeed=C_SPEED[speedIndex];
mPlayerColourIndex=Integer.valueOf(prefs.getString("playerBike","0"));
mDrawRecog=prefs.getBoolean("drawRecog",true);
}
 

Example 24

From project android-joedayz, under directory /Proyectos/FBConnectTest/src/com/facebook/android/.

Source file: Facebook.java

  17 
vote

/** 
 * This function does the heavy lifting of publishing an install.
 * @param fb
 * @param applicationId
 * @param context
 * @throws Exception
 */
private static void publishInstall(final Facebook fb,final String applicationId,final Context context) throws JSONException, FacebookError, MalformedURLException, IOException {
  String attributionId=Facebook.getAttributionId(context.getContentResolver());
  SharedPreferences preferences=context.getSharedPreferences(ATTRIBUTION_PREFERENCES,Context.MODE_PRIVATE);
  String pingKey=applicationId + "ping";
  long lastPing=preferences.getLong(pingKey,0);
  if (lastPing == 0 && attributionId != null) {
    Bundle supportsAttributionParams=new Bundle();
    supportsAttributionParams.putString(APPLICATION_FIELDS,SUPPORTS_ATTRIBUTION);
    JSONObject supportResponse=Util.parseJson(fb.request(applicationId,supportsAttributionParams));
    Object doesSupportAttribution=(Boolean)supportResponse.get(SUPPORTS_ATTRIBUTION);
    if (!(doesSupportAttribution instanceof Boolean)) {
      throw new JSONException(String.format("%s contains %s instead of a Boolean",SUPPORTS_ATTRIBUTION,doesSupportAttribution));
    }
    if ((Boolean)doesSupportAttribution) {
      Bundle publishParams=new Bundle();
      publishParams.putString(ANALYTICS_EVENT,MOBILE_INSTALL_EVENT);
      publishParams.putString(ATTRIBUTION_KEY,attributionId);
      String publishUrl=String.format(PUBLISH_ACTIVITY_PATH,applicationId);
      fb.request(publishUrl,publishParams,"POST");
      SharedPreferences.Editor editor=preferences.edit();
      editor.putLong(pingKey,System.currentTimeMillis());
      editor.commit();
    }
  }
}
 

Example 25

From project android-pedometer, under directory /src/name/bagi/levente/pedometer/.

Source file: Pedometer.java

  17 
vote

private void resetValues(boolean updateDisplay){
  if (mService != null && mIsRunning) {
    mService.resetValues();
  }
 else {
    mStepValueView.setText("0");
    mPaceValueView.setText("0");
    mDistanceValueView.setText("0");
    mSpeedValueView.setText("0");
    mCaloriesValueView.setText("0");
    SharedPreferences state=getSharedPreferences("state",0);
    SharedPreferences.Editor stateEditor=state.edit();
    if (updateDisplay) {
      stateEditor.putInt("steps",0);
      stateEditor.putInt("pace",0);
      stateEditor.putFloat("distance",0);
      stateEditor.putFloat("speed",0);
      stateEditor.putFloat("calories",0);
      stateEditor.commit();
    }
  }
}
 

Example 26

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/provider/.

Source file: BookStoreFactory.java

  17 
vote

public static BooksStore get(Context context){
  final SharedPreferences preferences=context.getSharedPreferences(Preferences.NAME,0);
  final String name=preferences.getString(Preferences.KEY_BOOKSTORE,DEFAULT_BOOK_STORE);
  BooksStore store=get(context,name);
  if (store == null) {
    final Iterator<Map.Entry<String,BooksStore>> iterator=sStores.entrySet().iterator();
    if (iterator.hasNext()) {
      store=iterator.next().getValue();
      final SharedPreferences.Editor editor=preferences.edit();
      editor.putString(Preferences.KEY_BOOKSTORE,store.getName());
      editor.commit();
      return store;
    }
  }
  return store;
}
 

Example 27

From project AndroidLab, under directory /src/src/de/tubs/ibr/android/ldap/core/activities/.

Source file: ConflictActivity.java

  17 
vote

private Bundle loadRemoteContact(String attributeUUID){
  SharedPreferences savedRemoteStates=getSharedPreferences("remoteState",MODE_PRIVATE);
  String ldif=savedRemoteStates.getString(attributeUUID,null);
  if (ldif == null) {
    return null;
  }
  LDIFReader reader=new LDIFReader(new BufferedReader(new StringReader(ldif)));
  com.unboundid.ldap.sdk.Entry lastSyncState=null;
  try {
    lastSyncState=reader.readEntry();
  }
 catch (  LDIFException e) {
    return null;
  }
catch (  IOException e) {
    return null;
  }
  return ContactManager.createMapableBundle(ContactManager.createBundleFromEntry(lastSyncState));
}
 

Example 28

From project 4308Cirrus, under directory /tendril-example/src/main/java/edu/colorado/cs/cirrus/android/.

Source file: CirrusPreferenceActivity.java

  15 
vote

public boolean onPreferenceClick(Preference preference){
  SharedPreferences.Editor editor=customCirrusPrefs.edit();
  if (preference.equals(setHomeLocPref)) {
    Toast.makeText(getBaseContext(),"Setting home location",Toast.LENGTH_SHORT).show();
    if (latitude == 0.0 || longitude == 0.0) {
      Toast.makeText(getBaseContext(),"Error getting GPS info",Toast.LENGTH_LONG).show();
      return false;
    }
    editor.putFloat("homeLatitude",(float)latitude);
    editor.putFloat("homeLongitude",(float)longitude);
    Toast.makeText(getBaseContext(),"Latitude: " + latitude + ", Longitude: "+ longitude,Toast.LENGTH_SHORT).show();
  }
 else   if (preference.equals(gpsFreqPref)) {
    editor.putString("gpsFreq",gpsFreqPref.getKey());
    Toast.makeText(getBaseContext(),"gpsFreq: " + gpsFreqPref.getKey(),Toast.LENGTH_SHORT).show();
  }
  return editor.commit();
}
 

Example 29

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/.

Source file: SettingsActivity.java

  15 
vote

@Override public void onSharedPreferenceChanged(SharedPreferences preferences,String key){
  if (!settingsHelper.validateFormat(key)) {
    Toast.makeText(context,R.string.setting_error,Toast.LENGTH_LONG).show();
  }
 else   if (key.equals(SettingsHelper.AVERAGING_TIME) && !settingsHelper.validateAveragingTime()) {
    Toast.makeText(context,R.string.averaging_time_error,Toast.LENGTH_LONG).show();
  }
}
 

Example 30

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/app/.

Source file: AmenoidApp.java

  15 
vote

@Override public void onCreate(){
  this.cache=new SimpleWebImageCache<ThumbnailBus,ThumbnailMessage>(null,null,101,bus);
  Config.init(getApplicationContext());
  DEVELOPER_MODE=getResources().getBoolean(R.bool.debuggable);
  if (getResources().getBoolean(R.bool.strict)) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyDropBox().penaltyLog().build());
  }
  super.onCreate();
  prefs=PreferenceManager.getDefaultSharedPreferences(this);
  amenTypeThin=Typeface.createFromAsset(getAssets(),"fonts/AmenTypeThin.ttf");
  amenTypeBold=Typeface.createFromAsset(getAssets(),"fonts/AmenTypeBold.ttf");
  instance=this;
  builder=new AlertDialog.Builder(this);
  Log.v(TAG,"onCreate");
  final String authToken=readAuthTokenFromPrefs(prefs);
  final User me=readMeFromPrefs(prefs);
  String email=prefs.getString(Constants.PREFS_EMAIL,null);
  if (TextUtils.isEmpty(email)) {
    email=prefs.getString(Constants.PREFS_USER_NAME,"");
    if (!TextUtils.isEmpty(email) && email.contains("@")) {
      SharedPreferences.Editor editor=prefs.edit();
      editor.putString(Constants.PREFS_EMAIL,email);
      editor.commit();
    }
  }
  final String password=prefs.getString(Constants.PREFS_PASSWORD,null);
  if (authToken != null && me != null) {
    configureAmenService();
    service.init(authToken,me);
  }
 else   if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)) {
    getService(email,password);
  }
 else {
    getService();
  }
}
 

Example 31

From project Android, under directory /app/src/main/java/com/github/mobile/ui/gist/.

Source file: GistFileFragment.java

  15 
vote

@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key){
  if (WRAP.equals(key)) {
    updateWrapItem();
    editor.setWrap(sharedPreferences.getBoolean(WRAP,false));
  }
}
 

Example 32

From project android-async-http, under directory /src/com/loopj/android/http/.

Source file: PersistentCookieStore.java

  15 
vote

@Override public void addCookie(Cookie cookie){
  String name=cookie.getName();
  if (!cookie.isExpired(new Date())) {
    cookies.put(name,cookie);
  }
 else {
    cookies.remove(name);
  }
  SharedPreferences.Editor prefsWriter=cookiePrefs.edit();
  prefsWriter.putString(COOKIE_NAME_STORE,TextUtils.join(",",cookies.keySet()));
  prefsWriter.putString(COOKIE_NAME_PREFIX + name,encodeCookie(new SerializableCookie(cookie)));
  prefsWriter.commit();
}
 

Example 33

From project Android-Battery-Widget, under directory /src/com/em/batterywidget/preferences/.

Source file: Preferences.java

  15 
vote

public void setValue(String key,int value){
  if (mPreference != null) {
    SharedPreferences.Editor editor=mPreference.edit();
    editor.putInt(key,value);
    editor.commit();
  }
}
 

Example 34

From project Android-FFXIEQ, under directory /ffxieq/src/com/github/kanata3249/ffxieq/android/db/.

Source file: FFXIEQSettings.java

  15 
vote

public void setUseExternalDB(boolean useExternalDB){
  SharedPreferences.Editor editor;
  editor=mContext.getSharedPreferences("ffxieq",Activity.MODE_PRIVATE).edit();
  editor.putBoolean("useExternalDB",useExternalDB);
  editor.commit();
}
 

Example 35

From project Android-File-Manager, under directory /src/com/nexes/manager/.

Source file: Main.java

  15 
vote

@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
  super.onActivityResult(requestCode,resultCode,data);
  SharedPreferences.Editor editor=mSettings.edit();
  boolean check;
  boolean thumbnail;
  int color, sort, space;
  if (requestCode == SETTING_REQ && resultCode == RESULT_CANCELED) {
    check=data.getBooleanExtra("HIDDEN",false);
    thumbnail=data.getBooleanExtra("THUMBNAIL",true);
    color=data.getIntExtra("COLOR",-1);
    sort=data.getIntExtra("SORT",0);
    space=data.getIntExtra("SPACE",View.VISIBLE);
    editor.putBoolean(PREFS_HIDDEN,check);
    editor.putBoolean(PREFS_THUMBNAIL,thumbnail);
    editor.putInt(PREFS_COLOR,color);
    editor.putInt(PREFS_SORT,sort);
    editor.putInt(PREFS_STORAGE,space);
    editor.commit();
    mFileMag.setShowHiddenFiles(check);
    mFileMag.setSortType(sort);
    mHandler.setTextColor(color);
    mHandler.setShowThumbnails(thumbnail);
    mStorageLabel.setVisibility(space);
    mHandler.updateDirectory(mFileMag.getNextDir(mFileMag.getCurrentDir(),true));
  }
}
 

Example 36

From project Android-File-Manager-Tablet, under directory /src/com/nexes/manager/tablet/.

Source file: MainActivity.java

  15 
vote

@Override protected void onPause(){
  super.onPause();
  String list=((DirListActivity)getFragmentManager().findFragmentById(R.id.list_frag)).getDirListString();
  String bookmark=((DirListActivity)getFragmentManager().findFragmentById(R.id.list_frag)).getBookMarkNameString();
  String saved=mPreferences.getString(SettingsActivity.PREF_LIST_KEY,"");
  String saved_book=mPreferences.getString(SettingsActivity.PREF_BOOKNAME_KEY,"");
  if (!list.equals(saved)) {
    SharedPreferences.Editor e=mPreferences.edit();
    e.putString(SettingsActivity.PREF_LIST_KEY,list);
    e.commit();
  }
  if (!bookmark.equals(saved_book)) {
    SharedPreferences.Editor e=mPreferences.edit();
    e.putString(SettingsActivity.PREF_BOOKNAME_KEY,bookmark);
    e.commit();
  }
}
 

Example 37

From project android-rackspacecloud, under directory /src/com/rackspacecloud/android/.

Source file: PasswordManager.java

  15 
vote

public void turnOffPassword(){
  SharedPreferences.Editor editor=settings.edit();
  editor.putString(Preferences.PREF_KEY_PASSCODE_HASH,"");
  editor.putBoolean(Preferences.PREF_KEY_PASSWORD_LOCK,false);
  editor.commit();
}
 

Example 38

From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/core/activity/.

Source file: TopLevelActivity.java

  15 
vote

public Void doInBackground(CursorGenerator... params){
  String[] perspectives=getResources().getStringArray(R.array.perspectives);
  int colour=getResources().getColor(R.drawable.pale_blue);
  ForegroundColorSpan span=new ForegroundColorSpan(colour);
  CharSequence[] labels=new CharSequence[perspectives.length];
  int length=perspectives.length;
  for (int i=0; i < length; i++) {
    labels[i]="  " + perspectives[i];
  }
  int[] cachedCounts=Preferences.getTopLevelCounts(TopLevelActivity.this);
  if (cachedCounts != null && cachedCounts.length == length) {
    for (int i=0; i < length; i++) {
      CharSequence label=labels[i] + "  (" + cachedCounts[i]+ ")";
      SpannableString spannable=new SpannableString(label);
      spannable.setSpan(span,labels[i].length(),label.length(),Spanned.SPAN_INCLUSIVE_INCLUSIVE);
      labels[i]=spannable;
    }
  }
  publishProgress(labels);
  String cachedCountStr="";
  for (int i=0; i < length; i++) {
    CursorGenerator generator=params[i];
    Cursor cursor=generator.generate();
    int count=cursor.getCount();
    cursor.close();
    CharSequence label="  " + perspectives[i] + "  ("+ count+ ")";
    SpannableString spannable=new SpannableString(label);
    spannable.setSpan(span,perspectives[i].length() + 2,label.length(),Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    labels[i]=spannable;
    publishProgress(labels);
    cachedCountStr+=count;
    if (i < length - 1) {
      cachedCountStr+=",";
    }
  }
  SharedPreferences.Editor editor=Preferences.getEditor(TopLevelActivity.this);
  editor.putString(Preferences.TOP_LEVEL_COUNTS_KEY,cachedCountStr);
  editor.commit();
  return null;
}
 

Example 39

From project android-voip-service, under directory /src/main/java/org/linphone/.

Source file: LinphoneActivity.java

  15 
vote

/** 
 * Check Account 
 */
private boolean checkDefined(SharedPreferences pref,int... keys){
  for (  int key : keys) {
    String conf=pref.getString(getString(key),null);
    if (conf == null || "".equals(conf))     return false;
  }
  return true;
}
 

Example 40

From project androidannotations, under directory /AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/api/sharedpreferences/.

Source file: SharedPreferencesCompat.java

  15 
vote

private static Method findApplyMethod(){
  try {
    Class<Editor> cls=SharedPreferences.Editor.class;
    return cls.getMethod("apply");
  }
 catch (  NoSuchMethodException unused) {
  }
  return null;
}