Animation question. - Android Software Development

I have an activity that is a blank screen except for one ImageView object that has it's gravity set to center. Then in my res\anim directory, I animate that image, basically moving it from the bottom of the screen to the center (rising up), using <translate>. What I'm trying to figure out how to do is have the activity load with a blank screen, not showing the ImageView until after the animation finishes with the image centered. What happens right now is the screen shows with the image already in the center, then the animation takes over and moves it from bottom to top. How Can I make the animation happen first, before showing the ImageView?

//Default:
imageView.setVisibility(View.INVISIBLE);
onAnimationStart() {
imageView.setVisibility(View.VISIBLE);
}

The .setVisibilty works, but it's led me to another problem. In my xml layout file for this activity, I only have 2 objects, a TextView at the top of the screen (using LinearLayout) and then an ImageView that is set to.
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView android:id="@+id/Image01"
android:src="@drawable/image_01"
android:layout_height="150dp"
android:layout_width="200dp"
androidaddingTop="10px"
>
</ImageView>
</LinearLayout>
This puts the image dead center of the screen. What I want the animation to do is have the image rise from the bottom of the screen to the center. The problem is that even if I have the .setVisibility to INVISIBLE in the onCreate, then set to VISIBLE after I start the animation, it still flashes the image in the dead center of the screen (for about half a second), then immediately drops to the bottom and rises back up to center. This looks sloppy. How can I make the image never show until appears at bottom then rise to the center? I beg for specifics, as I'm just getting feet wet with java and xml.

Never mind, this only seems to happen in the emulator. It works fine on the phone.

Related

Android animated widget homescreen

Hi,
I was just wondering, is there any way to have an animated widget on the android homescreen, which stays animated and consists of multiple frames? For instance, an animated flash, gif or png sequence?
Thanks
i never used animations on an app, but try it with gifs, or looped zip files, like bootanimation.zip, that creates an animated picture, from multiple files.
ilendemli said:
i never used animations on an app, but try it with gifs, or looped zip files, like bootanimation.zip, that creates an animated picture, from multiple files.
Click to expand...
Click to collapse
And this can be used as a simple widget?
don't know, wait for other posts, you can make a onclicklistener to an image
I'm not talking from experience here, but since widgets update in real time (facebook and twitter for example), there's obviously a method of updating what's displayed so I can't see any reason that you couldn't have an animated widget (other than the usual CPU and battery issues).
maybe develop a service that is constantly pushing messages to the widget? but I suppose this will be a huge battery drainer....
There should be a way to do it. After all, under the "res" folder, there is a supported and standard sub-directory called "anim" that can be used to bring compiled animation files to your app. Look into on the android developer site. I'm thinking this is the way to do it.
Here is a reference from the adroid dev site on using a class called AnimationDrawable:
public class
AnimationDrawable
extends DrawableContainer
implements Animatable Runnable
java.lang.Object
↳ android.graphics.drawable.Drawable
↳ android.graphics.drawable.DrawableContainer
↳ android.graphics.drawable.AnimationDrawable
Class Overview
An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.
The simplest way to create a frame-by-frame animation is to define the animation in an XML file, placed in the res/drawable/ folder, and set it as the background to a View object. Then, call run() to start the animation.
An AnimationDrawable defined in XML consists of a single <animation-list> element, and a series of nested <item> tags. Each item defines a frame of the animation. See the example below.
spin_animation.xml file in res/drawable/ folder:
Code:
<!-- Animation frames are wheel0.png -- wheel5.png files inside the
res/drawable/ folder -->
<animation-list android:id="selected" android:oneshot="false">
<item android:drawable="@drawable/wheel0" android:duration="50" />
<item android:drawable="@drawable/wheel1" android:duration="50" />
<item android:drawable="@drawable/wheel2" android:duration="50" />
<item android:drawable="@drawable/wheel3" android:duration="50" />
<item android:drawable="@drawable/wheel4" android:duration="50" />
<item android:drawable="@drawable/wheel5" android:duration="50" />
</animation-list>
Here is the code to load and play this animation.
Code:
// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start()
For more information, see the guide to Animation Resources.
demaxmeister said:
Hi,
I was just wondering, is there any way to have an animated widget on the android homescreen, which stays animated and consists of multiple frames? For instance, an animated flash, gif or png sequence?
Thanks
Click to expand...
Click to collapse
did you ever figure out a simple method to creating an animated simple widget? i was just wondering b/c this is something i too would like to have.
I found this on modaco a few days ago:
http://www.youtube.com/watch?v=G-4k62ln4j4
http://android.modaco.com/content/advent-vega-vega-modaco-com/329946/3d-desktop-plugin/#entry1567646
I think it is for a tablet? Is it possible to port?
Animation in widgets is possible, check my widget.
first off, yes animated widgets are possible. second, animated gifs are not supported natively by ImageView.
http://stackoverflow.com/questions/3660209/android-display-animated-gif
however agif is supported by the WebView so you could make a widget that is just a WebView that displays an animated gif.
http://stackoverflow.com/questions/2702860/how-to-make-animated-gifs-work-from-android-webview
it will suffer performance wise but it would work.
or you could just split the animated gif and make an AnimationDrawable
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
cheers!
Please try Animated Photo Frame Widget
https://play.google.com/store/apps/details?id=com.hikaru.photowidgetad
Bump.
Year 2016, still can't figure out how to animated widget.
Can somebody help me please? I tried to google for it, but all i got was gif animation loops and animations in progress bar. I want to know how do people animate the widgets like that of MIUI, DU battery saver and other weather widgets. Is there a library to do it?

