Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Commit

Permalink
Notification Can Hide
Browse files Browse the repository at this point in the history
  • Loading branch information
HumbleBeeBumbleBee authored and HumbleBeeBumbleBee committed Aug 1, 2016
1 parent 861aace commit 7b191bd
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 19 deletions.
21 changes: 13 additions & 8 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -70,7 +70,8 @@
<activity
android:name=".StatusActivity"
android:parentActivityName=".SettingsActivity">
<!--android:theme="@style/Theme.AppCompat.NoActionBar">-->

<!-- android:theme="@style/Theme.AppCompat.NoActionBar"> -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".SettingsActivity" />
Expand All @@ -83,7 +84,7 @@
android:value=".SettingsActivity" />
</activity>

<!-- the service -->
<!-- the services -->
<service
android:name=".service.ScrobblingService"
android:enabled="true"
Expand All @@ -98,6 +99,11 @@
</intent-filter>
</service>

<service
android:name=".service.ForegroundHide"
android:enabled="true"
android:exported="true"></service>

<!-- the receivers -->
<receiver
android:name=".receiver.AndroidMusicReceiver"
Expand Down Expand Up @@ -288,17 +294,16 @@
</receiver>

<!--
- will probably interfere badly with Winamp <receiver android:name="com.adam.aslfms.receiver.LastFmAPIReceiver"
android:exported="true" android:enabled="true"> <intent-filter> <action android:name="fm.last.android.metachanged"
/> <action android:name="fm.last.android.playbackpaused" /> <action android:name="fm.last.android.playbackcomplete"
- will probably interfere badly with Winamp <receiver android:name="com.adam.aslfms.receiver.LastFmAPIReceiver"
android:exported="true" android:enabled="true"> <intent-filter> <action android:name="fm.last.android.metachanged"
/> <action android:name="fm.last.android.playbackpaused" /> <action android:name="fm.last.android.playbackcomplete"
/> </intent-filter> </receiver>
-->

<receiver
android:name="com.adam.aslfms.util.ConnectivityChangeReceiver">
<receiver android:name=".util.ConnectivityChangeReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.STATE_CHANGE"/>
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>

Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/adam/aslfms/OptionsActivity.java
Expand Up @@ -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;
Expand All @@ -161,7 +161,7 @@ public PowerSpecificPrefs(PowerOptions power,

public void create() {
createChooserPreference();
//createNotifyPreference();
createNotifyPreference();
createScrobbleEnablePreference();
createNPEnablePreference();
createWhenPreference();
Expand All @@ -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) {
Expand All @@ -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));

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions app/src/main/java/com/adam/aslfms/service/ForegroundHide.java
@@ -0,0 +1,65 @@
/**
* This file is part of Simple Last.fm Scrobbler.
* <p/>
* https://github.com/tgwizard/sls
* <p/>
* Copyright 2011 Simple Last.fm Scrobbler Team
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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;
}
}
38 changes: 35 additions & 3 deletions app/src/main/java/com/adam/aslfms/service/ScrobblingService.java
Expand Up @@ -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
Expand All @@ -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 = "";
Expand All @@ -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;
}

Expand All @@ -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 {
Expand Down

0 comments on commit 7b191bd

Please sign in to comment.