Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed home screen widgets to show rewind/fast forward correctly #941

Open
wants to merge 1 commit into
base: edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ private void performUpdate(Context context, DownloadService service, int[] appWi
views.setImageViewResource(R.id.control_play, R.drawable.media_start_dark);
}

// Hide and show correct previous/next and rewind/fast forward buttons
if (service != null && service.shouldFastForward()) {
views.setViewVisibility(R.id.control_previous, View.GONE);
views.setViewVisibility(R.id.control_next, View.GONE);
views.setViewVisibility(R.id.control_rewind, View.VISIBLE);
views.setViewVisibility(R.id.control_fastforward, View.VISIBLE);
} else {
views.setViewVisibility(R.id.control_previous, View.VISIBLE);
views.setViewVisibility(R.id.control_next, View.VISIBLE);
views.setViewVisibility(R.id.control_rewind, View.GONE);
views.setViewVisibility(R.id.control_fastforward, View.GONE);
}

// Set the cover art
try {
boolean large = false;
Expand Down Expand Up @@ -301,5 +314,17 @@ private void linkButtons(Context context, RemoteViews views, boolean playerActiv
intent.setAction(DownloadService.CMD_PREVIOUS);
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);

intent = new Intent("DSub.REWIND"); // Use a unique action name to ensure a different PendingIntent to be created.
intent.setComponent(new ComponentName(context, DownloadService.class));
intent.setAction(DownloadService.CMD_REWIND);
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.control_rewind, pendingIntent);

intent = new Intent("DSub.FASTFORWARD"); // Use a unique action name to ensure a different PendingIntent to be created.
intent.setComponent(new ComponentName(context, DownloadService.class));
intent.setAction(DownloadService.CMD_FASTFORWARD);
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.control_fastforward, pendingIntent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class DownloadService extends Service {
public static final String CMD_STOP = "github.daneren2005.dsub.CMD_STOP";
public static final String CMD_PREVIOUS = "github.daneren2005.dsub.CMD_PREVIOUS";
public static final String CMD_NEXT = "github.daneren2005.dsub.CMD_NEXT";
public static final String CMD_REWIND = "github.daneren2005.dsub.CMD_REWIND";
public static final String CMD_FASTFORWARD = "github.daneren2005.dsub.CMD_FASTFORWARD";
public static final String CANCEL_DOWNLOADS = "github.daneren2005.dsub.CANCEL_DOWNLOADS";
public static final String START_PLAY = "github.daneren2005.dsub.START_PLAYING";
private static final long DEFAULT_DELAY_UPDATE_PROGRESS = 1000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public void run() {
downloadService.next();
} else if (DownloadService.CMD_PREVIOUS.equals(action)) {
downloadService.previous();
} else if (DownloadService.CMD_FASTFORWARD.equals(action)) {
downloadService.fastForward();
} else if (DownloadService.CMD_REWIND.equals(action)) {
downloadService.rewind();
} else if (DownloadService.CMD_TOGGLEPAUSE.equals(action)) {
downloadService.togglePlayPause();
} else if (DownloadService.CMD_PAUSE.equals(action)) {
Expand Down Expand Up @@ -170,6 +174,8 @@ public void onReceive(Context context, Intent intent) {
commandFilter.addAction(DownloadService.CMD_STOP);
commandFilter.addAction(DownloadService.CMD_PREVIOUS);
commandFilter.addAction(DownloadService.CMD_NEXT);
commandFilter.addAction(DownloadService.CMD_REWIND);
commandFilter.addAction(DownloadService.CMD_FASTFORWARD);
commandFilter.addAction(DownloadService.CANCEL_DOWNLOADS);
downloadService.registerReceiver(intentReceiver, commandFilter);

Expand Down Expand Up @@ -241,6 +247,10 @@ public void run() {
downloadService.next();
} else if(DownloadService.CMD_PREVIOUS.equals(action)) {
downloadService.previous();
} else if(DownloadService.CMD_REWIND.equals(action)) {
downloadService.rewind();
} else if(DownloadService.CMD_FASTFORWARD.equals(action)) {
downloadService.fastForward();
} else if(DownloadService.CANCEL_DOWNLOADS.equals(action)) {
downloadService.clearBackground();
} else if(intent.getExtras() != null) {
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/appwidget4x1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@
android:layout_height="fill_parent"
android:orientation="horizontal">

<ImageButton
android:id="@+id/control_rewind"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_rewind_dark"
android:visibility="gone" />

<ImageButton
android:id="@+id/control_previous"
android:layout_width="0dip"
Expand All @@ -104,6 +113,15 @@
android:layout_weight="1"
android:src="@drawable/media_forward_dark"
style="@style/NotificationButton" />

<ImageButton
android:id="@+id/control_fastforward"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_fastforward_dark"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>

Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/appwidget4x2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@
android:paddingBottom="4dip"
android:paddingTop="4dip" >

<ImageButton
android:id="@+id/control_rewind"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_rewind_dark"
android:visibility="gone" />

<ImageButton
android:id="@+id/control_previous"
android:layout_width="0dip"
Expand All @@ -130,6 +139,15 @@
android:layout_weight="1"
android:src="@drawable/media_forward_dark"
style="@style/NotificationButton" />

<ImageButton
android:id="@+id/control_fastforward"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_fastforward_dark"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>

Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/appwidget4x3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
android:orientation="horizontal"
android:paddingBottom="4dip">

<ImageButton
android:id="@+id/control_rewind"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_rewind_dark"
android:visibility="gone" />

<ImageButton
android:id="@+id/control_previous"
android:layout_width="0dip"
Expand All @@ -112,6 +121,15 @@
android:layout_weight="1"
android:src="@drawable/media_forward_dark"
style="@style/NotificationButton" />

<ImageButton
android:id="@+id/control_fastforward"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_fastforward_dark"
android:visibility="gone" />
</LinearLayout>

</LinearLayout>
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/res/layout/appwidget4x4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
<LinearLayout
android:id="@+id/appwidget_top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -91,6 +91,15 @@
android:paddingBottom="4dip"
android:paddingTop="4dip" >

<ImageButton
android:id="@+id/control_rewind"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_rewind_dark"
android:visibility="gone" />

<ImageButton
android:id="@+id/control_previous"
android:layout_width="0dip"
Expand All @@ -114,6 +123,15 @@
android:layout_weight="1"
android:src="@drawable/media_forward_dark"
style="@style/NotificationButton" />

<ImageButton
android:id="@+id/control_fastforward"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
style="@style/NotificationButton"
android:src="@drawable/media_fastforward_dark"
android:visibility="gone" />
</LinearLayout>

</LinearLayout>
Expand Down