Dialog view animates "manually" but not when using an animation - android

I am trying to apply a custom animation to show and hide a Dialog and have come across a certain problem.
A View provides two method for animation which are .animate() which I call a "manual" animation and .startAnimation(Animation animation) which receives an Animation object.
I access the dialog's view by calling alertDialog.getWindow().getDecorView() and try to animate it using startAnimation but that doesn't work. Only if I use the animate function I can animate it.
Here is a code example that, as far as I know, should return the same results but reproduces the problem I'm dealing with:
AlertDialog dialog = AlertDialog.Builder(MainActivity.this).create(); // Create the dialog
View decorView = dialog.getWindow().getDecorView(); // Access the dialog's view
// The animation below works fine
decorView.animate().rotationXBy(45).setDuration(500).start(); // Animate it "manually"
// Create an animation instance
RotateAnimation scaling = new RotateAnimation(0, 45);
scaling.setDuration(500);
scaling.setFillAfter(true);
// This animation does NOT work
decorView.startAnimation(scaling);
I have tried the same code with other views and it works normally so I guess there is some peculiarity for dialogs that break the functionality?
I'd like to know if I'm doing something wrong and, if possible, how can I achieve what I want?

I ended up going other way instead of using dialogs but with them, you really have to manually create your animations step by step instead of using those helpful classes that the platform provides.
I thought it could be some problem related to the view not being ready for the Animation and even started it inside a decorView.post(Runnable) but the same results were obtained.
If anyone else tries this approach (seriously don't, create your own view and animate it normally, you'll run into even worse problems animating the dialog's dismissal) be aware that animating a dialog is not so easy. Maybe look for libraries that do it.

Related

Sliding button or text across the screen

Sometimes you see in android applications that the move the button from one side of the screen to another (cosmetic stuffs) and it looks nice. Kind of like powerpoint presentation when you slide in text.
I was wondering, are these done typically using Animations in android classes or is it moved using coordinates/draw function in a loop. I am not sure which way is typically this done.
Thank you
I am not sure what exactly you mean (maybe you can give a specific example/app), but usually you use the Animation class to create an animation. There are some specific animations (subclasses) that can be used, but you can also create your own (by subclassing or via xml).
The one you describe sounds like the TranslateAnimation, that just translates the coordinates of a view at the beginning of an animation to coordinates at the end of the animation.
Also take a look here, for further reference.
http://developer.android.com/training/animation/index.html
http://developer.android.com/guide/topics/graphics/view-animation.html

Create blue "tutorial" dialogs as in Android 4.4

I would like to create some "dialogs" like those shown in Android 4.4 for example when you are first shown immersive mode. The little arrow is important for me because I would like to have the dialogin different places on the screen.
This is what I'm talking about:
Do I need to create a custom AlertDialog? How do I move it around, can I use the coordinates of a View? I don't really know where to start. Are there any examples on creating this type of thing? I am not interested in using the ShowcaseView library as in my opinion has the "old" holo look.
You can get the coordinate of views using getLocationOnScreen(), make sure to call this after the views have been inflated (so, not in onCreate() of your activity) or else you will be returned default int values (i.e. 0).
You should probably create your own DialogFragment. Incorporate your own custom layout which contains the little bubble and the button. A Quick and dirty sample for the onCreateDialog() would have the following
Dialog dialog = new Dialog(getActivity());
// Get rid of the annoying alert dialog title bar
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// You must set the content view after requesting window features, not before.
dialog.setContentView(someView);
// Make the dialog full screen
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//Dim the background
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(80, 0, 0, 0));
To incorporate the little arrow, you can try having variations of 9-patch images as the background of the little bubble. Another alternative would be to have an arrowhead and a bubble put into the same container, and setting the margin/padding between them to 0. Since you have the coordinates you can adjust the horizontal margins of the arrowhead accordingly. This is actually a pretty cool idea, I think I'll try my own interpretation of it this weekend.
I have actually been working on my own interpretation of the showcase library, Here is what i achieved. Much of the dynamic position changing should be the same I would think

Animation complete listener with popupwindow

I have a popupwindow that is using a
PopupWindow.setAnimationStyle()
to show a scale in/out animation for create/dismiss .Animation is working fine. I want to know when the scale in animation is complete , but I can't find a way ...
Is there a way to set a listener for the animations listed in animation style.
I guess if I make any of the following idea work , I can achieve it
create an animation style programmatically, so that I can register listeners for the involved animations.
instead of PopupWindow.setAnimationStyle() I can set animation directly to Popupwindow , something like **Popup.setAnimation.
I can get a reference to the animations of the Popupwindow.
I tried everything I can, to find a solution but to no avail.
Please help.

Remove fade animation from toast message

I am using a hack to display an overlay over a picture in Google TV using a constant toast message.
I would like to know if there is a way to further modify the toast to remove the fade in and fade out effect. Ideally I would like the overlay to appear instantly.
Any help or direction would be greatly appreciated.
For this , i suggest we can use a layout(FrameLayout).
and by using a new layout above your current layout and adding view that looks similar to TOAST to the top layer
After that do one thing by making object of View as v
eg:-
View v;
v.setVisiblity(GONE);
v.setVisibility(VISIBLE);
This will make your view appear or hide.
You can use a FrameLayout and create a new Layout layer above your current layout and add a view that looks like toast to the top layer.
Then you can use: View.setVisiblity(GONE); and View.setVisibility(VISIBLE);
to make your view appear and hide instantly.
View.setVisibility Documentation
FrameLayout example
I like a fade-in effect, but I was in need to cancel a toast message immediately without fade-out effect, since the toast message remained shown for a short moment even when the Activity was already exited.
I came to this solution to close (or actually hide) my toast message t immediately:
((TextView)t.getView().findViewById(android.R.id.message)).setTextColor(Color.TRANSPARENT);
t.setText("");
t.getView().setBackgroundColor(Color.TRANSPARENT);
t.cancel();
I assume to set colors transparent is the only way to hide the fade effect with standard Toast layout.

Custom Splash Screen - Android

Currently my android application shows a black screen with a loading wheel as it processes the user's request i:e as it gets content from the server. I would like to modify this screen to include an icon (image) that fades in and out continuously instead of the loading wheel. Is there any possible way to do it?
Yes, you'll use an Alpha Animation
See here
and here
and lastly here for a good tutorial on Animations with some nice code.
In order to "chain" your animations so that one starts after the other you'll use an Animation listener and start the other one from the onAnimationEnd method callback. Don't forget to put an if statement in there that checks to see if your stuff is done loading otherwise you'll end up with infinite recursion of your fade in and fade out.

Categories

Resources