Android Frame animation does not proceed more than one image - animationdrawable

I have created a folder called anim inside res folder. I have put 9 consequtive images in a folder called drawable inside res folder. Now I have created this:
public class AndroidAnimationActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_screen);
ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
final AnimationDrawable myAnimationDrawable= (AnimationDrawable)myAnimation.getDrawable();
myAnimation.post(new Runnable(){
public void run() {
myAnimationDrawable.start();
}
});
}
}
As you see I am trying to display this animation on a page called about_screen. It only shows the first frame and the rest of the frames are not shown (as animation). I have seen several people having similar problem like me but not exactly the same. I hope someone can help me with this. Please be specific. I am a new android learner. Thanks

Even I faced this problem, and the solution is simple.
The problem is, you are calling myAnimationDrawable.start() inside the onCreate() function.
You have two possible alternatives...
First one, make the animation interactive, so that you can call myAnimationDrawable.start()
inside some onClick() function.
Second option is to call myAnimationDrawable.start() inside View.OnFocusChangeListener(). In this case you don't have to make it interactive.

Related

Loader during Unity IAP Callback

I want to put loader in between dialog boxes come up for the purchase. What is the way for this?
Because when game player press Buy button, he should require to wait for 5 to 10 second depends on internet speed and server response and this process happed 2 to 3 times because multiple dialogs come up within screen.
So in this case, may be player can leave the screen. I want to put the loader so that game player realise that some processing is running in background, he required to wait for some time.
At present I was following completely this code for Unity IAP setup.
Integrating Unity IAP In Your Game
I assume this is for mobile platform but even if its not still the following can be considered:
Simple solution is to create a full screen Image (UI/Panel) object in your UI to block clicks. I would use Animator component (with triggers) to display this panel in front of other UI when there is a background process running.
public class Loader : MonoBehaviour
{
public static Loader Instance;
Animator m_Animator;
public bool Loading {get; private set;}
void Awake()
{
Instance = this; // However make sure there is only one object containing this script in the scene all time.
}
void Start()
{
//This gets the Animator, which should be attached to the GameObject you are intending to animate.
m_Animator = gameObject.GetComponent<Animator>();
Loading = false;
}
public void Show()
{
Loading = true;
m_Animator.SetBool("Loading", Loading); // this will show the panel.
}
public void Hide()
{
Loading = false;
m_Animator.SetBool("Loading", Loading); // this will hide the panel.
}
}
Then in any script which manipulates UI:
public void BuyButtonClicked()
{
Loader.Instance.Show();
// process time taking stuff
Loader.Instance.Hide();
}
You can also create any kind of loading animation as child of panel object using simple images and animation tool inside Unity (for example rotating animation (use fidget spinner, its cool)).
And in case of Android where user have option to leave screen by pressing OS back button you can prevent going back by checking if any loading is in progress by following example:
// code for back button
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
BackButtonPressed();
}
}
void BackButtonPressed()
{
if(Loader.Instance.Loading)
return;
// use back button event. (For example to leave screen)
}
Hope this helps ;)

Plugin Development: IResourceChangeListener called more than once on just one change

I am using IResourceChangeListener to listen to changes in resource.
my code is:
public void createPartControl(Composite parent) {
// Graph will hold all other objects
graph = new Graph(parent, SWT.NONE);
// create the graph with the right nodes and connections.
init();
//listen to changes in the resource.
workspace = ResourcesPlugin.getWorkspace();
resourceChangeListener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
//IResourceDelta delta = event.getDelta();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
init();
System.out.println("Something changed!");
}
});
}
};
workspace.addResourceChangeListener(resourceChangeListener);
}
public void dispose() {
workspace.removeResourceChangeListener(resourceChangeListener);
}
But, when I am doing just one change in the resource, and save it, the listener called more than once! (usually twice, but sometimes even 6 times!!!)
I tried to use delta to see if it's called in the project,folder,file..
and I didn't saw differences between the calls (maybe I didn't used it properly).
I found this link, but I didn't found there solution to solve my problem
IResourceChangeListener being called twice with one change
How can I fix my code?
Thanks.
There is nothing you can do in the listener code to change how many resource change events you get. It depends entirely on how the code making the changes is doing the change.
You may find that IResourceDelta.getKind and IResourceDelta.getFlags return different values in the events. Also something getMovedFromPath and getMovedToPath for rename or move operations.
If it is your code doing the change you can use a WorkspaceJob or WorkspaceModifyOperation to do atomic changes to the workspace which will also reduce the number of resource change events.
You might also want to check that your old listeners are being removed correctly.

StartCoroutine get error NullReferenceException

