@Override
    public RemoteViews getViewAt(int position) {
      RemoteViews row = new RemoteViews(context.getPackageName(), R.layout.widget_list_item);
      cursor.moveToPosition(position);
      Log.d(TAG, "view at " + position);
      row.setTextViewText(
          R.id.score_textview,
          Utilies.getScores(
              cursor.getInt(scoresAdapter.COL_HOME_GOALS),
              cursor.getInt(scoresAdapter.COL_AWAY_GOALS)));

      row.setTextViewText(R.id.home_name, cursor.getString(scoresAdapter.COL_HOME));
      row.setTextViewText(R.id.away_name, cursor.getString(scoresAdapter.COL_AWAY));

      row.setTextViewText(R.id.data_textview, cursor.getString(scoresAdapter.COL_MATCHTIME));

      Intent fillInIntent = new Intent();
      row.setOnClickFillInIntent(R.id.list_item, fillInIntent);

      row.setImageViewResource(
          R.id.home_crest,
          Utilies.getTeamCrestByTeamName(cursor.getString(scoresAdapter.COL_HOME)));
      row.setImageViewResource(
          R.id.away_crest,
          Utilies.getTeamCrestByTeamName(cursor.getString(scoresAdapter.COL_AWAY)));
      return row;
    }
  @Override
  public RemoteViews getViewAt(int position) {
    if (position == AdapterView.INVALID_POSITION
        || mCursor == null
        || !mCursor.moveToPosition(position)) {
      return null;
    }
    RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.widget_list);

    String homeTeamName = mCursor.getString(Utilities.DATABASE_HOME_COL);
    String awayTeamName = mCursor.getString(Utilities.DATABASE_AWAY_COL);

    remoteViews.setTextViewText(R.id.home_name, homeTeamName);
    remoteViews.setTextViewText(R.id.away_name, awayTeamName);

    String score =
        mUtilities.getScores(
            mCursor.getInt(Utilities.DATABASE_HOME_GOALS_COL),
            mCursor.getInt(Utilities.DATABASE_AWAY_GOALS_COL));
    remoteViews.setTextViewText(R.id.score_textview, score);

    remoteViews.setTextViewText(R.id.data_textview, mCursor.getString(Utilities.DATABASE_TIME_COL));

    remoteViews.setImageViewResource(
        R.id.home_crest, mUtilities.getTeamCrestByTeamName(homeTeamName));
    remoteViews.setImageViewResource(
        R.id.away_crest, mUtilities.getTeamCrestByTeamName(awayTeamName));

    return remoteViews;
  }
  @Override
  public RemoteViews getViewAt(int position) {
    RemoteViews row;
    Match match = data.get(position);
    if (match.getTitle() != null) {
      row = new RemoteViews(context.getPackageName(), R.layout.widget_scores_section);
      row.setTextViewText(R.id.title, match.getTitle());
    } else {
      row = new RemoteViews(context.getPackageName(), R.layout.widget_scores_list_item);

      row.setTextViewText(R.id.home_name, match.getHome());
      row.setTextViewText(R.id.away_name, match.getAway());

      row.setImageViewResource(R.id.home_crest, match.getHomeCrest());

      row.setImageViewResource(R.id.away_crest, match.getAwayCrest());

      row.setTextViewText(R.id.data_textview, match.getMacthTime());
      row.setTextViewText(R.id.score_textview, match.getScore());
    }
    Intent fillInIntent = new Intent();
    fillInIntent.putExtra("ROW_NUMBER", position);
    row.setOnClickFillInIntent(R.id.row, fillInIntent);

    ;
    return row;
  }
  /** 带按钮的通知栏 */
  public void showButtonNotify() {
    NotificationCompat.Builder mBuilder = new Builder(this);
    RemoteViews mRemoteViews =
        new RemoteViews(getPackageName(), R.layout.activity_notification_view_custom_button);
    mRemoteViews.setImageViewResource(R.id.custom_song_icon, R.drawable.notification_sing_icon);
    // API3.0 以上的时候显示按钮,否则消失
    mRemoteViews.setTextViewText(R.id.tv_custom_song_singer, "周杰伦");
    mRemoteViews.setTextViewText(R.id.tv_custom_song_name, "七里香");
    // 如果版本号低于(3。0),那么不显示按钮
    if (BaseTools.getSystemVersion() <= 9) {
      mRemoteViews.setViewVisibility(R.id.ll_custom_button, View.GONE);
    } else {
      mRemoteViews.setViewVisibility(R.id.ll_custom_button, View.VISIBLE);
      //
      if (isPlay) {
        mRemoteViews.setImageViewResource(R.id.btn_custom_play, R.drawable.notification_btn_pause);
      } else {
        mRemoteViews.setImageViewResource(R.id.btn_custom_play, R.drawable.notification_btn_play);
      }
    }

    // 点击的事件处理
    Intent buttonIntent = new Intent(ACTION_BUTTON);
    /* 上一首按钮 */
    buttonIntent.putExtra(INTENT_BUTTONID_TAG, BUTTON_PREV_ID);
    // 这里加了广播,所及INTENT的必须用getBroadcast方法
    PendingIntent intent_prev =
        PendingIntent.getBroadcast(this, 1, buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mRemoteViews.setOnClickPendingIntent(R.id.btn_custom_prev, intent_prev);
    /* 播放/暂停 按钮 */
    buttonIntent.putExtra(INTENT_BUTTONID_TAG, BUTTON_PALY_ID);
    PendingIntent intent_paly =
        PendingIntent.getBroadcast(this, 2, buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mRemoteViews.setOnClickPendingIntent(R.id.btn_custom_play, intent_paly);
    /* 下一首 按钮 */
    buttonIntent.putExtra(INTENT_BUTTONID_TAG, BUTTON_NEXT_ID);
    PendingIntent intent_next =
        PendingIntent.getBroadcast(this, 3, buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mRemoteViews.setOnClickPendingIntent(R.id.btn_custom_next, intent_next);

    mBuilder
        .setContent(mRemoteViews)
        .setContentIntent(getDefalutIntent(Notification.FLAG_ONGOING_EVENT))
        .setWhen(System.currentTimeMillis())
        // 通知产生的时间,会在通知信息里显示
        .setTicker("正在播放")
        .setPriority(Notification.PRIORITY_DEFAULT)
        // 设置该通知优先级
        .setOngoing(true)
        .setSmallIcon(R.drawable.notification_sing_icon);
    Notification notify = mBuilder.build();
    notify.flags = Notification.FLAG_ONGOING_EVENT;
    // 会报错,还在找解决思路
    // notify.contentView = mRemoteViews;
    // notify.contentIntent = PendingIntent.getActivity(this, 0, new
    // Intent(), 0);
    mNotificationManager.notify(200, notify);
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    Intent service_start = new Intent(getApplicationContext(), myFetchService.class);
    getApplicationContext().startService(service_start);

    Cursor scores =
        getApplicationContext()
            .getContentResolver()
            .query(DatabaseContract.scores_table.buildScores(), null, null, null, null);

    scores.moveToFirst();
    String lastestHome = scores.getString(scoresAdapter.COL_HOME);
    String lastestAway = scores.getString(scoresAdapter.COL_AWAY);
    Integer lastestScoreHome = scores.getInt(scoresAdapter.COL_HOME_GOALS);
    Integer lastestScoreAway = scores.getInt(scoresAdapter.COL_AWAY_GOALS);
    String lastestMatchTime = scores.getString(scoresAdapter.COL_MATCHTIME);

    // Retrieve all of the Today widget ids: these are the widgets we need to update
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds =
        appWidgetManager.getAppWidgetIds(new ComponentName(this, ScoreWidgetProvider.class));

    for (int appWidgetId : appWidgetIds) {
      int layoutId = R.layout.widget_score_small;
      RemoteViews views = new RemoteViews(getPackageName(), layoutId);

      // views.widget_home_name.setText(cursor.getString(COL_HOME));
      views.setTextViewText(R.id.widget_home_name, lastestHome);
      views.setTextViewText(R.id.widget_away_name, lastestAway);
      views.setTextViewText(R.id.widget_date_textview, lastestMatchTime);
      views.setTextViewText(
          R.id.widget_score_textview, Utilies.getScores(lastestScoreHome, lastestScoreAway));
      views.setImageViewResource(
          R.id.widget_home_crest, Utilies.getTeamCrestByTeamName(lastestHome));
      views.setImageViewResource(
          R.id.widget_away_crest, Utilies.getTeamCrestByTeamName(lastestAway));

      // Add the data to the RemoteViews
      // Content Descriptions for RemoteViews were only added in ICS MR1
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        views.setContentDescription(
            R.id.widget_score_textview,
            "Score " + Utilies.getScores(lastestScoreHome, lastestScoreAway));
        views.setContentDescription(R.id.widget_date_textview, "Time " + lastestMatchTime);
      }

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

      // Tell the AppWidgetManager to perform an update on the current app widget
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }
Example #6
0
  private void setupView() {
    progressBar = (ProgressBar) findViewById(R.id.download_progress);
    //		btn_confirm = (Button)findViewById(R.id.btn_confirm);
    btn_cancel = (Button) findViewById(R.id.btn_cancel);
    //		btn_confirm.setOnClickListener(buttonclick);
    btn_cancel.setOnClickListener(buttonclick);

    if ("0".equals(mInfo.updateForce)) {
      btn_cancel.setVisibility(View.GONE);
    }

    server_des = (TextView) findViewById(R.id.server_des);
    progress_text = (TextView) findViewById(R.id.progress_text);
    TextView updateDesc = (TextView) findViewById(R.id.updateDesc);
    StringBuilder desc = new StringBuilder("当前版本:").append(mInfo.localVersion).append("\n");
    desc.append("服务器版本:").append(mInfo.latestVersion);
    updateDesc.setText(desc);
    server_des.setText(mInfo.updateDesc);

    manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    view = new RemoteViews(getPackageName(), R.layout.upgrade_progress_notice);
    Intent intent = new Intent(this, DownloadView.class);
    pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.contentView = view;
    notification.contentIntent = pIntent;
    // 通知的图标必须设置(其他属性为可选设置),否则通知无法显示
    notification.icon = R.drawable.ic_launcher;
    view.setImageViewResource(R.id.image, R.drawable.ic_launcher); // 起一个线程用来更新progress
  }
Example #7
0
  private void loadAlarm() {
    remoteViews.setImageViewResource(R.id.alarm_image, R.drawable.icon);
    nextAlarm =
        Settings.System.getString(this.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED);
    Pattern hourPattern = Pattern.compile("([01]?[0-9]|2[0-3]):[0-5][0-9]");
    Pattern dayPatternEs = Pattern.compile("^[A-Za-z\u00e1]{2}");
    Pattern dayPatternEn = Pattern.compile("^[A-Za-z]{2}");
    Pattern dayPatternRu = Pattern.compile("^[\u0410-\u044f]{2}");
    Matcher hourMatcher = hourPattern.matcher(nextAlarm);
    Matcher dayMatcherEs = dayPatternEs.matcher(nextAlarm);
    Matcher dayMatcherEn = dayPatternEn.matcher(nextAlarm);
    Matcher dayMatcherRu = dayPatternRu.matcher(nextAlarm);

    if (hourMatcher.find()) {
      hour = hourMatcher.group();
    }

    if (dayMatcherEn.find()) {
      day = util.dayFormattedToDay(dayMatcherEn.group(), hour);
    } else if (dayMatcherRu.find()) {
      day = util.dayFormattedToDay(dayMatcherRu.group(), hour);
    } else if (dayMatcherEs.find()) {
      day = util.dayFormattedToDay(dayMatcherEs.group(), hour);
    } else {
      day = this.getString(R.string.withoutDay);
    }
  }
Example #8
0
 private void freshAnim(final Context context) { // 刷新的帧动画
   final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.weather_widget);
   views.setViewVisibility(R.id.pb_fresh_weather, View.VISIBLE);
   views.setImageViewResource(R.id.iv_fresh_weather, R.drawable.weather_widget_icon_yin_l);
   ComponentName provider = new ComponentName(context, WeatherWidget.class);
   AppWidgetManager.getInstance(context).updateAppWidget(provider, views);
 }
  private void updateWeatherData(
      Context context,
      AppWidgetManager appWidgetManager,
      int[] allWidgetIds,
      CityWeather cityWeather) {

    for (int id : allWidgetIds) {
      RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_weather);

      remoteViews.setTextViewText(R.id.location_text_widget, cityWeather.name);

      String description = cityWeather.weathers[0].description;
      if (description.contains("clear")) {
        remoteViews.setImageViewResource(R.id.icon_image_widget, R.drawable.clear);
      } else if (description.contains("rain")) {
        remoteViews.setImageViewResource(R.id.icon_image_widget, R.drawable.rain);
      } else if (description.contains("cloud")) {
        remoteViews.setImageViewResource(R.id.icon_image_widget, R.drawable.cloud);
      } else if (description.contains("snow")) {
        remoteViews.setImageViewResource(R.id.icon_image_widget, R.drawable.snow);
      } else if (description.contains("mist") || description.contains("haze")) {
        remoteViews.setImageViewResource(R.id.icon_image_widget, R.drawable.mist);
      }

      remoteViews.setTextViewText(
          R.id.temperature_text_widget, Utils.temperatureFormat(cityWeather.main.temp));
      remoteViews.setTextViewText(R.id.description_text_widget, description);

      // Register an onClickListener
      /*
      Intent clickIntent = new Intent(context, WeatherWidgetProvider.class);

      clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
      clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,
              allWidgetIds);

      PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, clickIntent,
              PendingIntent.FLAG_UPDATE_CURRENT);
      remoteViews.setOnClickPendingIntent(R.id.layout_widget, pendingIntent);
      */
      Intent configIntent = new Intent(context, MainActivity.class);
      PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);
      remoteViews.setOnClickPendingIntent(R.id.layout_widget, configPendingIntent);

      appWidgetManager.updateAppWidget(id, remoteViews);
    }
  }
  ///////////////////////////////////////////////////////////////////////////////
  // Setup the notification
  private void initNotification() {

    Intent resultIntent = new Intent(this, MainActivity.class);
    PendingIntent resultPendingIntent =
        PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, 0);

    PendingIntent toggleIntent = makePendingIntent(PlayService.class, NO_ACTION_TOGGLE_PLAY);
    PendingIntent nextIntent = makePendingIntent(PlayService.class, NO_ACTION_NEXT);
    PendingIntent prevIntent = makePendingIntent(PlayService.class, NO_ACTION_PREVIOUS);
    PendingIntent stopIntent = makePendingIntent(PlayService.class, NO_ACTION_STOP);

    notifiExpandView = new RemoteViews(getPackageName(), R.layout.notification_expanded);

    notifiExpandView.setTextViewText(R.id.lblNotificationTitle, currentSong.title);
    notifiExpandView.setImageViewResource(R.id.notificationAlbum, R.drawable.earth);
    notifiExpandView.setTextViewText(R.id.lblNotificationArtist, currentSong.artist);
    notifiExpandView.setTextViewText(R.id.lblNotificationAlbum, currentSong.album);
    notifiExpandView.setOnClickPendingIntent(R.id.btnPlay_pause, toggleIntent);
    notifiExpandView.setOnClickPendingIntent(R.id.btnNext, nextIntent);
    notifiExpandView.setOnClickPendingIntent(R.id.btnPrevious, prevIntent);
    notifiExpandView.setOnClickPendingIntent(R.id.btnNotificationStop, stopIntent);

    notifiSmallView = new RemoteViews(getPackageName(), R.layout.notification_small);

    notifiSmallView.setTextViewText(R.id.lblNotificationTitle, currentSong.title);
    notifiSmallView.setImageViewResource(R.id.notificationAlbum, R.drawable.earth);
    notifiSmallView.setTextViewText(
        R.id.lblNotificationAlbumArtist, currentSong.artist + " - " + currentSong.album);
    notifiSmallView.setOnClickPendingIntent(R.id.btnPlay_pause, toggleIntent);
    notifiSmallView.setOnClickPendingIntent(R.id.btnNext, nextIntent);
    notifiSmallView.setOnClickPendingIntent(R.id.btnPrevious, prevIntent);

    mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_action_play)
            .setOngoing(true)
            .setContentIntent(resultPendingIntent);

    notification = mBuilder.build();
    notification.bigContentView = notifiExpandView;
    notification.contentView = notifiSmallView;

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATON_ID, notification);
  }
Example #11
0
  public void playOrPause(View view) {

    if (playMusicService.getMediaPlayer().isPlaying()) {
      playPause.setImageResource(android.R.drawable.ic_media_play);
      playMusicService.getMediaPlayer().pause();

      notificationViews.setImageViewResource(
          R.id.playPauseButtomNotify, android.R.drawable.ic_media_play);
      notificationManager.notify(NOTIFICATION_ID, builder.build());
    } else {
      playPause.setImageResource(android.R.drawable.ic_media_pause);
      playMusicService.getMediaPlayer().start();

      notificationViews.setImageViewResource(
          R.id.playPauseButtomNotify, android.R.drawable.ic_media_pause);
      notificationManager.notify(NOTIFICATION_ID, builder.build());
    }
  }
 /*
  * 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 updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    int layoutId = getLayoutId(context, appWidgetManager, appWidgetId);

    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    RemoteViews views = new RemoteViews(context.getPackageName(), layoutId);
    views.setOnClickPendingIntent(R.id.widget_background, pendingIntent);
    views.setTextViewText(R.id.home_name, mLatestHome);
    views.setTextViewText(R.id.away_name, mLatestAway);
    views.setTextViewText(R.id.score_textview, mLatestScore);
    views.setTextViewText(R.id.data_textview, mLatestTime);
    views.setImageViewResource(
        R.id.home_crest, Utilies.getTeamCrestByTeamName(context.getResources(), mLatestHome));
    views.setImageViewResource(
        R.id.away_crest, Utilies.getTeamCrestByTeamName(context.getResources(), mLatestAway));

    appWidgetManager.updateAppWidget(appWidgetId, views);
  }
Example #14
0
  public static void updateNotification(Context context, String description, String boardToLaunch) {

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notification);
    views.setImageViewResource(R.id.play_pause, R.drawable.play_pause);
    views.setTextViewText(R.id.description, " " + description);

    File icon = new File(mSbDir, boardToLaunch + "/icon.png");
    if (icon.exists()) {
      Bitmap bitmap = IconUtils.decodeIcon(context, icon);
      views.setImageViewBitmap(R.id.icon, bitmap);
    } else {
      views.setImageViewResource(R.id.icon, R.drawable.board_icon);
    }

    Intent pauseIntent = new Intent(context, TogglePlayPauseService.class);
    PendingIntent pausePendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
    views.setOnClickPendingIntent(R.id.play_pause, pausePendingIntent);

    final Intent notificationIntent = new Intent(context, SoundboardMenu.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

    if (boardToLaunch != null) {
      notificationIntent.putExtra(SoundboardMenu.EXTRA_LAUNCH_BAORD_KEY, boardToLaunch);
    }

    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification.Builder builder =
        new Notification.Builder(context)
            .setOngoing(true)
            .setSmallIcon(R.drawable.icon)
            .setAutoCancel(false)
            .setTicker("Boarder")
            .setContentText(description)
            .setContentIntent(pendingIntent)
            .setContent(views);

    final NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(SoundboardMenu.TAG, mNotificationId, builder.getNotification());
  }
Example #15
0
 public void pickImage(int pow, int time) {
   if (time == 1 && pow == 0) {
     remoteViews.setImageViewResource(views[pow], R.drawable.dot_active);
     return;
   } else if (time == 0 && pow == 0) {
     remoteViews.setImageViewResource(views[pow], R.drawable.dot_inactive);
     return;
   }
   if (time >= (int) java.lang.Math.pow(2, pow) * 60) {
     remoteViews.setImageViewResource(views[pow], R.drawable.dot_active);
     time = time - ((int) java.lang.Math.pow(2, pow) * 60);
     // Log.d(null,"Time: "+time + " and " + pow);
   } else {
     remoteViews.setImageViewResource(views[pow], R.drawable.dot_inactive);
   }
   if (pow == 0) {
     return;
   }
   pickImage((pow - 1), time);
 }
Example #16
0
 /**
  * 自定义通知
  *
  * @param builder
  * @return
  */
 private NotificationCompat.Builder selfDefindNotification(NotificationCompat.Builder builder) {
   // 得到自定义通知布局文件对象
   RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notificatoindemo03);
   // 给布局文件对象属性设置值
   remoteViews.setImageViewResource(R.id.myselfnotificationIV, R.drawable.icon);
   remoteViews.setTextViewText(R.id.myselfnoticationTV1, "消息");
   remoteViews.setTextViewText(R.id.myselfnoticationTV2, "要放假了");
   // 把布局对象放入到通知的内容中
   builder.setContent(remoteViews);
   return builder;
 }
  /**
   * Changes the playback controls in and out of a paused state
   *
   * @param isPlaying True if music is playing, false otherwise
   */
  public void updatePlayState(final boolean isPlaying) {
    if (mNotification == null || mNotificationManager == null) {
      return;
    }
    if (mNotificationTemplate != null) {
      mNotificationTemplate.setImageViewResource(
          R.id.notification_base_play,
          isPlaying
              ? R.drawable.btn_notification_playback_pause
              : R.drawable.btn_notification_playback_play);
    }

    if (mExpandedView != null) {
      mExpandedView.setImageViewResource(
          R.id.notification_expanded_base_play,
          isPlaying
              ? R.drawable.btn_notification_playback_pause
              : R.drawable.btn_notification_playback_play);
    }
    mNotificationManager.notify(APOLLO_MUSIC_SERVICE, mNotification);
  }
  @Override
  public RemoteViews getViewAt(int position) {

    RemoteViews mView = new RemoteViews(mContext.getPackageName(), R.layout.scores_list_item);

    if (cursor != null) {
      if (cursor.moveToPosition(position)) {
        String dir = cursor.getString(cursor.getColumnIndex("date"));

        mView.setTextViewText(R.id.home_name, "" + cursor.getString(COL_HOME));
        mView.setTextViewText(R.id.away_name, "" + cursor.getString(COL_AWAY));
        mView.setTextViewText(R.id.data_textview, "" + cursor.getString(COL_DATE));
        mView.setTextViewText(
            R.id.score_textview,
            "" + Utilies.getScores(cursor.getInt(COL_HOME_GOALS), cursor.getInt(COL_AWAY_GOALS)));
        mView.setImageViewResource(
            R.id.home_crest, Utilies.getTeamCrestByTeamName(cursor.getString(COL_HOME)));
        mView.setImageViewResource(
            R.id.away_crest, Utilies.getTeamCrestByTeamName(cursor.getString(COL_AWAY)));
      }
    }

    final Intent fillInIntent = new Intent();
    fillInIntent.setAction(WidgetProvider.ACTION_OPEN_ACTIVITY);
    final Bundle bundle = new Bundle();

    bundle.putString(WidgetProvider.EXTRA_HOME_NAME, cursor.getString(COL_HOME));
    bundle.putString(WidgetProvider.EXTRA_AWAY_NAME, cursor.getString(COL_AWAY));
    bundle.putString(
        WidgetProvider.EXTRA_SCORE,
        Utilies.getScores(cursor.getInt(COL_HOME_GOALS), cursor.getInt(COL_AWAY_GOALS)));
    bundle.putString(WidgetProvider.EXTRA_DATE, cursor.getString(COL_DATE));
    bundle.putInt(WidgetProvider.EXTRA_MATCH_DAY, cursor.getInt(COL_MATCH_DAY));
    bundle.putInt(WidgetProvider.EXTRA_LEAGUE, cursor.getInt(COL_LEAGUE));
    fillInIntent.putExtras(bundle);
    mView.setOnClickFillInIntent(R.id.widget_id, fillInIntent);

    return mView;
  }
