From dfab60c2eb27b7514183baceaac94f1dcbe5bc5c Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Mon, 8 Oct 2012 13:05:15 -0700 Subject: [PATCH] add 4 layout sizes for the app widget --- MyTracks/res/layout/track_widget_4x1.xml | 96 +++++++ ..._widget_large.xml => track_widget_4x2.xml} | 102 ++++--- MyTracks/res/layout/track_widget_4x3.xml | 148 +++++++++++ MyTracks/res/layout/track_widget_4x4.xml | 156 +++++++++++ MyTracks/res/layout/track_widget_small.xml | 86 ------ MyTracks/res/values/styles.xml | 249 ++++++++++++------ MyTracks/res/xml/track_widget_info.xml | 2 +- .../mytracks/widgets/TrackWidgetProvider.java | 67 +++-- 8 files changed, 680 insertions(+), 226 deletions(-) create mode 100644 MyTracks/res/layout/track_widget_4x1.xml rename MyTracks/res/layout/{track_widget_large.xml => track_widget_4x2.xml} (58%) create mode 100644 MyTracks/res/layout/track_widget_4x3.xml create mode 100644 MyTracks/res/layout/track_widget_4x4.xml delete mode 100644 MyTracks/res/layout/track_widget_small.xml diff --git a/MyTracks/res/layout/track_widget_4x1.xml b/MyTracks/res/layout/track_widget_4x1.xml new file mode 100644 index 000000000..feb9b85bb --- /dev/null +++ b/MyTracks/res/layout/track_widget_4x1.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyTracks/res/layout/track_widget_large.xml b/MyTracks/res/layout/track_widget_4x2.xml similarity index 58% rename from MyTracks/res/layout/track_widget_large.xml rename to MyTracks/res/layout/track_widget_4x2.xml index 9927051be..9a0dcaea2 100644 --- a/MyTracks/res/layout/track_widget_large.xml +++ b/MyTracks/res/layout/track_widget_4x2.xml @@ -1,6 +1,6 @@ + style="@style/TrackWidgetBoundingBox" > + android:baselineAligned="false" + style="@style/TrackWidgetFrame" > - + style="@style/TrackWidgetStatsContainer" > + - + @@ -49,12 +40,18 @@ limitations under the License. - - - + + + - + @@ -69,10 +66,22 @@ limitations under the License. - - + + + + + + - + @@ -86,12 +95,18 @@ limitations under the License. - - - + + + - + @@ -106,31 +121,32 @@ limitations under the License. - - + + + style="@style/TrackWidgetButtonRecord" /> - + style="@style/TrackWidgetButtonStop" /> + - + \ No newline at end of file diff --git a/MyTracks/res/layout/track_widget_4x3.xml b/MyTracks/res/layout/track_widget_4x3.xml new file mode 100644 index 000000000..4061c5f24 --- /dev/null +++ b/MyTracks/res/layout/track_widget_4x3.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyTracks/res/layout/track_widget_4x4.xml b/MyTracks/res/layout/track_widget_4x4.xml new file mode 100644 index 000000000..1aa48114c --- /dev/null +++ b/MyTracks/res/layout/track_widget_4x4.xml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyTracks/res/layout/track_widget_small.xml b/MyTracks/res/layout/track_widget_small.xml deleted file mode 100644 index bb09a15e8..000000000 --- a/MyTracks/res/layout/track_widget_small.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MyTracks/res/values/styles.xml b/MyTracks/res/values/styles.xml index f0517e8bc..2eb104fd8 100644 --- a/MyTracks/res/values/styles.xml +++ b/MyTracks/res/values/styles.xml @@ -15,44 +15,44 @@ See the License for the specific language governing permissions and limitations under the License. --> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + - + - + - + - + - + - + - + - + - + - + - - - + - + + + - + + + - + + + + + + + - + - + - - + + - + + + + + - + + + + + + + + + + + + - - - - - + + + - + + + + + - + + + + + - - + + - + + + \ No newline at end of file diff --git a/MyTracks/res/xml/track_widget_info.xml b/MyTracks/res/xml/track_widget_info.xml index ddd60d3ff..33f3feaf0 100644 --- a/MyTracks/res/xml/track_widget_info.xml +++ b/MyTracks/res/xml/track_widget_info.xml @@ -16,7 +16,7 @@ limitations under the License. --> = LARGE_HEIGHT; - useLargeSize.put(appWidgetId, large); - RemoteViews remoteViews = getRemoteViews(context, -1L, large); + int heightSize; + if (newOptions == null) { + heightSize = 2; + } else { + int height = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); + if (height >= FOUR_CELLS) { + heightSize = 4; + } else if (height >= THREE_CELLS) { + heightSize = 3; + } else if (height >= TWO_CELLS) { + heightSize = 2; + } else { + heightSize = 1; + } + } + HEIGHT_SIZE.put(appWidgetId, heightSize); + RemoteViews remoteViews = getRemoteViews(context, -1L, heightSize); appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } @@ -96,7 +113,8 @@ public class TrackWidgetProvider extends AppWidgetProvider { */ public static void updateAppWidget( Context context, AppWidgetManager appWidgetManager, int appWidgetId) { - RemoteViews remoteViews = getRemoteViews(context, -1L, useLargeSize.get(appWidgetId, true)); + RemoteViews remoteViews = getRemoteViews( + context, -1L, HEIGHT_SIZE.get(appWidgetId, DEFAULT_HEIGHT)); appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } @@ -105,11 +123,28 @@ public class TrackWidgetProvider extends AppWidgetProvider { * * @param context the context * @param trackId the track id - * @param large true to use the large layout + * @param heightSize the layout height size */ - private static RemoteViews getRemoteViews(Context context, long trackId, boolean large) { - RemoteViews remoteViews = new RemoteViews(context.getPackageName(), - large ? R.layout.track_widget_large : R.layout.track_widget_small); + private static RemoteViews getRemoteViews(Context context, long trackId, int heightSize) { + int layout; + switch (heightSize) { + case 4: + layout = R.layout.track_widget_4x4; + break; + case 3: + layout = R.layout.track_widget_4x3; + break; + case 2: + layout = R.layout.track_widget_4x2; + break; + case 1: + layout = R.layout.track_widget_4x1; + break; + default: + layout = R.layout.track_widget_4x2; + break; + } + RemoteViews remoteViews = new RemoteViews(context.getPackageName(), layout); // Get the preferences long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key); @@ -142,7 +177,7 @@ public class TrackWidgetProvider extends AppWidgetProvider { updateRecordButton(context, remoteViews, isRecording, recordingTrackPaused); updateStopButton(context, remoteViews, isRecording); - if (large) { + if (heightSize > 1) { int item3 = PreferencesUtils.getInt( context, R.string.track_widget_item3, PreferencesUtils.TRACK_WIDGET_ITEM3_DEFAULT); int item4 = PreferencesUtils.getInt( @@ -214,7 +249,7 @@ public class TrackWidgetProvider extends AppWidgetProvider { TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(context); taskStackBuilder.addNextIntent(intent); PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0); - remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent); + remoteViews.setOnClickPendingIntent(R.id.track_widget_stats_container, pendingIntent); } /**