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:de.tu_berlin.snet.probe.FacebookProbe.java

private void fetchFacebook() {
    try {/*  ww w. j a v  a 2 s.c  o m*/
        SharedPreferences prefs = getContext().getSharedPreferences("default", Context.MODE_MULTI_PROCESS);
        Session session = Session.getActiveSession();
        List<Request> requests = new ArrayList<Request>();

        if (session == null) {
            Log.d(TAG, "Facebook Probe not activated.");
            return;
        }

        // default is Tue, 01 Jan 2008 00:00:00 GMT
        int since = prefs.getInt("facebook.since", 1199145600);
        int until = (int) (System.currentTimeMillis() / 1000);

        Bundle params = new Bundle();
        params.putInt("since", since);
        params.putInt("until", until);
        params.putInt("limit", 5000);

        for (final String requestId : REQUEST_IDS) {
            requests.add(new Request(session, requestId, params, null, new Request.Callback() {

                public void onCompleted(Response response) {
                    GraphObject graphObject = response.getGraphObject();
                    FacebookRequestError error = response.getError();

                    if (graphObject != null) {
                        JSONObject orig = graphObject.getInnerJSONObject();
                        JsonObject data = new JsonObject();

                        anonymizeData(orig);
                        data.addProperty(response.getRequest().getGraphPath(), orig.toString());
                        sendData(data);

                    } else if (error != null) {
                        Log.e(TAG, "Error: " + error.getErrorMessage());
                    }
                }

                private Set<String> sensitiveSet = new HashSet<String>(Arrays.asList(SENSITIVE));

                private void anonymizeData(Object o) {
                    try {
                        if (o instanceof JSONObject) {
                            JSONObject obj = (JSONObject) o;

                            // not needed, may contain sensitive data
                            obj.remove("paging");
                            obj.remove("actions");

                            for (Iterator<?> iter = obj.keys(); iter.hasNext();) {
                                String key = (String) iter.next();
                                Object val = obj.get(key);

                                if (!(val instanceof String))
                                    anonymizeData(val);

                                if (sensitiveSet.contains(key))
                                    obj.put(key, sensitiveData((String) val));
                            }
                        } else if (o instanceof JSONArray) {
                            JSONArray arr = (JSONArray) o;

                            for (int i = 0; i < arr.length(); i++)
                                anonymizeData(arr.get(i));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }));
        }
        boolean error = false;
        for (Response r : Request.executeBatchAndWait(requests)) {
            if (r.getError() != null)
                error = true;
        }
        if (!error)
            prefs.edit().putInt("facebook.since", until + 1).commit();

    } catch (Exception e) {
        e.printStackTrace();
    }
    stop();
}

From source file:com.pipit.agc.adapter.DayPickerVerticalAdapter.java

@Override
public void onBindViewHolder(final CardViewHolder holder, final int position) {
    holder.comment.setText(getDayOfWeekText(position + 1));

    /*Set listview height to show 7 days*/
    if (_screenheight < 1) {
        _screenheight = Math.round(Util.getScreenHeightMinusStatusBar(context));
    }/*from  ww  w . ja  va 2 s. co  m*/
    int txtheight = (int) (_screenheight / 7);
    holder.cv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, txtheight));

    final String gymDay = context.getResources().getString(R.string.gym_day);
    final String restDay = context.getResources().getString(R.string.rest_day);
    if (weeklySchedule.contains(position)) {
        holder.cvlayout.setBackgroundColor(ContextCompat.getColor(context, R.color.schemefour_lighterteal));
        holder.comment.setTextColor(ContextCompat.getColor(context, R.color.black));
        //holder.statuscircle.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.schemethree_teal), PorterDuff.Mode.SRC_ATOP);
        holder.statuscircle.setText(gymDay);
    } else {
        holder.cvlayout.setBackgroundColor(ContextCompat.getColor(context, R.color.basewhite));
        holder.comment.setTextColor(ContextCompat.getColor(context, R.color.black));
        //holder.statuscircle.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.schemethree_red), PorterDuff.Mode.SRC_ATOP);
        holder.statuscircle.setText(restDay);
    }

    holder.cv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*Remove or Add the date to the list*/
            String datestr = (Integer.toString(position));

            SharedPreferences prefs = context.getApplicationContext()
                    .getSharedPreferences(Constants.SHARED_PREFS, Context.MODE_MULTI_PROCESS);
            List<String> dates = (SharedPrefUtil.getListFromSharedPref(prefs,
                    Constants.SHAR_PREF_PLANNED_DAYS));
            if (dates.contains(datestr)) {
                //The clicked date was previously a Gym Day, and we need to showTimePickers it off
                dates.remove(datestr);
                Log.d(TAG, "Removed day " + datestr + " from weekly gym days");
                holder.statuscircle.setText(restDay);
                holder.cvlayout.setBackgroundColor(ContextCompat.getColor(context, R.color.basewhite));
                holder.comment.setTextColor(ContextCompat.getColor(context, R.color.black));
                //holder.statuscircle.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.schemethree_red), PorterDuff.Mode.SRC_ATOP);
                if (position == Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1) {
                    if (mFrag instanceof GymPickerVerticalFragment) {
                        ((GymPickerVerticalFragment) mFrag).toggleCurrentGymDayData(false);
                    }
                }
            } else {
                dates.add(datestr);
                Log.d(TAG, "Added day " + datestr + " to weekly gym days");
                holder.statuscircle.setText(gymDay);
                holder.cvlayout
                        .setBackgroundColor(ContextCompat.getColor(context, R.color.schemefour_lighterteal));
                holder.comment.setTextColor(ContextCompat.getColor(context, R.color.basewhite));
                //holder.statuscircle.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.schemethree_teal), PorterDuff.Mode.SRC_ATOP);
                if (position == Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1) {
                    if (mFrag instanceof GymPickerVerticalFragment) {
                        ((GymPickerVerticalFragment) mFrag).toggleCurrentGymDayData(true);
                    }
                }

            }
            SharedPrefUtil.putListToSharedPref(prefs.edit(), Constants.SHAR_PREF_PLANNED_DAYS, dates);
            updateData(null, null, new HashSet<Integer>(Util.listOfStringsToListOfInts(dates)));
        }
    });

}

