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.j4velin.wifiAutoOff.Locations.java

@Override
protected void onResume() {
    super.onResume();
    SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences",
            Context.MODE_MULTI_PROCESS);
    findViewById(R.id.timeoutwarning).setVisibility(prefs.getBoolean("off_no_network", true)
            && prefs.getInt("no_network_timeout", Receiver.TIMEOUT_NO_NETWORK) < 5 ? View.VISIBLE : View.GONE);
}

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

protected void updateVolumeData() {
    pref = getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS);
    currentVolume = pref.getInt(CURR_VOL_KEY, MAX_VOL);
    runATCmd(currentVolume);//from w  w w  . jav a  2 s. c o  m
}

From source file:org.zywx.wbpalmstar.platform.push.report.PushReportAgent.java

/**
 * ?/*from  ww w  . j  a v  a 2  s  . c  o  m*/
 *
 * @param type 1  0 
 */
public static void setPushState(Context context, int type) {
    PushReportUtility.log("setPushState--" + type);
    SharedPreferences sp = context.getSharedPreferences("saveData", Context.MODE_MULTI_PROCESS);
    Editor editor = sp.edit();
    editor.putString("localPushMes", String.valueOf(type));
    editor.commit();
    String pushMes = sp.getString("pushMes", String.valueOf(type));
    if (type == 1 && "1".equals(pushMes)) {
        Intent myIntent = new Intent(context, PushService.class);
        myIntent.putExtra("type", type);
        context.startService(myIntent);
    } else {
        Intent myIntent = new Intent(context, PushService.class);
        myIntent.putExtra("type", type);
        context.startService(myIntent);
    }
}

From source file:com.darshancomputing.alockblock.ALockBlockService.java

private static void loadSettingsFiles(Context context) {
    settings = context.getSharedPreferences(SettingsActivity.SETTINGS_FILE, Context.MODE_MULTI_PROCESS);
    sp_store = context.getSharedPreferences(SettingsActivity.SP_STORE_FILE, Context.MODE_MULTI_PROCESS);
}

From source file:com.codemodlabs.coordinate.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case RC_SIGN_IN:
        if (resultCode == RESULT_OK) {
            // If the error resolution was successful we should continue
            // processing errors.
            mSignInProgress = STATE_SIGN_IN;
        } else {/*  www  .j  a va  2s. co m*/
            // If the error resolution was not successful or the user canceled,
            // we should stop processing errors.
            mSignInProgress = STATE_DEFAULT;
        }

        if (!mGoogleApiClient.isConnecting()) {
            // If Google Play services resolved the issue with a dialog then
            // onStart is not called so we need to re-attempt connection here.
            mGoogleApiClient.connect();
        }
        break;
    case 10:
        if (resultCode == 2) {
            uberAPI.access_token = data.getStringExtra("access_token");
            uberAPI.expires_in = data.getIntExtra("expires_in", 0);

            SharedPreferences sharedPref = getSharedPreferences("apppreferences", Context.MODE_MULTI_PROCESS);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("access_token", uberAPI.access_token);
            editor.putInt("expires_in", uberAPI.expires_in);
            editor.commit();

            uberAPI.authenticate();
        }
        break;
    }
}

From source file:com.dycody.android.idealnote.ListFragment.java

private void init() {
    initEasterEgg();/*from  ww w .ja v  a2  s. c o m*/
    initListView();
    ubc = new UndoBarController(undoBarView, this);

    initNotesList(mainActivity.getIntent());
    initFab();
    initTitle();

    // Restores again DefaultSharedPreferences too reload in case of data erased from Settings
    prefs = mainActivity.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS);
}

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