I have two cs files, Main.cs and Menu.cs. On OnGUI event which is in Main.cs file I call method from Menu.cs.
private void OnGUI()
{
Menu menu=new Menu();
menu.Create_Menu();
}
And in Menu.cs.
public void Create_Menu ()
{
StartCoroutine(LoadCar());
}
private IEnumerator LoadCar()
{
//Load Object
Download download;
download=new Download();
GameObject go = null;
yield return StartCoroutine(LoadAsset("http://aleko-pc/3dobjects?key=1017&objecttype=1","car13",(x)=>{go = x;}));
}
I get error NullReferenceException
UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine)
If I copy private IEnumerator LoadCar() method in Main.cs class, and call from OnGUI it works.
Maybe I do not understant working area of Coroutines, Can any body help me?
First of all the OnGUI method is called every frame and I don't think you want to download the assets every frame.
Second, you need to make sure Menu is derived from MonoBehviour and added to the view hierarchy.
A better approach would be to add Menu as a component to a GameObject (maybe the same that has the Main script attached) and call Create_Menu on the Start method of Menu.

GWT Google Map Api V3 - broken when changing it

It is working fine for me for the first time it is rendered.
But, If I change anything over the map or recreate it, its broken.
Here is the screen shot for how it looks.
Here is a screen shot after I changed the results per page value.
This is my code.
#UiField DivElement mapPanel;
private GoogleMap googleMap;
public void loadAllMarkers(final List<LatLng> markers)
{
if(!markers.isEmpty())
{
final MapOptions options = MapOptions.create();
options.setMapTypeId(MapTypeId.ROADMAP);
googleMap = GoogleMap.create(mapPanel, options);
final LatLngBounds latLngBounds = LatLngBounds.create();
for(LatLng latLng : markers)
{
final MarkerOptions markerOptions = MarkerOptions.create();
markerOptions.setPosition(latLng);
markerOptions.setMap(googleMap);
final Marker marker = Marker.create(markerOptions);
latLngBounds.extend(marker.getPosition());
}
googleMap.setCenter(latLngBounds.getCenter());
googleMap.fitBounds(latLngBounds);
}
}
I am calling the loadAllMarkers() method whenever new results needs to be loaded.
Can someone point out what I am doing wrong here.
This seems to come from the following (which I pulled from a Google+ Community - GWT Maps V3 API):
Brandon DonnelsonMar 5, 2013
I've had this happen and forgotten why it is, but
mapwidget.triggerResize() will reset the tiles. This seems to happen
when the onAttach occurs and animation exists meaning that the div
started smaller and increases in side, but the map has already
attached. At the end of the animation, the map doesn't auto resize.
I'v been meaning to investigate auto resize but I haven't had time to
attack it yet.
In your case, you would call googleMap.triggerResize() after you finish your changes. this solved my problem when I had the exact same issue. I know it's a little late, but I hope it helps!
Another answer there was to extend the Map widget with the following:
#Override
protected void onAttach() {
super.onAttach();
Timer timer = new Timer() {
#Override
public void run() {
resize();
}
};
timer.schedule(5);
}
/*
* This method is called to fix the Map loading issue when opening
* multiple instances of maps in different tabs
* Triggers a resize event to be consumed by google api in order to resize view
* after attach.
*
*/
public void resize() {
LatLng center = this.getCenter();
MapHandlerRegistration.trigger(this, MapEventType.RESIZE);
this.setCenter(center);
}

Catching the scrolling event in gtk#

Which event from which widget should I catch when I need to run some code when ScrolledWindow is scrolled?
Ths widgets tree I am using is:
(my widget : Gtk.Container) > Viewport > ScrolledWindow
I tried many combinations of ScrollEvent, ScrollChild, etc. event handlers connected to all of them, but the only one that runs anything is an event from Viewport that about SetScrollAdjutstments being changed to (x=0,y=0) when the application starts.
You should attach to the GtkAdjustment living in the relevant scrollbar, and react to its "changed" event. Since Scrollbars are Ranges, you use the gtk_range_get_adjustment() call to do this.
unwind's answer was correct.
Just posting my code in case someone needs a full solution:
// in the xxx : Gtk.Container class:
protected override void OnParentSet(Widget previous_parent) {
Parent.ParentSet += HandleParentParentSet;
}
void HandleParentParentSet(object o, ParentSetArgs args) {
ScrolledWindow swn = (o as Widget).Parent as ScrolledWindow;
swn.Vadjustment.ValueChanged += HandleScrollChanged;
}
void HandleScrollChanged(object sender, EventArgs e) {
// vertical value changed
}
If you need to change the parent of any of those widgets, or may need to change the types and change the hardcoded types and handle disconnecting from the previous parent.