blob: 276d55ee9a5e06015818ed1b08d0ab7caa5a6090 [file] [log] [blame]
Dianne Hackbornd459f4b2012-02-27 18:37:40 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.fakeoemfeatures;
18
19import java.util.Random;
20
21import android.content.Context;
22import android.graphics.Canvas;
23import android.graphics.Paint;
24import android.os.Handler;
25import android.os.Message;
26import android.view.View;
27
28/**
29 * Dummy view to emulate stuff an OEM may want to do.
30 */
31public class FakeView extends View {
32 static final long TICK_DELAY = 30*1000; // 30 seconds
33 static final int MSG_TICK = 1;
34
35 final Handler mHandler = new Handler() {
36 @Override public void handleMessage(Message msg) {
37 switch (msg.what) {
38 case MSG_TICK:
39 invalidate();
40 sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
41 break;
42 default:
43 super.handleMessage(msg);
44 break;
45 }
46 }
47 };
48
49 final Paint mPaint = new Paint();
50 final Random mRandom = new Random();
51
52 public FakeView(Context context) {
53 super(context);
54 }
55
56 @Override
57 protected void onAttachedToWindow() {
58 super.onAttachedToWindow();
59 mHandler.sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
60 }
61
62 @Override
63 protected void onDetachedFromWindow() {
64 super.onDetachedFromWindow();
65 mHandler.removeMessages(MSG_TICK);
66 }
67
68 @Override
69 protected void onDraw(Canvas canvas) {
70 super.onDraw(canvas);
71 canvas.drawColor(0xff000000);
72 mPaint.setTextSize(mRandom.nextInt(40) + 10);
73 mPaint.setColor(0xff000000 + mRandom.nextInt(0x1000000));
74 int x = mRandom.nextInt(getWidth()) - (getWidth()/2);
75 int y = mRandom.nextInt(getHeight());
76 canvas.drawText("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
77 x, y, mPaint);
78 }
79}