public boolean setVersion(String version) {
    if (version == null) {
        return false;
    }/*ww  w .j  a v  a2s  . c  o  m*/
    File file = getFile(version);
    if (file == null || !file.isFile()) {
        if ("".equals(databaseVersion)) {
            return setDefaultVersion();
        } else {
            return false;
        }
    }
    if (database != null) {
        if (databaseVersion.equals(version)) {
            return true;
        }
        Log.d(TAG, "close database \"" + database.getPath() + "\"");
        database.close();
    }
    databaseVersion = version;
    try {
        database = SQLiteDatabase.openDatabase(file.getAbsolutePath(), null,
                SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
        Log.d(TAG, "open database \"" + database.getPath() + "\"");
        int oldsize = allhuman.size();
        setMetadata(database, databaseVersion, true);
        if (allhuman.size() > oldsize) {
            SharedPreferences.Editor editor = mContext
                    .getSharedPreferences(HUMAN_PREFERENCE, Context.MODE_MULTI_PROCESS).edit();
            for (Entry<String, String> entry : allhuman.entrySet()) {
                editor.putString(entry.getKey(), entry.getValue());
            }
            editor.commit();
        }
        return true;
    } catch (Exception e) {
        try {
            file.delete();
        } catch (Exception f) {
        }
        return setDefaultVersion();
    }
}

From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppsListFragment.java

@SuppressLint("WorldReadableFiles")
@Override//from ww w .j a va 2 s  . c  o  m
public boolean onOptionsItemSelected(MenuItem item) {
    if (pref.getBoolean(Common.ENABLE_PRO, false)) {
        final File prefsPackagesFileShort = new File(Common.PREFS_PACKAGES + ".xml");
        final File prefsPerAppFileShort = new File(Common.PREFS_PER_APP + ".xml");
        final File prefsPackagesFile = new File(getActivity().getApplicationInfo().dataDir + File.separator
                + "shared_prefs" + File.separator + prefsPackagesFileShort);
        final File prefsPerAppFile = new File(getActivity().getApplicationInfo().dataDir + File.separator
                + "shared_prefs" + File.separator + prefsPerAppFileShort);
        final File backupDir = new File(
                Environment.getExternalStorageDirectory() + File.separator + "MaxLock_Backup");

        switch (item.getItemId()) {
        case R.id.toolbar_backup_list:
            File curTimeDir = new File(backupDir + File.separator
                    + new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss", Locale.getDefault())
                            .format(new Date(System.currentTimeMillis()))
                    + File.separator);
            try {
                if (prefsPackagesFile.exists()) {
                    FileUtils.copyFileToDirectory(prefsPackagesFile, curTimeDir);
                    if (prefsPerAppFile.exists())
                        FileUtils.copyFileToDirectory(prefsPerAppFile, curTimeDir);
                } else
                    Toast.makeText(getActivity(), R.string.toast_no_files_to_backup, Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(getActivity(), R.string.toast_backup_restore_exception, Toast.LENGTH_SHORT)
                        .show();
                e.printStackTrace();
            }
            if (curTimeDir.exists() && new File(curTimeDir + File.separator + prefsPackagesFileShort).exists())
                Toast.makeText(getActivity(), R.string.toast_backup_success, Toast.LENGTH_SHORT).show();
            return true;

        case R.id.toolbar_restore_list:
            List<String> list = new ArrayList<>(Arrays.asList(backupDir.list()));
            restoreAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, list);
            restoreDialog = new AlertDialog.Builder(getActivity())
                    .setTitle(R.string.dialog_restore_list_message)
                    .setAdapter(restoreAdapter, new DialogInterface.OnClickListener() {
                        @SuppressLint("InlinedApi")
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            File restorePackagesFile = new File(backupDir + File.separator
                                    + restoreAdapter.getItem(i) + File.separator + prefsPackagesFileShort);
                            File restorePerAppFile = new File(backupDir + File.separator
                                    + restoreAdapter.getItem(i) + File.separator + prefsPerAppFileShort);
                            if (restorePackagesFile.exists()) {
                                try {
                                    //noinspection ResultOfMethodCallIgnored
                                    prefsPackagesFile.delete();
                                    FileUtils.copyFile(restorePackagesFile, prefsPackagesFile);
                                    if (restorePerAppFile.exists()) {
                                        //noinspection ResultOfMethodCallIgnored
                                        prefsPerAppFile.delete();
                                        FileUtils.copyFile(restorePerAppFile, prefsPerAppFile);
                                    }
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                getActivity().getSharedPreferences(Common.PREFS_PACKAGES,
                                        Context.MODE_MULTI_PROCESS);
                                getActivity().getSharedPreferences(Common.PREFS_PER_APP,
                                        Context.MODE_MULTI_PROCESS);
                                Toast.makeText(getActivity(), R.string.toast_restore_success,
                                        Toast.LENGTH_SHORT).show();
                                ((SettingsActivity) getActivity()).restart();
                            } else
                                Toast.makeText(getActivity(), R.string.toast_no_files_to_restore,
                                        Toast.LENGTH_SHORT).show();
                        }
                    }).setNegativeButton(android.R.string.cancel, null).show();
            restoreDialog.getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                    try {
                        FileUtils.deleteDirectory(
                                new File(backupDir + File.separator + restoreAdapter.getItem(i)));
                        restoreAdapter.remove(restoreAdapter.getItem(i));
                        restoreAdapter.notifyDataSetChanged();
                    } catch (IOException e) {
                        e.printStackTrace();
                        return false;
                    }
                    return true;
                }
            });
            return true;
        case R.id.toolbar_clear_list:
            //noinspection deprecation
            getActivity().getSharedPreferences(Common.PREFS_PACKAGES, Context.MODE_WORLD_READABLE).edit()
                    .clear().commit();
            //noinspection deprecation
            getActivity().getSharedPreferences(Common.PREFS_PER_APP, Context.MODE_WORLD_READABLE).edit().clear()
                    .commit();
            ((SettingsActivity) getActivity()).restart();
        }
    } else
        Toast.makeText(getActivity(), R.string.toast_pro_required, Toast.LENGTH_SHORT).show();
    return super.onOptionsItemSelected(item);
}

