Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
84 ligi 1
package org.ligi;
2
 
3
import android.app.Activity;
4
import android.os.Bundle;
5
 
6
import android.app.Activity;
7
import android.os.Bundle;
8
 
9
import android.view.View;
10
import android.widget.TextView;
11
 
12
 
13
import android.app.Activity;
14
import android.content.Context;
15
import android.graphics.*;
16
import android.os.Bundle;
17
import android.os.*;
18
import android.view.View;
19
 
20
import java.util.Random;
21
 
22
import android.view.Window;
23
import android.view.WindowManager;
24
import android.view.KeyEvent;
25
 
26
import android.graphics.Region.Op;
27
 
28
import org.bluez.*;
29
 
30
public class DUBwiseView
31
    extends View
32
    implements DUBwiseDefinitions
33
 
34
 
35
{
36
    private Paint   mPaint = new Paint();
37
 
38
    public static int LCD_CHAR_COUNT=222;
39
    // some images we need
40
    private Bitmap  bg_img,lcd_tiles,lcd_img;
41
 
42
    // pos for scrolling
43
    private int pos=0;
44
 
45
    String str1="";
46
    String[] lcd_lines;
47
    long last_run=0;
48
    int last_key=0;
49
 
50
    int wi,he;
51
    //     Activity context;
52
 
53
 
54
    Activity root;
55
    int lcd_top;
56
    int menu_y=0;
57
 
58
    public DUBwiseView(Context context) {
59
        super(context);
60
        root=(Activity) context;
61
        lcd_lines=new String[main_menu_items.length];
62
        for (int y=0;y<main_menu_items.length;y++)
63
            lcd_lines[y]=" " + main_menu_items[y];
64
 
65
        // needed to get Key Events
66
        setFocusable(true);
67
    }
68
 
69
 
70
    public Bitmap resize_to_screen(Bitmap orig,float x_scale_,float y_scale_)
71
    {
72
        // createa matrix for the manipulation
73
        Matrix matrix = new Matrix();
74
        float x_scale,y_scale;
75
        if (y_scale_!=0f)
76
            y_scale= (getHeight()*y_scale_ )/orig.height();
77
        else // take x_scale
78
            y_scale=(getWidth()*x_scale_ )/orig.width();
79
 
80
        if (x_scale_!=0f)
81
            x_scale= (getWidth()*x_scale_ )/orig.width();
82
        else
83
            x_scale= (getHeight()*y_scale_ )/orig.height();
84
 
85
        matrix.postScale(x_scale , y_scale);
86
        return Bitmap.createBitmap(orig, 0, 0,(int)( orig.width()),(int)( orig.height()), matrix, true);
87
    }
88
 
89
 
90
    public boolean onKeyDown(int keyCode, KeyEvent event)
91
    {
92
        switch ( keyCode)
93
            {
94
            case KeyEvent.KEYCODE_DPAD_DOWN :
95
                menu_y++;
96
                break;
97
 
98
            case KeyEvent.KEYCODE_DPAD_UP :
99
                menu_y--;
100
                break;
101
 
102
            case KeyEvent.KEYCODE_DPAD_CENTER :
103
                root.finish();
104
                break;
105
            }
106
 
107
        last_key=keyCode;
108
        calc_lcd();
109
        invalidate();
110
        return true;
111
    }
112
 
113
    @Override protected void onSizeChanged(int w, int h, int oldw, int oldh)
114
    {
115
 
116
        bg_img = resize_to_screen(BitmapFactory.decodeResource(getResources(), R.drawable.starfield),0f,1f);
117
        lcd_tiles = resize_to_screen(BitmapFactory.decodeResource(getResources(), R.drawable.lcd_green),0.05f*LCD_CHAR_COUNT,0f);
118
        calc_lcd();
119
    }
120
 
121
    public void calc_lcd()
122
    {
123
        lcd_top=getHeight()-lcd_lines.length*lcd_tiles.height();
124
        Paint paint = mPaint;
125
        lcd_img= Bitmap.createBitmap(getWidth(),lcd_lines.length*lcd_tiles.height()+100,false);
126
        Canvas lcd_canvas=new Canvas();
127
 
128
        lcd_canvas.setDevice(lcd_img);
129
        lcd_canvas.drawColor(Color.WHITE);
130
        int char_width=(int)(lcd_tiles.width()/LCD_CHAR_COUNT);
131
        for ( int lcd_line=0 ; lcd_line < lcd_lines.length ; lcd_line++)
132
            for (int char_pos=0;char_pos<20;char_pos++)
133
                {
134
                    int act_char=0;
135
 
136
                    if (char_pos<lcd_lines[lcd_line].length())
137
                        act_char=lcd_lines[lcd_line].charAt(char_pos)-32;
138
 
139
                    if ((menu_y==lcd_line)&& (char_pos==0))
140
                        act_char=30;
141
 
142
                    lcd_canvas.clipRect(new RectF(char_pos*char_width,lcd_tiles.height()*lcd_line,(char_pos+1)*char_width,lcd_tiles.height()*(lcd_line+1)),Op.REPLACE );
143
 
144
                    lcd_canvas.drawBitmap(lcd_tiles,(char_pos-act_char)*(char_width),lcd_tiles.height()*(lcd_line) , paint);
145
 
146
 
147
                }
148
    }
149
 
150
    public void tick()
151
    {
152
        pos--;
153
        pos%=bg_img.getWidth();
154
        //SystemClock.sleep(50);
155
    }
156
 
157
 
158
    @Override protected void onDraw(Canvas canvas) {
159
        tick();
160
 
161
        Paint paint = mPaint;
162
        paint.setAntiAlias(true);
163
 
164
 
165
        canvas.drawBitmap(bg_img,pos,0 , paint);
166
 
167
        if ((bg_img.width()+pos)<(getWidth()))
168
            canvas.drawBitmap(bg_img,pos+bg_img.width(),0 , paint);
169
 
170
        canvas.drawBitmap(lcd_img,0,lcd_top , paint);
171
 
172
        paint.setColor(Color.GREEN);
173
        canvas.drawText("LastKeyCode:"+last_key,10,10,paint);
174
 
175
        invalidate();
176
    }
177
}