diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 596bf278..93196556 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -70,7 +70,8 @@
-
+
+
@@ -83,7 +84,7 @@
android:value=".SettingsActivity" />
-
+
+
+
-
+
-
+
diff --git a/app/src/main/java/com/adam/aslfms/OptionsActivity.java b/app/src/main/java/com/adam/aslfms/OptionsActivity.java
index af4eeed4..4babdd7d 100644
--- a/app/src/main/java/com/adam/aslfms/OptionsActivity.java
+++ b/app/src/main/java/com/adam/aslfms/OptionsActivity.java
@@ -151,7 +151,7 @@ public PowerSpecificPrefs(PowerOptions power,
private PreferenceCategory category;
private ListPreference chooser;
- // private CheckBoxPreference notify;
+ private CheckBoxPreference notify;
private CheckBoxPreference scrobble;
private CheckBoxPreference np;
private ListPreference when;
@@ -161,7 +161,7 @@ public PowerSpecificPrefs(PowerOptions power,
public void create() {
createChooserPreference();
- //createNotifyPreference();
+ createNotifyPreference();
createScrobbleEnablePreference();
createNPEnablePreference();
createWhenPreference();
@@ -171,10 +171,10 @@ public void create() {
}
public boolean onClick(Preference pref) {
- /** if (pref == notify) {
+ if (pref == notify) {
settings.setNotifyEnabled(power, notify.isChecked());
return true;
- } else*/ if (pref == scrobble) {
+ } else if (pref == scrobble) {
settings.setScrobblingEnabled(power, scrobble.isChecked());
return true;
} else if (pref == np) {
@@ -198,7 +198,7 @@ private void update() {
chooser.setSummary(ao.getName(OptionsActivity.this));
chooser.setValue(ao.toString());
-// notify.setChecked(settings.isNotifyEnabled(power));
+ notify.setChecked(settings.isNotifyEnabled(power));
scrobble.setChecked(settings.isScrobblingEnabled(power));
np.setChecked(settings.isNowPlayingEnabled(power));
@@ -218,7 +218,7 @@ private void update() {
}
private void setScrobblingOptionsRestEnabled(AdvancedOptions ao) {
-// notify.setEnabled(ao == AdvancedOptions.CUSTOM);
+ notify.setEnabled(ao == AdvancedOptions.CUSTOM);
scrobble.setEnabled(ao == AdvancedOptions.CUSTOM);
np.setEnabled(ao == AdvancedOptions.CUSTOM);
when.setEnabled(ao == AdvancedOptions.CUSTOM);
@@ -247,13 +247,13 @@ private void createChooserPreference() {
chooser.setOnPreferenceChangeListener(mOnListPrefChange);
}
-/**
+
private void createNotifyPreference() {
notify = new CheckBoxPreference(OptionsActivity.this);
category.addPreference(notify);
notify.setTitle(R.string.advanced_options_notify_title);
}
-*/
+
private void createScrobbleEnablePreference() {
scrobble = new CheckBoxPreference(OptionsActivity.this);
category.addPreference(scrobble);
diff --git a/app/src/main/java/com/adam/aslfms/service/ForegroundHide.java b/app/src/main/java/com/adam/aslfms/service/ForegroundHide.java
new file mode 100644
index 00000000..b394a754
--- /dev/null
+++ b/app/src/main/java/com/adam/aslfms/service/ForegroundHide.java
@@ -0,0 +1,65 @@
+/**
+ * This file is part of Simple Last.fm Scrobbler.
+ *
+ * https://github.com/tgwizard/sls
+ *
+ * Copyright 2011 Simple Last.fm Scrobbler Team
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.adam.aslfms.service;
+
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.BitmapFactory;
+import android.os.IBinder;
+import android.support.v4.app.NotificationCompat;
+
+import com.adam.aslfms.R;
+import com.adam.aslfms.SettingsActivity;
+
+public class ForegroundHide extends Service {
+
+ Context ctx = this;
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent i, int flags, int startId) {
+ //Bundle extras = i.getExtras();
+
+
+ NotificationCompat.Builder builder =
+ new NotificationCompat.Builder(ctx)
+ .setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(),
+ R.mipmap.ic_launcher))
+ .setContentTitle("")
+ .setSmallIcon(R.mipmap.ic_notify)
+ .setContentText("");
+ Intent targetIntent = new Intent(ctx, SettingsActivity.class);
+ PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setContentIntent(contentIntent);
+
+
+ this.startForeground(14619, builder.build());
+
+ this.stopForeground(true);
+ return Service.START_NOT_STICKY;
+ }
+}
diff --git a/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java b/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java
index eed0a4ff..e7414b1b 100644
--- a/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java
+++ b/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java
@@ -85,6 +85,35 @@ public void onCreate() {
mDb = new ScrobblesDatabase(this);
mDb.open();
mNetManager = new NetworkerManager(this, mDb);
+
+ int sdk = Build.VERSION.SDK_INT;
+ if(sdk == Build.VERSION_CODES.GINGERBREAD || sdk == Build.VERSION_CODES.GINGERBREAD_MR1) {
+ String ar = "";
+ String tr = "";
+ String api = "";
+ if (mCurrentTrack != null){
+ ar = mCurrentTrack.getArtist();
+ tr = mCurrentTrack.getTrack();
+ api = mCurrentTrack.getMusicAPI().readAPIname();
+ }
+ NotificationCompat.Builder builder =
+ new NotificationCompat.Builder(mCtx)
+ .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(),
+ R.mipmap.ic_launcher))
+ .setContentTitle(ar)
+ .setSmallIcon(R.mipmap.ic_notify)
+ .setContentText(tr + " : " + api);
+ Intent targetIntent = new Intent(mCtx, SettingsActivity.class);
+ PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setContentIntent(contentIntent);
+
+ this.startForeground(14619, builder.build());
+
+ if (!settings.isNotifyEnabled(Util.checkPower(mCtx))) {
+ Intent iNoti = new Intent(mCtx, ForegroundHide.class);
+ this.startService(iNoti);
+ }
+ }
}
@Override
@@ -96,7 +125,6 @@ public void onDestroy() {
public int onStartCommand(Intent i, int flags, int startId) {
handleCommand(i, startId);
- NotificationManager nManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
String ar = "";
String tr = "";
String api = "";
@@ -116,8 +144,12 @@ public int onStartCommand(Intent i, int flags, int startId) {
PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
-
this.startForeground(14619, builder.build());
+
+ if (!settings.isNotifyEnabled(Util.checkPower(mCtx))) {
+ Intent iNoti = new Intent(mCtx, ForegroundHide.class);
+ startService(iNoti);
+ }
return Service.START_STICKY;
}
@@ -134,7 +166,7 @@ private void handleCommand(Intent i, int startId) {
}
String action = i.getAction();
Bundle extras = i.getExtras();
- if (action.equals(ACTION_CLEARCREDS)) {
+ if (action.equals(ACTION_CLEARCREDS)) {
if (extras.getBoolean("clearall", false)) {
mNetManager.launchClearAllCreds();
} else {