2019年10月28日 星期一

[Android]Camera + textureView

Camera1
縮放 :
Camera.Paramenters params = mCamera.getParameters();
params.setZoom(zoomLevel);
mCamera.setParameters(params);



Camera2
縮放
final int zoomScale = 200;
captureBuilder.set(CaptureRequest.SCALER_CROP_REGION, new
     Rect(zoomScale * mZoomLevel, zoomScale * mZoomLevel, mStartBounds.right
     - (zoomScale * mZoomLevel), mStartBounds.bottom - (zoomScale * mZoomLevel)));


TextureView解決相機預覽左右相反問題 :
mCameraTextureView.setRotationX(180.0f);




package com.example.multiscreencameratest;
import android.Manifest;import android.app.Service;import android.content.ComponentName;import android.content.Intent;import android.content.ServiceConnection;import android.content.pm.PackageManager;import android.graphics.Bitmap;import android.graphics.Matrix;import android.graphics.SurfaceTexture;import android.hardware.camera2.CameraAccessException;import android.hardware.camera2.CameraCaptureSession;import android.hardware.camera2.CameraCharacteristics;import android.hardware.camera2.CameraDevice;import android.hardware.camera2.CameraManager;import android.hardware.camera2.CameraMetadata;import android.hardware.camera2.CaptureRequest;import android.hardware.camera2.params.StreamConfigurationMap;import android.media.MediaPlayer;import android.os.Bundle;
import android.app.Activity;import android.app.AlertDialog;import android.app.Presentation;import android.content.Context;import android.content.DialogInterface;import android.content.res.Resources;import android.hardware.display.DisplayManager;import android.os.Handler;import android.os.HandlerThread;import android.os.IBinder;import android.os.Message;import android.support.annotation.NonNull;import android.support.v4.app.ActivityCompat;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.util.Size;import android.util.SparseArray;import android.view.Display;import android.view.Surface;import android.view.SurfaceHolder;import android.view.SurfaceView;import android.view.TextureView;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.AdapterView;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.ListView;import android.widget.Spinner;import android.widget.TextView;import android.widget.Toast;

import java.io.File;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;
import java.util.Arrays;import java.util.HashMap;import java.util.Map;
public class MainActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
    private final String LOG_TAG = "MultiScreenCameraTest";
    private static final int MESG_UPDATE_DISPLAY = 100;    private static final int MESG_SHOW_SCRENN = 101;    private static final int MESG_SHOW_ALL_SCRENN = 102;    private static final int MESG_HIDE_SCRENN = 103;    private static final int MESG_HIDE_ALL_SCRENN = 104;    private static final int MESG_SCAN_CAMERA = 200;
    private Context mContext = null;
    private MsgHandler mMsgHandler = null;
    private DisplayManager mDisplayManager;    private DisplayListAdapter mDisplayListAdapter;    private TextureView mCameraTextureView;
    private boolean mIsTextureViewAvailable = false;
    private CameraManager mCameraManager = null;    private CameraDevice mCameraDevice = null;    private Size mImageDimension = null;    protected CameraCaptureSession mCameraCaptureSession = null;    protected CaptureRequest.Builder mCaptureRequestBuilder = null;    private Handler mBackgroundHandler;    private HandlerThread mBackgroundThread;
    private Display[] mDisplays;    private boolean mShowAllDisplays = true;
    private HashMap, 
MultiScreen> mMultiScreenMap = null;
private HashMap, Integer> mCameraScreenMap = null; private static final int REQUEST_CAMERA_PERMISSION = 200;
private int degreeX = 0; public Document doc; public NodeList nlist;
public static int leftPillar_left; public static int leftPillar_top; public static int leftPillar_right; public static int leftPillar_bottom; public static int leftPillar_radius; public static int leftPillar_degree; public static int leftPillar_translationX; public static int leftPillar_translationY; public static float leftPillar_scaleX; public static float leftPillar_scaleY;
public static int rightPillar_left; public static int rightPillar_top; public static int rightPillar_right; public static int rightPillar_bottom; public static int rightPillar_radius; public static int rightPillar_degree; public static int rightPillar_translationX; public static int rightPillar_translationY; public static float rightPillar_scaleX; public static float rightPillar_scaleY;
public static boolean isRight = true;

private void hideSystemUI() {
View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); }