Example #19
0
 private static RemoteViews updateWidgetFromAccount(
     Context context, int widgetId, int layoutId, Class providerClass, Account a) {
   RemoteViews updateViews = new RemoteViews(context.getPackageName(), layoutId);
   updateViews.setTextViewText(R.id.line1, a.title);
   AccountType type = AccountType.valueOf(a.type);
   if (type.isCard && a.cardIssuer != null) {
     CardIssuer cardIssuer = CardIssuer.valueOf(a.cardIssuer);
     updateViews.setImageViewResource(R.id.account_icon, cardIssuer.iconId);
   } else {
     updateViews.setImageViewResource(R.id.account_icon, type.iconId);
   }
   long amount = a.totalAmount;
   updateViews.setTextViewText(R.id.note, Utils.amountToString(a.currency, amount));
   Utils u = new Utils(context);
   int amountColor = u.getAmountColor(amount);
   updateViews.setTextColor(R.id.note, amountColor);
   addScrollOnClick(context, updateViews, widgetId, providerClass);
   addTapOnClick(context, updateViews);
   addButtonsClick(context, updateViews);
   saveAccountForWidget(context, widgetId, a.id);
   return updateViews;
 }
Example #20
0
 private void initNofication() {
   notificationManager =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   notification = new Notification();
   notification.icon = R.drawable.ic_launcher; //
   notification.tickerText = "正在下载,请稍后!"; //
   Intent intent = new Intent();
   intent.setClass(context, Ri.class);
   PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
   notification.contentIntent = contentIntent;
   notificationViews = new RemoteViews(context.getPackageName(), R.layout.down_notification);
   notificationViews.setImageViewResource(R.id.download_icon, R.drawable.ic_launcher);
 }
  /** If there are actions, shows the button related views, and adds a button for each action. */
  private void addActionButtons(RemoteViews bigView) {
    // Remove the existing buttons in case an existing notification is being updated.
    bigView.removeAllViews(R.id.buttons);

    // Always set the visibility of the views associated with the action buttons. The current
    // visibility state is not known as perhaps an existing notification is being updated.
    int visibility = mActions.isEmpty() ? View.GONE : View.VISIBLE;
    bigView.setViewVisibility(R.id.button_divider, visibility);
    bigView.setViewVisibility(R.id.buttons, visibility);

    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    for (Action action : mActions) {
      RemoteViews view =
          new RemoteViews(mContext.getPackageName(), R.layout.web_notification_button);

      // If there is an icon then set it and add some padding.
      if (action.iconBitmap != null || action.iconId != 0) {
        if (useMaterial()) {
          view.setInt(R.id.button_icon, "setColorFilter", BUTTON_ICON_COLOR_MATERIAL);
        }

        int iconWidth = 0;
        if (action.iconBitmap != null) {
          view.setImageViewBitmap(R.id.button_icon, action.iconBitmap);
          iconWidth = action.iconBitmap.getWidth();
        } else if (action.iconId != 0) {
          view.setImageViewResource(R.id.button_icon, action.iconId);
          BitmapFactory.Options options = new BitmapFactory.Options();
          options.inJustDecodeBounds = true;
          BitmapFactory.decodeResource(resources, action.iconId, options);
          iconWidth = options.outWidth;
        }
        iconWidth = dpToPx(Math.min(pxToDp(iconWidth, metrics), MAX_ACTION_ICON_WIDTH_DP), metrics);

        // Set the padding of the button so the text does not overlap with the icon. Flip
        // between left and right manually as RemoteViews does not expose a method that sets
        // padding in a writing-direction independent way.
        int buttonPadding =
            dpToPx(BUTTON_PADDING_START_DP + BUTTON_ICON_PADDING_DP, metrics) + iconWidth;
        int buttonPaddingLeft = LocalizationUtils.isLayoutRtl() ? 0 : buttonPadding;
        int buttonPaddingRight = LocalizationUtils.isLayoutRtl() ? buttonPadding : 0;
        view.setViewPadding(R.id.button, buttonPaddingLeft, 0, buttonPaddingRight, 0);
      }

      view.setTextViewText(R.id.button, action.title);
      view.setOnClickPendingIntent(R.id.button, action.intent);
      bigView.addView(R.id.buttons, view);
    }
  }
  private void addPendingIntents(RemoteViews rv, boolean isPlaying, MediaInfo info) {
    Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK);
    playbackIntent.setPackage(getPackageName());
    PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0);

    Intent stopIntent = new Intent(ACTION_STOP);
    stopIntent.setPackage(getPackageName());
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);

    rv.setOnClickPendingIntent(R.id.playPauseView, playbackPendingIntent);
    rv.setOnClickPendingIntent(R.id.removeView, stopPendingIntent);

    if (isPlaying) {
      if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) {
        rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark);
      } else {
        rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_pause_sm_dark);
      }

    } else {
      rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_play_sm_dark);
    }
  }
 @Override
 public RemoteViews getViewAt(int position) {
   scoresCursor.moveToPosition(position);
   final RemoteViews remoteViews =
       new RemoteViews(context.getPackageName(), R.layout.scores_list_item);
   remoteViews.setTextViewText(R.id.home_name, scoresCursor.getString(ScoresAdapter.COL_HOME));
   remoteViews.setTextViewText(R.id.away_name, scoresCursor.getString(ScoresAdapter.COL_AWAY));
   remoteViews.setTextViewText(
       R.id.data_textview, scoresCursor.getString(ScoresAdapter.COL_MATCHTIME));
   remoteViews.setTextViewText(
       R.id.score_textview,
       Utilities.getScores(
           scoresCursor.getInt(ScoresAdapter.COL_HOME_GOALS),
           scoresCursor.getInt(ScoresAdapter.COL_AWAY_GOALS)));
   remoteViews.setImageViewResource(
       R.id.home_crest,
       Utilities.getTeamCrestByTeamName(
           context, scoresCursor.getString(ScoresAdapter.COL_HOME)));
   remoteViews.setImageViewResource(
       R.id.away_crest,
       Utilities.getTeamCrestByTeamName(
           context, scoresCursor.getString(ScoresAdapter.COL_AWAY)));
   return remoteViews;
 }
  // Init notification UI.
  private void initNotifyView(
      Context context,
      RemoteViews panelView,
      ChatMsgBaseInfo message,
      ContactInfo contact,
      Bitmap srcPhoto) {
    if (contact != null) {
      Bitmap photo = ImageLoaderManager.createCircleImage(srcPhoto);
      if (photo != null) {
        panelView.setViewVisibility(R.id.notify_profile_logogram_tv, View.GONE);
        panelView.setViewVisibility(R.id.notify_profile_iv, View.VISIBLE);
        panelView.setImageViewBitmap(R.id.notify_profile_iv, photo);
      } else {
        panelView.setViewVisibility(R.id.notify_profile_iv, View.VISIBLE);
        panelView.setImageViewResource(
            R.id.notify_profile_iv, CommonUtils.getPhotoBgResId(contact.getUsername()));
        panelView.setViewVisibility(R.id.notify_profile_logogram_tv, View.VISIBLE);
        panelView.setTextViewText(
            R.id.notify_profile_logogram_tv,
            contact.getUsername().substring(contact.getUsername().length() - 1));
      }
      panelView.setTextViewText(R.id.notify_sender_tv, contact.getUsername());
    } else {
      panelView.setTextViewText(R.id.notify_sender_tv, message.getContact());
      panelView.setViewVisibility(R.id.notify_profile_logogram_tv, View.GONE);
      panelView.setViewVisibility(R.id.notify_profile_iv, View.VISIBLE);
      panelView.setImageViewResource(R.id.notify_profile_iv, R.drawable.contact_default_profile);
    }

    // TODO: ADD Emoji parser later.
    // panelView.setTextViewText(R.id.notify_msg_content_tv,
    // EmojiParser.getInstance(context).getSmileyText(message.getData()));
    panelView.setTextViewText(R.id.notify_msg_content_tv, message.getData());
    panelView.setTextViewText(
        R.id.notify_time_tv, TimeFormattedUtil.getDetailDisplayTime(context, message.getTime()));
  }
  /** 创建挂机图标 */
  @SuppressWarnings("deprecation")
  public void showNotification() {
    if (!mSpUtil.getMsgNotify()) // 如果用户设置不显示挂机图标,直接返回
    return;

    // int icon = R.drawable.notify_general;
    int icon = R.drawable.app_icon;

    // CharSequence tickerText = getResources().getString(
    // R.string.app_is_run_background);
    CharSequence tickerText = "App is running in the background";

    long when = System.currentTimeMillis();
    mNotification = new Notification(icon, tickerText, when);

    // 放置在"正在运行"栏目中
    mNotification.flags = Notification.FLAG_ONGOING_EVENT;

    RemoteViews contentView =
        new RemoteViews(getPackageName(), R.layout.notify_status_bar_latest_event_view);

    contentView.setImageViewResource(R.id.icon, heads[2]);

    contentView.setTextViewText(R.id.title, mSpUtil.getNick());
    contentView.setTextViewText(R.id.text, tickerText);
    contentView.setLong(R.id.time, "setTime", when);
    // 指定个性化视图
    mNotification.contentView = contentView;

    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    // 指定内容意图
    mNotification.contentIntent = contentIntent;
    // 下面是4.0notify
    // Bitmap icon = BitmapFactory.decodeResource(getResources(),
    // heads[mSpUtil.getHeadIcon()]);
    // Notification.Builder notificationBuilder = new Notification.Builder(
    // this).setContentTitle(mSpUtil.getNick())
    // .setContentText(tickerText)
    // .setSmallIcon(R.drawable.notify_general)
    // .setWhen(System.currentTimeMillis())
    // .setContentIntent(contentIntent).setLargeIcon(icon);
    // Notification n = notificationBuilder.getNotification();
    // n.flags |= Notification.FLAG_NO_CLEAR;

    mNotificationManager.notify(MyPushMessageReceiver.NOTIFY_ID, mNotification);
  }