windowIsFloating=true & window size

I'm developing an activity with a floating main window (e.g. windowIsFloating=true in the activity style). Unfortunately, within a floating window my layout (using fill_parent) is not expanded to the full screen size; fill_parent behaves like wrap_content instead. I suppose floating windows are not automatically sized to the regular/maximized window size.
To circumvent this problem, I use the following code to add the layout to my window:
View view = getLayoutInflater().inflate(R.layout.main, null);
setContentView(view, new LayoutParams(width, height));
This renders my layout correctly. However, how do I find out the correct width and height, taking into account decorations like the status bar? According to the documentation, floating windows automatically get the FLAG_LAYOUT_INSET_DECOR set, causing the WindowManager to report inset rectangle needed to ensure the content is not covered by screen decorations. However, I can't find any documentation on how I can retrieve this inset rectangle; does anyone know this?
I've tried many options (all called from my Activity onCreate method), but they all either return non-usefull information or the full screen size, not taking into account the status bar height:
WindowManager.LayoutParams lp = (WindowManager.LayoutParams)getWindow().getAttributes();
Rect rect = getWindow().getDecorView().getBackground().getBounds();
getWindow().getDecorView().getGlobalVisibleRect(rect);
getWindow().getDecorView().getHitRect(rect);
getWindow().getDecorView().getLocalVisibleRect(rect);
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
I'm now using a work-around that simply substracts 38 from the height to account for the status bar, but of course that's not a real solution.
Also, does anyone know whether it is possible to hide or overlay the status bar when using a floating window? Setting windowFullScreen=false only works correctly for non-floating windows.
I believe you can set the theme in xml to remove the status bar in your app.
<activity android:name=".YourClassName" android:theme="@android:style/Theme.NoTitleBar"/>
And
<activity android:name=".YourClassName" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
From something awesome
O yea that is in the AndroidManifest.xml
From something awesome

[Q] Custom progress bar - I need a little help

