use of android.content.SharedPreferences in project platform_frameworks_base by android.
the class BugreportPrefs method setWarningState.
static void setWarningState(Context context, int value) {
final SharedPreferences prefs = context.getSharedPreferences(PREFS_BUGREPORT, Context.MODE_PRIVATE);
prefs.edit().putInt(KEY_WARNING_STATE, value).apply();
}
use of android.content.SharedPreferences in project ShowcaseView by amlcurran.
the class ShotStateStore method storeShot.
void storeShot() {
if (isSingleShot()) {
SharedPreferences internal = context.getSharedPreferences(PREFS_SHOWCASE_INTERNAL, Context.MODE_PRIVATE);
internal.edit().putBoolean("hasShot" + shotId, true).apply();
}
}
use of android.content.SharedPreferences in project google-services by googlesamples.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
mInformationTextView.setText(getString(R.string.gcm_send_message));
} else {
mInformationTextView.setText(getString(R.string.token_error_message));
}
}
};
mInformationTextView = (TextView) findViewById(R.id.informationTextView);
// Registering BroadcastReceiver
registerReceiver();
if (checkPlayServices()) {
// Start IntentService to register this application with GCM.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
}
use of android.content.SharedPreferences in project google-services by googlesamples.
the class RegistrationIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// [START register_for_gcm]
// Initially this call goes out to the network to retrieve the token, subsequent calls
// are local.
// R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
// See https://developers.google.com/cloud-messaging/android/start for details on this file.
// [START get_token]
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
// [END get_token]
Log.i(TAG, "GCM Registration Token: " + token);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(token);
// Subscribe to topic channels
subscribeTopics(token);
// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
// [END register_for_gcm]
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
}
// Notify UI that registration has completed, so the progress indicator can be hidden.
Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
use of android.content.SharedPreferences in project iosched by google.
the class AnalyticsHelper method setupPreferenceChangeListener.
/**
* Listens for preference changes. When a preference change relevant to toggling Analytics
* is detected, {@link AnalyticsHelper#enableOrDisableAnalyticsAsNecessary()} is called, which
* will decide whether Analytics should be enabled or disabled based on settings_prefs and
* application state.
*/
private static void setupPreferenceChangeListener() {
SharedPreferences userPrefs = PreferenceManager.getDefaultSharedPreferences(sAppContext);
sPrefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
// Most of the preferences will use these defaults.
String category = "Preference";
if (key != null) {
if (key.equals(SettingsUtils.PREF_TOS_ACCEPTED) || key.equals(SettingsUtils.PREF_ANALYTICS_ENABLED)) {
// If TOS is accepted, initialize the Analytics Tracker.
if (key.equals(SettingsUtils.PREF_TOS_ACCEPTED) && prefs.getBoolean(key, false) && mTracker == null) {
initializeAnalyticsTracker(sAppContext);
}
// Technically it's possible to just look up the values in the pref
// object provided and enable/disable in here, but it's safer to have all the
// "should analytics run" logic collected in one place.
enableOrDisableAnalyticsAsNecessary();
} else if (key.equals(SettingsUtils.PREF_LOCAL_TIMES)) {
String label = "Local time";
// ANALYTICS EVENT: Updated "Show Local Times" setting.
// Contains: The checkbox state of this setting.
sendEvent(category, getAction(prefs, key), label);
} else if (key.equals(BuildConfig.PREF_ATTENDEE_AT_VENUE)) {
// Toggle the "Attending in person" custom dimension so we can track
// how venue attendee behavior contrasts with remote attendee behavior.
boolean attending = prefs.getBoolean(key, true);
// ANALYTICS EVENT: Updated "On-Site Attendee" preference.
// Contains: Whether the attendee is identifying themselves as onsite or remote.
String attendeeType = attending ? "On-Site Attendee" : "Remote Attendee";
String label = "Will be at I/O";
sendEventWithCustomDimension(category, getAction(prefs, key), label, SLOT_ATTENDING_DIMENSION, attendeeType);
} else if (key.equals(BuildConfig.PREF_CONF_MESSAGES_ENABLED)) {
String label = "Conference Notification Cards";
// ANALYTICS EVENT: Updated "Conference Notification Cards" setting.
// Contains: The checkbox state of this setting.
sendEvent(category, getAction(prefs, key), label);
} else if (key.equals(SettingsUtils.PREF_SYNC_CALENDAR)) {
String label = "Sync with Google Calendar";
// ANALYTICS EVENT: Updated "Sync with Google Calendar" setting.
// Contains: The checkbox state of this setting.
sendEvent(category, getAction(prefs, key), label);
} else if (key.equals(BuildConfig.PREF_SESSION_REMINDERS_ENABLED)) {
String label = "Session Reminders";
// ANALYTICS EVENT: Updated "Session Reminders" setting.
// Contains: The checkbox state of this setting.
sendEvent(category, getAction(prefs, key), label);
} else if (key.equals(BuildConfig.PREF_SESSION_FEEDBACK_REMINDERS_ENABLED)) {
String label = "Feedback Reminders";
// ANALYTICS EVENT: Updated "Feedback Reminders" setting.
// Contains: The checkbox state of this setting.
sendEvent(category, getAction(prefs, key), label);
}
}
}
};
userPrefs.registerOnSharedPreferenceChangeListener(sPrefListener);
}
Aggregations