kopia lustrzana https://github.com/xdsopl/robot36
made linter happy
rodzic
15d1fe6896
commit
c12d11ab79
|
@ -55,7 +55,7 @@ public class ImageView extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPixels(int pixels[]) {
|
public void setPixels(int[] pixels) {
|
||||||
synchronized (holder) {
|
synchronized (holder) {
|
||||||
bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
|
bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ limitations under the License.
|
||||||
package xdsopl.robot36;
|
package xdsopl.robot36;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
@ -36,13 +37,14 @@ import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.view.MenuItemCompat;
|
import androidx.core.view.MenuItemCompat;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.ShareActionProvider;
|
import androidx.appcompat.widget.ShareActionProvider;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -64,8 +66,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private Bitmap bitmap;
|
private Bitmap bitmap;
|
||||||
private NotificationManager manager;
|
private NotificationManager manager;
|
||||||
private ShareActionProvider share;
|
private ShareActionProvider share;
|
||||||
private int notifyID = 1;
|
private final int notifyID = 1;
|
||||||
private int permissionsID = 2;
|
private final int permissionsID = 2;
|
||||||
private static final String channelID = "Robot36";
|
private static final String channelID = "Robot36";
|
||||||
private boolean enableAnalyzer = true;
|
private boolean enableAnalyzer = true;
|
||||||
private Menu menu;
|
private Menu menu;
|
||||||
|
@ -97,85 +99,79 @@ public class MainActivity extends AppCompatActivity {
|
||||||
void updateTitle(final String newTitle)
|
void updateTitle(final String newTitle)
|
||||||
{
|
{
|
||||||
if (getTitle() != newTitle) {
|
if (getTitle() != newTitle) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> setTitle(newTitle));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
setTitle(newTitle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void storeBitmap(Bitmap image) {
|
void storeBitmap(Bitmap image) {
|
||||||
bitmap = image;
|
bitmap = image;
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> {
|
||||||
@Override
|
Date date = new Date();
|
||||||
public void run() {
|
@SuppressLint("SimpleDateFormat") String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(date);
|
||||||
Date date = new Date();
|
@SuppressLint("SimpleDateFormat") String title = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
||||||
String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(date);
|
ContentValues values = new ContentValues();
|
||||||
String title = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
File dir;
|
||||||
ContentValues values = new ContentValues();
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
File dir;
|
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (!dir.exists())
|
||||||
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
//noinspection ResultOfMethodCallIgnored
|
||||||
if (!dir.exists())
|
dir.mkdirs();
|
||||||
dir.mkdirs();
|
File file;
|
||||||
File file;
|
try {
|
||||||
try {
|
file = File.createTempFile(name + "_", ".png", dir);
|
||||||
file = File.createTempFile(name + "_", ".png", dir);
|
name = file.getName();
|
||||||
name = file.getName();
|
} catch (IOException ignore) {
|
||||||
} catch (IOException ignore) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
FileOutputStream stream;
|
|
||||||
try {
|
|
||||||
stream = new FileOutputStream(file);
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
|
||||||
try {
|
|
||||||
stream.close();
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
values.put(MediaStore.Images.ImageColumns.DATA, file.toString());
|
|
||||||
} else {
|
|
||||||
name += ".png";
|
|
||||||
values.put(MediaStore.Images.Media.DISPLAY_NAME, name);
|
|
||||||
values.put(MediaStore.Images.Media.RELATIVE_PATH, "Pictures/");
|
|
||||||
values.put(MediaStore.Images.Media.IS_PENDING, 1);
|
|
||||||
}
|
}
|
||||||
values.put(MediaStore.Images.ImageColumns.TITLE, title);
|
FileOutputStream stream;
|
||||||
values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
|
try {
|
||||||
ContentResolver resolver = getContentResolver();
|
stream = new FileOutputStream(file);
|
||||||
Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
} catch (IOException ignore) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
return;
|
||||||
FileOutputStream stream;
|
|
||||||
try {
|
|
||||||
ParcelFileDescriptor descriptor = getContentResolver().openFileDescriptor(uri,"w");
|
|
||||||
stream = new FileOutputStream(descriptor.getFileDescriptor());
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
|
||||||
try {
|
|
||||||
stream.close();
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
values.clear();
|
|
||||||
values.put(MediaStore.Images.Media.IS_PENDING, 0);
|
|
||||||
resolver.update(uri, values, null, null);
|
|
||||||
}
|
}
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
try {
|
||||||
intent.setType("image/png");
|
stream.close();
|
||||||
share.setShareIntent(intent);
|
} catch (IOException ignore) {
|
||||||
Toast toast = Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT);
|
return;
|
||||||
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
|
}
|
||||||
toast.show();
|
values.put(MediaStore.Images.ImageColumns.DATA, file.toString());
|
||||||
|
} else {
|
||||||
|
name += ".png";
|
||||||
|
values.put(MediaStore.Images.Media.DISPLAY_NAME, name);
|
||||||
|
values.put(MediaStore.Images.Media.RELATIVE_PATH, "Pictures/");
|
||||||
|
values.put(MediaStore.Images.Media.IS_PENDING, 1);
|
||||||
}
|
}
|
||||||
|
values.put(MediaStore.Images.ImageColumns.TITLE, title);
|
||||||
|
values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
|
||||||
|
ContentResolver resolver = getContentResolver();
|
||||||
|
Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
FileOutputStream stream;
|
||||||
|
try {
|
||||||
|
ParcelFileDescriptor descriptor = getContentResolver().openFileDescriptor(uri,"w");
|
||||||
|
stream = new FileOutputStream(descriptor.getFileDescriptor());
|
||||||
|
descriptor.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
values.clear();
|
||||||
|
values.put(MediaStore.Images.Media.IS_PENDING, 0);
|
||||||
|
resolver.update(uri, values, null, null);
|
||||||
|
}
|
||||||
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
|
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||||
|
intent.setType("image/png");
|
||||||
|
share.setShareIntent(intent);
|
||||||
|
Toast toast = Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT);
|
||||||
|
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
|
||||||
|
toast.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +180,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
changeLayoutOrientation(getResources().getConfiguration());
|
changeLayoutOrientation(getResources().getConfiguration());
|
||||||
image = (ImageView)findViewById(R.id.image);
|
image = findViewById(R.id.image);
|
||||||
manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
startDecoder();
|
startDecoder();
|
||||||
}
|
}
|
||||||
|
@ -210,7 +206,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
updateMenuButtons();
|
updateMenuButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorMessage(final String title, final String shortText, final String longText) {
|
private void showErrorMessage(final String title, final String shortText) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(title);
|
builder.setTitle(title);
|
||||||
builder.setMessage(shortText);
|
builder.setMessage(shortText);
|
||||||
|
@ -227,7 +223,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
if (requestCode != permissionsID)
|
if (requestCode != permissionsID)
|
||||||
return;
|
return;
|
||||||
for (int result : grantResults)
|
for (int result : grantResults)
|
||||||
|
@ -244,7 +241,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||||
if (permissions.isEmpty())
|
if (permissions.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
ActivityCompat.requestPermissions(this, permissions.toArray(new String[permissions.size()]), permissionsID);
|
ActivityCompat.requestPermissions(this, permissions.toArray(new String[0]), permissionsID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,16 +252,16 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
decoder = new Decoder(this,
|
decoder = new Decoder(this,
|
||||||
(SpectrumView) findViewById(R.id.spectrum),
|
findViewById(R.id.spectrum),
|
||||||
(SpectrumView) findViewById(R.id.spectrogram),
|
findViewById(R.id.spectrogram),
|
||||||
(ImageView) findViewById(R.id.image),
|
findViewById(R.id.image),
|
||||||
(VUMeterView) findViewById(R.id.meter)
|
findViewById(R.id.meter)
|
||||||
);
|
);
|
||||||
decoder.enable_analyzer(enableAnalyzer);
|
decoder.enable_analyzer(enableAnalyzer);
|
||||||
showNotification();
|
showNotification();
|
||||||
updateMenuButtons();
|
updateMenuButtons();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
showErrorMessage(getString(R.string.decoder_error), e.getMessage(), Log.getStackTraceString(e));
|
showErrorMessage(getString(R.string.decoder_error), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +303,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration config) {
|
public void onConfigurationChanged(@NonNull Configuration config) {
|
||||||
super.onConfigurationChanged(config);
|
super.onConfigurationChanged(config);
|
||||||
changeLayoutOrientation(config);
|
changeLayoutOrientation(config);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue