Example usage for android.content.pm ActivityInfo SCREEN_ORIENTATION_LANDSCAPE

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

Introduction

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

Prototype

int SCREEN_ORIENTATION_LANDSCAPE

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

Click Source Link

Document

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

Usage

From source file:org.LK8000.LK8000.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (serviceClass == null)
        serviceClass = MyService.class;

    super.onCreate(savedInstanceState);
    //    Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());

    Fabric fabric = new Fabric.Builder(this).debuggable(true).kits(new Crashlytics(), new CrashlyticsNdk())
            .build();/*w w w .j  ava 2  s. co  m*/

    Fabric.with(fabric);

    Log.d(TAG, "ABI=" + Build.CPU_ABI);
    Log.d(TAG, "PRODUCT=" + Build.PRODUCT);
    Log.d(TAG, "MANUFACTURER=" + Build.MANUFACTURER);
    Log.d(TAG, "MODEL=" + Build.MODEL);
    Log.d(TAG, "DEVICE=" + Build.DEVICE);
    Log.d(TAG, "BOARD=" + Build.BOARD);
    Log.d(TAG, "FINGERPRINT=" + Build.FINGERPRINT);

    if (!Loader.loaded) {
        TextView tv = new TextView(this);
        tv.setText("Failed to load the native LK8000 libary.\n"
                + "Report this problem to us, and include the following information:\n" + "ABI=" + Build.CPU_ABI
                + "\n" + "PRODUCT=" + Build.PRODUCT + "\n" + "FINGERPRINT=" + Build.FINGERPRINT + "\n"
                + "error=" + Loader.error);
        setContentView(tv);
        return;
    }

    initialiseNative();

    NetUtil.initialise(this);
    InternalGPS.Initialize();
    NonGPSSensors.Initialize();

    IOIOHelper.onCreateContext(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR)
        // Bluetooth suppoert was added in Android 2.0 "Eclair"
        BluetoothHelper.Initialize(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
        // the DownloadManager was added in Android 2.3 "Gingerbread"
        DownloadUtil.Initialise(getApplicationContext());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        UsbSerialHelper.Initialise(this);
    }

    SoundUtil.Initialise();

    // fullscreen mode
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    /* Workaround for layout problems in Android KitKat with immersive full
       screen mode: Sometimes the content view was not initialized with the
       correct size, which caused graphics artifacts. */
    if (android.os.Build.VERSION.SDK_INT >= 19) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }

    enableImmersiveModeIfSupported();

    TextView tv = new TextView(this);
    tv.setText("Loading LK8000...");
    setContentView(tv);

    batteryReceiver = new BatteryReceiver();
    registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    SharedPreferences settings = getSharedPreferences("LK8000", 0);
    int screenOrientation = settings.getInt("screenOrientation", 0);
    switch (screenOrientation) {
    case 0:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        break;
    case 1:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
    case 2:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        break;
    case 3:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        break;
    case 4:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        break;
    default:
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

}

From source file:it.unicaradio.android.activities.MainActivity.java

