android.graphics.Paint#setSubpixelText ( )源码实例Demo

下面列出了android.graphics.Paint#setSubpixelText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: your-local-weather   文件: Utils.java
public static Bitmap createWeatherIconWithColor(Context context, String text, int iconColor) {
    Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    Typeface weatherFont = Typeface.createFromAsset(context.getAssets(),
                                                    "fonts/weathericons-regular-webfont.ttf");

    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
    paint.setTypeface(weatherFont);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(iconColor);
    paint.setTextSize(180);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(text, 128, 200, paint);
    return bitmap;
}
 
源代码2 项目: FriendBook   文件: PageLoader.java
private void initPaint() {
    //绘制提示的画笔
    mTipPaint = new Paint();
    mTipPaint.setColor(mPageView.getTextColor());
    mTipPaint.setTextAlign(Paint.Align.LEFT);//绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(mContext, DEFAULT_TIP_SIZE));//Tip默认的字体大小
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    //绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(mPageView.getTextColor());
    mTextPaint.setTextSize(mPageView.getTextSize());
    mTextPaint.setAntiAlias(true);

    mBgPaint = new Paint();
    mBgPaint.setColor(mPageView.getPageBackground());

    mBatteryPaint = new Paint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);
    mBatteryPaint.setColor(mPageView.getTextColor());

}
 
源代码3 项目: good-weather   文件: Utils.java
public static Bitmap createWeatherIcon(Context context, String text) {
    Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    Typeface weatherFont = Typeface.createFromAsset(context.getAssets(),
                                                    "fonts/weathericons-regular-webfont.ttf");

    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
    paint.setTypeface(weatherFont);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(AppPreference.getTextColor(context));
    paint.setTextSize(180);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(text, 128, 200, paint);
    return bitmap;
}
 
源代码4 项目: react-native-GPay   文件: CustomStyleSpan.java
private static void apply(
    Paint paint,
    int style,
    int weight,
    @Nullable String family,
    AssetManager assetManager) {
  int oldStyle;
  Typeface typeface = paint.getTypeface();
  if (typeface == null) {
    oldStyle = 0;
  } else {
    oldStyle = typeface.getStyle();
  }

  int want = 0;
  if ((weight == Typeface.BOLD) ||
      ((oldStyle & Typeface.BOLD) != 0 && weight == ReactTextShadowNode.UNSET)) {
    want |= Typeface.BOLD;
  }

  if ((style == Typeface.ITALIC) ||
      ((oldStyle & Typeface.ITALIC) != 0 && style == ReactTextShadowNode.UNSET)) {
    want |= Typeface.ITALIC;
  }

  if (family != null) {
    typeface = ReactFontManager.getInstance().getTypeface(family, want, assetManager);
  } else if (typeface != null) {
    // TODO(t9055065): Fix custom fonts getting applied to text children with different style
    typeface = Typeface.create(typeface, want);
  }

  if (typeface != null) {
    paint.setTypeface(typeface);
  } else {
    paint.setTypeface(Typeface.defaultFromStyle(want));
  }
  paint.setSubpixelText(true);
}
 
源代码5 项目: NovelReader   文件: PageLoader.java
private void initPaint() {
    // 绘制提示的画笔
    mTipPaint = new Paint();
    mTipPaint.setColor(mTextColor);
    mTipPaint.setTextAlign(Paint.Align.LEFT); // 绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE)); // Tip默认的字体大小
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    // 绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);

    // 绘制标题的画笔
    mTitlePaint = new TextPaint();
    mTitlePaint.setColor(mTextColor);
    mTitlePaint.setTextSize(mTitleSize);
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTitlePaint.setAntiAlias(true);

    // 绘制背景的画笔
    mBgPaint = new Paint();
    mBgPaint.setColor(mBgColor);

    // 绘制电池的画笔
    mBatteryPaint = new Paint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);

    // 初始化页面样式
    setNightMode(mSettingManager.isNightMode());
}
 
