Search in sources :

Example 66 with SharedPreferences

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();
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 67 with SharedPreferences

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();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 68 with SharedPreferences

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);
    }
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 69 with SharedPreferences

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);
}
Also used : SharedPreferences(android.content.SharedPreferences) InstanceID(com.google.android.gms.iid.InstanceID) Intent(android.content.Intent) IOException(java.io.IOException)

Example 70 with SharedPreferences

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);
}
Also used : SharedPreferences(android.content.SharedPreferences)

Aggregations

SharedPreferences (android.content.SharedPreferences)1762 Intent (android.content.Intent)221 View (android.view.View)110 Editor (android.content.SharedPreferences.Editor)100 TextView (android.widget.TextView)74 ArrayList (java.util.ArrayList)67 Context (android.content.Context)59 PendingIntent (android.app.PendingIntent)57 File (java.io.File)57 IOException (java.io.IOException)56 Bundle (android.os.Bundle)45 JSONException (org.json.JSONException)41 JSONObject (org.json.JSONObject)41 DialogInterface (android.content.DialogInterface)37 AdapterView (android.widget.AdapterView)34 ImageView (android.widget.ImageView)34 ListView (android.widget.ListView)34 SuppressLint (android.annotation.SuppressLint)33 JSONArray (run.wallet.common.json.JSONArray)33 ComponentName (android.content.ComponentName)31