private void decideAppOrientation() {
    if (getResources().getBoolean(R.bool.isTablet)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {/*from   w ww.  j  a  va2  s  .  co  m*/
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}

From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {//from w  ww . j a va 2 s  .  c o  m
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    setContentView(R.layout.activity_authentication);
    RelativeLayout relativeLayout = (RelativeLayout) this.findViewById(R.id.relavtiveLayoutAuthentication);

    if (Constants.DEFAULT_OWNERSHIP.equals(Constants.OWNERSHIP_COSU)) {
        relativeLayout.setVisibility(RelativeLayout.GONE);
    }
    deviceInfo = new DeviceInfo(context);
    etDomain = (EditText) findViewById(R.id.etDomain);
    etUsername = (EditText) findViewById(R.id.etUsername);
    etPassword = (EditText) findViewById(R.id.etPassword);
    etDomain.setFocusable(true);
    etDomain.requestFocus();
    btnSignIn = (Button) findViewById(R.id.btnSignIn);
    btnSignIn.setOnClickListener(onClickAuthenticate);
    btnSignIn.setEnabled(false);

    // change button color background till user enters a valid input
    btnSignIn.setBackgroundResource(R.drawable.btn_grey);
    btnSignIn.setTextColor(ContextCompat.getColor(this, R.color.black));
    TextView textViewSignIn = (TextView) findViewById(R.id.textViewSignIn);
    LinearLayout loginLayout = (LinearLayout) findViewById(R.id.loginLayout);

    if (Preference.hasPreferenceKey(context, Constants.TOKEN_EXPIRED)) {
        etDomain.setEnabled(false);
        etDomain.setTextColor(ContextCompat.getColor(this, R.color.black));
        etUsername.setEnabled(false);
        etUsername.setTextColor(ContextCompat.getColor(this, R.color.black));
        btnSignIn.setText(R.string.btn_sign_in);
        etPassword.setFocusable(true);
        etPassword.requestFocus();
        String tenantedUserName = Preference.getString(context, Constants.USERNAME);
        int tenantSeparator = tenantedUserName.lastIndexOf('@');
        etUsername.setText(tenantedUserName.substring(0, tenantSeparator));
        etDomain.setText(tenantedUserName.substring(tenantSeparator + 1, tenantedUserName.length()));
        isReLogin = true;
        textViewSignIn.setText(R.string.msg_need_to_sign_in);
    } else if (Constants.CLOUD_MANAGER != null) {
        isCloudLogin = true;
        etDomain.setVisibility(View.GONE);
        textViewSignIn.setText(R.string.txt_sign_in_cloud);
    }

    if (Preference.getBoolean(context, Constants.PreferenceFlag.DEVICE_ACTIVE) && !isReLogin) {
        Intent intent = new Intent(AuthenticationActivity.this, AlreadyRegisteredActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
        return;
    }

    TextView textViewSignUp = (TextView) findViewById(R.id.textViewSignUp);
    if (!isReLogin && Constants.SIGN_UP_URL != null) {
        Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
            @Override
            public String transformUrl(Matcher match, String url) {
                return Constants.SIGN_UP_URL;
            }
        };
        Pattern pattern = Pattern.compile(getResources().getString(R.string.txt_sign_up_linkify));
        Linkify.addLinks(textViewSignUp, pattern, null, null, transformFilter);
    } else {
        textViewSignUp.setVisibility(View.GONE);
    }

    if (Constants.HIDE_LOGIN_UI) {
        loginLayout.setVisibility(View.GONE);
    }

    if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            startLockTask();
        }
    }

    TextView textViewWipeData = (TextView) this.findViewById(R.id.textViewWipeData);
    if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP) && Constants.DISPLAY_WIPE_DEVICE_BUTTON) {
        textViewWipeData.setVisibility(View.VISIBLE);
        textViewWipeData.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(AuthenticationActivity.this).setTitle(getString(R.string.app_name))
                        .setMessage(R.string.wipe_confirmation)
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getApplicationContext()
                                        .getSystemService(Context.DEVICE_POLICY_SERVICE);
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
                                    devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE
                                            | DevicePolicyManager.WIPE_RESET_PROTECTION_DATA);
                                } else {
                                    devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE);
                                }
                            }
                        }).setNegativeButton(android.R.string.no, null).show();
            }
        });
    }

    ImageView logo = (ImageView) findViewById(R.id.imageViewLogo);
    if (Constants.COSU_SECRET_EXIT) {
        logo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                kioskExit++;
                if (kioskExit == 6) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        stopLockTask();
                    }
                    finish();
                }
            }
        });
    }

    etUsername.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
        }

        @Override
        public void afterTextChanged(Editable s) {
            enableSubmitIfReady();
        }
    });

    etPassword.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            enableSubmitIfReady();
        }

        @Override
        public void afterTextChanged(Editable s) {
            enableSubmitIfReady();
        }
    });

    if (org.wso2.iot.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE
            .equals(org.wso2.iot.agent.proxy.utils.Constants.Authenticator.MUTUAL_SSL_AUTHENTICATOR)) {

        AuthenticatorFactory authenticatorFactory = new AuthenticatorFactory();
        ClientAuthenticator authenticator = authenticatorFactory.getClient(
                org.wso2.iot.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE,
                AuthenticationActivity.this, Constants.AUTHENTICATION_REQUEST_CODE);
        authenticator.doAuthenticate();
    }

    //This is an override to ownership type.
    if (Constants.DEFAULT_OWNERSHIP != null) {
        deviceType = Constants.DEFAULT_OWNERSHIP;
        Preference.putString(context, Constants.DEVICE_TYPE, deviceType);
    } else {
        deviceType = Constants.OWNERSHIP_BYOD;
    }

    if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) {
        Intent intent = getIntent();
        if (intent.hasExtra("android.app.extra.token")) {
            adminAccessToken = intent.getStringExtra("android.app.extra.token");
            proceedToAuthentication();
        }
    }

    // This is added so that in case due to an agent customisation, if the authentication
    // activity is called the AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED is set, the activity
    // must be finished.
    if (Constants.AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED) {
        finish();
    }
}

