/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/ZANaviBusySpinner.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/ZANaviBusySpinner.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (show annotations) (download)
Sun Jun 17 08:12:47 2012 UTC (11 years, 9 months ago) by zoff99
File size: 3326 byte(s)
lots of new stuff and fixes
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 package com.zoffcc.applications.zanavi;
21
22 import android.content.Context;
23 import android.graphics.Canvas;
24 import android.graphics.Color;
25 import android.graphics.Paint;
26 import android.graphics.Paint.Style;
27 import android.graphics.RectF;
28 import android.view.animation.Animation;
29 import android.view.animation.LinearInterpolator;
30 import android.view.animation.RotateAnimation;
31 import android.widget.ImageView;
32
33 public class ZANaviBusySpinner extends ImageView
34 {
35 int mCanvasWidth;
36 int mCanvasHeight;
37 Paint paint;
38 RectF r;
39 int spinner_width;
40 public static final int spinner_size = 35;
41 public static Boolean active;
42 static RotateAnimation rotateAnim = null;
43
44 public ZANaviBusySpinner(Context context)
45 {
46 super(context);
47 spinner_width = 12;
48
49 this.paint = new Paint();
50 this.paint.setColor(Color.BLUE);
51 this.paint.setAlpha(150);
52 rotateAnim = null;
53 paint.setAntiAlias(true);
54 paint.setStrokeWidth(spinner_width);
55 paint.setStyle(Style.STROKE);
56 ZANaviBusySpinner.active = false;
57 this.r = new RectF(1, 1, 1, 1);
58 }
59
60 public void onSizeChanged(int w, int h, int oldw, int oldh)
61 {
62 super.onSizeChanged(w, h, oldw, oldh);
63 this.mCanvasWidth = w;
64 this.mCanvasHeight = h;
65 this.r = new RectF((this.mCanvasWidth / 2) - spinner_size, (this.mCanvasHeight / 2) - spinner_size, (this.mCanvasWidth / 2) + spinner_size, (this.mCanvasHeight / 2) + spinner_size);
66 cancelAnim(); // calc new since w,h has changed
67 }
68
69 private void createAnim(Canvas canvas)
70 {
71 try
72 {
73 rotateAnim = new RotateAnimation(0f, 359f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
74 rotateAnim.setRepeatMode(Animation.RESTART);
75 rotateAnim.setRepeatCount(Animation.INFINITE);
76 rotateAnim.setDuration(2600L); // speed of the animation, higher value = lower speed
77 rotateAnim.setInterpolator(new LinearInterpolator());
78 startAnimation(rotateAnim);
79 }
80 catch (Exception e)
81 {
82
83 }
84 }
85
86 static void cancelAnim()
87 {
88 try
89 {
90 rotateAnim.cancel();
91 rotateAnim.reset();
92 // System.out.println("ZANaviBusySpinner cancel");
93 }
94 catch (Exception e)
95 {
96
97 }
98
99 try
100 {
101 // System.out.println("ZANaviBusySpinner null");
102 rotateAnim = null;
103 }
104 catch (Exception e)
105 {
106
107 }
108
109 }
110
111 public void onDraw(Canvas c)
112 {
113 if (ZANaviBusySpinner.active)
114 {
115 if (rotateAnim == null)
116 {
117 createAnim(c);
118 }
119
120 // System.out.println("ZANaviBusySpinner draw");
121 c.drawArc(this.r, 0, 310, false, this.paint);
122 }
123 }
124 }

   
Visit the ZANavi Wiki