Example usage for android.content Context MODE_MULTI_PROCESS

List of usage examples for android.content Context MODE_MULTI_PROCESS

Introduction

In this page you can find the example usage for android.content Context MODE_MULTI_PROCESS.

Prototype

int MODE_MULTI_PROCESS

To view the source code for android.content Context MODE_MULTI_PROCESS.

Click Source Link

Document

SharedPreference loading flag: when set, the file on disk will be checked for modification even if the shared preferences instance is already loaded in this process.

Usage

From source file:Steps.StepsFragment.java

/**
 * Update the goal shred preference value with the steps
 * needed for the next goal to be achieved
 *//*from w ww .  j  a  v a  2  s  .  c  o m*/
private void updateGoal() {
    SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
    goal = prefs.getInt("goal", Fragment_Settings.DEFAULT_GOAL);
}

From source file:com.openatk.field_work.MainActivity.java

@Override
protected void onPause() {
    super.onPause();

    CameraPosition myCam = map.getCameraPosition();
    if (myCam != null) {
        SharedPreferences prefs = getApplicationContext().getSharedPreferences("com.openatk.field_work",
                Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = prefs.edit();
        LatLng where = myCam.target;// www. j a va  2s .c  om
        editor.putFloat("StartupLat", (float) where.latitude);
        editor.putFloat("StartupLng", (float) where.longitude);
        editor.putFloat("StartupZoom", (float) map.getCameraPosition().zoom);
        editor.putInt(MainActivity.PREF_GONE, MainActivity.PREF_GONE_NO_UPDATE);
        editor.commit();
    }
    //Set pref so everyone knows MainActivity is no longer here (listening)
    SharedPreferences prefs = getApplicationContext().getSharedPreferences("com.openatk.field_work",
            Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(MainActivity.PREF_GONE, MainActivity.PREF_GONE_NO_UPDATE);
    editor.commit();
    LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReciever);

    syncHelper.onPause();
}

From source file:Steps.StepsFragment.java

/**
 * Update the steps count//from  w ww. ja  v  a 2s  .  co m
 * TODO: this method needs refactoring
 */
private void updateViews() {
    Log.w("updateView", "updateViews");
    //Log.w("update  VIew", Integer.toString(total_start + steps));
    if (!goalAnimationPlaying) {
        if (isChecked) {
            textSteps.setText(Integer.toString(steps) + " steps today ");
        } else {
            SharedPreferences prefs = getActivity().getSharedPreferences("pedometer",
                    Context.MODE_MULTI_PROCESS);
            float height_value = prefs.getFloat("height_value", Fragment_Settings.DEFAULT_Human_Height);
            float stride_lenght;
            if (prefs.getString("sex", Fragment_Settings.DEFAULT_SEX).equals("male")) {
                stride_lenght = (float) (height_value * 0.415);
            } else {
                stride_lenght = (float) (height_value * 0.413);
            }
            float distance_today = (total_start + steps) * stride_lenght;
            if (prefs.getString("stepsize_unit", Fragment_Settings.DEFAULT_STEP_UNIT).equals("cm")) {
                distance_today /= 100000;
            } else {
                distance_today /= 5280;
            }
            textSteps.setText(String.format("%.3f km.", distance_today));
        }
    }
}

From source file:saphion.fragments.alarm.AlarmFragment.java

@SuppressLint("InlinedApi")
@Override//from w  w  w .jav  a2s  .  co m
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    final Context context = AlarmFragment.this.getActivity().getApplicationContext();
    final AsyncTask<Void, Void, Void> updateTask = new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... parameters) {
            ArrayList<AlarmItems> prevAlarms = AlarmPreference.retAlarms(getBaseContext());

            for (AlarmItems alarm : prevAlarms)

                if (context != null && alarm != null) {
                    ContentResolver cr = context.getContentResolver();
                    if (!Alarm.contains(context.getContentResolver(), new Alarm(alarm)))
                        Alarm.addAlarm(cr, alarm);

                }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            getActivity().getSharedPreferences("saphion.batterycaster_preferences", Context.MODE_MULTI_PROCESS)
                    .edit().putBoolean("FirstAfterUpdate", false).commit();
        }

    };
    if (getActivity().getSharedPreferences("saphion.batterycaster_preferences", Context.MODE_MULTI_PROCESS)
            .getBoolean("FirstAfterUpdate", true)) {

        updateTask.execute();
    }
    created = true;

    return Alarm.getAlarmsCursorLoader(getActivity());
}

From source file:com.openatk.field_work.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_FIELD_UPDATED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_JOB_UPDATED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_OPERATION_UPDATED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_WORKER_UPDATED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_FIELD_DELETED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_JOB_DELETED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_OPERATION_DELETED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_WORKER_DELETED));
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReciever,
            new IntentFilter(MainActivity.INTENT_EVERYTHING_DELETED));

    this.syncHelper.onResume(this); //Startup autosync if it is on

    SharedPreferences prefs = getApplicationContext().getSharedPreferences("com.openatk.field_work",
            Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);

    Boolean syncOccured = false;//w  w w. j ava 2 s  . c  o m
    //Didn't do a full reload, check if sync occurred while we were gone.
    if (prefs.getInt(MainActivity.PREF_GONE,
            MainActivity.PREF_GONE_NO_UPDATE) == MainActivity.PREF_GONE_UPDATE) {
        //We need to update the entire screen... Cloud sync occurred while we were gone and it made changes.
        //Clear atkmaps data
        Log.w("MainActivity - onResume", "Sync occured while we were gone. Reload everything.");
        map.clear();

        //Get the current selected field if there is one
        Integer selectedField = null;
        if (this.savedInstanceState != null) {
            selectedField = savedInstanceState.getInt("currentField", -100);
            if (selectedField == -100)
                selectedField = null;
        }

        this.currentFieldView = null;

        //Reload all fields from the db
        this.createFieldViews(selectedField);

        //Reload the operations
        this.updateCurrentOperation();

        //Update fragmentJob if its up
        this.updateFragmentJob();

        //Reload the list view data
        if (this.fragmentListView != null)
            this.fragmentListView.getData();
        syncOccured = true;
    }

    //Set pref so everyone knows MainActivity is active
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(MainActivity.PREF_GONE, MainActivity.PREF_GONE_HERE);
    editor.commit();
    if (syncOccured) {
        //Sync again in case this is a new organization
        this.syncHelper.sync(this);
    }
    //drawHazards();
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWidget.java

public void getPushState(String[] parm) {
    SharedPreferences sp = mContext.getSharedPreferences("saveData", Context.MODE_MULTI_PROCESS);
    String pushMes = sp.getString("pushMes", "0");
    String localPushMes = sp.getString("localPushMes", pushMes);
    jsCallback(function_getPushState, 0, EUExCallback.F_C_INT, Integer.parseInt(localPushMes));
}

From source file:me.piebridge.bible.Bible.java

String getRemoteVersions() throws ClientProtocolException, IOException {
    HttpClient client = new DefaultHttpClient();
    SharedPreferences sp = mContext.getSharedPreferences("json", Context.MODE_MULTI_PROCESS);
    String etag = sp.getString(JSON + "_etag", null);
    HttpGet get = new HttpGet(Bible.BIBLEDATA_PREFIX + JSON);
    if (etag != null) {
        get.addHeader("If-None-Match", etag);
    }/*from  w w  w  . j a v  a  2  s .  c o  m*/
    HttpResponse response = client.execute(get);
    if (response.getStatusLine().getStatusCode() == 304) {
        Log.d(TAG, JSON + " not modified");
        return null;
    }
    InputStream is = response.getEntity().getContent();
    String json = getStringFromInputStream(is);
    is.close();
    try {
        new JSONObject(json);
    } catch (JSONException e) {
        Log.d(TAG, "json: " + json);
        return null;
    }
    try {
        Header header = response.getFirstHeader("ETag");
        if (header != null) {
            sp.edit().putString(JSON + "_etag", header.getValue()).commit();
        }
        File tmpfile = new File(mContext.getFilesDir(), JSON + ".tmp");
        OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpfile));
        os.write(json.getBytes("UTF-8"));
        os.close();
        tmpfile.renameTo(new File(mContext.getFilesDir(), JSON));
    } catch (IOException e) {
    }
    return json;
}

From source file:com.auratech.launcher.Workspace.java

protected void setWallpaperDimension() {
    new AsyncTask<Void, Void, Void>() {
        public Void doInBackground(Void... args) {
            String spKey = WallpaperCropActivity.getSharedPreferencesKey();
            SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
            LauncherWallpaperPickerActivity.suggestWallpaperDimension(mLauncher.getResources(), sp,
                    mLauncher.getWindowManager(), mWallpaperManager);
            return null;
        }/*from w w  w  . j  av a  2s . co  m*/
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}

From source file:com.fairphone.fplauncher3.Workspace.java

protected void setWallpaperDimension() {
    new AsyncTask<Void, Void, Void>() {
        public Void doInBackground(Void... args) {
            String spKey = WallpaperCropActivity.getSharedPreferencesKey();
            SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
            LauncherWallpaperPickerActivity.suggestWallpaperDimension(mLauncher.getResources(), sp,
                    mLauncher.getWindowManager(), mWallpaperManager, Launcher.overrideWallpaperDimensions());
            return null;
        }/*  ww w.ja  v  a  2s  . c o m*/

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            mLauncher.updateDarknessOverlay();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

protected void setWallpaperDimension() {
    new AsyncTask<Void, Void, Void>() {
        public Void doInBackground(Void... args) {
            String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
            SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
            WallpaperUtils.suggestWallpaperDimension(mLauncher.getResources(), sp, mLauncher.getWindowManager(),
                    mWallpaperManager, mLauncher.overrideWallpaperDimensions());
            return null;
        }//w ww  . j a v a 2  s .c  o m
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}