From source file:gr.scify.newsum.ui.SearchViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_NORMAL
            & (getResources().getConfiguration().screenLayout
                    & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_SMALL) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }//  ww w  .  j a v a 2  s.co m
    SharedPreferences usertheme = getSharedPreferences("theme", 0);
    int newTheme = usertheme.getInt("theme", 2);
    Utils.onActivityCreateSetTheme(this, newTheme);

    SharedPreferences userlang = getSharedPreferences("lang", 0);
    String newlang = userlang.getString("lang", Locale.getDefault().getLanguage());
    Setlanguage.updateLanguage(getApplicationContext(), newlang);

    GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
    View inflate = getLayoutInflater().inflate(R.layout.view, null);
    gestureOverlayView.addView(inflate);
    gestureOverlayView.addOnGesturePerformedListener(this);
    gestureOverlayView.setGestureColor(Color.TRANSPARENT);
    gestureOverlayView.setUncertainGestureColor(Color.TRANSPARENT);
    gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!gestureLib.load()) {
        finish();
    }
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(gestureOverlayView);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    ImageView title_image = (ImageView) findViewById(R.id.title_image);
    title_image.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.scify)));
            startActivity(browse);
        }

    });

    // setContentView(R.layout.view);
    // TODO: Add Loading dialog

    SharedPreferences setvmassage = getSharedPreferences("dialog", 0);
    boolean dialogShown = setvmassage.getBoolean("dialogShown", false);

    if (!dialogShown) {
        // prepare the alert box
        AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
        alertbox.setMessage(R.string.view_massage);
        alertbox.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {

            }
        });
        alertbox.setCancelable(false);
        alertbox.show();

        SharedPreferences.Editor editor = setvmassage.edit();
        editor.putBoolean("dialogShown", true);
        editor.commit();
    }

    // Init waiting dialog
    showWaitingDialog();

    initLayoutAndControls();

}

From source file:com.gigigo.vuforia.core.sdkimagerecognition.cloudrecognition.CloudRecognition.java

protected void on_Resume() {
    // This is needed for some Droid devices to force portrait
    if (mIsDroidDevice) {
        this.mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }// w ww. j  a v a2 s  . c  o m

    try {
        if (vuforiaAppSession != null)
            vuforiaAppSession.resumeAR();
    } catch (VuforiaException e) {
        GGGLogImpl.log(e.getString(), LogLevel.ERROR);
    }

    // Resume the GL view:
    if (mGlView != null) {
        mGlView.setVisibility(View.VISIBLE);
        mGlView.onResume();
    }
}

From source file:org.uoyabause.android.YabauseHandler.java

