Search in sources :

Example 1 with OrientationEventListener

use of android.view.OrientationEventListener in project GSYVideoPlayer by CarGuo.

the class OrientationUtils method init.

private void init() {
    orientationEventListener = new OrientationEventListener(activity) {

        @Override
        public void onOrientationChanged(int rotation) {
            boolean autoRotateOn = (android.provider.Settings.System.getInt(activity.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1);
            if (!autoRotateOn) {
                if (mIsLand == 0) {
                    return;
                }
            }
            // 设置竖屏
            if (((rotation >= 0) && (rotation <= 30)) || (rotation >= 330)) {
                if (mClick) {
                    if (mIsLand > 0 && !mClickLand) {
                        return;
                    } else {
                        mClickPort = true;
                        mClick = false;
                        mIsLand = 0;
                    }
                } else {
                    if (mIsLand > 0) {
                        screenType = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                        if (gsyVideoPlayer.isIfCurrentIsFullscreen()) {
                            gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getShrinkImageRes());
                        } else {
                            gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getEnlargeImageRes());
                        }
                        mIsLand = 0;
                        mClick = false;
                    }
                }
            } else // 设置横屏
            if (((rotation >= 230) && (rotation <= 310))) {
                if (mClick) {
                    if (!(mIsLand == 1) && !mClickPort) {
                        return;
                    } else {
                        mClickLand = true;
                        mClick = false;
                        mIsLand = 1;
                    }
                } else {
                    if (!(mIsLand == 1)) {
                        screenType = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                        gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getShrinkImageRes());
                        mIsLand = 1;
                        mClick = false;
                    }
                }
            } else // 设置反向横屏
            if (rotation > 30 && rotation < 95) {
                if (mClick) {
                    if (!(mIsLand == 2) && !mClickPort) {
                        return;
                    } else {
                        mClickLand = true;
                        mClick = false;
                        mIsLand = 2;
                    }
                } else if (!(mIsLand == 2)) {
                    screenType = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                    gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getShrinkImageRes());
                    mIsLand = 2;
                    mClick = false;
                }
            }
        }
    };
    orientationEventListener.enable();
}
Also used : OrientationEventListener(android.view.OrientationEventListener)

Example 2 with OrientationEventListener

use of android.view.OrientationEventListener in project iterable-android-sdk by Iterable.

the class IterableWebViewClient method onStart.

/**
 * Sets up the webview and the dialog layout
 */
@Override
protected void onStart() {
    super.onStart();
    this.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    webView = new IterableWebView(context);
    webView.createWithHtml(this, htmlString);
    webView.addJavascriptInterface(this, JAVASCRIPT_INTERFACE);
    if (orientationListener == null) {
        orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {

            public void onOrientationChanged(int orientation) {
                // Resize the webview on device rotation
                if (loaded) {
                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            webView.loadUrl(IterableWebViewClient.resizeScript);
                        }
                    }, 1000);
                }
            }
        };
    }
    orientationListener.enable();
    RelativeLayout relativeLayout = new RelativeLayout(this.getContext());
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    relativeLayout.addView(webView, layoutParams);
    setContentView(relativeLayout, layoutParams);
    IterableApi.sharedInstance.trackInAppOpen(messageId);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) OrientationEventListener(android.view.OrientationEventListener) RelativeLayout(android.widget.RelativeLayout) Handler(android.os.Handler) Point(android.graphics.Point)

Example 3 with OrientationEventListener

use of android.view.OrientationEventListener in project OpenCamera by ageback.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    long debug_time = 0;
    if (MyDebug.LOG) {
        Log.d(TAG, "onCreate: " + this);
        debug_time = System.currentTimeMillis();
    }
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        // don't show orientation animations
        WindowManager.LayoutParams layout = getWindow().getAttributes();
        layout.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
        getWindow().setAttributes(layout);
    }
    setContentView(R.layout.activity_main);
    // initialise any unset preferences to their default values
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting default preference values: " + (System.currentTimeMillis() - debug_time));
    if (getIntent() != null && getIntent().getExtras() != null) {
        // whether called from testing
        is_test = getIntent().getExtras().getBoolean("test_project");
        if (MyDebug.LOG)
            Log.d(TAG, "is_test: " + is_test);
    }
    if (getIntent() != null && getIntent().getExtras() != null) {
        // whether called from Take Photo widget
        if (MyDebug.LOG)
            Log.d(TAG, "take_photo?: " + getIntent().getExtras().getBoolean(TakePhoto.TAKE_PHOTO));
    }
    if (getIntent() != null && getIntent().getAction() != null) {
        // invoked via the manifest shortcut?
        if (MyDebug.LOG)
            Log.d(TAG, "shortcut: " + getIntent().getAction());
    }
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    // determine whether we should support "auto stabilise" feature
    // risk of running out of memory on lower end devices, due to manipulation of large bitmaps
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    if (MyDebug.LOG) {
        Log.d(TAG, "standard max memory = " + activityManager.getMemoryClass() + "MB");
        Log.d(TAG, "large max memory = " + activityManager.getLargeMemoryClass() + "MB");
    }
    large_heap_memory = activityManager.getLargeMemoryClass();
    if (large_heap_memory >= 128) {
        supports_auto_stabilise = true;
    }
    if (MyDebug.LOG)
        Log.d(TAG, "supports_auto_stabilise? " + supports_auto_stabilise);
    // also added the check for having 128MB standard heap, to support modded LG G2, which has 128MB standard, 256MB large - see https://sourceforge.net/p/opencamera/tickets/9/
    if (activityManager.getMemoryClass() >= 128 || activityManager.getLargeMemoryClass() >= 512) {
        supports_force_video_4k = true;
    }
    if (MyDebug.LOG)
        Log.d(TAG, "supports_force_video_4k? " + supports_force_video_4k);
    // set up components
    mainUI = new MainUI(this);
    applicationInterface = new MyApplicationInterface(this, savedInstanceState);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating application interface: " + (System.currentTimeMillis() - debug_time));
    textFormatter = new TextFormatter(this);
    // determine whether we support Camera2 API
    initCamera2Support();
    // set up window flags for normal operation
    setWindowFlagsForCamera();
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting window flags: " + (System.currentTimeMillis() - debug_time));
    save_location_history = new SaveLocationHistory(this, "save_location_history", getStorageUtils().getSaveLocation());
    if (applicationInterface.getStorageUtils().isUsingSAF()) {
        if (MyDebug.LOG)
            Log.d(TAG, "create new SaveLocationHistory for SAF");
        save_location_history_saf = new SaveLocationHistory(this, "save_location_history_saf", getStorageUtils().getSaveLocationSAF());
    }
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after updating folder history: " + (System.currentTimeMillis() - debug_time));
    // set up sensors
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    // accelerometer sensor (for device orientation)
    if (mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
        if (MyDebug.LOG)
            Log.d(TAG, "found accelerometer");
        mSensorAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    } else {
        if (MyDebug.LOG)
            Log.d(TAG, "no support for accelerometer");
    }
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating accelerometer sensor: " + (System.currentTimeMillis() - debug_time));
    // magnetic sensor (for compass direction)
    if (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null) {
        if (MyDebug.LOG)
            Log.d(TAG, "found magnetic sensor");
        mSensorMagnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    } else {
        if (MyDebug.LOG)
            Log.d(TAG, "no support for magnetic sensor");
    }
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating magnetic sensor: " + (System.currentTimeMillis() - debug_time));
    // clear any seek bars (just in case??)
    mainUI.clearSeekBar();
    // set up the camera and its preview
    preview = new Preview(applicationInterface, ((ViewGroup) this.findViewById(R.id.preview)));
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating preview: " + (System.currentTimeMillis() - debug_time));
    // initialise on-screen button visibility
    View switchCameraButton = findViewById(R.id.switch_camera);
    switchCameraButton.setVisibility(preview.getCameraControllerManager().getNumberOfCameras() > 1 ? View.VISIBLE : View.GONE);
    View speechRecognizerButton = findViewById(R.id.audio_control);
    // disabled by default, until the speech recognizer is created
    speechRecognizerButton.setVisibility(View.GONE);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting button visibility: " + (System.currentTimeMillis() - debug_time));
    View pauseVideoButton = findViewById(R.id.pause_video);
    pauseVideoButton.setVisibility(View.GONE);
    View takePhotoVideoButton = findViewById(R.id.take_photo_when_video_recording);
    takePhotoVideoButton.setVisibility(View.GONE);
    // We initialise optional controls to invisible/gone, so they don't show while the camera is opening - the actual visibility is
    // set in cameraSetup().
    // Note that ideally we'd set this in the xml, but doing so for R.id.zoom causes a crash on Galaxy Nexus startup beneath
    // setContentView()!
    // To be safe, we also do so for take_photo and zoom_seekbar (we already know we've had no reported crashes for focus_seekbar,
    // however).
    View takePhotoButton = findViewById(R.id.take_photo);
    takePhotoButton.setVisibility(View.INVISIBLE);
    View zoomControls = findViewById(R.id.zoom);
    zoomControls.setVisibility(View.GONE);
    View zoomSeekbar = findViewById(R.id.zoom_seekbar);
    zoomSeekbar.setVisibility(View.INVISIBLE);
    // listen for orientation event change
    orientationEventListener = new OrientationEventListener(this) {

        @Override
        public void onOrientationChanged(int orientation) {
            MainActivity.this.mainUI.onOrientationChanged(orientation);
        }
    };
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting orientation event listener: " + (System.currentTimeMillis() - debug_time));
    // set up gallery button long click
    View galleryButton = findViewById(R.id.gallery);
    galleryButton.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // preview.showToast(null, "Long click");
            longClickedGallery();
            return true;
        }
    });
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting gallery long click listener: " + (System.currentTimeMillis() - debug_time));
    // listen for gestures
    gestureDetector = new GestureDetector(this, new MyGestureDetector());
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after creating gesture detector: " + (System.currentTimeMillis() - debug_time));
    // set up listener to handle immersive mode options
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
            if (!usingKitKatImmersiveMode())
                return;
            if (MyDebug.LOG)
                Log.d(TAG, "onSystemUiVisibilityChange: " + visibility);
            if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                if (MyDebug.LOG)
                    Log.d(TAG, "system bars now visible");
                // The system bars are visible. Make any desired
                // adjustments to your UI, such as showing the action bar or
                // other navigational controls.
                mainUI.setImmersiveMode(false);
                setImmersiveTimer();
            } else {
                if (MyDebug.LOG)
                    Log.d(TAG, "system bars now NOT visible");
                // The system bars are NOT visible. Make any desired
                // adjustments to your UI, such as hiding the action bar or
                // other navigational controls.
                mainUI.setImmersiveMode(true);
            }
        }
    });
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after setting immersive mode listener: " + (System.currentTimeMillis() - debug_time));
    // show "about" dialog for first time use; also set some per-device defaults
    boolean has_done_first_time = sharedPreferences.contains(PreferenceKeys.FirstTimePreferenceKey);
    if (MyDebug.LOG)
        Log.d(TAG, "has_done_first_time: " + has_done_first_time);
    if (!has_done_first_time) {
        setDeviceDefaults();
    }
    if (!has_done_first_time) {
        if (!is_test) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
            alertDialog.setTitle(R.string.app_name);
            alertDialog.setMessage(R.string.intro_text);
            alertDialog.setPositiveButton(android.R.string.ok, null);
            alertDialog.setNegativeButton(R.string.preference_online_help, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "online help");
                    launchOnlineHelp();
                }
            });
            alertDialog.show();
        }
        setFirstTimeFlag();
    }
    {
        // handle What's New dialog
        int version_code = -1;
        try {
            PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            version_code = pInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            if (MyDebug.LOG)
                Log.d(TAG, "NameNotFoundException exception trying to get version number");
            e.printStackTrace();
        }
        if (version_code != -1) {
            int latest_version = sharedPreferences.getInt(PreferenceKeys.LatestVersionPreferenceKey, 0);
            if (MyDebug.LOG) {
                Log.d(TAG, "version_code: " + version_code);
                Log.d(TAG, "latest_version: " + latest_version);
            }
            final boolean whats_new_enabled = false;
            if (whats_new_enabled) {
                final boolean force_whats_new = false;
                // don't show What's New if this is the first time the user has run
                if (has_done_first_time && (force_whats_new || version_code > latest_version)) {
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
                    alertDialog.setTitle(R.string.whats_new);
                    alertDialog.setMessage(R.string.whats_new_text);
                    alertDialog.setPositiveButton(android.R.string.ok, null);
                    alertDialog.setNegativeButton(R.string.donate, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (MyDebug.LOG)
                                Log.d(TAG, "donate");
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(MainActivity.getDonateLink()));
                            startActivity(browserIntent);
                        }
                    });
                    alertDialog.show();
                }
            }
            // we set the latest_version whether or not the dialog is shown - if we showed the irst time dialog, we don't
            // want to then show the What's New dialog next time we run!
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putInt(PreferenceKeys.LatestVersionPreferenceKey, version_code);
            editor.apply();
        }
    }
    setModeFromIntents(savedInstanceState);
    // load icons
    preloadIcons(R.array.flash_icons);
    preloadIcons(R.array.focus_mode_icons);
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: time after preloading icons: " + (System.currentTimeMillis() - debug_time));
    // initialise text to speech engine
    textToSpeechSuccess = false;
    // run in separate thread so as to not delay startup time
    new Thread(new Runnable() {

        public void run() {
            textToSpeech = new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {

                @Override
                public void onInit(int status) {
                    if (MyDebug.LOG)
                        Log.d(TAG, "TextToSpeech initialised");
                    if (status == TextToSpeech.SUCCESS) {
                        textToSpeechSuccess = true;
                        if (MyDebug.LOG)
                            Log.d(TAG, "TextToSpeech succeeded");
                    } else {
                        if (MyDebug.LOG)
                            Log.d(TAG, "TextToSpeech failed");
                    }
                }
            });
        }
    }).start();
    if (MyDebug.LOG)
        Log.d(TAG, "onCreate: total time for Activity startup: " + (System.currentTimeMillis() - debug_time));
}
Also used : MainUI(net.sourceforge.opencamera.UI.MainUI) AlertDialog(android.app.AlertDialog) OrientationEventListener(android.view.OrientationEventListener) DialogInterface(android.content.DialogInterface) GestureDetector(android.view.GestureDetector) ActivityManager(android.app.ActivityManager) TextToSpeech(android.speech.tts.TextToSpeech) WindowManager(android.view.WindowManager) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo) Preview(net.sourceforge.opencamera.Preview.Preview) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 4 with OrientationEventListener

use of android.view.OrientationEventListener in project OpenCamera by ageback.

the class Preview method cameraOpened.

/**
 * Called from UI thread after openCameraCore() completes on the background thread.
 */
private void cameraOpened() {
    long debug_time = 0;
    if (MyDebug.LOG) {
        Log.d(TAG, "cameraOpened()");
        debug_time = System.currentTimeMillis();
    }
    boolean take_photo = false;
    if (camera_controller != null) {
        Activity activity = (Activity) Preview.this.getContext();
        if (MyDebug.LOG)
            Log.d(TAG, "intent: " + activity.getIntent());
        if (activity.getIntent() != null && activity.getIntent().getExtras() != null) {
            take_photo = activity.getIntent().getExtras().getBoolean(TakePhoto.TAKE_PHOTO);
            activity.getIntent().removeExtra(TakePhoto.TAKE_PHOTO);
        } else {
            if (MyDebug.LOG)
                Log.d(TAG, "no intent data");
        }
        if (MyDebug.LOG)
            Log.d(TAG, "take_photo?: " + take_photo);
        setCameraDisplayOrientation();
        new OrientationEventListener(activity) {

            @Override
            public void onOrientationChanged(int orientation) {
                Preview.this.onOrientationChanged(orientation);
            }
        }.enable();
        if (MyDebug.LOG) {
            Log.d(TAG, "openCamera: time after setting orientation: " + (System.currentTimeMillis() - debug_time));
        }
        if (MyDebug.LOG)
            Log.d(TAG, "call setPreviewDisplay");
        cameraSurface.setPreviewDisplay(camera_controller);
        if (MyDebug.LOG) {
            Log.d(TAG, "openCamera: time after setting preview display: " + (System.currentTimeMillis() - debug_time));
        }
        setupCamera(take_photo);
        if (this.using_android_l) {
            configureTransform();
        }
    }
    if (MyDebug.LOG) {
        Log.d(TAG, "openCamera: total time for cameraOpened: " + (System.currentTimeMillis() - debug_time));
    }
}
Also used : OrientationEventListener(android.view.OrientationEventListener) Activity(android.app.Activity) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 5 with OrientationEventListener

