Skip to content

Instantly share code, notes, and snippets.

View imandaliya's full-sized avatar
🐢

Rahul Mandaliya imandaliya

🐢
View GitHub Profile
private fun saveImageToStorage() {
try {
val uri: Uri?
val fileName = "Screenshot_${Calendar.getInstance().time}.jpg"
val imageOutStream: OutputStream? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val values = ContentValues()
values.put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
values.put(MediaStore.Images.Media.MIME_TYPE, "image/*")
values.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES)
uri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
// original link : https://androidexplained.github.io/android/android11/scoped-storage/2020/09/29/file-saving-android-11.html
private fun openDocumentToSavePDF() {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/pdf"
val fileName = "Screenshot_${Calendar.getInstance().time}.pdf"
putExtra(Intent.EXTRA_TITLE, fileName)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
putExtra(DocumentsContract.EXTRA_INITIAL_URI, Environment.DIRECTORY_DOCUMENTS)
// Get external storage public directory file path
// original thread https://stackoverflow.com/questions/61406818/filenotfoundexception-open-failed-eperm-operation-not-permitted-during-saving
ContextWrapper cw = new ContextWrapper(mContext);
String fullPath = cw.getExternalFilesDir(Environment.DIRECTORY_MUSIC).toString();
File directory = cw.getExternalFilesDir(Environment.DIRECTORY_MUSIC);
@imandaliya
imandaliya / gist:8f8374986316b1d8401e74bc2dd9de19
Created August 8, 2020 13:58
The application could not be installed: INSTALL_FAILED_NO_MATCHING_ABIS in RenderScript
// add this line in defaultConfig
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a' , 'arm64-v8a'
}
package com.rahul.android.material.support.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public void setThemeTransparentBar(AppCompatActivity activity, AppBarLayout appBarLayout, Toolbar toolbar, RecyclerView recyclerView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (appBarLayout == null || toolbar == null || recyclerView == null) return;
int color = ContextCompat.getColor(activity.getApplicationContext(), R.color.bar_transparent);
appBarLayout.setBackgroundColor(color);
toolbar.setBackgroundColor(Color.TRANSPARENT);
@imandaliya
imandaliya / ImageUtilsML.kt
Created July 4, 2020 06:55
ImageUtils for Tensorflow
import android.graphics.*
import androidx.core.graphics.ColorUtils
import androidx.exifinterface.media.ExifInterface
import java.io.File
import java.nio.ByteBuffer
import java.nio.ByteOrder
abstract class ImageUtils {
companion object {
/*
To remove Webview inflation error
*/
public class MyWebView extends WebView {
public MyWebView(Context context) {
super(getFixedContext(context));
}
public MyWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
Material Desing for Android
https://dev.materialdesignicons.com/getting-started/android
Github : https://github.com/code-mc/material-icon-lib
// TODO call this method in AspectRation item clicked. where original size aspect ration is 0
private void resetCropView(){
mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle());
mGestureCropImageView.zoomInImage(mGestureCropImageView.getMinScale());
}