List of usage examples for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT
int SCREEN_ORIENTATION_PORTRAIT
To view the source code for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT.
Click Source Link
portrait
in the android.R.attr#screenOrientation attribute. From source file:Main.java
/** * Locks specified activity's orientation until it is unlocked or recreated. * * @param activity activity/*from w ww .ja v a 2 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:Main.java
public static int getScreenOrientation(Activity activity) { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; int orientation; // if the device's natural orientation is portrait: if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) { switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; default://from ww w. j a va 2 s .c om Log.e("getScreenOrientation", "Unknown screen orientation. Defaulting to portrait."); orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } else { // if the device's natural orientation is landscape or if the device // is square: switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; default: Log.e("getScreenOrientation", "Unknown screen orientation. Defaulting to landscape."); orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; }
From source file:Main.java
/** * Same as {@link #toggleOrientation(Activity)} except {@link Instrumentation#waitForIdleSync()} * is called after each orientation change. * * @param activity whose orientation will be changed and restored * @param instrumentation use for idle syncing *///from ww w.j a v a 2 s.com public static void toggleOrientationSync(final Activity activity, final Instrumentation instrumentation) { final int originalOrientation = activity.getResources().getConfiguration().orientation; final int newOrientation = originalOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; changeOrientation(activity, instrumentation, newOrientation); changeOrientation(activity, instrumentation, originalOrientation); }
From source file:Main.java
/** * @Thach Feb 21, 2014//from www . j av a 2 s. com * @Desc lock Orientation * @param b */ @SuppressWarnings("deprecation") public static void lockOrientation(Activity act, boolean isLock) { if (act == null) { return; } if (isLock) { Display display = act.getWindowManager().getDefaultDisplay(); int rotation = display.getRotation(); int height; int width; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) { height = display.getHeight(); width = display.getWidth(); } else { Point size = new Point(); display.getSize(size); height = size.y; width = size.x; } switch (rotation) { case Surface.ROTATION_90: if (width > height) act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else act.setRequestedOrientation(9/* reversePortait */); break; case Surface.ROTATION_180: if (height > width) act.setRequestedOrientation(9/* reversePortait */); else act.setRequestedOrientation(8/* reverseLandscape */); break; case Surface.ROTATION_270: if (width > height) act.setRequestedOrientation(8/* reverseLandscape */); else act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; default: if (height > width) act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); else act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else { act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } }
From source file:edu.chl.dat255.sofiase.readyforapet.viewcontroller.HowToPlayActivity.java
/** * onCreate method//from w w w . j a v a 2 s .co m * * @param savedInstanceState - Bundle */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.howtoplayactivity); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); instructions = (TextView) findViewById(R.id.howtoplay); instructions.setVisibility(View.VISIBLE); instructions.setText("Create a pet and name it by selecting play in the main menu. \n\n" + "Take care of your pet and make it happier by feeding, walking and playing with it every day. " + "When walking the pet you need to actually take a walk - all to prove that you are ready to take care of a real pet. \n\n" + "But watch out! If you leave your pet unattended for more than two days it is going to die.."); }
From source file:com.repay.android.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // If the available screen size is that of an average tablet (as defined // in the Android documentation) then allow the screen to rotate if (getResources().getBoolean(R.bool.lock_orientation)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }//w w w . j a v a 2 s .c o m super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate fragments mStartFr = new StartFragment(); getActionBar().setDisplayShowTitleEnabled(false); mFragMan = getSupportFragmentManager().beginTransaction(); mFragMan.add(mFrameLayout, mStartFr); mFragMan.commit(); }
From source file:org.alljoyn.services.audio.android.SourceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.player);//w w w .java 2 s . c o m setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mUIHelper = new UIHelper(this); mUIHelper.init(); }
From source file:com.prey.activities.WelcomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); menu();// w w w. jav a2 s . co m }
From source file:org.udevcommunity.utasbih.utasbih.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //Declaration Layout et Adapter String[] tasbih = { " ", " ", " ", " " }; //create Adapter ListAdapter adapter = new Adapter(this, tasbih); ListView tasbi_list = (ListView) findViewById(R.id.list1); tasbi_list.setAdapter(adapter);//w w w. j av a 2s . com //create onclick methodes tasbi_list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent counterActivity; switch (position) { case 0: counterActivity = new Intent(MainActivity.this, CounterActivity.class); counterActivity.putExtra("mode", 1); // Sending the parameter of mode of tasbih to the CounterActivity Activity startActivity(counterActivity); break; case 1: counterActivity = new Intent(MainActivity.this, CounterActivity.class); counterActivity.putExtra("mode", 2); // Sending the parameter of mode of tasbih to the CounterActivity Activity startActivity(counterActivity); break; case 2: counterActivity = new Intent(MainActivity.this, CounterActivity.class); counterActivity.putExtra("mode", 3); // Sending the parameter of mode of tasbih to the CounterActivity Activity startActivity(counterActivity); break; case 3: counterActivity = new Intent(MainActivity.this, CounterActivity.class); counterActivity.putExtra("mode", 4); // Sending the parameter of mode of tasbih to the CounterActivity Activity startActivity(counterActivity); break; default: counterActivity = new Intent(MainActivity.this, CounterActivity.class); counterActivity.putExtra("mode", 1); // Sending the parameter of mode of tasbih to the CounterActivity Activity startActivity(counterActivity); break; } } }); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
From source file:net.olejon.spotcommander.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Allow landscape? if (!mTools.allowLandscape()) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Layout//from w ww . ja v a 2 s .c o m setContentView(R.layout.activity_settings); //noinspection deprecation addPreferencesFromResource(R.xml.settings); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); toolbar.setTitleTextColor(ContextCompat.getColor(mContext, R.color.white)); toolbar.setTitle(getString(R.string.settings_title)); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { NavUtils.navigateUpFromSameTask(mActivity); } }); }