/**
     * 动画不断地执行的时候会回调该方法 interpolatedTime:范围是0 0ms-------------->300ms
     * 当前的图片高度--->动画执行之前的高度-高度差*interpolatedTime extraHeight------>0
     */
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {

      mView.getLayoutParams().height = (int) (originalHeight - extraHeight * interpolatedTime);
      mView.requestLayout();
      super.applyTransformation(interpolatedTime, t);
    }
Beispiel #2
0
 /**
  * 用于内部子控件超出控件本身范围滑动的监听
  *
  * @param deltaX X 轴的滑动距离
  * @param deltaY Y 轴的滑动距离,顶部超出的时候为负,底部超出的时候为正
  * @param scrollX
  * @param scrollY
  * @param scrollRangeX
  * @param scrollRangeY
  * @param maxOverScrollX
  * @param maxOverScrollY
  * @param isTouchEvent
  * @return
  */
 @Override
 protected boolean overScrollBy(
     int deltaX,
     int deltaY,
     int scrollX,
     int scrollY,
     int scrollRangeX,
     int scrollRangeY,
     int maxOverScrollX,
     int maxOverScrollY,
     boolean isTouchEvent) {
   Log.e("listview", "deltaY=======" + deltaY);
   if (deltaY < 0 && isTouchEvent) { // 如果是手指拖动到达顶部并且下拉
     int height = imageView.getHeight() - deltaY / 2; // imagview 变化后的高度
     totalY -= deltaY; // 将滑动的距离添加给滑动总距离
     if (height < MaxOverY) { // 如果当前控件的高度小于可滑动的最大值
       imageView.getLayoutParams().height = height;
       imageView.requestLayout(); // 设置高度后请求重新绘制位置
     }
   }
   return super.overScrollBy(
       deltaX,
       deltaY,
       scrollX,
       scrollY,
       scrollRangeX,
       scrollRangeY,
       maxOverScrollX,
       maxOverScrollY,
       isTouchEvent);
 }
  private void setPic() {

    Log.d("setPic", "Display image " + mCurrentPhotoPath);

    ImageView imageView = (ImageView) findViewById(R.id.cameraImage);

    int targetW = imageView.getWidth();
    int targetH = imageView.getHeight();

    Log.d("setPic", "layout ( " + targetW + " * " + targetH + " )");

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    Log.d("setPic", "display ( " + width + " * " + height + " )");

    imageView.getLayoutParams().width = ((width / 100) * 80);
    ;
    imageView.getLayoutParams().height = ((height / 100) * 80);
    imageView.requestLayout();

    targetW = imageView.getWidth();
    targetH = imageView.getHeight();

    Log.d("setPic", "new layout ( " + targetW + " * " + targetH + " )");

    /*
    // working for local image
            Bitmap bmp;
            bmp=BitmapFactory.decodeResource(getResources(),R.drawable.miau);//image is your image
            bmp=Bitmap.createScaledBitmap(bmp, targetW,targetH, true);
            imageView.setImageBitmap(bmp);
    */

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    Log.d("setPic", "photo ( " + photoW + " * " + photoH + " )");

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    imageView.setImageBitmap(bitmap);
  }
 /**
  * 해당 ImageView 의 크기를 임의로 조정하는 method <br>
  * Resize ImageView by what you want.
  *
  * @param iv - ImageView variable
  * @param width - set width of ImageView
  * @param height - set height of ImageView
  */
 public static void resizeImageView(ImageView iv, int width, int height) {
   //        iv.setLayoutParams(new ViewGroup.LayoutParams(width, height));
   iv.requestLayout();
   if (width != 0) {
     iv.getLayoutParams().width = width;
   }
   if (height != 0) {
     iv.getLayoutParams().height = height;
   }
 }
  @Override
  public void onCameraParametersSetup() {
    // replace here with [CF] mode as default.
    // Also, check if [CF] is available, and if not - set [AF], if [AF] is
    // not available - set first available
    preferenceFocusMode =
        ApplicationScreen.instance.getFocusModePref(ApplicationScreen.sDefaultFocusValue);

    int[] supportedFocusModes = CameraController.getSupportedFocusModes();
    if (supportedFocusModes != null && supportedFocusModes.length > 0) {
      if (!CameraController.isModeAvailable(supportedFocusModes, preferenceFocusMode)
          && preferenceFocusMode != CameraParameters.MF_MODE) {
        if (CameraController.isModeAvailable(supportedFocusModes, CameraParameters.AF_MODE_AUTO))
          preferenceFocusMode = CameraParameters.AF_MODE_AUTO;
        else preferenceFocusMode = supportedFocusModes[0];
      }
    }

    initializeParameters();

    initialize(CameraController.isFrontCamera(), 90);
    initializeSoundPlayers(
        ApplicationScreen.getAppResources().openRawResourceFd(R.raw.plugin_vf_focus_ok),
        ApplicationScreen.getAppResources().openRawResourceFd(R.raw.plugin_vf_focus_false));

    cancelAutoFocus();

    // Set the length of focus indicator according to preview frame size.
    int len = Math.min(mPreviewWidth, mPreviewHeight) / 25;
    ViewGroup.LayoutParams layout = mFocusIndicator.getLayoutParams();
    layout.width =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    layout.height =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    mFocusIndicator.requestLayout();

    layout = mMeteringIndicator.getLayoutParams();
    layout.width =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    layout.height =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    mMeteringIndicator.requestLayout();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    ctx = this;

    // Bundle extras = getIntent().getExtras();
    // if (extras!=null){
    //	content = extras.getString(CONTENT);
    // }

    setContentView(R.layout.mit150_welcome);

    final WebView wv = (WebView) findViewById(R.id.welcomeWV);

    ImageView iv = (ImageView) findViewById(R.id.welcomeIV);
    iv.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i = new Intent(ctx, MIT150VideoActivity.class);
            startActivity(i);
            // playVideo();
          }
        });

    // Scale Welcome image...

    Display display = getWindowManager().getDefaultDisplay();
    int screenWidth = display.getWidth();

    float scale = screenWidth / 320.0f;
    int h = (int) (scale * 180.0f);

    LayoutParams params = new LayoutParams(screenWidth, h);
    iv.setLayoutParams(params);
    iv.requestLayout();

    final Handler uiHandler =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            if (msg.arg1 == MobileWebApi.SUCCESS) {
              if (content != null)
                wv.loadDataWithBaseURL(
                    null, StyledContentHTML.html(ctx, content), mimeType, encoding, null);

              wv.requestLayout();
              wv.invalidate();
            }
          }
        };
    fetchMIT150WelcomeContent(this, uiHandler);
  }
  private boolean resizeOverScrollBy(int deltaY) {
    // 下拉的过程当中,不断地控制ImageView的高度
    /** deltaY:是在超出滑动的时候每毫秒滑动的距离 -- 增量 (-往下拉过渡,+往上拉过渡) 大小:根据用户滑动的速度决定 一般滑动的速度 -50~50 */
    if (deltaY < 0) {
      // 下拉过渡,不断增加ImageView的高度,deltay是负数,增加高度就是减去
      mImageView.getLayoutParams().height = mImageView.getHeight() - deltaY;
      // View重新调整宽高
      mImageView.requestLayout(); // onMeasure-->onLayout
    } else {
      // 上拉过渡,不断减小ImageView的高度,deltay是正数,减小高度还是减去
      if (mImageView.getHeight() > mImageViewHeight) {
        mImageView.getLayoutParams().height =
            Math.max(mImageView.getHeight() - deltaY, mImageViewHeight);
        // View重新调整宽高
        mImageView.requestLayout(); // onMeasure-->onLayout
      }
    }

    return false;
  }
 /** 监听ListView滑动 */
 @Override
 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
   super.onScrollChanged(l, t, oldl, oldt);
   // 获得ImageView的父控件
   View header = (View) mImageView.getParent();
   if (header.getTop() < 0 && mImageView.getHeight() > mImageViewHeight) {
     // 减小ImageView的高度 -- 不能超过图片最原始的高度
     mImageView.getLayoutParams().height =
         Math.max(mImageView.getHeight() + header.getTop(), mImageViewHeight);
     // ImageView所在的容器的高度也要变化:getTop--->0
     header.layout(header.getLeft(), 0, header.getRight(), header.getHeight());
     mImageView.requestLayout();
   }
 }
  private void setSelection(int new_x, int new_y, int new_w, int new_h) {
    if (bLoading) return;
    if (!bEntire) {
      // Clip the width and height
      int max_w = (int) shown_image_rect.width();
      int max_h = (int) shown_image_rect.height();
      new_w = new_w > max_w ? max_w : new_w < 0 ? 0 : new_w;
      new_h = new_h > max_h ? max_h : new_h < 0 ? 0 : new_h;
      // Movable range
      int x_min = (int) shown_image_rect.left;
      int y_min = (int) shown_image_rect.top;
      int x_max = (int) shown_image_rect.right - new_w;
      int y_max = (int) shown_image_rect.bottom - new_h;
      // Clip position in the movable range
      new_x = new_x < x_min ? x_min : new_x > x_max ? x_max : new_x;
      new_y = new_y < y_min ? y_min : new_y > y_max ? y_max : new_y;

    } else {
      new_w = (int) shown_image_rect.width();
      new_h = (int) shown_image_rect.height();
      new_x = (int) shown_image_rect.left;
      new_y = (int) shown_image_rect.top;
    }

    // Update selection
    LinearLayout.LayoutParams lpSelection =
        (LinearLayout.LayoutParams) ivSelection.getLayoutParams();
    drawFrame(new_x, new_y, new_w, new_h);
    lpSelection.setMargins(
        new_x, new_y, flOuter.getWidth() - new_w - new_x, flOuter.getHeight() - new_h - new_y);
    ivSelection.requestLayout();
    Log.e("DRAW", "DRAW");

    //        LinearLayout.LayoutParams lpSelection2 = (LinearLayout.LayoutParams)
    // ivSelection2.getLayoutParams();
    //        lpSelection2.setMargins(
    //                new_x
    //                , new_y
    //                , flOuter.getWidth() - new_w - new_x
    //                , flOuter.getHeight() - new_h - new_y
    //        );
    //        ivSelection2.requestLayout();

  }
  /**
   * 在listview滑动到头的时候执行,可以获取到继续滑动的距离和方向 deltaX:继续滑动x方向的距离 deltaY:继续滑动y方向的距离 负:表示顶部到头 正:表示底部到头
   * maxOverScrollX:x方向最大可以滚动的距离 maxOverScrollY:y方向最大可以滚动的距离 isTouchEvent: true: 是手指拖动滑动
   * false:表示fling靠惯性滑动;
   */
  @Override
  protected boolean overScrollBy(
      int deltaX,
      int deltaY,
      int scrollX,
      int scrollY,
      int scrollRangeX,
      int scrollRangeY,
      int maxOverScrollX,
      int maxOverScrollY,
      boolean isTouchEvent) {

    //		Log.e("tag", "deltaY: "+deltaY   +   "  isTouchEvent:"+isTouchEvent);
    if (deltaY < 0 && isTouchEvent) {
      // 表示顶部到头,并且是手动拖动到头的情况
      // 我们需要不断的增加ImageView的高度
      if (imageView != null) {
        int newHeight = imageView.getHeight() - deltaY / 3;
        if (newHeight > maxHeight) newHeight = maxHeight;

        imageView.getLayoutParams().height = newHeight;
        imageView.requestLayout(); // 使ImageView的布局参数生效
      }
    }

    return super.overScrollBy(
        deltaX,
        deltaY,
        scrollX,
        scrollY,
        scrollRangeX,
        scrollRangeY,
        maxOverScrollX,
        maxOverScrollY,
        isTouchEvent);
  }
Beispiel #11
0
 void setupCoverView(ImageView coverView) {
   coverView.getLayoutParams().width = myCoverWidth;
   coverView.getLayoutParams().height = myCoverHeight;
   coverView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
   coverView.requestLayout();
 }
 public boolean updateInfo(DrawSettings drawSettings) {
   boolean visible = false;
   int locimminent = -1;
   int[] loclanes = null;
   int dist = 0;
   // TurnType primary = null;
   if ((rh == null || !rh.isFollowingMode())
       && trackingUtilities.isMapLinkedToLocation()
       && settings.SHOW_LANES.get()) {
     RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
     Location lp = locationProvider.getLastKnownLocation();
     if (ro != null) {
       float degree = lp == null || !lp.hasBearing() ? 0 : lp.getBearing();
       loclanes = RouteResultPreparation.parseTurnLanes(ro, degree / 180 * Math.PI);
       if (loclanes == null) {
         loclanes = RouteResultPreparation.parseLanes(ro, degree / 180 * Math.PI);
       }
     }
   } else if (rh != null && rh.isRouteCalculated()) {
     if (rh.isFollowingMode() && settings.SHOW_LANES.get()) {
       NextDirectionInfo r = rh.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
       if (r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) {
         loclanes = r.directionInfo.getTurnType().getLanes();
         // primary = r.directionInfo.getTurnType();
         locimminent = r.imminent;
         // Do not show too far
         if ((r.distanceTo > 800 && r.directionInfo.getTurnType().isSkipToSpeak())
             || r.distanceTo > 1200) {
           loclanes = null;
         }
         dist = r.distanceTo;
       }
     } else {
       int di = MapRouteInfoControl.getDirectionInfo();
       if (di >= 0
           && MapRouteInfoControl.isControlVisible()
           && di < rh.getRouteDirections().size()) {
         RouteDirectionInfo next = rh.getRouteDirections().get(di);
         if (next != null) {
           loclanes = next.getTurnType().getLanes();
           // primary = next.getTurnType();
         }
       }
     }
   }
   visible = loclanes != null && loclanes.length > 0;
   if (visible) {
     if (!Arrays.equals(lanesDrawable.lanes, loclanes)
         || (locimminent == 0) != lanesDrawable.imminent) {
       lanesDrawable.imminent = locimminent == 0;
       lanesDrawable.lanes = loclanes;
       lanesDrawable.updateBounds();
       lanesView.setImageDrawable(null);
       lanesView.setImageDrawable(lanesDrawable);
       lanesView.requestLayout();
       lanesView.invalidate();
     }
     if (distChanged(dist, this.dist)) {
       this.dist = dist;
       if (dist == 0) {
         lanesShadowText.setText("");
         lanesText.setText("");
       } else {
         lanesShadowText.setText(OsmAndFormatter.getFormattedDistance(dist, app));
         lanesText.setText(OsmAndFormatter.getFormattedDistance(dist, app));
       }
       lanesShadowText.invalidate();
       lanesText.invalidate();
     }
   }
   updateVisibility(lanesShadowText, visible && shadowRadius > 0);
   updateVisibility(lanesText, visible);
   updateVisibility(lanesView, visible);
   updateVisibility(centerInfo, visible || progress.getVisibility() == View.VISIBLE);
   return true;
 }
 @Override
 public void requestLayout() {
   if (makeRequest) super.requestLayout();
 }