源代码6 项目: Jreader   文件: BookPageFactory.java
public BookPageFactory(int w, int h,Context context) {
    mWidth = w;
    mHeight = h;
    mcontext = context;
    m_fontSize = (int) context.getResources().getDimension(R.dimen.reading_default_text_size);
    sdf = new SimpleDateFormat("HH:mm");//HH:mm为24小时制,hh:mm为12小时制
    date = sdf.format(new java.util.Date());
    df = new DecimalFormat("#0.0");
    mBorderWidth = context.getResources().getDimension(R.dimen.reading_board_battery_border_width);
    marginWidth = (int) context.getResources().getDimension(R.dimen.readingMarginWidth);
    marginHeight = (int) context.getResources().getDimension(R.dimen.readingMarginHeight);
    typeface = Typeface.createFromAsset(context.getAssets(), "font/QH.ttf");
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);// 画笔
    mPaint.setTextAlign(Paint.Align.LEFT);// 左对齐
    mPaint.setTextSize(m_fontSize);// 字体大小
    mPaint.setColor(m_textColor);// 字体颜色
    mPaint.setTypeface(typeface);
    mPaint.setSubpixelText(true);// 设置该项为true,将有助于文本在LCD屏幕上的显示效果
    mVisibleWidth = mWidth - marginWidth * 2;
    mVisibleHeight = mHeight - marginHeight * 2;
    mLineCount = (int) (mVisibleHeight / m_fontSize) - 1; // 可显示的行数,-1是因为底部显示进度的位置容易被遮住
    batteryInfoIntent = context.getApplicationContext().registerReceiver(null,
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED)) ;//注册广播,随时获取到电池电量信息

    mBatterryPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBatterryPaint.setTextSize(CommonUtil.sp2px(context, 12));
    mBatterryPaint.setTypeface(typeface);
    mBatterryPaint.setTextAlign(Paint.Align.LEFT);
    mBatterryPaint.setColor(m_textColor);

    // Log.d("BookPageFactory","mBorderWidth"+mBorderWidth);
}
 
源代码7 项目: Weather   文件: Utils.java
public static Bitmap createWeatherIcon(Context context, String text) {
    Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    Typeface weatherFont = Typeface.createFromAsset(context.getAssets(), "fonts/weather-icons-v2.0.10.ttf");
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
    paint.setTypeface(weatherFont);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(ContextCompat.getColor(context , R.color.textColor));
    paint.setTextSize(180);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(text, 128, 200, paint);
    return bitmap;
}
 
源代码8 项目: CrawlerForReader   文件: BookPageView.java
private void init(Context context, @Nullable AttributeSet attrs) {
        defaultWidth = 600;
        defaultHeight = 1000;

        a = new MyPoint();
        f = new MyPoint();
        g = new MyPoint();
        e = new MyPoint();
        h = new MyPoint();
        c = new MyPoint();
        j = new MyPoint();
        b = new MyPoint();
        k = new MyPoint();
        d = new MyPoint();
        i = new MyPoint();

        pointPaint = new Paint();
        pointPaint.setColor(Color.RED);
        pointPaint.setTextSize(25);
        pointPaint.setStyle(Paint.Style.STROKE);

        bgPaint = new Paint();
        bgPaint.setColor(Color.GREEN);

        pathAPaint = new Paint();
        pathAPaint.setColor(Color.GREEN);
        pathAPaint.setAntiAlias(true);//设置抗锯齿

        pathBPaint = new Paint();
        pathBPaint.setColor(getResources().getColor(R.color.main_text_color));
        pathBPaint.setAntiAlias(true);//设置抗锯齿
//        pathBPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));我们不需要单独绘制path了,记得注释掉

        pathCPaint = new Paint();
        pathCPaint.setColor(Color.YELLOW);
        pathCPaint.setAntiAlias(true);//设置抗锯齿
//        pathCPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));
//        pathCPaint.setStyle(Paint.Style.STROKE);

        pathCContentPaint = new Paint();
        pathCContentPaint.setColor(Color.YELLOW);
        pathCContentPaint.setAntiAlias(true);//设置抗锯齿

        textPaint = new Paint();
        textPaint.setColor(Color.BLACK);
        textPaint.setTextAlign(Paint.Align.CENTER);
        textPaint.setSubpixelText(true);//设置自像素。如果该项为true,将有助于文本在LCD屏幕上的显示效果。
        textPaint.setTextSize(30);

        pathA = new Path();
        pathB = new Path();
        pathC = new Path();

        style = STYLE_LOWER_RIGHT;
        mScroller = new Scroller(context, new LinearInterpolator());
        mMatrix = new Matrix();

        createGradientDrawable();
    }
 