From source file:Steps.StepsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
    goal = prefs.getInt("goal", Fragment_Settings.DEFAULT_GOAL);
    //fix on create activity cout not to be 0 (non initalized)
    Database db = Database.getInstance(getActivity());
    todayOffset = db.getSteps(Util.getToday());
    since_boot = db.getCurrentSteps();/*from www  . java2s .  c o m*/
    steps = Math.max(todayOffset + since_boot, 0);

    rg = new DistributedRandomNumberGenerator(getActivity());

    db.close();

}

From source file:org.opendatakit.common.android.logic.PropertiesSingleton.java

/**
 * SharedPreferences are ONLY available from within ODK Services.
 *
 * @param context/*from  w  w  w  .  ja  v  a  2  s . c  om*/
 * @return
  */
private static SharedPreferences getSharedPreferences(Context context) {
    try {
        if (!context.getPackageName().equals(IntentConsts.AppProperties.APPLICATION_NAME)) {
            return null;
        }
        return context.getSharedPreferences(context.getPackageName(),
                Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
    } catch (Exception e) {
        Log.e("PropertiesSingleton", "Unable to access SharedPreferences!");
        return null;
    }
}

From source file:com.github.caifatcmd.VolumeService.java

@Override
public void onCreate() {
    pref = getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS);
    //pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String atcmdBinaryName = getApplicationContext().getResources().getText(R.string.atcmd_binary).toString();
    if ((new File("/system/bin/caifatcmd")).isFile())
        atcmdBinary = "/system/bin/caifatcmd";
    else if ((new File(getApplicationInfo().dataDir + "/lib/" + atcmdBinaryName)).isFile())
        atcmdBinary = getApplicationInfo().dataDir + "/lib/" + atcmdBinaryName;

    // Get current volume
    Integer retVal = 0; // = runATCmd(0);
    currentVolume = MAX_VOL; // - retVal + 1;
    gotoVolume = pref.getInt(CURR_VOL_KEY, currentVolume);
    Log.d("CallVolService", "Stored volume at " + gotoVolume);

    if (gotoVolume != currentVolume)
        retVal = runATCmd(gotoVolume);//from  w w  w.  jav  a 2s . c o  m

    if (retVal >= 0)
        currentVolume = gotoVolume;
    pref.edit().putInt(CURR_VOL_KEY, currentVolume).commit();
    //pref.edit().commit();

    //serviceActive = true;
    //stopSelf();

    super.onCreate();
    //return Service.START_NOT_STICKY;

    broadcaster = LocalBroadcastManager.getInstance(this);
    receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateVolumeData();
        }
    };
}

From source file:org.anhonesteffort.flock.sync.AbstractDavSyncAdapter.java

