diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-11 12:11:54 -0700 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-11 12:11:54 -0700 |
| commit | 243d18eb22363fcfe5fd76d93c8d2e30f1246ffd (patch) | |
| tree | eeed8d37a7f5fed1062b7d5b2a4dc00e9d5189f6 /samples | |
| parent | 692ab0217595fdccec6592fe7ef05ab1aada509d (diff) | |
| download | android_development-243d18eb22363fcfe5fd76d93c8d2e30f1246ffd.tar.gz android_development-243d18eb22363fcfe5fd76d93c8d2e30f1246ffd.tar.bz2 android_development-243d18eb22363fcfe5fd76d93c8d2e30f1246ffd.zip | |
auto import from //branches/cupcake/...@137873
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/ApiDemos/AndroidManifest.xml | 12 | ||||
| -rw-r--r-- | samples/ApiDemos/res/layout/appwidget_configure.xml (renamed from samples/ApiDemos/res/layout/gadget_configure.xml) | 4 | ||||
| -rw-r--r-- | samples/ApiDemos/res/layout/appwidget_provider.xml (renamed from samples/ApiDemos/res/layout/gadget_provider.xml) | 2 | ||||
| -rw-r--r-- | samples/ApiDemos/res/values/strings.xml | 8 | ||||
| -rw-r--r-- | samples/ApiDemos/res/xml/appwidget_provider.xml (renamed from samples/ApiDemos/res/xml/gadget_provider.xml) | 8 | ||||
| -rw-r--r-- | samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetConfigure.java (renamed from samples/ApiDemos/src/com/example/android/apis/gadget/ExampleGadgetConfigure.java) | 58 | ||||
| -rw-r--r-- | samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetProvider.java (renamed from samples/ApiDemos/src/com/example/android/apis/gadget/ExampleGadgetProvider.java) | 76 | ||||
| -rw-r--r-- | samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleBroadcastReceiver.java (renamed from samples/ApiDemos/src/com/example/android/apis/gadget/ExampleBroadcastReceiver.java) | 22 |
8 files changed, 95 insertions, 95 deletions
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml index afcfbc88f..0cbba1449 100644 --- a/samples/ApiDemos/AndroidManifest.xml +++ b/samples/ApiDemos/AndroidManifest.xml @@ -1653,18 +1653,18 @@ </activity> <!-- ************************************* --> - <!-- GADGET PACKAGE SAMPLES --> + <!-- APPWIDGET PACKAGE SAMPLES --> <!-- ************************************* --> - <receiver android:name=".gadget.ExampleGadgetProvider"> - <meta-data android:name="android.gadget.provider" - android:resource="@xml/gadget_provider" /> + <receiver android:name=".appwidget.ExampleAppWidgetProvider"> + <meta-data android:name="android.appwidget.provider" + android:resource="@xml/appwidget_provider" /> <intent-filter> - <action android:name="android.gadget.action.GADGET_UPDATE" /> + <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> </receiver> - <receiver android:name=".gadget.ExampleBroadcastReceiver" android:enabled="false"> + <receiver android:name=".appwidget.ExampleBroadcastReceiver" android:enabled="false"> <intent-filter> <action android:name="android.intent.ACTION_TIMEZONE_CHANGED" /> <action android:name="android.intent.ACTION_TIME" /> diff --git a/samples/ApiDemos/res/layout/gadget_configure.xml b/samples/ApiDemos/res/layout/appwidget_configure.xml index bc9f40dc8..c041ad64b 100644 --- a/samples/ApiDemos/res/layout/gadget_configure.xml +++ b/samples/ApiDemos/res/layout/appwidget_configure.xml @@ -23,11 +23,11 @@ <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" - android:text="@string/gadget_configure_instructions" + android:text="@string/appwidget_configure_instructions" /> <EditText - android:id="@+id/gadget_prefix" + android:id="@+id/appwidget_prefix" android:layout_width="fill_parent" android:layout_height="wrap_content" /> diff --git a/samples/ApiDemos/res/layout/gadget_provider.xml b/samples/ApiDemos/res/layout/appwidget_provider.xml index 49cf42f82..373db8f7d 100644 --- a/samples/ApiDemos/res/layout/gadget_provider.xml +++ b/samples/ApiDemos/res/layout/appwidget_provider.xml @@ -15,7 +15,7 @@ --> <TextView xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/gadget_text" + android:id="@+id/appwidget_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ff000000" diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml index bd1b0a38d..0cafe1428 100644 --- a/samples/ApiDemos/res/values/strings.xml +++ b/samples/ApiDemos/res/values/strings.xml @@ -814,11 +814,11 @@ <string name="listSeparatorTextViewStyle">listSeparatorTextViewStyle</string> <!-- ============================ --> - <!-- gadget examples strings --> + <!-- AppWidget examples strings --> <!-- ============================ --> - <string name="gadget_configure_instructions">This text will be shown before the date in our example gadget.</string> - <string name="gadget_prefix_default">Oh hai</string> - <string name="gadget_text_format"><xliff:g id="prefix">%1$s</xliff:g>: <xliff:g id="time">%2$s</xliff:g></string> + <string name="appwidget_configure_instructions">This text will be shown before the date in our example widget.</string> + <string name="appwidget_prefix_default">Oh hai</string> + <string name="appwidget_text_format"><xliff:g id="prefix">%1$s</xliff:g>: <xliff:g id="time">%2$s</xliff:g></string> </resources> diff --git a/samples/ApiDemos/res/xml/gadget_provider.xml b/samples/ApiDemos/res/xml/appwidget_provider.xml index 9ad6845f4..5f5c7351e 100644 --- a/samples/ApiDemos/res/xml/gadget_provider.xml +++ b/samples/ApiDemos/res/xml/appwidget_provider.xml @@ -14,14 +14,14 @@ limitations under the License. --> -<gadget-provider xmlns:android="http://schemas.android.com/apk/res/android" +<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="60dp" android:minHeight="30dp" android:updatePeriodMillis="86400000" - android:initialLayout="@layout/gadget_provider" - android:configure="com.example.android.apis.gadget.ExampleGadgetConfigure" + android:initialLayout="@layout/appwidget_provider" + android:configure="com.example.android.apis.appwidget.ExampleAppWidgetConfigure" > -</gadget-provider> +</appwidget-provider> <!-- 86400000 is the value of AlarmManager.INTERVAL_DAY - or once per day. --> diff --git a/samples/ApiDemos/src/com/example/android/apis/gadget/ExampleGadgetConfigure.java b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetConfigure.java index 03e7bb42f..e0a4c76b0 100644 --- a/samples/ApiDemos/src/com/example/android/apis/gadget/ExampleGadgetConfigure.java +++ b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetConfigure.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.example.android.apis.gadget; +package com.example.android.apis.appwidget; import android.app.Activity; +import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.gadget.GadgetManager; import android.os.Bundle; import android.util.Log; import android.view.View; @@ -33,19 +33,19 @@ import java.util.ArrayList; import com.example.android.apis.R; /** - * The configuration screen for the ExampleGadgetProvider gadget sample. + * The configuration screen for the ExampleAppWidgetProvider widget sample. */ -public class ExampleGadgetConfigure extends Activity { - static final String TAG = "ExampleGadgetConfigure"; +public class ExampleAppWidgetConfigure extends Activity { + static final String TAG = "ExampleAppWidgetConfigure"; private static final String PREFS_NAME - = "com.example.android.apis.gadget.ExampleGadgetProvider"; + = "com.example.android.apis.appwidget.ExampleAppWidgetProvider"; private static final String PREF_PREFIX_KEY = "prefix_"; - int mGadgetId = GadgetManager.INVALID_GADGET_ID; - EditText mGadgetPrefix; + int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; + EditText mAppWidgetPrefix; - public ExampleGadgetConfigure() { + public ExampleAppWidgetConfigure() { super(); } @@ -53,70 +53,70 @@ public class ExampleGadgetConfigure extends Activity { public void onCreate(Bundle icicle) { super.onCreate(icicle); - // Set the result to CANCELED. This will cause the gadget host to cancel - // out of the gadget placement if they press the back button. + // Set the result to CANCELED. This will cause the widget host to cancel + // out of the widget placement if they press the back button. setResult(RESULT_CANCELED); // Set the view layout resource to use. - setContentView(R.layout.gadget_configure); + setContentView(R.layout.appwidget_configure); // Find the EditText - mGadgetPrefix = (EditText)findViewById(R.id.gadget_prefix); + mAppWidgetPrefix = (EditText)findViewById(R.id.appwidget_prefix); // Bind the action for the save button. findViewById(R.id.save_button).setOnClickListener(mOnClickListener); - // Find the gadget id from the intent. + // Find the widget id from the intent. Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { - mGadgetId = extras.getInt( - GadgetManager.EXTRA_GADGET_ID, GadgetManager.INVALID_GADGET_ID); + mAppWidgetId = extras.getInt( + AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } - // If they gave us an intent without the gadget id, just bail. - if (mGadgetId == GadgetManager.INVALID_GADGET_ID) { + // If they gave us an intent without the widget id, just bail. + if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); } - mGadgetPrefix.setText(loadTitlePref(ExampleGadgetConfigure.this, mGadgetId)); + mAppWidgetPrefix.setText(loadTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId)); } View.OnClickListener mOnClickListener = new View.OnClickListener() { public void onClick(View v) { // When the button is clicked, save the string in our prefs and return that they // clicked OK. - saveTitlePref(ExampleGadgetConfigure.this, mGadgetId, - mGadgetPrefix.getText().toString()); + saveTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId, + mAppWidgetPrefix.getText().toString()); setResult(RESULT_OK); finish(); } }; - // Write the prefix to the SharedPreferences object for this gadget - static void saveTitlePref(Context context, int gadgetId, String text) { + // Write the prefix to the SharedPreferences object for this widget + static void saveTitlePref(Context context, int appWidgetId, String text) { SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit(); - prefs.putString(PREF_PREFIX_KEY + gadgetId, text); + prefs.putString(PREF_PREFIX_KEY + appWidgetId, text); prefs.commit(); } - // Read the prefix from the SharedPreferences object for this gadget. + // Read the prefix from the SharedPreferences object for this widget. // If there is no preference saved, get the default from a resource - static String loadTitlePref(Context context, int gadgetId) { + static String loadTitlePref(Context context, int appWidgetId) { SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0); String prefix = prefs.getString(PREF_PREFIX_KEY, null); if (prefix != null) { return prefix; } else { - return context.getString(R.string.gadget_prefix_default); + return context.getString(R.string.appwidget_prefix_default); } } - static void deleteTitlePref(Context context, int gadgetId) { + static void deleteTitlePref(Context context, int appWidgetId) { } - static void loadAllTitlePrefs(Context context, ArrayList<Integer> gadgetIds, + static void loadAllTitlePrefs(Context context, ArrayList<Integer> appWidgetIds, ArrayList<String> texts) { } } diff --git a/samples/ApiDemos/src/com/example/android/apis/gadget/ExampleGadgetProvider.java b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetProvider.java index eb1dab311..6977d3e6e 100644 --- a/samples/ApiDemos/src/com/example/android/apis/gadget/ExampleGadgetProvider.java +++ b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetProvider.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package com.example.android.apis.gadget; +package com.example.android.apis.appwidget; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.gadget.GadgetManager; -import android.gadget.GadgetProvider; import android.os.SystemClock; import android.util.Log; import android.widget.RemoteViews; @@ -33,89 +33,89 @@ import java.util.ArrayList; import com.example.android.apis.R; /** - * A gadget provider. We have a string that we pull from a preference in order to show - * the configuration settings and the current time when the gadget was updated. We also + * A widget provider. We have a string that we pull from a preference in order to show + * the configuration settings and the current time when the widget was updated. We also * register a BroadcastReceiver for time-changed and timezone-changed broadcasts, and * update then too. * * <p>See also the following files: * <ul> - * <li>ExampleGadgetConfigure.java</li> + * <li>ExampleAppWidgetConfigure.java</li> * <li>ExampleBroadcastReceiver.java</li> - * <li>res/layout/gadget_configure.xml</li> - * <li>res/layout/gadget_provider.xml</li> - * <li>res/xml/gadget_provider.xml</li> + * <li>res/layout/appwidget_configure.xml</li> + * <li>res/layout/appwidget_provider.xml</li> + * <li>res/xml/appwidget_provider.xml</li> * </ul> */ -public class ExampleGadgetProvider extends GadgetProvider { +public class ExampleAppWidgetProvider extends AppWidgetProvider { // log tag - private static final String TAG = "ExampleGadgetProvider"; + private static final String TAG = "ExampleAppWidgetProvider"; - public void onUpdate(Context context, GadgetManager gadgetManager, int[] gadgetIds) { + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d(TAG, "onUpdate"); - // For each gadget that needs an update, get the text that we should display: + // For each widget that needs an update, get the text that we should display: // - Create a RemoteViews object for it // - Set the text in the RemoteViews object - // - Tell the GadgetManager to show that views object for the gadget. - final int N = gadgetIds.length; + // - Tell the AppWidgetManager to show that views object for the widget. + final int N = appWidgetIds.length; for (int i=0; i<N; i++) { - int gadgetId = gadgetIds[i]; - String titlePrefix = ExampleGadgetConfigure.loadTitlePref(context, gadgetId); - updateGadget(context, gadgetManager, gadgetId, titlePrefix); + int appWidgetId = appWidgetIds[i]; + String titlePrefix = ExampleAppWidgetConfigure.loadTitlePref(context, appWidgetId); + updateAppWidget(context, appWidgetManager, appWidgetId, titlePrefix); } } - public void onDeleted(Context context, int[] gadgetIds) { + public void onDeleted(Context context, int[] appWidgetIds) { Log.d(TAG, "onDeleted"); - // When the user deletes the gadget, delete the preference associated with it. - final int N = gadgetIds.length; + // When the user deletes the widget, delete the preference associated with it. + final int N = appWidgetIds.length; for (int i=0; i<N; i++) { - ExampleGadgetConfigure.deleteTitlePref(context, gadgetIds[i]); + ExampleAppWidgetConfigure.deleteTitlePref(context, appWidgetIds[i]); } } public void onEnabled(Context context) { Log.d(TAG, "onEnabled"); - // When the first gadget is created, register for the TIMEZONE_CHANGED and TIME_CHANGED - // broadcasts. We don't want to be listening for these if nobody has our gadget active. + // When the first widget is created, register for the TIMEZONE_CHANGED and TIME_CHANGED + // broadcasts. We don't want to be listening for these if nobody has our widget active. // This setting is sticky across reboots, but that doesn't matter, because this will - // be called after boot if there is a gadget instance for this provider. + // be called after boot if there is a widget instance for this provider. PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting( - new ComponentName("com.example.android.apis", ".gadget.ExampleBroadcastReceiver"), + new ComponentName("com.example.android.apis", ".appwidget.ExampleBroadcastReceiver"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } public void onDisabled(Context context) { - // When the first gadget is created, stop listening for the TIMEZONE_CHANGED and + // When the first widget is created, stop listening for the TIMEZONE_CHANGED and // TIME_CHANGED broadcasts. Log.d(TAG, "onDisabled"); Class clazz = ExampleBroadcastReceiver.class; PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting( - new ComponentName("com.example.android.apis", ".gadget.ExampleBroadcastReceiver"), + new ComponentName("com.example.android.apis", ".appwidget.ExampleBroadcastReceiver"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } - static void updateGadget(Context context, GadgetManager gadgetManager, - int gadgetId, String titlePrefix) { - Log.d(TAG, "updateGadget gadgetId=" + gadgetId + " titlePrefix=" + titlePrefix); + static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, + int appWidgetId, String titlePrefix) { + Log.d(TAG, "updateAppWidget appWidgetId=" + appWidgetId + " titlePrefix=" + titlePrefix); // Getting the string this way allows the string to be localized. The format // string is filled in using java.util.Formatter-style format strings. - CharSequence text = context.getString(R.string.gadget_text_format, - ExampleGadgetConfigure.loadTitlePref(context, gadgetId), + CharSequence text = context.getString(R.string.appwidget_text_format, + ExampleAppWidgetConfigure.loadTitlePref(context, appWidgetId), "0x" + Long.toHexString(SystemClock.elapsedRealtime())); // Construct the RemoteViews object. It takes the package name (in our case, it's our - // package, but it needs this because on the other side it's the gadget host inflating + // package, but it needs this because on the other side it's the widget host inflating // the layout from our package). - RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.gadget_provider); - views.setTextViewText(R.id.gadget_text, text); + RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); + views.setTextViewText(R.id.appwidget_text, text); - // Tell the gadget manager - gadgetManager.updateGadget(gadgetId, views); + // Tell the widget manager + appWidgetManager.updateAppWidget(appWidgetId, views); } } diff --git a/samples/ApiDemos/src/com/example/android/apis/gadget/ExampleBroadcastReceiver.java b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleBroadcastReceiver.java index eec10b2ca..f6e01add1 100644 --- a/samples/ApiDemos/src/com/example/android/apis/gadget/ExampleBroadcastReceiver.java +++ b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleBroadcastReceiver.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package com.example.android.apis.gadget; +package com.example.android.apis.appwidget; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.gadget.GadgetManager; -import android.gadget.GadgetProvider; import android.os.SystemClock; import android.util.Log; import android.widget.RemoteViews; @@ -33,8 +33,8 @@ import java.util.ArrayList; import com.example.android.apis.R; /** - * A BroadcastReceiver that listens for updates for the ExampleGadgetProvider. This - * BroadcastReceiver starts off disabled, and we only enable it when there is a gadget + * A BroadcastReceiver that listens for updates for the ExampleAppWidgetProvider. This + * BroadcastReceiver starts off disabled, and we only enable it when there is a widget * instance created, in order to only receive notifications when we need them. */ public class ExampleBroadcastReceiver extends BroadcastReceiver { @@ -42,20 +42,20 @@ public class ExampleBroadcastReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Log.d("ExmampleBroadcastReceiver", "intent=" + intent); - // For our example, we'll also update all of the gadgets when the timezone + // For our example, we'll also update all of the widgets when the timezone // changes, or the user or network sets the time. String action = intent.getAction(); if (action.equals(Intent.ACTION_TIMEZONE_CHANGED) || action.equals(Intent.ACTION_TIME_CHANGED)) { - GadgetManager gm = GadgetManager.getInstance(context); - ArrayList<Integer> gadgetIds = new ArrayList(); + AppWidgetManager gm = AppWidgetManager.getInstance(context); + ArrayList<Integer> appWidgetIds = new ArrayList(); ArrayList<String> texts = new ArrayList(); - ExampleGadgetConfigure.loadAllTitlePrefs(context, gadgetIds, texts); + ExampleAppWidgetConfigure.loadAllTitlePrefs(context, appWidgetIds, texts); - final int N = gadgetIds.size(); + final int N = appWidgetIds.size(); for (int i=0; i<N; i++) { - ExampleGadgetProvider.updateGadget(context, gm, gadgetIds.get(i), texts.get(i)); + ExampleAppWidgetProvider.updateAppWidget(context, gm, appWidgetIds.get(i), texts.get(i)); } } } |