Example #26
0
        @Override
        public void handleMessage(Message msg) {
          Editor ed = settings.edit();
          switch (msg.what) {
            case MSG_CONNECT_START:
              ed.putBoolean("isConnecting", true);
              break;
            case MSG_CONNECT_FINISH:
              ed.putBoolean("isConnecting", false);
              ed.putBoolean("isSwitching", false);
              break;
            case MSG_CONNECT_SUCCESS:
              ed.putBoolean("isRunning", true);
              // stateChanged = new ConnectivityBroadcastReceiver();
              // registerReceiver(stateChanged, new IntentFilter(
              // ConnectivityManager.CONNECTIVITY_ACTION));
              break;
            case MSG_CONNECT_FAIL:
              ed.putBoolean("isRunning", false);
              break;
            case MSG_DISCONNECT_FINISH:
              ed.putBoolean("isRunning", false);
              ed.putBoolean("isSwitching", false);

              try {
                notificationManager.cancel(0);
                notificationManager.cancel(1);
              } catch (Exception ignore) {
                // Nothing
              }

              // for widget, maybe exception here
              try {
                RemoteViews views = new RemoteViews(getPackageName(), R.layout.sshtunnel_appwidget);
                views.setImageViewResource(R.id.serviceToggle, R.drawable.off);
                AppWidgetManager awm = AppWidgetManager.getInstance(SSHTunnelService.this);
                awm.updateAppWidget(
                    awm.getAppWidgetIds(
                        new ComponentName(SSHTunnelService.this, SSHTunnelWidgetProvider.class)),
                    views);
              } catch (Exception ignore) {
                // Nothing
              }
              break;
          }
          ed.commit();
          super.handleMessage(msg);
        }
 /** 显示自定义的带进度条通知栏 */
 private void showCustomProgressNotify(String status) {
   RemoteViews mRemoteViews = new RemoteViews(getPackageName(), R.layout.view_custom_progress);
   mRemoteViews.setImageViewResource(R.id.custom_progress_icon, R.drawable.icon);
   mRemoteViews.setTextViewText(R.id.tv_custom_progress_title, "今日头条");
   mRemoteViews.setTextViewText(R.id.tv_custom_progress_status, status);
   if (progress >= 100 || downloadThread == null) {
     mRemoteViews.setProgressBar(R.id.custom_progressbar, 0, 0, false);
     mRemoteViews.setViewVisibility(R.id.custom_progressbar, View.GONE);
   } else {
     mRemoteViews.setProgressBar(R.id.custom_progressbar, 100, progress, false);
     mRemoteViews.setViewVisibility(R.id.custom_progressbar, View.VISIBLE);
   }
   mBuilder.setContent(mRemoteViews).setContentIntent(getDefalutIntent(0)).setTicker("头条更新");
   Notification nitify = mBuilder.build();
   nitify.contentView = mRemoteViews;
   mNotificationManager.notify(notifyId, nitify);
 }
  public void initNotif() {
    mDownProgrNotif = new Notification();
    mDownProgrNotif.icon = android.R.drawable.stat_sys_download;
    mDownProgrNotif.flags |= Notification.FLAG_ONGOING_EVENT;

    mRemoteViews = new RemoteViews(mPackageHelper.getPackageName(), layout_id);
    mRemoteViews.setImageViewResource(icon_id, mPackageHelper.getAppIcon());

    mDownProgrNotif.contentView = mRemoteViews;
    Intent intent = null;
    if (clazz != null) {
      intent = new Intent(ApplicationBean.getApplication(), clazz);
    }
    mDownProgrNotif.contentIntent =
        PendingIntent.getService(mContext, 0, intent == null ? new Intent() : intent, 0);
    //		mContextNotificationManager.notify(id, mDownProgrNotif);
  }
