예제 #1
0
  private InternalWidget.WidgetData GenWidget(String widget_id) {
    InternalWidget.WidgetData widget = new InternalWidget.WidgetData();

    widget.priority = meetingTime.equals("None") ? 0 : 1;

    String iconFile = "idle_calendar.bmp";
    if (widget_id.equals(id_0)) {
      widget.id = id_0;
      widget.description = desc_0;
      widget.width = 24;
      widget.height = 32;
    } else if (widget_id.equals(id_1)) {
      widget.id = id_1;
      widget.description = desc_1;
      widget.width = 96;
      widget.height = 32;
    } else if (widget_id.equals(id_2)) {
      widget.id = id_2;
      widget.description = desc_2;
      widget.width = 16;
      widget.height = 16;
      iconFile = "idle_calendar_10.bmp";
    } else if (widget_id.equals(id_3)) {
      widget.id = id_3;
      widget.description = desc_3;
      widget.width = 80;
      widget.height = 16;
      iconFile = "idle_calendar_10.bmp";
    } else if (widget_id.equals(id_4)) {
      widget.id = id_4;
      widget.description = desc_4;
      widget.width = 48;
      widget.height = 32;
      iconFile = null;
    } else if (widget_id.equals(id_5)) {
      widget.id = id_5;
      widget.description = desc_5;
      widget.width = 40;
      widget.height = 16;
      iconFile = null;
    }

    Bitmap icon = iconFile == null ? null : Utils.getBitmap(context, iconFile);

    widget.bitmap = Bitmap.createBitmap(widget.width, widget.height, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(widget.bitmap);
    canvas.drawColor(Color.WHITE);

    if (widget.height == 16 && icon != null) {
      if (icon != null) canvas.drawBitmap(icon, widget.width == 16 ? 2 : 0, 0, null);
      if (meetingTime.equals("None"))
        canvas.drawText("-", widget.width == 16 ? 8 : 6, 15, paintSmallNumerals);
      else {
        // Strip out colon to make it fit;
        String time = meetingTime.replace(":", "");

        if (widget.width == 16) {
          canvas.drawText(time, 8, 15, paintSmallNumerals);
        } else {
          paintSmallNumerals.setTextAlign(Align.LEFT);
          canvas.drawText(time, 0, 15, paintSmallNumerals);
          paintSmallNumerals.setTextAlign(Align.CENTER);
        }
      }
    } else if (icon != null) {
      canvas.drawBitmap(icon, 0, 3, null);

      if ((Preferences.displayLocationInSmallCalendarWidget)
          && (!meetingTime.equals("None"))
          && (meetingLocation != null)
          && (!meetingLocation.equals("---"))
          && (widget_id.equals(id_0))
          && (meetingLocation.length() > 0)
          && (meetingLocation.length() <= 3)) {
        canvas.drawText(meetingLocation, 12, 15, paintSmall);
      } else {
        Calendar c = Calendar.getInstance();
        if ((Preferences.eventDateInCalendarWidget) && (!meetingTime.equals("None"))) {
          c.setTimeInMillis(meetingStartTimestamp);
        }
        int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);
        if (dayOfMonth < 10) {
          canvas.drawText("" + dayOfMonth, 12, 16, paintNumerals);
        } else {
          canvas.drawText("" + dayOfMonth / 10, 9, 16, paintNumerals);
          canvas.drawText("" + dayOfMonth % 10, 15, 16, paintNumerals);
        }
      }
      canvas.drawText(meetingTime, 12, 30, paintSmall);
    }

    String text = "";
    if (iconFile == null) text = meetingTime;
    if ((meetingTitle != null)) {
      if (text.length() > 0) text += " : ";
      text += meetingTitle;
    }
    if ((meetingLocation != null) && (meetingLocation.length() > 0))
      text += " - " + meetingLocation;

    if (widget_id.equals(id_1) || widget_id.equals(id_4)) {

      paintSmall.setTextAlign(Align.LEFT);

      int iconSpace = iconFile == null ? 0 : 25;

      canvas.save();
      StaticLayout layout =
          new StaticLayout(
              text,
              paintSmall,
              widget.width - iconSpace,
              Layout.Alignment.ALIGN_CENTER,
              1.2f,
              0,
              false);
      int height = layout.getHeight();
      int textY = 16 - (height / 2);
      if (textY < 0) {
        textY = 0;
      }
      canvas.translate(iconSpace, textY); // position the text
      layout.draw(canvas);
      canvas.restore();

      paintSmall.setTextAlign(Align.CENTER);
    } else if (widget_id.equals(id_3) || widget_id.equals(id_5)) {
      paintSmall.setTextAlign(Align.LEFT);

      int iconSpace = iconFile == null ? 0 : 11;

      canvas.save();
      StaticLayout layout =
          new StaticLayout(
              text,
              paintSmall,
              widget.width - iconSpace,
              Layout.Alignment.ALIGN_CENTER,
              1.0f,
              0,
              false);
      int height = layout.getHeight();
      int textY = 8 - (height / 2);
      if (textY < 0) {
        textY = 0;
      }
      canvas.translate(iconSpace, textY); // position the text
      layout.draw(canvas);
      canvas.restore();

      paintSmall.setTextAlign(Align.CENTER);
    }

    return widget;
  }