use of android.view.OrientationEventListener in project GwellDemo by dxsdyhm.

the class MonitoerActivity method initData.

private void initData() {
    // 此处是一种并不常见的横竖屏监听,客户可自行修改实现
    mOrientationEventListener = new OrientationEventListener(this) {

        @Override
        public void onOrientationChanged(int rotation) {
            // 设置横屏
            if (((rotation >= 0) && (rotation <= 30)) || (rotation >= 330)) {
                if (mIsLand) {
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    mIsLand = false;
                    setHalfScreen(true);
                }
            } else if (((rotation >= 230) && (rotation <= 310))) {
                if (!mIsLand) {
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                    mIsLand = true;
                    setHalfScreen(false);
                }
            }
        }
    };
    mOrientationEventListener.enable();
}
Also used : OrientationEventListener(android.view.OrientationEventListener)

Aggregations

OrientationEventListener (android.view.OrientationEventListener)6 Point (android.graphics.Point)2 WindowManager (android.view.WindowManager)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageInfo (android.content.pm.PackageInfo)1 Paint (android.graphics.Paint)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Handler (android.os.Handler)1 RecognizerIntent (android.speech.RecognizerIntent)1 TextToSpeech (android.speech.tts.TextToSpeech)1 GestureDetector (android.view.GestureDetector)1 View (android.view.View)1 RelativeLayout (android.widget.RelativeLayout)1 Preview (net.sourceforge.opencamera.Preview.Preview)1