List of usage examples for android.view SurfaceHolder addCallback
public void addCallback(Callback callback);
From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // historyManager must be initialized here to update the history preference // historyManager = new HistoryManager(this); // historyManager.trimHistory(); // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't // want to open the camera driver and measure the screen size if we're going to show the help on // first launch. That led to bugs where the scanning rectangle was the wrong size and partially // off screen. cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); resultView = findViewById(R.id.result_view); statusView = (TextView) findViewById(R.id.status_view); handler = null;// ww w .jav a 2 s. c om lastResult = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) { //setRequestedOrientation(getCurrentOrientation()); } else { //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } resetStatusView(); beepManager.updatePrefs(); ambientLightManager.start(cameraManager); inactivityTimer.onResume(); Intent intent = getIntent(); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; sourceUrl = null; scanFromWebPageManager = null; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { // Scan the formats the intent requested, and return the result to the calling activity. source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); decodeHints = DecodeHintManager.parseDecodeHints(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } if (intent.hasExtra(Intents.Scan.CAMERA_ID)) { int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1); if (cameraId >= 0) { cameraManager.setManualCameraId(cameraId); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { statusView.setText(customPromptMessage); } } else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) { // Scan only products and send the result to mobile Product Search. source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { // Scan formats requested in query string (all formats if none specified). // If a return URL is specified, send the results there. Otherwise, handle it ourselves. source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(dataString); scanFromWebPageManager = new ScanFromWebPageManager(inputUri); decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); // Allow a sub-set of the hints to be specified by the caller. decodeHints = DecodeHintManager.parseDecodeHints(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the camera. surfaceHolder.addCallback(this); } }
From source file:com.honglang.zxing.CaptureActivity.java
private void resetCamera() { // resetStatusView(); handler = null;// w w w .ja v a2s . co m lastResult = null; resetStatusView(); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still // exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the // camera. surfaceHolder.addCallback(CaptureActivity.this); } beepManager.updatePrefs(); ambientLightManager.start(cameraManager); inactivityTimer.onResume(); }
From source file:com.honglang.zxing.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // CameraManager must be initialized here, not in onCreate(). This is // necessary because we don't // want to open the camera driver and measure the screen size if we're // going to show the help on // first launch. That led to bugs where the scanning rectangle was the // wrong size and partially // off screen. cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); // resultView = findViewById(R.id.result_view); statusView = (TextView) findViewById(R.id.status_view); handler = null;// w w w . j av a 2 s . c om lastResult = null; resetStatusView(); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still // exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the // camera. surfaceHolder.addCallback(this); } beepManager.updatePrefs(); ambientLightManager.start(cameraManager); inactivityTimer.onResume(); Intent intent = getIntent(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { // Scan the formats the intent requested, and return the result // to the calling activity. source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); decodeHints = DecodeHintManager.parseDecodeHints(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { statusView.setText(customPromptMessage); } } else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) { // Scan only products and send the result to mobile Product // Search. source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { // Scan formats requested in query string (all formats if none // specified). // If a return URL is specified, send the results there. // Otherwise, handle it ourselves. source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(dataString); // scanFromWebPageManager = new // ScanFromWebPageManager(inputUri); decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); // Allow a sub-set of the hints to be specified by the caller. decodeHints = DecodeHintManager.parseDecodeHints(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } }
From source file:cw.kop.autobackground.settings.WearSettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); View view;// ww w . jav a 2s .c o m if (displayMetrics.widthPixels > displayMetrics.heightPixels) { view = inflater.inflate(R.layout.wear_settings_layout_landscape, container, false); watchContainer = (RelativeLayout) view.findViewById(R.id.watch_face_container); watchContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int height = watchBackground.getHeight(); ViewGroup.LayoutParams watchContainerParams = watchContainer.getLayoutParams(); watchContainerParams.height = height; watchContainerParams.width = height; watchContainer.setLayoutParams(watchContainerParams); watchContainer.setPadding(Math.round(height * 0.278f), Math.round(height * 0.23f), Math.round(height * 0.278f), Math.round(height * 0.33f)); watchContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); redraw(); } }); watchContainer.setOnClickListener(this); watchBackground = (ImageView) view.findViewById(R.id.watch_face_background); watchBackground.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (getView() == null) { return; } ViewGroup.LayoutParams watchContainerParams = watchBackground.getLayoutParams(); watchContainerParams.width = watchBackground.getHeight(); watchBackground.setLayoutParams(watchContainerParams); watchBackground.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } else { view = inflater.inflate(R.layout.wear_settings_layout, container, false); watchContainer = (RelativeLayout) view.findViewById(R.id.watch_face_container); watchContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int width = displayMetrics.widthPixels; ViewGroup.LayoutParams watchContainerParams = watchContainer.getLayoutParams(); watchContainerParams.height = width; watchContainerParams.width = width; watchContainer.setLayoutParams(watchContainerParams); watchContainer.setPadding(Math.round(width * 0.278f), Math.round(width * 0.23f), Math.round(width * 0.278f), Math.round(width * 0.33f)); watchContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); redraw(); } }); watchContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { preferenceList.setVisibility(View.VISIBLE); recyclerView.setAdapter(null); recyclerView.setVisibility(View.GONE); } }); watchBackground = (ImageView) view.findViewById(R.id.watch_face_background); watchBackground.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (getView() == null) { return; } ViewGroup.LayoutParams watchContainerParams = watchBackground.getLayoutParams(); watchContainerParams.height = watchBackground.getWidth(); watchBackground.setLayoutParams(watchContainerParams); watchBackground.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } surfaceView = (SurfaceView) view.findViewById(R.id.surface_view); // surfaceView.setZOrderOnTop(true); surfaceView.setOnClickListener(this); surfaceView.setOnTouchListener(this); SurfaceHolder holder = surfaceView.getHolder(); holder.addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { loadImageFile(); redraw(); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { loadImageFile(); redraw(); } @Override public void surfaceDestroyed(SurfaceHolder holder) { } }); recyclerView = (RecyclerView) view.findViewById(R.id.watch_options_list); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setItemAnimator(new DefaultItemAnimator()); preferenceList = (ListView) view.findViewById(android.R.id.list); Button syncButton = (Button) view.findViewById(R.id.sync_button); syncButton.setText("Sync Settings"); syncButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "syncButton pressed"); syncSettings(); } }); // findPreference("wear_time_type").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // // DialogFactory.ListDialogListener listDialogListener = new DialogFactory.ListDialogListener() { // @Override // public void onItemClick(AdapterView<?> parent, // View view, // int position, // long id) { // // switch (position) { // case 0: // AppSettings.setTimeType(AppSettings.DIGITAL); // recyclerView.setAdapter(null); // preferenceList.setVisibility(View.VISIBLE); // recyclerView.setVisibility(View.GONE); // redraw(); // break; // case 1: // AppSettings.setTimeType(AppSettings.ANALOG); // recyclerView.setAdapter(null); // preferenceList.setVisibility(View.VISIBLE); // recyclerView.setVisibility(View.GONE); // redraw(); // break; // } // dismissDialog(); // } // }; // // DialogFactory.showListDialog(appContext, // "Watch face", // listDialogListener, // R.array.wear_time_types); // return true; // } // }); findPreference("wear_time_adjust").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { DialogFactory.TimeDialogListener listener = new DialogFactory.TimeDialogListener() { @Override public void onTimeSet(TimePicker view, int hour, int minute) { Time time = new Time(); time.setToNow(); long offset = (hour - time.hour) * 3600000 + (minute - time.minute) * 60000; Log.i(TAG, "Time offset set: " + offset); AppSettings.setTimeOffset(offset); this.dismissDialog(); redraw(); } }; DialogFactory.showTimeDialog(appContext, "Enter time", listener, -1, -1); return true; } }); return view; }
From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // CameraManager must be initialized here, not in onCreate(). This is // necessary because we don't // want to open the camera driver and measure the screen size if we're // going to show the help on // first launch. That led to bugs where the scanning rectangle was the // wrong size and partially // off screen. cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); resultView = findViewById(R.id.result_view); statusView = (TextView) findViewById(R.id.status_view); handler = null;//ww w. jav a 2s .co m lastResult = null; resetStatusView(); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still // exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the // camera. surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } beepManager.updatePrefs(); inactivityTimer.onResume(); Intent intent = getIntent(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { // Scan the formats the intent requested, and return the result // to the calling activity. source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { statusView.setText(customPromptMessage); } } else if (dataString != null && dataString.contains(PRODUCT_SEARCH_URL_PREFIX) && dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) { // Scan only products and send the result to mobile Product // Search. source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { // Scan formats requested in query string (all formats if none // specified). // If a return URL is specified, send the results there. // Otherwise, handle it ourselves. source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(sourceUrl); returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM); returnRaw = inputUri.getQueryParameter(RAW_PARAM) != null; decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } }
From source file:com.android.onemedia.playback.LocalRenderer.java
/** * Checks if the holder is ready and either sets up a callback to wait for * it or sets it directly. If/*from w w w . j a va 2 s . c om*/ * * @param holder * @param player * @return */ private boolean isHolderReady(final SurfaceHolder holder, final MediaPlayer player) { mHolder = holder; if (holder != null) { if (holder.getSurface() != null && holder.getSurface().isValid()) { player.setDisplay(holder); return true; } else { Log.w(TAG, "Holder not null, waiting for it to be ready"); // If the holder isn't ready yet add a callback to set the // holder when it's ready. SurfaceHolder.Callback cb = new SurfaceHolder.Callback() { @Override public void surfaceDestroyed(SurfaceHolder arg0) { } @Override public void surfaceCreated(SurfaceHolder arg0) { if (player.equals(mPlayer)) { player.setDisplay(arg0); preparePlayer(player, true); } } @Override public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { } }; mHolderCB = cb; holder.addCallback(cb); return false; } } return true; }
From source file:com.bookkos.bircle.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // cameraManager?????????????(onCreate????????????) cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); // resultView = findViewById(R.id.result_view); handler = null;/*ww w . j a v a 2 s . c o m*/ lastResult = null; registFlag = 0; resetStatusView(); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { initCamera(surfaceHolder); } else { surfaceHolder.addCallback(this); } bircleBeepManager.updatePrefs(); ambientLightManager.start(cameraManager); inactivityTimer.onResume(); Intent intent = getIntent(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); decodeHints = DecodeHintManager.parseDecodeHints(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { } } else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) { source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(dataString); decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); decodeHints = DecodeHintManager.parseDecodeHints(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } }