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:com.darshancomputing.BatteryIndicatorPro.BatteryInfoService.java

private void loadSettingsFiles() {
    settings = getSharedPreferences(SettingsActivity.SETTINGS_FILE, Context.MODE_MULTI_PROCESS);
    sp_service = getSharedPreferences(SettingsActivity.SP_SERVICE_FILE, Context.MODE_MULTI_PROCESS);
}

From source file:ca.mimic.apphangar.Settings.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInstance = this;

    setContentView(R.layout.activity_settings);

    prefs = new PrefsGet(getSharedPreferences(getPackageName(), Context.MODE_MULTI_PROCESS));

    mContext = this;

    if (showChangelog(prefs)) {
        launchChangelog();/*from   w w  w . java2s  .  co m*/
    }

    display = getWindowManager().getDefaultDisplay();
    updateDisplayWidth();

    myService = new ServiceCall(mContext);
    myService.setConnection(mConnection);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    actionBar.setTitle(R.string.title_activity_settings);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setCustomView(R.layout.action_spinner);
    setUpSpinner((Spinner) actionBar.getCustomView().findViewById(R.id.config_spinner));
    actionBar.setDisplayShowCustomEnabled(true);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(4);

    mGetFragments = new GetFragments();
    mGetFragments.setFm(getFragmentManager());
    mGetFragments.setVp(mViewPager);

    ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    };

    mViewPager.setOnPageChangeListener(pageChangeListener);

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    pageChangeListener.onPageSelected(GENERAL_TAB);

}

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

private void setUpMapIfNeeded() {
    if (map == null) {
        //TODO IDK if we need this, check beginning of onCreate
        map = ((ATKSupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getAtkMap();
    }/*from ww w  . java 2s.  c  o m*/

    if (atkMapFragment.getRetained() == false) {
        Log.d("setUpMapIfNeeded", "New map need to set it up");

        //New map, we need to set it up
        setUpMap();

        SharedPreferences prefs = this.getSharedPreferences("com.openatk.field_work", Context.MODE_PRIVATE);
        Float startLat = prefs.getFloat("StartupLat", START_LAT);
        Float startLng = prefs.getFloat("StartupLng", START_LNG);
        Float startZoom = prefs.getFloat("StartupZoom", START_ZOOM);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(startLat, startLng), startZoom));

        //TODO do stuff for hazards
        //this.showingHazards = prefs.getBoolean("showingHazards", false);
    } else {
        Log.d("setUpMapIfNeeded", "Old map, get everything from it");

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

        SharedPreferences prefs = getApplicationContext().getSharedPreferences("com.openatk.field_work",
                Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
        //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.
            //We will do this in onResume after we register our receivers.
        } else {
            //Old map we need to get all our data from it
            //Get the FieldViews from ATKMap
            List<ATKPolygonView> polygonViews = map.getPolygonViews();
            for (int i = 0; i < polygonViews.size(); i++) {
                FieldView fieldView = (FieldView) polygonViews.get(i).getData();
                this.fieldViews.add(fieldView);
                Log.d("setUpMapIfNeeded", "selected field:" + Integer.toString(selectedField));
                Log.d("setUpMapIfNeeded", "fieldView:" + Integer.toString(fieldView.getFieldId()));
                if (fieldView.getFieldId() == selectedField) {
                    this.currentFieldView = fieldView;
                }
            }
        }
    }
    Log.d("setUpMapIfNeeded", "map was setup");
    //Setup stuff for new activity
    map.setOnMapClickListener(this);
    map.setOnPolygonClickListener(this);
    map.setOnPointClickListener(this);
    map.setOnPointDragListener(this);
    this.updateCurrentOperation();
}

From source file:ca.mimic.apphangar.Settings.java

@Override
protected void onResume() {
    super.onResume();
    prefs = new PrefsGet(getSharedPreferences(getPackageName(), Context.MODE_MULTI_PROCESS));
    Tools.HangarLog("onResume Settings!");
    try {/*from   w ww  .ja  v  a  2 s.  c o  m*/
        ((Spinner) getActionBar().getCustomView().findViewById(R.id.config_spinner)).setSelection(0);
    } catch (Exception e) {
    }
    if (mLaunchedPaypal) {
        mLaunchedPaypal = false;
        launchThanks(THANK_YOU_PAYPAL);
    }
    myService.watchHelper(START_SERVICE);
}

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