/** Called when the activity is first created. */
@Override//from  www. ja  v  a  2s.  co m
public void onCreate(Bundle savedInstanceState) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Yabause.this);
    boolean lock_landscape = sharedPref.getBoolean("pref_landscape", false);
    if (lock_landscape == true) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }

    super.onCreate(savedInstanceState);
    System.gc();

    YabauseApplication application = (YabauseApplication) getApplication();
    mTracker = application.getDefaultTracker();

    setContentView(R.layout.main);
    getWindow().setSustainedPerformanceMode(true);
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    if (sharedPref.getBoolean("pref_analog_pad", false) == true) {
        mNavigationView.setCheckedItem(R.id.pad_mode);
    }

    DrawerLayout.DrawerListener drawerListener = new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View view, float v) {

        }

        @Override
        public void onDrawerOpened(View view) {
            if (menu_showing == false) {
                menu_showing = true;
                YabauseRunnable.pause();
                audio.mute(audio.SYSTEM);
                String name = YabauseRunnable.getGameTitle();
                TextView tx = (TextView) findViewById(R.id.menu_title);
                if (tx != null) {
                    tx.setText(name);
                }

                if (adView != null) {
                    LinearLayout lp = (LinearLayout) findViewById(R.id.navilayer);
                    if (lp != null) {
                        final int mCount = lp.getChildCount();
                        boolean find = false;
                        for (int i = 0; i < mCount; ++i) {
                            final View mChild = lp.getChildAt(i);
                            if (mChild == adView) {
                                find = true;
                            }
                        }
                        if (find == false) {
                            lp.addView(adView);
                        }
                        AdRequest adRequest = new AdRequest.Builder()
                                .addTestDevice("303A789B146C169D4BDB5652D928FF8E").build();
                        adView.loadAd(adRequest);
                    }
                }

            }
        }

        @Override
        public void onDrawerClosed(View view) {

            if (waiting_reault == false && menu_showing == true) {
                menu_showing = false;
                YabauseRunnable.resume();
                audio.unmute(audio.SYSTEM);
            }

        }

        @Override
        public void onDrawerStateChanged(int i) {
        }
    };
    this.mDrawerLayout.setDrawerListener(drawerListener);

    audio = new YabauseAudio(this);

    Intent intent = getIntent();
    String game = intent.getStringExtra("org.uoyabause.android.FileName");
    if (game != null && game.length() > 0) {
        YabauseStorage storage = YabauseStorage.getStorage();
        gamepath = storage.getGamePath(game);
    } else
        gamepath = "";

    String exgame = intent.getStringExtra("org.uoyabause.android.FileNameEx");
    if (exgame != null) {
        gamepath = exgame;
    }

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    readPreferences();

    padm = PadManager.getPadManager();
    padm.loadSettings();
    waiting_reault = false;

    handler = new YabauseHandler(this);
    yabauseThread = new YabauseRunnable(this);

    UiModeManager uiModeManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
        SharedPreferences prefs = getSharedPreferences("private", Context.MODE_PRIVATE);
        Boolean hasDonated = prefs.getBoolean("donated", false);
        if (hasDonated) {
            adView = null;
        } else {
            adView = new AdView(this);
            adView.setAdUnitId(getString(R.string.banner_ad_unit_id2));
            adView.setAdSize(AdSize.BANNER);
            AdRequest adRequest = new AdRequest.Builder().build();
            adView.loadAd(adRequest);
            adView.setAdListener(new AdListener() {
                @Override
                public void onAdOpened() {
                    // Save app state before going to the ad overlay.
                }
            });
        }
    } else {
        adView = null;
    }

}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsActivity.java

