Merge branch 'audiorecorder-3.2.21'

This commit is contained in:
Alexey Kuznetsov 2018-09-25 14:34:51 +03:00
commit 2c3c48602e
5 changed files with 85 additions and 32 deletions

View file

@ -4,14 +4,14 @@ import com.android.build.OutputFile
android {
compileSdkVersion 25
buildToolsVersion '27.0.3'
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.github.axet.audiorecorder"
minSdkVersion 9
targetSdkVersion 23 // 24+ file:// unable to open
versionCode 278
versionName "3.2.20"
versionCode 279
versionName "3.2.21"
}
signingConfigs {
release {
@ -57,5 +57,5 @@ android {
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.github.axet:android-audio-library:1.0.121' // implementation project(':android-audio-library')
implementation 'com.github.axet:android-audio-library:1.0.123' // implementation project(':android-audio-library')
}

View file

@ -1,16 +1,29 @@
package com.github.axet.audiorecorder.app;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.view.ContextThemeWrapper;
import android.view.View;
import android.widget.RemoteViews;
import com.github.axet.androidlibrary.widgets.NotificationChannelCompat;
import com.github.axet.androidlibrary.widgets.RemoteViewsCompat;
import com.github.axet.androidlibrary.widgets.ThemeUtils;
import com.github.axet.audiolibrary.encoders.FormatFLAC;
import com.github.axet.audiolibrary.encoders.FormatM4A;
import com.github.axet.audiolibrary.encoders.FormatOGG;
import com.github.axet.audiorecorder.R;
import com.github.axet.audiorecorder.activities.MainActivity;
import java.util.Locale;
public class MainApplication extends com.github.axet.audiolibrary.app.MainApplication {
@ -36,29 +49,26 @@ public class MainApplication extends com.github.axet.audiolibrary.app.MainApplic
@Override
public void onCreate() {
super.onCreate();
final SharedPreferences defaultValueSp = getSharedPreferences(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, Context.MODE_PRIVATE);
if (!defaultValueSp.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
PreferenceManager.setDefaultValues(this, R.xml.pref_general, false);
if (!FormatOGG.supported(this)) {
switch (getVersion(PREFERENCE_VERSION, R.xml.pref_general)) {
case -1:
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor edit = shared.edit();
if (Build.VERSION.SDK_INT >= 18)
edit.putString(MainApplication.PREFERENCE_ENCODING, FormatM4A.EXT);
else
edit.putString(MainApplication.PREFERENCE_ENCODING, FormatFLAC.EXT);
if (!FormatOGG.supported(this)) {
if (Build.VERSION.SDK_INT >= 18)
edit.putString(MainApplication.PREFERENCE_ENCODING, FormatM4A.EXT);
else
edit.putString(MainApplication.PREFERENCE_ENCODING, FormatFLAC.EXT);
}
edit.putInt(PREFERENCE_VERSION, 2);
edit.commit();
}
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor edit = shared.edit();
edit.putInt(PREFERENCE_VERSION, 1);
edit.commit();
} else { // second start, check version
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
switch (shared.getInt(PREFERENCE_VERSION, 0)) {
case 0:
version_0_to_1();
break;
}
break;
case 0:
version_0_to_1();
version_1_to_2();
break;
case 1:
version_1_to_2();
break;
}
setTheme(getUserTheme());
}
@ -66,9 +76,50 @@ public class MainApplication extends com.github.axet.audiolibrary.app.MainApplic
void version_0_to_1() {
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor edit = shared.edit();
edit.putInt(PREFERENCE_VERSION, 1);
edit.putFloat(PREFERENCE_VOLUME, shared.getFloat(PREFERENCE_VOLUME, 0) + 1); // update volume from 0..1 to 0..1..4
edit.putInt(PREFERENCE_VERSION, 1);
edit.commit();
}
@SuppressLint("RestrictedApi")
void version_1_to_2() {
Locale locale = Locale.getDefault();
if (locale.toString().startsWith("ru")) {
String title = "Программа переименована";
String text = "'Аудио Рекордер' -> '" + getString(R.string.app_name) + "'";
PendingIntent main = PendingIntent.getService(this, 0,
new Intent(this, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews view = new RemoteViews(getPackageName(), MainApplication.getTheme(this, R.layout.notifictaion_recording_light, R.layout.notifictaion_recording_dark));
ContextThemeWrapper theme = new ContextThemeWrapper(this, MainApplication.getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark));
RemoteViewsCompat.setImageViewTint(view, R.id.icon_circle, ThemeUtils.getThemeColor(theme, R.attr.colorButtonNormal)); // android:tint="?attr/colorButtonNormal" not working API16
RemoteViewsCompat.applyTheme(theme, view);
view.setViewVisibility(R.id.notification_record, View.GONE);
view.setViewVisibility(R.id.notification_pause, View.GONE);
view.setOnClickPendingIntent(R.id.status_bar_latest_event_content, main);
view.setTextViewText(R.id.notification_title, title);
view.setTextViewText(R.id.notification_text, text);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(text)
.setTicker(title)
.setSmallIcon(R.drawable.ic_mic)
.setContent(view);
if (Build.VERSION.SDK_INT < 11)
builder.setContentIntent(main);
if (Build.VERSION.SDK_INT >= 21)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
Notification n = builder.build();
channelStatus.apply(n);
NotificationManagerCompat nm = NotificationManagerCompat.from(this);
nm.notify((int) System.currentTimeMillis(), n);
}
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor edit = shared.edit();
edit.putInt(PREFERENCE_VERSION, 2);
edit.commit();
}
}

View file

@ -1,5 +1,6 @@
package com.github.axet.audiorecorder.services;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
@ -14,6 +15,7 @@ import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.view.ContextThemeWrapper;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
@ -115,7 +117,6 @@ public class RecordingService extends Service {
@Override
public void onCreate() {
setTheme(MainApplication.getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark));
super.onCreate();
Log.d(TAG, "onCreate");
@ -168,6 +169,7 @@ public class RecordingService extends Service {
showNotificationAlarm(false, null);
}
@SuppressLint("RestrictedApi")
public Notification build(Intent intent) {
String targetFile = intent.getStringExtra("targetFile");
boolean recording = intent.getBooleanExtra("recording", false);
@ -187,8 +189,9 @@ public class RecordingService extends Service {
RemoteViews view = new RemoteViews(getPackageName(), MainApplication.getTheme(this, R.layout.notifictaion_recording_light, R.layout.notifictaion_recording_dark));
RemoteViewsCompat.setImageViewTint(view, R.id.icon_circle, ThemeUtils.getThemeColor(this, R.attr.colorButtonNormal)); // android:tint="?attr/colorButtonNormal" not working API16
RemoteViewsCompat.applyTheme(this, view);
ContextThemeWrapper theme = new ContextThemeWrapper(this, MainApplication.getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark));
RemoteViewsCompat.setImageViewTint(view, R.id.icon_circle, ThemeUtils.getThemeColor(theme, R.attr.colorButtonNormal)); // android:tint="?attr/colorButtonNormal" not working API16
RemoteViewsCompat.applyTheme(theme, view);
String title;
String text;
@ -232,9 +235,8 @@ public class RecordingService extends Service {
.setSmallIcon(R.drawable.ic_mic)
.setContent(view);
if (Build.VERSION.SDK_INT < 11) {
if (Build.VERSION.SDK_INT < 11)
builder.setContentIntent(main);
}
if (Build.VERSION.SDK_INT >= 21)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

View file

@ -1,5 +1,5 @@
<resources>
<string name="app_name">Аудио Рекордер</string>
<string name="app_name">Диктофон</string>
<string-array name="themes_text">
<item>Тема Светлая</item>

View file

@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
classpath 'com.android.tools.build:gradle:3.2.0'
}
}