android


getCurrentSizeRange() on Android earlier than 4.1


On Android API 16 (4.1 Jelly Bean) and later we have the method getCurrentSizeRange to get the range of width and height. How do I get the size range on versions earlier than 4.1?
I tried to look into the source code to see how the range is computed. It is done differently on different Android versions and I couldn't find the logic which computes these sizes. Any pointers that could help me find this is much appreciated.
If you're just trying to determine the heights and widths for portrait and landscape, you could just quickly force the orientation both ways and get the metrics each way. The following snippet does that. The code is guarded by a simple preference check since I tested this in onCreate() and the orientation changes will cause an activity restart (and go into a loop). In your app, you'll probably want to do something more specific. Also, all of the methods used are valid down to API 1, but may have been replaced or renamed in higher versions.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("firstTime", true)) {
prefs.edit().putBoolean("firstTime", false).commit();
DisplayMetrics dm = new DisplayMetrics();
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindowManager().getDefaultDisplay().getMetrics(dm);
Log.e(TAG, String.format("landscape is %d x %d", dm.widthPixels, dm.heightPixels));
// Do something with the values, perhaps saving them in prefs
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindowManager().getDefaultDisplay().getMetrics(dm);
Log.e(TAG, String.format("portrait is %d x %d", dm.widthPixels, dm.heightPixels));
// Do something with the values, perhaps saving them in prefs
}

Related Links

Android -How to populate a query according to the user click item of GridView?
Google play developer console tablet optimization tips-how to fix?
SQLite, why cant android find the column? [duplicate]
Target Downgrade
List view element height [duplicate]
Center video at center of screen - Videoview Android
Why is my app leaking memory on screen rotation?
Android Smart Lock for Passwords sign out
Which encryption to use to send a base64 string securely over HTTP?
RelativeLayout-LayoutParams cannot be cast to FrameLayout-LayoutParams
Handle only horizontal movement using onTouchEvent
Android load images from URL into custom listview adapter without Picasso
Is rawQuery broken when using selectionArgs with INNER JOIN
If an API does not provide push notifications. What other methods can be used?
Changing layout managers for different views in RecyclerView
Line break when importing csv to mysql and sqlite

Categories

HOME
developer-tools
linkedin
merge
fpga
rdbms
3d
youtube-data-api-v3
error-handling
edge
scripting
regular-language
pearson-correlation
jax-ws
bing-maps
extjs4.2
spin
mql5
owin
ipmitool
filechannel
spring-social
parameter-passing
symfony-2.8
pyramid
nim
oledb
imagemap
imageresizer
aggregation
monit
game-theory
motion-detection
flooding
has-and-belongs-to-many
bringtofront
gp
jaws
dumpbin
autolisp
getpixel
indy10
apns-php
health-monitoring
naming
preloader
install.packages
placeholder
knime
berkeley-db-je
ntvs
serde
chai-as-promised
datamaps
reindex
amq
oracleclient
check-mk
mouseleave
jtree
grails-plugin
dup
firebase-security
refinerycms
createprocess
jnlua
java-money
jquery-forms-plugin
diff3
xmltype
java-security
code-documentation
showdialog
packet-sniffers
android-cookiemanager
android-vibration
rickshaw
entry-point
jqmodal
ignite-ui
kissfft
grails-domain-class
multitasking
jammer
embedded-fonts
ie8-compatibility-mode
process-explorer
idn
sentestingkit
uimanageddocument
xcode3.2
database-create
strsep
django-paypal
diagrams
uideviceorientation
skype4java
lobo-cobra
google-wave
blind

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App