Example #1
2
 @Override
 public void handleMessage(Message msg) {
   // TODO Auto-generated method stub
   switch (msg.what) {
     case BACK_SCALE:
       float scale = (scaleY / 2 + imgHeight) / (imgHeight); // 得到缩放倍数
       if (scaleY > 0) {
         isBacking = true;
         matrix.set(currentMatrix);
         ListView.LayoutParams relativeLayout =
             new ListView.LayoutParams((int) (scale * imgWidth), (int) (scale * imgHeight));
         imageView.setLayoutParams(relativeLayout);
         matrix.postScale(scale, scale, imgWidth / 2, 0);
         imageView.setImageMatrix(matrix);
         scaleY = (float) (scaleY / 2 - 1);
         mHandler.sendEmptyMessageDelayed(BACK_SCALE, 20);
       } else {
         scaleY = 0;
         ListView.LayoutParams relativeLayout =
             new ListView.LayoutParams((int) imgWidth, (int) imgHeight);
         imageView.setLayoutParams(relativeLayout);
         matrix.set(defaultMatrix);
         imageView.setImageMatrix(matrix);
         isBacking = false;
       }
       break;
     default:
       break;
   }
   super.handleMessage(msg);
 }
Example #2
0
 public void onImageBitmapSet() {
   int imageWidth = mResultImageView.getDrawable().getIntrinsicWidth();
   int imageHeight = mResultImageView.getDrawable().getIntrinsicHeight();
   Matrix m = mResultImageView.getImageMatrix();
   RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight);
   RectF viewRect =
       new RectF(
           0,
           0,
           ((View) mResultImageView.getParent()).getWidth(),
           ((View) mResultImageView.getParent()).getHeight());
   m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
   mResultImageView.setImageMatrix(m);
   mResultImageView.invalidate();
   mMatrix = m;
   Log.d(TAG, "init mMatrix: " + mMatrix.toString());
   Log.d(
       TAG,
       "init, imagehview: " + mResultImageView.getDrawable().toString() + " w: " + imageWidth);
   Log.d(TAG, "init, imageheight: " + imageHeight + " w: " + imageWidth);
   Log.d(
       TAG,
       "init, viewheight: "
           + ((View) mResultImageView.getParent()).getHeight()
           + " w: "
           + ((View) mResultImageView.getParent()).getWidth());
   if (progressDialog != null) {
     progressDialog.dismiss();
   }
 }
  /**
   * @brief resetView method
   * @param v
   * @detail This method is called when the reset button is clicked and will reset the pictures is
   *     zoomed in/out or rotated left/right
   */
  public void resetView(View v) {
    ImageView view = (ImageView) v;
    matrix = new Matrix();

    view.setScaleType(ImageView.ScaleType.MATRIX);
    view.setImageMatrix(matrix);
  }
 private void arrowlistener() {
   int width = arrowicon.getMeasuredWidth();
   int height = arrowicon.getMeasuredHeight();
   LogUtils.D("onClick" + width + " " + height);
   Matrix matrix = new Matrix();
   count++;
   matrix.postRotate(180 * count, width / 2, height / 2);
   arrowicon.setImageMatrix(matrix);
   if (count % 2 != 0) {
     list_title.setVisibility(View.VISIBLE);
     list_content.setVisibility(View.VISIBLE);
     View view = (View) mViewPager.getParent();
     Bitmap bitmap =
         BitmapUtils.shot(
             getView(),
             (int) view.getX(),
             (int) view.getY(),
             mViewPager.getMeasuredWidth(),
             mViewPager.getMeasuredHeight());
     if (bitmap != null)
       list_content.setBackground(
           new BitmapDrawable(BitmapUtils.blurBitmap(bitmap, getActivity())));
     //                    list_content.setBackground(new
     // BitmapDrawable(BitmapUtils.compressBmpFromBmp(bitmap)));
     mItemHScrollView.setVisibility(View.GONE);
     mViewPager.setVisibility(View.GONE);
   } else {
     list_title.setVisibility(View.GONE);
     list_content.setVisibility(View.GONE);
     list_content.setBackground(null);
     mItemHScrollView.setVisibility(View.VISIBLE);
     mViewPager.setVisibility(View.VISIBLE);
   }
 }
  private Dialog showZoomDialog() {
    Dialog zoomedDialog = new Dialog(SyncResultsActivity.this);
    zoomedDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    zoomedDialog.setContentView(R.layout.zoomedpic);
    zoomedDialog.setCancelable(true);

    final ImageView image = (ImageView) zoomedDialog.findViewById(R.id.image);

    final int padding = 15;

    final int width = mContactImage.getWidth();
    final int height = mContactImage.getHeight();

    int newWidth = width;
    int newHeight = height;

    final int windowHeight = getWindowManager().getDefaultDisplay().getHeight();
    final int windowWidth = getWindowManager().getDefaultDisplay().getWidth();

    boolean scale = false;
    float ratio;

    if (newHeight >= windowHeight) {
      ratio = (float) newWidth / (float) newHeight;
      newHeight = windowHeight - padding;
      newWidth = Math.round(ratio * (float) newHeight);

      scale = true;
    }

    if (newWidth >= windowWidth) {
      ratio = (float) newHeight / (float) newWidth;
      newWidth = windowWidth - padding;
      newHeight = Math.round(ratio * (float) newWidth);

      scale = true;
    }

    image.setImageBitmap(mContactImage);

    if (scale) {
      Matrix m = new Matrix();
      m.postScale((float) newWidth / (float) width, (float) newHeight / (float) height);
      image.setImageMatrix(m);

      zoomedDialog.getWindow().setLayout(newWidth, newHeight);
    }

    zoomedDialog.setOnCancelListener(
        new OnCancelListener() {
          public void onCancel(DialogInterface dialog) {
            removeDialog(ZOOM_PIC);
          }
        });

    return zoomedDialog;
  }
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;

    if (v == imgText) {
      switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
          savedMatrix.set(matrix);
          start.set(event.getX(), event.getY());
          mode = DRAG;
          lastEvent = null;
          break;
        case MotionEvent.ACTION_POINTER_DOWN:
          oldDist = spacing(event);
          if (oldDist > 10f) {
            savedMatrix.set(matrix);
            midPoint(mid, event);
            mode = ZOOM;
          }
          lastEvent = new float[4];
          lastEvent[0] = event.getX(0);
          lastEvent[1] = event.getX(1);
          lastEvent[2] = event.getY(0);
          lastEvent[3] = event.getY(1);
          d = rotation(event);
          break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
          mode = NONE;
          lastEvent = null;
          break;
        case MotionEvent.ACTION_MOVE:
          if (mode == DRAG) {
            // ...
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
          } else if (mode == ZOOM && event.getPointerCount() == 2) {
            float newDist = spacing(event);
            matrix.set(savedMatrix);
            if (newDist > 10f) {
              float scale = newDist / oldDist;
              matrix.postScale(scale, scale, mid.x, mid.y);
            }
            if (lastEvent != null) {
              newRot = rotation(event);
              float r = newRot - d;
              matrix.postRotate(r, view.getMeasuredWidth() / 2, view.getMeasuredHeight() / 2);
            }
          }
          break;
      }

      view.setImageMatrix(matrix);
      return true;
    } else return false;
  }
Example #7
0
    /** 图片拖动监听 */
    @Override
    public boolean onTouch(View v, MotionEvent event) {

      ImageView view = (ImageView) v;

      dumpEvent(event);

      // Handle touch events here...
      switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
          matrix.set(view.getImageMatrix());
          savedMatrix.set(matrix);
          start.set(event.getX(), event.getY());
          // Log.d(TAG, "mode=DRAG");
          mode = DRAG;

          // Log.d(TAG, "mode=NONE");
          break;
        case MotionEvent.ACTION_POINTER_DOWN:
          oldDist = spacing(event);
          // Log.d(TAG, "oldDist=" + oldDist);
          if (oldDist > 10f) {
            savedMatrix.set(matrix);
            midPoint(mid, event);
            mode = ZOOM;
            // Log.d(TAG, "mode=ZOOM");
          }
          break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
          mode = NONE;
          // Log.e("view.getWidth", view.getWidth() + "");
          // Log.e("view.getHeight", view.getHeight() + "");

          break;
        case MotionEvent.ACTION_MOVE:
          if (mode == DRAG) {
            // ...
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
          } else if (mode == ZOOM) {
            float newDist = spacing(event);
            // Log.d(TAG, "newDist=" + newDist);
            if (newDist > 10f) {
              matrix.set(savedMatrix);
              float scale = newDist / oldDist;
              matrix.postScale(scale, scale, mid.x, mid.y);
            }
          }
          break;
      }

      view.setImageMatrix(matrix);
      return true; // indicate event was handled
    }
Example #8
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;

    // Dump touch event to log
    //	      dumpEvent(event);

    // Handle touch events here...
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        // 设置拖拉模式
      case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);
        // 設置初始點位置
        start.set(event.getX(), event.getY());
        Log.d(TAG, "mode=DRAG");
        mode = DRAG;
        break;
        // 设置多点触摸模式
      case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        Log.d(TAG, "oldDist=" + oldDist);
        if (oldDist > 10f) {
          savedMatrix.set(matrix);
          midPoint(mid, event);
          mode = ZOOM;
          Log.d(TAG, "mode=ZOOM");
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        Log.d(TAG, "mode=NONE");
        break;
        // 若为DRAG模式,则点击移动图片
      case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
          // ...
          matrix.set(savedMatrix);
          matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
        } else if (mode == ZOOM) {
          float newDist = spacing(event);
          Log.d(TAG, "newDist=" + newDist);
          if (newDist > 10f) {
            matrix.set(savedMatrix);
            float scale = newDist / oldDist;
            matrix.postScale(scale, scale, mid.x, mid.y);
          }
        }
        break;
    }

    view.setImageMatrix(matrix);
    return true; // indicate event was handled
  }
  public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) {
    super(context);
    mArrowImageView = new ImageView(context);

    Drawable arrowD = getResources().getDrawable(R.drawable.indicator_arrow);
    mArrowImageView.setImageDrawable(arrowD);

    final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding);
    mArrowImageView.setPadding(padding, padding, padding, padding);
    addView(mArrowImageView);

    int inAnimResId, outAnimResId;
    switch (mode) {
      case PULL_FROM_END:
        inAnimResId = R.anim.slide_in_from_bottom;
        outAnimResId = R.anim.slide_out_to_bottom;
        setBackgroundResource(R.drawable.indicator_bg_bottom);

        // Rotate Arrow so it's pointing the correct way
        mArrowImageView.setScaleType(ScaleType.MATRIX);
        Matrix matrix = new Matrix();
        matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f);
        mArrowImageView.setImageMatrix(matrix);
        break;
      default:
      case PULL_FROM_START:
        inAnimResId = R.anim.slide_in_from_top;
        outAnimResId = R.anim.slide_out_to_top;
        setBackgroundResource(R.drawable.indicator_bg_top);
        break;
    }

    mInAnim = AnimationUtils.loadAnimation(context, inAnimResId);
    mInAnim.setAnimationListener(this);

    mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId);
    mOutAnim.setAnimationListener(this);

    final Interpolator interpolator = new LinearInterpolator();
    mRotateAnimation =
        new RotateAnimation(
            0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    mRotateAnimation.setInterpolator(interpolator);
    mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
    mRotateAnimation.setFillAfter(true);

    mResetRotateAnimation =
        new RotateAnimation(
            -180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    mResetRotateAnimation.setInterpolator(interpolator);
    mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
    mResetRotateAnimation.setFillAfter(true);
  }
Example #10
0
 private void rotateImageView(ImageView imageview, int i, float f) {
   DisplayMetrics displaymetrics = new DisplayMetrics();
   windowManager.getDefaultDisplay().getMetrics(displaymetrics);
   Matrix matrix = new Matrix();
   float f1 = f % 360F;
   imageview.setScaleType(android.widget.ImageView.ScaleType.MATRIX);
   matrix.postRotate(
       f1,
       imageview.getDrawable().getBounds().width() / 2,
       imageview.getDrawable().getBounds().width() / 2);
   imageview.setImageMatrix(matrix);
 }
Example #11
0
  /**
   * 向下滑动让图片变大
   *
   * @param event
   * @return
   */
  public boolean onTouchEvent(MotionEvent event) {

    if (!isHaveHead) { // 无头部图片
      return super.onTouchEvent(event);
    }
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        // 手指压下屏幕
      case MotionEvent.ACTION_DOWN:
        if (isBacking) {
          return super.onTouchEvent(event);
        }
        int[] location = new int[2];
        imageView.getLocationInWindow(location);
        if (location[1] >= 0) {
          mode = MODE_DRAG;
          // 记录ImageView当前的移动位置
          currentMatrix.set(imageView.getImageMatrix());
          startPoint.set(event.getX(), event.getY());
        }
        break;
        // 手指在屏幕上移动,改事件会被不断触发
      case MotionEvent.ACTION_MOVE:
        // 拖拉图片
        if (mode == MODE_DRAG) {
          float dx = event.getX() - startPoint.x; // 得到x轴的移动距离
          float dy = event.getY() - startPoint.y; // 得到y轴的移动距离
          // 在没有移动之前的位置上进行移动
          if (dy / 2 + imgHeight <= 1.5 * imgHeight) {
            matrix.set(currentMatrix);
            float scale = (dy / 2 + imgHeight) / (imgHeight); // 得到缩放倍数
            if (dy > 0) {
              scaleY = dy;
              ListView.LayoutParams relativeLayout =
                  new ListView.LayoutParams((int) (scale * imgWidth), (int) (scale * imgHeight));
              imageView.setLayoutParams(relativeLayout);
              matrix.postScale(scale, scale, imgWidth / 2, 0);
              imageView.setImageMatrix(matrix);
            }
          }
        }
        break;
        // 手指离开屏幕
      case MotionEvent.ACTION_UP:
        // 当触点离开屏幕,图片还原
        mHandler.sendEmptyMessage(BACK_SCALE);
      case MotionEvent.ACTION_POINTER_UP:
        mode = 0;
        break;
    }

    return super.onTouchEvent(event);
  }