Example #29
0
  public RemoteViews buildUpdate(int position) {
    try {
      Task task = getTask(position);

      String textContent;
      Resources r = context.getResources();
      int textColor =
          r.getColor(dark ? R.color.widget_text_color_dark : R.color.widget_text_color_light);

      textContent = task.getTitle();

      RemoteViews row = new RemoteViews(Constants.PACKAGE, R.layout.widget_row);

      if (task.isCompleted()) {
        textColor = r.getColor(R.color.task_list_done);
        row.setInt(R.id.text, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
      } else {
        row.setInt(R.id.text, "setPaintFlags", Paint.ANTI_ALIAS_FLAG);
        if (task.hasDueDate() && task.isOverdue()) {
          textColor = r.getColor(R.color.task_list_overdue);
        }
      }

      row.setTextViewText(R.id.text, textContent);
      row.setTextColor(R.id.text, textColor);
      row.setImageViewResource(R.id.completeBox, getCheckbox(task));

      Intent editIntent = new Intent();
      editIntent.setAction(TasksWidget.EDIT_TASK);
      editIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId());
      editIntent.putExtra(TaskListActivity.OPEN_TASK, task.getId());
      row.setOnClickFillInIntent(R.id.text, editIntent);

      Intent completeIntent = new Intent();
      completeIntent.setAction(TasksWidget.COMPLETE_TASK);
      completeIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId());
      row.setOnClickFillInIntent(R.id.completeBox, completeIntent);

      return row;
    } catch (Exception e) {
      // can happen if database is not ready
      Log.e("WIDGET-UPDATE", "Error updating widget", e);
    }

    return null;
  }
Example #30
0
 private void showNotification(Context context) {
   NotificationManager nm =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   int icon = R.drawable.ic_launcher;
   String tickerText = "";
   long when = System.currentTimeMillis();
   Intent it = new Intent(context, NotiActivity.class);
   PendingIntent contentIntent = PendingIntent.getActivity(context, 0, it, 0);
   RemoteViews remoteview = new RemoteViews(context.getPackageName(), R.layout.alarmitem);
   remoteview.setImageViewResource(R.id.alarmimage, R.drawable.alarm);
   remoteview.setTextViewText(R.id.showalarmtime, message);
   Notification notic = new Notification(icon, tickerText, when);
   notic.defaults = Notification.DEFAULT_ALL;
   notic.contentIntent = contentIntent;
   notic.contentView = remoteview;
   notic.flags = Notification.FLAG_NO_CLEAR;
   nm.notify(0, notic);
 }