List of usage examples for android.content Intent FLAG_GRANT_WRITE_URI_PERMISSION
int FLAG_GRANT_WRITE_URI_PERMISSION
To view the source code for android.content Intent FLAG_GRANT_WRITE_URI_PERMISSION.
Click Source Link
From source file:com.demo.firebase.MainActivity.java
@AfterPermissionGranted(RC_STORAGE_PERMS) private void launchCamera() { Log.d(TAG, "launchCamera"); // Check that we have permission to read images from external storage. String perm = Manifest.permission.WRITE_EXTERNAL_STORAGE; if (!EasyPermissions.hasPermissions(this, perm)) { EasyPermissions.requestPermissions(this, getString(R.string.rationale_storage), RC_STORAGE_PERMS, perm); return;// www. j a va2s.c o m } // Choose file storage location, must be listed in res/xml/file_paths.xml File dir = new File(Environment.getExternalStorageDirectory() + "/photos"); File file = new File(dir, UUID.randomUUID().toString() + ".jpg"); try { // Create directory if it does not exist. if (!dir.exists()) { dir.mkdir(); } boolean created = file.createNewFile(); Log.d(TAG, "file.createNewFile:" + file.getAbsolutePath() + ":" + created); } catch (IOException e) { Log.e(TAG, "file.createNewFile" + file.getAbsolutePath() + ":FAILED", e); } // Create content:// URI for file, required since Android N // See: https://developer.android.com/reference/android/support/v4/content/FileProvider.html mFileUri = FileProvider.getUriForFile(this, "com.google.firebase.quickstart.firebasestorage.fileprovider", file); // Create and launch the intent Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri); // Grant permission to camera (this is required on KitKat and below) List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resolveInfos) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, mFileUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } // Start picture-taking intent startActivityForResult(takePictureIntent, RC_TAKE_PICTURE); }
From source file:com.google.samples.apps.gameloopmanager.TestLoopsActivity.java
private void runScenario(String packageName, int scenario) throws IOException { String filename = String.format("results%d.json", scenario > 0 ? scenario : 0); File f = new File(Environment.getExternalStorageDirectory(), filename); //noinspection ResultOfMethodCallIgnored f.createNewFile();// w w w .j av a 2 s. co m String myPackageName = getPackageName(); Uri fileUri = FileProvider.getUriForFile(this, myPackageName, f); Intent intent = new Intent("com.google.intent.action.TEST_LOOP").setPackage(packageName) .setDataAndType(fileUri, "application/javascript").setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (scenario >= 0) { intent.putExtra("scenario", scenario); } runningTestLoop = true; startActivityForResult(intent, TEST_LOOP_REQUEST_CODE); }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View v = inflater.inflate(R.layout.intent_editor_general, container, false); // Prepare form mActionText = (AutoCompleteTextView) v.findViewById(R.id.action); mActionsSpinner = (Spinner) v.findViewById(R.id.action_spinner); mDataText = (AutoCompleteTextView) v.findViewById(R.id.data); mDataTextWrapper = v.findViewById(R.id.data_wrapper); mDataTextHeader = v.findViewById(R.id.data_header); mDataTypeHeader = v.findViewById(R.id.data_type_header); mDataTypeText = (TextView) v.findViewById(R.id.data_type); mDataTypeSpinner = (Spinner) v.findViewById(R.id.data_type_spinner); mDataTypeSpinnerWrapper = v.findViewById(R.id.data_type_spinner_wrapper); mDataTypeSlash = v.findViewById(R.id.data_type_slash); mDataSubtypeText = (TextView) v.findViewById(R.id.data_type_after_slash); mComponentText = (TextView) v.findViewById(R.id.component); mComponentTypeSpinner = (Spinner) v.findViewById(R.id.componenttype); mComponentTypeSpinner.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.componenttypes))); mMethodSpinner = (Spinner) v.findViewById(R.id.method); mCategoriesContainer = (ViewGroup) v.findViewById(R.id.categories); mAddCategoryButton = (Button) v.findViewById(R.id.category_add); mCategoriesHeader = v.findViewById(R.id.categories_header); mResponseCodeTextView = (TextView) v.findViewById(R.id.response_code); mPackageNameText = (AutoCompleteTextView) v.findViewById(R.id.package_name); mResultCodeWrapper = v.findViewById(R.id.result_intent_wrapper); mComponentTypeAndMethodSpinners = v.findViewById(R.id.component_and_method_spinners); mComponentHeader = v.findViewById(R.id.component_header); mComponentFieldWithButtons = v.findViewById(R.id.component_field_with_buttons); mPackageNameHeader = v.findViewById(R.id.package_name_header); mIntentTrackerSummary = (TextView) v.findViewById(R.id.intent_tracker_summary); mIntentTrackerSummary.setMovementMethod(LinkMovementMethod.getInstance()); // Apparently using android:scrollHorizontally="true" does not work. // http://stackoverflow.com/questions/9011944/android-ice-cream-sandwich-edittext-disabling-spell-check-and-word-wrap mComponentText.setHorizontallyScrolling(true); // Bind button actions (android:onClick="" applies to hosting activity) mAddCategoryButton.setOnClickListener(new OnClickListener() { @Override// w w w. j a va2s .c o m public void onClick(View v) { addCategoryTextField(""); } }); v.findViewById(R.id.component_pick).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pickComponent(); } }); v.findViewById(R.id.component_pick).setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { findComponent(); return true; } }); v.findViewById(R.id.component_clear).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mComponentText.setText(""); } }); v.findViewById(R.id.data_query_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getIntentEditor().updateIntent(); startActivity( new Intent(getActivity(), AdvancedQueryActivity.class).setData(mEditedIntent.getData())); } }); v.findViewById(R.id.data_query_button) .setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { getIntentEditor().updateIntent(); final Uri uri = mEditedIntent.getData(); if (uri != null) { final String scheme = uri.getScheme(); final String authority = uri.getAuthority(); if ("content".equals(scheme) && authority != null) { menu.add("Wrap").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { mDataText.setText("content://" + ((mEditedIntent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)) != 0 ? ProxyProviderForGrantUriPermission.AUTHORITY : ProxyProvider.AUTHORITY) + "/" + authority + uri.getPath()); return true; } }); } } } }); // Set up autocomplete mUriAutocompleteAdapter = new UriAutocompleteAdapter(getActivity()); mDataText.setAdapter(mUriAutocompleteAdapter); mPackageNameText.setAdapter(new PackageNameAutocompleteAdapter(getActivity())); // Get edited intent for form filling mEditedIntent = getEditedIntent(); // Component field, affects options menu if (mEditedIntent.getComponent() != null) { mComponentText.setText(mEditedIntent.getComponent().flattenToShortString()); } mComponentText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateIntentComponent(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); // Fill the form setupActionSpinnerOrField(); updateNonActionIntentFilter(true); mDataText.setText(mEditedIntent.getDataString()); mPackageNameText.setText(mEditedIntent.getPackage()); showOrHideFieldsForResultIntent(); showOrHideAdvancedFields(); if (getComponentType() == IntentEditorConstants.RESULT) { mResponseCodeTextView.setText(String.valueOf(getIntentEditor().getMethodId())); mResponseCodeTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { getIntentEditor().setMethodId(Integer.parseInt(s.toString())); mResponseCodeTextView.setError(null); } catch (NumberFormatException e) { mResponseCodeTextView.setError(getIntentEditor().getText(R.string.value_parse_error)); } } @Override public void afterTextChanged(Editable s) { } }); } else { initComponentAndMethodSpinners(); } setupActionAutocomplete(); // Prepare intent tracker { IntentTracker tracker = getIntentEditor().getIntentTracker(); if (tracker != null) { tracker.setUpdateListener(this, true); } else { onNoTracker(); } } return v; }
From source file:de.k3b.android.toGoZip.SettingsActivity.java
private boolean openPicker(CharSequence oldFolder, int folderpickerCode, boolean useDocumentProvider) { if (!useDocumentProvider) { Intent intent = new Intent(SettingsActivity.this, FolderPicker.class); if ((oldFolder != null) && (oldFolder.length() > 0)) { intent.putExtra("location", oldFolder); // initial dir }//from w ww . j a va 2s .c o m startActivityForResult(intent, folderpickerCode); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); startActivityForResult(intent, folderpickerCode); } return true; }
From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java
public void takePicture() { if (!canSetPhoto()) { return;//w w w. j ava2s . c om } if (isMyDataIncomplete()) { checkMyData(); } else { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = getCameraMediaFile(); if (file != null) { Uri photoURI = FileProvider.getUriForFile(this, "de.bahnhoefe.deutschlands.bahnhofsfotos.fileprovider", file); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); intent.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, getResources().getString(R.string.app_name)); intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, bahnhof.getTitle()); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivityForResult(intent, REQUEST_TAKE_PICTURE); } else { Toast.makeText(this, R.string.unable_to_create_folder_structure, Toast.LENGTH_LONG).show(); } } }
From source file:com.jefftharris.passwdsafe.StorageFileListFragment.java
/** Open a password file URI from an intent */ private void openUri(Intent openIntent) { Uri uri = openIntent.getData();// w w w .j av a 2s .c o m int flags = openIntent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); Context ctx = getContext(); String title = RecentFilesDb.getSafDisplayName(uri, ctx); RecentFilesDb.updateOpenedSafFile(uri, flags, ctx); if (title != null) { openUri(uri, title); } }
From source file:org.gnucash.android.ui.common.BaseDrawerActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_CANCELED) { super.onActivityResult(requestCode, resultCode, data); return;/*from ww w. ja va 2 s. co m*/ } switch (requestCode) { case AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE: AccountsActivity.importXmlFileFromIntent(this, data, null); break; case BaseDrawerActivity.REQUEST_OPEN_DOCUMENT: //this uses the Storage Access Framework final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); AccountsActivity.importXmlFileFromIntent(this, data, null); getContentResolver().takePersistableUriPermission(data.getData(), takeFlags); break; default: super.onActivityResult(requestCode, resultCode, data); break; } }
From source file:net.bluehack.ui.WallpapersActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*from ww w.jav a 2 s .c o m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { boolean done; TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground); if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) { int width = AndroidUtilities.displaySize.x; int height = AndroidUtilities.displaySize.y; if (width > height) { int temp = width; width = height; height = temp; } TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height)); String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg"; File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); try { done = AndroidUtilities.copyFile(f, toFile); } catch (Exception e) { done = false; FileLog.e("tmessages", e); } } else { if (selectedBackground == -1) { File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg"); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); done = fromFile.renameTo(toFile); } else { done = true; } } if (done) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("selectedBackground", selectedBackground); editor.putInt("selectedColor", selectedColor); editor.commit(); ApplicationLoader.reloadWallpaper(); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); FrameLayout frameLayout = new FrameLayout(context); fragmentView = frameLayout; backgroundImage = new ImageView(context); backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP); frameLayout.addView(backgroundImage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); backgroundImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); progressView = new FrameLayout(context); progressView.setVisibility(View.INVISIBLE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52)); progressViewBackground = new View(context); progressViewBackground.setBackgroundResource(R.drawable.system_loader); progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER)); ProgressBar progressBar = new ProgressBar(context); try { progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.loading_animation)); } catch (Exception e) { //don't promt } progressBar.setIndeterminate(true); AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500); progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER)); RecyclerListView listView = new RecyclerListView(context); listView.setClipToPadding(false); listView.setTag(8); listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0); LinearLayoutManager layoutManager = new LinearLayoutManager(context); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); listView.setLayoutManager(layoutManager); listView.setDisallowInterceptTouchEvents(true); listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); listView.setAdapter(listAdapter = new ListAdapter(context)); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM)); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position == 0) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel) }; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { if (i == 0) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 10); } else if (i == 1) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 11); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); showDialog(builder.create()); } else { if (position - 1 < 0 || position - 1 >= wallPapers.size()) { return; } TLRPC.WallPaper wallPaper = wallPapers.get(position - 1); selectedBackground = wallPaper.id; listAdapter.notifyDataSetChanged(); processSelectedBackground(); } } }); processSelectedBackground(); return fragmentView; }
From source file:com.mb.android.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == PURCHASE_REQUEST) { if (resultCode == RESULT_OK) { if (currentProduct.getEmbyFeatureCode() != null) { AppstoreRegRequest request = new AppstoreRegRequest(); request.setStore(intent.getStringExtra("store")); request.setApplication(AppPackageName); request.setProduct(currentProduct.getSku()); request.setFeature(currentProduct.getEmbyFeatureCode()); request.setType(currentProduct.getProductType().toString()); if (intent.getStringExtra("storeId") != null) request.setStoreId(intent.getStringExtra("storeId")); request.setStoreToken(intent.getStringExtra("storeToken")); request.setEmail(purchaseEmail); request.setAmt(currentProduct.getPrice()); RespondToWebView(String.format("window.IapManager.onPurchaseComplete(" + jsonSerializer.SerializeToString(request) + ");")); } else { // no emby feature - just report success RespondToWebView(String.format("window.IapManager.onPurchaseComplete(true);")); }/*from w w w. j av a 2 s. c o m*/ } else { RespondToWebView(String.format("window.IapManager.onPurchaseComplete(false);")); } } else if (requestCode == REQUEST_DIRECTORY_SAF && resultCode == Activity.RESULT_OK) { Uri uri = intent.getData(); final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check for the freshest data. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getContentResolver().takePersistableUriPermission(uri, takeFlags); } RespondToWebviewWithSelectedPath(uri); } else if (requestCode == REQUEST_DIRECTORY && resultCode == RESULT_OK) { if (intent.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) { // For JellyBean and above if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = intent.getClipData(); if (clip != null) { for (int i = 0; i < clip.getItemCount(); i++) { Uri uri = clip.getItemAt(i).getUri(); RespondToWebviewWithSelectedPath(uri); } } // For Ice Cream Sandwich } else { ArrayList<String> paths = intent.getStringArrayListExtra(FilePickerActivity.EXTRA_PATHS); if (paths != null) { for (String path : paths) { Uri uri = Uri.parse(path); RespondToWebviewWithSelectedPath(uri); } } } } else { Uri uri = intent.getData(); // Do something with the URI if (uri != null) { RespondToWebviewWithSelectedPath(uri); } } } else if (requestCode == VIDEO_PLAYBACK) { /*boolean completed = resultCode == RESULT_OK; boolean error = resultCode == RESULT_OK ? false : (intent == null ? true : intent.getBooleanExtra("error", false)); long positionMs = intent == null || completed ? 0 : intent.getLongExtra("position", 0); String currentSrc = intent == null ? null : intent.getStringExtra(VideoPlayerActivity.PLAY_EXTRA_ITEM_LOCATION); if (currentSrc == null) { currentSrc = ""; } RespondToWebView(String.format("VideoRenderer.Current.onActivityClosed(%s, %s, %s, '%s');", !completed, error, positionMs, currentSrc));*/ } }
From source file:kr.wdream.ui.WallpapersActivity.java
@Override public View createView(Context context) { Log.d(LOG_TAG, "createView"); actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(/* w ww . ja v a 2s. co m*/ LocaleController.getString("ChatBackground", kr.wdream.storyshop.R.string.ChatBackground)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { boolean done; TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground); if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) { int width = AndroidUtilities.displaySize.x; int height = AndroidUtilities.displaySize.y; if (width > height) { int temp = width; width = height; height = temp; } TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height)); String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg"; File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); try { done = AndroidUtilities.copyFile(f, toFile); } catch (Exception e) { done = false; FileLog.e("tmessages", e); } } else { if (selectedBackground == -1) { File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg"); File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg"); done = fromFile.renameTo(toFile); } else { done = true; } } if (done) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("selectedBackground", selectedBackground); editor.putInt("selectedColor", selectedColor); editor.commit(); ApplicationLoader.reloadWallpaper(); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, kr.wdream.storyshop.R.drawable.ic_done, AndroidUtilities.dp(56)); FrameLayout frameLayout = new FrameLayout(context); fragmentView = frameLayout; backgroundImage = new ImageView(context); backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP); frameLayout.addView(backgroundImage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); backgroundImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); progressView = new FrameLayout(context); progressView.setVisibility(View.INVISIBLE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52)); progressViewBackground = new View(context); progressViewBackground.setBackgroundResource(kr.wdream.storyshop.R.drawable.system_loader); progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER)); ProgressBar progressBar = new ProgressBar(context); try { progressBar.setIndeterminateDrawable( context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.loading_animation)); } catch (Exception e) { //don't promt } progressBar.setIndeterminate(true); AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500); progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER)); RecyclerListView listView = new RecyclerListView(context); listView.setClipToPadding(false); listView.setTag(8); listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0); LinearLayoutManager layoutManager = new LinearLayoutManager(context); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); listView.setLayoutManager(layoutManager); listView.setDisallowInterceptTouchEvents(true); listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); listView.setAdapter(listAdapter = new ListAdapter(context)); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM)); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position == 0) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] { LocaleController.getString("FromCamera", kr.wdream.storyshop.R.string.FromCamera), LocaleController.getString("FromGalley", kr.wdream.storyshop.R.string.FromGalley), LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel) }; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { if (i == 0) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 10); } else if (i == 1) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 11); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); showDialog(builder.create()); } else { if (position - 1 < 0 || position - 1 >= wallPapers.size()) { return; } TLRPC.WallPaper wallPaper = wallPapers.get(position - 1); selectedBackground = wallPaper.id; listAdapter.notifyDataSetChanged(); processSelectedBackground(); } } }); processSelectedBackground(); return fragmentView; }