Commit 8a625701 authored by axet's avatar axet 🍄

Merge branch 'binauralbeats-1.4.24'

parents fb59008b 991f807c
......@@ -8,8 +8,8 @@ android {
applicationId "com.github.axet.binauralbeats"
minSdkVersion 9
targetSdkVersion 23
versionCode 153
versionName "1.4.22"
versionCode 156
versionName "1.4.24"
}
signingConfigs {
release {
......
package com.github.axet.binauralbeats.services;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
......@@ -18,6 +19,7 @@ import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.media.session.MediaButtonReceiver;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v7.view.ContextThemeWrapper;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
......@@ -87,7 +89,6 @@ public class BeatsService extends Service implements SharedPreferences.OnSharedP
@Override
public void onCreate() {
setTheme(MainApplication.getTheme(this, R.style.AppThemeLight, R.style.AppThemeDark));
super.onCreate();
Log.d(TAG, "onCreate");
......@@ -164,6 +165,9 @@ public class BeatsService extends Service implements SharedPreferences.OnSharedP
showNotificationAlarm(false);
unregisterReceiver(receiver);
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
shared.unregisterOnSharedPreferenceChangeListener(this);
}
public static boolean getAttr(AttributeSet attrs, String name, TypedValue out) {
......@@ -188,15 +192,17 @@ public class BeatsService extends Service implements SharedPreferences.OnSharedP
return false;
}
@SuppressLint("RestrictedApi")
Notification buildNotification() {
PendingIntent main = PendingIntent.getService(this, 0,
new Intent(this, BeatsService.class).setAction(SHOW_ACTIVITY),
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));
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.AppThemeLight, R.style.AppThemeDark));
RemoteViewsCompat.setImageViewTint(view, R.id.icon_circle, ThemeUtils.getThemeColor(theme, R.attr.colorButtonNormal)); // android:tint="?attr/colorButtonNormal" not working API16
RemoteViewsCompat.applyTheme(theme, view);
boolean pause = !playing && !end;
String title = name;
......@@ -256,6 +262,7 @@ public class BeatsService extends Service implements SharedPreferences.OnSharedP
if (!show) {
stopForeground(false);
nm.cancel(NOTIFICATION_RECORDING_ICON);
notification = null;
} else {
Notification n = buildNotification();
if (notification == null)
......@@ -268,28 +275,29 @@ public class BeatsService extends Service implements SharedPreferences.OnSharedP
void headset(boolean b, boolean playing) {
if (b) {
if (ms == null)
if (ms == null) {
ms = new MediaSessionCompat(this, TAG, new ComponentName(this, RecordingReceiver.class), null);
ms.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPlay() {
pause();
}
ms.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPlay() {
pause();
}
@Override
public void onPause() {
pause();
}
@Override
public void onPause() {
pause();
}
@Override
public void onStop() {
try {
stop.send();
} catch (PendingIntent.CanceledException e) {
Log.d(TAG, "pause canceled", e);
@Override
public void onStop() {
try {
stop.send();
} catch (PendingIntent.CanceledException e) {
Log.d(TAG, "pause canceled", e);
}
}
}
});
});
}
PlaybackStateCompat state = new PlaybackStateCompat.Builder()
.setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_STOP)
.setState(playing ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, 0, 1)
......@@ -316,8 +324,6 @@ public class BeatsService extends Service implements SharedPreferences.OnSharedP
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(MainApplication.PREFERENCE_THEME)) {
stopService(new Intent(this, getClass()));
startService(new Intent(this, getClass()));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment