Skip to content

Fixed file storage to default to getFilesDir() #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:background="#f4f3f3"
app:tabMode="fixed" />

<com.muddzdev.quickshot.demo.NonSwipeViewPager
<io.github.muddz.quickshot.demo.NonSwipeViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions demo/src/main/res/layout/view_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.muddzdev.quickshot.demo.DrawingBoardView
<io.github.muddz.quickshot.demo.DrawingBoardView
android:id="@+id/drawingview"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -32,4 +32,4 @@
android:textSize="18sp" />
</LinearLayout>

</FrameLayout>
</FrameLayout>
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android.useAndroidX=true
#Publish plugin: https://github.com/vanniktech/gradle-maven-publish-plugin
GROUP=io.github.muddz
POM_ARTIFACT_ID=quickshot
VERSION_NAME=1.4.0
VERSION_NAME=1.5.0

POM_NAME=quickshot
POM_DESCRIPTION=Capture images of any View, SurfaceView or Bitmap from your Android app in: .jpg .png or .nomedia with simple oneliner codes.
Expand All @@ -21,4 +21,4 @@ POM_SCM_CONNECTION=scm:git:git://github.com/Muddz/Quickshot.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/Muddz/Quickshot.git

POM_DEVELOPER_ID=Muddz
POM_DEVELOPER_NAME=Muddi Walid
POM_DEVELOPER_NAME=Muddi Walid
Empty file modified gradlew
100644 → 100755
Empty file.
25 changes: 24 additions & 1 deletion quickshot/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.library'
id 'com.vanniktech.maven.publish'
// id 'com.vanniktech.maven.publish'
id 'maven-publish'
}
android {
compileSdk 30
Expand All @@ -24,3 +25,25 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
}

publishing {
publications {
Common(MavenPublication) {
groupId GROUP
version VERSION_NAME
artifactId POM_ARTIFACT_ID

artifact("$buildDir/outputs/aar/quickshot-release.aar")

pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.getByName("releaseCompileClasspath").getResolvedConfiguration().getFirstLevelModuleDependencies().each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.moduleGroup)
dependency.appendNode('artifactId', it.moduleName)
dependency.appendNode('version', it.moduleVersion)
}
}
}
}
}
58 changes: 3 additions & 55 deletions quickshot/src/main/java/io/github/muddz/quickshot/QuickShot.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
package io.github.muddz.quickshot;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.util.Log;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import java.io.BufferedOutputStream;
import java.io.File;
Expand Down Expand Up @@ -224,12 +216,9 @@ static class BitmapSaver extends AsyncTask<Void, Void, Void> {
this.listener = listener;
}

/**
* @deprecated
*/
private void saveLegacy() {
private void save() {
if (path == null) {
path = Environment.getExternalStorageDirectory() + File.separator + DIRECTORY_PICTURES;
path = weakContext.get().getFilesDir() + File.separator + DIRECTORY_PICTURES;
}
File directory = new File(path);
directory.mkdirs();
Expand All @@ -254,49 +243,9 @@ private void saveLegacy() {
}
}

@RequiresApi(Build.VERSION_CODES.Q)
private void saveScopedStorage() {
path = path != null ? (DIRECTORY_PICTURES + File.separator + path) : DIRECTORY_PICTURES;
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, filename);
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, path);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, QuickShotUtils.getMimeType(fileExtension));
ContentResolver resolver = weakContext.get().getContentResolver();
Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
if (imageUri == null) {
errorMsg = String.format("Couldn't insert ContentValues with data: [%s] into the ContentResolver", contentValues.toString());
cancel(true);
return;
}
try (OutputStream out = resolver.openOutputStream(imageUri)) {
switch (fileExtension) {
case EXTENSION_JPG:
bitmap.compress(Bitmap.CompressFormat.JPEG, jpgQuality, out);
break;
case EXTENSION_PNG:
bitmap.compress(Bitmap.CompressFormat.PNG, 0, out);
break;
}
file = new File(path, filename + fileExtension);
} catch (Exception e) {
if (printStacktrace) {
e.printStackTrace();
}
errorMsg = e.toString();
resolver.delete(imageUri, null, null);
cancel(true);
} finally {
bitmap = null;
}
}

@Override
protected Void doInBackground(Void... voids) {
if (QuickShotUtils.isAboveAPI29()) {
saveScopedStorage();
} else {
saveLegacy();
}
save();
return null;
}

Expand All @@ -319,4 +268,3 @@ public void run() {
}
}
}

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Image format defaults to `.JPG`
Add the dependency in your `build.gradle`
```groovy
dependencies {
implementation 'io.github.muddz:quickshot:1.4.0'
implementation 'io.github.muddz:quickshot:1.5.0'
}
```
----
Expand Down