Fade out like the zoom controls

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Fade out like the zoom controls

Postby Daniel » Sat Jan 23, 2010 2:26 pm

Hello,

I want to place a widget on the mal, which behaves like the zoom control buttons. So that is fades in, if the user taps on the map, and after some seconds of not using it, it should fade out. I hope you can help me with that.

Is there a Timer or something like that, that could help me?

Many thanks
Daniel
Daniel
Freshman
Freshman
 
Posts: 8
Joined: Sun Jan 10, 2010 7:07 pm

Top

Postby Daniel » Sun Jan 24, 2010 2:44 pm

Ok, I solved it on my own :)

I added the following local variables:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. /**
  5.  
  6. * animations constants in milliseconds
  7.  
  8. */
  9.  
  10. private final static int DURATION = 3000, ANIMATION_TIME = 300;
  11.  
  12.  
  13.  
  14. /**
  15.  
  16. * {@link Handler} for the timer
  17.  
  18. */
  19.  
  20. private static Handler mHandler = new Handler();
  21.  
  22.  
  23.  
  24. /**
  25.  
  26. * fade in- and out animations
  27.  
  28. */
  29.  
  30. private static Animation mFadeIn, mFadeOut;
  31.  
  32.  
  33.  
  34. ...
  35.  
  36. // initialize animations
  37.  
  38. mFadeIn = new AlphaAnimation(0, 1);
  39.  
  40. mFadeIn.setDuration(ANIMATION_TIME);
  41.  
  42. mFadeOut = new AlphaAnimation(1, 0);
  43.  
  44. mFadeOut.setDuration(ANIMATION_TIME);
  45.  
  46.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


In the OnTap-method of the map activity, I call the setActive()-method, that starts the animation and the timer.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. /**
  3.  
  4. * setActive sets this {@link DateSeekBar} visible and starts a fade in
  5.  
  6. * animation. It also starts the timer, so that this widget will also fade
  7.  
  8. * out after an idle time.
  9.  
  10. */
  11.  
  12. public static void setActive() {
  13.  
  14.         if (dateSeekBar.getVisibility() != View.VISIBLE)
  15.  
  16.                 dateSeekBar.startAnimation(mFadeIn);
  17.  
  18.         dateSeekBar.setVisibility(View.VISIBLE);
  19.  
  20.         // start timer
  21.  
  22.         mHandler.removeCallbacks(hideSeekBar);
  23.  
  24.         mHandler.postDelayed(hideSeekBar, DURATION);
  25.  
  26. }
  27.  
  28. /**
  29.  
  30. * If this {@link Runnable} is started, the {@link DateSeekBar} will fade
  31.  
  32. * out and be invisible.
  33.  
  34. */
  35.  
  36. private static Runnable hideSeekBar = new Runnable() {
  37.  
  38.         public void run() {
  39.  
  40.                 dateSeekBar.startAnimation(mFadeOut);
  41.  
  42.                 dateSeekBar.setVisibility(View.GONE);
  43.  
  44.                 mHandler.removeCallbacks(hideSeekBar);
  45.  
  46.         }
  47.  
  48. };
  49.  
  50.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


When interacting with the widget, I'm removing the timer with:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. mHandler.removeCallbacks(hideSeekBar);
  3.  
  4.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

and in the stopTrackingTouch-method I'm starting the timer again:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. mHandler.postDelayed(hideSeekBar, DURATION);
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


I hope this can be helpful for anybody out there :)
Daniel
Freshman
Freshman
 
Posts: 8
Joined: Sun Jan 10, 2010 7:07 pm

Postby Draffodx » Tue Jan 26, 2010 11:58 am

Thanks for posting the solution Daniel, will be helpful to me in the future, good write up
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby thetuxracer » Tue Jan 26, 2010 12:03 pm

OOPS!! I ACCIDENTLY POSTED HERE, HAVE LOTS OF THREADS OPEN :(

MY APOLOGIES.
thetuxracer
Developer
Developer
 
Posts: 26
Joined: Mon Jan 04, 2010 7:59 am
Location: Nashik, MH, India

Re: Fade out like the zoom controls

Postby darko1002001 » Thu Sep 02, 2010 12:44 am

Can anybody please explain in more details how do i do this. i cant find anything similar anywhere and its just what i need.

i have made this map layout, and i want the behavior of the relativeLayout containing 3 buttons to be the same as the zoomControls on the MapView.(fade in and out onTouch on the map).

is there anywhere a more detailed tutorial or example of doing this?

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:layout_width="fill_parent"
  4.    android:layout_height="fill_parent">
  5.  
  6.     <com.google.android.maps.MapView
  7.        android:id="@+id/mapView"
  8.        android:layout_width="fill_parent"
  9.        android:layout_height="fill_parent"
  10.        android:enabled="true"
  11.        android:clickable="true"
  12.        android:apiKey="0vcU1EZuLQ8ZReorh1rRSR_k2sOHjl0tz3WnhFA"
  13.        />
  14.  
  15. <RelativeLayout
  16.         android:layout_height="wrap_content" android:layout_width="fill_parent"
  17.         android:background="@color/FadeGray" android:id="@+id/ButtonLayout">
  18.  
  19.         <Button android:layout_height="50dp" android:id="@+id/ButtonStart"
  20.                 android:text="S" android:layout_toLeftOf="@+id/ButtonCurrentLoc"
  21.                 android:layout_width="fill_parent"></Button>
  22.  
  23.  
  24.         <Button android:id="@+id/ButtonCurrentLoc" android:text="C"
  25.                 android:layout_height="50dp" android:layout_width="100dp"
  26.                 android:layout_centerInParent="true"></Button>
  27.  
  28.  
  29.         <Button android:layout_height="50dp" android:id="@+id/ButtonDest"
  30.                 android:text="D" android:layout_alignParentRight="true"
  31.                 android:layout_toRightOf="@+id/ButtonCurrentLoc" android:layout_width="fill_parent"></Button>
  32.  
  33. </RelativeLayout>
  34.  
  35. </RelativeLayout>
Parsed in 0.006 seconds, using GeSHi 1.0.8.4
darko1002001
Junior Developer
Junior Developer
 
Posts: 20
Joined: Sat Jun 26, 2010 12:52 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest