[android-developers] Re: how can i check landscap orientation ?
Hi make use of sensorListener and it will work . i have used the same .. when u use sensorlistener and sensormanager in ur view it has got an override method as onSizeChanged which return the width and height. so using change in size u will get the orientation Below is a code for u of orientation check . enjoy : import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.hardware.SensorManager; import android.hardware.SensorListener; import android.util.Log; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; public class Midlet extends Activity { /** Tag string for our debug logs */ private static final String TAG = Sensors; private SensorManager mSensorManager; private GraphView mGraphView; private class GraphView extends View implements SensorListener { public GraphView(Context context) { super(context); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { System.out.println(on sizechanged); super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { } public void onSensorChanged(int sensor, float[] values) { } public void onAccuracyChanged(int sensor, int accuracy) { // TODO Auto-generated method stub } } /** * Initialization of the Activity after it is first created. Must at least * call {...@link android.app.Activity#setContentView setContentView()} to * describe what is to be displayed in the screen. */ @Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mGraphView = new GraphView(this); setContentView(mGraphView); } @Override protected void onResume() { super.onResume(); mSensorManager.registerListener(mGraphView, SensorManager.SENSOR_ACCELEROMETER | SensorManager.SENSOR_MAGNETIC_FIELD | SensorManager.SENSOR_ORIENTATION, SensorManager.SENSOR_DELAY_FASTEST); } @Override protected void onStop() { mSensorManager.unregisterListener(mGraphView); super.onStop(); } } On Wed, Mar 25, 2009 at 11:26 AM, Suman ipeg.stud...@gmail.com wrote: Hi Many thanks for replies. I actually want to do something if the screen orientation is landscap. Am trying something like this... if(getRequestedOrientation()== landscap) { { But it was not working. So if the way is correct then please tell me if(getRequestedOrientation()== ) Or suggest something another way. Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: how can i check landscap orientation ?
If you just want to find the current orientation of the screen, the sensor manager is just totally the wrong direction to take. What you want to do is use getResources().getConfiguration() (sorry I incorrectly previously posted to use getDisplayMetrics()). You can follow the docs on getRequestedOrientation() to see the (fairly large) set of possible values it returns and that usually it is not telling you the actual current orientation: http://developer.android.com/reference/android/app/Activity.html#getRequestedOrientation() http://developer.android.com/reference/android/content/pm/ActivityInfo.html#screenOrientation http://developer.android.com/reference/android/R.attr.html#screenOrientation So if you are getting SCREEN_ORIENTATION_PORTRAIT or SCREEN_ORIENTATION_LANDSCAPE from here, you are just finding out that you had told the system that you want to force the screen to be portrait or landscape while your activity is in the foreground. This is what you want to use if you just want to find out the current screen orientation: http://developer.android.com/reference/android/content/res/Resources.html#getConfiguration() http://developer.android.com/reference/android/content/res/Configuration.html#orientation On Tue, Mar 24, 2009 at 11:16 PM, suhas gavas suhas.ga...@gmail.com wrote: Hi make use of sensorListener and it will work . i have used the same .. when u use sensorlistener and sensormanager in ur view it has got an override method as onSizeChanged which return the width and height. so using change in size u will get the orientation Below is a code for u of orientation check . enjoy : import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.hardware.SensorManager; import android.hardware.SensorListener; import android.util.Log; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; public class Midlet extends Activity { /** Tag string for our debug logs */ private static final String TAG = Sensors; private SensorManager mSensorManager; private GraphView mGraphView; private class GraphView extends View implements SensorListener { public GraphView(Context context) { super(context); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { System.out.println(on sizechanged); super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { } public void onSensorChanged(int sensor, float[] values) { } public void onAccuracyChanged(int sensor, int accuracy) { // TODO Auto-generated method stub } } /** * Initialization of the Activity after it is first created. Must at least * call {...@link android.app.Activity#setContentView setContentView()} to * describe what is to be displayed in the screen. */ @Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mGraphView = new GraphView(this); setContentView(mGraphView); } @Override protected void onResume() { super.onResume(); mSensorManager.registerListener(mGraphView, SensorManager.SENSOR_ACCELEROMETER | SensorManager.SENSOR_MAGNETIC_FIELD | SensorManager.SENSOR_ORIENTATION, SensorManager.SENSOR_DELAY_FASTEST); } @Override protected void onStop() { mSensorManager.unregisterListener(mGraphView); super.onStop(); } } On Wed, Mar 25, 2009 at 11:26 AM, Suman ipeg.stud...@gmail.com wrote: Hi Many thanks for replies. I actually want to do something if the screen orientation is landscap. Am trying something like this... if(getRequestedOrientation()== landscap) { { But it was not working. So if the way is correct then please tell me if(getRequestedOrientation()== ) Or suggest something another way. Thanks in advance. -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To
[android-developers] Re: how can i check landscap orientation ?
Pls add andoid:configChanges=orientation|keyboard And override onConfigurationChanged and check the orientation against Configuration.ORIENTATION_LANDSCAPE or potrait On Mar 25, 2009 12:56 AM, Suman ipeg.stud...@gmail.com wrote: Hi Many thanks for replies. I actually want to do something if the screen orientation is landscap. Am trying something like this... if(getRequestedOrientation()== landscap) { { But it was not working. So if the way is correct then please tell me if(getRequestedOrientation()== ) Or suggest something another way. Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: how can i check landscap orientation ?
On Wed, Mar 25, 2009 at 9:25 AM, Kather Jailani jail...@gmail.com wrote: Pls add andoid:configChanges=orientation|keyboard And override onConfigurationChanged and check the orientation against Configuration.ORIENTATION_LANDSCAPE or potrait Please don't do that unless you really have a good reason to do so. (Such as playing a video.) -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---