public static void disableAuthNotificationsForRunningAdapters(Context context, Account account) {
    AddressbookSyncScheduler addressbookSync = new AddressbookSyncScheduler(context);
    CalendarsSyncScheduler calendarSync = new CalendarsSyncScheduler(context);
    KeySyncScheduler keySync = new KeySyncScheduler(context);
    SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_MULTI_PROCESS);

    if (addressbookSync.syncInProgress(account)) {
        settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + addressbookSync.getAuthority(), true).commit();
        Log.e(TAG, "disabling auth notifications for " + addressbookSync.getAuthority());
    }/* w  w w  . j a  v a  2 s .  c  om*/

    if (calendarSync.syncInProgress(account)) {
        settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + calendarSync.getAuthority(), true).commit();
        Log.e(TAG, "disabling auth notifications for " + calendarSync.getAuthority());
    }

    if (keySync.syncInProgress(account)) {
        settings.edit().putBoolean(KEY_VOID_AUTH_NOTIFICATIONS + keySync.getAuthority(), true).commit();
        Log.e(TAG, "disabling auth notifications for " + keySync.getAuthority());
    }
}

From source file:it.feio.android.omninotes.async.MainMenuTask.java

private boolean checkSkippableItem(int i) {
    boolean skippable = false;
    SharedPreferences prefs = mainActivity.getSharedPreferences(Constants.PREFS_NAME,
            Context.MODE_MULTI_PROCESS);
    boolean dynamicMenu = prefs.getBoolean(Constants.PREF_DYNAMIC_MENU, true);
    DynamicNavigationLookupTable dynamicNavigationLookupTable = null;
    if (dynamicMenu) {
        dynamicNavigationLookupTable = DynamicNavigationLookupTable.getInstance();
    }/*from   ww  w . j  a  va 2  s . c o  m*/
    switch (i) {
    case Navigation.REMINDERS:
        if (dynamicMenu && dynamicNavigationLookupTable.getReminders() == 0)
            skippable = true;
        break;
    case Navigation.UNCATEGORIZED:
        boolean showUncategorized = prefs.getBoolean(Constants.PREF_SHOW_UNCATEGORIZED, false);
        if (!showUncategorized || (dynamicMenu && dynamicNavigationLookupTable.getUncategorized() == 0))
            skippable = true;
        break;
    case Navigation.ARCHIVE:
        if (dynamicMenu && dynamicNavigationLookupTable.getArchived() == 0)
            skippable = true;
        break;
    case Navigation.TRASH:
        if (dynamicMenu && dynamicNavigationLookupTable.getTrashed() == 0)
            skippable = true;
        break;
    }
    return skippable;
}

From source file:com.dycody.android.idealnote.async.MainMenuTask.java

private boolean checkSkippableItem(int i) {
    boolean skippable = false;
    SharedPreferences prefs = mainActivity.getSharedPreferences(Constants.PREFS_NAME,
            Context.MODE_MULTI_PROCESS);
    boolean dynamicMenu = prefs.getBoolean(Constants.PREF_DYNAMIC_MENU, true);
    DynamicNavigationLookupTable dynamicNavigationLookupTable = null;
    if (dynamicMenu) {
        dynamicNavigationLookupTable = DynamicNavigationLookupTable.getInstance();
    }/*from w  ww.j  av  a2  s . c  o  m*/
    switch (i) {
    case Navigation.REMINDERS:
        if (dynamicMenu && dynamicNavigationLookupTable.getReminders() == 0)
            skippable = false;
        break;
    case Navigation.UNCATEGORIZED:
        boolean showUncategorized = prefs.getBoolean(Constants.PREF_SHOW_UNCATEGORIZED, false);
        if (!showUncategorized || (dynamicMenu && dynamicNavigationLookupTable.getUncategorized() == 0))
            skippable = true;
        break;
    case Navigation.ARCHIVE:
        if (dynamicMenu && dynamicNavigationLookupTable.getArchived() == 0)
            skippable = false;
        break;
    case Navigation.TRASH:
        if (dynamicMenu && dynamicNavigationLookupTable.getTrashed() == 0)
            skippable = false;
        break;
    default:
        Log.e(Constants.TAG, "Wrong element choosen: " + i);
    }
    return skippable;
}

From source file:org.zywx.wbpalmstar.engine.EBrowserWidgetPool.java

public void pushNotify(String appType) {
    SharedPreferences pres = mContext.getSharedPreferences("saveData", Context.MODE_MULTI_PROCESS);
    String appId = pres.getString(BConstant.F_PUSH_APPID, "");
    if (TextUtils.isEmpty(appId)) {
        mWgtStack.peek().pushNotify(appType);
    } else {/*from   www  .  j a v a2  s. c o  m*/
        EBrowserWidget widget = mWgtStack.get(appId);
        if (null != widget) {
            widget.pushNotify(appType);
        } else {
            mWgtStack.peek().pushNotify(appType);
        }
    }
}