private void determineStatus() {
    try {//www .j  a  v  a 2  s  .  com
        if (mIsBound) {
            ConnectivityManager conMngr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
            android.net.NetworkInfo wifi = conMngr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

            if (!wifi.isConnected()) {
                BOINCActivity.monitor.setAutostart(false);
                BOINCActivity.monitor.setRunMode(BOINCDefs.RUN_MODE_NEVER);
            } else {
                SharedPreferences mSharedPreferences = getApplicationContext().getSharedPreferences(
                        "org.computeforcancer.android", Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
                monitor.setAutostart(mSharedPreferences.getBoolean(SharedPrefs.AUTO_START, true));
                BOINCActivity.monitor.setRunMode(
                        mSharedPreferences.getBoolean(SharedPrefs.AUTO_START, true) ? BOINCDefs.RUN_MODE_AUTO
                                : BOINCDefs.RUN_MODE_NEVER);
            }
            Integer newComputingStatus = monitor.getComputingStatus();
            if (newComputingStatus != clientComputingStatus) {
                // computing status has changed, update and invalidate to force adaption of action items
                clientComputingStatus = newComputingStatus;
                supportInvalidateOptionsMenu();
            }
            /*
            if(numberProjectsInNavList != monitor.getProjects().size())
              numberProjectsInNavList = mDrawerListAdapter.compareAndAddProjects((ArrayList<Project>)monitor.getProjects());
            //setAppTitle();
            */}
    } catch (Exception e) {
    }
}

From source file:Steps.StepsFragment.java

@Override
public void onResume() {
    super.onResume();

    Log.d("RESUMMEE", "resume");
    Database db = Database.getInstance(getActivity());

    SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);

    goal = prefs.getInt("goal", Fragment_Settings.DEFAULT_GOAL);
    db.close();// w ww . j  a v  a2s .  c  o  m
}

From source file:Steps.StepsFragment.java

private void updateStickerPackCountIncrease() {
    SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
    int availableStickerPacks = prefs.getInt("packs", 0);
    availableStickerPacks++;//from  ww w. jav a 2  s .c  om
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt("packs", availableStickerPacks);
    editor.commit();
    buttonOpenPack.setText(Integer.toString(availableStickerPacks) + " New Packs");
}

From source file:Steps.StepsFragment.java

private void updateStickerPackCountText() {

    SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
    int availableStickerPacks = prefs.getInt("packs", 0);
    //      availableStickerPacks++;
    //      SharedPreferences.Editor editor = prefs.edit();
    //   editor.putInt("packs", availableStickerPacks);
    //   editor.commit();
    buttonOpenPack.setText(Integer.toString(availableStickerPacks) + " New Packs");
}

From source file:org.computeforcancer.android.client.Monitor.java

/**
 * Reads client status via RPCs/*from ww  w.  jav  a  2  s.c  o  m*/
 * Optimized to retrieve only subset of information (required to determine wakelock state) if screen is turned off
 * @param forceCompleteUpdate forces update of entire status information, regardless of screen status
 */
private synchronized void readClientStatus(Boolean forceCompleteUpdate) {
    try {
        CcStatus status; // read independently of screen status

        // complete status read, depending on screen status
        // screen off: only read computing status to adjust wakelock, do not send broadcast
        // screen on: read complete status, set ClientStatus, send broadcast
        // forceCompleteUpdate: read complete status, independently of screen setting
        if (screenOn || forceCompleteUpdate) {
            // complete status read, with broadcast
            if (Logging.VERBOSE)
                Log.d(Logging.TAG, "readClientStatus(): screen on, get complete status");
            status = clientInterface.getCcStatus();
            CcState state = clientInterface.getState();
            ArrayList<Transfer> transfers = clientInterface.getFileTransfers();
            AcctMgrInfo acctMgrInfo = clientInterface.getAcctMgrInfo();
            ArrayList<Notice> newNotices = clientInterface
                    .getNotices(Monitor.getClientStatus().getMostRecentNoticeSeqNo());

            if ((status != null) && (state != null) && (state.results != null) && (state.projects != null)
                    && (transfers != null) && (state.host_info != null) && (acctMgrInfo != null)) {
                Monitor.getClientStatus().setClientStatus(status, state.results, state.projects, transfers,
                        state.host_info, acctMgrInfo, newNotices);
            } else {
                String nullValues = "";
                try {
                    if (state == null)
                        nullValues += "state,";
                    if (state.results == null)
                        nullValues += "state.results,";
                    if (state.projects == null)
                        nullValues += "state.projects,";
                    if (transfers == null)
                        nullValues += "transfers,";
                    if (state.host_info == null)
                        nullValues += "state.host_info,";
                    if (acctMgrInfo == null)
                        nullValues += "acctMgrInfo,";
                } catch (NullPointerException e) {
                }
                ;
                if (Logging.ERROR)
                    Log.e(Logging.TAG, "readClientStatus(): connection problem, null: " + nullValues);
            }

            // update notices notification
            //NoticeNotification.getInstance(getApplicationContext()).update(Monitor.getClientStatus().getRssNotices(), Monitor.getAppPrefs().getShowNotificationForNotices());

            // check whether monitor is still intended to update, if not, skip broadcast and exit...
            if (updateBroadcastEnabled) {
                Intent clientStatus = new Intent();
                clientStatus.setAction("org.computeforcancer.android.clientstatus");
                getApplicationContext().sendBroadcast(clientStatus);
            }
        } else {
            // read only ccStatus to adjust wakelocks and service state independently of screen status
            status = clientInterface.getCcStatus();
        }

        // independent of screen on off:
        // wake locks and foreground enabled when Client is not suspended, therefore also during
        // idle.
        // treat cpu throttling as if it was computing.
        Boolean computing = (status.task_suspend_reason == BOINCDefs.SUSPEND_NOT_SUSPENDED)
                || (status.task_suspend_reason == BOINCDefs.SUSPEND_REASON_CPU_THROTTLE);
        if (Logging.VERBOSE)
            Log.d(Logging.TAG, "readClientStatus(): computation enabled: " + computing);
        Monitor.getClientStatus().setWifiLock(computing);
        Monitor.getClientStatus().setWakeLock(computing);
        SharedPreferences mSharedPreferences = getApplicationContext().getSharedPreferences(
                "org.computeforcancer.android", Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
        //Log.d("TEST", "deviceStatus.getStatus().user_active " + deviceStatus.getStatus().user_active);
        if (computing && !deviceStatus.getStatus().user_active) {
            //Log.d("TEST", "computing");
            currTime = System.currentTimeMillis();
            if (currTime - prevTime < 14000) {
                temp = mSharedPreferences.getLong(
                        SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""),
                        0);
                ;
                //Log.d("TEST", "1get DONATION_TIME " + temp);
                //Log.d("TEST", "1put DONATION_TIME " + (temp +
                //      currTime - prevTime));
                mSharedPreferences.edit()
                        .putLong(
                                SharedPrefs.DONATION_TIME
                                        + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""),
                                temp + currTime - prevTime)
                        .commit();
            }
            prevTime = currTime;
            //Log.d("TEST", "1get START_SESSION_TIME " + startSessionTime);
            if (startSessionTime == 0) {
                //Log.d("TEST", "1put START_SESSION_TIME " + currTime);
                startSessionTime = currTime;
            }
        } else {
            //Log.d("TEST", "2get START_SESSION_TIME " + startSessionTime);
            if (startSessionTime != 0) {
                currTime = System.currentTimeMillis();
                mSharedPreferences.edit()
                        .putLong(
                                SharedPrefs.LAST_SESSION_TIME
                                        + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""),
                                currTime - startSessionTime)
                        .commit();

                //Log.d("TEST", "2get DONATION_TIME " + mSharedPreferences.getLong(SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0));

                temp = mSharedPreferences.getLong(
                        SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""),
                        0);
                ;
                mSharedPreferences.edit()
                        .putLong(
                                SharedPrefs.DONATION_TIME
                                        + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""),
                                temp + currTime - prevTime)
                        .commit();
                prevTime = currTime;

                sendDonationTimeMessage(
                        mSharedPreferences.getLong(SharedPrefs.LAST_SESSION_TIME
                                + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0),
                        mSharedPreferences.getLong(SharedPrefs.DONATION_TIME
                                + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0),
                        mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""));
                //Log.d("TEST", "2put START_SESSION_TIME " + 0);
                startSessionTime = 0;
                //Log.d("TEST", "System.currentTimeMillis() " + System.currentTimeMillis());
                //Log.d("TEST", "System.getLastNotification() " + mSharedPreferences.getLong(SharedPrefs.LAST_NOTIFICATION, 0));
                //Log.d("TEST", "System.getNotificationDelay() " + mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE));
                if (currTime - mSharedPreferences.getLong(SharedPrefs.LAST_NOTIFICATION, 0) > mSharedPreferences
                        .getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE)) {
                    mSharedPreferences.edit().putLong(SharedPrefs.LAST_NOTIFICATION, System.currentTimeMillis())
                            .commit();
                    //Log.d("TEST", "get DONATION_TIME " + mSharedPreferences.getLong(SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0));
                    sendNotification(mSharedPreferences.getLong(SharedPrefs.DONATION_TIME
                            + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0));
                }
            }
        }
        //ClientNotification.getInstance(getApplicationContext()).update(Monitor.getClientStatus(), this, computing);

    } catch (Exception e) {
        if (Logging.ERROR)
            Log.e(Logging.TAG, "Monitor.readClientStatus excpetion: " + e.getMessage(), e);
    }
}

From source file:Steps.StepsFragment.java

private void updateStickerPackCountDecrease() {
    SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_MULTI_PROCESS);
    int availableStickerPacks = prefs.getInt("packs", 0);
    availableStickerPacks--;/*from  w  w w .ja v  a  2s .  c om*/
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt("packs", availableStickerPacks);
    editor.commit();
    buttonOpenPack.setText(Integer.toString(availableStickerPacks) + " New Packs");
}