Make widget double tap setting global

This commit is contained in:
Christopher Eby 2011-09-03 19:05:08 -05:00
parent 4abbbfd6f3
commit b8c137310a
7 changed files with 33 additions and 168 deletions

View File

@ -60,13 +60,6 @@ THE SOFTWARE.
android:name="android.appwidget.provider"
android:resource="@xml/one_cell_widget" />
</receiver>
<activity
android:name=".OneCellWidgetConfigure"
android:theme="@android:style/Theme.Dialog">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<receiver
android:name=".FourLongWidget"
android:label="Vanilla Music 1x4">

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/double_tap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/double_tap_widget" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:background="#fff" >
<Button android:id="@+id/place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/place_widget"
android:singleLine="true" />
</FrameLayout>
</LinearLayout>

View File

@ -41,8 +41,6 @@ THE SOFTWARE.
<!-- Widgets -->
<string name="starting">Starting up...</string>
<string name="place_widget">Place Widget</string>
<string name="double_tap_widget">Double tap widget to open player (reduces responsiveness)</string>
<!-- New Playlist Dialog -->
<string name="choose_playlist_name">Choose Playlist Name</string>
@ -138,6 +136,8 @@ THE SOFTWARE.
<string name="use_idle_timeout_summary">When active, playback will be stopped after the given period of inactivity</string>
<string name="idle_timeout_title">Idle Timeout</string>
<string name="idle_timeout_summary">The amount of time that must pass before becoming idle</string>
<string name="double_tap_title">Double Tap Widget</string>
<string name="double_tap_summary">Double-tapping the 1x1 widget will open the player. Incurs a 400ms delay before the widget responds to actions.</string>
<string name="scrobble_title">Use ScrobbleDroid API</string>
<string name="scrobble_summary">Scrobble to Last.FM through ScrobbleDroid or Simple Last.FM Scrobbler</string>
</resources>

View File

@ -3,6 +3,5 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="72dip"
android:minHeight="72dip"
android:configure="org.kreed.vanilla.OneCellWidgetConfigure"
android:initialLayout="@layout/one_cell_widget"
/>
/>

View File

@ -118,6 +118,11 @@ THE SOFTWARE.
android:title="@string/idle_timeout_title"
android:summary="@string/idle_timeout_summary"
android:dependency="use_idle_timeout" />
<CheckBoxPreference
android:key="double_tap"
android:title="@string/double_tap_title"
android:summary="@string/double_tap_summary"
android:defaultValue="false" />
<CheckBoxPreference
android:key="scrobble"
android:title="@string/scrobble_title"

View File

@ -101,35 +101,33 @@ public class OneCellWidget extends AppWidgetProvider {
if (ids == null || ids.length == 0)
return;
for (int i = ids.length; --i != -1; ) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
boolean doubleTap = settings.getBoolean("double_tap_" + ids[i], false);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
boolean doubleTap = settings.getBoolean("double_tap", false);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.one_cell_widget);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.one_cell_widget);
if (state != -1) {
boolean playing = (state & PlaybackService.FLAG_PLAYING) != 0;
views.setImageViewResource(R.id.play_pause, playing ? R.drawable.hidden_pause : R.drawable.hidden_play);
}
ComponentName service = new ComponentName(context, PlaybackService.class);
Intent playPause = new Intent(doubleTap ? PlaybackService.ACTION_TOGGLE_PLAYBACK_DELAYED : PlaybackService.ACTION_TOGGLE_PLAYBACK);
playPause.setComponent(service);
views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(context, 0, playPause, 0));
Intent next = new Intent(doubleTap ? PlaybackService.ACTION_NEXT_SONG_DELAYED : PlaybackService.ACTION_NEXT_SONG);
next.setComponent(service);
views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(context, 0, next, 0));
if (song == null) {
views.setImageViewResource(R.id.cover_view, R.drawable.icon);
} else {
int size = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 72, context.getResources().getDisplayMetrics());
views.setImageViewBitmap(R.id.cover_view, CoverBitmap.createCompactBitmap(song, size, size));
}
manager.updateAppWidget(ids[i], views);
if (state != -1) {
boolean playing = (state & PlaybackService.FLAG_PLAYING) != 0;
views.setImageViewResource(R.id.play_pause, playing ? R.drawable.hidden_pause : R.drawable.hidden_play);
}
ComponentName service = new ComponentName(context, PlaybackService.class);
Intent playPause = new Intent(doubleTap ? PlaybackService.ACTION_TOGGLE_PLAYBACK_DELAYED : PlaybackService.ACTION_TOGGLE_PLAYBACK);
playPause.setComponent(service);
views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(context, 0, playPause, 0));
Intent next = new Intent(doubleTap ? PlaybackService.ACTION_NEXT_SONG_DELAYED : PlaybackService.ACTION_NEXT_SONG);
next.setComponent(service);
views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(context, 0, next, 0));
if (song == null) {
views.setImageViewResource(R.id.cover_view, R.drawable.icon);
} else {
int size = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 72, context.getResources().getDisplayMetrics());
views.setImageViewBitmap(R.id.cover_view, CoverBitmap.createCompactBitmap(song, size, size));
}
manager.updateAppWidget(ids, views);
}
}

View File

@ -1,86 +0,0 @@
/*
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.kreed.vanilla;
import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
/**
* A configuration dialog for the OneCellWidget. Displays the double tap
* preference.
*/
public class OneCellWidgetConfigure extends Activity implements OnClickListener {
/**
* The id of the widget we are configuring.
*/
private int mAppWidgetId;
/**
* The check box for the double-tap-opens-players preference.
*/
private CheckBox mDoubleTap;
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setResult(RESULT_CANCELED);
setContentView(R.layout.one_cell_widget_configure);
mDoubleTap = (CheckBox)findViewById(R.id.double_tap);
findViewById(R.id.place).setOnClickListener(this);
Bundle extras = getIntent().getExtras();
if (extras != null)
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
finish();
}
public void onClick(View view)
{
boolean doubleTap = mDoubleTap.isChecked();
// save the setting
SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
prefs.putBoolean("double_tap_" + mAppWidgetId, doubleTap);
prefs.commit();
AppWidgetManager manager = AppWidgetManager.getInstance(this);
new OneCellWidget().onUpdate(this, manager, new int[] { mAppWidgetId });
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
}