@Override public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus); if (hasFocus) {
hideSystemUI(); }
}

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); Log.d(LOG_TAG, "onCreate"); try {
readxml(); } catch (IOException e) {
Log.d(LOG_TAG, "XML load exception " + e); e.printStackTrace(); }
setContentView(R.layout.activity_main); mContext = getApplicationContext(); mMsgHandler = new MsgHandler();
mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE); mCameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); mCameraScreenMap = new HashMap, Integer>(); mCameraTextureView = (TextureView) findViewById(R.id.camera); mCameraTextureView.setSurfaceTextureListener(mTextureListener); //boris if(isRight == true){
Log.d(LOG_TAG, "[KH]isRight"); mCameraTextureView.setOutlineProvider(new TextureVideoViewOutlineProvider(0, 0, 3900, 1920, rightPillar_radius, rightPillar_degree)); //mCameraTextureView.setOutlineProvider(new TextureVideoViewOutlineProvider(rightPillar_left, rightPillar_top, rightPillar_right, rightPillar_bottom, rightPillar_radius, rightPillar_degree)); mCameraTextureView.setRotation(250);//rightPillar_degree mCameraTextureView.setTranslationX(200);//rightPillar_translationX mCameraTextureView.setTranslationY(200);//rightPillar_translationY -1000 mCameraTextureView.setScaleX(2.6f);//rightPillar_scaleX Log.d(LOG_TAG, "[KH] mCameraTextureView getWidth = " + mCameraTextureView.getWidth()); mCameraTextureView.setScaleY(2.6f);//rightPillar_scaleY //mCameraTextureView.setRotationX(180.0f); }else{
mCameraTextureView.setOutlineProvider(new TextureVideoViewOutlineProvider(leftPillar_left, leftPillar_top, leftPillar_right, leftPillar_bottom, leftPillar_radius, leftPillar_degree)); mCameraTextureView.setRotation(leftPillar_degree);//leftPillar_degree mCameraTextureView.setTranslationX(leftPillar_translationX); mCameraTextureView.setTranslationY(leftPillar_translationY); mCameraTextureView.setScaleX(leftPillar_scaleX); mCameraTextureView.setScaleY(leftPillar_scaleY); //mCameraTextureView.setRotationX(180.0f); }
mCameraTextureView.setClipToOutline(true);
mDisplayListAdapter = new DisplayListAdapter(this);

mMultiScreenMap = new HashMap, MultiScreen>();
mDisplayManager.registerDisplayListener(mDisplayListener, null); if(mMsgHandler != null) {
mMsgHandler.sendEmptyMessage(MESG_UPDATE_DISPLAY); mMsgHandler.sendEmptyMessageDelayed(MESG_SHOW_ALL_SCRENN, 1000);// mMsgHandler.sendEmptyMessageDelayed(MESG_SCAN_CAMERA, 2000); }
}

@Override protected void onResume() {
super.onResume(); Log.d(LOG_TAG, "onResume"); startBackgroundThread(); }
@Override protected void onPause() {
super.onPause(); Log.d(LOG_TAG, "onPause"); }

@Override protected void onDestroy() {
super.onDestroy(); Log.d(LOG_TAG, "onDestroy"); mDisplayManager.unregisterDisplayListener(mDisplayListener); try {
if(mCameraCaptureSession != null) {
mCameraCaptureSession.stopRepeating(); }
} catch (CameraAccessException e) {
e.printStackTrace(); }
if(mMsgHandler != null) {
mMsgHandler.sendEmptyMessage(MESG_HIDE_ALL_SCRENN); }
stopBackgroundThread(); closeCamera(); }

@Override protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); }

@Override public void onItemClick(AdapterView parent, View view, int position, long id) {
final Display display = (Display)view.getTag();// Log.d(LOG_TAG, String.format("onItemClick position: %d, DisplayId: %d", position, display.getDisplayId())); Log.d(LOG_TAG, "Show display #" + display.getDisplayId() + " info"); Context context = view.getContext(); AlertDialog.Builder builder = new AlertDialog.Builder(context); Resources r = context.getResources(); AlertDialog alert = builder
.setTitle(r.getString(
R.string.presentation_alert_info_text, display.getDisplayId()))
.setMessage(display.toString())
.setNeutralButton(R.string.presentation_alert_dismiss_text, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); }
})
.create(); alert.show(); }

