@Override
 public boolean onTouchEvent(MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       mMoveOutside = false;
       mFingerRect = new Rect(getLeft(), getTop(), getRight(), getBottom());
       mTouchPoint.set(Math.round(event.getX()), Math.round(event.getY()));
       mState = StateTouchDown;
       mStartTime = System.currentTimeMillis();
       invalidate();
       break;
     case MotionEvent.ACTION_MOVE:
       if (!mFingerRect.contains(getLeft() + (int) event.getX(), getTop() + (int) event.getY())) {
         mMoveOutside = true;
         mState = StateNormal;
         invalidate();
       }
       break;
     case MotionEvent.ACTION_UP:
       if (!mMoveOutside) {
         mState = StateTouchUp;
         mStartTime = System.currentTimeMillis();
         invalidate();
         performClick();
       }
       break;
     case MotionEvent.ACTION_CANCEL:
       mState = StateNormal;
       invalidate();
       break;
   }
   return true;
 }
Пример #2
0
  // Maps the cropping rectangle from image space to screen space.
  private Rect computeLayout() {

    RectF r = new RectF(mCropRect.left, mCropRect.top, mCropRect.right, mCropRect.bottom);
    mMatrix.mapRect(r);
    return new Rect(
        Math.round(r.left), Math.round(r.top), Math.round(r.right), Math.round(r.bottom));
  }
Пример #3
0
  public MapView(Context ctx, boolean allowNetAccess, int mode) {
    super(ctx);

    Display display;

    this.allowNetAccess = allowNetAccess;

    geoUtils = new GeoUtils(mode);

    setBackgroundColor(0xFF555570);
    display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    scrWidth = display.getWidth();
    scrHeight = display.getHeight();
    setMinimumHeight(scrWidth);
    setMinimumWidth(scrHeight);
    tileWidth = (int) Math.ceil(scrWidth / 256.0) + 1;
    tileHeight = (int) Math.ceil(scrHeight / 256.0) + 1;
    gestureDetector = new GestureDetector(ctx, new GestureListener());

    zoomOutButton = new Button(ctx);
    zoomOutButton.setText("  -  ");
    zoomOutButton.setOnClickListener(this);

    zoomInButton = new Button(ctx);
    zoomInButton.setText("  +  ");
    zoomInButton.setOnClickListener(this);

    updateUI(true);
    addView(zoomOutButton);
    addView(zoomInButton);
  }
Пример #4
0
 private void touch_move(float x, float y) {
   float dx = Math.abs(x - mX);
   float dy = Math.abs(y - mY);
   if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
     mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
     mX = x;
     mY = y;
   }
 }
  /** Resets the dirty region when the motion event occurs. */
  private void resetDirtyRect(float eventX, float eventY) {

    // The lastTouchX and lastTouchY were set when the ACTION_DOWN
    // motion event occurred.
    dirtyRect.left = Math.min(lastTouchX, eventX);
    dirtyRect.right = Math.max(lastTouchX, eventX);
    dirtyRect.top = Math.min(lastTouchY, eventY);
    dirtyRect.bottom = Math.max(lastTouchY, eventY);
  }
 /**
  * Uses the currently selected color to determine the point on the hue/saturation wheel that
  * corresponds to that hue/saturation combination.
  *
  * @return a float[2] where float[0] is the x coordinate and float[1] is the y coordinate.
  */
 private float[] findCrosshairsCenter() {
   // find hypotenuse for calculations
   float distanceFromCenter = mNewColor[1] * (float) mRadius;
   // angle should be in degrees so we need to change to radians
   float angle = mNewColor[0] * ((float) Math.PI / 180.0f);
   float xFromCenter = distanceFromCenter * (float) Math.cos(angle);
   float yFromCenter = distanceFromCenter * (float) Math.sin(angle);
   return new float[] {xFromCenter, yFromCenter};
 }
Пример #7
0
 private void touch_move(float x, float y) {
   float dx = Math.abs(x - tiX);
   float dy = Math.abs(y - tiY);
   if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
     tiPath.quadTo(tiX, tiY, (x + tiX) / 2, (y + tiY) / 2);
     tiX = x;
     tiY = y;
   }
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (velocityTracker == null) { // If we do not have velocity tracker
      velocityTracker = VelocityTracker.obtain(); // then get one
    }
    velocityTracker.addMovement(event); // add this movement to it
    positiveScroll = true;

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (!flinger.isFinished()) { // If scrolling, then stop now
            flinger.forceFinished();
          }
          currentX = (int) event.getRawX();
          currentY = (int) event.getRawY();
          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          final int x2 = (int) event.getRawX();
          final int y2 = (int) event.getRawY();
          final int diffX = currentX - x2;
          final int diffY = currentY - y2;
          currentX = x2;
          currentY = y2;

          scrollBy(diffX, diffY);
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          final VelocityTracker velocityTracker = this.velocityTracker;
          velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
          int velocityX = (int) velocityTracker.getXVelocity();
          int velocityY = (int) velocityTracker.getYVelocity();

          if (Math.abs(velocityX) > minimumVelocity || Math.abs(velocityY) > minimumVelocity) {
            flinger.start(
                getActualScrollX(),
                getActualScrollY(),
                velocityX,
                velocityY,
                getMaxScrollX(),
                getMaxScrollY());
          } else {
            if (this.velocityTracker != null) { // If the velocity less than threshold
              this.velocityTracker.recycle(); // recycle the tracker
              this.velocityTracker = null;
            }
          }
          break;
        }
    }
    return true;
  }
 /**
  * @param velocity
  * @return the page you should "land" on
  */
 private int getNextPage(int velocity) {
   int nextPage;
   if (velocity > mMinimumVelocity) {
     nextPage = getCurrentPageFloor();
   } else if (velocity < -mMinimumVelocity) {
     nextPage = getCurrentPageCeil();
   } else {
     nextPage = getCurrentPageRound();
   }
   return Math.min(Math.max(nextPage, 0), mPageCount - 1);
 }
  @Override
  protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);

    int height = bounds.height();
    int width = bounds.width();

    numRectanglesHorizontal = (int) Math.ceil(width / mRectangleSize);
    numRectanglesVertical = (int) Math.ceil(height / mRectangleSize);

    generatePatternBitmap();
  }
  /**
   * @brief Calculate the correct aspect ratio bounds.
   * @param bounds Available Space for the element
   * @return Rect with the correct aspect ratio, fitting in available space
   */
  private Rect elementCalculateAspectRatioBounds(Rect bounds) {
    Rect newBounds;

    if ((float) bounds.width() / (float) bounds.height() > getElementAspectRatio()) {
      newBounds = new Rect(bounds.left, bounds.top, 0, bounds.bottom);
      newBounds.right = newBounds.left + Math.round(newBounds.height() * getElementAspectRatio());
    } else {
      newBounds = new Rect(bounds.left, bounds.top, bounds.right, 0);
      newBounds.bottom = newBounds.top + Math.round(newBounds.width() / getElementAspectRatio());
    }

    return newBounds;
  }
Пример #12
0
 public static int calculateInSampleSize(
     BitmapFactory.Options options, int reqWidth, int reqHeight) {
   int h = options.outHeight;
   int w = options.outWidth;
   int inSampleSize = 0;
   if (h > reqHeight || w > reqWidth) {
     float ratioW = (float) w / reqWidth;
     float ratioH = (float) h / reqHeight;
     inSampleSize = (int) Math.min(ratioH, ratioW);
   }
   inSampleSize = Math.max(1, inSampleSize);
   return inSampleSize;
 }
  private void drawBrightnessIndicator(Canvas canvas) {
    // get a representation of the height of the indicator within the bar
    float brightnessHeight = mNewColor[2] * mWheel.getHeight();
    // Log.d(TAG, String.format("Brightness height: %f", brightnessHeight));
    // convert the height to an absolute y position based on the bar's position
    float absoluteY = mWheelPosition.y + mWheel.getHeight() - brightnessHeight;
    // get the y value "above" the x axis for the x coordinate calculation
    // note: because of symmetry, the sign doesn't matter so we'll use the positive
    float heightAboveXAxis = Math.abs(brightnessHeight - (float) mRadius);
    // Log.d(TAG, String.format("Height above X: %f", heightAboveXAxis));
    float leftEdgeRadius = (float) (mRadius + SPACE_BETWEEN_WHEEL_AND_BAR);
    float rightEdgeRadius = leftEdgeRadius + ARC_WIDTH;
    // get the x coordinate relative to the center of the wheel
    float leftXInCircle =
        (float) Math.sqrt(leftEdgeRadius * leftEdgeRadius - heightAboveXAxis * heightAboveXAxis);
    float rightXInCircle =
        (float) Math.sqrt(rightEdgeRadius * rightEdgeRadius - heightAboveXAxis * heightAboveXAxis);
    // get the absolute x and y coordinates of the left edge of the bar at the bar height
    float leftX = mWheelCenter.x + leftXInCircle;
    float rightX = mWheelCenter.x + rightXInCircle;

    float indicatorHeight = BRIGHTNESS_INDICATOR_SIZE / 2.0f;
    float indicatorWidth = BRIGHTNESS_INDICATOR_SIZE;

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(1.0f);

    Path leftTrianglePath = new Path();
    leftTrianglePath.moveTo(leftX, absoluteY - indicatorHeight);
    leftTrianglePath.lineTo(leftX + indicatorWidth, absoluteY);
    leftTrianglePath.lineTo(leftX, absoluteY + indicatorHeight);
    leftTrianglePath.close();
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawPath(leftTrianglePath, paint);
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(leftTrianglePath, paint);

    Path rightTrianglePath = new Path();
    rightTrianglePath.moveTo(rightX, absoluteY - indicatorHeight);
    rightTrianglePath.lineTo(rightX - indicatorWidth, absoluteY);
    rightTrianglePath.lineTo(rightX, absoluteY + indicatorHeight);
    rightTrianglePath.close();
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawPath(rightTrianglePath, paint);
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(rightTrianglePath, paint);
  }
Пример #14
0
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {

    float xDelta = Math.abs(motionEvent.getRawX() - showcaseX);
    float yDelta = Math.abs(motionEvent.getRawY() - showcaseY);
    double distanceFromFocus = Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2));

    if (mOptions.hideOnClickOutside && distanceFromFocus > showcaseRadius) {
      this.hide();
      return true;
    }

    return mOptions.block && distanceFromFocus > showcaseRadius;
  }
Пример #15
0
  /** 当屏幕被触摸时调用 */
  @Override
  public boolean onTouchEvent(MotionEvent event) {

    // 设置贝塞尔曲线的坐标为触摸时坐标
    qStartX = (int) event.getX();
    qStartY = (int) event.getY();

    // 设置贝塞尔曲线的控制点坐标为终点坐标与起点坐标对应的差值的一半,注意这里不是曲线的中点
    qControlX = Math.abs(qEndX - qStartX) / 2;
    qCOntrolY = Math.abs(qEndY - qStartY) / 2;

    // 设置控制点的横坐标不返回
    cReturn = false;
    return super.onTouchEvent(event);
  }
Пример #16
0
  // 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;

    if (mCircle) {
      float distX = x - r.centerX();
      float distY = y - r.centerY();
      int distanceFromCenter = (int) Math.sqrt(distX * distX + distY * distY);
      int radius = mDrawRect.width() / 2;
      int delta = distanceFromCenter - radius;
      if (Math.abs(delta) <= hysteresis) {
        if (Math.abs(distY) > Math.abs(distX)) {
          if (distY < 0) {
            retval = GROW_TOP_EDGE;
          } else {
            retval = GROW_BOTTOM_EDGE;
          }
        } else {
          if (distX < 0) {
            retval = GROW_LEFT_EDGE;
          } else {
            retval = GROW_RIGHT_EDGE;
          }
        }
      } else if (distanceFromCenter < radius) {
        retval = MOVE;
      } else {
        retval = GROW_NONE;
      }
    } else {
      // 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;
  }
Пример #17
0
  /**
   * This function randomly picks a point along the x-axis and y-axis then draws a line across it
   *
   * @param BL bottom-left
   * @param TR top-right
   * @param HL # of horizontal lines
   * @param VL # of vertical lines
   */
  public ArrayList Draw_Random_Lines(Point BL, Point TR, int HL, int VL) {

    int min_x = BL.x; // parse the Points
    int min_y = BL.y;
    int max_x = TR.x;
    int max_y = TR.y;
    int x, y;

    Random rd = new Random();

    /*
     * The purpose of the algorithm is to prevent any odd number integers to be randomized
     * By dividing the random number by 2 and flooring it will force the random number to be an even integer
     * Then multiplying it by 2 will bring it back to its original value or +/-1 if the number was odd to begin with
     * This will make error checking a lot easier because we can take out any duplicate numbers that are being generated
     * Also not needing to worry about lines being generated right next to each other
     */
    for (int i = 0; i < HL; i++) { // draw horizontal lines
      y =
          (int) Math.floor((double) (rd.nextInt(max_y - min_y) + min_y) / 3)
              * 3; // pick a point on the y-axis to draw the horizontal line
      if (HL_list.contains(y)
          || y < min_y + 2
          || y > max_y - 2) // check to see if the y-axis generated is already in the list
      i--;
      else {
        HL_list.add(y);
        LineObject LO = new LineObject(BL.x, y, TR.x, y);
        line_list.add(LO); // put into array to check for errors
        // drawLine(BL.x,y,TR.x,y);
      }
    }

    for (int j = 0; j < VL; j++) { // draw vertical lines
      x =
          (int) Math.floor((double) (rd.nextInt(max_x - min_x) + min_x) / 3)
              * 3; // pick a point on the x-axis to draw the vertical line
      if (VL_list.contains(x) || x < min_x + 2 || x > max_x - 2) j--;
      else {
        VL_list.add(x);
        LineObject LO = new LineObject(x, BL.y, x, TR.y);
        line_list.add(LO);
        // drawLine(x,BL.y,x,TR.y);
      }
    }

    return line_list;
  }
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    //        Logger.d(TAG, String.format("onSizeChanged, w: %s, h: %s, oldw: %s, oldh: %s", w, h,
    // oldw, oldh));
    if (isFirst && w > 0 && h > 0) {
      isFirst = false;

      originWidth = w;
      originHeight = h;

      originRadius = Math.min(originWidth, originHeight) / 2;
      curRadius = originRadius;
      touchedPointRadius = originRadius;

      maxMoveLength = ABAppUtil.getDeviceHeight(context) / 6;

      refreshStartPoint();

      ViewGroup.LayoutParams lp = this.getLayoutParams();
      if (RelativeLayout.LayoutParams.class.isAssignableFrom(lp.getClass())) {
        originLp = (RelativeLayout.LayoutParams) lp;
      }
      newLp = new RelativeLayout.LayoutParams(lp.width, lp.height);
    }
  }
 private int changeColorAlpha(int color, float value) {
   int alpha = Math.round(Color.alpha(color) * value);
   int red = Color.red(color);
   int green = Color.green(color);
   int blue = Color.blue(color);
   return Color.argb(alpha, red, green, blue);
 }
Пример #20
0
  // ==============================================================================
  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 = Math.max(1, 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;
  }
Пример #21
0
    public byte[] getTileImageData(int x, int y, int zoom) {
      mStream.reset();

      Matrix matrix = new Matrix(mBaseMatrix);
      float scale = (float) (Math.pow(2, zoom) * mScale);
      matrix.postScale(scale, scale);
      matrix.postTranslate(-x * mDimension, -y * mDimension);

      mBitmap.eraseColor(Color.TRANSPARENT);
      Canvas c = new Canvas(mBitmap);
      c.setMatrix(matrix);

      // NOTE: Picture is not thread-safe.
      synchronized (mSvgPicture) {
        mSvgPicture.draw(c);
      }

      BufferedOutputStream stream = new BufferedOutputStream(mStream);
      mBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
      try {
        stream.close();
      } catch (IOException e) {
        Log.e(TAG, "Error while closing tile byte stream.");
        e.printStackTrace();
      }
      return mStream.toByteArray();
    }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    //        Logger.d(TAG, "onTouchEvent: " + event);
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        isTouched = true;
        this.setLayoutParams(newLp);
        endPoint.x = (int) downX;
        endPoint.y = (int) downY;

        changeViewHeight(
            this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        postInvalidate();

        downX = event.getX() + location[0];
        downY = event.getY() + location[1];
        //                Logger.d(TAG, String.format("downX: %f, downY: %f", downX, downY));

        break;
      case MotionEvent.ACTION_MOVE:
        // 计算直角边和斜边(用于计算绘制两圆之间的填充去)
        triangle.deltaX = event.getX() - downX;
        triangle.deltaY = -1 * (event.getY() - downY); // y轴方向相反,所有需要取反
        double distance =
            Math.sqrt(triangle.deltaX * triangle.deltaX + triangle.deltaY * triangle.deltaY);
        triangle.hypotenuse = distance;
        //                Logger.d(TAG, "triangle: " + triangle);
        refreshCurRadiusByMoveDistance((int) distance);

        endPoint.x = (int) event.getX();
        endPoint.y = (int) event.getY();

        postInvalidate();

        break;
      case MotionEvent.ACTION_UP:
        isTouched = false;
        this.setLayoutParams(originLp);

        if (isArrivedMaxMoved) { // 触发事件
          changeViewHeight(this, originWidth, originHeight);
          postInvalidate();
          if (null != onDraggableFlagViewListener) {
            onDraggableFlagViewListener.onFlagDismiss(this);
          }
          Logger.d(TAG, "触发事件...");
          resetAfterDismiss();
        } else { // 还原
          changeViewHeight(this, originWidth, originHeight);
          startRollBackAnimation(500 /*ms*/);
        }

        downX = Float.MAX_VALUE;
        downY = Float.MAX_VALUE;
        break;
    }

    return true;
  }
