@Override
 public void onReceive(Context context, Intent intent) {
   AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   int id =
       intent.getIntExtra(
           AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
   String date = intent.getStringExtra(EXTRA_DATE);
   switch (intent.getAction()) {
     case ACTION_PREVIOUS_CLICK:
       RemoteViews remoteViews = getRemoteViews(context, id, date);
       if (remoteViews != null) {
         mSharedPreferenceHelper.setDateForWidget(date);
         appWidgetManager.updateAppWidget(id, remoteViews);
       }
       break;
     case ACTION_NEXT_CLICK:
       RemoteViews remoteViews1 = getRemoteViews(context, id, date);
       if (remoteViews1 != null) {
         appWidgetManager.updateAppWidget(id, remoteViews1);
       }
       break;
     case ACTION_TODAY_CLICK:
       RemoteViews remoteViews2 = getRemoteViews(context, id, date);
       if (remoteViews2 != null) {
         mSharedPreferenceHelper.setDateForWidget(date);
         appWidgetManager.updateAppWidget(id, remoteViews2);
       }
       break;
     case ACTION_UPDATE:
       int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
       setRemotes(context, AppWidgetManager.getInstance(context), appWidgetIds);
       break;
     case ACTION_UPDATE_NOTE:
       appWidgetManager.notifyAppWidgetViewDataChanged(
           intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), R.id.list_widget);
       break;
     case ACTION_HEADER_CLICK:
       Intent i = new Intent(context, MainActivity.class);
       i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       context.startActivity(i);
       break;
   }
   super.onReceive(context, intent);
 }
Пример #2
0
  private void handleIsOpen(final Context mContext, final OpeningStatus openingStatus) {
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
    final int[] appWidgetIds =
        appWidgetManager.getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class));
    final RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget);
    views.setTextViewText(R.id.appwidget_text, mContext.getText(R.string.refreshing_analog));
    views.setTextColor(
        R.id.appwidget_text, ContextCompat.getColor(mContext, android.R.color.primary_text_dark));
    // Instruct the widget manager to update the widget
    for (int appWidgetId : appWidgetIds) {
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }

    CharSequence widgetText;
    if (openingStatus.open) {
      widgetText = mContext.getString(R.string.widget_open_analog);
      views.setTextColor(R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.openColor));
    } else {
      widgetText = mContext.getString(R.string.widget_closed_analog);
      views.setTextColor(
          R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.closedColor));
    }

    views.setTextViewText(R.id.appwidget_text, widgetText);
    views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext));
    // Instruct the widget manager to update the widget
    for (int appWidgetId : appWidgetIds) {
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }
 private void pushUpdate(
     final Context context, final int[] appWidgetIds, final RemoteViews views) {
   final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   if (appWidgetIds != null) {
     appWidgetManager.updateAppWidget(appWidgetIds, views);
   } else {
     appWidgetManager.updateAppWidget(new ComponentName(context, getClass()), views);
   }
 }
  static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    Log.d(TAG, "updateAppWidget ID:" + appWidgetId);

    boolean isContentProviderInstalled = isPackageInstalled(CONTENT_PROVIDER_PACKAGE, context);
    /*
            Log.d(TAG, "is On This Day installed:"+isContentProviderInstalled);
            Log.d(TAG, "is ContentProviderInstalled:"+DataFetcher.isProviderInstalled(context));
    */

    // save current Lang
    Resources res = context.getResources();
    Configuration conf = res.getConfiguration();
    String currentLang = conf.locale.getLanguage();

    // get settings lang
    String settingLang = SettingsActivity.loadPrefs(context, appWidgetId);
    if (settingLang == null || settingLang.isEmpty()) {
      settingLang = currentLang;
    }

    Date currentDate = new Date();

    RemoteViews rv;
    if (!isContentProviderInstalled) {
      // no content provider

      rv = new RemoteViews(context.getPackageName(), R.layout.plz_install_widget_layout);

      // Create an Intent to launch Play Market

      Intent intent;
      // TODO check is market:// parsed
      try {
        intent =
            new Intent(
                Intent.ACTION_VIEW, Uri.parse("market://details?id=" + CONTENT_PROVIDER_PACKAGE));
      } catch (android.content.ActivityNotFoundException anfe) {
        intent =
            new Intent(
                Intent.ACTION_VIEW,
                Uri.parse(
                    "https://play.google.com/store/apps/details?id=" + CONTENT_PROVIDER_PACKAGE));
      }
      PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
      rv.setOnClickPendingIntent(R.id.installView, pendingIntent);

    } else {
      rv = new RemoteViews(context.getPackageName(), R.layout.atd_widget_layout);

      setTitle(rv, context, settingLang, currentDate);

      // start service for getData and create Views
      setList(rv, context, settingLang, currentDate, appWidgetId);
    }

    //
    // Do additional processing specific to this app widget...
    //
    appWidgetManager.updateAppWidget(appWidgetId, rv);
  }