Example #12
0
    @TestTargets({
        @TestTargetNew(
            level = TestLevel.COMPLETE,
            method = "setImageMatrix",
            args = {android.graphics.Matrix.class}
        ),
        @TestTargetNew(
            level = TestLevel.COMPLETE,
            method = "getImageMatrix",
            args = {}
        )
    })
    public void testAccessImageMatrix() {
        final ImageView imageView = new ImageView(mActivity);

        imageView.setImageMatrix(null);
        assertNotNull(imageView.getImageMatrix());

        final Matrix matrix = new Matrix();
        imageView.setImageMatrix(matrix);
        assertEquals(matrix, imageView.getImageMatrix());
    }
 /** ³õʼ»¯¶¯»­ */
 private void InitImageView() {
   cursor = (ImageView) findViewById(R.id.cursor);
   bmpW =
       BitmapFactory.decodeResource(getResources(), R.drawable.friends_line)
           .getWidth(); // »ñȡͼƬ¿í¶È
   DisplayMetrics dm = new DisplayMetrics();
   getWindowManager().getDefaultDisplay().getMetrics(dm);
   int screenW = dm.widthPixels; // »ñÈ¡·Ö±æÂÊ¿í¶È
   offset = (screenW / 3 - bmpW) / 2; // ¼ÆËãÆ«ÒÆÁ¿
   Matrix matrix = new Matrix();
   matrix.postTranslate(offset, 0);
   cursor.setImageMatrix(matrix); // ÉèÖö¯»­³õʼλÖÃ
 }
Example #14
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        // primary touch event starts: remember touch down location
        touchState = DRAG;
        eventX = event.getX(0);
        eventY = event.getY(0);
        break;

      case MotionEvent.ACTION_POINTER_DOWN:
        // secondary touch event starts: remember distance and center
        eventDistance = calcDistance(event);
        calcMidpoint(event);
        if (eventDistance > MIN_DIST) touchState = ZOOM;
        else touchState = NONE;
        break;
      case MotionEvent.ACTION_MOVE:
        if (touchState == DRAG) {
          // single finger drag, translate accordingly
          matrix.set(eventMatrix);
          matrix.postTranslate(event.getX(0) - eventX, event.getY(0) - eventY);

        } else if (touchState == ZOOM) {
          // multi-finger zoom, scale accordingly around center
          float dist = calcDistance(event);

          if (dist > MIN_DIST) {
            matrix.set(eventMatrix);
            float scale = dist / eventDistance;
            matrix.postScale(scale, scale, eventX, eventY);
          }
        }

        // Perform the transformation
        view.setImageMatrix(matrix);
        break;

      case MotionEvent.ACTION_UP:
        eventMatrix.set(matrix);
        break;
      case MotionEvent.ACTION_POINTER_UP:
        eventMatrix.set(matrix);
        touchState = NONE;
        break;
    }

    return true;
  }
Example #15
0
 public void onCreate() {
   ivViewer = new ImageView(activity);
   ivViewer.setScaleType(ScaleType.MATRIX);
   ivViewer.setBackgroundColor(0xc0000000);
   ivViewer.setOnTouchListener(this);
   if (pic != null && !pic.isRecycled()) {
     ivViewer.setImageBitmap(pic);
   }
   dm = new DisplayMetrics();
   activity.getWindowManager().getDefaultDisplay().getMetrics(dm); // 获取分辨率
   minZoom();
   CheckView();
   ivViewer.setImageMatrix(matrix);
   activity.setContentView(ivViewer);
 }
Example #16
0
 /** 初始化动画 */
 private void initImageView() {
   cursor = (ImageView) findViewById(R.id.tab2_bg);
   bmpW =
       BitmapFactory.decodeResource(getResources(), R.drawable.topbar_select).getWidth(); // 获取图片宽度
   DisplayMetrics dm = new DisplayMetrics();
   getWindowManager().getDefaultDisplay().getMetrics(dm);
   int screenW = dm.widthPixels; // 获取分辨率宽度
   // System.out.println("屏幕宽度:" + screenW);
   offset =
       (screenW / 3 - bmpW)
           / 2; // 计算偏移量:屏幕宽度/3,平分为3分,如果是3个view的话,再减去图片宽度,因为图片居中,所以要得到两变剩下的空隙需要再除以2
   Matrix matrix = new Matrix();
   matrix.postTranslate(offset * 3 + bmpW, 0); // 初始化位置
   cursor.setImageMatrix(matrix); // 设置动画初始位置
 }
Example #17
0
  /** 初始化精品项目 */
  public void initJPXM() {
    // 下面四个页面的list
    List<Fragment> fragmentList = new ArrayList<Fragment>();
    // 页面标题的list
    //        List<String> titleList=new ArrayList<String>();

    // 叶卡头标
    // 动画图片的宽度
    int bmpWidth;
    tv_zhtj = (TextView) findViewById(R.id.tv_zhtj);
    tv_zxsx = (TextView) findViewById(R.id.tv_zxsx);
    tv_jezg = (TextView) findViewById(R.id.tv_jezg);
    tv_gzzd = (TextView) findViewById(R.id.tv_gzzd);
    tv_zhtj.setOnClickListener(this);
    tv_zxsx.setOnClickListener(this);
    tv_jezg.setOnClickListener(this);
    tv_gzzd.setOnClickListener(this);
    viewPager3 = (ViewPager) findViewById(R.id.viewPager3);
    fragmentList.add(new SyJPOneFragment());
    fragmentList.add(new SyJPOneFragment());
    fragmentList.add(new SyJPOneFragment());
    fragmentList.add(new SyJPOneFragment());
    // 初始化那个红色标识动画
    cursor = (ImageView) findViewById(R.id.cursor);
    DisplayMetrics dm = new DisplayMetrics();
    // 获得窗口属性
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    // 获得屏幕宽度
    int screenW = dm.widthPixels;
    btmWidth = screenW / 4;
    // 设定这个cursor的宽
    cursor.setLayoutParams(
        new LinearLayout.LayoutParams(btmWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
    Log.i("xinbei", "屏幕的宽度++++++++++++++++" + screenW);

    Log.i("xinbei", "bitmap的值++++++++++++++++" + btmWidth);
    // 计算偏移量
    offset = (screenW / 4 - btmWidth) / 2;
    Log.e("xinbei", "我就看看是不是==0" + offset);
    Matrix matrix = new Matrix();
    matrix.postTranslate(offset, 0);
    // 设置动画初始位置
    cursor.setImageMatrix(matrix);
    viewPager3.setAdapter(new SyJPFragmentAdapter(getSupportFragmentManager(), fragmentList));
    viewPager3.setCurrentItem(0);
    viewPager3.setOnPageChangeListener(
        new MyJPXMPageChangeListener(offset, btmWidth, currIndex, cursor));
  }
Example #18
0
  @Override
  protected void onPostExecute(Boolean result) {
    if (!result) {
      Toast.makeText(this.context, "ツイートに失敗しました。", Toast.LENGTH_LONG).show();
      return;
    }

    LayoutInflater inflater =
        (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.activity_tweeted_toast, null);

    // スタンプ画像を設定
    ImageView stampImage = (ImageView) view.findViewById(R.id.stampImage);
    stampImage.setImageBitmap(this.bitmap);

    // 画面サイズを取得する
    Display disp = this.context.getWindowManager().getDefaultDisplay();

    // 画面の幅(Pixel)÷画像ファイルの幅(Pixel)=画面いっぱいに表示する場合の倍率
    float factor = (disp.getWidth() / this.bitmap.getWidth()) * 0.8f;

    // 表示サイズ(Pixel)を指定して、LayoutParamsを生成(ImageViewはこのサイズになる)
    LinearLayout.LayoutParams lp =
        new LinearLayout.LayoutParams(
            (int) (this.bitmap.getWidth() * factor), (int) (this.bitmap.getHeight() * factor));
    // 中央に表示する
    lp.gravity = Gravity.CENTER;

    // LayoutParamsをImageViewに設定
    stampImage.setLayoutParams(lp);

    // ImageViewのMatrixに拡大率を指定
    Matrix m = stampImage.getImageMatrix();
    m.reset();
    m.postScale(factor, factor);
    stampImage.setImageMatrix(m);

    // ツイート内容を設定
    TextView tweetText = (TextView) view.findViewById(R.id.tweetText);
    tweetText.setText(this.text);
    Log.i("Tweet内容", this.text);

    // Toastを表示
    Toast toast = new Toast(this.context);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(view);
    toast.show();
  }
Example #19
0
  private void setImageViewMatrix(Matrix matrix) {
    ImageView imageView = getImageView();
    if (null != imageView) {

      checkImageViewScaleType();
      imageView.setImageMatrix(matrix);

      // Call MatrixChangedListener if needed
      if (null != mMatrixChangeListener) {
        RectF displayRect = getDisplayRect(matrix);
        if (null != displayRect) {
          mMatrixChangeListener.onMatrixChanged(displayRect);
        }
      }
    }
  }
Example #20
0
 private void initHead() {
   LayoutInflater inflater = LayoutInflater.from(mContext);
   headerView = inflater.inflate(R.layout.top_img, null);
   imageView = (ImageView) headerView.findViewById(R.id.imageView);
   float scale = (float) displayWidth / (float) bmp.getWidth(); // 1080/1800
   matrix.postScale(scale, scale, 0, 0);
   imageView.setImageMatrix(matrix);
   defaultMatrix.set(matrix);
   imgHeight = scale * bmp.getHeight();
   imgWidth = scale * bmp.getWidth();
   ListView.LayoutParams relativeLayout =
       new ListView.LayoutParams((int) imgWidth, (int) imgHeight);
   imageView.setLayoutParams(relativeLayout);
   this.addHeaderView(headerView);
   isHaveHead = true;
 }
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;
    dumpEvent(event);

    // Handle touch events here...
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);
        start.set(event.getX(), event.getY());
        Log.d(ImageViewerActivity.class.getName(), "mode=DRAG");
        mode = DRAG;
        break;
      case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        Log.d(ImageViewerActivity.class.getName(), "oldDist=" + oldDist);
        if (oldDist > 10f) {
          savedMatrix.set(matrix);
          midPoint(mid, event);
          mode = ZOOM;
          Log.d(ImageViewerActivity.class.getName(), "mode=ZOOM");
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        Log.d(ImageViewerActivity.class.getName(), "mode=NONE");
        break;
      case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
          matrix.set(savedMatrix);
          matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
        } else if (mode == ZOOM) {
          float newDist = spacing(event);
          Log.d(ImageViewerActivity.class.getName(), "newDist=" + newDist);
          if (newDist > 10f) {
            matrix.set(savedMatrix);
            float scale = newDist / oldDist;
            matrix.postScale(scale, scale, mid.x, mid.y);
          }
        }
        break;
    }

    view.setImageMatrix(matrix);
    return true;
  }
Example #22
0
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   ImageView view = (ImageView) v;
   // Dump touch event to log
   dumpEvent(event);
   // int rotation=(int)Math.toDegrees(r);
   // Handle touch events here...
   switch (event.getAction() & MotionEvent.ACTION_MASK) {
     case MotionEvent.ACTION_DOWN:
       savedMatrix.set(matrix);
       start.set(event.getX(), event.getY());
       System.out.println("get x >>>" + event.getX());
       System.out.println("get y>>>" + event.getY());
       mode = DRAG;
       break;
     case MotionEvent.ACTION_POINTER_DOWN:
       oldDist = spacing(event);
       if (oldDist > 10f) {
         savedMatrix.set(matrix);
         midPoint(mid, event);
         mode = ZOOM;
       }
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_POINTER_UP:
       mode = NONE;
       break;
     case MotionEvent.ACTION_MOVE:
       if (mode == DRAG) {
         // ...
         matrix.set(savedMatrix);
         matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
       } else if (mode == ZOOM) {
         float newDist = spacing(event);
         if (newDist > 10f) {
           matrix.set(savedMatrix);
           float scale = newDist / oldDist;
           matrix.postScale(scale, scale, mid.x, mid.y);
         }
       }
       break;
   }
   // fixing();
   view.setImageMatrix(matrix);
   return true; // indicate event was handled
 }
Example #23
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // start tracing to "/sdcard/tuch.trace"
    //      android.os.Debug.startMethodTracing("tuch");
    Context mc = getApplicationContext();
    affirm = MediaPlayer.create(mc, R.raw.gotit);
    deny = MediaPlayer.create(mc, R.raw.nope);

    setContentView(R.layout.main);
    CONTEXT = this;
    ImageView view = (ImageView) findViewById(R.id.imageView);
    view.setOnTouchListener(this);
    matrix.postTranslate(-xLoc, -yLoc);
    view.setImageMatrix(matrix);
    lpView = new TextView(CONTEXT);
    lpView.setTextAppearance(CONTEXT, R.style.MyDefaultTextAppearance);
  }
Example #24
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);
        start.set(event.getX(), event.getY());
        mode = DRAG;
        break;
      case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 10f) {
          savedMatrix.set(matrix);
          midPoint(mid, event);
          mode = ZOOM;
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
      case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
          // ...
          matrix.set(savedMatrix);
          matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
          start_x = event.getX() - start.x;
          start_y = event.getY() - start.y;
        } else if (mode == ZOOM) {
          float newDist = spacing(event);
          if (newDist > 10f) {
            matrix.set(savedMatrix);
            float scale = newDist / oldDist;
            mAspect = scale;
            matrix.postScale(scale, scale, mid.x, mid.y);
          }
        }
        break;
    }

    view.setImageMatrix(matrix);
    view.invalidate();
    return true;
  }
Example #25
0
  // 调整图片
  private void adjustImg(Bitmap baseBitmap) {
    Bitmap oldBitmap = baseBitmap.copy(Bitmap.Config.ARGB_8888, true);

    int bitmapWidth = oldBitmap.getWidth();
    int bitmapHeight = oldBitmap.getHeight();
    Matrix m = new Matrix();
    // 如果图片的宽度大于高度,则需要旋转90重新生成图片
    if (bitmapWidth > bitmapHeight) {
      m.postRotate(90); // 旋转90度
    } else {
      m.postRotate(0); // 不做旋转
    }

    bitmap = Bitmap.createBitmap(oldBitmap, 0, 0, bitmapWidth, bitmapHeight, m, false);
    locImg.setImageBitmap(bitmap);
    center();
    // 顺序不能变化,否则导致初始化不能居中
    locImg.setImageMatrix(matrix);
  }
Example #26
0
  /** 触屏监听 */
  public boolean onTouch(View v, MotionEvent event) {

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        // 主点按下
      case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);
        prev.set(event.getX(), event.getY());
        mode = DRAG;
        break;
        // 副点按下
      case MotionEvent.ACTION_POINTER_DOWN:
        dist = spacing(event);
        // 如果连续两点距离大于10,则判定为多点模式
        if (spacing(event) > 10f) {
          savedMatrix.set(matrix);
          midPoint(mid, event);
          mode = ZOOM;
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        // savedMatrix.set(matrix);
        break;
      case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
          matrix.set(savedMatrix);
          matrix.postTranslate(event.getX() - prev.x, event.getY() - prev.y);
        } else if (mode == ZOOM) {
          float newDist = spacing(event);
          if (newDist > 10f) {
            matrix.set(savedMatrix);
            float tScale = newDist / dist;
            matrix.postScale(tScale, tScale, mid.x, mid.y);
          }
        }
        break;
    }
    locImg.setImageMatrix(matrix);
    CheckView();
    return true;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
      setContentView(R.layout.menu19_error);
      Context mContext = getApplicationContext();
      //		   	BitmapDrawable d = (BitmapDrawable)
      // mContext.getResources().getDrawable(R.drawable.p1);
      Display display = getWindowManager().getDefaultDisplay();
      float disWidth = display.getWidth();
      float disHeight = display.getHeight();
      view = (ImageView) findViewById(R.id.imageView19error);
      view.setOnTouchListener(this);

      scale = 1.0f;
      //	Toast.makeText(getApplicationContext()," disWidth "+disWidth,Toast.LENGTH_LONG).show();

      //      Log.d("2222screeeenWirdthhhhhhh"," is " +disWidth);

      scale = 0.4f;
      if (disWidth <= 321) { // 320 is my mini Alcatel pop C1
        scale = 0.1f;
        //   	matrix.setScale(scale,scale);
        // 	matrix.postTranslate(-600, -800);
      }
      if (disWidth <= 721 && disWidth >= 322) { // 720 is my Motorolla G, quite big screen
        scale = 0.27f;
        //   	matrix.setScale(scale,scale);
        // 	matrix.postTranslate(-600, -800);
      }
      matrix.setScale(scale, scale);
      // matrix.postTranslate(-1100.0f, -600.0f);
      view.setImageMatrix(matrix);
    } catch (Exception e) {
      startActivity(new Intent(this, GeneralErrorMessage.class)); // dummy error pic
      finish();
      //	    		Toast.makeText(getApplicationContext()," Sorry, your phoine does not have enough VM
      // memory  "+e,Toast.LENGTH_LONG).show();
      // TODO
    }
  }
Example #28
0
  protected void animate(final ImageView backgroundImage) {
    backgroundImage.setScaleType(ImageView.ScaleType.MATRIX);

    final float scaleFactor =
        (float) backgroundImage.getHeight()
            / (float) backgroundImage.getDrawable().getIntrinsicHeight()
            * 1.25f;
    matrix.postScale(scaleFactor, scaleFactor);
    matrix.postTranslate(
        -value * (float) Math.cos(angle), value * (float) Math.sin(angle)); // Translates the matrix
    backgroundImage.setImageMatrix(matrix);

    ValueAnimator animator; // Creates an animator that goes from 0->100 or 100->0
    if (value == 0) animator = ValueAnimator.ofFloat(0, 100);
    else animator = ValueAnimator.ofFloat(value, 0);

    // Updater that translates the image in the direction
    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            value = (float) animation.getAnimatedValue();
            matrix.reset();
            matrix.postScale(scaleFactor, scaleFactor);
            matrix.postTranslate(-value * (float) Math.cos(angle), value * (float) Math.sin(angle));
            backgroundImage.setImageMatrix(matrix);
          }
        });
    animator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            animate(backgroundImage);
          }
        });
    animator.setDuration(value == -1 ? 10 : 50000);
    animator.setInterpolator(new LinearInterpolator());
    animator.setStartDelay(0);
    animator.start();
  }
  private void updateMatrix(int action) {
    Matrix matrix = new Matrix();

    switch (action) {
      case ACTION_ROTATE:
        matrix.postRotate(45, 450, 450);
        break;
      case ACTION_TRANSLATE:
        matrix.postTranslate(250, 250);
        break;
      case ACTION_SCALE:
        matrix.postScale(1 / 2f, 2, 100, 100);
        break;
      case ACTION_SKEW:
        matrix.postSkew(0.2f, 0.2f, 100, 100);
        break;
      default:
        break;
    }

    mImageView.setImageMatrix(matrix);
  }
        @Override
        public boolean onTouch(View v, MotionEvent event) {
          ImageView view = (ImageView) v;

          switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
              if (savedPointsVisible) {
                hideSavedPoints();
                savedPointsVisible = false;
              }
              startPoint.set(event.getX(), event.getY());
              savedMatrix.set(matrix);
              mode = DRAG;
              break;
            case MotionEvent.ACTION_POINTER_DOWN:
              if (savedPointsVisible) {
                hideSavedPoints();
                savedPointsVisible = false;
              }
              oldDist = spacing(event);
              if (oldDist > 10f) {
                savedMatrix.set(matrix);
                midPoint(midPoint, event);
                mode = ZOOM;
              }
              break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
              mode = NONE;
              refreshSavedPoints();
              savedPointsVisible = true;
              break;
            case MotionEvent.ACTION_MOVE:
              if (mode == DRAG) {
                matrix.set(savedMatrix);
                matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y);
              } else if (mode == ZOOM) {
                float newDist = spacing(event);
                if (newDist > 10f) {
                  matrix.set(savedMatrix);
                  float scale = newDist / oldDist;

                  matrix.postScale(scale, scale, midPoint.x, midPoint.y);
                  matrix.getValues(imageValues);

                  /** ZOOM CONTROL * */
                  if (imageValues[0] < viewWidth * 1. / bounds.width()) {
                    matrix.setScale(
                        viewWidth * 1.f / bounds.width(),
                        viewWidth * 1.f / bounds.width(),
                        midPoint.x,
                        midPoint.y);
                  }
                  if (imageValues[0] > 2) {
                    matrix.setScale(2, 2);
                  }
                }
              }
              matrix.getValues(imageValues);
              /** PANNING CONTROL * */
              if (imageValues[2] > 0) {
                matrix.postTranslate(-imageValues[2], 0);
              }
              if (imageValues[5] > 0) {
                matrix.postTranslate(0, -imageValues[5]);
              }
              if (imageValues[2] < viewWidth - bounds.width() * imageValues[0]) {
                matrix.postTranslate(
                    viewWidth - bounds.width() * imageValues[0] - imageValues[2], 0);
              }

              if (imageValues[5] < -bounds.height() * imageValues[0]) {
                matrix.postTranslate(0, -bounds.height() * imageValues[0] - imageValues[5]);
              }

              break;
          }

          view.setImageMatrix(matrix);

          return true;
        }