mirror of
https://github.com/olgamiller/SSTVEncoder2.git
synced 2025-12-06 06:52:01 +01:00
Fixes write permission for each sdk version, improved image loading
This commit is contained in:
parent
c14af42222
commit
fbd4aef064
|
|
@ -3,8 +3,7 @@
|
|||
package="om.sstvencoder">
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="18"/>
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="false"/>
|
||||
|
|
|
|||
|
|
@ -177,15 +177,18 @@ public class CropView extends ImageView {
|
|||
mImageOK = false;
|
||||
mOrientation = 0;
|
||||
recycle();
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setBitmapStream(InputStream stream) throws IOException {
|
||||
public void setBitmap(@NonNull InputStream stream) throws IOException {
|
||||
mImageOK = false;
|
||||
mOrientation = 0;
|
||||
recycle();
|
||||
loadImage(stream);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void loadImage(InputStream stream) throws IOException {
|
||||
// app6 + exif
|
||||
int bufferBytes = 1048576;
|
||||
if (!stream.markSupported())
|
||||
|
|
@ -214,7 +217,6 @@ public class CropView extends ImageView {
|
|||
|
||||
mImageOK = true;
|
||||
resetInputRect();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void recycle() {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import android.view.SubMenu;
|
|||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import om.sstvencoder.ModeInterfaces.IModeInfo;
|
||||
import om.sstvencoder.TextOverlay.Label;
|
||||
|
|
@ -86,8 +86,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
uri = mSettings.getImageUri();
|
||||
verbose = false;
|
||||
}
|
||||
if (loadImage(uri, verbose))
|
||||
mSettings.setImageUri(uri);
|
||||
loadImage(uri, verbose);
|
||||
}
|
||||
|
||||
private Uri getImageUriFromIntent(Intent intent) {
|
||||
|
|
@ -105,29 +104,39 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
// Set verbose to false for any Uri that might have expired (e.g. shared from browser).
|
||||
private boolean loadImage(Uri uri, boolean verbose) {
|
||||
ContentResolver resolver = getContentResolver();
|
||||
InputStream stream = null;
|
||||
if (uri != null) {
|
||||
mSettings.setImageUri(uri);
|
||||
try {
|
||||
ContentResolver resolver = getContentResolver();
|
||||
mCropView.setBitmapStream(resolver.openInputStream(uri));
|
||||
mCropView.rotateImage(getOrientation(resolver, uri));
|
||||
return true;
|
||||
} catch (FileNotFoundException ex) {
|
||||
stream = resolver.openInputStream(uri);
|
||||
} catch (Exception ex) { // e.g. FileNotFoundException, SecurityException
|
||||
if (ex.getCause() instanceof ErrnoException
|
||||
&& ((ErrnoException) ex.getCause()).errno == OsConstants.EACCES) {
|
||||
requestPermissions();
|
||||
} else if (verbose) {
|
||||
String s = getString(R.string.load_img_err_title) + ": \n" + ex.getMessage();
|
||||
Toast.makeText(this, s, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (verbose) {
|
||||
String s = Utility.createMessage(ex) + "\n\n" + uri;
|
||||
showErrorMessage(getString(R.string.load_img_err_title), ex.getMessage(), s);
|
||||
return false;
|
||||
}
|
||||
showFileNotLoadedMessage(ex, verbose);
|
||||
}
|
||||
}
|
||||
mCropView.setNoBitmap();
|
||||
return false;
|
||||
if (stream == null) {
|
||||
mCropView.setNoBitmap();
|
||||
mSettings.setImageUri(null);
|
||||
return false;
|
||||
}
|
||||
return loadImage(stream, resolver, uri);
|
||||
}
|
||||
|
||||
private boolean loadImage(InputStream stream, ContentResolver resolver, Uri uri) {
|
||||
try {
|
||||
mCropView.setBitmap(stream);
|
||||
} catch (Exception ex) {
|
||||
String s = Utility.createMessage(ex) + "\n\n" + uri;
|
||||
showErrorMessage(getString(R.string.load_img_err_title), ex.getMessage(), s);
|
||||
return false;
|
||||
}
|
||||
mCropView.rotateImage(getOrientation(resolver, uri));
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isIntentActionValid(String action) {
|
||||
|
|
@ -147,6 +156,15 @@ public class MainActivity extends AppCompatActivity {
|
|||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
|
||||
}
|
||||
|
||||
private void showFileNotLoadedMessage(Exception ex, boolean verbose) {
|
||||
String s;
|
||||
if (verbose)
|
||||
s = getString(R.string.load_img_err_title) + ": \n" + ex.getMessage();
|
||||
else
|
||||
s = getString(R.string.message_prev_img_not_loaded);
|
||||
Toast.makeText(this, s, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void showErrorMessage(final String title, final String shortText, final String longText) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(title);
|
||||
|
|
@ -280,18 +298,13 @@ public class MainActivity extends AppCompatActivity {
|
|||
case REQUEST_IMAGE_CAPTURE:
|
||||
if (resultCode == RESULT_OK) {
|
||||
Uri uri = Uri.fromFile(mFile);
|
||||
if (loadImage(uri, true)) {
|
||||
mSettings.setImageUri(uri);
|
||||
if (loadImage(uri, true))
|
||||
addImageToGallery(uri);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REQUEST_PICK_IMAGE:
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
Uri uri = data.getData();
|
||||
if (loadImage(uri, true))
|
||||
mSettings.setImageUri(uri);
|
||||
}
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
loadImage(data.getData(), true);
|
||||
break;
|
||||
default:
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
<string name="load_img_err_title">Image loading error</string>
|
||||
<string name="load_img_orientation_err_title">Image orientation error</string>
|
||||
<string name="load_img_err_txt_unsupported">Unsupported content.</string>
|
||||
<string name="message_prev_img_not_loaded">Previous image could not be loaded.</string>
|
||||
<string name="btn_send_email">Send Email</string>
|
||||
<string name="btn_ok">OK</string>
|
||||
<string name="email_subject">SSTV Encoder - Bug Report</string>
|
||||
|
|
|
|||
Loading…
Reference in a new issue