Android Open Source - UniversalImagePick Viewfinder View






From Project

Back to project page UniversalImagePick.

License

The source code is released under:

Apache License

If you think the Android project UniversalImagePick listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.luffyjet.universalimagepick.widget;
/*from ww  w .  j a  v a2s  .  c o m*/
/*
 * Copyright (C) 2008 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;

import com.luffyjet.universalimagepick.R;

/**
 * This view is overlaid on top of the camera preview. It adds the viewfinder
 * rectangle and partial transparency outside it, as well as the laser scanner
 * animation and result points.
 * 
 */
public final class ViewfinderView extends View {
  private static final String TAG = "log";
  /**
   * ?????????
   */
  private static final long ANIMATION_DELAY = 10L;
  /**
   * ????
   */
  private static final int BORDER_WIDTH = 1;
  /**
   * ??
   */
  private Paint mPaint;
  /**
   * ????
   */
  private final int maskColor;
  /**
   * ???
   */
  public  Rect mFrame;
  
  private static float density;
  private Bitmap resultBitmap;


  public ViewfinderView(Context context, AttributeSet attrs) {
    super(context, attrs);

    density = context.getResources().getDisplayMetrics().density;

    mPaint = new Paint();
    Resources resources = getResources();
    maskColor = resources.getColor(R.color.viewfinder_mask);

    mFrame = new Rect(50, 250, 450, 650);
  }

  @Override
  public void onDraw(Canvas canvas) {

    // ???????????
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    mPaint.setColor(maskColor);
    // ??????????????
    canvas.drawRect(0, 0, width, mFrame.top, mPaint);//???
    canvas.drawRect(0, mFrame.top, mFrame.left, mFrame.bottom, mPaint);//????
    canvas.drawRect(mFrame.right, mFrame.top, width, mFrame.bottom, mPaint);//??????
    canvas.drawRect(0, mFrame.bottom, width, height, mPaint);//???

    // ??????????
    mPaint.setColor(Color.WHITE);
    canvas.drawRect(mFrame.left, mFrame.top, mFrame.right, mFrame.top + BORDER_WIDTH, mPaint);//????????
    canvas.drawRect(mFrame.left, mFrame.top, mFrame.left + BORDER_WIDTH, mFrame.bottom, mPaint);//??????
    canvas.drawRect(mFrame.right - BORDER_WIDTH, mFrame.top, mFrame.right, mFrame.bottom, mPaint);//????????
    canvas.drawRect(mFrame.left, mFrame.bottom - BORDER_WIDTH, mFrame.right, mFrame.bottom, mPaint);//??

    // ????????????????????
    postInvalidateDelayed(ANIMATION_DELAY, mFrame.left, mFrame.top, mFrame.right, mFrame.bottom);
  }

  public void drawViewfinder() {
    resultBitmap = null;
    invalidate();
  }

  /**
   * Draw a bitmap with the result points highlighted instead of the live
   * scanning display.
   * 
   * @param barcode
   *            An image of the decoded barcode.
   */
  public void drawResultBitmap(Bitmap barcode) {
    resultBitmap = barcode;
    invalidate();
  }
}




Java Source Code List

com.luffyjet.universalimagepick.App.java
com.luffyjet.universalimagepick.Constants.java
com.luffyjet.universalimagepick.MainActivity.java
com.luffyjet.universalimagepick.Test.java
com.luffyjet.universalimagepick.adapter.BucketAdapter.java
com.luffyjet.universalimagepick.adapter.GalleryAdapter.java
com.luffyjet.universalimagepick.adapter.PickGridAdapter.java
com.luffyjet.universalimagepick.adapter.PreviewAdapter.java
com.luffyjet.universalimagepick.adapter.ResultAdapter.java
com.luffyjet.universalimagepick.model.ImageBucket.java
com.luffyjet.universalimagepick.model.Image.java
com.luffyjet.universalimagepick.model.ImagesHelper.java
com.luffyjet.universalimagepick.model.Thumbnail.java
com.luffyjet.universalimagepick.ui.BaseActivity.java
com.luffyjet.universalimagepick.ui.GalleryActivity.java
com.luffyjet.universalimagepick.ui.PickActivity.java
com.luffyjet.universalimagepick.utils.LogUtil.java
com.luffyjet.universalimagepick.widget.CropImageView.java
com.luffyjet.universalimagepick.widget.CustomGridView.java
com.luffyjet.universalimagepick.widget.MulitPointTouchListener.java
com.luffyjet.universalimagepick.widget.ViewfinderView.java