TextureView.SurfaceTextureListener mTextureListener = new TextureView.SurfaceTextureListener() {
@Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.d(LOG_TAG, "onSurfaceTextureAvailable"); mIsTextureViewAvailable = true; if(mMsgHandler != null) {
mMsgHandler.sendEmptyMessageDelayed(MESG_SCAN_CAMERA, 1500); }
}
@Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
// Transform you image captured size according to the surface width and height }
@Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.d(LOG_TAG, "onSurfaceTextureDestroyed"); mIsTextureViewAvailable = false; return false; }
@Override public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
};
private void updateDisplay() {
mDisplays = mDisplayManager.getDisplays(getDisplayCategory()); Log.d(LOG_TAG, "There are currently " + mDisplays.length + " displays connected."); mDisplayListAdapter.updateContents(); }

private String getDisplayCategory() {
return mShowAllDisplays ? null : DisplayManager.DISPLAY_CATEGORY_PRESENTATION; }

@Override public void onClick(View v) {
switch (v.getId()) {
case R.id.info:
Log.d(LOG_TAG, "Show display info"); Context context = v.getContext(); AlertDialog.Builder builder = new AlertDialog.Builder(context); final Display display = (Display)v.getTag(); Resources r = context.getResources(); AlertDialog alert = builder
.setTitle(r.getString(
R.string.presentation_alert_info_text, display.getDisplayId()))
.setMessage(display.toString())
.setNeutralButton(R.string.presentation_alert_dismiss_text, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); }
})
.create(); alert.show(); break; default:
break; }
}

private final DisplayManager.DisplayListener mDisplayListener =
new DisplayManager.DisplayListener() {
@Override public void onDisplayAdded(int displayId) {
Log.d(LOG_TAG, "Display #" + displayId + " added"); if(mMsgHandler != null) {
mMsgHandler.sendEmptyMessage(MESG_UPDATE_DISPLAY); Message message = new Message(); message.what = MESG_SHOW_SCRENN; message.arg1 = displayId; mMsgHandler.sendMessage(message); }
}
@Override public void onDisplayChanged(int displayId) {
Log.d(LOG_TAG, "Display #" + displayId + " changed");// if(mMsgHandler != null) {// mMsgHandler.sendEmptyMessage(MESG_UPDATE_DISPLAY);// Message message = new Message();// message.what = MESG_HIDE_SCRENN;// message.arg1 = displayId;// mMsgHandler.sendMessage(message);// Message message1 = new Message();// message1.what = MESG_SHOW_SCRENN;// message1.arg1 = displayId;// mMsgHandler.sendMessage(message1);// } }
@Override public void onDisplayRemoved(int displayId) {
Log.d(LOG_TAG, "Display #" + displayId + " removed"); if(mMsgHandler != null) {
mMsgHandler.sendEmptyMessage(MESG_UPDATE_DISPLAY); Message message = new Message(); message.what = MESG_HIDE_SCRENN; message.arg1 = displayId; mMsgHandler.sendMessage(message); }
}
};
private final class DisplayListAdapter extends ArrayAdapter {
final Context mContext; public DisplayListAdapter(Context context) {
super(context, R.layout.presentation_list_item); mContext = context; }
@Override public View getView(int position, View convertView, ViewGroup parent) {
final View v; if (convertView == null) {
v = ((Activity) mContext).getLayoutInflater().inflate(
R.layout.presentation_list_item, null); } else {
v = convertView; }
final Display display = getItem(position); final int displayId = display.getDisplayId();
v.setTag(display); TextView tv = (TextView)v.findViewById(R.id.display_id); tv.setText(v.getContext().getResources().getString(
R.string.presentation_display_id_text, displayId, display.getName())); return v; }

public void updateContents() {
clear(); addAll(mDisplays); }
}

private void showScreen(Display display) {
Log.d(LOG_TAG, "Show screen on display #" + display.getDisplayId()); if(display.getDisplayId() == 0) {
Log.d(LOG_TAG, "Display id is 0, just return!"); return; }
MultiScreen screen = new MultiScreen(this, display); screen.show(); screen.setOnDismissListener(mOnDismissListener); mMultiScreenMap.put(display.getDisplayId(), screen); Log.d(LOG_TAG, "Screen count: " + mMultiScreenMap.size()); if(mMsgHandler != null) {
if(!mMsgHandler.hasMessages(MESG_SCAN_CAMERA)) {
mMsgHandler.sendEmptyMessage(MESG_SCAN_CAMERA); }
}
}

private void hideScreen(int displayId) {
Log.d(LOG_TAG, "Hide screen on display #" + displayId); if(displayId == 0) {
Log.d(LOG_TAG, "Display id is 0, just return!"); return; }
if (mMultiScreenMap.containsKey(displayId)) {
mMultiScreenMap.get(displayId).dismiss(); }
}

private final DialogInterface.OnDismissListener mOnDismissListener =
new DialogInterface.OnDismissListener() {
@Override public void onDismiss(DialogInterface dialog) {
MultiScreen presentation = (MultiScreen)dialog; int displayId = presentation.getDisplay().getDisplayId(); Log.d(LOG_TAG, "Screen on display #" + displayId + " was dismissed"); mMultiScreenMap.remove(displayId); Log.d(LOG_TAG, "Screen count: " + mMultiScreenMap.size()); if(mCameraScreenMap.containsValue(displayId)) {
for (Map.Entry,
Integer> entry : mCameraScreenMap.entrySet()) {
int display_id = entry.getValue(); if(displayId == display_id) {
mCameraScreenMap.remove(entry.getKey()); }
}
}
}
};
private void scanCamera() {
Log.d(LOG_TAG, "scanCamera"); try {
for (String camera_id : mCameraManager.getCameraIdList()) {
Log.d(LOG_TAG, String.format("camera_id: %s", camera_id)); if(camera_id.equals("0")) {
mCameraScreenMap.put(camera_id, 0); openCamera(camera_id); }
if(!mCameraScreenMap.containsKey(camera_id)) {
for (Map.Entry, MultiScreen> entry : mMultiScreenMap.entrySet()) {
int display_id = entry.getKey(); if(!mCameraScreenMap.containsValue(display_id)) {
mCameraScreenMap.put(camera_id, display_id); mMultiScreenMap.get(display_id).openCamera(camera_id); }
}
}
}
} catch (CameraAccessException e) {
e.printStackTrace(); }
}

public void openCamera(String camera_id) {
Log.d(LOG_TAG, String.format("openCamera camera_id: %s", camera_id)); try {
CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(camera_id); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); Size size[] = map.getOutputSizes(SurfaceTexture.class); for(int index = 0; index < size.length; ++index) {
Log.d(LOG_TAG, "index: " + index + ", size: " + size[index].getWidth() + "x" + size[index].getHeight()); }
mImageDimension = map.getOutputSizes(SurfaceTexture.class)[0]; Log.d(LOG_TAG, String.format("Image dimension width: %d, height: %d", mImageDimension.getWidth(), mImageDimension.getHeight())); // Add permission for camera and let user grant the permission if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CAMERA_PERMISSION); return; }
mCameraManager.openCamera(camera_id, mStateCallback, null);
} catch (CameraAccessException e) {
e.printStackTrace(); }
}

private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
@Override public void onOpened(CameraDevice camera) {
//This is called when the camera is open Log.d(LOG_TAG, "onOpened id: " + camera.getId()); mCameraDevice = camera; createCameraPreview(); }
@Override public void onDisconnected(CameraDevice camera) {
Log.d(LOG_TAG, "onDisconnected id: " + camera.getId()); if(mCameraDevice != null) {
mCameraDevice.close(); }
}
@Override public void onError(CameraDevice camera, int error) {
Log.d(LOG_TAG, "onError id: " + camera.getId() + " error: " + error); if(mCameraDevice != null) {
mCameraDevice.close(); }
}
};
private void createCameraPreview() {
Log.d(LOG_TAG, "createCameraPreview"); try {
SurfaceTexture texture = mCameraTextureView.getSurfaceTexture(); texture.setDefaultBufferSize(mImageDimension.getWidth(), mImageDimension.getHeight()); Surface surface = new Surface(texture); mCaptureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); mCaptureRequestBuilder.addTarget(surface); mCameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback(){
@Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
//The camera is already closed if (null == mCameraDevice) {
return; }
mCameraCaptureSession = cameraCaptureSession; mCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); updatePreview(); }
@Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
Toast.makeText(mContext, "Configuration change", Toast.LENGTH_SHORT).show(); }
}, null); } catch (CameraAccessException e) {
e.printStackTrace(); }
}

protected void updatePreview() {
Log.d(LOG_TAG, String.format("updatePreview")); try {
if(mCameraCaptureSession != null) {
mCameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(), null, mBackgroundHandler); }
else {
Log.d(LOG_TAG, "No camera capture session"); }
} catch (CameraAccessException e) {
e.printStackTrace(); }
}

private void closeCamera() {
if(mCameraDevice != null) {
mCameraDevice.close(); }
}

private void startBackgroundThread() {
Log.d(LOG_TAG, "startBackgroundThread"); mBackgroundThread = new HandlerThread("Camera Background"); mBackgroundThread.start(); mBackgroundHandler = new Handler(mBackgroundThread.getLooper()); }

public void readxml()throws IOException{
Log.d(LOG_TAG, "[KH]enterning readxml"); File f = new File("/sdcard/Download/cam_setting.xml"); if (f.exists()){
Log.d(LOG_TAG, "[KH]xml setting file is exist"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); System.out.println(dbf.getClass().getName()); try {
DocumentBuilder db=dbf.newDocumentBuilder(); doc=db.parse(new File("/sdcard/Download/cam_setting.xml")); nlist=doc.getElementsByTagName("cam_configs"); int len=nlist.getLength(); for(int i=0;i;i++)
{
Element eltPer=(Element)nlist.item(i); Node elleftPillar_left = eltPer.getElementsByTagName("leftPillar_left").item(0); Node elleftPillar_top = eltPer.getElementsByTagName("leftPillar_top").item(0); Node elleftPillar_right = eltPer.getElementsByTagName("leftPillar_right").item(0); Node elleftPillar_bottom = eltPer.getElementsByTagName("leftPillar_bottom").item(0); Node elleftPillar_radius = eltPer.getElementsByTagName("leftPillar_radius").item(0); Node elleftPillar_degree = eltPer.getElementsByTagName("leftPillar_degree").item(0); Node elleftPillar_translationX = eltPer.getElementsByTagName("leftPillar_translationX").item(0); Node elleftPillar_translationY = eltPer.getElementsByTagName("leftPillar_translationY").item(0); Node elleftPillar_scaleX = eltPer.getElementsByTagName("leftPillar_scaleX").item(0); Node elleftPillar_scaleY = eltPer.getElementsByTagName("leftPillar_scaleY").item(0);
Node elrightPillar_left = eltPer.getElementsByTagName("rightPillar_left").item(0); Node elrightPillar_top = eltPer.getElementsByTagName("rightPillar_top").item(0); Node elrightPillar_right = eltPer.getElementsByTagName("rightPillar_right").item(0); Node elrightPillar_bottom = eltPer.getElementsByTagName("rightPillar_bottom").item(0); Node elrightPillar_radius = eltPer.getElementsByTagName("rightPillar_radius").item(0); Node elrightPillar_degree = eltPer.getElementsByTagName("rightPillar_degree").item(0); Node elrightPillar_translationX = eltPer.getElementsByTagName("rightPillar_translationX").item(0); Node elrightPillar_translationY = eltPer.getElementsByTagName("rightPillar_translationY").item(0); Node elrightPillar_scaleX = eltPer.getElementsByTagName("rightPillar_scaleX").item(0); Node elrightPillar_scaleY = eltPer.getElementsByTagName("rightPillar_scaleY").item(0);
leftPillar_left = Integer.valueOf(elleftPillar_left.getFirstChild().getNodeValue()).intValue(); leftPillar_top = Integer.valueOf(elleftPillar_top.getFirstChild().getNodeValue()).intValue(); leftPillar_right = Integer.valueOf(elleftPillar_right.getFirstChild().getNodeValue()).intValue(); leftPillar_bottom = Integer.valueOf(elleftPillar_bottom.getFirstChild().getNodeValue()).intValue(); leftPillar_radius = Integer.valueOf(elleftPillar_radius.getFirstChild().getNodeValue()).intValue(); leftPillar_degree = Integer.valueOf(elleftPillar_degree.getFirstChild().getNodeValue()).intValue(); leftPillar_translationX = Integer.valueOf(elleftPillar_translationX.getFirstChild().getNodeValue()).intValue(); leftPillar_translationY = Integer.valueOf(elleftPillar_translationY.getFirstChild().getNodeValue()).intValue(); leftPillar_scaleX = Float.valueOf(elleftPillar_scaleX.getFirstChild().getNodeValue()).floatValue(); leftPillar_scaleY = Float.valueOf(elleftPillar_scaleY.getFirstChild().getNodeValue()).floatValue();
rightPillar_left = Integer.valueOf(elrightPillar_left.getFirstChild().getNodeValue()).intValue(); rightPillar_top = Integer.valueOf(elrightPillar_top.getFirstChild().getNodeValue()).intValue(); rightPillar_right = Integer.valueOf(elrightPillar_right.getFirstChild().getNodeValue()).intValue(); rightPillar_bottom = Integer.valueOf(elrightPillar_bottom.getFirstChild().getNodeValue()).intValue(); rightPillar_radius = Integer.valueOf(elrightPillar_radius.getFirstChild().getNodeValue()).intValue(); rightPillar_degree = Integer.valueOf(elrightPillar_degree.getFirstChild().getNodeValue()).intValue(); rightPillar_translationX = Integer.valueOf(elrightPillar_translationX.getFirstChild().getNodeValue()).intValue(); rightPillar_translationY = Integer.valueOf(elrightPillar_translationY.getFirstChild().getNodeValue()).intValue(); rightPillar_scaleX = Float.valueOf(elrightPillar_scaleX.getFirstChild().getNodeValue()).floatValue(); rightPillar_scaleY = Float.valueOf(elrightPillar_scaleY.getFirstChild().getNodeValue()).floatValue(); Log.d(LOG_TAG, "leftPillar_left = " + leftPillar_left + ",leftPillar_top = " + leftPillar_top + ",leftPillar_right = " + leftPillar_right +
",leftPillar_bottom = " + leftPillar_bottom + ",leftPillar_radius = " + leftPillar_radius + ",leftPillar_degree = " + leftPillar_degree +
",leftPillar_translationX = " + leftPillar_translationX + ",leftPillar_translationY = " + leftPillar_translationY +
",leftPillar_scaleX = " + leftPillar_scaleX + ", leftPillar_scaleY = " + leftPillar_scaleY +
",rightPillar_left = " + rightPillar_left + ",rightPillar_top = " + rightPillar_top + ",rightPillar_right = " + rightPillar_right +
",rightPillar_bottom = " + rightPillar_bottom + ",rightPillar_radius = " + rightPillar_radius + ",rightPillar_degree = " + rightPillar_degree +
",rightPillar_translationX = " + rightPillar_translationX + ",rightPillar_translationY = " + rightPillar_translationY +
",rightPillar_scaleX = " + rightPillar_scaleX + ",rightPillar_scaleY = " + rightPillar_scaleY); }
} catch (Exception e) {
Log.e(LOG_TAG, "file load exception " + e); }
}else{
Log.d(LOG_TAG, "The xml file is not exist"); leftPillar_left = 0; leftPillar_top = 120; leftPillar_right = 1600; leftPillar_bottom = 780; leftPillar_radius = 0; leftPillar_degree = -20; leftPillar_translationX = -500; leftPillar_translationY = -500; leftPillar_scaleX = 1.0f; leftPillar_scaleY = 1.0f; rightPillar_left = 0; rightPillar_top = 120; rightPillar_right = 1600; rightPillar_bottom = 780; rightPillar_radius = 0; rightPillar_degree = -20; rightPillar_translationX = -500; rightPillar_translationY = -500; rightPillar_scaleX = 1.0f; rightPillar_scaleY = 1.0f; }
}

private void stopBackgroundThread() {
Log.d(LOG_TAG, "stopBackgroundThread"); mBackgroundThread.quitSafely(); try {
mBackgroundThread.join(); mBackgroundThread = null; mBackgroundHandler = null; } catch (InterruptedException e) {
e.printStackTrace(); }
}

private final class MsgHandler extends Handler
{
@Override public void handleMessage(Message msg)
{
Log.d(LOG_TAG, "handler message = " + msg.what);
switch (msg.what) {
case MESG_UPDATE_DISPLAY:
Log.d(LOG_TAG, "MESG_UPDATE_DISPLAY"); updateDisplay(); break; case MESG_SHOW_ALL_SCRENN:
Log.d(LOG_TAG, "MESG_SHOW_ALL_SCRENN"); for (Display display : mDisplays) {
// Log.d(LOG_TAG, "" + display); showScreen(display); }
break; case MESG_SHOW_SCRENN:
Log.d(LOG_TAG, "MESG_SHOW_SCRENN"); for (Display display : mDisplays) {
//Log.d(LOG_TAG, "" + display); if(display.getDisplayId() == msg.arg1) {
showScreen(display); break; }
}
break; case MESG_HIDE_SCRENN:
Log.d(LOG_TAG, "MESG_HIDE_SCRENN"); hideScreen(msg.arg1); break; case MESG_HIDE_ALL_SCRENN:
Log.d(LOG_TAG, "MESG_HIDE_ALL_SCRENN"); for (Display display : mDisplays) {
// Log.d(LOG_TAG, "" + display); hideScreen(display.getDisplayId()); }
break; case MESG_SCAN_CAMERA:
Log.d(LOG_TAG, "MESG_SCAN_CAMERA"); scanCamera(); break; default:
Log.d(LOG_TAG, "unknown message header " + msg.what); break; }
}
}
}

沒有留言:

張貼留言