android


How should I deal with an Live wallpaper so it supports multiple aspect ratios?


I have a live wallpaper all set up (for simplicity's sake, assume it consists of two rotating bitmaps positioned side by side, each rotating at different speeds; also note that the bitmaps' edges (not the invisible box around the image, but rather the actual pixels of the drawing) are touching.)
I described the translate for each as a percentage of the canvas size (a value between 0 and 1 multiplied by c.getHeight(), and c.getWidth() (where c is a canvas).)
Anyways, everything works fine as long the aspect ratio is maintained. So xxhdpi and xhdpi # 1080x1920 and 720x1280 is all good, but then when i run it on a nexus s # 480x800, the two bitmaps are no longer positioned properly.
I do not want to distort my images (they are circles and must remain circles), so I was thinking the best way would be the limit the size of the canvas and center it.
So for the nexus s # 480x800, i would actually want to only draw in a 450x800 area which i would center on my screen.
In fact, I would always want to have my 2 bitmaps in an area respecting the height = width * 0.5625.
How should I go about doing this?
NB: I based my live wallpaper around the cube sample.
Please let me know if I left any important details out,
Thank you!
Werner
inside your Engine, implement following to capture the screen's height and width
int screenHeight, screenWidth;
#Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
screenHeight = height; screenWidth = width;
}
and wherever you decode your bitmap, do it like this:-
//get bitmap
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap);
//scale bitmap
bitmap = Bitmap.createScaledBitmap(bitmap, screenWidth, screenWidth * 0.5625, true);
This will fill your entire screen with a circle of correct aspect ratio (width * 0.5625).
And then make it centred by:-
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
final SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = holder.lockCanvas();
int x = ( screenHeight - screenWidth*0.5625 ) / 2;
canvas.drawBitmap(bitmap, 0, x, paint);

Related Links

Bluetooth Headset Button input
Android long Internet connect when starting after phone been locked
How to fill all space in parent Relative layout?
Android Update SSL Certificate
How to dynamically change view visibility using android data binding
there is connection but why i don't get the response retrofit
Calling main activity shows Activity not found exception
Unable to bind data in Recycler view in android
How to implement a special URL in my Android Application?
How to convert the json object response from retrofit success response?
I can only get part of a url and put into a String?
How to calculate aar method count and field count while proguard ?
Single vector resource multiple tints
How to implement resizeable fragment by user drag (not predefined transition animation)
com.google.android.gms.auth.GoogleAuthException: UNREGISTERED_ON_API_CONSOLE
How to draw multiple bitmaps of even more drawables randomly but next to eachother. (android)

Categories

HOME
turing-machines
apache-flink
amp-html
alexa-skills-kit
case
apache-spark-mllib
apiblueprint
knitr
google-apps
rds
hugo
jax-ws
rcloud
extjs4.2
spin
ycsb
eip
atlassian
magnetic-cards
selectize.js
symbol
powershell-v5.0
dimensional-modeling
template-engine
google-data-studio
jersey-1.0
shortest-path
drive
user-experience
kendo-mobile
imagemap
epsilon
tiki-wiki
onload
ms-access-web-app
apktool
anki
deltaspike
lubridate
latitude-longitude
salesforce-communities
wurfl
zoomify
projects-and-solutions
apns-php
linq-to-objects
signals-slots
apache-stanbol
postgresql-8.4
avcapturedevice
gitlist
fclose
mongotemplate
video-conferencing
boo
sundials
pdf-conversion
quicktime
payload
d3-force-directed
template-toolkit
mathcad
smartfoxserver
node-request
grails-plugin
dup
gogs
bizagi
nupic
false-sharing
libvlc
dynamics-nav-2016
sapi
qt5.2
iokit
rubaxa-sortable
doctype
skspritenode
nutiteq
zxspectrum
umlgraph
public-html
execve
appserver
extjs2
android-usb
cocoalibspotify-2.0
script#
beaker-testing
cmmi
kaleidoscope
time.h
epiceditor
extreme-programming
failing-tests
isa-swizzling
w3c-geolocation
nhprof
interprocess
lalr
ifilter

Resources

Encrypt Message