Пример #5
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
      Intent svcIntent = new Intent(context, WidgetService.class);

      svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
      svcIntent.putExtra(
          AppWidgetManager.EXTRA_CUSTOM_INFO, PrefUtils.getInt(appWidgetId + ".fontsize", 0));
      svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

      RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
      widget.setOnClickPendingIntent(
          R.id.feed_icon,
          PendingIntent.getActivity(context, 0, new Intent(context, HomeActivity.class), 0));
      widget.setPendingIntentTemplate(
          R.id.feedsListView,
          PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW), 0));

      widget.setRemoteAdapter(R.id.feedsListView, svcIntent);
      widget.setInt(
          R.id.feedsListView,
          "setBackgroundColor",
          PrefUtils.getInt(appWidgetId + ".background", STANDARD_BACKGROUND));

      appWidgetManager.updateAppWidget(appWidgetId, widget);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);
  }
Пример #6
0
  @Override
  public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    Log.v(TAG, "onStart");

    // RemoteViews is used with widget. This can be displayed in another process.
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.main);
    // Prepare Intent which is sent when button is clicked
    Intent buttonIntent = new Intent();

    // If this Intent is issued when button is clicked
    if (BUTTON_CLICK_ACTION.equals(intent.getAction())) {
      buttonIntent.setAction(BUTTON_CLICK_ACTION2);
      remoteViews.setTextViewText(R.id.text, "Push Button");
    } else {
      buttonIntent.setAction(BUTTON_CLICK_ACTION);
      remoteViews.setTextViewText(R.id.text, "WidgetSample");
    }

    // Handle this Intent as PendingIntent
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, buttonIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.button, pendingIntent);
    Log.v(TAG, "set PendingIntent here");
    Toast.makeText(this, "set PendingIntent", Toast.LENGTH_SHORT).show();

    // Update AppWidget display
    ComponentName thisWidget = new ComponentName(this, WidgetSample.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    manager.updateAppWidget(thisWidget, remoteViews);
  }
Пример #7
0
  private void updateWidgets() {
    RemoteViews widget = new RemoteViews(getPackageName(), R.layout.ticker_widget);
    widget.setOnClickPendingIntent(
        R.id.feed_ticker_tap_area,
        PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0));

    Cursor unread =
        getContentResolver()
            .query(
                FeedData.EntryColumns.CONTENT_URI,
                new String[] {FeedData.ALL_UNREAD_NUMBER},
                null,
                null,
                null);
    if (unread != null) {
      if (unread.moveToFirst()) {
        int unread_count = unread.getInt(0);
        if (unread_count > 0) {
          widget.setTextViewText(R.id.feed_ticker, String.valueOf(unread_count));
          widget.setViewVisibility(R.id.feed_ticker, View.VISIBLE);
          widget.setViewVisibility(R.id.feed_ticker_circle, View.VISIBLE);
        } else {
          widget.setViewVisibility(R.id.feed_ticker, View.INVISIBLE);
          widget.setViewVisibility(R.id.feed_ticker_circle, View.INVISIBLE);
        }
      }
      unread.close();
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    appWidgetManager.updateAppWidget(
        new ComponentName(getPackageName(), TickerWidgetProvider.class.getName()), widget);
  }