From source file:org.computeforcancer.android.PrefsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (Logging.VERBOSE)
        Log.d(Logging.TAG, "ProjectsFragment onCreateView");
    // Inflate the layout for this fragment
    View layout = inflater.inflate(R.layout.prefs_layout, container, false);
    lv = (ListView) layout.findViewById(R.id.listview);
    listAdapter = new PrefsListAdapter(getActivity(), this, R.id.listview, data);
    lv.setAdapter(listAdapter);/*from   w  ww .  ja v a2s .  c  om*/
    final SharedPreferences mSharedPreferences = getContext().getSharedPreferences(
            "org.computeforcancer.android", Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
    mAutoStart = (SwitchCompat) layout.findViewById(R.id.switchRun);
    mAutoStart.setChecked(mSharedPreferences.getBoolean(SharedPrefs.AUTO_START, true));
    mAutoStart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSharedPreferences.edit().putBoolean(SharedPrefs.AUTO_START, b).commit();
            try {
                BOINCActivity.monitor.setAutostart(b);
                BOINCActivity.monitor.setRunMode(b ? BOINCDefs.RUN_MODE_AUTO : BOINCDefs.RUN_MODE_NEVER);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    });

    mDailyButton = (AppCompatRadioButton) layout.findViewById(R.id.checkBtnDaily);
    mDailyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mDailyButton.setChecked(true);
            mWeeklyButton.setChecked(false);
            mMonthlyButton.setChecked(false);
            mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, DAY).commit();
        }
    });
    mWeeklyButton = (AppCompatRadioButton) layout.findViewById(R.id.checkBtnWeekly);
    mWeeklyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mDailyButton.setChecked(false);
            mWeeklyButton.setChecked(true);
            mMonthlyButton.setChecked(false);
            mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, WEEK).commit();
        }
    });
    mMonthlyButton = (AppCompatRadioButton) layout.findViewById(R.id.checkBtnMonthly);
    mMonthlyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mDailyButton.setChecked(false);
            mWeeklyButton.setChecked(false);
            mMonthlyButton.setChecked(true);
            mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, MONTH).commit();
        }
    });
    final SwitchCompat notificationSwitch = (SwitchCompat) layout.findViewById(R.id.switchNotifications);

    notificationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                mDailyButton.setChecked(true);
                mWeeklyButton.setChecked(false);
                mMonthlyButton.setChecked(false);
                mDailyButton.setEnabled(true);
                mWeeklyButton.setEnabled(true);
                mMonthlyButton.setEnabled(true);
                if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY,
                        Long.MAX_VALUE) == Long.MAX_VALUE) {
                    mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, DAY).commit();
                }
            } else {
                mDailyButton.setChecked(true);
                mWeeklyButton.setChecked(false);
                mMonthlyButton.setChecked(false);
                mDailyButton.setEnabled(false);
                mWeeklyButton.setEnabled(false);
                mMonthlyButton.setEnabled(false);
                mSharedPreferences.edit().putLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE).commit();
            }
        }
    });

    if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE) == DAY) {
        notificationSwitch.setChecked(true);
        mDailyButton.setChecked(true);
        mWeeklyButton.setChecked(false);
        mMonthlyButton.setChecked(false);
        mDailyButton.setEnabled(true);
        mWeeklyButton.setEnabled(true);
        mMonthlyButton.setEnabled(true);
    } else if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE) == WEEK) {
        notificationSwitch.setChecked(true);
        mDailyButton.setChecked(false);
        mWeeklyButton.setChecked(true);
        mMonthlyButton.setChecked(false);
        mDailyButton.setEnabled(true);
        mWeeklyButton.setEnabled(true);
        mMonthlyButton.setEnabled(true);
    } else if (mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE) == MONTH) {
        notificationSwitch.setChecked(true);
        mDailyButton.setChecked(false);
        mWeeklyButton.setChecked(false);
        mMonthlyButton.setChecked(true);
        mDailyButton.setEnabled(true);
        mWeeklyButton.setEnabled(true);
        mMonthlyButton.setEnabled(true);
    } else {
        notificationSwitch.setChecked(false);
        mDailyButton.setChecked(true);
        mWeeklyButton.setChecked(false);
        mMonthlyButton.setChecked(false);
        mDailyButton.setEnabled(false);
        mWeeklyButton.setEnabled(false);
        mMonthlyButton.setEnabled(false);
    }

    return layout;
}