Skip to content

Commit 6c3cde4

Browse files
committed
Add PaintWidget demo
1 parent 0dbe1d1 commit 6c3cde4

File tree

5 files changed

+100
-15
lines changed

5 files changed

+100
-15
lines changed

AndroidUIDemo/AndroidManifest.xml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:versionCode="1"
4-
android:versionName="1.0.0" package="com.oreilly.demo.android.pa.uidemo">
5-
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14" />
6-
<application android:icon="@drawable/icon" android:label="@string/app_name">
7-
<activity android:name=".TouchMe"
8-
android:label="@string/app_name">
3+
package="com.oreilly.demo.android.pa.uidemo"
4+
android:versionCode="1"
5+
android:versionName="1.0.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="8"
9+
android:targetSdkVersion="14" />
10+
11+
<application
12+
android:icon="@drawable/icon"
13+
android:label="@string/app_name" >
14+
<activity
15+
android:name=".TouchMe"
16+
android:label="@string/app_name" >
917
<intent-filter>
1018
<action android:name="android.intent.action.MAIN" />
19+
1120
<category android:name="android.intent.category.LAUNCHER" />
1221
</intent-filter>
1322
</activity>
1423
</application>
15-
</manifest>
24+
25+
</manifest>

AndroidViewDemo/AndroidManifest.xml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:versionCode="1"
4-
android:versionName="1.0.0" package="com.oreilly.demo.android.pa.viewdemo">
5-
<uses-sdk android:targetSdkVersion="14"></uses-sdk>
3+
package="com.oreilly.demo.android.pa.viewdemo"
4+
android:versionCode="1"
5+
android:versionName="1.0.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="10"
9+
android:targetSdkVersion="14" />
10+
611
<application
12+
android:hardwareAccelerated="false"
713
android:icon="@drawable/icon"
8-
android:label="@string/app_name"
9-
android:hardwareAccelerated="true">
10-
<activity android:name=".TransformIt"
11-
android:label="@string/app_name">
14+
android:label="@string/app_name" >
15+
<activity
16+
android:name=".TransformIt"
17+
android:label="@string/app_name" >
1218
<intent-filter>
1319
<action android:name="android.intent.action.MAIN" />
20+
1421
<category android:name="android.intent.category.LAUNCHER" />
1522
</intent-filter>
1623
</activity>
1724
</application>
18-
</manifest>
25+
26+
</manifest>

AndroidViewDemo/res/layout/paint.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent" >
5+
6+
<com.oreilly.demo.android.pa.viewdemo.widget.PaintWidget
7+
android:layout_width="match_parent"
8+
android:layout_height="match_parent" />
9+
10+
</FrameLayout>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.oreilly.demo.android.pa.viewdemo;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
6+
public class PaintActivity extends Activity {
7+
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
setContentView(R.layout.paint);
12+
}
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.oreilly.demo.android.pa.viewdemo.widget;
2+
3+
import android.content.Context;
4+
import android.graphics.Canvas;
5+
import android.graphics.Color;
6+
import android.graphics.Paint;
7+
import android.util.AttributeSet;
8+
import android.view.View;
9+
10+
public class PaintWidget extends View {
11+
12+
public PaintWidget(Context context, AttributeSet attrs, int defStyle) {
13+
this(context);
14+
}
15+
16+
public PaintWidget(Context context, AttributeSet attrs) {
17+
this(context);
18+
}
19+
20+
public PaintWidget(Context context) { super(context); }
21+
22+
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
23+
setMeasuredDimension(100, 100);
24+
}
25+
26+
@Override protected void onDraw(Canvas canvas) {
27+
canvas.drawColor(Color.WHITE);
28+
29+
Paint paint = new Paint();
30+
canvas.drawLine(33, 0, 33, 100, paint);
31+
32+
paint.setColor(Color.RED);
33+
paint.setStrokeWidth(10);
34+
canvas.drawLine(56, 0, 56, 100, paint);
35+
36+
paint.setColor(Color.GREEN);
37+
paint.setStrokeWidth(5);
38+
39+
for (int y = 30, alpha = 255; alpha > 2; alpha >>= 1, y += 10) {
40+
paint.setAlpha(alpha);
41+
canvas.drawLine(0, y, 100, y, paint);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)