Engine() {
   super();
   prefs = GalleryWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
   prefs.registerOnSharedPreferenceChangeListener(this);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_REPLACEIMAGE);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_SYNC);
   onSharedPreferenceChanged(prefs, null);
   backgroundPaint.setFilterBitmap(false);
   backgroundPaint.setAntiAlias(true);
   backgroundPaint.setColor(Color.BLACK);
   textPaint.setAntiAlias(true);
   textPaint.setColor(Color.WHITE);
   textPaint.setShadowLayer(5f, 1f, 1f, Color.GRAY);
   textPaint.setSubpixelText(true);
   textPaint.setTextAlign(Paint.Align.LEFT);
   textPaint.setTextSize(18);
   textPaint.setTypeface(Typeface.MONOSPACE);
   this.setTouchEventsEnabled(true);
   if (Build.VERSION.SDK_INT >= 14) {
     try {
       // hinting = textPaint.HINTING_ON;
       int hinting = textPaint.getClass().getField("HINTING_ON").getInt(textPaint);
       // textPaint.setHinting(hinting);
       textPaint.getClass().getMethod("setHinting", int.class).invoke(textPaint, hinting);
     } catch (IllegalAccessException e) {
       System.err.println(e.toString());
     } catch (InvocationTargetException e) {
       System.err.println(e.toString());
     } catch (NoSuchMethodException e) {
       System.err.println(e.toString());
     } catch (NoSuchFieldException e) {
       System.err.println(e.toString());
     }
   }
 }
  private void initViewPaint() {
    paint = new Paint();

    paint.setTextSize(20 * ratio);
    paint.setColor(Color.BLACK);
    paint.setTextAlign(Align.CENTER);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
  }
  protected void initCompassView() {
    setFocusable(true);
    Resources r = this.getResources();

    circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    circlePaint.setColor(R.color.transparent_color);
    circlePaint.setStrokeWidth(1);
    circlePaint.setStyle(Paint.Style.STROKE);

    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setColor(r.getColor(R.color.text_color));
    textPaint.setFakeBoldText(true);
    textPaint.setSubpixelText(true);
    textPaint.setTextAlign(Align.LEFT);

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

    markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    markerPaint.setColor(r.getColor(R.color.transparent_color));
    markerPaint.setAlpha(200);
    markerPaint.setStrokeWidth(1);
    markerPaint.setStyle(Paint.Style.STROKE);
    markerPaint.setShadowLayer(2, 1, 1, r.getColor(R.color.transparent_color));

    borderGradientColors = new int[4];
    borderGradientPositions = new float[4];

    borderGradientColors[3] = r.getColor(R.color.transparent_color);
    borderGradientColors[2] = r.getColor(R.color.transparent_color);
    borderGradientColors[1] = r.getColor(R.color.transparent_color);
    borderGradientColors[0] = r.getColor(R.color.transparent_color);
    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 = r.getColor(R.color.transparent_color);
    skyHorizonColorTo = r.getColor(R.color.transparent_color);

    groundHorizonColorFrom = r.getColor(R.color.transparent_color);
    groundHorizonColorTo = r.getColor(R.color.transparent_color);
  }
Exemplo n.º 4
0
  private void init(Context context) {
    mContext = context;

    mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);

    View v = LayoutInflater.from(context).inflate(R.layout.view_main, null);

    compassView = (ImageView) v.findViewById(R.id.compass_view);
    canvasView = (ImageView) v.findViewById(R.id.canvas_view);

    // Resize canvasView
    ResizeImageView.resizeImageView(
        canvasView, ResolutionUtil.displayWidth(context), ResolutionUtil.displayWidth(context));

    Bitmap bitmap =
        Bitmap.createBitmap(
            ResolutionUtil.displayWidth(context),
            ResolutionUtil.displayHeight(context),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // Draw transparent screen
    Paint transPainter = new Paint();
    transPainter.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), transPainter);

    Paint drawPaint = new Paint();
    drawPaint.reset();
    drawPaint.setFlags(Paint.DITHER_FLAG);
    drawPaint.setAntiAlias(true);
    drawPaint.setSubpixelText(true);
    drawPaint.setColor(Color.GREEN);
    drawPaint.setStyle(Paint.Style.STROKE);
    drawPaint.setStrokeJoin(Paint.Join.ROUND);
    drawPaint.setStrokeCap(Paint.Cap.ROUND);
    drawPaint.setStrokeWidth(10);
    canvas.drawLines(
        new float[] {bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, 0},
        drawPaint);

    canvasView.setImageBitmap(bitmap);

    // invoke canvasView
    canvasView.invalidate();

    addView(v);
  }
  public PercentageDrawable() {
    mBounds = new RectF();
    mTextBounds = new Rect();

    mArcPaint = new Paint();
    mArcPaint.setAntiAlias(true);

    mBackgroundArcPaint = new Paint();
    mBackgroundArcPaint.setAntiAlias(true);

    mForegroundCirclePaint = new Paint();
    mForegroundCirclePaint.setAntiAlias(true);

    mTextPaint = new Paint();
    mTextPaint.setSubpixelText(true);
    mTextPaint.setAntiAlias(true);
  }
 public Bitmap buildText(String text) {
   Bitmap myBitmap = Bitmap.createBitmap(260, 184, Bitmap.Config.ARGB_4444);
   ;
   Canvas myCanvas = new Canvas(myBitmap);
   Paint paint = new Paint();
   // To use own font
   Typeface face = Typeface.create("Arial", Typeface.NORMAL);
   paint.setAntiAlias(true);
   paint.setSubpixelText(true);
   paint.setTypeface(face);
   paint.setStyle(Paint.Style.FILL);
   paint.setColor(Color.RED);
   paint.setTextSize(65);
   paint.setTextAlign(Paint.Align.CENTER);
   myCanvas.drawText(text, 80, 60, paint);
   return myBitmap;
 }
Exemplo n.º 7
0
 /**
  * Y周的刻度值
  *
  * @param canvas
  */
 private void drawYValueText(Canvas canvas) {
   Paint paint = new Paint();
   paint.setColor(axesLineColor);
   paint.setAntiAlias(true);
   paint.setSubpixelText(true);
   paint.setTypeface(Typeface.MONOSPACE);
   paint.setTextSize(leftTextSize);
   paint.setTextAlign(Align.RIGHT);
   /*int yHeight = height - topPadding - bottomPadding - topTextHeight;
         int spaceLength = yHeight / yNum;
   int spaceValue = (yMaxValue - yMinValue) / yNum;
   for (int i = 0; i < 6; i++) {
   	canvas.drawText((yMinValue + spaceValue * i) + "", leftPadding + yTextWidth - 5, height - bottomPadding - yTextWidth - (spaceLength * i),
   			paint);
   }*/
   canvas.drawText(
       "优秀",
       leftPadding + (yTextWidth + leftTextSize) / 2,
       height - bottomPadding - xTextHeight - (spaceYLength * 5) + leftTextSize / 2,
       paint);
   canvas.drawText(
       "良好",
       leftPadding + (yTextWidth + leftTextSize) / 2,
       height - bottomPadding - xTextHeight - (spaceYLength * 4) + leftTextSize / 2,
       paint);
   canvas.drawText(
       "一般",
       leftPadding + (yTextWidth + leftTextSize) / 2,
       height - bottomPadding - xTextHeight - (spaceYLength * 3) + leftTextSize / 2,
       paint);
   canvas.drawText(
       "差劲",
       leftPadding + (yTextWidth + leftTextSize) / 2,
       height - bottomPadding - xTextHeight - (spaceYLength * 2) + leftTextSize / 2,
       paint);
   canvas.drawText(
       "恶劣",
       leftPadding + (yTextWidth + leftTextSize) / 2,
       height - bottomPadding - xTextHeight - (spaceYLength * 1) + leftTextSize / 2,
       paint);
 }
Exemplo n.º 8
0
  /**
   * 画折线图,网格竖线,X坐标值
   *
   * @param canvas
   */
  private void drawChartLine(Canvas canvas) {
    Paint paintChart = new Paint();
    paintChart.setColor(chartLineColor);
    paintChart.setAntiAlias(true);
    paintChart.setStyle(Style.STROKE);
    paintChart.setStrokeWidth(chartLineSize);

    Paint paintGrid = new Paint();
    paintGrid.setColor(gridLineColor);
    paintGrid.setAntiAlias(true);
    paintGrid.setStyle(Style.STROKE);
    paintGrid.setStrokeWidth(gridLineSize);

    Paint paintTopText = new Paint();
    paintTopText.setColor(axesLineColor);
    paintTopText.setAntiAlias(true);
    paintTopText.setSubpixelText(true);
    paintTopText.setTypeface(Typeface.MONOSPACE);
    paintTopText.setTextSize(topTextSize);
    paintTopText.setTextAlign(Align.CENTER);

    Paint paintBottomText = new Paint();
    paintBottomText.setColor(axesLineColor);
    paintBottomText.setAntiAlias(true);
    paintBottomText.setSubpixelText(true);
    paintBottomText.setTypeface(Typeface.MONOSPACE);
    paintBottomText.setTextSize(bottomTextSize);
    paintBottomText.setTextAlign(Align.CENTER);

    Paint paintPoint = new Paint();
    paintPoint.setColor(pointColor);
    paintPoint.setAntiAlias(true);
    paintPoint.setStyle(Style.FILL);

    pressedPaint = new Paint();
    pressedPaint.setColor(pressedColor);
    pressedPaint.setAntiAlias(true);
    pressedPaint.setStyle(Style.FILL);

    Paint paintShape = new Paint();
    paintShape.setStyle(Style.FILL);
    paintShape.setColor(shapeColor);
    paintShape.setAlpha(shapeAlpha);

    if (axesData.size() > 0) {
      for (int i = 0; i < axesData.size(); i++) {
        if (i < axesData.size() - 1) {
          // 画折线
          canvas.drawLine(
              axesData.get(i).X,
              axesData.get(i).Y,
              axesData.get(i + 1).X,
              axesData.get(i + 1).Y,
              paintChart);
          if (isShapeShow) {
            // 画阴影
            Path path = new Path();
            path.moveTo(axesData.get(i).X, height - bottomPadding - xTextHeight);
            path.lineTo(axesData.get(i).X, axesData.get(i).Y + chartLineSize / 2);
            path.lineTo(axesData.get(i + 1).X, axesData.get(i + 1).Y + chartLineSize / 2);
            path.lineTo(axesData.get(i + 1).X, height - bottomPadding - xTextHeight);
            canvas.drawPath(path, paintShape);
          }
        }
        // 画网格竖线
        // canvas.drawLine(axesData.get(i).X, height - bottomPadding - xTextHeight,
        // axesData.get(i).X, topPadding + topTextHeight, paintGrid);
        // 写X轴坐标的刻度值
        if (!TextUtils.isEmpty(axesData.get(i).getxText())) {
          setTextSizeForWidth(
              paintBottomText, spaceXLength - 10, axesData.get(i).getxText()); // 10为相邻日期文字间隔
          canvas.drawText(
              axesData.get(i).getxText(),
              axesData.get(i).X,
              height - bottomPadding - xTextHeight / 2,
              paintBottomText);
        }
        // 写顶部的刻度值
        if (!TextUtils.isEmpty(axesData.get(i).getTopText())) {
          // 取消了顶部隔年显示的数据
          //					canvas.drawText(axesData.get(i).getTopText(), axesData.get(i).X, topPadding,
          // paintTopText);
        }
        // 画数据点
        if (pointBitmap == null) {
          canvas.drawCircle(axesData.get(i).X, axesData.get(i).Y, pointSize + 1, paintChart);
          canvas.drawCircle(axesData.get(i).X, axesData.get(i).Y, pointSize, paintPoint);
        } else {
          Matrix matrix = new Matrix();
          canvas.drawBitmap(pointBitmap, matrix, paintPoint);
        }
      }

      // 画最后一个数据的网格竖线
      // canvas.drawLine(axesData.get(axesData.size() - 1).X, height - bottomPadding - xTextHeight,
      // axesData.get(axesData.size() - 1).X,
      //        topPadding + topTextHeight, paintGrid);
      // 写X轴坐标的最后一个值的刻度值
      /*
       * canvas.drawText(axesData.get(axesData.size() - 1).X + "",
       * axesData.get(axesData.size() - 1).X, height - bottomPadding -
       * xTextHeight / 2, paintBottomText);
       */
      // 写顶部的最后一个刻度值
      // canvas.drawText("2014", axesData.get(axesData.size() - 1).X,
      // topPadding, paintTopText);
      // 画数最后一个据点
      if (pointBitmap == null) {
        // canvas.drawCircle(axesData.get(axesData.size() - 1).X,
        // axesData.get(axesData.size() - 1).Y, pointSize + 1,
        // paintChart);
        // canvas.drawCircle(axesData.get(axesData.size() - 1).X,
        // axesData.get(axesData.size() - 1).Y, pointSize, paintPoint);
      } else {
        Matrix matrix = new Matrix();
        canvas.drawBitmap(pointBitmap, matrix, paintPoint);
      }
    }

    if (currentPressedPoint != null) {
      // canvas.drawCircle(currentPressedPoint.X, currentPressedPoint.Y, pointSize, pressedPaint);
    }
  }