Home | History | Annotate | Download | only in appwidgetprovider
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.tests.appwidgetprovider;
     18 
     19 import android.content.BroadcastReceiver;
     20 import android.content.ComponentName;
     21 import android.content.Context;
     22 import android.content.Intent;
     23 import android.appwidget.AppWidgetManager;
     24 import android.os.Bundle;
     25 import android.os.SystemClock;
     26 import android.util.Log;
     27 import android.widget.RemoteViews;
     28 
     29 public class TestAppWidgetProvider extends BroadcastReceiver {
     30 
     31     static final String TAG = "TestAppWidgetProvider";
     32 
     33     public void onReceive(Context context, Intent intent) {
     34         String action = intent.getAction();
     35         Log.d(TAG, "intent=" + intent);
     36 
     37         if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
     38             Log.d(TAG, "ENABLED");
     39         }
     40         else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
     41             Log.d(TAG, "DISABLED");
     42         }
     43         else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
     44             if (true) return;
     45             Log.d(TAG, "UPDATE");
     46             Bundle extras = intent.getExtras();
     47             int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
     48 
     49             AppWidgetManager gm = AppWidgetManager.getInstance(context);
     50             RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
     51             views.setTextViewText(R.id.oh_hai_text, "hai: " + SystemClock.elapsedRealtime());
     52             if (false) {
     53                 gm.updateAppWidget(appWidgetIds, views);
     54             } else {
     55                 gm.updateAppWidget(new ComponentName("com.android.tests.appwidgetprovider",
     56                             "com.android.tests.appwidgetprovider.TestAppWidgetProvider"), views);
     57             }
     58         }
     59     }
     60 }
     61 
     62