I'm totally lost right now after trying so many different ways to create a custom progress bar. I'm shooting for something like Catch Notes', it's a perfect example.
Right now, my Action Bar is calling a generic progress bar layout and that works fine. I've attached a picture of what I'm looking for to help even more.
Code:
switch (item.getItemId()) {
case R.id.refresh: //Obviously, this is my refresh Action Bar icon.
item.setActionView(R.layout.progress);
return true;
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ProgressBar>
</LinearLayout>
http://developer.android.com/reference/android/widget/ProgressBar.html
one second...
i just noticed you are already setting your own style
Code:
style="?android:attr/progressBarStyleSmall"
can you post your progressBarStyleSmall.xml and other relevant drawables, layer-lists, shapes, and animations xml files?
i have been trying to make one of these for a while as well.
killersnowman said:
http://developer.android.com/reference/android/widget/ProgressBar.html
can you post your progressBarStyleSmall.xml and other relevant drawables, layer-lists, shapes, and animations xml files?
i have been trying to make one of these for a while as well.
Click to expand...
Click to collapse
The style I'm referencing is the default Android ProgressBar style for a small progress bar. You just drag the small progress bar into your layout.
k well you should look into making your own style. i have styles on the brain so i thought it was a custom one.

"Screenshot" of the whole scrollview (horizontal in vertical)

Hi,
I am developing the app which displays big tableview. I used horizontal scrollview inside the vertical scrollview and now, I would like to take a screenshot of the whole tableview. However, nothing I found is working. It either takes full width but not full height or only the size of the screen.
Thanks

[NST/G] Editing framework-res.apk xml files

I'd like to make a few small changes in the framework-res.apk. I thought this might be "easy", but so far it's not.
I decompiled the apk file using apktool and located the two files I wanted to alter in res/layout. I made the changes, then saved the two edited files.
Next I opened the original framework-res.apk archive with WinRAR and then dragged the edited xml files into the proper location ("store", not "normal" or "compress") and then closed the archive.
Finally, I used CWM to copy the new framework-res.apk back to the NST and rebooted.
Boot loop.
Is it not possible to deal with slightly edited xml files in this way?
nmyshkin said:
I'd like to make a few small changes in the framework-res.apk. I thought this might be "easy", but so far it's not.
I decompiled the apk file using apktool and located the two files I wanted to alter in res/layout. I made the changes, then saved the two edited files.
Next I opened the original framework-res.apk archive with WinRAR and then dragged the edited xml files into the proper location ("store", not "normal" or "compress") and then closed the archive.
Finally, I used CWM to copy the new framework-res.apk back to the NST and rebooted.
Boot loop.
It is not possible to deal with slightly edited xml files in this way?
Click to expand...
Click to collapse
I found a working method: https://forum.xda-developers.com/t/...rk-res-apk-with-apktool.1545361/post-23589640
But...I want to move the quicknav bar to the top of the screen. The changes I made in the xml files do that, but the status bar covers the top part of the quicknav bar. Ideally I'd like the quicknav bar to cover the status bar (maybe not allowed?), or at least position right beneath it.
The relevant xml code which seems to control the screen position of the quicknav bar looks like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@id/quickNavMainView" android:background="@drawable/checker" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:layout_gravity="bottom|center" android:id="@id/quickNavHSView" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_gravity="bottom|center" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@id/home" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_home_normal" />
<ImageView android:id="@id/library" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_library_normal" />
<ImageView android:id="@id/shop" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_shop_normal" />
<ImageView android:id="@id/search" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_search_normal" />
<ImageView android:id="@id/settings" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_settings_normal" />
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
I've changed "bottom" in lines 4 and 5 to "top". That gets the job done, but with the problem mentioned: the status bar covers the top portion of the quicknav bar.
Help?
Changing framework or services or whatever you don't need to go to recovery.
They are just part of Android and have no influence on the Linux.
Code:
# stop
<do stuff>
# start
How about a screen shot?
I don't even think that I've ever even seen the stock QuickNav.
I'm not sure if this frame is the full screen or what.
How about adding android:layout_marginTop="24dp"?
(That dimension was picked out of the air. YMMV)
Renate said:
How about a screen shot?
I don't even think that I've ever even seen the stock QuickNav.
I'm not sure if this frame is the full screen or what.
How about adding android:layout_marginTop="24dp"?
(That dimension was picked out of the air. YMMV)
Click to expand...
Click to collapse
Thanks for the response. I'll try the marginTop idea. I've been looking all over for something like that but just hadn't generated the proper search string I guess.
Getting screenshots was a lot harder than I anticipated. The quicknav bar seems to disable the side hardware buttons when it is displayed but I finally figured out a way to get reasonable shots. You can clearly see the issue with the status bar when the quicknav buttons are moved to the top.
nmyshkin said:
I finally figured out a way to get reasonable shots.
Click to expand...
Click to collapse
What's the matter? You don't like my AdbGrab.exe (in sig)?
Renate said:
I'm not sure if this frame is the full screen or what.
How about adding android:layout_marginTop="24dp"?
(That dimension was picked out of the air. YMMV)
Click to expand...
Click to collapse
You were close (and right, of course)!
The bar becomes a little scrunched for some reason (less white space above and below icons/text) but it just abuts the status bar with android:layout marginTop="18dp". I don't care much about the loss of the white space, so it's on with the rest of my project.
Thanks again for the help.
Hmm, something's screwy.
Maybe try this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@id/quickNavMainView" android:background="@drawable/checker" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="18dp">
<ImageView android:id="@id/home" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_home_normal" />
<ImageView android:id="@id/library" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_library_normal" />
<ImageView android:id="@id/shop" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_shop_normal" />
<ImageView android:id="@id/search" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_search_normal" />
<ImageView android:id="@id/settings" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_settings_normal" />
</LinearLayout>
</FrameLayout>
Renate said:
Hmm, something's screwy.
Maybe try this:
Code:
<?xml version="1.0" encoding="utf-8"?>
...etc.
Click to expand...
Click to collapse
It seems to make no discernible difference. I notice that the line:
Code:
<HorizontalScrollView android:layout_gravity="bottom|center" android:id="@id/quickNavHSView" android:layout_width="fill_parent" android:layout_height="wrap_content">
is missing from your version. That, too, seems to make no difference.
There is another xml file which seems to have something to do with the "appicons" (which are just png images stored in the apk, text included):
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@id/appIcon" android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:layout_gravity="top|left|center" android:id="@id/badgeImage" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</FrameLayout>
Not seeing anything there that jumps out at me. If the android:layout_marginTop="18dp" is changed to something like "100dp" the bar more or less collapses into a fat line, as well as moving further down the display window, so there is some interaction between the "simple" shifting of the vertical display of the bar and the vertical size of the bar itself.
Like I say, it's not a big deal for me. As long as content is not cut off, a slight flattening of quicknav bar is fine.
All the tiles are 120 x 112 so that the horizontal scroll is overblown. (5 x 120 = 600).
I was trying to get rid of that.
Use my only Linear Layout and change layout_height="112dp"
For testing purposes you can also add android:background="#cccccc".
That way if the LL expands but the buttons don't you can see the shading.
Renate said:
All the tiles are 120 x 112 so that the horizontal scroll is overblown. (5 x 120 = 600).
I was trying to get rid of that.
Use my only Linear Layout and change layout_height="112dp"
For testing purposes you can also add android:background="#cccccc".
That way if the LL expands but the buttons don't you can see the shading.
Click to expand...
Click to collapse
Does the android:background="#cccccc" go in the LinearLayout section or in the overall FrameLayout? Right now it's kinda moot because I can't seem to produce an apk file that does not cause a bootloop. I have a previous trial version with android:layout_ marginTop="20dp" which does NOT produce a bootloop. The file size is about 2874 Kb. Every new version I try to build with Apktool today is coming out around 3366 Kb and they all cause a bootloop. I have no idea what is going on with Apktool, but I'll keep plugging away, with breaks for mental health!
nmyshkin said:
Does the android:background="#cccccc" go in the LinearLayout section...
Click to expand...
Click to collapse
In the LL.
When you're floundering in layouts, it's helpful to set some color background for each containing element.
Obviously, on a B&W device you'll not see that, but a screen grab will show it.
(You can just stick to background colors that are differentiable in B&W,)
The FrameLayout is the whole screen which dims the normal screen.
The LinearLayout should be 600 x 120 automatically.
You can even do a reality check by saying (in LL) android:layout_height="500dp".
Renate said:
When you're floundering in layout...
Click to expand...
Click to collapse
I think "floundering" is the operative word here!
Try as I might, I have been unable to produce a framework-res.apk that did not cause a boot loop IF I left out the
Code:
<HorizontalScrollView android:layout_gravity="bottom|center" android:id="@id/quickNavHSView" android:layout_width="fill_parent" android:layout_height="wrap_content">
This is what I have right now:
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@id/quickNavMainView" android:background="@drawable/checker" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:layout_gravity="top|center" android:id="@id/quickNavHSView" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_gravity="top|center" android:layout_width="wrap_content" android:layout_height="112dp" android:layout_marginTop="18dp" android:background="#cccccc">
<ImageView android:id="@id/home" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_home_normal" />
<ImageView android:id="@id/library" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_library_normal" />
<ImageView android:id="@id/shop" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_shop_normal" />
<ImageView android:id="@id/search" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_search_normal" />
<ImageView android:id="@id/settings" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c_quicknav_settings_normal" />
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
I was surprised to find that changing android:layout_gravity="top|center" in the LinearLayout section did NOT move the bar to the top. It was only when I made the change in the HorizontalScrollView that the bar went to the top of the screen (or almost).
I don't see any shading and perhaps the boxes are now even a bit smaller than before (see screenshot below). Again, I could live with this so it's not a deal-breaker for my intended project. It is interesting (and maybe just a little hair-raising) how these things interact in ways that I would not expect.
When you have a "boot loop" (which is just really Android flailing while the Linux is fine) you should check the logcat, it will tell you where the problem is.
I don't know how I missed where that HorizontalScroll was being used.
Yeah, I do. I was accidentally looking for quickNavHsView and not quickNavHSView.
In services.jar, com/android/server/status/StatusBarService uses that.
It must be a HorizontalScroll. You need that.
The quick nav itself is com/android/server/status/BNGossamerQuickNavbar
The default for layouts is top anyway.
Make the LinearLayout big, android:layout_height="300dp".
You won't see any background of the LL until it's bigger than its contents.
Renate said:
Make the LinearLayout big, android:layout_height="300dp".
You won't see any background of the LL until it's bigger than its contents.
Click to expand...
Click to collapse
OK. I did that but I'm not sure exactly what it tells me except that the size of the layout is greater than the size of the actual navbar images? I see this sort of thing when I am designing a scene in Tasker and the background field is larger than the image itself. There I would know what to do. Here....
Also, how does this relate to the squished (cut off?) images in the navbar?
Edit: I take some of this back now that I have looked more closely at the screenshot. The navbar is not so squished, although still not full size. This would suggest that if I make android:layout_height even larger the navbar will return to normal size. And maybe it does not matter since the background is transparent if I don't specify a color?
So, Bob's your uncle.
For the LinearLayout
android:layout_height="152dp" android:layout_marginTop="40dp"
You don't need to add a background.
How are you getting those screenshots and why are they JPEGs?
You can use
Code:
# screenshot /sdcard/snap.png
I forget if AdbGrab works for that.
There is that whole screenshot/screencap/framebuffer thing.
(Also format 1 & formt 2)
Renate said:
So, Bob's your uncle.
For the LinearLayout
android:layout_height="152dp" android:layout_marginTop="40dp"
You don't need to add a background.
How are you getting those screenshots and why are they JPEGs?
You can use
Code:
# screenshot /sdcard/snap.png
I forget if AdbGrab works for that.
There is that whole screenshot/screencap/framebuffer thing.
(Also format 1 & formt 2)
Click to expand...
Click to collapse
Well, that's just nifty! Thanks for looking at this and helping out.
I'm getting the screenshots using my swiss army knife app QuickTiles which includes a screenshot option. This uses the Screenshot Easy app as a plugin. I selected jpeg as the format, could have been png. You may recall that the native screenshot capabilities of the NST leave something to be desired. Screenshots come out with a green cast (or is is blue?) because of some weird color coding which I can't remember now.
Anyway, I normally have Quick Tiles assigned to the "clock" region of the status bar, but I want the quicknav bar there, so I temporarily assigned Quick Tiles to the "n" button. As much as I love Quick Tiles and spent a lot of time figuring it all out, I will be the first to admit that it is sometimes maddeningly slow to open. Other times it is nearly immediate, just like any other app on the NST. The quicknav bar (which I don't use at all), opens instantaneously. Over time and use I've worked my tile selection down to 5 (6 for my NSTG), so I've been thinking about trying to adapt the quicknav bar to replace Quick Tiles. It doesn't have the gee-whiz stuff like the battery percentage, date, and so on, but the response time is what I'm after at this point in my life.

Categories

Resources