Esempio n. 1
0
  private void drawPageGrid(int w, int h) {
    Bitmap newBackgroundBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
    Canvas newBackgroundCanvas = new Canvas();
    newBackgroundCanvas.setBitmap(newBackgroundBitmap);

    if (mBackgroundBitmap != null) {
      newBackgroundCanvas.drawBitmap(mBackgroundBitmap, 0, 0, null);
    }
    mBackgroundBitmap = newBackgroundBitmap;
    mBackgroundCanvas = newBackgroundCanvas;

    // make the entire canvas page colour
    mBackgroundCanvas.drawPaint(pagePainter);

    // Draw Background Grid
    Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay();
    width = display.getWidth(); // start
    height = display.getHeight(); // end

    for (int i = 0; i < width; i += xpos) {
      mBackgroundCanvas.drawLine(i, 0, i, height, gridPainter);
    }
    for (int i = 0; i < height; i += ypos) {
      mBackgroundCanvas.drawLine(0, i, width, i, gridPainter);
    }
  }
Esempio n. 2
0
  private void undo() {
    try {
      if (undoPathList.size() > 0) {
        HistoryItem item = undoPathList.get(undoPathList.size() - 1);
        redoPathList.add(item);
        undoPathList.remove(undoPathList.size() - 1);

        Paint paint = new Paint();
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        mCacheCanvas.drawPaint(paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC));

        for (int i = 0; i < undoPathList.size(); i++) {
          HistoryItem item_t = undoPathList.get(i);
          if (item_t.getType() == HistoryItem.TYPE_PATH) {
            mCacheCanvas.drawPath(item_t.getPath(), item_t.getPaint());
          } else if (item_t.getType() == HistoryItem.TYPE_TEXT) {
            mCacheCanvas.drawText(
                item_t.getText(),
                item_t.getTextStartPoint().x,
                item_t.getTextStartPoint().y,
                item_t.getPaint());
          } else if (item_t.getType() == HistoryItem.TYPE_ERASER) {
            item_t.getPaint().setXfermode(new PorterDuffXfermode(Mode.DST_IN));
            mCacheCanvas.drawPath(item_t.getPath(), item_t.getPaint());
          }
        }
        handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 3
0
 public void drawField(Canvas canvas) {
   canvas.drawPaint(mClearPaint);
   for (FE e : this) {
     setFieldRect(mFieldRect, e);
     e.draw(canvas, mFieldRect);
   }
 }
Esempio n. 4
0
  /**
   * Sets the icon for the marker. Can be changed at any time.
   *
   * @param icon if null, the default osmdroid marker is used.
   */
  public void setIcon(Drawable icon) {
    if (ENABLE_TEXT_LABELS_WHEN_NO_IMAGE
        && icon == null
        && this.mTitle != null
        && this.mTitle.length() > 0) {
      Paint background = new Paint();
      background.setColor(mTextLabelBackgroundColor);

      Paint p = new Paint();
      p.setTextSize(mTextLabelFontSize);
      p.setColor(mTextLabelForegroundColor);

      p.setAntiAlias(true);
      p.setTypeface(Typeface.DEFAULT_BOLD);
      p.setTextAlign(Paint.Align.LEFT);
      int width = (int) (p.measureText(getTitle()) + 0.5f);
      float baseline = (int) (-p.ascent() + 0.5f);
      int height = (int) (baseline + p.descent() + 0.5f);
      Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(image);
      c.drawPaint(background);
      c.drawText(getTitle(), 0, baseline, p);

      mIcon = new BitmapDrawable(resource, image);
    }
    if (!ENABLE_TEXT_LABELS_WHEN_NO_IMAGE && icon != null) this.mIcon = icon;
    // there's still an edge case here, title label no defined, icon is null and textlabel is
    // enabled
    if (this.mIcon == null) mIcon = mDefaultIcon;
  }
Esempio n. 5
0
 public void renderText(int x, int y, Canvas c, String text, int fontSize) {
   p.setColor(Color.TRANSPARENT);
   c.drawPaint(p);
   p.setColor(Color.GRAY);
   p.setStyle(Paint.Style.FILL);
   p.setTextSize(fontSize);
   c.drawText(text, x + 2, y + fontSize, p);
 }
Esempio n. 6
0
 /**
  * draw bottom/right half shadow
  *
  * @param canvas
  */
 private void drawNextShadow(Canvas canvas) {
   final float degreesFlipped = getDegreesFlipped();
   if (degreesFlipped < 90) {
     final int alpha = (int) ((Math.abs(degreesFlipped - 90) / 90f) * MAX_SHADOW_ALPHA);
     mShadowPaint.setAlpha(alpha);
     canvas.drawPaint(mShadowPaint);
   }
 }
 @Override
 public void onDraw(Canvas canvas) {
   if (mDrawCircle) {
     canvas.drawCircle(mAnimateFrom.centerX(), mAnimateFrom.centerY(), mRadius, mPaint);
   } else if (mFill) {
     canvas.drawPaint(mPaint);
   }
   super.onDraw(canvas);
 }
Esempio n. 8
0
 public void clearCanvas() {
   Paint paint = new Paint();
   paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
   if (mCacheCanvas != null && undoPathList != null && redoPathList != null) {
     mCacheCanvas.drawPaint(paint);
     paint.setXfermode(new PorterDuffXfermode(Mode.SRC));
     handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE);
     undoPathList.clear();
     redoPathList.clear();
   }
 }
Esempio n. 9
0
  @Override
  protected void onDraw(Canvas c) {
    super.onDraw(c);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);

    // make the entire canvas white
    paint.setColor(Color.WHITE);
    c.drawPaint(paint);

    paint.setColor(Color.BLUE);
    c.drawRect(50, 100, 200, 3, paint);

    // make the entire canvas white
    paint.setColor(Color.WHITE);
    c.drawPaint(paint);

    paint.setColor(Color.BLUE);
    c.drawRect(50, 100, 200, 3, paint);
  }
Esempio n. 10
0
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   Log.v("DrawBoundary", "onDraw");
   paint.setStyle(Paint.Style.STROKE);
   canvas.drawPaint(paint);
   width = getWidth();
   height = getHeight();
   // Use Color.parseColor to define HTML colors
   paint.setColor(Color.YELLOW);
   canvas.drawCircle(width / 2, height / 2, radius, paint);
 }
Esempio n. 11
0
 public static Bitmap bitmapWithPath(String path) {
   if (fileExits(path)) return decodeThumbFile(new File(path));
   else {
     Bitmap b = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888);
     Canvas canvas = new Canvas(b);
     Paint paint = new Paint();
     paint.setColor(Color.BLACK);
     paint.setTextSize(10);
     canvas.drawPaint(paint);
     // canvas.drawText("Loading", x, y, paint);
     canvas.drawARGB(1, 0, 0, 0);
     Log.d("thumb", "width = " + b.getWidth());
     return b;
   }
 }
Esempio n. 12
0
  @Override
  public Bitmap transform(Bitmap bitmap) {
    Bitmap mutableBitmap =
        Bitmap.createBitmap(
            bitmap.getWidth() + (mBorder * 2),
            bitmap.getHeight() + (mBorder * 2),
            bitmap.getConfig());

    Canvas canvas = new Canvas(mutableBitmap);
    Paint paint = new Paint();
    paint.setColor(mColor);
    canvas.drawPaint(paint);
    canvas.drawBitmap(bitmap, mBorder, mBorder, paint);
    return mutableBitmap;
  }
  public void updateBackground() {
    if (getWidth() == 0 || getHeight() == 0) {
      return;
    }
    Bitmap background = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
    background.eraseColor(ColorPickerDialog.mNewColor);
    Canvas checkerdBackgroundCanvas = new Canvas(background);

    Rect colorRect = new Rect(0, 0, getWidth(), getHeight());
    if (ColorPickerDialog.mBackgroundPaint != null) {
      checkerdBackgroundCanvas.drawRect(colorRect, ColorPickerDialog.mBackgroundPaint);
    }
    mColorPaint.setColor(ColorPickerDialog.mNewColor);
    checkerdBackgroundCanvas.drawPaint(mColorPaint);
    setBackgroundDrawable(new BitmapDrawable(background));
  }
Esempio n. 14
0
  @Override
  public void onDraw(Canvas c) {
    // c.drawColor(Color.BLUE);

    c.drawPaint(mFloorPaint);

    mRobot.draw(c);

    // c.drawText("Loops: " + String.valueOf(mLoops), 100, 100, mPaint);
    c.drawText("Time: " + (60 - (mTimer / 1000)), 50, 50, mPaint);

    String scoreText = "Score: " + String.valueOf(mScore);
    float widthOfText = mPaint.measureText(scoreText);

    c.drawText(scoreText, mScreenRect.width() - 50 - widthOfText, 50, mPaint);
  }
Esempio n. 15
0
  private void drawMarkedPosition(Canvas canvas) {
    if (markedPosition == null) return;

    canvas.save();

    float x = markedPosition.col * cellWidth;
    float y = markedPosition.row * cellHeight;
    canvas.translate(x, y);

    Paint paint =
        puzzle.isClue(markedPosition.row, markedPosition.col)
            ? theme.getMarkedPositionCluePaint()
            : theme.getMarkedPositionPaint();
    canvas.clipRect(0, 0, cellWidth, cellHeight);
    canvas.drawPaint(paint);

    canvas.restore();
  }
Esempio n. 16
0
  private void drawTextCanvas(Canvas canvas, String text) {
    // TODO Auto-generated method stub

    // set color the background
    canvas.drawPaint(paint);

    // Setup textView like your normanlly would with your activity context
    TextView tv = new TextView(mContext);

    tv.setMaxWidth(300);

    // setup Text
    tv.setText(mText);

    // set Textcolor
    tv.setTextColor(Color.BLUE);

    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);

    // enable SetDrawing cache
    tv.setDrawingCacheEnabled(true);

    tv.measure(
        MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(canvas.getHeight(), MeasureSpec.EXACTLY));
    tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

    Bitmap bm =
        BitmapFactory.decodeResource(getResources(), R.drawable.khung_xanh)
            .copy(Bitmap.Config.ARGB_8888, true);
    bm =
        Bitmap.createScaledBitmap(
            bm,
            tv.getMeasuredWidth() + 40,
            (int) ((int) tv.getLineCount() * (tv.getLineHeight() + 8)),
            true);
    canvas.drawBitmap(bm, 0, 0, paint);

    // draw bitmap from drawingcache to the canvas
    canvas.drawBitmap(tv.getDrawingCache(), 20, 20, paint);

    // disable drawing cache
    tv.setDrawingCacheEnabled(false);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    w = getWidth();
    h = getHeight();
    p.setColor(Color.BLACK);
    p.setStyle(Style.FILL);
    canvas.drawPaint(p);

    p.setColor(Color.WHITE);
    for (int i = 0; i < w; i += 100) {
      for (int j = 0; j < h; j += 50) {
        canvas.drawLine(i, 0, i, getHeight() - 10, p);
        canvas.drawLine(0, j, getWidth() - 10, j, p);
      }
    }
    p.setTextSize(20);
    canvas.drawText("Hatseflats", 10, 25, p);
  }
  @Override
  public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mPaint == null) mPaint = new Paint();

    if (mShader != null) {
      mShaderBitmap =
          Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
      Canvas tempCanvas = new Canvas(mShaderBitmap);
      Paint paint = new Paint();
      paint.setShader(mShader);
      tempCanvas.drawPaint(paint);
    }
    if (mVerts != null) {
      canvas.drawBitmapMesh(mBitmap, 50, 5, mVerts, 0, null, 0, null);
      if (mShaderBitmap != null)
        canvas.drawBitmapMesh(mShaderBitmap, 50, 5, mVerts, 0, null, 0, null);
    } else canvas.drawBitmap(mBitmap, new Matrix(), mPaint);
  }
Esempio n. 19
0
  private void drawPageGridOrLines(int w, int h) {

    Resources res = getResources();
    int xpos = Math.round(res.getDimension(R.dimen.grid_size));
    int ypos = Math.round(res.getDimension(R.dimen.grid_size));

    Bitmap newBackgroundBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
    Canvas newBackgroundCanvas = new Canvas();
    newBackgroundCanvas.setBitmap(newBackgroundBitmap);

    if (mBackgroundBitmap != null) {
      newBackgroundCanvas.drawBitmap(mBackgroundBitmap, 0, 0, null);
    }
    mBackgroundBitmap = newBackgroundBitmap;
    mBackgroundCanvas = newBackgroundCanvas;

    // make the entire canvas page colour
    mBackgroundCanvas.drawPaint(mPagePainter);

    // Draw Background Grid
    Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay();
    width = display.getWidth(); // start
    height = display.getHeight(); // end

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getContext());
    String pageBackgroundPref = prefs.getString("pageBackgroundPref", "Grid");

    // lines only
    if (!pageBackgroundPref.equals("None")) {
      for (int i = 0; i < height; i += ypos) {
        mBackgroundCanvas.drawLine(0, i, width, i, mGridPainter);
      }
    }

    if (pageBackgroundPref.equals("Grid")) {
      // add for square graph paper:
      for (int i = 0; i < width; i += xpos) {
        mBackgroundCanvas.drawLine(i, 0, i, height, mGridPainter);
      }
    }
  }
  public static SmartTexture createGradient(int width, int height, int... colors) {

    String key = "" + width + "x" + height + ":" + colors;

    if (all.containsKey(key)) {

      return all.get(key);

    } else {

      Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
      Canvas canvas = new Canvas(bmp);
      Paint paint = new Paint();
      paint.setShader(new LinearGradient(0, 0, 0, height, colors, null, TileMode.CLAMP));
      canvas.drawPaint(paint);

      SmartTexture tx = new SmartTexture(bmp);
      all.put(key, tx);
      return tx;
    }
  }
Esempio n. 21
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mShader != null) {
      canvas.setDrawFilter(mFast);

      int saveCount = canvas.save();

      mPaint.setShader(mShader);
      canvas.drawRect(mRealRect, mPaint);

      canvas.translate(mPaddingLeft - mLineBigSize / 2, 0);
      mPaint.setShader(mShader1);
      canvas.drawPaint(mPaint);

      mPaint.setShader(null);

      float rw = ((float) mRealRect.width() - (mCorrectionX)) / 2;
      canvas.drawBitmap(mIndicator, (rw + (rw * mValue)), 0, mPaint);
      canvas.restoreToCount(saveCount);
    }
  }
    private void drawNextFrame() {
      SurfaceHolder holder = getSurfaceHolder();
      mCanvas = holder.lockCanvas();

      // Create canvas once we're ready to draw
      mRect.set(0, 0, mCanvas.getWidth(), mCanvas.getHeight());

      if (mCanvasBitmap == null) {
        mCanvasBitmap =
            Bitmap.createBitmap(mCanvas.getWidth(), mCanvas.getHeight(), Bitmap.Config.ARGB_8888);
      }
      mCanvas.drawColor(mBgColor);

      if (mBytes != null) {
        // Render all audio renderers
        AudioData audioData = new AudioData(mBytes);
        for (Renderer r : mRenderers) {
          r.render(mCanvas, audioData, mRect);
        }
      }

      if (mFFTBytes != null) {
        // Render all FFT renderers
        FFTData fftData = new FFTData(mFFTBytes);
        for (Renderer r : mRenderers) {
          r.render(mCanvas, fftData, mRect);
        }
      }

      holder.unlockCanvasAndPost(mCanvas);

      mHandler.removeCallbacks(mUpdateDisplay);
      mHandler.postDelayed(mUpdateDisplay, 200);
      // Fade out old contents
      mCanvas.drawPaint(mFadePaint);
      Log.i(TAG, ".drawNextFrame()");
    }
Esempio n. 23
0
    @Override
    protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);

      // Draw color on background
      canvas.drawPaint(backgroundPaint);

      pauseBt.getPauseMenuButton().draw(canvas);

      if (showCardsState) // showing cards on game start for a few seconds
      for (int i = 0; i < cardList.size(); i++)
          canvas.drawBitmap(cardList.get(i).img, null, cardList.get(i).rect, null);
      else {
        for (int i = 0; i < cardList.size(); i++) // draw back side or normal side in all images
        {
          if (cardList.get(i).turned)
            canvas.drawBitmap(cardList.get(i).img, null, cardList.get(i).rect, null);
          else canvas.drawBitmap(backSideImg, null, cardList.get(i).rect, null);
        }

        if (currentSelectedRectIndex1 != -1)
          canvas.drawBitmap(
              cardList.get(currentSelectedRectIndex1).img,
              null,
              cardList.get(currentSelectedRectIndex1).rect,
              null); // draw current selected images
        if (currentSelectedRectIndex2 != -1)
          canvas.drawBitmap(
              cardList.get(currentSelectedRectIndex2).img,
              null,
              cardList.get(currentSelectedRectIndex2).rect,
              null);
      }
      // Invalidate view at about 60fps
      postDelayed(this, 16);
    }
Esempio n. 24
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {

    // GET SETTINGS FROM SHARED PREFERENCES
    SharedPreferences settingsF = getSharedPreferences(FUZZY_STUFF, 0);
    int backgroundColorF =
        settingsF.getInt("BackgroundColorF", this.getResources().getColor(R.color.palesky));
    int textColorF = settingsF.getInt("TextColorF", this.getResources().getColor(R.color.night));
    String packageName = settingsF.getString("PackageName", "com.android.alarmclock");
    String className = settingsF.getString("ClassName", "com.android.alarmclock.AlarmClock");

    // CALCULATE ALL THE TIME DEPENDENT VARIABLES

    // reset the time dependent addition
    long alarmAddMillis = 0;

    // get time instance and values
    Calendar rightNow = Calendar.getInstance();
    int thisMin = rightNow.get(Calendar.MINUTE);
    int thisHour = rightNow.get(Calendar.HOUR);

    // set correct hour values
    nextHour = thisHour + 1;
    if (thisHour == 0) {
      thisHour = 12;
    }
    if (nextHour == 13) {
      nextHour = 1;
    }

    // set text values based on minutes
    if (thisMin >= 0 && thisMin <= 7) {
      wordA = "its";
      wordB = "about";
      wordA_B = "its_about";
      clockH = thisHour;
      nextAlarmMin = 8;
      alarmAddMillis = 0;
    }
    if (thisMin >= 8 && thisMin <= 22) {
      wordA = "quarter";
      wordB = "past";
      wordA_B = "quarter_past";
      clockH = thisHour;
      nextAlarmMin = 23;
      alarmAddMillis = 0;
    }
    if (thisMin >= 23 && thisMin <= 37) {
      wordA = "half";
      wordB = "past";
      wordA_B = "half_past";
      clockH = thisHour;
      nextAlarmMin = 38;
      alarmAddMillis = 0;
    }
    if (thisMin >= 38 && thisMin <= 52) {
      wordA = "quarter";
      wordB = "to";
      wordA_B = "quarter_to";
      clockH = nextHour;
      nextAlarmMin = 53;
      alarmAddMillis = 0;
    }
    if (thisMin >= 53 && thisMin <= 59) {
      wordA = "its";
      wordB = "about";
      wordA_B = "its_about";
      clockH = nextHour;
      nextAlarmMin = 8;
      alarmAddMillis = 3600000;
    }

    // CANCEL ANY UNSENT ALARM
    if (alarmManager != null) {
      alarmManager.cancel(pendingIntent);
    }

    // SET UP THE NEXT ALARM

    // set the time
    Calendar nextAlarm = Calendar.getInstance();
    // add one hour of millis if its for the next hour
    nextAlarm.setTimeInMillis(System.currentTimeMillis() + alarmAddMillis);
    // set the correct minute
    nextAlarm.set(Calendar.MINUTE, nextAlarmMin);
    nextAlarm.set(Calendar.SECOND, 15);
    nextAlarm.set(Calendar.MILLISECOND, 0);

    // request the alarm
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent usIntent = new Intent(this, AlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(this, 0, usIntent, 0);
    // use onExact for API19+
    int currentApiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentApiVersion <= 18) {
      alarmManager.set(AlarmManager.RTC, nextAlarm.getTimeInMillis(), pendingIntent);
    } else {
      alarmManager.setExact(AlarmManager.RTC, nextAlarm.getTimeInMillis(), pendingIntent);
    }

    // SET UP THE IMAGES

    // get the resource id ints for images to send by remoteviews
    int timePhraseA =
        this.getResources().getIdentifier("phr_" + wordA, "drawable", this.getPackageName());
    int timePhraseB =
        this.getResources().getIdentifier("phr_" + wordB, "drawable", this.getPackageName());
    int timePhraseA_B =
        this.getResources().getIdentifier("phr_" + wordA_B, "drawable", this.getPackageName());
    int hourWordImageCrop =
        this.getResources().getIdentifier("num_" + clockH, "drawable", this.getPackageName());
    int hourWordImageWide =
        this.getResources()
            .getIdentifier("num_" + clockH + "_w", "drawable", this.getPackageName());

    // SET THE BITMAP COLOR AND OTHER VALUES
    fillPaintF = new Paint(Paint.FILTER_BITMAP_FLAG);
    fillPaintF.setColor(textColorF);
    fillPaintF.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;

    // ASSEMBLE THE PENDING INTENTS

    // create the open configuration pending intent
    Intent openAWC = new Intent(this, AppWidgetConfigure.class);
    openAWC.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent openAwcPi =
        PendingIntent.getActivity(this, 0, openAWC, PendingIntent.FLAG_UPDATE_CURRENT);

    // create the open alarms pending intent - done here because it couldnt be saved in prefs
    // set up open Alarms Intent
    PendingIntent alarmPI = null;
    PackageManager packageManager = this.getPackageManager();
    Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
    // get the activity info and attach to the intent
    try {
      ComponentName cn = new ComponentName(packageName, className);
      packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
      alarmClockIntent.setComponent(cn);
    } catch (PackageManager.NameNotFoundException e) {
      stopSelf();
    }
    // finalize the pending intent
    alarmPI = PendingIntent.getActivity(this, 0, alarmClockIntent, 0);

    // create the refresh widget pending intent
    Intent startUpdateF = new Intent(this, UpdateService.class);
    startUpdateF.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pendingStartUpdateF =
        PendingIntent.getService(this, 0, startUpdateF, PendingIntent.FLAG_UPDATE_CURRENT);

    // **** BACKGROUND IMAGE PREPARATION ****

    // draw an empty image
    bitmapBackgroundF = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    // paint in the color
    Canvas canvasBackgroundF = new Canvas(bitmapBackgroundF);
    fillPaintBackgroundF = new Paint();
    fillPaintBackgroundF.setColor(backgroundColorF);
    canvasBackgroundF.drawPaint(fillPaintBackgroundF);

    // SEND ALL THE STUFF TO THE PLACED WIDGETS

    // get appwidgetmanager instance for all widgets
    AppWidgetManager localAppWidgetManager = AppWidgetManager.getInstance(this);

    // update all 4x1 widget instances
    ComponentName thisWidget4x1 = new ComponentName(getBaseContext(), WidgetProvider4x1.class);
    int[] allWidgetIds4x1 = localAppWidgetManager.getAppWidgetIds(thisWidget4x1);
    if (allWidgetIds4x1 != null) {

      // join the images together into one strip
      Bitmap bitmap4x1partA = BitmapFactory.decodeResource(getResources(), timePhraseA, options);
      Bitmap bitmap4x1partB = BitmapFactory.decodeResource(getResources(), timePhraseB, options);
      Bitmap bitmap4x1partC =
          BitmapFactory.decodeResource(getResources(), hourWordImageCrop, options);

      Bitmap bitmap4x1strip =
          Bitmap.createBitmap(
              bitmap4x1partA.getWidth() + bitmap4x1partB.getWidth() + bitmap4x1partC.getWidth(),
              bitmap4x1partA.getHeight(),
              Bitmap.Config.ARGB_8888);
      Canvas canvas4x1strip = new Canvas(bitmap4x1strip);
      canvas4x1strip.drawBitmap(bitmap4x1partA, 0, 0, null);
      canvas4x1strip.drawBitmap(bitmap4x1partB, bitmap4x1partA.getWidth(), 0, null);
      canvas4x1strip.drawBitmap(
          bitmap4x1partC, bitmap4x1partA.getWidth() + bitmap4x1partB.getWidth(), 0, null);

      // generate adjusted images if color theme isnt default

      // strip
      Bitmap bitmap4x1strip2 = bitmap4x1strip.copy(Bitmap.Config.ARGB_8888, true);
      Canvas canvas4x1strip2 = new Canvas(bitmap4x1strip2);
      canvas4x1strip2.drawPaint(fillPaintF);

      for (int widgetId : allWidgetIds4x1) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout_4x1);
        remoteViews.setImageViewBitmap(R.id.imageviewBG, bitmapBackgroundF);
        remoteViews.setImageViewBitmap(R.id.imageviewABC, bitmap4x1strip2);
        remoteViews.setOnClickPendingIntent(R.id.topclickLeft, alarmPI);
        remoteViews.setOnClickPendingIntent(R.id.topclickRight, openAwcPi);
        localAppWidgetManager.updateAppWidget(widgetId, remoteViews);
      }
      bitmap4x1strip2 = null;
      canvas4x1strip2 = null;
      bitmap4x1strip = null;
      canvas4x1strip = null;
    }

    // update all 3x2 widget instances
    ComponentName thisWidget3x2 = new ComponentName(getBaseContext(), WidgetProvider3x2.class);
    int[] allWidgetIds3x2 = localAppWidgetManager.getAppWidgetIds(thisWidget3x2);
    if (allWidgetIds3x2 != null) {
      // generate adjusted images if color theme isnt default
      // time phrase
      if (bitmapTimePhraseA_B == null) {
        bitmapTimePhraseA_B1 = BitmapFactory.decodeResource(getResources(), timePhraseA_B, options);
        bitmapTimePhraseA_B = bitmapTimePhraseA_B1.copy(Bitmap.Config.ARGB_8888, true);
        canvasPhrase = new Canvas(bitmapTimePhraseA_B);
        canvasPhrase.drawPaint(fillPaintF);
      }
      // hour word
      if (bitmapHourWordImage == null) {
        bitmapHourWordImage1 =
            BitmapFactory.decodeResource(getResources(), hourWordImageWide, options);
        bitmapHourWordImage = bitmapHourWordImage1.copy(Bitmap.Config.ARGB_8888, true);
        canvasHour = new Canvas(bitmapHourWordImage);
        canvasHour.drawPaint(fillPaintF);
      }
      for (int widgetId : allWidgetIds3x2) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout_3x2);
        remoteViews.setImageViewBitmap(R.id.imageviewA_B, bitmapTimePhraseA_B);
        remoteViews.setImageViewBitmap(R.id.imageviewC, bitmapHourWordImage);
        remoteViews.setImageViewBitmap(R.id.imageviewBG, bitmapBackgroundF);
        remoteViews.setOnClickPendingIntent(R.id.topclickLeft, alarmPI);
        remoteViews.setOnClickPendingIntent(R.id.topclickRight, openAwcPi);
        localAppWidgetManager.updateAppWidget(widgetId, remoteViews);
      }
    }

    // CLEAR ALL THE BITMAPS
    bitmapTimePhraseA_B = null;
    bitmapTimePhraseA_B1 = null;
    bitmapHourWordImageCrop = null;
    bitmapHourWordImageCrop1 = null;
    bitmapHourWordImage = null;
    bitmapHourWordImage1 = null;
    canvasPhrase = null;
    canvasHour = null;
    bitmapBackgroundF = null;

    stopSelf();
    return super.onStartCommand(intent, flags, startId);
  }
Esempio n. 25
0
 public void clear() {
   if (canvas != null) {
     canvas.drawPaint(back);
   }
 }
Esempio n. 26
0
  /**
   * Something changed in our parent {@link TerminalView}, maybe it's a new parent, or maybe it's an
   * updated font size. We should recalculate terminal size information and request a PTY resize.
   */
  public final synchronized void parentChanged(TerminalView parent) {
    if (manager != null && !manager.isResizeAllowed()) {
      Log.d(TAG, "Resize is not allowed now");
      return;
    }

    this.parent = parent;
    final int width = parent.getWidth();
    final int height = parent.getHeight();

    // Something has gone wrong with our layout; we're 0 width or height!
    if (width <= 0 || height <= 0) return;

    clipboard = (ClipboardManager) parent.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    keyListener.setClipboardManager(clipboard);

    if (!forcedSize) {
      // recalculate buffer size
      int newColumns, newRows;

      newColumns = width / charWidth;
      newRows = height / charHeight;

      // If nothing has changed in the terminal dimensions and not an intial
      // draw then don't blow away scroll regions and such.
      if (newColumns == columns && newRows == rows) return;

      columns = newColumns;
      rows = newRows;
    }

    // reallocate new bitmap if needed
    boolean newBitmap = (bitmap == null);
    if (bitmap != null) newBitmap = (bitmap.getWidth() != width || bitmap.getHeight() != height);

    if (newBitmap) {
      discardBitmap();
      bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
      canvas.setBitmap(bitmap);
    }

    // clear out any old buffer information
    defaultPaint.setColor(Color.BLACK);
    canvas.drawPaint(defaultPaint);

    // Stroke the border of the terminal if the size is being forced;
    if (forcedSize) {
      int borderX = (columns * charWidth) + 1;
      int borderY = (rows * charHeight) + 1;

      defaultPaint.setColor(Color.GRAY);
      defaultPaint.setStrokeWidth(0.0f);
      if (width >= borderX) canvas.drawLine(borderX, 0, borderX, borderY + 1, defaultPaint);
      if (height >= borderY) canvas.drawLine(0, borderY, borderX + 1, borderY, defaultPaint);
    }

    try {
      // request a terminal pty resize
      synchronized (buffer) {
        buffer.setScreenSize(columns, rows, true);
      }

      if (transport != null) transport.setDimensions(columns, rows, width, height);
    } catch (Exception e) {
      Log.e(TAG, "Problem while trying to resize screen or PTY", e);
    }

    // redraw local output if we don't have a sesson to receive our resize request
    if (transport == null) {
      synchronized (localOutput) {
        ((vt320) buffer).reset();

        for (String line : localOutput) ((vt320) buffer).putString(line);
      }
    }

    // force full redraw with new buffer size
    fullRedraw = true;
    redraw();

    parent.notifyUser(String.format("%d x %d", columns, rows));

    Log.i(TAG, String.format("parentChanged() now width=%d, height=%d", columns, rows));
  }
Esempio n. 27
0
  public void onDraw() {
    int fg, bg;
    synchronized (buffer) {
      boolean entireDirty = buffer.update[0] || fullRedraw;
      boolean isWideCharacter = false;

      // walk through all lines in the buffer
      for (int l = 0; l < buffer.height; l++) {

        // check if this line is dirty and needs to be repainted
        // also check for entire-buffer dirty flags
        if (!entireDirty && !buffer.update[l + 1]) continue;

        // reset dirty flag for this line
        buffer.update[l + 1] = false;

        // walk through all characters in this line
        for (int c = 0; c < buffer.width; c++) {
          int addr = 0;
          int currAttr = buffer.charAttributes[buffer.windowBase + l][c];

          {
            int fgcolor = defaultFg;

            // check if foreground color attribute is set
            if ((currAttr & VDUBuffer.COLOR_FG) != 0)
              fgcolor = ((currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT) - 1;

            if (fgcolor < 8 && (currAttr & VDUBuffer.BOLD) != 0) fg = color[fgcolor + 8];
            else fg = color[fgcolor];
          }

          // check if background color attribute is set
          if ((currAttr & VDUBuffer.COLOR_BG) != 0)
            bg = color[((currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT) - 1];
          else bg = color[defaultBg];

          // support character inversion by swapping background and foreground color
          if ((currAttr & VDUBuffer.INVERT) != 0) {
            int swapc = bg;
            bg = fg;
            fg = swapc;
          }

          // set underlined attributes if requested
          defaultPaint.setUnderlineText((currAttr & VDUBuffer.UNDERLINE) != 0);

          isWideCharacter = (currAttr & VDUBuffer.FULLWIDTH) != 0;

          if (isWideCharacter) addr++;
          else {
            // determine the amount of continuous characters with the same settings and print them
            // all at once
            while (c + addr < buffer.width
                && buffer.charAttributes[buffer.windowBase + l][c + addr] == currAttr) {
              addr++;
            }
          }

          // Save the current clip region
          canvas.save(Canvas.CLIP_SAVE_FLAG);

          // clear this dirty area with background color
          defaultPaint.setColor(bg);
          if (isWideCharacter) {
            canvas.clipRect(
                c * charWidth, l * charHeight, (c + 2) * charWidth, (l + 1) * charHeight);
          } else {
            canvas.clipRect(
                c * charWidth, l * charHeight, (c + addr) * charWidth, (l + 1) * charHeight);
          }
          canvas.drawPaint(defaultPaint);

          // write the text string starting at 'c' for 'addr' number of characters
          defaultPaint.setColor(fg);
          if ((currAttr & VDUBuffer.INVISIBLE) == 0)
            canvas.drawText(
                buffer.charArray[buffer.windowBase + l],
                c,
                addr,
                c * charWidth,
                (l * charHeight) - charTop,
                defaultPaint);

          // Restore the previous clip region
          canvas.restore();

          // advance to the next text block with different characteristics
          c += addr - 1;
          if (isWideCharacter) c++;
        }
      }

      // reset entire-buffer flags
      buffer.update[0] = false;
    }
    fullRedraw = false;
  }
Esempio n. 28
0
  @SuppressLint("WrongCall") // Suppress the warning since this does not refer to Android's onDraw()
  @Override
  public void onDraw(Canvas canvas) {
    if (bridge.bitmap != null) {
      // draw the bitmap
      bridge.onDraw();

      // draw the bridge bitmap if it exists
      canvas.drawBitmap(bridge.bitmap, 0, 0, paint);

      // also draw cursor if visible
      if (bridge.buffer.isCursorVisible()) {
        int cursorColumn = bridge.buffer.getCursorColumn();
        final int cursorRow = bridge.buffer.getCursorRow();

        final int columns = bridge.buffer.getColumns();

        if (cursorColumn == columns) cursorColumn = columns - 1;

        if (cursorColumn < 0 || cursorRow < 0) return;

        int currentAttribute = bridge.buffer.getAttributes(cursorColumn, cursorRow);
        boolean onWideCharacter = (currentAttribute & VDUBuffer.FULLWIDTH) != 0;

        int x = cursorColumn * bridge.charWidth;
        int y =
            (bridge.buffer.getCursorRow() + bridge.buffer.screenBase - bridge.buffer.windowBase)
                * bridge.charHeight;

        // Save the current clip and translation
        canvas.save();

        canvas.translate(x, y);
        canvas.clipRect(0, 0, bridge.charWidth * (onWideCharacter ? 2 : 1), bridge.charHeight);
        canvas.drawPaint(cursorPaint);

        final int deadKey = bridge.getKeyHandler().getDeadKey();
        if (deadKey != 0) {
          canvas.drawText(new char[] {(char) deadKey}, 0, 1, 0, 0, cursorStrokePaint);
        }

        // Make sure we scale our decorations to the correct size.
        canvas.concat(scaleMatrix);

        int metaState = bridge.getKeyHandler().getMetaState();

        if ((metaState & TerminalKeyListener.OUR_SHIFT_ON) != 0)
          canvas.drawPath(shiftCursor, cursorStrokePaint);
        else if ((metaState & TerminalKeyListener.OUR_SHIFT_LOCK) != 0)
          canvas.drawPath(shiftCursor, cursorPaint);

        if ((metaState & TerminalKeyListener.OUR_ALT_ON) != 0)
          canvas.drawPath(altCursor, cursorStrokePaint);
        else if ((metaState & TerminalKeyListener.OUR_ALT_LOCK) != 0)
          canvas.drawPath(altCursor, cursorPaint);

        if ((metaState & TerminalKeyListener.OUR_CTRL_ON) != 0)
          canvas.drawPath(ctrlCursor, cursorStrokePaint);
        else if ((metaState & TerminalKeyListener.OUR_CTRL_LOCK) != 0)
          canvas.drawPath(ctrlCursor, cursorPaint);

        // Restore previous clip region
        canvas.restore();
      }

      // draw any highlighted area
      if (bridge.isSelectingForCopy()) {
        SelectionArea area = bridge.getSelectionArea();
        canvas.save(Canvas.CLIP_SAVE_FLAG);
        canvas.clipRect(
            area.getLeft() * bridge.charWidth,
            area.getTop() * bridge.charHeight,
            (area.getRight() + 1) * bridge.charWidth,
            (area.getBottom() + 1) * bridge.charHeight);
        canvas.drawPaint(cursorPaint);
        canvas.restore();
      }
    }
  }