源代码9 项目: Wrox-ProfessionalAndroid-4E   文件: CompassView.java
public CompassView(Context context, AttributeSet attrs,
                   int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  setFocusable(true);
  final TypedArray a = context.obtainStyledAttributes(attrs,
    R.styleable.CompassView, defStyleAttr, 0);
  if (a.hasValue(R.styleable.CompassView_bearing)) {
    setBearing(a.getFloat(R.styleable.CompassView_bearing, 0));
  }
  a.recycle();

  Context c = this.getContext();
  Resources r = this.getResources();

  circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  circlePaint.setColor(ContextCompat.getColor(c, R.color.background_color));
  circlePaint.setStrokeWidth(1);
  circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  circlePaint.setStyle(Paint.Style.STROKE);

  northString = r.getString(R.string.cardinal_north);
  eastString = r.getString(R.string.cardinal_east);
  southString = r.getString(R.string.cardinal_south);
  westString = r.getString(R.string.cardinal_west);

  textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  textPaint.setColor(ContextCompat.getColor(c, R.color.text_color));
  textPaint.setTextSize(40);
  textPaint.setFakeBoldText(true);
  textPaint.setSubpixelText(true);
  textPaint.setTextAlign(Paint.Align.LEFT);
  textPaint.setTextSize(30);

  textHeight = (int)textPaint.measureText("yY");

  markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  markerPaint.setColor(ContextCompat.getColor(c, R.color.marker_color));
  markerPaint.setAlpha(200);
  markerPaint.setStrokeWidth(1);
  markerPaint.setStyle(Paint.Style.STROKE);
  markerPaint.setShadowLayer(2, 1, 1, ContextCompat.getColor(c,
    R.color.shadow_color));

  borderGradientColors = new int[4];
  borderGradientPositions = new float[4];
  borderGradientColors[3] = ContextCompat.getColor(c,
    R.color.outer_border);
  borderGradientColors[2] = ContextCompat.getColor(c,
    R.color.inner_border_one);
  borderGradientColors[1] = ContextCompat.getColor(c,
    R.color.inner_border_two);
  borderGradientColors[0] = ContextCompat.getColor(c,
    R.color.inner_border);
  borderGradientPositions[3] = 0.0f;
  borderGradientPositions[2] = 1-0.03f;
  borderGradientPositions[1] = 1-0.06f;
  borderGradientPositions[0] = 1.0f;

  glassGradientColors = new int[5];
  glassGradientPositions = new float[5];

  int glassColor = 245;
  glassGradientColors[4] = Color.argb(65, glassColor,
    glassColor, glassColor);
  glassGradientColors[3] = Color.argb(100, glassColor,
    glassColor, glassColor);
  glassGradientColors[2] = Color.argb(50, glassColor,
    glassColor, glassColor);
  glassGradientColors[1] = Color.argb(0, glassColor,
    glassColor, glassColor);
  glassGradientColors[0] = Color.argb(0, glassColor,
    glassColor, glassColor);
  glassGradientPositions[4] = 1-0.0f;
  glassGradientPositions[3] = 1-0.06f;
  glassGradientPositions[2] = 1-0.10f;
  glassGradientPositions[1] = 1-0.20f;
  glassGradientPositions[0] = 1-1.0f;

  skyHorizonColorFrom = ContextCompat.getColor(c,
    R.color.horizon_sky_from);
  skyHorizonColorTo = ContextCompat.getColor(c,
    R.color.horizon_sky_to);
  groundHorizonColorFrom = ContextCompat.getColor(c,
    R.color.horizon_ground_from);
  groundHorizonColorTo = ContextCompat.getColor(c,
    R.color.horizon_ground_to);
}
 
源代码10 项目: Wrox-ProfessionalAndroid-4E   文件: CompassView.java
public CompassView(Context context, AttributeSet attrs,
                   int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  setFocusable(true);
  final TypedArray a = context.obtainStyledAttributes(attrs,
    R.styleable.CompassView, defStyleAttr, 0);
  if (a.hasValue(R.styleable.CompassView_bearing)) {
    setBearing(a.getFloat(R.styleable.CompassView_bearing, 0));
  }
  a.recycle();

  Context c = this.getContext();
  Resources r = this.getResources();

  circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  circlePaint.setColor(ContextCompat.getColor(c, R.color.background_color));
  circlePaint.setStrokeWidth(1);
  circlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  circlePaint.setStyle(Paint.Style.STROKE);

  northString = r.getString(R.string.cardinal_north);
  eastString = r.getString(R.string.cardinal_east);
  southString = r.getString(R.string.cardinal_south);
  westString = r.getString(R.string.cardinal_west);

  textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  textPaint.setColor(ContextCompat.getColor(c, R.color.text_color));
  textPaint.setTextSize(40);
  textPaint.setFakeBoldText(true);
  textPaint.setSubpixelText(true);
  textPaint.setTextAlign(Paint.Align.LEFT);
  textPaint.setTextSize(30);

  textHeight = (int)textPaint.measureText("yY");

  markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  markerPaint.setColor(ContextCompat.getColor(c, R.color.marker_color));
  markerPaint.setAlpha(200);
  markerPaint.setStrokeWidth(1);
  markerPaint.setStyle(Paint.Style.STROKE);
  markerPaint.setShadowLayer(2, 1, 1, ContextCompat.getColor(c,
    R.color.shadow_color));

  borderGradientColors = new int[4];
  borderGradientPositions = new float[4];
  borderGradientColors[3] = ContextCompat.getColor(c,
    R.color.outer_border);
  borderGradientColors[2] = ContextCompat.getColor(c,
    R.color.inner_border_one);
  borderGradientColors[1] = ContextCompat.getColor(c,
    R.color.inner_border_two);
  borderGradientColors[0] = ContextCompat.getColor(c,
    R.color.inner_border);
  borderGradientPositions[3] = 0.0f;
  borderGradientPositions[2] = 1-0.03f;
  borderGradientPositions[1] = 1-0.06f;
  borderGradientPositions[0] = 1.0f;

  glassGradientColors = new int[5];
  glassGradientPositions = new float[5];

  int glassColor = 245;
  glassGradientColors[4] = Color.argb(65, glassColor,
    glassColor, glassColor);
  glassGradientColors[3] = Color.argb(100, glassColor,
    glassColor, glassColor);
  glassGradientColors[2] = Color.argb(50, glassColor,
    glassColor, glassColor);
  glassGradientColors[1] = Color.argb(0, glassColor,
    glassColor, glassColor);
  glassGradientColors[0] = Color.argb(0, glassColor,
    glassColor, glassColor);
  glassGradientPositions[4] = 1-0.0f;
  glassGradientPositions[3] = 1-0.06f;
  glassGradientPositions[2] = 1-0.10f;
  glassGradientPositions[1] = 1-0.20f;
  glassGradientPositions[0] = 1-1.0f;

  skyHorizonColorFrom = ContextCompat.getColor(c,
    R.color.horizon_sky_from);
  skyHorizonColorTo = ContextCompat.getColor(c,
    R.color.horizon_sky_to);
  groundHorizonColorFrom = ContextCompat.getColor(c,
    R.color.horizon_ground_from);
  groundHorizonColorTo = ContextCompat.getColor(c,
    R.color.horizon_ground_to);
}
 
源代码11 项目: BookPage   文件: BookPageView.java
private void init(Context context, @Nullable AttributeSet attrs){
        defaultWidth = 600;
        defaultHeight = 1000;

        a = new MyPoint();
        f = new MyPoint();
        g = new MyPoint();
        e = new MyPoint();
        h = new MyPoint();
        c = new MyPoint();
        j = new MyPoint();
        b = new MyPoint();
        k = new MyPoint();
        d = new MyPoint();
        i = new MyPoint();

        pointPaint = new Paint();
        pointPaint.setColor(Color.RED);
        pointPaint.setTextSize(25);
        pointPaint.setStyle(Paint.Style.STROKE);

        bgPaint = new Paint();
        bgPaint.setColor(Color.GREEN);

        pathAPaint = new Paint();
        pathAPaint.setColor(Color.GREEN);
        pathAPaint.setAntiAlias(true);//设置抗锯齿

        pathBPaint = new Paint();
        pathBPaint.setColor(getResources().getColor(R.color.blue_light));
        pathBPaint.setAntiAlias(true);//设置抗锯齿
//        pathBPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));我们不需要单独绘制path了,记得注释掉

        pathCPaint = new Paint();
        pathCPaint.setColor(Color.YELLOW);
        pathCPaint.setAntiAlias(true);//设置抗锯齿
//        pathCPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));
//        pathCPaint.setStyle(Paint.Style.STROKE);

        pathCContentPaint = new Paint();
        pathCContentPaint.setColor(Color.YELLOW);
        pathCContentPaint.setAntiAlias(true);//设置抗锯齿

        textPaint = new Paint();
        textPaint.setColor(Color.BLACK);
        textPaint.setTextAlign(Paint.Align.CENTER);
        textPaint.setSubpixelText(true);//设置自像素。如果该项为true,将有助于文本在LCD屏幕上的显示效果。
        textPaint.setTextSize(30);

        pathA = new Path();
        pathB = new Path();
        pathC = new Path();

        style = STYLE_LOWER_RIGHT;
        mScroller = new Scroller(context,new LinearInterpolator());
        mMatrix = new Matrix();

        createGradientDrawable();
    }
 