From source file:com.happysanta.vkspy.Fragments.MainFragment.java

public void longpollToggle(Boolean active) {

    SharedPreferences preferences = context.getSharedPreferences("longpoll", Context.MODE_MULTI_PROCESS);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("status", active);
    editor.commit();//  w w w. j  ava  2 s . c  om

    Intent longPollService = new Intent(context, LongPollService.class);
    Bundle bundle = new Bundle();
    bundle.putInt(LongPollService.ACTION,
            (active ? LongPollService.ACTION_START : LongPollService.ACTION_STOP));
    longPollService.putExtras(bundle);
    context.startService(longPollService);

}

From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListFragment.java

@SuppressLint({ "WorldReadableFiles", "CommitPrefEdits" })
@Override/*from  w ww.ja  v  a  2  s.c  o m*/
public boolean onOptionsItemSelected(MenuItem item) {
    if (prefs.getBoolean(Common.ENABLE_PRO, false) || item.getItemId() == R.id.toolbar_filter_activated) {
        final File prefsPackagesFileShort = new File(Common.PREFS_PACKAGES + ".xml");
        final File prefsPerAppFileShort = new File(Common.PREFS_PER_APP + ".xml");
        final File prefsActivitiesFileShort = new File(Common.PREFS_ACTIVITIES + ".xml");
        final File prefsPackagesFile = new File(getActivity().getApplicationInfo().dataDir + File.separator
                + "shared_prefs" + File.separator + prefsPackagesFileShort);
        final File prefsPerAppFile = new File(getActivity().getApplicationInfo().dataDir + File.separator
                + "shared_prefs" + File.separator + prefsPerAppFileShort);
        final File prefsActivitiesFile = new File(getActivity().getApplicationInfo().dataDir + File.separator
                + "shared_prefs" + File.separator + prefsActivitiesFileShort);
        final File backupDir = new File(
                Environment.getExternalStorageDirectory() + File.separator + "MaxLock_Backup");

        switch (item.getItemId()) {
        case R.id.toolbar_backup_list:
            File curTimeDir = new File(backupDir + File.separator
                    + new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss", Locale.getDefault())
                            .format(new Date(System.currentTimeMillis()))
                    + File.separator);
            backupFile(prefsPackagesFile, curTimeDir);
            backupFile(prefsPerAppFile, curTimeDir);
            backupFile(prefsActivitiesFile, curTimeDir);
            if (curTimeDir.exists() && new File(curTimeDir + File.separator + prefsPackagesFileShort).exists())
                Toast.makeText(getActivity(), R.string.toast_backup_success, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.toolbar_restore_list:
            List<String> list = new ArrayList<>(Arrays.asList(backupDir.list()));
            restoreAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, list);
            restoreDialog = new AlertDialog.Builder(getActivity())
                    .setTitle(R.string.dialog_restore_list_message)
                    .setAdapter(restoreAdapter, new DialogInterface.OnClickListener() {
                        @SuppressLint("InlinedApi")
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            File restorePackagesFile = new File(backupDir + File.separator
                                    + restoreAdapter.getItem(i) + File.separator + prefsPackagesFileShort);
                            File restorePerAppFile = new File(backupDir + File.separator
                                    + restoreAdapter.getItem(i) + File.separator + prefsPerAppFileShort);
                            File restoreActivitiesFile = new File(backupDir + File.separator
                                    + restoreAdapter.getItem(i) + File.separator + prefsActivitiesFileShort);
                            if (restorePackagesFile.exists()) {
                                try {
                                    //noinspection ResultOfMethodCallIgnored
                                    prefsPackagesFile.delete();
                                    FileUtils.copyFile(restorePackagesFile, prefsPackagesFile);
                                    if (restorePerAppFile.exists()) {
                                        //noinspection ResultOfMethodCallIgnored
                                        prefsPerAppFile.delete();
                                        FileUtils.copyFile(restorePerAppFile, prefsPerAppFile);
                                    }
                                    if (prefsActivitiesFile.exists()) {
                                        //noinspection ResultOfMethodCallIgnored
                                        prefsActivitiesFile.delete();
                                        FileUtils.copyFile(restoreActivitiesFile, prefsActivitiesFile);
                                    }
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                getActivity().getSharedPreferences(Common.PREFS_PACKAGES,
                                        Context.MODE_MULTI_PROCESS);
                                getActivity().getSharedPreferences(Common.PREFS_PER_APP,
                                        Context.MODE_MULTI_PROCESS);
                                Toast.makeText(getActivity(), R.string.toast_restore_success,
                                        Toast.LENGTH_SHORT).show();
                                ((SettingsActivity) getActivity()).restart();
                            } else
                                Toast.makeText(getActivity(), R.string.toast_no_files_to_restore,
                                        Toast.LENGTH_SHORT).show();
                        }
                    }).setNegativeButton(android.R.string.cancel, null).show();
            restoreDialog.getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                    try {
                        FileUtils.deleteDirectory(
                                new File(backupDir + File.separator + restoreAdapter.getItem(i)));
                        restoreAdapter.remove(restoreAdapter.getItem(i));
                        restoreAdapter.notifyDataSetChanged();
                    } catch (IOException e) {
                        e.printStackTrace();
                        return false;
                    }
                    return true;
                }
            });
            return true;
        case R.id.toolbar_setting:
            launchFragment(new SettingsFragment(), true, this);
            return true;

        case R.id.toolbar_clear_list:
            //noinspection deprecation
            getActivity().getSharedPreferences(Common.PREFS_PACKAGES, Context.MODE_WORLD_READABLE).edit()
                    .clear().commit();
            //noinspection deprecation
            getActivity().getSharedPreferences(Common.PREFS_PER_APP, Context.MODE_WORLD_READABLE).edit().clear()
                    .commit();
            ((SettingsActivity) getActivity()).restart();
            return true;
        case R.id.toolbar_filter_activated:
            String appListFilter = prefs.getString("app_list_filter", "");
            if (appListFilter == null) {
                return true;
            }
            switch (appListFilter) {
            case "@*activated*":
                prefs.edit().putString("app_list_filter", "@*deactivated*").commit();
                break;
            case "@*deactivated*":
                prefs.edit().putString("app_list_filter", "").commit();
                break;
            default:
                prefs.edit().putString("app_list_filter", "@*activated*").commit();
                break;
            }
            filterIcon(item);
            filter();
            return true;
        }
    } else
        Toast.makeText(getActivity(), R.string.toast_pro_required, Toast.LENGTH_SHORT).show();
    return super.onOptionsItemSelected(item);
}