Center peek wallpaper in activity without stretching - android

I'm developing an alternative home application which fits on one screen.
Currently I have one activity ,which has the height and width of the phone screen,in which I try to set default wallpaper as background.
I use this code to do this:
getWindow().setBackgroundDrawable(peekWallpaper());
The problem is that it stretch the wallpaper to make it fit in one screen, so my wallpaper becomes completely flattened.
I found a workaround to avoid this, I extends drawable class and overide the method setBounds in order to avoid the stretching. But by doing this, I only see the left top corner of my wallpaper. So I would like to center it.
How can I do that ? Am I on the right way to do it ?
I have seen some methods in WallpaperManager class to move wallpaper :
setWallpaperOffsetSteps(float xStep, float yStep)
and
setWallpaperOffsets (IBinder windowToken, float xOffset, float yOffset)
But I don't find any sample of code on how to use IBinder parameters, can it be usefull on my case ?
Thx in advance.

Related

how to scale image between 2 views with given coordinates in android

In my application I have a requirement to animate an image (this image view has an arrow set as source).
I am unable to figure this out how I can achieve this.To solve this i got x and y coordinates of second view that is rectangle after getting coordintes i am setting
scaleX() of image view that is purple line but I am not geeting desire out put because it stretches to the whole screen along x-axis
here is the code what i tried is
int x = (int) imageView.getX();
imageView2.setScaleX(x);
here imageview is rectangular box and imageview 2 is the purple line
Why you dont try with scenes? It's exactly what you need.
http://developer.android.com/training/transitions/scenes.html
I think you are getting the correct output when using the above code. Scale is defined against initial dimensions. And you would need to use something like this
dist = box.getX() - circle.getX()
and your scale would be
imageView2.setScale(dist/distInitial)
where distInitial you compute it at creation time using the dist formula.
You might need to change the position because it is scaled around the center of it (i.e. a smaller scale shrink margins to center of image)
You might want to perform this operations using a Canvas. It might be more efficient.

Animate activity exit transition with pivot- alternative to overridePendingTransition()

First of all not duplicate of : Alternative to overridePendingTransition() - Android
I want to scale an activity (exit) with a pivot point. The problem is that the xml pivotX & pivotY values use pixels which makes things difficult. So overridePendingTransition() is not really helpful because it only uses a xml animation.
So I want to animate the scale-exit of an activity (from 1f to 0f scaling rate) with a pivot of 50dp of the right of the screen and 100dp from the bottom of the screen.
Any ideas?
You have to start a transparent Activity and make your animation from here
Look at Android Developers Activity Animation where they explain the old custom/manual Activity Transition.

Flip Animation in Android for two views

*Can anybody tell me how to do this *
I am new in android.I wanted to create animations for below :
I have two views : 1.Image drawn by canvas (assume DrawView) & 2. TextView
I added rotation to DrawView from -90 to 90 (works like its wiping screen from bottom left corner to bottom right corner in circular motion)
Now I want to show TextView just like DrawView image is uncovering Textview.
I think Drawview should act like foreground view and textView like background .
I am adding image for better explaination!
Image Link :
https://docs.google.com/file/d/0B8DGjJBt0XQ_TVBtS0lidUFhZzA/edit?usp=sharing
Thanks in advance
I used two views in frame layout.
made Image drawn by canvas (assume DrawView) as front view .
using DrawView.bringToFront();
Worked !

Android rotate imageview in layout file

In my app each of the screens has a background image. I want to use the same image for portrait and landscape, but to make it look decent I need to rotate the image 90 degrees when in landscape so that it does not get stretched to fill the screen.
My solution was to just create two copies of the image one for portrait that I put in drawable-port and one for landscape that I put in drawable-land. Now that I have many different backgrounds my solution of just embedding a second copy of the image in my apk is causing the apk size to be much larger then needed.
How can I support rotated images, preferably in pure XML. In code I suppose you could just rotate the image before onStart and it would work, but I would really rather keep it in the XML if possible.
Thanks for the help!
I can't think of a way to do this in XML. But if you created a custom class that inherited from whichever view you're applying the background to (say, RelativeLayout), then you could do something like
#Override
protected void onSizeChanged(int newWidth, int newHeight, int oldWidth, int oldHeight) {
if (newWidth > newHeight) { // landscape
// rotate the background
}
}
This way, you only have to implement the rotation once and all of your views would auto-rotate their backgrounds.

Can I programmatically set a wallpaper to not scroll?

I am writing an app that allows a user to set the phone's wallpaper from a list of pictures.
By default it scrolls across the multiple home screens. I want the wallpaper on the home screen to be a static non-scrolling image.
What can I do programmatically to achieve this? Is this even possible?
I am using wallpaperManager.setResource(...); to set the wallpaper.
I've also tried wallpaperManager.setWallpaperOffsetSteps(0,0); but that did not solve my problem.
I'v fulfilled this feature by:
final WallpaperManager wpm = (WallpaperManager)getSystemService(
Context.WALLPAPER_SERVICE);
wpm.setWallpaperOffsetSteps(1, 1);
wpm.suggestDesiredDimensions(SCREEN_WIDTH, SCREEN_HEIGHT);
This is controlled by the Launcher application. If you want a non-scrolling wallpaper, install a Launcher app that doesn't scroll the wallpaper :)
Normally ImageWallpaper's size is set double wider than display's width so when you scroll home left or right, ImageWallpaper handles offsetchange events.
I've not tried this, but it may work i think. You may try this: [suggestDesiredDimensions]: http://developer.android.com/reference/android/app/WallpaperManager.html#suggestDesiredDimensions(int, int)
Set dimensions same as your workspace's width.
In case you do not know the screen width and screen height while setting wallpaper, this might help (P.S It is in Kotlin)
val manager = WallpaperManager.getInstance(context)
val drawable = manager.builtInDrawable
manager.setWallpaperOffsetSteps(1F, 1F)
val height = drawable.intrinsicHeight
val width = drawable.intrinsicWidth
val scaledBitmap = Bitmap.createScaledBitmap(bitmap, width, height,true)
If you want to put some effort into a solution, you could create a live wallpaper which displays a static, user-selectable image. Then your wallpaper could override the offset changes if that's what is desired. That's a lot of work, though, to stop the scrolling effect.
Alternatively, you could crop the image to the screen's size before setting it to wallpaper. That would stop the scrolling, but would break screen orientation changes.
can you try
final WallpaperManager wpm = (WallpaperManager)getSystemService(
Context.WALLPAPER_SERVICE);
wpm.setWallpaperOffsetSteps(1, 1);
wpm.suggestDesiredDimensions(SCREEN_WIDTH, SCREEN_HEIGHT);
For extremally decrease scrolling just crop a bitmap to device screen ratio, for example 9*16 and set this bitmap by wallpaper manager, but it works for one screen orientation (it is OK for smart phones).
Other solutions do not work.

Categories

Resources