源代码12 项目: prayer-times-android   文件: WidgetLegacy.java
static void update1x1(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    Resources r = context.getResources();
    float dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());

    LocalDateTime now = LocalDateTime.now();
    LocalDate today = now.toLocalDate();

    Theme theme = WidgetUtils.getTheme(widgetId);
    Times times = WidgetUtils.getTimes(widgetId);
    if (times == null) {
        WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId);
        return;
    }

    WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1f);
    int s = size.width;
    if (s <= 0)
        return;
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);

    int next = times.getNextTime();
    String left = LocaleUtils.formatPeriod(now, times.getTime(today, next), false);
    if (Preferences.VAKIT_INDICATOR_TYPE.get().equals("next"))
        next = next + 1;

    remoteViews.setOnClickPendingIntent(R.id.widget, TimesFragment.getPendingIntent(times));

    Bitmap bmp = Bitmap.createBitmap(s, s, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    canvas.scale(0.99f, 0.99f, s / 2f, s / 2f);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(theme.bgcolor);
    canvas.drawRect(0, 0, s, s, paint);

    paint.setColor(theme.textcolor);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);

    paint.setColor(theme.hovercolor);

    String city = times.getName();

    paint.setColor(theme.textcolor);

    float cs = s / 5f;
    float ts = (s * 35) / 100f;
    int vs = s / 4;
    paint.setTextSize(cs);
    cs = (cs * s * 0.9f) / paint.measureText(city);
    cs = (cs > vs) ? vs : cs;

    paint.setTextSize(vs);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(Vakit.getByIndex(next).prevTime().getString(), s / 2f, (s * 22) / 80f, paint);

    paint.setTextSize(ts);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(left, s / 2f, (s / 2f) + ((ts * 1) / 3), paint);

    paint.setTextSize(cs);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(city, s / 2f, ((s * 3) / 4f) + ((cs * 2) / 3), paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(dp);
    paint.setColor(theme.strokecolor);
    canvas.drawRect(0, 0, s, s, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}
 
源代码13 项目: prayer-times-android   文件: WidgetLegacy.java
static void updateSilenter(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    Resources r = context.getResources();
    float dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());

    Theme theme = WidgetUtils.getTheme(widgetId);
    WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1f);
    int s = size.width;
    if (s <= 0)
        return;
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);

    Intent i = new Intent(context, SilenterPrompt.class);
    remoteViews.setOnClickPendingIntent(R.id.widget, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

    Bitmap bmp = Bitmap.createBitmap(s, s, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    canvas.scale(0.99f, 0.99f, s / 2f, s / 2f);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(theme.bgcolor);
    canvas.drawRect(0, 0, s, s, paint);

    paint.setColor(theme.textcolor);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);

    paint.setColor(theme.hovercolor);

    paint.setColor(theme.textcolor);

    paint.setTextSize((s * 25) / 100f);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText("Sessize", s / 2f, (s * 125) / 300f, paint);
    canvas.drawText("al", s / 2f, (s * 25) / 30f, paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(dp);
    paint.setColor(theme.strokecolor);
    canvas.drawRect(0, 0, s, s, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}
 
源代码14 项目: prayer-times-android   文件: WidgetLegacy.java
static void update1x1(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    Resources r = context.getResources();
    float dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());

    LocalDateTime now = LocalDateTime.now();
    LocalDate today = now.toLocalDate();

    Theme theme = WidgetUtils.getTheme(widgetId);
    Times times = WidgetUtils.getTimes(widgetId);
    if (times == null) {
        WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId);
        return;
    }

    WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1f);
    int s = size.width;
    if (s <= 0)
        return;
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);

    int next = times.getNextTime();
    String left = LocaleUtils.formatPeriod(now, times.getTime(today, next), false);
    if (Preferences.VAKIT_INDICATOR_TYPE.get().equals("next"))
        next = next + 1;

    remoteViews.setOnClickPendingIntent(R.id.widget, TimesFragment.getPendingIntent(times));

    Bitmap bmp = Bitmap.createBitmap(s, s, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    canvas.scale(0.99f, 0.99f, s / 2f, s / 2f);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(theme.bgcolor);
    canvas.drawRect(0, 0, s, s, paint);

    paint.setColor(theme.textcolor);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);

    paint.setColor(theme.hovercolor);

    String city = times.getName();

    paint.setColor(theme.textcolor);

    float cs = s / 5f;
    float ts = (s * 35) / 100f;
    int vs = s / 4;
    paint.setTextSize(cs);
    cs = (cs * s * 0.9f) / paint.measureText(city);
    cs = (cs > vs) ? vs : cs;

    paint.setTextSize(vs);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(Vakit.getByIndex(next).prevTime().getString(), s / 2f, (s * 22) / 80f, paint);

    paint.setTextSize(ts);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(left, s / 2f, (s / 2f) + ((ts * 1) / 3), paint);

    paint.setTextSize(cs);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText(city, s / 2f, ((s * 3) / 4f) + ((cs * 2) / 3), paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(dp);
    paint.setColor(theme.strokecolor);
    canvas.drawRect(0, 0, s, s, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}
 
源代码15 项目: prayer-times-android   文件: WidgetLegacy.java
static void updateSilenter(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    Resources r = context.getResources();
    float dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());

    Theme theme = WidgetUtils.getTheme(widgetId);
    WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1f);
    int s = size.width;
    if (s <= 0)
        return;
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);

    Intent i = new Intent(context, SilenterPrompt.class);
    remoteViews.setOnClickPendingIntent(R.id.widget, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

    Bitmap bmp = Bitmap.createBitmap(s, s, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    canvas.scale(0.99f, 0.99f, s / 2f, s / 2f);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(theme.bgcolor);
    canvas.drawRect(0, 0, s, s, paint);

    paint.setColor(theme.textcolor);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);

    paint.setColor(theme.hovercolor);

    paint.setColor(theme.textcolor);

    paint.setTextSize((s * 25) / 100f);
    paint.setTextAlign(Paint.Align.CENTER);
    canvas.drawText("Sessize", s / 2f, (s * 125) / 300f, paint);
    canvas.drawText("al", s / 2f, (s * 25) / 30f, paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(dp);
    paint.setColor(theme.strokecolor);
    canvas.drawRect(0, 0, s, s, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}