예제 #2
0
  public Bitmap update(Context context, boolean preview, int watchType) {

    TextPaint paintSmall = new TextPaint();
    paintSmall.setColor(Color.BLACK);
    paintSmall.setTextSize(FontCache.instance(context).Small.size);
    paintSmall.setTypeface(FontCache.instance(context).Small.face);

    TextPaint paintSmallOutline = new TextPaint();
    paintSmallOutline.setColor(Color.WHITE);
    paintSmallOutline.setTextSize(FontCache.instance(context).Small.size);
    paintSmallOutline.setTypeface(FontCache.instance(context).Small.face);

    TextPaint paintLarge = new TextPaint();
    paintLarge.setColor(Color.BLACK);
    paintLarge.setTextSize(FontCache.instance(context).Large.size);
    paintLarge.setTypeface(FontCache.instance(context).Large.face);

    TextPaint paintLargeOutline = new TextPaint();
    paintLargeOutline.setColor(Color.WHITE);
    paintLargeOutline.setTextSize(FontCache.instance(context).Large.size);
    paintLargeOutline.setTypeface(FontCache.instance(context).Large.face);

    MediaControl.TrackInfo lastTrack = MediaControl.getLastTrack();

    if (watchType == WatchType.DIGITAL) {

      Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);
      canvas.drawColor(Color.WHITE);

      if (lastTrack.isEmpty()) {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player_idle.png"), 0, 0, null);
      } else {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player.png"), 0, 0, null);

        StringBuilder lowerText = new StringBuilder();
        if (!lastTrack.artist.equals("")) {
          lowerText.append(lastTrack.artist);
        }
        if (!lastTrack.album.equals("")) {
          if (lowerText.length() > 0) lowerText.append("\n\n");
          lowerText.append(lastTrack.album);
        }

        Utils.autoText(
            context,
            canvas,
            lastTrack.track,
            0,
            8,
            96,
            35,
            Layout.Alignment.ALIGN_CENTER,
            Color.BLACK);
        Utils.autoText(
            context,
            canvas,
            lowerText.toString(),
            0,
            54,
            96,
            35,
            Layout.Alignment.ALIGN_CENTER,
            Color.BLACK);
      }
      drawDigitalAppSwitchIcon(context, canvas, preview);

      return bitmap;
    } else if (watchType == WatchType.ANALOG) {
      Bitmap bitmap = Bitmap.createBitmap(80, 32, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);
      canvas.drawColor(Color.WHITE);

      if (lastTrack.isEmpty()) {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player_idle_oled.png"), 0, 0, null);
      } else {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player_oled.png"), 0, 0, null);

        TextPaint tp = null;
        if (paintLarge.measureText(lastTrack.track) < 75) {
          tp = paintLarge;
        } else {
          tp = paintSmall;
        }

        canvas.save();
        StaticLayout layout =
            new StaticLayout(
                lastTrack.track, tp, 75, Layout.Alignment.ALIGN_CENTER, 1.2f, 0, false);
        int height = layout.getHeight();
        int textY = 8 - (height / 2);
        if (textY < 0) {
          textY = 0;
        }
        canvas.translate(0, textY); // position the text
        canvas.clipRect(0, 0, 75, 16);
        layout.draw(canvas);
        canvas.restore();

        canvas.save();
        StringBuilder lowerText = new StringBuilder();
        if (!lastTrack.artist.equals("")) {
          lowerText.append(lastTrack.artist);
        }
        if (!lastTrack.album.equals("")) {
          if (lowerText.length() > 0) lowerText.append("\n\n");
          lowerText.append(lastTrack.album);
        }

        if (paintLarge.measureText(lowerText.toString()) < 75) {
          tp = paintLarge;
        } else {
          tp = paintSmall;
        }

        layout =
            new StaticLayout(
                lowerText.toString(), tp, 75, Layout.Alignment.ALIGN_CENTER, 1.0f, 0, false);
        height = layout.getHeight();
        textY = 24 - (height / 2);
        if (textY < 16) {
          textY = 16;
        }
        canvas.translate(0, textY); // position the text
        canvas.clipRect(0, 0, 75, 16);
        layout.draw(canvas);
        canvas.restore();
      }

      return bitmap;
    }

    return null;
  }