예제 #1
0
 @Override
 public void draw(Canvas canvas) {
   canvas.save();
   canvas.rotate(rotation, drawableArea.exactCenterX(), drawableArea.exactCenterY());
   canvas.drawPath(glyphPath, glyphPaint);
   canvas.restore();
 }
 public void onWindowTransitionLocked(WindowState windowState, int transition) {
   if (DEBUG_WINDOW_TRANSITIONS) {
     Slog.i(
         LOG_TAG,
         "Window transition: "
             + AppTransition.appTransitionToString(transition)
             + " displayId: "
             + windowState.getDisplayId());
   }
   final boolean magnifying = mMagnifedViewport.isMagnifyingLocked();
   final int type = windowState.mAttrs.type;
   switch (transition) {
     case WindowManagerPolicy.TRANSIT_ENTER:
     case WindowManagerPolicy.TRANSIT_SHOW:
       {
         if (!magnifying) {
           break;
         }
         switch (type) {
           case WindowManager.LayoutParams.TYPE_APPLICATION:
           case WindowManager.LayoutParams.TYPE_APPLICATION_PANEL:
           case WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA:
           case WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL:
           case WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG:
           case WindowManager.LayoutParams.TYPE_SEARCH_BAR:
           case WindowManager.LayoutParams.TYPE_PHONE:
           case WindowManager.LayoutParams.TYPE_SYSTEM_ALERT:
           case WindowManager.LayoutParams.TYPE_TOAST:
           case WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY:
           case WindowManager.LayoutParams.TYPE_PRIORITY_PHONE:
           case WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG:
           case WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG:
           case WindowManager.LayoutParams.TYPE_SYSTEM_ERROR:
           case WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY:
           case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL:
           case WindowManager.LayoutParams.TYPE_RECENTS_OVERLAY:
             {
               Rect magnifiedRegionBounds = mTempRect2;
               mMagnifedViewport.getMagnifiedFrameInContentCoordsLocked(magnifiedRegionBounds);
               Rect touchableRegionBounds = mTempRect1;
               windowState.getTouchableRegion(mTempRegion1);
               mTempRegion1.getBounds(touchableRegionBounds);
               if (!magnifiedRegionBounds.intersect(touchableRegionBounds)) {
                 try {
                   mCallbacks.onRectangleOnScreenRequested(
                       touchableRegionBounds.left,
                       touchableRegionBounds.top,
                       touchableRegionBounds.right,
                       touchableRegionBounds.bottom);
                 } catch (RemoteException re) {
                   /* ignore */
                 }
               }
             }
             break;
         }
         break;
       }
   }
 }
예제 #3
0
  @Override
  protected void onDraw(Canvas canvas) {
    int i = 1;
    if (percentList != null && !percentList.isEmpty()) {
      for (Float f : percentList) {
        rect.set(
            BAR_SIDE_MARGIN * i + barWidth * (i - 1),
            topMargin,
            (BAR_SIDE_MARGIN + barWidth) * i,
            getHeight() - bottomTextHeight - TEXT_TOP_MARGIN);
        canvas.drawRect(rect, bgPaint);
        rect.set(
            BAR_SIDE_MARGIN * i + barWidth * (i - 1),
            topMargin + (int) ((getHeight() - topMargin) * percentList.get(i - 1)),
            (BAR_SIDE_MARGIN + barWidth) * i,
            getHeight() - bottomTextHeight - TEXT_TOP_MARGIN);
        canvas.drawRect(rect, fgPaint);
        i++;
      }
    }

    if (bottomTextList != null && !bottomTextList.isEmpty()) {
      i = 1;
      for (String s : bottomTextList) {
        canvas.drawText(
            s,
            BAR_SIDE_MARGIN * i + barWidth * (i - 1) + barWidth / 2,
            getHeight() - bottomTextDescent,
            textPaint);
        i++;
      }
    }
  }
  // ==============================================================================
  public final int[] renderGlyph(
      char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) {
    Path p = new Path();
    paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds(boundsF, true);
    matrix.mapRect(boundsF);

    boundsF.roundOut(bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = bounds.height();

    Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bm);
    matrix.postTranslate(-bounds.left, -bounds.top);
    c.setMatrix(matrix);
    c.drawPath(p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded];

    bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
  }
예제 #5
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mContent.set(
        getPaddingLeft(), getPaddingTop(), r - l - getPaddingRight(), b - t - getPaddingBottom());
    final int width = mContent.width();
    final int height = mContent.height();

    // no scrolling yet, so tell dimensions to fill exactly
    mHoriz.setSize(width);
    mVert.setSize(height);

    final Rect parentRect = new Rect();
    final Rect childRect = new Rect();

    for (int i = 0; i < getChildCount(); i++) {
      final View child = getChildAt(i);
      final LayoutParams params = (LayoutParams) child.getLayoutParams();

      parentRect.set(mContent);

      if (child instanceof ChartNetworkSeriesView || child instanceof ChartGridView) {
        // series are always laid out to fill entire graph area
        // TODO: handle scrolling for series larger than content area
        Gravity.apply(params.gravity, width, height, parentRect, childRect);
        child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);

      } else if (child instanceof ChartSweepView) {
        layoutSweep((ChartSweepView) child, parentRect, childRect);
        child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
      }
    }
  }
예제 #6
0
 @Override
 protected void onDraw(Canvas canvas) {
   if (processor.isLoaded()) {
     int offsetLeft = (getWidth() - countInRow * smileySize) / 2;
     for (int i = 0; i < smileyIds.length; i++) {
       int row = i / countInRow;
       int col = i % countInRow;
       rect.set(
           col * smileySize + smileyPadding + offsetLeft,
           row * smileySize + smileyPadding,
           (col + 1) * smileySize - smileyPadding + offsetLeft,
           (row + 1) * smileySize - smileyPadding);
       if (!canvas.quickReject(rect.left, rect.top, rect.right, rect.bottom, Canvas.EdgeType.AA)) {
         Bitmap img = processor.getSection(smileysSections[i]);
         if (img != null) {
           sectionRect.set(
               smileysX[i] * smileySrcSize,
               smileysY[i] * smileySrcSize,
               (smileysX[i] + 1) * smileySrcSize,
               (smileysY[i] + 1) * smileySrcSize);
           canvas.drawBitmap(img, sectionRect, rect, paint);
         }
       }
     }
   }
 }
예제 #7
0
 @Override
 public boolean onLoadInt(int command_, int intData_) {
   try {
     switch (command_) {
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTLEFT:
         _BitmapRect.left = intData_;
         break;
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTTOP:
         _BitmapRect.top = intData_;
         break;
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTRIGHT:
         _BitmapRect.right = intData_;
         break;
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTBOTTOM:
         _BitmapRect.bottom = intData_;
         break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSLEFT:
         //                        _PositionRect.left = intData_;
         //                        break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSTOP:
         //                        _PositionRect.top = intData_;
         //                        break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSRIGHT:
         //                        _PositionRect.right = intData_;
         //                        break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSBOTTOM:
         //                        _PositionRect.bottom = intData_;
         //                        break;
     }
   } catch (Exception e) {
     return false;
   }
   return true;
 }
예제 #8
0
 public void paintBitmap(Context context, Canvas c, Rect dest) {
   int color0 = Color.argb(0xFF, 196, 181, 51);
   int color1 = Color.argb(0xFF, 251, 219, 39);
   int color2 = Color.argb(0xFF, 255, 239, 151);
   int border = Color.argb(0xFF, 220, 200, 80);
   Paint p = new Paint();
   p.setAntiAlias(true);
   float width = dest.width() / 20.0f;
   float insideSize = dest.width() - 2 * width;
   RectF inside1 =
       new RectF(
           dest.left + width - 1,
           dest.top + width - 1,
           dest.right - width + 1,
           dest.bottom - width + 1);
   RectF inside =
       new RectF(dest.left + width, dest.top + width, dest.right - width, dest.bottom - width);
   LinearGradient linear =
       new LinearGradient(
           inside1.left,
           inside1.top + insideSize / 3,
           inside1.right,
           inside1.top + 2 * insideSize / 3,
           new int[] {color0, color1, color2},
           null,
           Shader.TileMode.CLAMP);
   p.setShader(linear);
   c.drawRoundRect(inside1, width, width, p);
   p.setShader(null);
   p.setColor(border);
   Path path = new Path();
   path.addRoundRect(inside, width, width, Path.Direction.CCW);
   path.addRect(new RectF(dest), Path.Direction.CW);
   c.drawPath(path, p);
 }
예제 #9
0
 private void getScreenBitmap() {
   mView.getRootView().destroyDrawingCache();
   mView.getGlobalVisibleRect(mRect, point);
   realheight = mView.getHeight();
   realwidth = mView.getWidth();
   dst.set(0, 0, realwidth, realheight);
   int w = Math.round(realwidth * BITMAP_RATIO);
   int h = Math.round(realheight * BITMAP_RATIO);
   w = w & ~0x03;
   h = h & ~0x03;
   if (w <= 0 || h <= 0) return;
   if (bitmap == null || bitmap.getWidth() != w || bitmap.getHeight() != h) {
     bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
     mMatrix.setScale(BITMAP_RATIO, BITMAP_RATIO);
     mMatrix.invert(mDrawMatrix);
     src.set(0, 0, w, h);
   }
   float dx = -(Math.min(0, mView.getLeft()) + mRect.left);
   float dy = (-point.y);
   mCanvas.restoreToCount(1);
   mCanvas.setBitmap(bitmap);
   mCanvas.setMatrix(mMatrix);
   mCanvas.translate(dx, dy);
   mCanvas.save();
   mView.getRootView().draw(mCanvas);
 }
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

      if (distanceY != 0 && distanceX != 0) {}

      if (null != bannerView) {
        Rect rect = new Rect();
        bannerView.getHitRect(rect);

        if (null != e1) {
          if (rect.contains((int) e1.getX(), (int) e1.getY())) {
            return false;
          }
        }

        if (null != e2) {
          if (rect.contains((int) e2.getX(), (int) e2.getY())) {
            return false;
          }
        }
      }
      //            if(Math.abs(distanceY) >= Math.abs(distanceX))
      //            {
      //                Log.e("listview", "********************** distanceX :" + distanceX + "
      // distanceY" + distanceY + "\n");
      //                return true;
      //            }
      //            Log.e("listview", "-------------------------- distanceX :" + distanceX + "
      // distanceY" + distanceY + "\n");
      return true;
    }
예제 #11
0
  /**
   * Returns a PNG-encoded screenshot of the the window region at (|windowX|, |windowY|) with the
   * size |width| by |height| pixels.
   */
  @CalledByNative
  public byte[] grabSnapshot(int windowX, int windowY, int width, int height) {
    try {
      // Take a screenshot of the root activity view. This generally includes UI
      // controls such as the URL bar and OS windows such as the status bar.
      View rootView = mActivity.findViewById(android.R.id.content).getRootView();
      Bitmap bitmap = UiUtils.generateScaledScreenshot(rootView, 0, Bitmap.Config.ARGB_8888);
      if (bitmap == null) return null;

      // Clip the result into the requested region.
      if (windowX > 0
          || windowY > 0
          || width != bitmap.getWidth()
          || height != bitmap.getHeight()) {
        Rect clip = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        clip.intersect(windowX, windowY, windowX + width, windowY + height);
        bitmap = Bitmap.createBitmap(bitmap, clip.left, clip.top, clip.width(), clip.height());
      }

      // Compress the result into a PNG.
      ByteArrayOutputStream result = new ByteArrayOutputStream();
      if (!bitmap.compress(Bitmap.CompressFormat.PNG, 100, result)) return null;
      bitmap.recycle();
      return result.toByteArray();
    } catch (OutOfMemoryError e) {
      Log.e(TAG, "Out of memory while grabbing window snapshot.", e);
      return null;
    }
  }
        @Override
        public boolean onTouch(View v, MotionEvent event) {
          switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
              matrix.getValues(imageValues);

              selectedPoint[0] = (event.getX() - imageValues[2]) / imageValues[0];
              selectedPoint[1] = (event.getY() - imageValues[5]) / imageValues[4];

              Log.d("POINT_TOUCH", "IMAGE : " + selectedPoint[0] + " and " + selectedPoint[1]);

              if (selectedPoint[1] < bounds.height()) {
                marker.setX(event.getX() - markerBounds.width() / 2);
                marker.setY(event.getY() - markerBounds.height());
                marker.setAlpha(VISIBLE);
                measureButton.setClickable(true);
                measureButton.setEnabled(true);
              } else {
                marker.setAlpha(TRANSPARENT);
                measureButton.setClickable(false);
                measureButton.setEnabled(false);
              }
              break;
          }
          return true;
        }
예제 #13
0
 private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
   TypedArray a =
       context.obtainStyledAttributes(
           attrs, R.styleable.CardView, defStyleAttr, R.style.CardView_Light);
   int backgroundColor = a.getColor(R.styleable.CardView_cardBackgroundColor, 0);
   float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0);
   float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0);
   float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0);
   mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false);
   mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true);
   int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0);
   mContentPadding.left =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, defaultPadding);
   mContentPadding.top =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, defaultPadding);
   mContentPadding.right =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, defaultPadding);
   mContentPadding.bottom =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, defaultPadding);
   if (elevation > maxElevation) {
     maxElevation = elevation;
   }
   a.recycle();
   IMPL.initialize(this, context, backgroundColor, radius, elevation, maxElevation);
 }
예제 #14
0
  private void computeGlyphPath() {
    drawableArea.set(getBounds());
    drawableArea.inset(padding, padding);
    glyphPaint.getTextPath(glyph, 0, 1, 0, 0, glyphPath);
    // Add an extra path point to fix the icon remaining blank on a Galaxy Note 2 running 4.1.2.
    glyphPath.computeBounds(glyphPathBounds, false);
    final float centerX = glyphPathBounds.centerX();
    final float centerY = glyphPathBounds.centerY();
    glyphPath.moveTo(centerX, centerY);
    glyphPath.lineTo(centerX + 0.001f, centerY + 0.001f);
    final float areaWidthF = (float) drawableArea.width();
    final float areaHeightF = (float) drawableArea.height();
    final float scaleX = areaWidthF / glyphPathBounds.width();
    final float scaleY = areaHeightF / glyphPathBounds.height();
    final float scaleFactor = Math.min(scaleX, scaleY);
    glyphPathTransform.setScale(scaleFactor, scaleFactor);
    glyphPath.transform(glyphPathTransform);

    // TODO this two pass calculation irks me.
    // It has to be possible to push this into a single Matrix transform; what makes it hard is
    // that the origin of Text is not top-left, but baseline-left so need to account for that.
    glyphPath.computeBounds(glyphPathBounds, false);
    final float areaLeftF = (float) drawableArea.left;
    final float areaTopF = (float) drawableArea.top;
    float transX = areaLeftF - glyphPathBounds.left;
    transX += 0.5f * Math.abs(areaWidthF - glyphPathBounds.width());
    float transY = areaTopF - glyphPathBounds.top;
    transY += 0.5f * Math.abs(areaHeightF - glyphPathBounds.height());
    glyphPath.offset(transX, transY);

    invalidateSelf();
  }
예제 #15
0
  /**
   * This will generate a bitmap with the pattern as big as the rectangle we were allow to draw on.
   * We do this to chache the bitmap so we don't need to recreate it each time draw() is called
   * since it takes a few milliseconds.
   */
  private void generatePatternBitmap() {

    if (getBounds().width() <= 0 || getBounds().height() <= 0) {
      return;
    }

    mBitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888);
    Canvas canvas = new Canvas(mBitmap);

    Rect r = new Rect();
    boolean verticalStartWhite = true;
    for (int i = 0; i <= numRectanglesVertical; i++) {

      boolean isWhite = verticalStartWhite;
      for (int j = 0; j <= numRectanglesHorizontal; j++) {

        r.top = i * mRectangleSize;
        r.left = j * mRectangleSize;
        r.bottom = r.top + mRectangleSize;
        r.right = r.left + mRectangleSize;

        canvas.drawRect(r, isWhite ? mPaintWhite : mPaintGray);

        isWhite = !isWhite;
      }

      verticalStartWhite = !verticalStartWhite;
    }
  }
 protected void onDraw(Canvas canvas)
 {
     this;
     JVM INSTR monitorenter ;
     c.set(getThumbOffset(), getHeight() / 2 - f / 4, getWidth() - getThumbOffset(), getHeight() / 2 + f / 4);
     d.setColor(0xff888888);
     canvas.drawRect(c, d);
     int i = getWidth();
     int j = getHeight();
     canvas.drawBitmap(e, i / 2 - e.getWidth() / 2, j / 2 - e.getHeight() / 2, null);
     if (getProgress() > 500)
     {
         c.set(getWidth() / 2, getHeight() / 2 - f / 2, (getWidth() / 2 + (getWidth() * (getProgress() - 500)) / 1000) - ((getProgress() - 500) * getThumbOffset()) / 500, getHeight() / 2 + f / 2);
         d.setColor(g.getResources().getColor(0x7f0f0007));
         canvas.drawRect(c, d);
     }
     if (getProgress() < 500)
     {
         c.set((getWidth() / 2 - (getWidth() * (500 - getProgress())) / 1000) + ((500 - getProgress()) * getThumbOffset()) / 500, getHeight() / 2 - f / 2, getWidth() / 2, getHeight() / 2 + f / 2);
         d.setColor(g.getResources().getColor(0x7f0f0007));
         canvas.drawRect(c, d);
     }
     super.onDraw(canvas);
     this;
     JVM INSTR monitorexit ;
     return;
     canvas;
     throw canvas;
 }
예제 #17
0
  @StressTest
  @UiThreadTest
  public void testRandomTouch() {
    MemoryLogger memoryLogger = new MemoryLogger("testRandomTouch", 100);

    viewManager.setKeyboardLayout(KeyboardLayout.TWELVE_KEYS);

    final int actions = 500;

    final Random random = new Random();
    Rect rect = getViewRect();

    memoryLogger.logMemory("start");
    for (int i = 0; i < actions; i++) {
      final int x = rect.left + random.nextInt(rect.width());
      final int y = rect.top + random.nextInt(rect.height());

      inputView.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, x, y, 0));
      inputView.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, x, y, 0));

      // updateRequest sends asynchronous message to server. So we need to wait a moment
      // for server processing.
      sleep(200);

      memoryLogger.logMemoryInterval();
    }
    memoryLogger.logMemory("start");
  }
예제 #18
0
 public void onDraw(Canvas canvas)
 {
     canvas.drawARGB(255, 0, 0, 0);
     getDrawingRect(a);
     b.as.a(canvas, (a.width() - b.as.f) / 2, (a.height() - b.as.g) / 2);
     invalidate();
 }
예제 #19
0
  // 裁剪解决方案---(根据Bitmap图片压缩)
  public static Bitmap createScaledBitmap(
      Bitmap unscaledBitmap, int dstWidth, int dstHeight, ScalingLogic scalingLogic) {

    Rect srcRect =
        calculateSrcRect(
            unscaledBitmap.getWidth(),
            unscaledBitmap.getHeight(),
            dstWidth,
            dstHeight,
            scalingLogic);

    Rect dstRect =
        calculateDstRect(
            unscaledBitmap.getWidth(),
            unscaledBitmap.getHeight(),
            dstWidth,
            dstHeight,
            scalingLogic);

    Bitmap scaledBitmap = Bitmap.createBitmap(dstRect.width(), dstRect.height(), Config.RGB_565);

    Canvas canvas = new Canvas(scaledBitmap);

    canvas.drawBitmap(unscaledBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG));

    return scaledBitmap;
  }
예제 #20
0
 /**
  * A factory method to build the appropriate LuminanceSource object based on the format of the
  * preview buffers, as described by Camera.Parameters.
  *
  * @param data A preview frame.
  * @param width The width of the image.
  * @param height The height of the image.
  * @return A PlanarYUVLuminanceSource instance.
  */
 public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
   Rect rect = getFramingRectInPreview();
   int previewFormat = configManager.getPreviewFormat();
   String previewFormatString = configManager.getPreviewFormatString();
   switch (previewFormat) {
       // This is the standard Android format which all devices are REQUIRED to
       // support.
       // In theory, it's the only one we should ever care about.
     case PixelFormat.YCbCr_420_SP:
       // This format has never been seen in the wild, but is compatible as
       // we only care
       // about the Y channel, so allow it.
     case PixelFormat.YCbCr_422_SP:
       return new PlanarYUVLuminanceSource(
           data, width, height, rect.left, rect.top, rect.width(), rect.height());
     default:
       // The Samsung Moment incorrectly uses this variant instead of the
       // 'sp' version.
       // Fortunately, it too has all the Y data up front, so we can read
       // it.
       if ("yuv420p".equals(previewFormatString)) {
         return new PlanarYUVLuminanceSource(
             data, width, height, rect.left, rect.top, rect.width(), rect.height());
       }
   }
   throw new IllegalArgumentException(
       "Unsupported picture format: " + previewFormat + '/' + previewFormatString);
 }
 @Override
 public boolean onSingleTapConfirmed(MotionEvent e) {
   Rect viewRect = new Rect();
   for (int i = 0; i < getChildCount(); i++) {
     View child = getChildAt(i);
     int left = child.getLeft();
     int right = child.getRight();
     int top = child.getTop();
     int bottom = child.getBottom();
     viewRect.set(left, top, right, bottom);
     if (viewRect.contains((int) e.getX(), (int) e.getY())) {
       if (mOnItemClicked != null) {
         mOnItemClicked.onItemClick(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       if (mOnItemSelected != null) {
         mOnItemSelected.onItemSelected(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       break;
     }
   }
   return true;
 }
예제 #22
0
  @Override
  public void draw(Canvas canvas, Rect chartArea) {
    int n = points.size();
    scaledGap = barGap * (float) (chartArea.width() / (maxX - minX));
    barWidth = (chartArea.width() - scaledGap * (n - 1)) / n;

    Point p;
    double scaledY;
    double yMax = chartArea.top;

    for (int i = 0; i < points.size(); i++) {

      y0 = chartArea.top + chartArea.height();

      p = points.get(i);
      scaledY = (p.getY() - minY + barGap) * (chartArea.height()) / (maxY - minY + 2 * barGap);
      double scaledX = i * (barWidth + scaledGap);

      if (!areSum.get(i)) {
        y0 = yMax + scaledY;
        drawPoint(canvas, scaledX + chartArea.left, yMax, colors.get(i));
        yMax += scaledY;
      } else {
        drawPoint(
            canvas,
            scaledX + chartArea.left,
            chartArea.top + chartArea.height() - scaledY,
            colors.get(i));
      }
    }
  }
  /** @brief update helper function for the polaroid bg layer */
  private void updatePolaroidDrawable(Rect bounds) {
    PDEColor highColor;
    PDEColor lowColor;
    float red, green, blue;
    Rect frameRect = new Rect(0, 0, bounds.width(), bounds.height());

    mElementCornerRadius = bounds.width() * 0.07f;
    // update Frame
    mElementPolaroidDrawable.setBounds(frameRect);
    mElementPolaroidDrawable.setElementCornerRadius(mElementCornerRadius);
    mElementPolaroidDrawable.setElementBorderColor(mElementPolaroidFrameColor);
    // todo: this border stuff does not work properly!!! So we take a workaround.
    // mElementPolaroidDrawable.setElementBorderWidth(polaroidRelativeValue(2.5f));
    int border = Math.round(polaroidRelativeValue(2.5f));
    mElementGradientDrawable.setBounds(
        frameRect.left + border,
        frameRect.top + border,
        frameRect.right - border,
        frameRect.bottom - border);

    red = mElementPolaroidFrameColor.getRed();
    blue = mElementPolaroidFrameColor.getBlue();
    green = mElementPolaroidFrameColor.getGreen();

    highColor = new PDEColor(red, green, blue, 0.0f);
    lowColor = new PDEColor(red - 0.33f, green - 0.33f, blue - 0.33f, 0.75f);
    mElementGradientDrawable.setElementBackgroundGradientColors(highColor, highColor, lowColor);
    mElementGradientDrawable.setElementGradientDistributionPositions(0.0f, 0.85f, 1.0f);

    // set other layer data
    mElementPolaroidDrawable.setElementBackgroundColor(mElementPolaroidFrameColor);
    mElementGradientDrawable.setElementCornerRadius(mElementCornerRadius);
    mElementGradientDrawable.setElementBorderColor(PDEColor.valueOf("DTTransparentBlack"));
  }
  // Determines which edges are hit by touching at (x, y)
  public int getHit(float x, float y) {
    Rect r = computeLayout();
    final float hysteresis = 20F;
    int retval = GROW_NONE;

    // verticalCheck makes sure the position is between the top and
    // the bottom edge (with some tolerance). Similar for horizCheck.
    boolean verticalCheck = (y >= r.top - hysteresis) && (y < r.bottom + hysteresis);
    boolean horizCheck = (x >= r.left - hysteresis) && (x < r.right + hysteresis);

    // Check whether the position is near some edge(s)
    if ((Math.abs(r.left - x) < hysteresis) && verticalCheck) {
      retval |= GROW_LEFT_EDGE;
    }
    if ((Math.abs(r.right - x) < hysteresis) && verticalCheck) {
      retval |= GROW_RIGHT_EDGE;
    }
    if ((Math.abs(r.top - y) < hysteresis) && horizCheck) {
      retval |= GROW_TOP_EDGE;
    }
    if ((Math.abs(r.bottom - y) < hysteresis) && horizCheck) {
      retval |= GROW_BOTTOM_EDGE;
    }

    // Not near any edge but inside the rectangle: move
    if (retval == GROW_NONE && r.contains((int) x, (int) y)) {
      retval = MOVE;
    }
    return retval;
  }
예제 #25
0
  private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners =
        new float[] {
          halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize
        };
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
  }
예제 #26
0
  void updateDstRect() {
    if (mApplyGravity) {
      if (mIsCircular) {
        final int minDimen = Math.min(mBitmapWidth, mBitmapHeight);
        gravityCompatApply(mGravity, minDimen, minDimen, getBounds(), mDstRect);

        // inset the drawing rectangle to the largest contained square,
        // so that a circle will be drawn
        final int minDrawDimen = Math.min(mDstRect.width(), mDstRect.height());
        final int insetX = Math.max(0, (mDstRect.width() - minDrawDimen) / 2);
        final int insetY = Math.max(0, (mDstRect.height() - minDrawDimen) / 2);
        mDstRect.inset(insetX, insetY);
        mCornerRadius = 0.5f * minDrawDimen;
      } else {
        gravityCompatApply(mGravity, mBitmapWidth, mBitmapHeight, getBounds(), mDstRect);
      }
      mDstRectF.set(mDstRect);

      if (mBitmapShader != null) {
        // setup shader matrix
        mShaderMatrix.setTranslate(mDstRectF.left, mDstRectF.top);
        mShaderMatrix.preScale(
            mDstRectF.width() / mBitmap.getWidth(), mDstRectF.height() / mBitmap.getHeight());
        mBitmapShader.setLocalMatrix(mShaderMatrix);
        mPaint.setShader(mBitmapShader);
      }

      mApplyGravity = false;
    }
  }
예제 #27
0
  protected Rect getIconRect(int viewWidth, int viewHeight, int drawableWidth, int drawableHeight) {
    DragLayer dragLayer = mLauncher.getDragLayer();

    // Find the rect to animate to (the view is center aligned)
    Rect to = new Rect();
    dragLayer.getViewRectRelativeToSelf(this, to);

    final int width = drawableWidth;
    final int height = drawableHeight;

    final int left;
    final int right;

    if (Utilities.isRtl(getResources())) {
      right = to.right - getPaddingRight();
      left = right - width;
    } else {
      left = to.left + getPaddingLeft();
      right = left + width;
    }

    final int top = to.top + (getMeasuredHeight() - height) / 2;
    final int bottom = top + height;

    to.set(left, top, right, bottom);

    // Center the destination rect about the trash icon
    final int xOffset = (int) -(viewWidth - width) / 2;
    final int yOffset = (int) -(viewHeight - height) / 2;
    to.offset(xOffset, yOffset);

    return to;
  }
  /**
   * Method that load the gles texture and apply to the requestor frame (which includes fix the
   * aspect ratio and/or effects and borders)
   *
   * @param requestor The requestor target
   * @param ti The original texture information (the one with the bitmap one)
   */
  private void applyToRequestor(TextureRequestor requestor, GLESTextureInfo ti) {
    // Transform requestor dimensions to screen dimensions
    RectF dimens = requestor.getRequestorDimensions();
    Rect pixels =
        new Rect(
            0,
            0,
            (int) (mScreenDimensions.width() * dimens.width() / 2),
            (int) (mScreenDimensions.height() * dimens.height() / 2));

    final Disposition disposition = requestor.getDisposition();
    synchronized (mEffectsSync) {
      if (disposition.hasFlag(Disposition.EFFECT_FLAG)) {
        ti.effect = mEffects.getNextEffect();
      }
      if (disposition.hasFlag(Disposition.BORDER_FLAG)) {
        ti.border = mBorders.getNextBorder();
      }
    }

    // Check if we have to apply any correction to the image
    GLESTextureInfo dst;
    if (ti.bitmap != null && Preferences.General.isFixAspectRatio(mContext)) {

      // Create a texture of power of two here to avoid scaling the bitmap twice
      int w = pixels.width();
      int h = pixels.height();
      if (!BitmapUtils.isPowerOfTwo(w, h)
          && PreferencesProvider.Preferences.General.isPowerOfTwo(mContext)) {
        w = h = BitmapUtils.calculateUpperPowerOfTwo(Math.min(w, h));
      }

      // Create a thumbnail of the image
      Bitmap thumb = BitmapUtils.createScaledBitmap(ti.bitmap, w, h, BitmapUtils.ScalingLogic.CROP);
      if (!thumb.equals(ti.bitmap)) {
        ti.bitmap.recycle();
      }
      dst = GLESUtil.loadTexture(mContext, thumb, ti.effect, ti.border, pixels);
    } else {
      // Load the texture without any correction
      dst = GLESUtil.loadTexture(mContext, ti.bitmap, ti.effect, ti.border, pixels);
    }

    // Swap references
    ti.bitmap = dst.bitmap;
    ti.handle = dst.handle;
    ti.effect = null;
    ti.border = null;
    dst.handle = 0;
    dst.bitmap = null;

    // And notify to the requestor
    requestor.setTextureHandle(ti);

    // Clean up memory
    if (ti.bitmap != null) {
      ti.bitmap.recycle();
      ti.bitmap = null;
    }
  }
예제 #29
0
 private void drawRecentTitle(Canvas paramCanvas) {
   Object localObject2 = "继续收听  “";
   Object localObject1 = localObject2;
   if (this.mNode != null) {
     localObject1 = localObject2;
     if (this.mNode.nodeName != null) {
       localObject1 = localObject2;
       if (this.mNode.nodeName.equalsIgnoreCase("playhistory"))
         localObject1 =
             "继续收听  “" + ((ProgramNode) ((PlayHistoryNode) this.mNode).playNode).title + "”";
     }
   }
   localObject2 = SkinManager.getInstance().getSubTextPaint();
   localObject1 =
       TextUtils.ellipsize(
               (CharSequence) localObject1,
               (TextPaint) localObject2,
               this.recentTitleLayout.width,
               TextUtils.TruncateAt.END)
           .toString();
   Rect localRect = new Rect();
   ((TextPaint) localObject2)
       .getTextBounds((String) localObject1, 0, ((String) localObject1).length(), localRect);
   float f = this.recentTitleLayout.leftMargin;
   int i = this.recentTitleLayout.topMargin;
   int j = localRect.top;
   paramCanvas.drawText(
       (String) localObject1,
       f,
       (this.recentItemLayout.height - localRect.height()) / 2 + (i - j),
       (Paint) localObject2);
 }
예제 #30
0
  private void updatePath() {
    float radius = getWidth() / 20;
    float arrowHeight = getHeight() / 4;

    Rect rect = new Rect(2, 2, this.getWidth() - 4, this.getHeight() - 4);

    mPath = new Path();
    mPath.moveTo(rect.left + radius, rect.top);
    mPath.lineTo(rect.right, rect.top);
    mPath.lineTo(rect.right, rect.bottom - arrowHeight);
    mPath.lineTo(rect.exactCenterX(), rect.bottom);
    mPath.lineTo(rect.left, rect.bottom - arrowHeight);
    mPath.lineTo(rect.left, rect.top);
    mPath.close();

    int color = this.getContext().getResources().getColor(R.color.tag_unselected_outline);
    if (mIsActive) color = this.getContext().getResources().getColor(R.color.tag_selected_outline);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(color);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setStrokeWidth(0);
    mPaint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you
    // want
    mPaint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too
    mPaint.setPathEffect(new CornerPathEffect(radius)); // set the path
    // effect when they

    color = this.getContext().getResources().getColor(R.color.tag_unselected);
    if (mIsActive) color = this.getContext().getResources().getColor(R.color.tag_selected);
    mShader = new LinearGradient(0, 0, 0, getHeight(), color, color, Shader.TileMode.CLAMP);
  }