diff options
author | Jan-Felix Schmakeit <jfschmakeit@google.com> | 2014-09-26 14:04:31 +1000 |
---|---|---|
committer | Jan-Felix Schmakeit <jfschmakeit@google.com> | 2015-01-07 18:07:57 +1100 |
commit | 2989852bd9ad63395a956a3221ecac4c2fd55271 (patch) | |
tree | dbd2262e395ba1826574d2e27ac916650191a416 | |
parent | 5c90c5c48a831b569dbc5d181479e143f9966723 (diff) | |
download | android-2989852bd9ad63395a956a3221ecac4c2fd55271.tar.gz |
Port legacy "WeartherListWidget" to template system.
Change-Id: I638d5a1fc0a93946fee6e16e1ca989f01a7b2aa9
37 files changed, 1694 insertions, 0 deletions
diff --git a/content/WidgetData/Application/.gitignore b/content/WidgetData/Application/.gitignore new file mode 100644 index 00000000..6eb878d4 --- /dev/null +++ b/content/WidgetData/Application/.gitignore @@ -0,0 +1,16 @@ +# Copyright 2013 The Android Open Source Project +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. +src/template/ +src/common/ +build.gradle diff --git a/content/WidgetData/Application/README-fragmentview.txt b/content/WidgetData/Application/README-fragmentview.txt new file mode 100644 index 00000000..38d903f0 --- /dev/null +++ b/content/WidgetData/Application/README-fragmentview.txt @@ -0,0 +1,37 @@ +<!-- + Copyright 2013 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> + +Steps to implement FragmentView template: +-in template-params.xml.ftl: + -add the following line to common imports + <common src="activities"/> + +-Add a Fragment to show behavior. In your MainActivity.java class, it will reference a Fragment + called (yourProjectName)Fragment.java. Create that file in your project, using the "main" source + folder instead of "common" or "templates". + For instance, if your package name is com.example.foo, create the file + src/main/java/com/example/foo/FooFragment.java + + +-Within this fragment, make sure that the onCreate method has the line + "setHasOptionsMenu(true);", to enable the fragment to handle menu events. + +-In order to override menu events, override onOptionsItemSelected. + +-refer to sampleSamples/fragmentViewSample for a reference implementation of a +project built on this template. + + diff --git a/content/WidgetData/Application/proguard-project.txt b/content/WidgetData/Application/proguard-project.txt new file mode 100644 index 00000000..0d8f171d --- /dev/null +++ b/content/WidgetData/Application/proguard-project.txt @@ -0,0 +1,20 @@ + To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/content/WidgetData/Application/src/main/AndroidManifest.xml b/content/WidgetData/Application/src/main/AndroidManifest.xml new file mode 100644 index 00000000..1c5fb745 --- /dev/null +++ b/content/WidgetData/Application/src/main/AndroidManifest.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2013 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.widgetdata" + android:versionCode="1" + android:versionName="1.0"> + + <uses-sdk android:minSdkVersion="4" + android:targetSdkVersion="20" /> + + <application android:allowBackup="true" + android:label="@string/app_name" + android:icon="@drawable/ic_launcher" + android:theme="@style/AppTheme"> + + <!-- The widget provider --> + <receiver android:name="WeatherWidgetProvider"> + <intent-filter> + <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> + </intent-filter> + <!-- This specifies the widget provider info --> + <meta-data android:name="android.appwidget.provider" + android:resource="@xml/widgetinfo" /> + </receiver> + + <!-- The service serving the RemoteViews to the collection widget --> + <service android:name="WeatherWidgetService" + android:permission="android.permission.BIND_REMOTEVIEWS" + android:exported="false" /> + + <!-- The content provider serving the (fake) weather data --> + <provider android:name="WeatherDataProvider" + android:authorities="com.example.android.widgetdata.provider" android:exported="true" /> + + <activity android:name=".MainActivity" + android:label="@string/app_name"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + + +</manifest> diff --git a/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherDataProvider.java b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherDataProvider.java new file mode 100644 index 00000000..2508f014 --- /dev/null +++ b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherDataProvider.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.example.android.widgetdata; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.net.Uri; + +import java.util.ArrayList; + +/** + * A dummy class that we are going to use internally to store weather data. Generally, this data + * will be stored in an external and persistent location (ie. File, Database, SharedPreferences) so + * that the data can persist if the process is ever killed. For simplicity, in this sample the + * data will only be stored in memory. + */ +class WeatherDataPoint { + String day; + int degrees; + + WeatherDataPoint(String d, int deg) { + day = d; + degrees = deg; + } +} + +/** + * The AppWidgetProvider for our sample weather widget. + */ +public class WeatherDataProvider extends ContentProvider { + public static final Uri CONTENT_URI = + Uri.parse("content://com.example.android.widgetdata.provider"); + public static class Columns { + public static final String ID = "_id"; + public static final String DAY = "day"; + public static final String TEMPERATURE = "temperature"; + } + + /** + * Generally, this data will be stored in an external and persistent location (ie. File, + * Database, SharedPreferences) so that the data can persist if the process is ever killed. + * For simplicity, in this sample the data will only be stored in memory. + */ + private static final ArrayList<WeatherDataPoint> sData = new ArrayList<WeatherDataPoint>(); + + @Override + public boolean onCreate() { + // We are going to initialize the data provider with some default values + sData.add(new WeatherDataPoint("Monday", 13)); + sData.add(new WeatherDataPoint("Tuesday", 1)); + sData.add(new WeatherDataPoint("Wednesday", 7)); + sData.add(new WeatherDataPoint("Thursday", 4)); + sData.add(new WeatherDataPoint("Friday", 22)); + sData.add(new WeatherDataPoint("Saturday", -10)); + sData.add(new WeatherDataPoint("Sunday", -13)); + sData.add(new WeatherDataPoint("Monday", 8)); + sData.add(new WeatherDataPoint("Tuesday", 11)); + sData.add(new WeatherDataPoint("Wednesday", -1)); + sData.add(new WeatherDataPoint("Thursday", 27)); + sData.add(new WeatherDataPoint("Friday", 27)); + sData.add(new WeatherDataPoint("Saturday", 27)); + sData.add(new WeatherDataPoint("Sunday", 27)); + return true; + } + + @Override + public synchronized Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + assert(uri.getPathSegments().isEmpty()); + + // In this sample, we only query without any parameters, so we can just return a cursor to + // all the weather data. + final MatrixCursor c = new MatrixCursor( + new String[]{ Columns.ID, Columns.DAY, Columns.TEMPERATURE }); + for (int i = 0; i < sData.size(); ++i) { + final WeatherDataPoint data = sData.get(i); + c.addRow(new Object[]{ new Integer(i), data.day, new Integer(data.degrees) }); + } + return c; + } + + @Override + public String getType(Uri uri) { + return "vnd.android.cursor.dir/vnd.widgetdata.temperature"; + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + // This example code does not support inserting + return null; + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + // This example code does not support deleting + return 0; + } + + @Override + public synchronized int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + assert(uri.getPathSegments().size() == 1); + + // In this sample, we only update the content provider individually for each row with new + // temperature values. + final int index = Integer.parseInt(uri.getPathSegments().get(0)); + final MatrixCursor c = new MatrixCursor( + new String[]{ Columns.ID, Columns.DAY, Columns.TEMPERATURE }); + assert(0 <= index && index < sData.size()); + final WeatherDataPoint data = sData.get(index); + data.degrees = values.getAsInteger(Columns.TEMPERATURE); + + // Notify any listeners that the data backing the content provider has changed, and return + // the number of rows affected. + getContext().getContentResolver().notifyChange(uri, null); + return 1; + } + +} diff --git a/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherWidgetProvider.java b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherWidgetProvider.java new file mode 100644 index 00000000..cd801488 --- /dev/null +++ b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherWidgetProvider.java @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.example.android.widgetdata; + +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; +import android.content.Context; +import android.content.Intent; +import android.content.ComponentName; +import android.content.ContentValues; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.database.Cursor; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.HandlerThread; +import android.widget.RemoteViews; +import android.widget.Toast; + +import java.util.Random; + +/** + * Our data observer just notifies an update for all weather widgets when it detects a change. + */ +class WeatherDataProviderObserver extends ContentObserver { + private AppWidgetManager mAppWidgetManager; + private ComponentName mComponentName; + + WeatherDataProviderObserver(AppWidgetManager mgr, ComponentName cn, Handler h) { + super(h); + mAppWidgetManager = mgr; + mComponentName = cn; + } + + @Override + public void onChange(boolean selfChange) { + // The data has changed, so notify the widget that the collection view needs to be updated. + // In response, the factory's onDataSetChanged() will be called which will requery the + // cursor for the new data. + mAppWidgetManager.notifyAppWidgetViewDataChanged( + mAppWidgetManager.getAppWidgetIds(mComponentName), R.id.weather_list); + } +} + +/** + * The weather widget's AppWidgetProvider. + */ +public class WeatherWidgetProvider extends AppWidgetProvider { + public static String CLICK_ACTION = "com.example.android.widgetdata.CLICK"; + public static String REFRESH_ACTION = "com.example.android.widgetdata.REFRESH"; + public static String EXTRA_DAY_ID = "com.example.android.widgetdata.day"; + + private static HandlerThread sWorkerThread; + private static Handler sWorkerQueue; + private static WeatherDataProviderObserver sDataObserver; + private static final int sMaxDegrees = 96; + + private boolean mIsLargeLayout = true; + private int mHeaderWeatherState = 0; + + public WeatherWidgetProvider() { + // Start the worker thread + sWorkerThread = new HandlerThread("WeatherWidgetProvider-worker"); + sWorkerThread.start(); + sWorkerQueue = new Handler(sWorkerThread.getLooper()); + } + + // XXX: clear the worker queue if we are destroyed? + + @Override + public void onEnabled(Context context) { + // Register for external updates to the data to trigger an update of the widget. When using + // content providers, the data is often updated via a background service, or in response to + // user interaction in the main app. To ensure that the widget always reflects the current + // state of the data, we must listen for changes and update ourselves accordingly. + final ContentResolver r = context.getContentResolver(); + if (sDataObserver == null) { + final AppWidgetManager mgr = AppWidgetManager.getInstance(context); + final ComponentName cn = new ComponentName(context, WeatherWidgetProvider.class); + sDataObserver = new WeatherDataProviderObserver(mgr, cn, sWorkerQueue); + r.registerContentObserver(WeatherDataProvider.CONTENT_URI, true, sDataObserver); + } + } + + @Override + public void onReceive(Context ctx, Intent intent) { + final String action = intent.getAction(); + if (action.equals(REFRESH_ACTION)) { + // BroadcastReceivers have a limited amount of time to do work, so for this sample, we + // are triggering an update of the data on another thread. In practice, this update + // can be triggered from a background service, or perhaps as a result of user actions + // inside the main application. + final Context context = ctx; + sWorkerQueue.removeMessages(0); + sWorkerQueue.post(new Runnable() { + @Override + public void run() { + final ContentResolver r = context.getContentResolver(); + final Cursor c = r.query(WeatherDataProvider.CONTENT_URI, null, null, null, + null); + final int count = c.getCount(); + + // We disable the data changed observer temporarily since each of the updates + // will trigger an onChange() in our data observer. + r.unregisterContentObserver(sDataObserver); + for (int i = 0; i < count; ++i) { + final Uri uri = ContentUris.withAppendedId(WeatherDataProvider.CONTENT_URI, i); + final ContentValues values = new ContentValues(); + values.put(WeatherDataProvider.Columns.TEMPERATURE, + new Random().nextInt(sMaxDegrees)); + r.update(uri, values, null, null); + } + r.registerContentObserver(WeatherDataProvider.CONTENT_URI, true, sDataObserver); + + final AppWidgetManager mgr = AppWidgetManager.getInstance(context); + final ComponentName cn = new ComponentName(context, WeatherWidgetProvider.class); + mgr.notifyAppWidgetViewDataChanged(mgr.getAppWidgetIds(cn), R.id.weather_list); + } + }); + + final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + } else if (action.equals(CLICK_ACTION)) { + // Show a toast + final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + final String day = intent.getStringExtra(EXTRA_DAY_ID); + final String formatStr = ctx.getResources().getString(R.string.toast_format_string); + Toast.makeText(ctx, String.format(formatStr, day), Toast.LENGTH_SHORT).show(); + } + + super.onReceive(ctx, intent); + } + + private RemoteViews buildLayout(Context context, int appWidgetId, boolean largeLayout) { + RemoteViews rv; + if (largeLayout) { + // Specify the service to provide data for the collection widget. Note that we need to + // embed the appWidgetId via the data otherwise it will be ignored. + final Intent intent = new Intent(context, WeatherWidgetService.class); + intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); + rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout); + rv.setRemoteAdapter(appWidgetId, R.id.weather_list, intent); + + // Set the empty view to be displayed if the collection is empty. It must be a sibling + // view of the collection view. + rv.setEmptyView(R.id.weather_list, R.id.empty_view); + + // Bind a click listener template for the contents of the weather list. Note that we + // need to update the intent's data if we set an extra, since the extras will be + // ignored otherwise. + final Intent onClickIntent = new Intent(context, WeatherWidgetProvider.class); + onClickIntent.setAction(WeatherWidgetProvider.CLICK_ACTION); + onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); + final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0, + onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); + rv.setPendingIntentTemplate(R.id.weather_list, onClickPendingIntent); + + // Bind the click intent for the refresh button on the widget + final Intent refreshIntent = new Intent(context, WeatherWidgetProvider.class); + refreshIntent.setAction(WeatherWidgetProvider.REFRESH_ACTION); + final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, + refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT); + rv.setOnClickPendingIntent(R.id.refresh, refreshPendingIntent); + + // Restore the minimal header + rv.setTextViewText(R.id.city_name, context.getString(R.string.city_name)); + } else { + rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout_small); + + // Update the header to reflect the weather for "today" + Cursor c = context.getContentResolver().query(WeatherDataProvider.CONTENT_URI, null, + null, null, null); + if (c.moveToPosition(0)) { + int tempColIndex = c.getColumnIndex(WeatherDataProvider.Columns.TEMPERATURE); + int temp = c.getInt(tempColIndex); + String formatStr = context.getResources().getString(R.string.header_format_string); + String header = String.format(formatStr, temp, + context.getString(R.string.city_name)); + rv.setTextViewText(R.id.city_name, header); + } + c.close(); + } + return rv; + } + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + // Update each of the widgets with the remote adapter + for (int i = 0; i < appWidgetIds.length; ++i) { + RemoteViews layout = buildLayout(context, appWidgetIds[i], mIsLargeLayout); + appWidgetManager.updateAppWidget(appWidgetIds[i], layout); + } + super.onUpdate(context, appWidgetManager, appWidgetIds); + } + + @Override + public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, + int appWidgetId, Bundle newOptions) { + + int minWidth = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); + int maxWidth = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH); + int minHeight = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); + int maxHeight = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT); + + RemoteViews layout; + if (minHeight < 100) { + mIsLargeLayout = false; + } else { + mIsLargeLayout = true; + } + layout = buildLayout(context, appWidgetId, mIsLargeLayout); + appWidgetManager.updateAppWidget(appWidgetId, layout); + } +} diff --git a/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherWidgetService.java b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherWidgetService.java new file mode 100644 index 00000000..b88eb5fe --- /dev/null +++ b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WeatherWidgetService.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.example.android.widgetdata; + +import android.appwidget.AppWidgetManager; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.widget.RemoteViews; +import android.widget.RemoteViewsService; + +/** + * This is the service that provides the factory to be bound to the collection service. + */ +public class WeatherWidgetService extends RemoteViewsService { + @Override + public RemoteViewsFactory onGetViewFactory(Intent intent) { + return new StackRemoteViewsFactory(this.getApplicationContext(), intent); + } +} + +/** + * This is the factory that will provide data to the collection widget. + */ +class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory { + private Context mContext; + private Cursor mCursor; + private int mAppWidgetId; + + public StackRemoteViewsFactory(Context context, Intent intent) { + mContext = context; + mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + } + + public void onCreate() { + // Since we reload the cursor in onDataSetChanged() which gets called immediately after + // onCreate(), we do nothing here. + } + + public void onDestroy() { + if (mCursor != null) { + mCursor.close(); + } + } + + public int getCount() { + return mCursor.getCount(); + } + + public RemoteViews getViewAt(int position) { + // Get the data for this position from the content provider + String day = "Unknown Day"; + int temp = 0; + if (mCursor.moveToPosition(position)) { + final int dayColIndex = mCursor.getColumnIndex(WeatherDataProvider.Columns.DAY); + final int tempColIndex = mCursor.getColumnIndex( + WeatherDataProvider.Columns.TEMPERATURE); + day = mCursor.getString(dayColIndex); + temp = mCursor.getInt(tempColIndex); + } + + // Return a proper item with the proper day and temperature + final String formatStr = mContext.getResources().getString(R.string.item_format_string); + final int itemId = R.layout.widget_item; + RemoteViews rv = new RemoteViews(mContext.getPackageName(), itemId); + rv.setTextViewText(R.id.widget_item, String.format(formatStr, temp, day)); + + // Set the click intent so that we can handle it and show a toast message + final Intent fillInIntent = new Intent(); + final Bundle extras = new Bundle(); + extras.putString(WeatherWidgetProvider.EXTRA_DAY_ID, day); + fillInIntent.putExtras(extras); + rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent); + + return rv; + } + public RemoteViews getLoadingView() { + // We aren't going to return a default loading view in this sample + return null; + } + + public int getViewTypeCount() { + // Technically, we have two types of views (the dark and light background views) + return 2; + } + + public long getItemId(int position) { + return position; + } + + public boolean hasStableIds() { + return true; + } + + public void onDataSetChanged() { + // Refresh the cursor + if (mCursor != null) { + mCursor.close(); + } + mCursor = mContext.getContentResolver().query(WeatherDataProvider.CONTENT_URI, null, null, + null, null); + } +} diff --git a/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WidgetDataFragment.java b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WidgetDataFragment.java new file mode 100644 index 00000000..b7500a98 --- /dev/null +++ b/content/WidgetData/Application/src/main/java/com/example/android/widgetdata/WidgetDataFragment.java @@ -0,0 +1,19 @@ +package com.example.android.widgetdata; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A Dummy Fragment that shows the intro text from a layout. + */ +public class WidgetDataFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment, null); + } +} diff --git a/content/WidgetData/Application/src/main/res/drawable-hdpi/ic_launcher.png b/content/WidgetData/Application/src/main/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..a602e847 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/content/WidgetData/Application/src/main/res/drawable-hdpi/sunny.png b/content/WidgetData/Application/src/main/res/drawable-hdpi/sunny.png Binary files differnew file mode 100644 index 00000000..42785b9d --- /dev/null +++ b/content/WidgetData/Application/src/main/res/drawable-hdpi/sunny.png diff --git a/content/WidgetData/Application/src/main/res/drawable-mdpi/ic_launcher.png b/content/WidgetData/Application/src/main/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..c828af29 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/content/WidgetData/Application/src/main/res/drawable-mdpi/sunny.png b/content/WidgetData/Application/src/main/res/drawable-mdpi/sunny.png Binary files differnew file mode 100644 index 00000000..9453447a --- /dev/null +++ b/content/WidgetData/Application/src/main/res/drawable-mdpi/sunny.png diff --git a/content/WidgetData/Application/src/main/res/drawable-nodpi/preview.png b/content/WidgetData/Application/src/main/res/drawable-nodpi/preview.png Binary files differnew file mode 100644 index 00000000..b9c87800 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/drawable-nodpi/preview.png diff --git a/content/WidgetData/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/content/WidgetData/Application/src/main/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..b8911f9b --- /dev/null +++ b/content/WidgetData/Application/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/content/WidgetData/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/content/WidgetData/Application/src/main/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 00000000..042438ff --- /dev/null +++ b/content/WidgetData/Application/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/content/WidgetData/Application/src/main/res/layout/fragment.xml b/content/WidgetData/Application/src/main/res/layout/fragment.xml new file mode 100644 index 00000000..9281e3a9 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/layout/fragment.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + Copyright 2014 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/vertical_page_margin" + android:layout_marginLeft="@dimen/horizontal_page_margin" + android:layout_marginRight="@dimen/horizontal_page_margin" + android:layout_marginTop="@dimen/vertical_page_margin" + android:text="@string/usage" /> + +</ScrollView>
\ No newline at end of file diff --git a/content/WidgetData/Application/src/main/res/layout/widget_item.xml b/content/WidgetData/Application/src/main/res/layout/widget_item.xml new file mode 100644 index 00000000..bd3b3f55 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/layout/widget_item.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2011 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/widget_item" + android:layout_width="match_parent" + android:layout_height="46dp" + android:background="#F0F0F0" + android:gravity="center_vertical" + android:paddingLeft="25dp" + android:textColor="#232323" + android:textSize="20sp" /> diff --git a/content/WidgetData/Application/src/main/res/layout/widget_layout.xml b/content/WidgetData/Application/src/main/res/layout/widget_layout.xml new file mode 100644 index 00000000..8aca749a --- /dev/null +++ b/content/WidgetData/Application/src/main/res/layout/widget_layout.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2011 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginBottom="@dimen/widget_margin_bottom" + android:layout_marginLeft="@dimen/widget_margin_left" + android:layout_marginRight="@dimen/widget_margin_right" + android:layout_marginTop="@dimen/widget_margin_top" + android:orientation="vertical"> + <!-- We define separate margins to allow for flexibility in twiddling the margins + depending on device form factor and target SDK version. --> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="80dp" + android:background="#F8F8F8" + android:orientation="horizontal"> + + <ImageView + android:id="@+id/city_weather" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:adjustViewBounds="true" + android:padding="12dp" + android:scaleType="fitStart" + android:src="@drawable/sunny" /> + + <TextView + android:id="@+id/city_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/city_name" + android:textAllCaps="true" + android:textColor="#232323" + android:textSize="24sp" /> + </LinearLayout> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_weight="1" + android:background="#F8F8F8"> + + <ListView + android:id="@+id/weather_list" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + <TextView + android:id="@+id/empty_view" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:text="@string/empty_view_text" + android:textColor="#ffffff" + android:textSize="20sp" + android:visibility="gone" /> + </FrameLayout> + + <Button + android:id="@+id/refresh" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="#F8F8F8" + android:gravity="center" + android:padding="12dp" + android:text="@string/refresh" + android:textAllCaps="true" + android:textColor="#232323" + android:textSize="14sp" /> +</LinearLayout> diff --git a/content/WidgetData/Application/src/main/res/layout/widget_layout_small.xml b/content/WidgetData/Application/src/main/res/layout/widget_layout_small.xml new file mode 100644 index 00000000..40fff692 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/layout/widget_layout_small.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2011 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginBottom="@dimen/widget_margin_bottom" + android:layout_marginLeft="@dimen/widget_margin_left" + android:layout_marginRight="@dimen/widget_margin_right" + android:layout_marginTop="@dimen/widget_margin_top" + android:orientation="vertical"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="80dp" + android:background="#F8F8F8" + android:orientation="horizontal"> + + <ImageView + android:id="@+id/city_weather" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:adjustViewBounds="true" + android:padding="12dp" + android:scaleType="fitStart" + android:src="@drawable/sunny" /> + + <TextView + android:id="@+id/city_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:text="@string/city_name" + android:textAllCaps="true" + android:textColor="#232323" + android:textSize="24sp" /> + </LinearLayout> +</LinearLayout> diff --git a/content/WidgetData/Application/src/main/res/values-v14/dimens.xml b/content/WidgetData/Application/src/main/res/values-v14/dimens.xml new file mode 100644 index 00000000..8b5494e6 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/values-v14/dimens.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<resources> + <dimen name="widget_margin_top">0dp</dimen> + <dimen name="widget_margin_bottom">0dp</dimen> + <dimen name="widget_margin_left">0dp</dimen> + <dimen name="widget_margin_right">0dp</dimen> +</resources> diff --git a/content/WidgetData/Application/src/main/res/values/dimens.xml b/content/WidgetData/Application/src/main/res/values/dimens.xml new file mode 100644 index 00000000..00257a9a --- /dev/null +++ b/content/WidgetData/Application/src/main/res/values/dimens.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<resources> + <dimen name="widget_margin_top">8dp</dimen> + <dimen name="widget_margin_bottom">8dp</dimen> + <dimen name="widget_margin_left">8dp</dimen> + <dimen name="widget_margin_right">8dp</dimen> +</resources>
\ No newline at end of file diff --git a/content/WidgetData/Application/src/main/res/values/strings.xml b/content/WidgetData/Application/src/main/res/values/strings.xml new file mode 100644 index 00000000..00fbb9a9 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/values/strings.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<resources> + <string name="empty_view_text">No cities found...</string> + <string name="toast_format_string">%1$s!</string> + <string name="item_format_string">%1$d\u00B0 on %2$s</string> + <string name="header_format_string">%1$d\u00B0 in %2$s</string> + + <string name="refresh">Refresh</string> + <string name="city_name">San Francisco</string> + <string name="usage">Add the widget named <b>Widget Data</b> to your home screen to use this sample.</string> +</resources> diff --git a/content/WidgetData/Application/src/main/res/xml/widgetinfo.xml b/content/WidgetData/Application/src/main/res/xml/widgetinfo.xml new file mode 100644 index 00000000..2e419439 --- /dev/null +++ b/content/WidgetData/Application/src/main/res/xml/widgetinfo.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<appwidget-provider + xmlns:android="http://schemas.android.com/apk/res/android" + android:minWidth="280dp" + android:minHeight="180dp" + android:updatePeriodMillis="1800000" + android:initialLayout="@layout/widget_layout" + android:resizeMode="vertical" + android:minResizeWidth="280dp" + android:minResizeHeight="70dp" + android:previewImage="@drawable/preview"> +</appwidget-provider> diff --git a/content/WidgetData/Application/tests/AndroidManifest.xml b/content/WidgetData/Application/tests/AndroidManifest.xml new file mode 100644 index 00000000..2ba50adc --- /dev/null +++ b/content/WidgetData/Application/tests/AndroidManifest.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2013 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2013 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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 name must be unique so suffix with "tests" so package loader doesn't ignore us --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.listwidget.tests" + android:versionCode="1" + android:versionName="1.0"> + + <uses-sdk + android:minSdkVersion="18" + android:targetSdkVersion="19" /> + + <!-- We add an application tag here just so that we can indicate that + this package needs to link against the android.test library, + which is needed when building test cases. --> + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <!-- + Specifies the instrumentation test runner used to run the tests. + --> + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.example.android.listwidget" + android:label="Tests for com.example.android.listwidget" /> + +</manifest>
\ No newline at end of file diff --git a/content/WidgetData/Application/tests/src/com/example/android/listwidget/tests/SampleTests.java b/content/WidgetData/Application/tests/src/com/example/android/listwidget/tests/SampleTests.java new file mode 100644 index 00000000..ee8f93ab --- /dev/null +++ b/content/WidgetData/Application/tests/src/com/example/android/listwidget/tests/SampleTests.java @@ -0,0 +1,76 @@ +/* +* Copyright 2013 The Android Open Source Project +* +* 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 +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* 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. +*/ +/* +* Copyright (C) 2013 The Android Open Source Project +* +* 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 +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* 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.example.android.listwidget.tests; + +import com.example.android.listwidget.*; + +import android.test.ActivityInstrumentationTestCase2; + +/** +* Tests for listwidget sample. +*/ +public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> { + + private MainActivity mTestActivity; + private ListwidgetFragment mTestFragment; + + public SampleTests() { + super(MainActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + // Starts the activity under test using the default Intent with: + // action = {@link Intent#ACTION_MAIN} + // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK} + // All other fields are null or empty. + mTestActivity = getActivity(); + mTestFragment = (ListwidgetFragment) + mTestActivity.getSupportFragmentManager().getFragments().get(1); + } + + /** + * Test if the test fixture has been set up correctly. + */ + public void testPreconditions() { + //Try to add a message to add context to your assertions. These messages will be shown if + //a tests fails and make it easy to understand why a test failed + assertNotNull("mTestActivity is null", mTestActivity); + assertNotNull("mTestFragment is null", mTestFragment); + } + + /** + * Add more tests below. + */ + +}
\ No newline at end of file diff --git a/content/WidgetData/LICENSE b/content/WidgetData/LICENSE new file mode 100644 index 00000000..1af981f5 --- /dev/null +++ b/content/WidgetData/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2014 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. diff --git a/content/WidgetData/README.md b/content/WidgetData/README.md new file mode 100644 index 00000000..cdba7100 --- /dev/null +++ b/content/WidgetData/README.md @@ -0,0 +1,67 @@ +Android WidgetData Sample +=================================== + +Sample demonstrating how to instantiate an ActionBar on Android, define +action items, and set an "up" navigation link. Uses the Support Library +for compatibility with pre-3.0 devices. + +Introduction +------------ + +Long intro here. + +Multi-paragraph introduction to sample, from an educational point-of-view. +*Makrdown* formatting allowed. See [Markdown Documentation][1] +for details. + +[1]: http://daringfireball.net/projects/markdown/syntax + +Pre-requisites +-------------- + +- Android SDK v21 +- Android Build Tools v21.1.1 +- Android Support Repository + +Screenshots +------------- + +<img src="screenshots/1-main.png" height="400" alt="Screenshot"/> <img src="screenshots/2-settings.png" height="400" alt="Screenshot"/> + +Getting Started +--------------- + +This sample uses the Gradle build system. To build this project, use the +"gradlew build" command or use "Import Project" in Android Studio. + +Support +------- + +- Google+ Community: https://plus.google.com/communities/105153134372062985968 +- Stack Overflow: http://stackoverflow.com/questions/tagged/android + +If you've found an error in this sample, please file an issue: +https://github.com/googlesamples/android-WidgetData + +Patches are encouraged, and may be submitted by forking this project and +submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. + +License +------- + +Copyright 2014 The Android Open Source Project, Inc. + +Licensed to the Apache Software Foundation (ASF) under one or more contributor +license agreements. See the NOTICE file distributed with this work for +additional information regarding copyright ownership. The ASF licenses this +file to you 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 + +http://www.apache.org/licenses/LICENSE-2.0 + +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. diff --git a/content/WidgetData/build.gradle b/content/WidgetData/build.gradle new file mode 100644 index 00000000..2b8d1ef1 --- /dev/null +++ b/content/WidgetData/build.gradle @@ -0,0 +1,11 @@ + +// BEGIN_EXCLUDE +import com.example.android.samples.build.SampleGenPlugin +apply plugin: SampleGenPlugin + +samplegen { + pathToBuild "../../../../build" + pathToSamplesCommon "../../common" +} +apply from: "../../../../build/build.gradle" +// END_EXCLUDE diff --git a/content/WidgetData/buildSrc/build.gradle b/content/WidgetData/buildSrc/build.gradle new file mode 100644 index 00000000..8c294c23 --- /dev/null +++ b/content/WidgetData/buildSrc/build.gradle @@ -0,0 +1,15 @@ +repositories { + mavenCentral() +} +dependencies { + compile 'org.freemarker:freemarker:2.3.20' +} + +sourceSets { + main { + groovy { + srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy") + } + } +} + diff --git a/content/WidgetData/gradle/wrapper/gradle-wrapper.jar b/content/WidgetData/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 00000000..8c0fb64a --- /dev/null +++ b/content/WidgetData/gradle/wrapper/gradle-wrapper.jar diff --git a/content/WidgetData/gradle/wrapper/gradle-wrapper.properties b/content/WidgetData/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..fe552619 --- /dev/null +++ b/content/WidgetData/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Jan 07 17:32:06 EST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/content/WidgetData/gradlew b/content/WidgetData/gradlew new file mode 100755 index 00000000..91a7e269 --- /dev/null +++ b/content/WidgetData/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/content/WidgetData/gradlew.bat b/content/WidgetData/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/content/WidgetData/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/content/WidgetData/screenshots/1-widget.png b/content/WidgetData/screenshots/1-widget.png Binary files differnew file mode 100644 index 00000000..3d2b8d33 --- /dev/null +++ b/content/WidgetData/screenshots/1-widget.png diff --git a/content/WidgetData/screenshots/icon-web.png b/content/WidgetData/screenshots/icon-web.png Binary files differnew file mode 100644 index 00000000..8a9d0bda --- /dev/null +++ b/content/WidgetData/screenshots/icon-web.png diff --git a/content/WidgetData/settings.gradle b/content/WidgetData/settings.gradle new file mode 100644 index 00000000..9464a359 --- /dev/null +++ b/content/WidgetData/settings.gradle @@ -0,0 +1 @@ +include 'Application' diff --git a/content/WidgetData/template-params.xml b/content/WidgetData/template-params.xml new file mode 100644 index 00000000..552f3a2d --- /dev/null +++ b/content/WidgetData/template-params.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?><!-- + Copyright 2013 The Android Open Source Project + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. +--> +<sample> + <name>WidgetData</name> + <group>Content</group> + <package>com.example.android.widgetdata</package> + + <!-- change minSdk if needed--> + <minSdk>11</minSdk> + + <strings> + <intro> + <![CDATA[ + This sample demonstrates how to create a list-based widget specifically backed by a + content provider.\n\n +This sample uses a collection view (a ListView) to present some mock weather data in a widget. +In particular, we will be using a content provider to demonstrate how the widget can retrieve data +and update itself when you are using more complex data sources. +When working with external data, or data which must be fetched over high latency, it is important +to keep the data cached in a persistent location so that the widget feels responsive. + ]]> + </intro> + </strings> + + <template src="base" /> + <template src="FragmentView" /> + <common src="activities"/> + <common src="logger" /> + + <metadata> + <status>PUBLISHED</status> + <categories>Content</categories> + <technologies>Android</technologies> + <languages>Java</languages> + <solutions>Mobile</solutions> + <level>INTERMEDIATE</level> + <icon>screenshots/icon-web.png</icon> + <screenshots> + <img>screenshots/1-widget.png</img> + </screenshots> + <api_refs> + <android>android.widget.RemoteViews</android> + <android>android.widget.RemoteViewsService</android> + <android>android.database.ContentObserver</android> + <android>android.content.ContentResolver</android> + </api_refs> + <description> +<![CDATA[ +This sample demonstrates how to create a list-based widget specifically backed +by a content provider. +]]> + </description> + <intro> +<![CDATA[ +This sample uses a collection view (a ListView) to present some mock weather data in a widget. +In particular, we will be using a content provider to demonstrate how the widget can retrieve data +and update itself when you are using more complex data sources. +When working with external data, or data which must be fetched over high latency, it is important +to keep the data cached in a persistent location so that the widget feels responsive. + +We define a [ContentProvider][1] that handles queries from a [RemoteView][2] [ListView][3] widget. +A [ContentObserver][4] notifies the widget when data changes in the ContentProvider. +Data for the widget is provided by a [RemoteViewsService][5] that populates a RemoteView collection (the ListView). + +[1]: http://developer.android.com/reference/android/content/ContentProvider.html +[2]: http://developer.android.com/reference/android/widget/RemoteViews.RemoteView.html +[3]: http://developer.android.com/reference/android/widget/ListView.html +[4]: http://developer.android.com/reference/android/database/ContentObserver.html +[5]: http://developer.android.com/reference/android/widget/RemoteViewsService.html +]]> + </intro> +</metadata> +</sample> |