Пример #23
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);
  }
  /** @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"));
  }
Пример #25
0
  public SVGTileProvider(File file, float dpi) throws IOException {
    mScale = Math.round(dpi + .3f); // Make it look nice on N7 (1.3 dpi)
    mDimension = BASE_TILE_SIZE * mScale;

    mPool = new TileGeneratorPool(POOL_MAX_SIZE);

    SVG svg = new SVGBuilder().readFromInputStream(new FileInputStream(file)).build();
    mSvgPicture = svg.getPicture();
    RectF limits = svg.getLimits();

    // These values map the SVG file to world coordinates.
    // See: http://stackoverflow.com/questions/21167584/google-io-2013-app-mystery-values
    mBaseMatrix = new Matrix();
    mBaseMatrix.setPolyToPoly(
        new float[] {
          0,
          0, // North-West
          limits.width(),
          0, // North-East
          limits.width(),
          limits.height() // South-East
        },
        0,
        BuildConfig.MAP_FLOORPLAN_MAPPING,
        0,
        3);
  }
  private void adjustFirstCellsAndScroll() {
    int values[];

    //		values = adjustFirstCellsAndScroll(scrollX, firstColumn, widths);
    //		scrollX = values[0];
    //		firstColumn = values[1];
    // 切换应用导致重新布局时横向滚到最前端
    scrollX = 0;
    firstColumn = 0;
    sumX = 0;

    values = adjustFirstCellsAndScroll(scrollY, firstRow, heights);
    scrollY = values[0];
    firstRow = values[1];

    if (lineView != null) {
      int maxY = lineView.getBottom() - height + lineView.getTop();
      // data变化后maxY发生变化,而之前存的sumY也失效了,滑动时以现在的maxY为准
      if (maxY < 0) {
        maxY = 0;
      }
      sumY = Math.min(maxY, sumY);
      lineView.scrollBy(0, sumY);
    }
  }
Пример #27
0
    @Override
    public void run() {
      isInertia = true;
      boolean isEnable = false;
      while (isInertia) {
        isScrollEnd = false;
        if (xVelocity < 0) {
          acceler = -200;
        } else {
          acceler = 200;
        }
        try {
          int space = (xVelocity - acceler) / 20;

          if (acceler < 0 && space >= 0) {
            isInertia = false;
          }
          if (acceler > 0 && space <= 0) {
            isInertia = false;
          }
          if (axesData.size() > 1 && (Math.abs(space) > 2)) {

            int max = axesData.get(axesData.size() - 1).X;
            int min = axesData.get(0).X;
            int maxLimit = width - rightPadding - 20;
            int minLimit = leftPadding + yTextWidth + 20;
            if (min + space > minLimit) { // 滑动以后左边界判断
              if (min < minLimit) {
                space = minLimit - min;
                isEnable = true;
              } else {
                space = 0;
              }
            } else {
              isEnable = true;
            }
            if (max + space < maxLimit) { // 滑动后右边界判断
              if (max > maxLimit) {
                space = maxLimit - max;
                isEnable = true;
              } else {
                space = 0;
              }
            } else {
              isEnable = true;
            }
            if (isEnable) {

              refreshChart(space);
            }
          }
          xVelocity = xVelocity - acceler * 2;
          sleep(timeInterval);
          isScrollEnd = true;
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
 /**
  * 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);
   }
 }
 private int scrollBounds(int desiredScroll, int firstCell, int sizes[], int viewSize) {
   if (desiredScroll == 0) {
     // no op
   } else if (desiredScroll < 0) {
     desiredScroll = Math.max(desiredScroll, -sumArray(sizes, 1, firstCell));
   } else {
     desiredScroll =
         Math.min(
             desiredScroll,
             Math.max(
                 0,
                 sumArray(sizes, firstCell + 1, sizes.length - 1 - firstCell)
                     + sizes[0]
                     - viewSize));
   }
   return desiredScroll;
 }
Пример #30
0
 @Override
 public boolean getPadding(Rect padding) {
   padding.left = 0;
   padding.top = 0;
   padding.right = 0;
   padding.bottom = 0;
   final Rec[] array = mLayerState.mArray;
   final int N = mLayerState.mNum;
   for (int i = 0; i < N; i++) {
     reapplyPadding(i, array[i]);
     padding.left = Math.max(padding.left, mPaddingL[i]);
     padding.top = Math.max(padding.top, mPaddingT[i]);
     padding.right = Math.max(padding.right, mPaddingR[i]);
     padding.bottom = Math.max(padding.bottom, mPaddingB[i]);
   }
   return true;
 }