Example usage for android.content.pm ActivityInfo SCREEN_ORIENTATION_NOSENSOR

List of usage examples for android.content.pm ActivityInfo SCREEN_ORIENTATION_NOSENSOR

Introduction

In this page you can find the example usage for android.content.pm ActivityInfo SCREEN_ORIENTATION_NOSENSOR.

Prototype

int SCREEN_ORIENTATION_NOSENSOR

To view the source code for android.content.pm ActivityInfo SCREEN_ORIENTATION_NOSENSOR.

Click Source Link

Document

Constant corresponding to nosensor in the android.R.attr#screenOrientation attribute.

Usage

From source file:Main.java

/**
 * Locks specified activity's orientation until it is unlocked or recreated.
 *
 * @param activity activity/*from ww  w  .  j a v  a2 s.  c  o m*/
 */
public static void lockOrientation(Activity activity) {
    Configuration config = activity.getResources().getConfiguration();
    final int deviceOrientation = config.orientation;
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();

    int orientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
    if (deviceOrientation == Configuration.ORIENTATION_PORTRAIT) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180)
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    } else if (deviceOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270)
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    }

    activity.setRequestedOrientation(orientation);
}

From source file:de.limexcomputer.cordova.plugin.rotationlock.RotationLock.java

/**
 * Executes the request./*from w  w  w . j  a v a 2s .c om*/
 *
 * This method is called from the WebView thread.
 * To do a non-trivial amount of work, use:
 *     cordova.getThreadPool().execute(runnable);
 *
 * To run on the UI thread, use:
 *     cordova.getActivity().runOnUiThread(runnable);
 *
 * @param action   The action to execute.
 * @param args     The exec() arguments in JSON form.
 * @param callback The callback context used when calling back into JavaScript.
 * @return         Whether the action was valid.
 */
@Override
public boolean execute(String action, JSONArray args, CallbackContext callback) throws JSONException {

    if (!action.equalsIgnoreCase("setOrientation")) {
        return false;
    }

    String orientation = args.optString(0);

    Activity activity = this.cordova.getActivity();

    // refer to https://github.com/their/pg-plugin-screen-orientation/blob/master/src/ScreenOrientation.java

    if (orientation.equals(UNSPECIFIED)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    } else if (orientation.equals(LANDSCAPE)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else if (orientation.equals(PORTRAIT)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else if (orientation.equals(USER)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
    } else if (orientation.equals(BEHIND)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_BEHIND);
    } else if (orientation.equals(SENSOR)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    } else if (orientation.equals(NOSENSOR)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    } else if (orientation.equals(SENSOR_LANDSCAPE)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    } else if (orientation.equals(SENSOR_PORTRAIT)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    } else if (orientation.equals(REVERSE_LANDSCAPE)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
    } else if (orientation.equals(REVERSE_PORTRAIT)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
    } else if (orientation.equals(FULL_SENSOR)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
    }

    callback.success(orientation);
    return true;
}

From source file:org.apache.cordova.screenorientation.ScreenOrientation.java

public int getOrientation(String orientation) {
    if (orientation.equals(UNSPECIFIED)) {
        return (ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    } else if (orientation.equals(LANDSCAPE)) {
        return (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else if (orientation.equals(PORTRAIT)) {
        return (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else if (orientation.equals(USER)) {
        return (ActivityInfo.SCREEN_ORIENTATION_USER);
    } else if (orientation.equals(BEHIND)) {
        return (ActivityInfo.SCREEN_ORIENTATION_BEHIND);
    } else if (orientation.equals(SENSOR)) {
        return (ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    } else if (orientation.equals(NOSENSOR)) {
        return (ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    } else if (orientation.equals(SENSOR_LANDSCAPE)) {
        return (ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    } else if (orientation.equals(SENSOR_PORTRAIT)) {
        return (ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    } else if (orientation.equals(REVERSE_LANDSCAPE)) {
        return (ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
    } else if (orientation.equals(REVERSE_PORTRAIT)) {
        return (ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
    } else if (orientation.equals(FULL_SENSOR)) {
        return (ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
    }//from   ww  w . ja v  a 2  s  . c  o  m

    return (ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}

From source file:org.gluu.super_gluu.app.GluuMainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the view from gluu_activity_main_main.xml
    setContentView(R.layout.gluu_activity_main);
    context = getApplicationContext();//ww w .  ja v  a  2 s. c  o  m

    //Init main tab vie and pager
    initMainTabView();

    LocalBroadcastManager.getInstance(this).registerReceiver(mPushMessageReceiver,
            new IntentFilter(GluuMainActivity.QR_CODE_PUSH_NOTIFICATION));

    // Init network layer
    CommunicationService.init();

    // Init device UUID service
    DeviceUuidManager deviceUuidFactory = new DeviceUuidManager();
    deviceUuidFactory.init(this);

    this.dataStore = new AndroidKeyDataStore(context);
    this.u2f = new SoftwareDevice(this, dataStore);

    checkUserCameraPermission();

    //temporary turn off rotation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

    //Init InAPP-Purchase service
    initIAPurchaseService();
}

From source file:org.gluu.super_gluu.app.activities.MainNavDrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nav_drawer_main);
    ButterKnife.bind(this);
    context = getApplicationContext();//from  w  ww.j  av a 2  s.c  om

    fragmentManager = getSupportFragmentManager();
    setupToolbar();
    initNavDrawer();

    // Init network layer
    CommunicationService.init();

    // Init device UUID service
    DeviceUuidManager deviceUuidFactory = new DeviceUuidManager();
    deviceUuidFactory.init(this);

    this.dataStore = new AndroidKeyDataStore(context);
    this.u2f = new SoftwareDevice(this, dataStore);

    checkUserCameraPermission();

    //temporary turn off rotation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

    //Init InAPP-Purchase service
    initIAPurchaseService();

    setupInterstitialAd();

    setupInitialFragment();
}

From source file:com.stasbar.knowyourself.alarms.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final long instanceId = AlarmInstance.getId(getIntent().getData());
    mAlarmInstance = AlarmInstance.getInstance(getContentResolver(), instanceId);
    if (mAlarmInstance == null) {
        // The alarm was deleted before the activity got created, so just finish()
        LOGGER.e("Error displaying alarm for intent: %s", getIntent());
        finish();// w  ww . j  a v a2  s .c  o m
        return;
    } else if (mAlarmInstance.mAlarmState != AlarmInstance.FIRED_STATE) {
        LOGGER.i("Skip displaying alarm for instance: %s", mAlarmInstance);
        finish();
        return;
    }

    LOGGER.i("Displaying alarm for instance: %s", mAlarmInstance);

    // Get the volume/camera button behavior setting
    mVolumeBehavior = Utils.getDefaultSharedPreferences(this).getString(SettingsActivity.KEY_VOLUME_BUTTONS,
            SettingsActivity.DEFAULT_VOLUME_BEHAVIOR);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

    // Hide navigation bar to minimize accidental tap on Home key
    hideNavigationBar();

    // Close dialogs and window shade, so this is fully visible
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    // Honor rotation on tablets; fix the orientation on phones.
    if (!getResources().getBoolean(R.bool.config_rotateAlarmAlert)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    }

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    setContentView(R.layout.alarm_activity);

    mAlertView = (ViewGroup) findViewById(R.id.alert);
    mAlertTitleView = (TextView) mAlertView.findViewById(R.id.alert_title);
    mAlertInfoView = (TextView) mAlertView.findViewById(R.id.alert_info);

    mContentView = (ViewGroup) findViewById(R.id.content);
    mAlarmButton = (ImageView) mContentView.findViewById(R.id.alarm);
    mSnoozeButton = (ImageView) mContentView.findViewById(R.id.snooze);
    mDismissButton = (ImageView) mContentView.findViewById(R.id.dismiss);
    mHintView = (TextView) mContentView.findViewById(R.id.hint);

    final TextView titleView = (TextView) mContentView.findViewById(R.id.title);
    final TextClock digitalClock = (TextClock) mContentView.findViewById(R.id.digital_clock);
    final CircleView pulseView = (CircleView) mContentView.findViewById(R.id.pulse);

    titleView.setText(mAlarmInstance.getLabelOrDefault(this));
    Utils.setTimeFormat(digitalClock);

    mCurrentHourColor = UiDataModel.getUiDataModel().getWindowBackgroundColor();
    getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));

    mAlarmButton.setOnTouchListener(this);
    mSnoozeButton.setOnClickListener(this);
    mDismissButton.setOnClickListener(this);

    mAlarmAnimator = AnimatorUtils.getScaleAnimator(mAlarmButton, 1.0f, 0.0f);
    mSnoozeAnimator = getButtonAnimator(mSnoozeButton, Color.WHITE);
    mDismissAnimator = getButtonAnimator(mDismissButton, mCurrentHourColor);
    mPulseAnimator = ObjectAnimator.ofPropertyValuesHolder(pulseView,
            PropertyValuesHolder.ofFloat(CircleView.RADIUS, 0.0f, pulseView.getRadius()),
            PropertyValuesHolder.ofObject(CircleView.FILL_COLOR, AnimatorUtils.ARGB_EVALUATOR,
                    ColorUtils.setAlphaComponent(pulseView.getFillColor(), 0)));
    mPulseAnimator.setDuration(PULSE_DURATION_MILLIS);
    mPulseAnimator.setInterpolator(PULSE_INTERPOLATOR);
    mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mPulseAnimator.start();
}

From source file:com.androidinspain.deskclock.alarms.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setVolumeControlStream(AudioManager.STREAM_ALARM);
    final long instanceId = AlarmInstance.getId(getIntent().getData());
    mAlarmInstance = AlarmInstance.getInstance(getContentResolver(), instanceId);
    if (mAlarmInstance == null) {
        // The alarm was deleted before the activity got created, so just finish()
        LOGGER.e("Error displaying alarm for intent: %s", getIntent());
        finish();//from   w w w.  j av a  2 s  .c o m
        return;
    } else if (mAlarmInstance.mAlarmState != AlarmInstance.FIRED_STATE) {
        LOGGER.i("Skip displaying alarm for instance: %s", mAlarmInstance);
        finish();
        return;
    }

    LOGGER.i("Displaying alarm for instance: %s", mAlarmInstance);

    // Get the volume/camera button behavior setting
    mVolumeBehavior = DataModel.getDataModel().getAlarmVolumeButtonBehavior();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

    // Hide navigation bar to minimize accidental tap on Home key
    hideNavigationBar();

    // Close dialogs and window shade, so this is fully visible
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    // Honor rotation on tablets; fix the orientation on phones.
    if (!getResources().getBoolean(com.androidinspain.deskclock.R.bool.rotateAlarmAlert)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    }

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    setContentView(com.androidinspain.deskclock.R.layout.alarm_activity);

    mAlertView = (ViewGroup) findViewById(com.androidinspain.deskclock.R.id.alert);
    mAlertTitleView = (TextView) mAlertView.findViewById(com.androidinspain.deskclock.R.id.alert_title);
    mAlertInfoView = (TextView) mAlertView.findViewById(com.androidinspain.deskclock.R.id.alert_info);

    mContentView = (ViewGroup) findViewById(com.androidinspain.deskclock.R.id.content);
    mAlarmButton = (ImageView) mContentView.findViewById(com.androidinspain.deskclock.R.id.alarm);
    mSnoozeButton = (ImageView) mContentView.findViewById(com.androidinspain.deskclock.R.id.snooze);
    mDismissButton = (ImageView) mContentView.findViewById(com.androidinspain.deskclock.R.id.dismiss);
    mHintView = (TextView) mContentView.findViewById(com.androidinspain.deskclock.R.id.hint);

    final TextView titleView = (TextView) mContentView.findViewById(com.androidinspain.deskclock.R.id.title);
    final TextClock digitalClock = (TextClock) mContentView
            .findViewById(com.androidinspain.deskclock.R.id.digital_clock);
    final CircleView pulseView = (CircleView) mContentView
            .findViewById(com.androidinspain.deskclock.R.id.pulse);

    titleView.setText(mAlarmInstance.getLabelOrDefault(this));
    Utils.setTimeFormat(digitalClock, false);

    mCurrentHourColor = ThemeUtils.resolveColor(this, android.R.attr.windowBackground);
    getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));

    mAlarmButton.setOnTouchListener(this);
    mSnoozeButton.setOnClickListener(this);
    mDismissButton.setOnClickListener(this);

    mAlarmAnimator = AnimatorUtils.getScaleAnimator(mAlarmButton, 1.0f, 0.0f);
    mSnoozeAnimator = getButtonAnimator(mSnoozeButton, Color.WHITE);
    mDismissAnimator = getButtonAnimator(mDismissButton, mCurrentHourColor);
    mPulseAnimator = ObjectAnimator.ofPropertyValuesHolder(pulseView,
            PropertyValuesHolder.ofFloat(CircleView.RADIUS, 0.0f, pulseView.getRadius()),
            PropertyValuesHolder.ofObject(CircleView.FILL_COLOR, AnimatorUtils.ARGB_EVALUATOR,
                    ColorUtils.setAlphaComponent(pulseView.getFillColor(), 0)));
    mPulseAnimator.setDuration(PULSE_DURATION_MILLIS);
    mPulseAnimator.setInterpolator(PULSE_INTERPOLATOR);
    mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mPulseAnimator.start();
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final long instanceId = AlarmInstance.getId(getIntent().getData());
    mAlarmInstance = AlarmInstance.getInstance(getContentResolver(), instanceId);
    if (mAlarmInstance == null) {
        // The alarm was deleted before the activity got created, so just finish()
        LogUtils.e(LOGTAG, "Error displaying alarm for intent: %s", getIntent());
        finish();/*from  w ww. j  a  va  2s  .  c om*/
        return;
    } else if (mAlarmInstance.mAlarmState != AlarmInstance.FIRED_STATE) {
        LogUtils.i(LOGTAG, "Skip displaying alarm for instance: %s", mAlarmInstance);
        finish();
        return;
    }

    LogUtils.i(LOGTAG, "Displaying alarm for instance: %s", mAlarmInstance);

    // Get the volume/camera button behavior setting
    mVolumeBehavior = Utils.getDefaultSharedPreferences(this).getString(SettingsActivity.KEY_VOLUME_BUTTONS,
            SettingsActivity.DEFAULT_VOLUME_BEHAVIOR);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

    // Hide navigation bar to minimize accidental tap on Home key
    hideNavigationBar();

    // Close dialogs and window shade, so this is fully visible
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    // In order to allow tablets to freely rotate and phones to stick
    // with "nosensor" (use default device orientation) we have to have
    // the manifest start with an orientation of unspecified" and only limit
    // to "nosensor" for phones. Otherwise we get behavior like in b/8728671
    // where tablets start off in their default orientation and then are
    // able to freely rotate.
    if (!getResources().getBoolean(R.bool.config_rotateAlarmAlert)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    }

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    setContentView(R.layout.alarm_activity);

    mAlertView = (ViewGroup) findViewById(R.id.alert);
    mAlertTitleView = (TextView) mAlertView.findViewById(R.id.alert_title);
    mAlertInfoView = (TextView) mAlertView.findViewById(R.id.alert_info);

    mContentView = (ViewGroup) findViewById(R.id.content);
    mAlarmButton = (ImageView) mContentView.findViewById(R.id.alarm);
    mSnoozeButton = (ImageView) mContentView.findViewById(R.id.snooze);
    mDismissButton = (ImageView) mContentView.findViewById(R.id.dismiss);
    mHintView = (TextView) mContentView.findViewById(R.id.hint);

    final TextView titleView = (TextView) mContentView.findViewById(R.id.title);
    final TextClock digitalClock = (TextClock) mContentView.findViewById(R.id.digital_clock);
    final CircleView pulseView = (CircleView) mContentView.findViewById(R.id.pulse);

    titleView.setText(mAlarmInstance.getLabelOrDefault(this));
    Utils.setTimeFormat(this, digitalClock);

    mCurrentHourColor = Utils.getCurrentHourColor();
    getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));

    mAlarmButton.setOnTouchListener(this);
    mSnoozeButton.setOnClickListener(this);
    mDismissButton.setOnClickListener(this);

    mAlarmAnimator = AnimatorUtils.getScaleAnimator(mAlarmButton, 1.0f, 0.0f);
    mSnoozeAnimator = getButtonAnimator(mSnoozeButton, Color.WHITE);
    mDismissAnimator = getButtonAnimator(mDismissButton, mCurrentHourColor);
    mPulseAnimator = ObjectAnimator.ofPropertyValuesHolder(pulseView,
            PropertyValuesHolder.ofFloat(CircleView.RADIUS, 0.0f, pulseView.getRadius()),
            PropertyValuesHolder.ofObject(CircleView.FILL_COLOR, AnimatorUtils.ARGB_EVALUATOR,
                    ColorUtils.setAlphaComponent(pulseView.getFillColor(), 0)));
    mPulseAnimator.setDuration(PULSE_DURATION_MILLIS);
    mPulseAnimator.setInterpolator(PULSE_INTERPOLATOR);
    mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mPulseAnimator.start();
}

From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final long instanceId = AlarmInstance.getId(getIntent().getData());
    mAlarmInstance = AlarmInstance.getInstance(getContentResolver(), instanceId);
    if (mAlarmInstance == null) {
        // The alarm was deleted before the activity got created, so just finish()
        LogUtils.e(LOGTAG, "Error displaying alarm for intent: %s", getIntent());
        finish();//  w w w.  j  ava2 s  .  c  om
        return;
    } else if (mAlarmInstance.mAlarmState != AlarmInstance.FIRED_STATE) {
        LogUtils.i(LOGTAG, "Skip displaying alarm for instance: %s", mAlarmInstance);
        finish();
        return;
    }

    LogUtils.i(LOGTAG, "Displaying alarm for instance: %s", mAlarmInstance);

    // Get the volume/camera button behavior setting
    mVolumeBehavior = PreferenceManager.getDefaultSharedPreferences(this)
            .getString(SettingsActivity.KEY_VOLUME_BUTTONS, SettingsActivity.DEFAULT_VOLUME_BEHAVIOR);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

    // Hide navigation bar to minimize accidental tap on Home key
    hideNavigationBar();

    // Close dialogs and window shade, so this is fully visible
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    // In order to allow tablets to freely rotate and phones to stick
    // with "nosensor" (use default device orientation) we have to have
    // the manifest start with an orientation of unspecified" and only limit
    // to "nosensor" for phones. Otherwise we get behavior like in b/8728671
    // where tablets start off in their default orientation and then are
    // able to freely rotate.
    if (!getResources().getBoolean(R.bool.config_rotateAlarmAlert)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    }

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    setContentView(R.layout.alarm_activity);

    mAlertView = (ViewGroup) findViewById(R.id.alert);
    mAlertTitleView = (TextView) mAlertView.findViewById(R.id.alert_title);
    mAlertInfoView = (TextView) mAlertView.findViewById(R.id.alert_info);

    mContentView = (ViewGroup) findViewById(R.id.content);
    mAlarmButton = (ImageView) mContentView.findViewById(R.id.alarm);
    mSnoozeButton = (ImageView) mContentView.findViewById(R.id.snooze);
    mDismissButton = (ImageView) mContentView.findViewById(R.id.dismiss);
    mHintView = (TextView) mContentView.findViewById(R.id.hint);

    final TextView titleView = (TextView) mContentView.findViewById(R.id.title);
    //        final TextClock digitalClock = (TextClock) mContentView.findViewById(R.id.digital_clock);
    final TextTime digitalClock = (TextTime) mContentView.findViewById(R.id.digital_clock);
    final CircleView pulseView = (CircleView) mContentView.findViewById(R.id.pulse);

    titleView.setText(mAlarmInstance.getLabelOrDefault(this));
    Utils.setTimeFormat(this, digitalClock);

    mCurrentHourColor = Utils.getCurrentHourColor();
    getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));

    mAlarmButton.setOnTouchListener(this);
    mSnoozeButton.setOnClickListener(this);
    mDismissButton.setOnClickListener(this);

    mAlarmAnimator = AnimatorUtils.getScaleAnimator(mAlarmButton, 1.0f, 0.0f);
    mSnoozeAnimator = getButtonAnimator(mSnoozeButton, Color.WHITE);
    mDismissAnimator = getButtonAnimator(mDismissButton, mCurrentHourColor);
    mPulseAnimator = ObjectAnimator.ofPropertyValuesHolder(pulseView,
            PropertyValuesHolder.ofFloat(CircleView.RADIUS, 0.0f, pulseView.getRadius()),
            PropertyValuesHolder.ofObject(CircleView.FILL_COLOR, AnimatorUtils.ARGB_EVALUATOR,
                    ColorUtils.setAlphaComponent(pulseView.getFillColor(), 0)));
    mPulseAnimator.setDuration(PULSE_DURATION_MILLIS);
    mPulseAnimator.setInterpolator(PULSE_INTERPOLATOR);
    mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mPulseAnimator.start();
}

From source file:com.BibleQuote.ui.ReaderActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (PreferenceHelper.restoreStateBoolean("DisableAutoScreenRotation")) {
        super.onConfigurationChanged(newConfig);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    } else {//from   w w w  .  j a v a 2  s. co m
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        super.onConfigurationChanged(newConfig);
    }
}