List of usage examples for android.content Context MODE_WORLD_READABLE
int MODE_WORLD_READABLE
To view the source code for android.content Context MODE_WORLD_READABLE.
Click Source Link
From source file:com.intervigil.micdroid.MainActivity.java
private void moveFile(String src, String dst) throws IOException { int len;//from w ww .ja v a2s. c om InputStream in = null; OutputStream out = null; byte[] buf = new byte[1024]; try { in = mContext.openFileInput(src); out = mContext.openFileOutput(dst, Context.MODE_WORLD_READABLE); while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } catch (IOException e) { throw e; } finally { try { if (in != null) { in.close(); mContext.deleteFile(src); } if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static int[] getUnreads(Context context) { SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); HomeDataSource data = HomeDataSource.getInstance(context); int homeTweets = data.getUnreadCount(currentAccount); MentionsDataSource mentions = MentionsDataSource.getInstance(context); int mentionsTweets = mentions.getUnreadCount(currentAccount); int dmTweets = sharedPrefs.getInt("dm_unread_" + currentAccount, 0); return new int[] { homeTweets, mentionsTweets, dmTweets }; }
From source file:org.ros.android.rviz_for_android.drawable.loader.ColladaLoader.java
private Map<String, ETC1Texture> getTextures(String prefix) { Map<String, ETC1Texture> retval = new HashMap<String, ETC1Texture>(); String filesDirectory = serverConnection.getContext().getFilesDir().toString() + "/"; // Find which types of acceptable textures are present (diffuse, bump, etc) for (textureType t : textureType.values()) { if (attributeExists("/COLLADA/library_effects/", t.toString(), "texture/@texture")) { String texPointer = super.existResult; String filename = null; // If the image library has an image with texPointer's ID, use that // otherwise, follow the pointer trail if (attributeExists("/COLLADA/library_images/image[@id='" + texPointer + "']/init_from")) { filename = super.existResult; Log.d("DAE", "Shortcut to texture name: " + filename); } else { // Locate the image ID from the texture pointer String imgID = getSingleAttribute( "/COLLADA/library_effects//newparam[@sid='" + texPointer + "']/sampler2D/source"); // Locate the image name String imgName = getSingleAttribute( "/COLLADA/library_effects//newparam[@sid='" + imgID + "']/surface/init_from"); // Locate the filename filename = getSingleAttribute("/COLLADA/library_images/image[@id='" + imgName + "']/init_from"); }/*from www.j a v a2s. co m*/ Log.d("DAE", "Filename = " + filename); if (filename.length() == 0) Log.e("DAE", "Filename = 0 length!"); // If a cached compressed copy exists, load that. Otherwise, download, compress, and save the image String compressedFilename = "COMPRESSED_" + serverConnection.getSanitizedPrefix(imgPrefix) + filename; if (!serverConnection.fileExists(compressedFilename)) { Log.i("DAE", "No compressed cached copy exists."); // Load the uncompressed image String downloadedFilename = serverConnection.getFile(imgPrefix + filename); Bitmap uncompressed = null; if (downloadedFilename == null) { Log.e("DAE", "Unable to get file " + imgPrefix + filename + " from server!"); uncompressed = Bitmap.createBitmap(new int[] { 0, 0 }, 1, 1, Bitmap.Config.RGB_565); } else uncompressed = openTextureFile(filesDirectory, downloadedFilename); // Flip the image Matrix flip = new Matrix(); flip.postScale(1f, -1f); Bitmap uncompressed_two = Bitmap.createBitmap(uncompressed, 0, 0, uncompressed.getWidth(), uncompressed.getHeight(), flip, true); uncompressed.recycle(); // Compress the image ETC1Texture compressed = compressBitmap(uncompressed_two); // Save the compressed texture try { BufferedOutputStream bout = new BufferedOutputStream(serverConnection.getContext() .openFileOutput(compressedFilename, Context.MODE_WORLD_READABLE)); bout.write(compressed.getData().array()); bout.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // Add the compressed texture to the return map retval.put(t.toString(), compressed); } else { Log.i("DAE", "A compressed cached copy exists!"); // Load the existing compressed texture try { byte[] dataArray = IOUtils .toByteArray(serverConnection.getContext().openFileInput(compressedFilename)); // Determine the dimensions of the image int bytes = 2 * dataArray.length; int width = 1024; int height = 1024; while ((width * height) > bytes && (width * height) >= 1) { width /= 2; height /= 2; } Log.i("DAE", "Compressed size determined to be " + width + " x " + height); ByteBuffer dataBuffer = ByteBuffer.allocateDirect(dataArray.length) .order(ByteOrder.nativeOrder()); dataBuffer.put(dataArray); dataBuffer.position(0); ETC1Texture compressed = new ETC1Texture(width, height, dataBuffer); retval.put(t.toString(), compressed); } catch (FileNotFoundException e) { Log.e("DAE", "Compressed texture not found!"); e.printStackTrace(); } catch (IOException e) { Log.e("DAE", "IOException!"); e.printStackTrace(); } } } } return retval; }
From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppsListFragment.java
@SuppressLint("WorldReadableFiles") @Override//from ww w. ja v a2s . 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:org.mozilla.gecko.GeckoAppShell.java
public static boolean loadLibsSetup(String apkName) { // The package data lib directory isn't placed in ld.so's // search path, so we have to manually load libraries that // libxul will depend on. Not ideal. GeckoApp geckoApp = GeckoApp.mAppContext; GeckoProfile profile = geckoApp.getProfile(); profile.moveProfilesToAppInstallLocation(); try {//from w w w .j a v a 2 s . c o m String[] dirs = GeckoApp.mAppContext.getPluginDirectories(); StringBuffer pluginSearchPath = new StringBuffer(); for (int i = 0; i < dirs.length; i++) { Log.i(LOGTAG, "dir: " + dirs[i]); pluginSearchPath.append(dirs[i]); pluginSearchPath.append(":"); } GeckoAppShell.putenv("MOZ_PLUGIN_PATH=" + pluginSearchPath); } catch (Exception ex) { Log.i(LOGTAG, "exception getting plugin dirs", ex); } GeckoAppShell.putenv("HOME=" + profile.getFilesDir().getPath()); GeckoAppShell.putenv("GRE_HOME=" + GeckoApp.sGREDir.getPath()); Intent i = geckoApp.getIntent(); String env = i.getStringExtra("env0"); Log.i(LOGTAG, "env0: " + env); for (int c = 1; env != null; c++) { GeckoAppShell.putenv(env); env = i.getStringExtra("env" + c); Log.i(LOGTAG, "env" + c + ": " + env); } File f = geckoApp.getDir("tmp", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE); if (!f.exists()) f.mkdirs(); GeckoAppShell.putenv("TMPDIR=" + f.getPath()); f = Environment.getDownloadCacheDirectory(); GeckoAppShell.putenv("EXTERNAL_STORAGE=" + f.getPath()); File cacheFile = getCacheDir(); String linkerCache = System.getenv("MOZ_LINKER_CACHE"); if (System.getenv("MOZ_LINKER_CACHE") == null) { GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + cacheFile.getPath()); } File pluginDataDir = GeckoApp.mAppContext.getDir("plugins", 0); GeckoAppShell.putenv("ANDROID_PLUGIN_DATADIR=" + pluginDataDir.getPath()); // gingerbread introduces File.getUsableSpace(). We should use that. long freeSpace = getFreeSpace(); try { File downloadDir = null; File updatesDir = null; if (Build.VERSION.SDK_INT >= 8) { downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); updatesDir = GeckoApp.mAppContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); } else { updatesDir = downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "download"); } GeckoAppShell.putenv("DOWNLOADS_DIRECTORY=" + downloadDir.getPath()); GeckoAppShell.putenv("UPDATES_DIRECTORY=" + updatesDir.getPath()); } catch (Exception e) { Log.i(LOGTAG, "No download directory has been found: " + e); } putLocaleEnv(); boolean extractLibs = GeckoApp.ACTION_DEBUG.equals(i.getAction()); if (!extractLibs) { // remove any previously extracted libs File[] files = cacheFile.listFiles(); if (files != null) { Iterator<File> cacheFiles = Arrays.asList(files).iterator(); while (cacheFiles.hasNext()) { File libFile = cacheFiles.next(); if (libFile.getName().endsWith(".so")) libFile.delete(); } } } return extractLibs; }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static String[] getTitle(int[] unreadCount, Context context, int currentAccount) { String text = ""; String name = null;/*from w w w .j ava2 s . com*/ String names = ""; int homeTweets = unreadCount[0]; int mentionsTweets = unreadCount[1]; int dmTweets = unreadCount[2]; // they only have a new mention if (mentionsTweets == 1 && homeTweets == 0 && dmTweets == 0) { MentionsDataSource mentions = MentionsDataSource.getInstance(context); name = mentions.getNewestName(currentAccount); String n = mentions.getNewestNames(currentAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); for (String s : n.split(" ")) { if (!s.equals("") && !sharedPrefs.getString("twitter_screen_name_" + currentAccount, "").equals(s) && !s.equals(name)) { names += "@" + s + " "; } } text = context.getResources().getString(R.string.mentioned_by) + " @" + name; // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return null; } } else if (homeTweets == 0 && mentionsTweets == 0 && dmTweets == 1) { // they have 1 new direct message DMDataSource dm = DMDataSource.getInstance(context); name = dm.getNewestName(currentAccount); text = context.getResources().getString(R.string.message_from) + " @" + name; } else { // other cases we will just put Test text = context.getResources().getString(R.string.app_name); } return new String[] { text, name, names }; }
From source file:piuk.blockchain.android.WalletApplication.java
public void deleteBitcoinJLocalData() { try {//from www. j a va 2 s. c o m //Delete the wallet file File bitcoinJFile = getFileStreamPath(Constants.WALLET_FILENAME_PROTOBUF); if (bitcoinJFile.exists()) { bitcoinJFile.delete(); } } catch (Exception e) { e.printStackTrace(); } try { //Clear the blockchain file (we need to rescan) File blockChainFile = new File( getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); if (blockChainFile.exists()) blockChainFile.delete(); } catch (Exception e) { e.printStackTrace(); } }
From source file:cn.ttyhuo.view.UserView.java
public void setupViews(JSONObject jsonObject, final Context context) throws JSONException { JSONObject jObject;/*from ww w . jav a 2 s.c o m*/ if (jsonObject.has("user")) jObject = jsonObject.getJSONObject("user"); else jObject = jsonObject.getJSONObject("userWithLatLng"); String userStatus = JSONUtil.getStringFromJson(jObject, "status", ""); if (!userStatus.equals("")) { if (tv_userStatus != null) tv_userStatus.setText("(" + userStatus + ")"); } else { if (tv_userStatus != null) tv_userStatus.setText(""); } if (tv_userTypeStr != null) tv_userTypeStr.setText(JSONUtil.getStringFromJson(jsonObject, "userTypeStr", "")); String userName = JSONUtil.getStringFromJson(jObject, "userName", "??"); String imgUrl = JSONUtil.getStringFromJson(jObject, "imgUrl", ""); int verifyFlag = 0; if (JSONUtil.getBoolFromJson(jObject, "sfzVerify")) { verifyFlag = 1; iv_userVerify.setVisibility(View.VISIBLE); imgUrl = JSONUtil.getStringFromJson(jObject, "faceImgUrl", imgUrl); userName = JSONUtil.getStringFromJson(jObject, "identityName", userName); } else { iv_userVerify.setVisibility(View.GONE); } tv_userName.setText(userName); int gender = JSONUtil.getIntFromJson(jsonObject, "gender", 0); if (gender == 2) { iv_gender.setImageResource(R.drawable.icon_nv_big); ll_gender.setBackgroundResource(R.drawable.bg_nv); } else if (gender == 1) { iv_gender.setImageResource(R.drawable.icon_nan_big); ll_gender.setBackgroundResource(R.drawable.bg_nan); } else { //TODO:?? } Integer age = JSONUtil.getIntFromJson(jsonObject, "age", 0); tv_userAge.setText(age.toString()); double lat = JSONUtil.getDoubleFromJson(jObject, "lat", 0.0); double lng = JSONUtil.getDoubleFromJson(jObject, "lng", 0.0); String distance = ((MyApplication) ((Activity) context).getApplication()).getDistance(lat, lng); //TODO: tv_lastPlace.setText(distance + "km"); JSONUtil.setValueFromJson(tv_lastTime, jObject, "latlngDate", ""); if (tv_mobileNo != null) { String mobileNo = JSONUtil.getStringFromJson(jObject, "mobileNo", ""); if (mobileNo.length() > 7) { mobileNo = mobileNo.substring(0, 3) + "****" + mobileNo.substring(7); } tv_mobileNo.setText(mobileNo); } int thumbUpCount = jObject.getInt("thumbUpCount"); int favoriteUserCount = jObject.getInt("favoriteUserCount"); boolean alreadyFavorite = jObject.getBoolean("alreadyFavorite"); final int userID = jObject.getInt("userID"); setFavoriteAndThumbUp(userID, thumbUpCount, favoriteUserCount, alreadyFavorite, context, jObject); if (JSONUtil.getBoolFromJson(jsonObject, "hasProduct")) { iv_hasProduct.setVisibility(View.GONE); tv_hasProduct.setVisibility(View.VISIBLE); View.OnClickListener theClick = new View.OnClickListener() { // ? ? @Override public void onClick(View v) { switch (v.getId()) { case R.id.iv_hasProduct: case R.id.tv_hasProduct: Intent intent = new Intent(context, MainPage.class); intent.putExtra("contentFragment", "UserProductFragment"); intent.putExtra("windowTitle", "?"); intent.putExtra("hasWindowTitle", true); intent.putExtra("extraID", userID); context.startActivity(intent); break; default: break; } } }; iv_hasProduct.setOnClickListener(theClick); tv_hasProduct.setOnClickListener(theClick); } else { iv_hasProduct.setVisibility(View.GONE); tv_hasProduct.setVisibility(View.GONE); } verifyFlag = setupTruckInfo(context, jObject, jsonObject, verifyFlag); if (fl_title != null) { JSONUtil.setFieldValueFromJson(fl_title, jsonObject, "title", ""); JSONUtil.setFieldValueFromJson(fl_description, jsonObject, "description", ""); JSONUtil.setFieldValueFromJson(fl_hobby, jsonObject, "hobby", ""); JSONUtil.setFieldValueFromJson(fl_homeTown, jsonObject, "homeTown", ""); JSONUtil.setFieldValueFromJson(fl_createDate, jObject, "createDate", ""); } verifyFlag = setupCompanyInfo(jsonObject, jObject, verifyFlag); setupUserVerifyImg(jObject, verifyFlag); setupFaceImg(context, imgUrl); if (iv_qrcode != null) { Map<String, String> params = new HashMap<String, String>(); StringBuilder buf = new StringBuilder("http://qr.liantu.com/api.php"); params.put("text", "http://ttyh.aliapp.com/mvc/viewUser_" + userID); params.put("bg", "ffffff"); params.put("fg", "cc0000"); params.put("fg", "gc0000"); params.put("el", "h"); params.put("w", "300"); params.put("m", "10"); params.put("pt", "00ff00"); params.put("inpt", "000000"); params.put("logo", "http://ttyh-document.oss-cn-qingdao.aliyuncs.com/ic_launcher.jpg"); try { // GET?URL if (params != null && !params.isEmpty()) { buf.append("?"); for (Map.Entry<String, String> entry : params.entrySet()) { buf.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")) .append("&"); } buf.deleteCharAt(buf.length() - 1); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } final String qrcodeUrl = buf.toString(); ImageLoader.getInstance().displayImage(qrcodeUrl, iv_qrcode, new DisplayImageOptions.Builder() .resetViewBeforeLoading(true).cacheInMemory(true).cacheOnDisc(true).build()); iv_qrcode.setOnClickListener(new View.OnClickListener() { // ? ? @Override public void onClick(View v) { try { FileOutputStream fos = context.openFileOutput("qrcode.png", Context.MODE_WORLD_READABLE); FileInputStream fis = new FileInputStream( ImageLoader.getInstance().getDiscCache().get(qrcodeUrl)); byte[] buf = new byte[1024]; int len = 0; while ((len = fis.read(buf)) != -1) { fos.write(buf, 0, len); } fis.close(); fos.close(); shareMsg(context, "?", "?", "??: ", context.getFileStreamPath("qrcode.png")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }); } final String mobile = JSONUtil.getStringFromJson(jObject, "mobileNo", ""); if (!mobile.isEmpty()) { if (tv_footer_call_btn != null) { tv_footer_call_btn.setOnClickListener(new View.OnClickListener() { // ? ? @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); intent.setData(Uri.parse("tel:" + mobile));//mobile?????? context.startActivity(intent); } }); } if (iv_phoneIcon != null) { iv_phoneIcon.setOnClickListener(new View.OnClickListener() { // ? ? @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); intent.setData(Uri.parse("tel:" + mobile));//mobile?????? context.startActivity(intent); } }); } } else { if (tv_footer_call_btn != null) tv_footer_call_btn.setOnClickListener(null); if (iv_phoneIcon != null) iv_phoneIcon.setOnClickListener(null); } }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static int[] getUnreads(Context context) { SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); HomeDataSource data = HomeDataSource.getInstance(context); int homeTweets = data.getUnreadCount(currentAccount); MentionsDataSource mentions = MentionsDataSource.getInstance(context); int mentionsTweets = mentions.getUnreadCount(currentAccount); int dmTweets = sharedPrefs.getInt("dm_unread_" + currentAccount, 0); return new int[] { homeTweets, mentionsTweets, dmTweets }; }
From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListFragment.java
@SuppressLint({ "WorldReadableFiles", "CommitPrefEdits" }) @Override//w ww.j a va2 s . c om 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); }