Search in sources :

Example 41 with SurfaceView

use of android.view.SurfaceView in project summer-android by cn-cerc.

the class FrmScanBarcode method onResume.

@Override
protected void onResume() {
    super.onResume();
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        initCamera(surfaceHolder);
    } else {
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;
    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }
    initBeepSound();
    vibrate = true;
}
Also used : SurfaceHolder(android.view.SurfaceHolder) AudioManager(android.media.AudioManager) SurfaceView(android.view.SurfaceView)

Example 42 with SurfaceView

use of android.view.SurfaceView in project incubator-weex by apache.

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) ResultPoint(com.google.zxing.ResultPoint) Paint(android.graphics.Paint) SurfaceView(android.view.SurfaceView)

Example 43 with SurfaceView

use of android.view.SurfaceView in project vlc-android by GeoffreyMetais.

the class VideoPlayerActivity method onCreate.

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!VLCInstance.testCompatibleCPU(this)) {
        exit(RESULT_CANCELED);
        return;
    }
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    if (!VLCApplication.showTvUi()) {
        mTouchControls = (mSettings.getBoolean("enable_volume_gesture", true) ? TOUCH_FLAG_AUDIO_VOLUME : 0) + (mSettings.getBoolean("enable_brightness_gesture", true) ? TOUCH_FLAG_BRIGHTNESS : 0) + (mSettings.getBoolean("enable_double_tap_seek", true) ? TOUCH_FLAG_SEEK : 0);
    }
    /* Services and miscellaneous */
    mAudioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE);
    mAudioMax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    audioBoostEnabled = mSettings.getBoolean("audio_boost", false);
    mEnableCloneMode = mSettings.getBoolean("enable_clone_mode", false);
    mDisplayManager = new DisplayManager(this, mEnableCloneMode);
    setContentView(mDisplayManager.isPrimary() ? R.layout.player : R.layout.player_remote_control);
    /**
     * initialize Views an their Events
     */
    mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setBackgroundDrawable(null);
    mActionBar.setDisplayShowCustomEnabled(true);
    mActionBar.setCustomView(R.layout.player_action_bar);
    mRootView = findViewById(R.id.player_root);
    mActionBarView = (ViewGroup) mActionBar.getCustomView();
    mTitle = mActionBarView.findViewById(R.id.player_overlay_title);
    if (!AndroidUtil.isJellyBeanOrLater) {
        View v = findViewById(R.id.player_overlay_systime);
        if (v instanceof TextView)
            mSysTime = (TextView) v;
        v = findViewById(R.id.player_overlay_battery);
        if (v instanceof TextView)
            mBattery = (TextView) v;
    }
    mPlaylistToggle = (ImageView) findViewById(R.id.playlist_toggle);
    mPlaylist = (RecyclerView) findViewById(R.id.video_playlist);
    mScreenOrientation = Integer.valueOf(mSettings.getString("screen_orientation", "99"));
    mSurfaceView = (SurfaceView) findViewById(R.id.player_surface);
    mSubtitlesSurfaceView = (SurfaceView) findViewById(R.id.subtitles_surface);
    mSubtitlesSurfaceView.setZOrderMediaOverlay(true);
    mSubtitlesSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    mSurfaceFrame = (FrameLayout) findViewById(R.id.player_surface_frame);
    /* Loading view */
    mLoading = (ImageView) findViewById(R.id.player_overlay_loading);
    dimStatusBar(true);
    mHandler.sendEmptyMessageDelayed(LOADING_ANIMATION, LOADING_ANIMATION_DELAY);
    mSwitchingView = false;
    mAskResume = mSettings.getBoolean("dialog_confirm_resume", false);
    sDisplayRemainingTime = mSettings.getBoolean(KEY_REMAINING_TIME_DISPLAY, false);
    // Clear the resume time, since it is only used for resumes in external
    // videos.
    final SharedPreferences.Editor editor = mSettings.edit();
    editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
    // Also clear the subs list, because it is supposed to be per session
    // only (like desktop VLC). We don't want the custom subtitle files
    // to persist forever with this video.
    editor.putString(PreferencesActivity.VIDEO_SUBTITLE_FILES, null);
    // Paused flag - per session too, like the subs list.
    editor.remove(PreferencesActivity.VIDEO_PAUSED);
    editor.apply();
    final IntentFilter filter = new IntentFilter();
    if (mBattery != null)
        filter.addAction(Intent.ACTION_BATTERY_CHANGED);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    registerReceiver(mReceiver, filter);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    // 100 is the value for screen_orientation_start_lock
    setRequestedOrientation(getScreenOrientation(mScreenOrientation));
    // Extra initialization when no secondary display is detected
    if (mDisplayManager.isPrimary()) {
        // Tips
        if (!BuildConfig.DEBUG && !VLCApplication.showTvUi() && !mSettings.getBoolean(PREF_TIPS_SHOWN, false)) {
            ((ViewStubCompat) findViewById(R.id.player_overlay_tips)).inflate();
            mOverlayTips = findViewById(R.id.overlay_tips_layout);
        }
        // Set margins for TV overscan
        if (VLCApplication.showTvUi()) {
            int hm = getResources().getDimensionPixelSize(R.dimen.tv_overscan_horizontal);
            int vm = getResources().getDimensionPixelSize(R.dimen.tv_overscan_vertical);
            final RelativeLayout uiContainer = (RelativeLayout) findViewById(R.id.player_ui_container);
            final RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) uiContainer.getLayoutParams();
            lp.setMargins(hm, 0, hm, vm);
            uiContainer.setLayoutParams(lp);
            final LinearLayout.LayoutParams titleParams = (LinearLayout.LayoutParams) mTitle.getLayoutParams();
            titleParams.setMargins(0, vm, 0, 0);
            mTitle.setLayoutParams(titleParams);
        }
    }
    getWindowManager().getDefaultDisplay().getMetrics(mScreen);
    mSurfaceYDisplayRange = Math.min(mScreen.widthPixels, mScreen.heightPixels);
    mSurfaceXDisplayRange = Math.max(mScreen.widthPixels, mScreen.heightPixels);
    mCurrentScreenOrientation = getResources().getConfiguration().orientation;
    if (mIsBenchmark) {
        mCurrentSize = SURFACE_FIT_SCREEN;
    } else {
        mCurrentSize = mSettings.getInt(PreferencesActivity.VIDEO_RATIO, SURFACE_BEST_FIT);
    }
    mMedialibrary = VLCApplication.getMLInstance();
    mIsRtl = AndroidUtil.isJellyBeanMR1OrLater && TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}
Also used : IntentFilter(android.content.IntentFilter) LayoutParams(android.view.ViewGroup.LayoutParams) SharedPreferences(android.content.SharedPreferences) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) SurfaceView(android.view.SurfaceView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) ViewStubCompat(android.support.v7.widget.ViewStubCompat) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) TargetApi(android.annotation.TargetApi)

Example 44 with SurfaceView

use of android.view.SurfaceView in project keepass2android by PhilippC.

the class CaptureActivity method onPause.

@Override
protected void onPause() {
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    inactivityTimer.onPause();
    ambientLightManager.stop();
    cameraManager.closeDriver();
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
    super.onPause();
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceView(android.view.SurfaceView)

Example 45 with SurfaceView

use of android.view.SurfaceView in project keepass2android by PhilippC.

the class CaptureActivity method onResume.

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

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