Search in sources :

Example 6 with SurfaceView

use of android.view.SurfaceView in project android_frameworks_base by ResurrectionRemix.

the class GetBitmapSurfaceViewActivity 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(GetBitmapSurfaceViewActivity.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());
    });
    content.addView(mSurfaceView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER));
    content.addView(button, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
    setContentView(content);
}
Also used : Bitmap(android.graphics.Bitmap) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) FileOutputStream(java.io.FileOutputStream) SurfaceView(android.view.SurfaceView) View(android.view.View) SurfaceView(android.view.SurfaceView) IOException(java.io.IOException)

Example 7 with SurfaceView

use of android.view.SurfaceView in project android_frameworks_base by ResurrectionRemix.

the class MffContext method createDummySurfaceView.

@SuppressWarnings("deprecation")
private SurfaceView createDummySurfaceView(Context context) {
    // This is only called on Gingerbread devices, so deprecation warning is unnecessary.
    SurfaceView dummySurfaceView = new SurfaceView(context);
    dummySurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    // If we have an activity for this context we'll add the SurfaceView to it (as a 1x1 view
    // in the top-left corner). If not, we warn the user that they may need to add one manually.
    Activity activity = findActivityForContext(context);
    if (activity != null) {
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(1, 1);
        activity.addContentView(dummySurfaceView, params);
    } else {
        Log.w("MffContext", "Could not find activity for dummy surface! Consider specifying " + "your own SurfaceView!");
    }
    return dummySurfaceView;
}
Also used : ViewGroup(android.view.ViewGroup) Activity(android.app.Activity) SurfaceView(android.view.SurfaceView)

Example 8 with SurfaceView

use of android.view.SurfaceView in project android_frameworks_base by ResurrectionRemix.

the class CameraTooActivity method onResume.

/**
     * Called when our {@code Activity} gains focus. <p>Starts initializing the camera.</p>
     */
@Override
protected void onResume() {
    super.onResume();
    // Start a background thread to manage camera requests
    mBackgroundThread = new HandlerThread("background");
    mBackgroundThread.start();
    mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
    mForegroundHandler = new Handler(getMainLooper());
    mCameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
    // Inflate the SurfaceView, set it as the main layout, and attach a listener
    View layout = getLayoutInflater().inflate(R.layout.mainactivity, null);
    mSurfaceView = (SurfaceView) layout.findViewById(R.id.mainSurfaceView);
    mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback);
    setContentView(mSurfaceView);
// Control flow continues in mSurfaceHolderCallback.surfaceChanged()
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) SurfaceView(android.view.SurfaceView) View(android.view.View)

Example 9 with SurfaceView

use of android.view.SurfaceView in project XobotOS by xamarin.

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();
    }
    int eglSurfaceId;
    if (sur != null) {
        eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
    } else if (native_window instanceof SurfaceTexture) {
        eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, (SurfaceTexture) native_window, attrib_list);
    } else {
        throw new java.lang.UnsupportedOperationException("eglCreateWindowSurface() can only be called with an instance of " + "SurfaceView, SurfaceHolder or SurfaceTexture at the moment, " + "this will be fixed later.");
    }
    if (eglSurfaceId == 0) {
        return EGL10.EGL_NO_SURFACE;
    }
    return new EGLSurfaceImpl(eglSurfaceId);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceTexture(android.graphics.SurfaceTexture) SurfaceView(android.view.SurfaceView) Surface(android.view.Surface)

Example 10 with SurfaceView

use of android.view.SurfaceView in project zxing by zxing.

the class CaptureActivity method onResume.

@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;
    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);
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SharedPreferences(android.content.SharedPreferences) HistoryManager(com.google.zxing.client.android.history.HistoryManager) CameraManager(com.google.zxing.client.android.camera.CameraManager) Intent(android.content.Intent) Uri(android.net.Uri) Paint(android.graphics.Paint) ResultPoint(com.google.zxing.ResultPoint) SurfaceView(android.view.SurfaceView)

Aggregations

SurfaceView (android.view.SurfaceView)137 SurfaceHolder (android.view.SurfaceHolder)65 View (android.view.View)35 SurfaceTexture (android.graphics.SurfaceTexture)18 Intent (android.content.Intent)16 FrameLayout (android.widget.FrameLayout)15 Surface (android.view.Surface)14 Button (android.widget.Button)13 TextView (android.widget.TextView)11 SharedPreferences (android.content.SharedPreferences)10 Bitmap (android.graphics.Bitmap)9 ImageView (android.widget.ImageView)9 IOException (java.io.IOException)9 ViewGroup (android.view.ViewGroup)8 LinearLayout (android.widget.LinearLayout)8 FileOutputStream (java.io.FileOutputStream)8 AudioManager (android.media.AudioManager)7 OnClickListener (android.view.View.OnClickListener)7 CameraManager (com.google.zxing.client.android.camera.CameraManager)7 IntentFilter (android.content.IntentFilter)6