aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/layout/appwidget4x1.xml3
-rw-r--r--res/layout/appwidget4x2.xml3
-rw-r--r--res/layout/appwidget4x3.xml3
-rw-r--r--res/layout/appwidget4x4.xml3
-rw-r--r--res/values/strings.xml2
-rw-r--r--res/xml/settings.xml6
-rw-r--r--src/github/daneren2005/dsub/provider/DSubWidgetProvider.java27
7 files changed, 29 insertions, 18 deletions
diff --git a/res/layout/appwidget4x1.xml b/res/layout/appwidget4x1.xml
index 5e55aa37..68fecb9a 100644
--- a/res/layout/appwidget4x1.xml
+++ b/res/layout/appwidget4x1.xml
@@ -5,7 +5,8 @@
android:minWidth="250dp"
android:minHeight="40dp"
android:background="@drawable/appwidget_bg"
- android:orientation="horizontal" >
+ android:orientation="horizontal"
+ android:id="@+id/widget_root">
<ImageView
android:id="@+id/appwidget_coverart"
diff --git a/res/layout/appwidget4x2.xml b/res/layout/appwidget4x2.xml
index 575ae1c2..8409bbbf 100644
--- a/res/layout/appwidget4x2.xml
+++ b/res/layout/appwidget4x2.xml
@@ -5,7 +5,8 @@
android:minWidth="250dp"
android:minHeight="110dp"
android:background="@drawable/appwidget_bg"
- android:orientation="horizontal" >
+ android:orientation="horizontal"
+ android:id="@+id/widget_root">
<ImageView
android:id="@+id/appwidget_coverart"
diff --git a/res/layout/appwidget4x3.xml b/res/layout/appwidget4x3.xml
index b4f685bc..e72a266d 100644
--- a/res/layout/appwidget4x3.xml
+++ b/res/layout/appwidget4x3.xml
@@ -3,7 +3,8 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/appwidget_bg"
- android:orientation="vertical" >
+ android:orientation="vertical"
+ android:id="@+id/widget_root">
<ImageView
android:id="@+id/appwidget_coverart"
diff --git a/res/layout/appwidget4x4.xml b/res/layout/appwidget4x4.xml
index 6e6c12ab..c885829b 100644
--- a/res/layout/appwidget4x4.xml
+++ b/res/layout/appwidget4x4.xml
@@ -3,7 +3,8 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
- android:background="@drawable/appwidget_bg" >
+ android:background="@drawable/appwidget_bg"
+ android:id="@+id/widget_root">
<ImageView
android:id="@+id/appwidget_coverart"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5702271a..3721109e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -331,6 +331,8 @@
<string name="settings.video_flash">Flash (Requires Plugin)</string>
<string name="settings.cache_screen_title">Cache/Network</string>
<string name="settings.playback_title">Playback</string>
+ <string name="settings.hide_widget_title">Hide Widget</string>
+ <string name="settings.hide_widget_summary">Hide widget after exiting app</string>
<string name="shuffle.title">Shuffle By</string>
<string name="shuffle.startYear">Start Year:</string>
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index bbfbf620..8f6759c0 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -37,6 +37,12 @@
android:key="displayTrack"
android:defaultValue="false"/>
+ <CheckBoxPreference
+ android:title="@string/settings.hide_widget_title"
+ android:summary="@string/settings.hide_widget_summary"
+ android:key="hideWidget"
+ android:defaultValue="false"/>
+
</PreferenceCategory>
<PreferenceCategory
diff --git a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
index f8023712..f0c7f9fb 100644
--- a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
+++ b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java
@@ -37,6 +37,7 @@ import android.graphics.RectF;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.View;
import android.widget.RemoteViews;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.DownloadActivity;
@@ -46,6 +47,8 @@ import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.DownloadServiceImpl;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.Util;
+
import java.util.HashMap;
/**
@@ -62,7 +65,6 @@ public class DSubWidgetProvider extends AppWidgetProvider {
private static DSubWidget4x2 instance4x2;
private static DSubWidget4x3 instance4x3;
private static DSubWidget4x4 instance4x4;
- private boolean hidden = false;
public static synchronized void notifyInstances(Context context, DownloadService service, boolean playing) {
if(instance4x1 == null) {
@@ -105,13 +107,6 @@ public class DSubWidgetProvider extends AppWidgetProvider {
if(getLayout() == R.layout.appwidget4x2) {
views.setTextViewText(R.id.album, "");
}
-
- // Hide widget
- SharedPreferences prefs = Util.getPreferences(context);
- if(prefs.getBoolean(Constants.PREFERENCES_KEY_HIDE_WIDGET, false)) {
- views.setViewVisibility(0, View.GONE);
- hidden = true;
- }
linkButtons(context, views, false);
pushUpdate(context, appWidgetIds, views);
@@ -151,12 +146,16 @@ public class DSubWidgetProvider extends AppWidgetProvider {
private void performUpdate(Context context, DownloadService service, int[] appWidgetIds, boolean playing) {
final Resources res = context.getResources();
final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout());
-
- // Make sure widget is visible
- if(hidden) {
- views.setViewVisibility(0, View.VISIBLE);
- hidden = false;
- }
+
+ if(playing) {
+ views.setViewVisibility(R.id.widget_root, View.VISIBLE);
+ } else {
+ // Hide widget
+ SharedPreferences prefs = Util.getPreferences(context);
+ if(prefs.getBoolean(Constants.PREFERENCES_KEY_HIDE_WIDGET, false)) {
+ views.setViewVisibility(R.id.widget_root, View.GONE);
+ }
+ }
MusicDirectory.Entry currentPlaying = service.getCurrentPlaying() == null ? null : service.getCurrentPlaying().getSong();
String title = currentPlaying == null ? null : currentPlaying.getTitle();