fix old phones
This commit is contained in:
parent
07958f719f
commit
c81ef79727
7 changed files with 88 additions and 32 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.axet.audiorecorder.activities;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.ActionBar;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
|
@ -9,8 +8,8 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
|
|
@ -39,14 +38,15 @@ import android.widget.SeekBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.axet.androidlibrary.animations.RemoveItemAnimation;
|
||||
import com.github.axet.androidlibrary.widgets.OpenFileDialog;
|
||||
import com.github.axet.androidlibrary.widgets.ThemeUtils;
|
||||
import com.github.axet.androidlibrary.widgets.PopupShareActionProvider;
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.animations.RecordingAnimation;
|
||||
import com.github.axet.androidlibrary.animations.RemoveItemAnimation;
|
||||
import com.github.axet.audiorecorder.app.MainApplication;
|
||||
import com.github.axet.audiorecorder.app.RawSamples;
|
||||
import com.github.axet.audiorecorder.app.Storage;
|
||||
import com.github.axet.androidlibrary.widgets.PopupShareActionProvider;
|
||||
import com.github.axet.audiorecorder.widgets.PitchView;
|
||||
import com.google.android.gms.appindexing.Action;
|
||||
import com.google.android.gms.appindexing.AppIndex;
|
||||
import com.google.android.gms.common.api.GoogleApiClient;
|
||||
|
|
@ -638,6 +638,8 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
|
|||
public static final String[] PERMISSIONS = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
|
||||
boolean permitted(String[] ss) {
|
||||
if (Build.VERSION.SDK_INT < 11)
|
||||
return true;
|
||||
for (String s : ss) {
|
||||
if (ContextCompat.checkSelfPermission(this, s) != PackageManager.PERMISSION_GRANTED) {
|
||||
return false;
|
||||
|
|
@ -647,6 +649,8 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
|
|||
}
|
||||
|
||||
boolean permitted() {
|
||||
if (Build.VERSION.SDK_INT < 11)
|
||||
return true;
|
||||
for (String s : PERMISSIONS) {
|
||||
if (ContextCompat.checkSelfPermission(this, s) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, PERMISSIONS, 1);
|
||||
|
|
|
|||
|
|
@ -738,6 +738,8 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
};
|
||||
|
||||
boolean permitted(String[] ss) {
|
||||
if (Build.VERSION.SDK_INT < 11)
|
||||
return true;
|
||||
for (String s : ss) {
|
||||
if (ContextCompat.checkSelfPermission(this, s) != PackageManager.PERMISSION_GRANTED) {
|
||||
return false;
|
||||
|
|
@ -747,6 +749,8 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
boolean permitted() {
|
||||
if (Build.VERSION.SDK_INT < 11)
|
||||
return true;
|
||||
for (String s : PERMISSIONS) {
|
||||
if (ContextCompat.checkSelfPermission(this, s) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, PERMISSIONS, 1);
|
||||
|
|
|
|||
|
|
@ -208,6 +208,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
|
|||
public static final String[] PERMISSIONS = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
|
||||
public static boolean permitted(Context context, String[] ss) {
|
||||
if (Build.VERSION.SDK_INT < 11)
|
||||
return true;
|
||||
for (String s : ss) {
|
||||
if (ContextCompat.checkSelfPermission(context, s) != PackageManager.PERMISSION_GRANTED) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.axet.audiorecorder.app;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
|
|
@ -10,13 +9,8 @@ import android.os.Build;
|
|||
import android.os.StatFs;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.activities.RecordingActivity;
|
||||
import com.github.axet.audiorecorder.encoders.FormatM4A;
|
||||
import com.github.axet.audiorecorder.encoders.FormatWAV;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
|
@ -42,6 +36,8 @@ public class Storage {
|
|||
public static final String[] PERMISSIONS = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
|
||||
public boolean permitted(String[] ss) {
|
||||
if (Build.VERSION.SDK_INT < 11)
|
||||
return true;
|
||||
for (String s : ss) {
|
||||
if (ContextCompat.checkSelfPermission(context, s) != PackageManager.PERMISSION_GRANTED) {
|
||||
return false;
|
||||
|
|
@ -227,7 +223,7 @@ public class Storage {
|
|||
|
||||
StatFs fsi = new StatFs(f.getPath());
|
||||
if (Build.VERSION.SDK_INT < 18)
|
||||
return fsi.getBlockSize() * fsi.getAvailableBlocks();
|
||||
return fsi.getBlockSize() * (long) fsi.getAvailableBlocks();
|
||||
else
|
||||
return fsi.getBlockSizeLong() * fsi.getAvailableBlocksLong();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,18 @@
|
|||
package com.github.axet.audiorecorder.widgets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.axet.androidlibrary.widgets.ThemeUtils;
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.app.MainApplication;
|
||||
import com.github.axet.audiorecorder.app.RawSamples;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
|
@ -83,8 +77,7 @@ public class PitchView extends ViewGroup {
|
|||
Handler handler;
|
||||
Runnable run;
|
||||
|
||||
public static HandlerUpdate start(Handler handler, Runnable run, long updateSpeed) {
|
||||
HandlerUpdate r = new HandlerUpdate();
|
||||
public static HandlerUpdate start(HandlerUpdate r, Handler handler, Runnable run, long updateSpeed) {
|
||||
r.run = run;
|
||||
r.start = System.currentTimeMillis();
|
||||
r.updateSpeed = updateSpeed;
|
||||
|
|
@ -94,14 +87,18 @@ public class PitchView extends ViewGroup {
|
|||
return r;
|
||||
}
|
||||
|
||||
public static HandlerUpdate start(Handler handler, Runnable run, long updateSpeed) {
|
||||
HandlerUpdate r = new HandlerUpdate();
|
||||
return start(r, handler, run, updateSpeed);
|
||||
}
|
||||
|
||||
|
||||
public static void stop(Handler handler, Runnable run) {
|
||||
handler.removeCallbacks(run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.run.run();
|
||||
|
||||
long cur = System.currentTimeMillis();
|
||||
|
||||
long diff = cur - start;
|
||||
|
|
@ -112,6 +109,40 @@ public class PitchView extends ViewGroup {
|
|||
if (delay > updateSpeed)
|
||||
delay = updateSpeed;
|
||||
|
||||
post(delay);
|
||||
}
|
||||
|
||||
void post(long delay) {
|
||||
this.run.run();
|
||||
|
||||
if (delay > 0)
|
||||
this.handler.postDelayed(this, delay);
|
||||
else
|
||||
this.handler.post(this);
|
||||
}
|
||||
}
|
||||
|
||||
// if CPU speed not enough skip frames
|
||||
public static class FallbackUpdate extends HandlerUpdate {
|
||||
Runnable fallback;
|
||||
long slow;
|
||||
|
||||
public static FallbackUpdate start(Handler handler, Runnable run, Runnable fallback, long updateSpeed) {
|
||||
FallbackUpdate r = new FallbackUpdate();
|
||||
r.fallback = fallback;
|
||||
r.slow = updateSpeed / 4;
|
||||
return (FallbackUpdate) start(r, handler, run, updateSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
void post(long delay) {
|
||||
if (delay < slow) {
|
||||
Log.d(TAG, "fallback " + delay + " " + slow);
|
||||
this.fallback.run();
|
||||
} else {
|
||||
Log.d(TAG, "run " + delay + " " + slow);
|
||||
this.run.run();
|
||||
}
|
||||
if (delay > 0)
|
||||
this.handler.postDelayed(this, delay);
|
||||
else
|
||||
|
|
@ -421,11 +452,12 @@ public class PitchView extends ViewGroup {
|
|||
}
|
||||
|
||||
public void fit(int max) {
|
||||
if (max < 0) // -1
|
||||
return;
|
||||
if (data.size() > max) {
|
||||
int cut = data.size() - max;
|
||||
data.subList(0, cut).clear();
|
||||
samples += cut;
|
||||
|
||||
int m = data.size() - 1;
|
||||
// screen rotate may cause play/edit offsets off screen
|
||||
if (editPos > m)
|
||||
|
|
@ -571,13 +603,18 @@ public class PitchView extends ViewGroup {
|
|||
public void edit() {
|
||||
if (edit == null) {
|
||||
editFlash = true;
|
||||
|
||||
edit = HandlerUpdate.start(handler, new Runnable() {
|
||||
edit = FallbackUpdate.start(handler, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
draw();
|
||||
editFlash = !editFlash;
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
graph.calc();
|
||||
editFlash = !editFlash;
|
||||
}
|
||||
}, EDIT_UPDATE_SPEED);
|
||||
}
|
||||
}
|
||||
|
|
@ -595,12 +632,16 @@ public class PitchView extends ViewGroup {
|
|||
|
||||
if (draw == null) {
|
||||
time = System.currentTimeMillis();
|
||||
|
||||
draw = HandlerUpdate.start(handler, new Runnable() {
|
||||
draw = FallbackUpdate.start(handler, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawCalc();
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
graph.calc();
|
||||
}
|
||||
}, UPDATE_SPEED);
|
||||
}
|
||||
}
|
||||
|
|
@ -638,11 +679,16 @@ public class PitchView extends ViewGroup {
|
|||
|
||||
if (play == null) {
|
||||
time = System.currentTimeMillis();
|
||||
play = HandlerUpdate.start(handler, new Runnable() {
|
||||
play = FallbackUpdate.start(handler, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
draw();
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
graph.calc();
|
||||
}
|
||||
}, UPDATE_SPEED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@
|
|||
android:src="@drawable/play"
|
||||
android:tint="?attr/colorAccent" />
|
||||
|
||||
<Space
|
||||
<View
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
|
@ -135,7 +135,7 @@
|
|||
android:src="@drawable/ic_create_black_24dp"
|
||||
android:tint="?attr/colorAccent" />
|
||||
|
||||
<Space
|
||||
<View
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
|
@ -148,7 +148,7 @@
|
|||
android:src="@drawable/share"
|
||||
android:tint="?attr/colorAccent" />
|
||||
|
||||
<Space
|
||||
<View
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
|
|
|||
|
|
@ -61,23 +61,27 @@
|
|||
<item quantity="one">%d день</item>
|
||||
<item quantity="few">%d дня </item>
|
||||
<item quantity="many">%d дней</item>
|
||||
<item quantity="other">%d дней</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="hours">
|
||||
<item quantity="one">%d час</item>
|
||||
<item quantity="few">%d часа</item>
|
||||
<item quantity="many">%d часов</item>
|
||||
<item quantity="other">%d часов</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="minutes">
|
||||
<item quantity="one">%d минута</item>
|
||||
<item quantity="few">%d минуты</item>
|
||||
<item quantity="many">%d минут</item>
|
||||
<item quantity="other">%d минут</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="seconds">
|
||||
<item quantity="one">%d секунда</item>
|
||||
<item quantity="few">%d секунды</item>
|
||||
<item quantity="many">%d секунд</item>
|
||||
<item quantity="other">%d секунд</item>
|
||||
</plurals>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue