use of android.view.SurfaceView in project android_frameworks_base by ResurrectionRemix.
the class SurfaceHolderTarget method onBindToView.
@Override
public void onBindToView(View view) {
if (view instanceof SurfaceView) {
SurfaceHolder holder = ((SurfaceView) view).getHolder();
if (holder == null) {
throw new RuntimeException("Could not get SurfaceHolder from SurfaceView " + view + "!");
}
setSurfaceHolder(holder);
} else {
throw new IllegalArgumentException("View must be a SurfaceView!");
}
}
use of android.view.SurfaceView in project android_frameworks_base by ResurrectionRemix.
the class SmartCamera method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simplecamera);
setTitle("Smart Camera");
mContext = new MffContext(this);
mCameraView = (SurfaceView) findViewById(R.id.cameraView);
mGoodBadTextView = (TextView) findViewById(R.id.goodOrBadTextView);
mFPSTextView = (TextView) findViewById(R.id.fpsTextView);
mScoreTextView = (TextView) findViewById(R.id.scoreTextView);
mStartStopButton = (Button) findViewById(R.id.startButton);
mImagesSavedTextView = (TextView) findViewById(R.id.imagesSavedTextView);
mImagesSavedTextView.setText("");
mSpinner = (Spinner) findViewById(R.id.spinner);
mLinearLayout = (LinearLayout) findViewById(R.id.scrollViewLinearLayout);
mImages = new ArrayList<ImageView>();
// Spinner is used to determine how many image views are displayed at the bottom
// of the screen. Based on the item position that is selected, we inflate that
// many imageviews into the bottom linear layout.
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
mLinearLayout.removeViews(0, numImages);
numImages = position + 1;
mImages.clear();
LayoutInflater inflater = getLayoutInflater();
for (int i = 0; i < numImages; i++) {
ImageView tmp = (ImageView) inflater.inflate(R.layout.imageview, null);
mImages.add(tmp);
mLinearLayout.addView(tmp);
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
numImages = mSpinner.getSelectedItemPosition() + 1;
mImages.clear();
LayoutInflater inflater = getLayoutInflater();
for (int i = 0; i < numImages; i++) {
ImageView tmp = (ImageView) inflater.inflate(R.layout.imageview, null);
mImages.add(tmp);
mLinearLayout.addView(tmp);
}
// Button used to start and stop the capture of images when they are deemed great
mStartStopButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mStartStopButton.getText().equals("Start")) {
mGraph.getVariable("startCapture").setValue(true);
mStartStopButton.setText("Stop");
mSpinner.setEnabled(false);
} else {
boolean tmp = (Boolean) mGraph.getVariable("startCapture").getValue();
if (tmp == false) {
return;
}
if (count == numImages - 1)
countHasReachedMax = true;
captureImages();
}
}
});
// Button to open the gallery to show the images in there
Button galleryOpen = (Button) findViewById(R.id.galleryOpenButton);
galleryOpen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent openGalleryIntent = new Intent(Intent.ACTION_MAIN);
openGalleryIntent.addCategory(Intent.CATEGORY_APP_GALLERY);
startActivity(openGalleryIntent);
}
});
loadGraph();
mGraph.getVariable("startCapture").setValue(false);
runGraph();
}
use of android.view.SurfaceView in project android_frameworks_base by ResurrectionRemix.
the class HardwareCanvasSurfaceViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout content = new FrameLayout(this);
mSurfaceView = new SurfaceView(this);
mSurfaceView.getHolder().addCallback(this);
Button button = new Button(this);
button.setText("Copy bitmap to /sdcard/surfaceview.png");
button.setOnClickListener((View v) -> {
final Bitmap b = Bitmap.createBitmap(mSurfaceView.getWidth(), mSurfaceView.getHeight(), Bitmap.Config.ARGB_8888);
PixelCopy.request(mSurfaceView, b, (int result) -> {
if (result != PixelCopy.SUCCESS) {
Toast.makeText(HardwareCanvasSurfaceViewActivity.this, "Failed to copy", Toast.LENGTH_SHORT).show();
return;
}
try {
try (FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/surfaceview.png")) {
b.compress(Bitmap.CompressFormat.PNG, 100, out);
}
} catch (Exception e) {
// Ignore
}
}, mSurfaceView.getHandler());
});
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(button, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mSurfaceView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
content.addView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
setContentView(content);
}
use of android.view.SurfaceView in project weex-example by KalicyZhou.
the class CaptureActivity method onPause.
@Override
protected void onPause() {
if (handler != null) {
handler.quitSynchronously();
handler = null;
}
inactivityTimer.onPause();
ambientLightManager.stop();
beepManager.close();
cameraManager.closeDriver();
// historyManager = null; // Keep for onActivityResult
if (!hasSurface) {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.removeCallback(this);
}
super.onPause();
}
use of android.view.SurfaceView in project android_frameworks_base by crdroidandroid.
the class EGLImpl method eglCreateWindowSurface.
public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) {
Surface sur = null;
if (native_window instanceof SurfaceView) {
SurfaceView surfaceView = (SurfaceView) native_window;
sur = surfaceView.getHolder().getSurface();
} else if (native_window instanceof SurfaceHolder) {
SurfaceHolder holder = (SurfaceHolder) native_window;
sur = holder.getSurface();
} else if (native_window instanceof Surface) {
sur = (Surface) native_window;
}
long eglSurfaceId;
if (sur != null) {
eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
} else if (native_window instanceof SurfaceTexture) {
eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, native_window, attrib_list);
} else {
throw new java.lang.UnsupportedOperationException("eglCreateWindowSurface() can only be called with an instance of " + "Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment.");
}
if (eglSurfaceId == 0) {
return EGL10.EGL_NO_SURFACE;
}
return new EGLSurfaceImpl(eglSurfaceId);
}
Aggregations