Пример #8
0
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d(
        Constants.TAG,
        "[ColorThemeChangedReceiver onReceive]---intent.getAction()=" + intent.getAction());
    if (intent.getAction().equals("action.flyaudio.colortheme")) {
      Log.e("lixuanbright", "action.flyaudio.colortheme====");
      //			AppWidgetDao dao = new AppWidgetDao(context);
      //			List<Integer> appWidgetIds = dao.getAppWidgetIds();
      int[] appWidgetIds = AppWidgetDao.getAllAppWidgetId(context);
      appWidgetManager = AppWidgetManager.getInstance(context);
      for (int appWidgetId : appWidgetIds) {
        remoteViews = SwitchWidget.initRemoteViews(context, appWidgetId);
        //  restore shortcut had been set
        SwitchWidget.dataRestore(context, appWidgetId, remoteViews, false);

        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
      }
      //			dao.close();
    }
    if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
      Log.e("lixuanbright", "主题:Intent.ACTION_LOCALE_CHANGED===");
      /*			int[] appWidgetIds = AppWidgetDao.getAllAppWidgetId(context);
      appWidgetManager = AppWidgetManager.getInstance(context);
      for (int appWidgetId : appWidgetIds) {
       remoteViews =SwitchWidget.initRemoteViews(context, appWidgetId);
      	//  restore shortcut had been set
      	SwitchWidget.dataRestore(context, appWidgetId , remoteViews, false);

      	appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
      }*/
    }
  }
Пример #9
0
  @Override
  public void onUpdate(Context ctxt, AppWidgetManager mgr, int[] appWidgetIds) {
    ComponentName me = new ComponentName(ctxt, AppWidget.class);
    RemoteViews updateViews = new RemoteViews("apt.tutorial", R.layout.widget);
    SQLiteDatabase db = (new RestaurantSQLiteHelper(ctxt)).getReadableDatabase();

    try {
      Cursor c = db.rawQuery("SELECT COUNT(*) FROM restaurants", null);

      c.moveToFirst();

      int count = c.getInt(0);

      c.close();

      if (count > 0) {
        int offset = (int) (count * Math.random());
        String args[] = {String.valueOf(offset)};

        c = db.rawQuery("SELECT name FROM restaurants LIMIT 1 OFFSET ?", args);
        c.moveToFirst();
        updateViews.setTextViewText(R.id.name, c.getString(0));
      } else {
        updateViews.setTextViewText(R.id.name, ctxt.getString(R.string.empty));
      }
    } finally {
      db.close();
    }

    mgr.updateAppWidget(me, updateViews);
  }
Пример #10
0
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.d(TAG, "onUpdate");

    for (int i = 0; i < appWidgetIds.length; i++) {
      int appWidgetId = appWidgetIds[i];

      Intent intent = new Intent(context, StackWidgetService.class);
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

      intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

      RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      views.setRemoteAdapter(appWidgetId, R.id.stack_view, intent);
      views.setEmptyView(R.id.stack_view, R.id.empty_view);

      Intent toastIntent = new Intent(context, FootballScoreWidget.class);
      toastIntent.setAction(FootballScoreWidget.OPEN_ACTIVITY_ACTION);
      toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
      intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
      PendingIntent toastPendingIntent =
          PendingIntent.getBroadcast(context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      views.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent);

      appWidgetManager.updateAppWidget(appWidgetId, views);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);
  }
  private void updateAppWidget(
      Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    // Construct the RemoteViews object
    //        RemoteViews views = new RemoteViews(context.getPackageName(),
    // R.layout.widget_single_account);
    RemoteViews views = getRemoteViews(context, appWidgetManager, appWidgetId);

    // todo: allow selecting the account from a list.

    // todo: load the configured account id
    AppSettings settings = new AppSettings(context);
    String defaultAccountId = settings.getGeneralSettings().getDefaultAccountId();
    if (StringUtils.isNotEmpty(defaultAccountId)) {
      displayAccountInfo(context, defaultAccountId, views);
    }

    // handle + click -> open the new transaction screen for this account.
    // todo: pass the account id?
    initializeNewTransactionCommand(context, views);

    // handle logo click -> open the app.
    initializeStartAppCommand(context, views);

    // click account name -> refresh the balance.
    initializeRefreshDataCommand(context, views, appWidgetId);

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
  }
Пример #12
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int i = 0; i < appWidgetIds.length; i++) {
      GregorianCalendar cal = new GregorianCalendar();

      SimpleDateFormat weekFormat = new SimpleDateFormat("EEE");
      String strWeek = weekFormat.format(cal.getTime());

      SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd");
      String strDate = dateFormat.format(cal.getTime());

      RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.myapp_widget);
      remote.setTextViewText(R.id.tvDate, strDate);
      remote.setTextViewText(R.id.tvWeekDay, strWeek);

      Intent intent = new Intent(context, MyAppWidget.class);
      intent.setAction(ACTION_MYAPPWIDGET_DISPLAY);
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);

      PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
      remote.setOnClickPendingIntent(R.id.btnWidget, pIntent);

      appWidgetManager.updateAppWidget(appWidgetIds[i], remote);
    }
  }
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    super.onUpdate(context, appWidgetManager, appWidgetIds);
    final int N = appWidgetIds.length;

    for (int i = 0; i < N; i++) {

      int widgetId = appWidgetIds[i];
      Intent intent = new Intent();
      intent.setAction(WidgetBroadcastReceiver.INTENT_ACTION);
      intent.putExtra("widgetID", widgetId);
      intent.setClassName(
          WidgetBroadcastReceiver.class.getPackage().getName(),
          WidgetBroadcastReceiver.class.getName());

      PendingIntent pendingIntent =
          PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

      remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      remoteView.setOnClickPendingIntent(R.id.widgetButton, pendingIntent);

      appWidgetManager.updateAppWidget(widgetId, remoteView);
    }
  }
  /**
   * Update the widget
   *
   * @param context
   * @param appWidgetManager
   * @param appWidgetId
   */
  static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    // Prepare widget views
    RemoteViews views =
        new RemoteViews(context.getPackageName(), R.layout.activity_verbose_clock_widget);

    String heure = ClockActivity.getHourString(context);

    views.setTextViewText(
        R.id.hourTv,
        heure.substring(0, heure.indexOf("heure") - 1).replace("\n", "").toUpperCase());
    views.setTextViewText(
        R.id.hourLabelTv, heure.substring(heure.indexOf("heure")).replace("\n", ""));

    if (!ClockActivity.getMinutesString(context).equals("")) {
      String minute = ClockActivity.getMinutesString(context);
      views.setTextViewText(
          R.id.minTv,
          minute.substring(0, minute.indexOf("minute") - 1).replace("\n", "").toUpperCase());
      views.setTextViewText(
          R.id.minLabelTv, minute.substring(minute.indexOf("minute")).replace("\n", ""));
    } else {
      views.setTextViewText(R.id.minTv, "");
      views.setTextViewText(R.id.minLabelTv, "");
    }

    Intent intent = new Intent(context, VerboseClockWidget.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    views.setOnClickPendingIntent(R.id.clock_widget, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetId, views);
  }
  public void onReceive(Context context, Intent intent) {

    Log.d("TimeSetReceiver", "onReceive");

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);

    ComponentName thisWidget; // 组件名
    AppWidgetManager manager; // AppWidget管理器

    thisWidget = new ComponentName(context, CalendarWidget.class);
    manager = AppWidgetManager.getInstance(context);

    Calendar calendar = Calendar.getInstance();

    int day = calendar.get(Calendar.DAY_OF_MONTH);
    int month = calendar.get(Calendar.MONTH) + 1;
    int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    Lunar lunar = new Lunar(calendar);

    Log.d("TimeSetReceiver", month + "," + day + lunar.toString());

    String month_week = month + "月" + "          周" + weekArray[week];
    views.setTextViewText(R.id.month_week, month_week);
    views.setTextViewText(R.id.nongli, lunar.toString());
    views.setTextViewText(R.id.day, Html.fromHtml("<B>" + String.valueOf(day) + "</B>"));

    manager.updateAppWidget(thisWidget, views);

    Log.d("TimeSetReceiver", "updateAppWidget finish");
  }
  public static void updateWidgets(
      final Context context,
      @Nonnull final AppWidgetManager appWidgetManager,
      @Nonnull final int[] appWidgetIds,
      @Nonnull final BigInteger balance) {
    final Configuration config =
        new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final Spannable balanceStr =
        new SpannableString(
            GenericUtils.formatValue(balance, config.getBtcPrecision(), config.getBtcShift()));
    WalletUtils.formatSignificant(balanceStr, WalletUtils.SMALLER_SPAN);

    for (final int appWidgetId : appWidgetIds) {
      final RemoteViews views =
          new RemoteViews(context.getPackageName(), R.layout.wallet_balance_widget_content);
      views.setTextViewText(R.id.widget_wallet_prefix, config.getBtcPrefix());
      views.setTextViewText(R.id.widget_wallet_balance, balanceStr);
      views.setOnClickPendingIntent(
          R.id.widget_button_balance,
          PendingIntent.getActivity(context, 0, new Intent(context, WalletActivity.class), 0));
      views.setOnClickPendingIntent(
          R.id.widget_button_request,
          PendingIntent.getActivity(
              context, 0, new Intent(context, RequestCoinsActivity.class), 0));
      views.setOnClickPendingIntent(
          R.id.widget_button_send,
          PendingIntent.getActivity(context, 0, new Intent(context, SendCoinsActivity.class), 0));
      views.setOnClickPendingIntent(
          R.id.widget_button_send_qr,
          PendingIntent.getActivity(context, 0, new Intent(context, SendCoinsQrActivity.class), 0));

      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }
Пример #17
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    // Get all ids
    ComponentName thisWidget = new ComponentName(context, MyWidgetProvider.class);
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
    for (int widgetId : allWidgetIds) {
      // Create some random data
      int number = (new Random().nextInt(100));

      RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      Log.w("WidgetExample", String.valueOf(number));
      // Set the text
      remoteViews.setTextViewText(R.id.update, String.valueOf(number));

      // Register an onClickListener
      Intent intent = new Intent(context, MyWidgetProvider.class);

      intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

      PendingIntent pendingIntent =
          PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
      appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
  }
  @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) {

      // Here we setup the intent which points to the StackViewService which will
      // provide the views for this collection.
      Intent intent = new Intent(context, StackWidgetService.class);
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
      // When intents are compared, the extras are ignored, so we need to embed the extras
      // into the data so that the extras will not be ignored.
      intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
      RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);

      // The empty view is displayed when the collection has no items. It should be a sibling
      // of the collection view.
      rv.setEmptyView(R.id.stack_view, R.id.empty_view);

      // Here we setup the a pending intent template. Individuals items of a collection
      // cannot setup their own pending intents, instead, the collection as a whole can
      // setup a pending intent template, and the individual items can set a fillInIntent
      // to create unique before on an item to item basis.
      Intent toastIntent = new Intent(context, StackWidgetProvider.class);
      toastIntent.setAction(StackWidgetProvider.TOAST_ACTION);
      toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
      intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
      PendingIntent toastPendingIntent =
          PendingIntent.getBroadcast(context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent);

      appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
  }
Пример #19
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.menu_layout);

    Intent update = new Intent(context, MenuProvider.class);
    update.setAction(CLICK_UPDATE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, update_code, update, 0);
    remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);

    Intent nextDate = new Intent(context, MenuProvider.class);
    nextDate.setAction(CLICK_NEXT);
    pendingIntent = PendingIntent.getBroadcast(context, right_code, nextDate, 0);
    remoteViews.setOnClickPendingIntent(R.id.arrow_right, pendingIntent);

    Intent previousDate = new Intent(context, MenuProvider.class);
    previousDate.setAction(CLICK_PREVIOUS);
    pendingIntent = PendingIntent.getBroadcast(context, left_code, previousDate, 0);
    remoteViews.setOnClickPendingIntent(R.id.arrow_left, pendingIntent);

    remoteViews.setRemoteAdapter(R.id.dish_list, new Intent(context, DishListService.class));
    updateDate(remoteViews, R.id.date_text, PreferenceManager.getCalendar(context));
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.appwidget.action.notify")) {
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
      int appWidgetIds[] =
          appWidgetManager.getAppWidgetIds(new ComponentName(context, TimeTableProvider.class));

      for (int i = 0; i < appWidgetIds.length; i++) {
        Intent svcIntent = new Intent(context, TimeTableWidget.class);

        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

        widget.setRemoteAdapter(appWidgetIds[i], R.id.words, svcIntent);

        Intent clickIntent = new Intent(context, MainActivity.class);
        PendingIntent clickPI =
            PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        widget.setPendingIntentTemplate(R.id.words, clickPI);

        widget.setTextViewText(R.id.weekday, TimeTableControl.today());
        appWidgetManager.updateAppWidget(appWidgetIds[i], widget);
      }
      appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.words);
    }
    super.onReceive(context, intent);
  }
Пример #21
0
  @Override
  public void onHandleIntent(Intent intent) {
    ComponentName me = new ComponentName(this, AppWidget.class);
    RemoteViews updateViews = new RemoteViews("apt.tutorial", R.layout.widget);
    RestaurantHelper helper = new RestaurantHelper(this);
    AppWidgetManager mgr = AppWidgetManager.getInstance(this);

    try {
      Cursor c = helper.getReadableDatabase().rawQuery(SQL_QUERY_COUNT, null);
      c.moveToFirst();
      int count = c.getInt(0);
      c.close();
      if (count > 0) {
        int offset = (int) (count * Math.random());
        String args[] = {String.valueOf(offset)};
        c = helper.getReadableDatabase().rawQuery(SQL_QUERY_SELECT, args);
        c.moveToFirst();
        updateViews.setTextViewText(R.id.name, c.getString(1));
        Intent i = new Intent(this, DetailForm.class);
        i.putExtra(LunchList.ID_EXTRA, c.getString(0));
        PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
        updateViews.setOnClickPendingIntent(R.id.name, pi);
        c.close();
      } else {
        updateViews.setTextViewText(R.id.title, this.getString(R.string.empty));
      }
    } finally {
      helper.close();
    }

    Intent i = new Intent(this, WidgetService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    updateViews.setOnClickPendingIntent(R.id.next, pi);
    mgr.updateAppWidget(me, updateViews);
  }
  @SuppressWarnings("deprecation")
  public static void updateAppWidget(
      Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

    Intent intent = new Intent(context, WidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    rv.setRemoteAdapter(appWidgetId, R.id.list_view, intent);

    Intent onListClickIntent = new Intent(context, WidgetProvider.class);
    onListClickIntent.setAction(ACTION_LIST_CLICK);
    onListClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    onListClickIntent.setData(Uri.parse(onListClickIntent.toUri(Intent.URI_INTENT_SCHEME)));

    final PendingIntent onListClickPendingIntent =
        PendingIntent.getBroadcast(
            context, 0, onListClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setPendingIntentTemplate(R.id.list_view, onListClickPendingIntent);

    /*
    Intent intentWidget = new Intent(context, WidgetProvider.class);
    PendingIntent pendingWidgetIntent = PendingIntent.getBroadcast(context, 0, intentWidget, PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.cb_lv_item_read_wrapper, pendingWidgetIntent);
    */

    Intent intentToDoListAct = new Intent(context, NewsReaderListActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intentToDoListAct, 0);
    rv.setOnClickPendingIntent(R.id.tV_widget_header, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetId, rv);

    if (Constants.debugModeWidget) Log.d(TAG, "updateAppWidget - WidgetID: " + appWidgetId);
  }
Пример #23
0
  @Override
  public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (intent.getAction().equals(DATA_FETCHED)) {

      int appWidgetId =
          intent.getIntExtra(
              AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

      RemoteViews remoteViews = updateWidgetListView(context, appWidgetId);

      // update and notify widget when data arrives

      appWidgetManager.updateAppWidget(appWidgetId, remoteViews);

      appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.stack_view);
    }

    if (intent.getAction().equals(TOAST_ACTION)) {
      // The click form the widget item is received here
      int appWidgetId =
          intent.getIntExtra(
              AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
      int viewIndex = intent.getIntExtra(EXTRA_ITEM, 0);
      context.startActivity(
          new Intent(context, ShowImagesActivity.class)
              .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
              .putExtra("click", "Clicked Movie is \n --- " + Constants.text[viewIndex]));
    }
  }
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int appWidgetId : appWidgetIds) {
      RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_detail);

      // Create an Intent to launch MainActivity
      Intent intent = new Intent(context, MainActivity.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
      views.setOnClickPendingIntent(R.id.widget, pendingIntent);

      // Set up the collection
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        setRemoteAdapter(context, views);
      } else {
        setRemoteAdapterV11(context, views);
      }

      // when click the Widget
      boolean useDetailActivity = context.getResources().getBoolean(R.bool.use_detail_activity);
      Intent clickIntentTemplate =
          useDetailActivity
              ? new Intent(context, MainActivity.class)
              : new Intent(context, MainActivity.class);
      PendingIntent clickPendingIntentTemplate =
          TaskStackBuilder.create(context)
              .addNextIntentWithParentStack(clickIntentTemplate)
              .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
      views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
      views.setEmptyView(R.id.widget_list, R.id.widget_empty);

      // Tell the AppWidgetManager to perform an update on the current app widget
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }
Пример #25
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    for (int i = 0; i < appWidgetIds.length; i++) {
      // Setup the widget, and data source / adapter
      Intent svcIntent = new Intent(context, DDWidgetService.class);

      svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
      svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

      RemoteViews widget;

      SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

      if (sp.getString("theme", "Light").equals("Light")) {
        widget = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      } else {
        widget = new RemoteViews(context.getPackageName(), R.layout.widget_layout_dark);
      }

      widget.setRemoteAdapter(R.id.listView, svcIntent);

      Intent clickIntent = new Intent(context, ClickHandlingActivity.class);
      PendingIntent clickPI =
          PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);

      widget.setPendingIntentTemplate(R.id.listView, clickPI);

      appWidgetManager.updateAppWidget(appWidgetIds[i], widget);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);
  }
Пример #26
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { //
    Cursor c =
        context.getContentResolver().query(StatusProvider.CONTENT_URI, null, null, null, null); //
    try {
      if (c.moveToFirst()) { //
        CharSequence user = c.getString(c.getColumnIndex(StatusData.C_USER)); //
        CharSequence createdAt =
            DateUtils.getRelativeTimeSpanString(
                context, c.getLong(c.getColumnIndex(StatusData.C_CREATED_AT)));
        CharSequence message = c.getString(c.getColumnIndex(StatusData.C_TEXT));

        // Loop through all instances of this widget
        for (int appWidgetId : appWidgetIds) { //
          Log.d(TAG, "Updating widget " + appWidgetId);
          RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.yamba_widget); //
          views.setTextViewText(R.id.textUser, user); //
          views.setTextViewText(R.id.textCreatedAt, createdAt);
          views.setTextViewText(R.id.textText, message);
          views.setOnClickPendingIntent(
              android.R.drawable.btn_default,
              PendingIntent.getActivity(
                  context, 0, new Intent(context, TimelineActivity.class), 0));
          appWidgetManager.updateAppWidget(appWidgetId, views); //
        }
      } else {
        Log.d(TAG, "No data to update");
      }
    } finally {
      c.close(); //
    }
    Log.d(TAG, "onUpdated");
  }
Пример #27
0
 private void refreshText(AppWidgetManager mgr, int widgetId) {
   RemoteViews remoteViews =
       new RemoteViews(getApplicationContext().getPackageName(), R.layout.appwidget);
   remoteViews.setViewVisibility(R.id.text, View.INVISIBLE);
   remoteViews.setViewVisibility(R.id.progress, View.VISIBLE);
   mgr.updateAppWidget(widgetId, remoteViews);
 }
Пример #28
0
 @Override
 public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
   for (int appWidgetId : appWidgetIds) {
     RemoteViews remoteViews = updateWidgetListView(context, appWidgetId);
     appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
   }
   super.onUpdate(context, appWidgetManager, appWidgetIds);
 }
Пример #29
0
 /*
  * Refresh widget
  */
 private void updateWidget(Context ctx) {
   RemoteViews rview = new RemoteViews(ctx.getPackageName(), R.layout.widget);
   ComponentName cname = new ComponentName(ctx, BlurApnSwitch.class);
   AppWidgetManager amgr = AppWidgetManager.getInstance(ctx);
   rview.setImageViewResource(
       R.id.Unknown, getApnStatus(ctx) ? R.drawable.apn_on : R.drawable.apn_off);
   makeClickable(ctx, rview);
   amgr.updateAppWidget(cname, rview);
 }
 private void setRemotes(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
   for (int id : appWidgetIds) {
     RemoteViews remoteViews = getRemoteViews(context, id, TimetableUtils.todayDate());
     if (remoteViews != null) {
       appWidgetManager.updateAppWidget(id, remoteViews);
     }
   }
   appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.list_widget);
 }