Search in sources :

Example 6 with SharedPreferences

use of android.content.SharedPreferences in project EazeGraph by blackfizz.

the class NavigationDrawerFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Read in the flag indicating whether or not the user has demonstrated awareness of the
    // drawer. See PREF_USER_LEARNED_DRAWER for details.
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
    if (savedInstanceState != null) {
        mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
        mFromSavedInstanceState = true;
    }
    // Select either the default item (0) or the last selected item.
    selectItem(mCurrentSelectedPosition);
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 7 with SharedPreferences

use of android.content.SharedPreferences in project AndroidCourseResources by bignerdranch.

the class ProviderReceiver method setIndex.

public static void setIndex(Context context, int index) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit().putInt(PREF_INDEX, index).commit();
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 8 with SharedPreferences

use of android.content.SharedPreferences in project baker-android by bakerframework.

the class GindActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    if (this.getActionBar() != null) {
        this.getActionBar().hide();
    }
    sdfInput = new SimpleDateFormat(getString(R.string.inputDateFormat), Locale.US);
    sdfOutput = new SimpleDateFormat(getString(R.string.outputDateFormat), Locale.US);
    Intent intent = this.getIntent();
    if (intent.hasExtra("START_DOWNLOAD")) {
        this.startDownload = intent.getStringExtra("START_DOWNLOAD");
    }
    try {
        loadingScreen();
        STANDALONE_MODE = getResources().getBoolean(R.bool.run_as_standalone);
        //Getting the user main account
        AccountManager manager = AccountManager.get(this);
        Account[] accounts = manager.getAccountsByType("com.google");
        // any account the user have on the phone.
        if (accounts.length == 0) {
            accounts = manager.getAccounts();
        }
        if (accounts.length != 0) {
            // We will use the first account on the list.
            userAccount = accounts[0].type + "_" + accounts[0].name;
        } else {
            // Wow, if we still do not have any working account
            // then we will have to use the ANDROID_ID,
            // Read: http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID
            Log.e(this.getClass().toString(), "USER ACCOUNT COULD NOT BE RETRIEVED, WILL USE ANDROID_ID.");
            userAccount = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        }
        Log.d(this.getClass().getName(), "APP_ID: " + this.getString(R.string.app_id) + ", USER_ID: " + userAccount);
        if (checkPlayServices()) {
            Log.d(this.getClass().getName(), "Google Play Services enabled.");
            gcm = GoogleCloudMessaging.getInstance(this);
            registrationId = getRegistrationId(this.getApplicationContext());
            Log.d(this.getClass().getName(), "Obtained registration ID: " + registrationId);
            registerInBackground();
        } else {
            Log.e(this.getClass().toString(), "No valid Google Play Services APK found.");
        }
        if (STANDALONE_MODE) {
            activateStandalone();
        } else {
            CheckInternetTask checkInternetTask = new CheckInternetTask(this, this, CHECK_INTERNET_TASK);
            checkInternetTask.execute();
        }
        SharedPreferences sharedPreferences = this.getPreferences();
        if (sharedPreferences.getBoolean(Configuration.FIRST_TIME_RUN, true) && getResources().getBoolean(R.bool.ut_enable_tutorial)) {
            //the app is being launched for first time, do something
            Log.d(this.getClass().getName(), "First time app running, launching tutorial.");
            showAppUsage();
            sharedPreferences.edit().putBoolean(Configuration.FIRST_TIME_RUN, false).apply();
        }
        // Here we register the APP OPEN event on Google Analytics
        if (getResources().getBoolean(R.bool.ga_enable) && getResources().getBoolean(R.bool.ga_register_app_open_event)) {
            ((ABakerApp) this.getApplication()).sendEvent(getString(R.string.application_category), getString(R.string.application_open), getString(R.string.application_open_label));
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(this.getClass().getName(), "Cannot load configuration.");
    }
}
Also used : Account(android.accounts.Account) CheckInternetTask(com.baker.abaker.workers.CheckInternetTask) SharedPreferences(android.content.SharedPreferences) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) AccountManager(android.accounts.AccountManager) SimpleDateFormat(java.text.SimpleDateFormat) JSONException(org.json.JSONException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 9 with SharedPreferences

use of android.content.SharedPreferences in project baker-android by bakerframework.

the class GindActivity method saveExtractionFinished.

private void saveExtractionFinished(boolean state) {
    final SharedPreferences preferences = this.getPreferences();
    SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean(Configuration.EXTRACTION_FINISHED, state);
    editor.apply();
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 10 with SharedPreferences

use of android.content.SharedPreferences in project baker-android by bakerframework.

the class GcmBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (testing == false) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        receiveNotifications = sharedPreferences.getBoolean(Configuration.PREF_RECEIVE_NOTIFICATIONS, true);
        receiveNotificationsDownload = sharedPreferences.getBoolean(Configuration.PREF_RECEIVE_NOTIFICATIONS_DOWNLOAD, true);
        receiveNotificationsDownloadOnlyWifi = sharedPreferences.getBoolean(Configuration.PREF_RECEIVE_NOTIFICATIONS_DOWNLOAD_ONLY_WIFI, true);
        canDownload = !receiveNotificationsDownloadOnlyWifi | Configuration.connectionIsWiFi(context);
    }
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    messageType = gcm.getMessageType(intent);
    if (!receiveNotifications) {
        processFinishedCode = 1;
        return;
    }
    if (!extras.isEmpty()) {
        // has effect of unparcelling Bundle
        Log.i(this.getClass().toString(), "Received: " + extras.toString());
        /**
             * Filter messages based on message type. Since it is likely that GCM
             * will be extended in the future with new message types, just ignore
             * any message types you're not interested in, or that you don't
             * recognize.
             **/
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification(context, "Error notification", "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification(context, "Deleted messages", "Deleted messages on server: " + extras.toString());
        // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            try {
                JSONObject json = new JSONObject(extras.getString("notificationData"));
                // Values can be either "standard-notification" or "background-download". This value is required.
                String type = json.getString("type");
                if ("standard-notification".equals(type)) {
                    // A title to show at the notification bar in android. This value is optional.
                    String title = json.has("title") ? json.getString("title") : "";
                    // The message description for the notification to show at the notifications bar in android. This value is optional.
                    String message = json.has("message") ? json.getString("message") : "";
                    this.sendNotification(context, title, message);
                } else if ("background-download".equals(type)) {
                    if (receiveNotificationsDownload) {
                        if (canDownload) {
                            processFinishedCode = 4;
                            if (json.has("issueName")) {
                                // Values can be "latest" or the name of the issue, for example "magazine-12". This value is required.
                                String issueName = json.getString("issueName");
                                Intent gindIntent = new Intent(context, GindActivity.class);
                                gindIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                gindIntent.putExtra("START_DOWNLOAD", issueName);
                                context.startActivity(gindIntent);
                            }
                        } else {
                            processFinishedCode = 3;
                            return;
                        }
                    } else {
                        processFinishedCode = 2;
                        return;
                    }
                }
            } catch (Exception ex) {
                // Do nothing, if it fails we simply do not process the notification.
                Log.e(this.getClass().toString(), ex.getMessage());
            }
        // Post notification of received message.
        //sendNotification(context, extras.getString("collapse_key"), extras.getString("message"));
        }
    }
}
Also used : JSONObject(org.json.JSONObject) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) GoogleCloudMessaging(com.google.android.gms.gcm.GoogleCloudMessaging)

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