add notification channels
This commit is contained in:
parent
c58434d44c
commit
b093cb6c14
6 changed files with 45 additions and 18 deletions
|
|
@ -57,5 +57,5 @@ android {
|
|||
|
||||
dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
implementation 'com.github.axet:android-audio-library:1.0.118' // implementation project(':android-audio-library')
|
||||
implementation 'com.github.axet:android-audio-library:1.0.120' // implementation project(':android-audio-library')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,12 +104,12 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
|
||||
receiver = new ScreenReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
public void onScreenOff() {
|
||||
boolean p = storage.recordingPending();
|
||||
boolean c = shared.getBoolean(MainApplication.PREFERENCE_CONTROLS, false);
|
||||
if (!p && !c)
|
||||
return;
|
||||
super.onReceive(context, intent);
|
||||
super.onScreenOff();
|
||||
}
|
||||
};
|
||||
receiver.registerReceiver(this);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package com.github.axet.audiorecorder.app;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
|
||||
import com.github.axet.androidlibrary.widgets.NotificationChannelCompat;
|
||||
import com.github.axet.audiolibrary.encoders.FormatFLAC;
|
||||
import com.github.axet.audiolibrary.encoders.FormatM4A;
|
||||
import com.github.axet.audiolibrary.encoders.FormatOGG;
|
||||
|
|
@ -19,10 +21,18 @@ public class MainApplication extends com.github.axet.audiolibrary.app.MainApplic
|
|||
|
||||
public static final String PREFERENCE_VERSION = "version";
|
||||
|
||||
public NotificationChannelCompat channelStatus;
|
||||
|
||||
public int getUserTheme() {
|
||||
return getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
channelStatus = new NotificationChannelCompat(this, "status", "Status", NotificationManagerCompat.IMPORTANCE_LOW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
package com.github.axet.audiorecorder.services;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
|
@ -16,12 +13,14 @@ import android.os.IBinder;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.github.axet.androidlibrary.widgets.OptimizationPreferenceCompat;
|
||||
import com.github.axet.androidlibrary.widgets.ProximityShader;
|
||||
import com.github.axet.androidlibrary.widgets.ThemeUtils;
|
||||
import com.github.axet.audiolibrary.app.Storage;
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.activities.MainActivity;
|
||||
|
|
@ -48,6 +47,7 @@ public class RecordingService extends Service {
|
|||
public static String RECORD_BUTTON = RecordingService.class.getCanonicalName() + ".RECORD_BUTTON";
|
||||
|
||||
Storage storage; // for storage path
|
||||
Notification notification;
|
||||
|
||||
public static void startIfEnabled(Context context) {
|
||||
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
|
@ -107,14 +107,20 @@ public class RecordingService extends Service {
|
|||
public RecordingService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
setTheme(MainApplication.getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark));
|
||||
super.onCreate();
|
||||
Log.d(TAG, "onCreate");
|
||||
|
||||
storage = new Storage(this);
|
||||
|
||||
startForeground(NOTIFICATION_RECORDING_ICON, build(new Intent()));
|
||||
showNotificationAlarm(true, new Intent());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -158,9 +164,6 @@ public class RecordingService extends Service {
|
|||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.d(TAG, "onDestory");
|
||||
|
||||
stopForeground(false);
|
||||
|
||||
showNotificationAlarm(false, null);
|
||||
}
|
||||
|
||||
|
|
@ -181,9 +184,9 @@ public class RecordingService extends Service {
|
|||
new Intent(this, RecordingService.class).setAction(RECORD_BUTTON),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
RemoteViews view = new RemoteViews(getPackageName(), MainApplication.getTheme(getBaseContext(),
|
||||
R.layout.notifictaion_recording_light,
|
||||
R.layout.notifictaion_recording_dark));
|
||||
RemoteViews view = new RemoteViews(getPackageName(), MainApplication.getTheme(this, R.layout.notifictaion_recording_light, R.layout.notifictaion_recording_dark));
|
||||
|
||||
view.setInt(R.id.icon_circle, "setColorFilter", ThemeUtils.getThemeColor(this, R.attr.colorButtonNormal)); // android:tint="?attr/colorButtonNormal" not working API16
|
||||
|
||||
String title;
|
||||
String text;
|
||||
|
|
@ -237,13 +240,20 @@ public class RecordingService extends Service {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
// alarm dismiss button
|
||||
public void showNotificationAlarm(boolean show, Intent intent) {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
NotificationManagerCompat nm = NotificationManagerCompat.from(this);
|
||||
if (!show) {
|
||||
notificationManager.cancel(NOTIFICATION_RECORDING_ICON);
|
||||
stopForeground(false);
|
||||
nm.cancel(NOTIFICATION_RECORDING_ICON);
|
||||
notification = null;
|
||||
} else {
|
||||
notificationManager.notify(NOTIFICATION_RECORDING_ICON, build(intent));
|
||||
Notification n = build(intent);
|
||||
((MainApplication) getApplication()).channelStatus.apply(n);
|
||||
if (notification == null)
|
||||
startForeground(NOTIFICATION_RECORDING_ICON, n);
|
||||
else
|
||||
nm.notify(NOTIFICATION_RECORDING_ICON, n);
|
||||
notification = n;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
6
app/src/main/res/values-sw700dp/dimens.xml
Normal file
6
app/src/main/res/values-sw700dp/dimens.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
<resources>
|
||||
<attr name="recColor" format="color" />
|
||||
<attr name="cutColor" format="color" />
|
||||
|
||||
<string name="source_mic" translatable="false">mic</string>
|
||||
<string name="source_default" translatable="false">default</string>
|
||||
<string name="source_raw" translatable="false">raw</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue