Commit Android

Commit Android Label and rect sight removing
This commit is contained in:
PaoloMessina 2015-01-16 12:12:39 +01:00
parent 9d94500548
commit 790704f750

View File

@ -8,10 +8,6 @@ import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.drawable.ShapeDrawable;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.Camera.CameraInfo; import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.PreviewCallback;
@ -22,12 +18,8 @@ import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import net.sourceforge.zbar.ImageScanner; import net.sourceforge.zbar.ImageScanner;
@ -61,16 +53,6 @@ implements SurfaceHolder.Callback {
// Customisable stuff // Customisable stuff
String whichCamera; String whichCamera;
String flashMode; String flashMode;
/* START - ALMAVIVA */
RelativeLayout relativeLayout;
RelativeLayout line;
View parent;
int width;
int height;
boolean drawSight = false;
/* END - ALMAVIVA */
// For retrieving R.* resources, from the actual app package // For retrieving R.* resources, from the actual app package
// (we can't use actual.application.package.R.* in our code as we // (we can't use actual.application.package.R.* in our code as we
@ -87,9 +69,6 @@ implements SurfaceHolder.Callback {
// Activity Lifecycle ---------------------------------------------- // Activity Lifecycle ----------------------------------------------
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override @Override
public void onCreate (Bundle savedInstanceState) public void onCreate (Bundle savedInstanceState)
{ {
@ -105,7 +84,6 @@ implements SurfaceHolder.Callback {
String textInstructions = params.optString("text_instructions"); String textInstructions = params.optString("text_instructions");
whichCamera = params.optString("camera"); whichCamera = params.optString("camera");
flashMode = params.optString("flash"); flashMode = params.optString("flash");
drawSight = params.optString("drawSight") != null ? Boolean.valueOf(params.optString("drawSight").toLowerCase()) : false;
// Initiate instance variables // Initiate instance variables
autoFocusHandler = new Handler(); autoFocusHandler = new Handler();
@ -142,65 +120,6 @@ implements SurfaceHolder.Callback {
((FrameLayout) findViewById(getResourceId("id/csZbarScannerView"))).addView(scannerSurface); ((FrameLayout) findViewById(getResourceId("id/csZbarScannerView"))).addView(scannerSurface);
findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront(); findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront();
findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront(); findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront();
/* START - ALMAVIVA */
// Creating a new RelativeLayout
if(drawSight){
relativeLayout = new RelativeLayout(this);
line = new RelativeLayout(this);
// Defining the RelativeLayout layout parameters.
// In this case I want to fill its parent
parent = ((FrameLayout) findViewById(getResourceId("id/csZbarScannerView")));
parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Ensure you call it only once :
parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
width = parent.getWidth();
height = parent.getHeight();
double dim = width < height ? (width / 1.2) : (height / 1.2);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams((int)dim,(int)dim);
rlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
rlp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
rlp.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
relativeLayout.setGravity(Gravity.CENTER);
relativeLayout.setLayoutParams(rlp);
relativeLayout.invalidate();
relativeLayout.requestLayout();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(((int)dim - 16),8);
lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
lp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
lp.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
line.setGravity(Gravity.CENTER);
line.setLayoutParams(lp);
line.setBackgroundColor(Color.RED);
line.invalidate();
line.requestLayout();
}
});
ShapeDrawable rectShapeDrawable = new ShapeDrawable(); // pre defined class
// get paint
Paint paint = rectShapeDrawable.getPaint();
// set border color, stroke and stroke width
paint.setColor(Color.GREEN);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(8); // you can change the value of 5
relativeLayout.setBackgroundDrawable(rectShapeDrawable);
relativeLayout.addView(line);
((RelativeLayout) findViewById(getResourceId("id/csZbarScannerViewContainer"))).addView(relativeLayout);
}
/* END - ALMAVIVA */
} }
@Override @Override
@ -306,19 +225,16 @@ implements SurfaceHolder.Callback {
private AutoFocusCallback autoFocusCb = new AutoFocusCallback() private AutoFocusCallback autoFocusCb = new AutoFocusCallback()
{ {
public void onAutoFocus(boolean success, Camera camera) { public void onAutoFocus(boolean success, Camera camera) {
camera.cancelAutoFocus(); autoFocusHandler.postDelayed(doAutoFocus, autoFocusInterval);
autoFocusHandler.postDelayed(doAutoFocus, autoFocusInterval); }
}
}; };
private Runnable doAutoFocus = new Runnable() private Runnable doAutoFocus = new Runnable()
{ {
public void run() { public void run() {
if(camera != null){ if(camera != null) camera.autoFocus(autoFocusCb);
camera.autoFocus(autoFocusCb); }
}
}
}; };
// Camera callbacks ------------------------------------------------ // Camera callbacks ------------------------------------------------