Android Open Source - MapAlarmist Settings Activity






From Project

Back to project page MapAlarmist.

License

The source code is released under:

Copyright 2013 Guilhem Vellut <guilhem@vellut.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), t...

If you think the Android project MapAlarmist 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

package com.vellut.geoalarm;
//from w  w w  . j a  va2s.c om
import com.google.analytics.tracking.android.EasyTracker;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

public class SettingsActivity extends Activity implements
    SharedPreferences.OnSharedPreferenceChangeListener {

  private SettingsFragment settingsFragment;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    settingsFragment = new SettingsFragment();
    getFragmentManager().beginTransaction()
        .replace(android.R.id.content, settingsFragment).commit();
  }
  
  @Override
  protected void onStart() {
    super.onStart();
    EasyTracker.getInstance(this).activityStart(this);
  }
  
  @Override 
  protected void onStop() {
    super.onStop();
    EasyTracker.getInstance(this).activityStop(this);
  }

  @Override
  protected void onResume() {
    super.onResume();
    PreferenceManager.getDefaultSharedPreferences(this)
        .registerOnSharedPreferenceChangeListener(this);
  }

  @Override
  protected void onPause() {
    super.onPause();
    PreferenceManager.getDefaultSharedPreferences(this)
        .unregisterOnSharedPreferenceChangeListener(this);
  }

  public static class SettingsFragment extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      addPreferencesFromResource(R.xml.settings);

      for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        initSummary(getPreferenceScreen().getPreference(i));
      }
    }
  }

  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
      String key) {
    Preference pref = settingsFragment.findPreference(key);
    updateSummary(pref);
    
    GeoAlarmUtils.trackEvent(this, "ui_action", "button_press", "changed_location_technique",
        null);
  }

  private static void initSummary(Preference p) {
    if (p instanceof PreferenceCategory) {
      PreferenceCategory pCat = (PreferenceCategory) p;
      for (int i = 0; i < pCat.getPreferenceCount(); i++) {
        initSummary(pCat.getPreference(i));
      }
    } else {
      updateSummary(p);
    }
  }

  private static void updateSummary(Preference p) {
    if (p instanceof ListPreference) {
      ListPreference listPref = (ListPreference) p;
      p.setSummary(listPref.getEntry());
    }
    if (p instanceof EditTextPreference) {
      EditTextPreference editTextPref = (EditTextPreference) p;
      p.setSummary(editTextPref.getText());
    }
  }

}




Java Source Code List

com.vellut.geoalarm.AlarmWakeUpBroadcastReceiver.java
com.vellut.geoalarm.AlarmWakeUpService.java
com.vellut.geoalarm.GeoAlarmBootServiceStarter.java
com.vellut.geoalarm.GeoAlarmBootService.java
com.vellut.geoalarm.GeoAlarmUtils.java
com.vellut.geoalarm.GeoAlarm.java
com.vellut.geoalarm.MainActivity.java
com.vellut.geoalarm.ReceiveTransitionsBroadcastReceiver.java
com.vellut.geoalarm.ReceiveTransitionsIntentService.java
com.vellut.geoalarm.SavedLocation.java
com.vellut.geoalarm.SettingsActivity.java
com.vellut.geoalarm.SwipeDismissListViewTouchListener.java
com.vellut.geoalarm.io.LatLngBoundsDeserializer.java
com.vellut.geoalarm.io.LatLngBoundsSerializer.java