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

How can i span this text over multiple lines?
(Read and) Parse an XML file from Internal Storage
Delphi sharesheet xe5
how to set margin on imageview using code in android?
Virtual MIDI on Android - possible?
How am I meant to call quit() on a Looper instance once I've called loop()
How to correctly measure the height of a view before it is drawn
graph using Android GraphView
Android - setOnClickListener method how does it work?
Android - detecting beacon disables wifi
AndroidTV HeaderItem icon can't be set
Image not completely showing in HorizontalScrollView
custom radio buttons trimmed
facebook api on android - how can I get the number of friends that a user has?
Android send image to webserver
Handle with AlertDialog into the doInBackground

Categories

HOME
phpword
microsoftgraph
google-cloud-platform
jax-rs
opendj
yandex
vxml
jquery-ui
android-json
title
special-characters
elasticsearch-5
rcloud
owin
commonjs
siddhi
project-intu
php-5.6
symmetricds
3nf
flatpak
android-intent
qsqlquery
dreamweaver
delphi-xe5
database-connection
google-maps-autocomplete
kendo-mobile
event-store
scriptella
dynamically-generated
pic32
stackexchange
progress-bar
underscore.js
winexe
iis-express
jaws
sqsh
scrollview
dotspatial
eviews
utorrent
sql-server-2000
login-script
jwplayer6
xcode7.3
xdocreport
chef-solo
c9.io
news
apache-stanbol
portforwarding
softmax
avcapturedevice
photos
apache-spark-dataset
flask-restful
gitlist
context-switch
oracleclient
quicktime
juice-ui
taocp
pytables
watch-os-2
signalr.client
windows-azure-queues
cifilter
lean
clipboard.js
qbxml
concurrentmodification
slash
dulwich
branch-and-bound
cakephp-2.7
android-cookiemanager
xml-namespaces
functional-java
radiant
file-not-found
clickbank
inputmismatchexception
ebay-lms
process-explorer
route-provider
windows-98
http-status-code-410
argouml
qi4j
midlet
fusefabric
jdb
gobject-introspection
timthumb
quotation-marks
luajava
ruby-1.8
zend-rest
zen
interop-domino
fail-fast-fail-early

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