/** Handles item selections */
@Override//from   ww w.j  a  v a  2 s . co m
public boolean onOptionsItemSelected(MenuItem item) {
    Resources res = this.getResources();
    switch (item.getItemId()) {
    case android.R.id.home:
        closeStudyOptions();
        return true;

    case MENU_PREFERENCES:
        startActivityForResult(new Intent(this, Preferences.class), StudyOptionsFragment.PREFERENCES_UPDATE);
        if (AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
        }
        return true;

    case MENU_ROTATE:
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        return true;

    case MENU_NIGHT:
        SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this);
        if (preferences.getBoolean("invertedColors", false)) {
            preferences.edit().putBoolean("invertedColors", false).commit();
            item.setIcon(R.drawable.ic_menu_night);
        } else {
            preferences.edit().putBoolean("invertedColors", true).commit();
            item.setIcon(R.drawable.ic_menu_night_checked);
        }
        return true;
    case DeckPicker.MENU_CREATE_DYNAMIC_DECK:
        StyledDialog.Builder builder = new StyledDialog.Builder(StudyOptionsActivity.this);
        builder.setTitle(res.getString(R.string.new_deck));

        mDialogEditText = new EditText(StudyOptionsActivity.this);
        ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames();
        int n = 1;
        String cramDeckName = "Cram 1";
        while (names.contains(cramDeckName)) {
            n++;
            cramDeckName = "Cram " + n;
        }
        mDialogEditText.setText(cramDeckName);
        // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter });
        builder.setView(mDialogEditText, false, false);
        builder.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                long id;
                Bundle initialConfig = new Bundle();
                try {
                    initialConfig.putString("searchSuffix",
                            "'deck:" + AnkiDroidApp.getCol().getDecks().current().getString("name") + "'");
                    id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString());
                    AnkiDroidApp.getCol().getDecks().get(id);
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
                loadContent(false, initialConfig);
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.create().show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.mitre.svmp.activities.AppRTCActivity.java

private int getDeviceDefaultOrientation() {
    WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    Configuration config = getResources().getConfiguration();
    int rotation = windowManager.getDefaultDisplay().getRotation();

    int value = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
            && config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
                    && config.orientation == Configuration.ORIENTATION_PORTRAIT))
        value = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

    return value;
}

From source file:fr.cph.stock.android.activity.ChartActivity.java

/**
 * /*from   w  w  w .ja v  a2 s  .c  om*/
 * @return
 */
private String getData() {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    String data = null;
    try {
        InputStream is = null;
        StringWriter writer = new StringWriter();
        switch (chartType) {
        case CAPITALIZATION:
            is = getApplicationContext().getAssets().open("www/pie.html");
            IOUtils.copy(is, writer, "UTF8");
            data = writer.toString();
            data = data.replace("#DATA#", portfolio.getChartCapData());
            data = data.replace("#TITLE#", portfolio.getChartCapTitle());
            data = data.replace("#DRAW#", portfolio.getChartCapDraw());
            data = data.replace("#COMPANIES#", portfolio.getChartCapCompanies());
            data = data.replaceAll("#WIDTH#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            data = data.replaceAll("#HEIGHT#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            actionBar.setTitle("Capitalization Chart");
            webView.setHorizontalScrollBarEnabled(false);
            break;
        case SECTOR:
            is = getApplicationContext().getAssets().open("www/pie.html");
            IOUtils.copy(is, writer, "UTF8");
            data = writer.toString();
            data = data.replace("#DATA#", portfolio.getChartSectorData());
            data = data.replace("#TITLE#", portfolio.getChartSectorTitle());
            data = data.replace("#DRAW#", portfolio.getChartSectorDraw());
            data = data.replace("#COMPANIES#", portfolio.getChartSectorCompanies());
            data = data.replaceAll("#WIDTH#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            data = data.replaceAll("#HEIGHT#", (int) (metrics.widthPixels / metrics.density) - 30 + "");
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            actionBar.setTitle("Sector Chart");
            webView.setHorizontalScrollBarEnabled(false);
            break;
        case SHARE_VALUE:
            is = getApplicationContext().getAssets().open("www/share_value.html");
            IOUtils.copy(is, writer, "UTF8");
            data = writer.toString();
            data = data.replace("#DATA#", portfolio.getChartData());
            data = data.replace("#DRAW#", portfolio.getChartDraw());
            data = data.replace("#COLOR#", portfolio.getChartColors());
            data = data.replace("#DATE#", portfolio.getChartDate());
            data = data.replaceAll("#WIDTH#", ((int) (metrics.widthPixels / metrics.density)) - 30 + "");
            data = data.replaceAll("#HEIGHT#", (int) (metrics.heightPixels / metrics.density / 1.35) + "");
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            actionBar.setTitle("Share Value Chart");
            break;
        }
    } catch (IOException e) {
        Log.e(TAG, "", e);
    }
    return data;
}