├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── assets
│ │ │ └── Satisfy-Regular.ttf
│ │ ├── res
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── maps.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── maps.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ └── maps.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ ├── sample_scale.xml
│ │ │ │ ├── sample_skew.xml
│ │ │ │ ├── sample_rotate.xml
│ │ │ │ ├── practice_rotate.xml
│ │ │ │ ├── practice_scale.xml
│ │ │ │ ├── sample_clip_path.xml
│ │ │ │ ├── sample_clip_rect.xml
│ │ │ │ ├── sample_flipboard.xml
│ │ │ │ ├── sample_translate.xml
│ │ │ │ ├── practice_clip_path.xml
│ │ │ │ ├── practice_flipboard.xml
│ │ │ │ ├── sample_matrix_scale.xml
│ │ │ │ ├── practice_matrix_skew.xml
│ │ │ │ ├── sample_camera_rotate.xml
│ │ │ │ ├── sample_matrix_rotate.xml
│ │ │ │ ├── practice_camera_rotate.xml
│ │ │ │ ├── practice_matrix_rotate.xml
│ │ │ │ ├── sample_matrix_translate.xml
│ │ │ │ ├── practice_matrix_translate.xml
│ │ │ │ ├── practice_measure_text.xml
│ │ │ │ ├── sample_camera_rotate_fixed.xml
│ │ │ │ ├── sample_camera_rotate_hitting_face.xml
│ │ │ │ ├── practice_camera_rotate_hitting_face.xml
│ │ │ │ ├── sample_matrix_skew.xml
│ │ │ │ ├── practice_skew.xml
│ │ │ │ ├── practice_translate.xml
│ │ │ │ ├── practice_matrix_scale.xml
│ │ │ │ ├── practice_clip_rect.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── fragment_page.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── hencoder
│ │ │ └── hencoderpracticedraw4
│ │ │ ├── practice
│ │ │ ├── Practice01ClipRectView.java
│ │ │ ├── Practice06SkewView.java
│ │ │ ├── Practice04ScaleView.java
│ │ │ ├── Practice05RotateView.java
│ │ │ ├── Practice03TranslateView.java
│ │ │ ├── Practice10MatrixSkewView.java
│ │ │ ├── Practice02ClipPathView.java
│ │ │ ├── Practice08MatrixScaleView.java
│ │ │ ├── Practice09MatrixRotateView.java
│ │ │ ├── Practice11CameraRotateView.java
│ │ │ ├── Practice07MatrixTranslateView.java
│ │ │ ├── Practice12CameraRotateFixedView.java
│ │ │ ├── Practice14FlipboardView.java
│ │ │ └── Practice13CameraRotateHittingFaceView.java
│ │ │ ├── sample
│ │ │ ├── Sample01ClipRectView.java
│ │ │ ├── Sample06SkewView.java
│ │ │ ├── Sample03TranslateView.java
│ │ │ ├── Sample05RotateView.java
│ │ │ ├── Sample04ScaleView.java
│ │ │ ├── Sample07MatrixTranslateView.java
│ │ │ ├── Sample11CameraRotateView.java
│ │ │ ├── Sample02ClipPathView.java
│ │ │ ├── Sample10MatrixSkewView.java
│ │ │ ├── Sample09MatrixRotateView.java
│ │ │ ├── Sample08MatrixScaleView.java
│ │ │ ├── Sample12CameraRotateFixedView.java
│ │ │ ├── Sample14FlipboardView.java
│ │ │ └── Sample13CameraRotateHittingFaceView.java
│ │ │ ├── PageFragment.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── hencoder
│ │ │ └── hencoderpracticedraw4
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── hencoder
│ │ └── hencoderpracticedraw4
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── images
├── icon.png
├── preview.png
├── preview_after.png
├── project_sample.png
└── project_practice.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
├── misc.xml
└── markdown-navigator.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/images/icon.png
--------------------------------------------------------------------------------
/images/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/images/preview.png
--------------------------------------------------------------------------------
/images/preview_after.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/images/preview_after.png
--------------------------------------------------------------------------------
/images/project_sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/images/project_sample.png
--------------------------------------------------------------------------------
/images/project_practice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/images/project_practice.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/assets/Satisfy-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/app/src/main/assets/Satisfy-Regular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/maps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/app/src/main/res/drawable-xhdpi/maps.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/maps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/app/src/main/res/drawable-xxhdpi/maps.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/maps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/app/src/main/res/drawable-xxxhdpi/maps.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hencoder/PracticeDraw4/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_scale.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_skew.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jul 09 11:29:58 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_scale.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_clip_path.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_clip_rect.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_flipboard.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_translate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_clip_path.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_flipboard.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_matrix_scale.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_matrix_skew.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_camera_rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_matrix_rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_camera_rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_matrix_rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_matrix_translate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_matrix_translate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_measure_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_camera_rotate_fixed.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_camera_rotate_hitting_face.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_camera_rotate_hitting_face.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sample_matrix_skew.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_skew.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_translate.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_matrix_scale.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/practice_clip_rect.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/com/hencoder/hencoderpracticedraw4/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | HenCoder 绘制 4 练习项目
4 | ===
5 |
6 | ### 这是什么?
7 |
8 | 这不是一个独立使用的项目,它是 [HenCoder Android 开发进阶:UI 1-4 绘制的辅助](http://hencoder.com/ui-1-4) 的配套练习项目。
9 |
10 | ### 怎么用?
11 |
12 | 项目是一个可以直接运行的 Android App 项目,项目运行后,在手机上打开是这样的:
13 |
14 | 
15 |
16 | 工程下有一个 `/practice` 目录:
17 |
18 | 
19 |
20 | 你要做的是就是,在 `/practice` 下的每一个 `PracticeXxxView.java` 文件中写代码,绘制出和页面上半部分相同的效果。例如写 `Practice01ClipRectView.java` 以绘制出经过平移的图形。就像这样:
21 |
22 | 
23 |
24 | > 当然,没必要做得和示例一毛一样。这是一个练习,而不是一个超级模仿秀,关键是把技能掌握。
25 |
26 | 如果做不出来,可以参考 `/sample` 目录下的代码:
27 |
28 | 
29 |
30 | 练习做完,绘制第四期(绘制的辅助)的内容也就掌握得差不多了。
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/hencoder/hencoderpracticedraw4/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hencoder.hencoderpracticedraw4", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/rengwuxian/.android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HenCoder 绘制 4
3 | clipRect()
4 | clipPath()
5 | translate()
6 | scale()
7 | rotate()
8 | skew()
9 | Matrix.translate()
10 | Matrix.scale()
11 | Matrix.rotate()
12 | Matrix.skew()
13 | Camera.rotateX/Y()
14 | Camera.rotateX/Y() 修正版
15 | Camera.rotateX/Y() 糊脸修正
16 | 翻页效果
17 | setFillPath()
18 | setTextPath()
19 |
20 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 | defaultConfig {
7 | applicationId "com.hencoder.hencoderpracticedraw4"
8 | minSdkVersion 18
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | compile 'com.android.support:support-core-ui:25.3.1'
30 | compile 'com.android.support:design:25.3.1'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_page.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
19 |
20 |
24 |
25 |
29 |
30 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice01ClipRectView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.hencoder.hencoderpracticedraw4.R;
13 |
14 | public class Practice01ClipRectView extends View {
15 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
16 | Bitmap bitmap;
17 |
18 | public Practice01ClipRectView(Context context) {
19 | super(context);
20 | }
21 |
22 | public Practice01ClipRectView(Context context, @Nullable AttributeSet attrs) {
23 | super(context, attrs);
24 | }
25 |
26 | public Practice01ClipRectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | }
29 |
30 | {
31 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
32 | }
33 |
34 | @Override
35 | protected void onDraw(Canvas canvas) {
36 | super.onDraw(canvas);
37 |
38 | int left = (getWidth() - bitmap.getWidth()) / 2;
39 | int top = (getHeight() - bitmap.getHeight()) / 2;
40 |
41 | canvas.drawBitmap(bitmap, left, top, paint);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice06SkewView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice06SkewView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice06SkewView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice06SkewView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice06SkewView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice04ScaleView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice04ScaleView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice04ScaleView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice04ScaleView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice04ScaleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice05RotateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice05RotateView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice05RotateView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice05RotateView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice05RotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice03TranslateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice03TranslateView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice03TranslateView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice03TranslateView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice03TranslateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice10MatrixSkewView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice10MatrixSkewView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice10MatrixSkewView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice10MatrixSkewView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice10MatrixSkewView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice02ClipPathView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Path;
9 | import android.graphics.Point;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Practice02ClipPathView extends View {
17 | Paint paint = new Paint();
18 | Bitmap bitmap;
19 | Point point1 = new Point(200, 200);
20 | Point point2 = new Point(600, 200);
21 |
22 | public Practice02ClipPathView(Context context) {
23 | super(context);
24 | }
25 |
26 | public Practice02ClipPathView(Context context, @Nullable AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | public Practice02ClipPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | }
33 |
34 | {
35 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
36 | }
37 |
38 | @Override
39 | protected void onDraw(Canvas canvas) {
40 | super.onDraw(canvas);
41 |
42 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
43 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice08MatrixScaleView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice08MatrixScaleView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice08MatrixScaleView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice08MatrixScaleView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice08MatrixScaleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice09MatrixRotateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice09MatrixRotateView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice09MatrixRotateView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice09MatrixRotateView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice09MatrixRotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice11CameraRotateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice11CameraRotateView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice11CameraRotateView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice11CameraRotateView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice11CameraRotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice07MatrixTranslateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice07MatrixTranslateView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice07MatrixTranslateView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice07MatrixTranslateView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice07MatrixTranslateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice12CameraRotateFixedView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Practice12CameraRotateFixedView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Practice12CameraRotateFixedView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Practice12CameraRotateFixedView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Practice12CameraRotateFixedView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
42 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample01ClipRectView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.hencoder.hencoderpracticedraw4.R;
13 |
14 | public class Sample01ClipRectView extends View {
15 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
16 | Bitmap bitmap;
17 |
18 | public Sample01ClipRectView(Context context) {
19 | super(context);
20 | }
21 |
22 | public Sample01ClipRectView(Context context, @Nullable AttributeSet attrs) {
23 | super(context, attrs);
24 | }
25 |
26 | public Sample01ClipRectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | }
29 |
30 | {
31 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
32 | }
33 |
34 | @Override
35 | protected void onDraw(Canvas canvas) {
36 | super.onDraw(canvas);
37 |
38 | int left = (getWidth() - bitmap.getWidth()) / 2;
39 | int top = (getHeight() - bitmap.getHeight()) / 2;
40 |
41 | canvas.save();
42 | canvas.clipRect(left + 50, top + 50, left + 300, top + 200);
43 | canvas.drawBitmap(bitmap, left, top, paint);
44 | canvas.restore();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample06SkewView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Sample06SkewView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Sample06SkewView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Sample06SkewView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Sample06SkewView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.save();
42 | canvas.skew(0, 0.5f);
43 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
44 | canvas.restore();
45 |
46 | canvas.save();
47 | canvas.skew(-0.5f, 0);
48 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
49 | canvas.restore();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample03TranslateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Sample03TranslateView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Sample03TranslateView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Sample03TranslateView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Sample03TranslateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | canvas.save();
42 | canvas.translate(-100, -100);
43 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
44 | canvas.restore();
45 |
46 | canvas.save();
47 | canvas.translate(200, 0);
48 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
49 | canvas.restore();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample05RotateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import com.hencoder.hencoderpracticedraw4.R;
14 |
15 | public class Sample05RotateView extends View {
16 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
17 | Bitmap bitmap;
18 | Point point1 = new Point(200, 200);
19 | Point point2 = new Point(600, 200);
20 |
21 | public Sample05RotateView(Context context) {
22 | super(context);
23 | }
24 |
25 | public Sample05RotateView(Context context, @Nullable AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | public Sample05RotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | }
32 |
33 | {
34 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | int bitmapWidth = bitmap.getWidth();
42 | int bitmapHeight = bitmap.getHeight();
43 |
44 | canvas.save();
45 | canvas.rotate(180, point1.x + bitmapWidth / 2, point1.y + bitmapHeight / 2);
46 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
47 | canvas.restore();
48 |
49 | canvas.save();
50 | canvas.rotate(45, point2.x + bitmapWidth / 2, point2.y + bitmapHeight / 2);
51 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
52 | canvas.restore();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample04ScaleView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Point;
9 | import android.graphics.Typeface;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Sample04ScaleView extends View {
17 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | Bitmap bitmap;
19 | Point point1 = new Point(200, 200);
20 | Point point2 = new Point(600, 200);
21 |
22 | public Sample04ScaleView(Context context) {
23 | super(context);
24 | }
25 |
26 | public Sample04ScaleView(Context context, @Nullable AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | public Sample04ScaleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | }
33 |
34 | {
35 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
36 | }
37 |
38 | @Override
39 | protected void onDraw(Canvas canvas) {
40 | super.onDraw(canvas);
41 |
42 | int bitmapWidth = bitmap.getWidth();
43 | int bitmapHeight = bitmap.getHeight();
44 |
45 | canvas.save();
46 | canvas.scale(1.3f, 1.3f, point1.x + bitmapWidth / 2, point1.y + bitmapHeight / 2);
47 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
48 | canvas.restore();
49 |
50 | canvas.save();
51 | canvas.scale(0.6f, 1.6f, point2.x + bitmapWidth / 2, point2.y + bitmapHeight / 2);
52 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
53 | canvas.restore();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample07MatrixTranslateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 | import android.graphics.Point;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Sample07MatrixTranslateView extends View {
17 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | Bitmap bitmap;
19 | Point point1 = new Point(200, 200);
20 | Point point2 = new Point(600, 200);
21 | Matrix matrix = new Matrix();
22 |
23 | public Sample07MatrixTranslateView(Context context) {
24 | super(context);
25 | }
26 |
27 | public Sample07MatrixTranslateView(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public Sample07MatrixTranslateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | {
36 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
37 | }
38 |
39 | @Override
40 | protected void onDraw(Canvas canvas) {
41 | super.onDraw(canvas);
42 |
43 | canvas.save();
44 | matrix.reset();
45 | matrix.postTranslate(-100, -100);
46 | canvas.concat(matrix);
47 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
48 | canvas.restore();
49 |
50 | canvas.save();
51 | matrix.reset();
52 | matrix.postTranslate(200, 0);
53 | canvas.concat(matrix);
54 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
55 | canvas.restore();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample11CameraRotateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Camera;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.Point;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Sample11CameraRotateView extends View {
17 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | Bitmap bitmap;
19 | Point point1 = new Point(200, 100);
20 | Point point2 = new Point(600, 200);
21 | Camera camera = new Camera();
22 |
23 | public Sample11CameraRotateView(Context context) {
24 | super(context);
25 | }
26 |
27 | public Sample11CameraRotateView(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public Sample11CameraRotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | {
36 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
37 | }
38 |
39 | @Override
40 | protected void onDraw(Canvas canvas) {
41 | super.onDraw(canvas);
42 |
43 | canvas.save();
44 | camera.save();
45 | camera.rotateX(30);
46 | camera.applyToCanvas(canvas);
47 | camera.restore();
48 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
49 | canvas.restore();
50 |
51 | canvas.save();
52 | camera.save();
53 | camera.rotateY(30);
54 | camera.applyToCanvas(canvas);
55 | camera.restore();
56 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
57 | canvas.restore();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/PageFragment.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.LayoutRes;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.ViewStub;
11 |
12 | public class PageFragment extends Fragment {
13 | @LayoutRes int sampleLayoutRes;
14 | @LayoutRes int practiceLayoutRes;
15 |
16 | public static PageFragment newInstance(@LayoutRes int sampleLayoutRes, @LayoutRes int practiceLayoutRes) {
17 | PageFragment fragment = new PageFragment();
18 | Bundle args = new Bundle();
19 | args.putInt("sampleLayoutRes", sampleLayoutRes);
20 | args.putInt("practiceLayoutRes", practiceLayoutRes);
21 | fragment.setArguments(args);
22 | return fragment;
23 | }
24 |
25 | @Nullable
26 | @Override
27 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
28 | View view = inflater.inflate(R.layout.fragment_page, container, false);
29 |
30 | ViewStub sampleStub = (ViewStub) view.findViewById(R.id.sampleStub);
31 | sampleStub.setLayoutResource(sampleLayoutRes);
32 | sampleStub.inflate();
33 |
34 | ViewStub practiceStub = (ViewStub) view.findViewById(R.id.practiceStub);
35 | practiceStub.setLayoutResource(practiceLayoutRes);
36 | practiceStub.inflate();
37 |
38 | return view;
39 | }
40 |
41 | @Override
42 | public void onCreate(@Nullable Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | Bundle args = getArguments();
45 | if (args != null) {
46 | sampleLayoutRes = args.getInt("sampleLayoutRes");
47 | practiceLayoutRes = args.getInt("practiceLayoutRes");
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample02ClipPathView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Path;
9 | import android.graphics.Point;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Sample02ClipPathView extends View {
17 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | Bitmap bitmap;
19 | Path path1 = new Path();
20 | Path path2 = new Path();
21 | Point point1 = new Point(200, 200);
22 | Point point2 = new Point(600, 200);
23 |
24 | public Sample02ClipPathView(Context context) {
25 | super(context);
26 | }
27 |
28 | public Sample02ClipPathView(Context context, @Nullable AttributeSet attrs) {
29 | super(context, attrs);
30 | }
31 |
32 | public Sample02ClipPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | }
35 |
36 | {
37 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
38 |
39 | path1.addCircle(point1.x + 200, point1.y + 200, 150, Path.Direction.CW);
40 |
41 | path2.setFillType(Path.FillType.INVERSE_WINDING);
42 | path2.addCircle(point2.x + 200, point2.y + 200, 150, Path.Direction.CW);
43 | }
44 |
45 | @Override
46 | protected void onDraw(Canvas canvas) {
47 | super.onDraw(canvas);
48 |
49 | canvas.save();
50 | canvas.clipPath(path1);
51 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
52 | canvas.restore();
53 |
54 | canvas.save();
55 | canvas.clipPath(path2);
56 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
57 | canvas.restore();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample10MatrixSkewView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 | import android.graphics.Point;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Sample10MatrixSkewView extends View {
17 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | Bitmap bitmap;
19 | Point point1 = new Point(200, 200);
20 | Point point2 = new Point(600, 200);
21 | Matrix matrix = new Matrix();
22 |
23 | public Sample10MatrixSkewView(Context context) {
24 | super(context);
25 | }
26 |
27 | public Sample10MatrixSkewView(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public Sample10MatrixSkewView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | {
36 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
37 | }
38 |
39 | @Override
40 | protected void onDraw(Canvas canvas) {
41 | super.onDraw(canvas);
42 |
43 | int bitmapWidth = bitmap.getWidth();
44 | int bitmapHeight = bitmap.getHeight();
45 |
46 | canvas.save();
47 | matrix.reset();
48 | matrix.postSkew(0, 0.5f, point1.x + bitmapWidth / 2, point1.y + bitmapHeight / 2);
49 | canvas.concat(matrix);
50 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
51 | canvas.restore();
52 |
53 | canvas.save();
54 | matrix.reset();
55 | matrix.postSkew(-0.5f, 0, point2.x + bitmapWidth / 2, point2.y + bitmapHeight / 2);
56 | canvas.concat(matrix);
57 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
58 | canvas.restore();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample09MatrixRotateView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 | import android.graphics.Point;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Sample09MatrixRotateView extends View {
17 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | Bitmap bitmap;
19 | Point point1 = new Point(200, 200);
20 | Point point2 = new Point(600, 200);
21 | Matrix matrix = new Matrix();
22 |
23 | public Sample09MatrixRotateView(Context context) {
24 | super(context);
25 | }
26 |
27 | public Sample09MatrixRotateView(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public Sample09MatrixRotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | {
36 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
37 | }
38 |
39 | @Override
40 | protected void onDraw(Canvas canvas) {
41 | super.onDraw(canvas);
42 |
43 | int bitmapWidth = bitmap.getWidth();
44 | int bitmapHeight = bitmap.getHeight();
45 |
46 | canvas.save();
47 | matrix.reset();
48 | matrix.postRotate(180, point1.x + bitmapWidth / 2, point1.y + bitmapHeight / 2);
49 | canvas.concat(matrix);
50 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
51 | canvas.restore();
52 |
53 | canvas.save();
54 | matrix.reset();
55 | matrix.postRotate(45, point2.x + bitmapWidth / 2, point2.y + bitmapHeight / 2);
56 | canvas.concat(matrix);
57 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
58 | canvas.restore();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample08MatrixScaleView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 | import android.graphics.Point;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.hencoder.hencoderpracticedraw4.R;
15 |
16 | public class Sample08MatrixScaleView extends View {
17 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
18 | Bitmap bitmap;
19 | Point point1 = new Point(200, 200);
20 | Point point2 = new Point(600, 200);
21 | Matrix matrix = new Matrix();
22 |
23 | public Sample08MatrixScaleView(Context context) {
24 | super(context);
25 | }
26 |
27 | public Sample08MatrixScaleView(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public Sample08MatrixScaleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | {
36 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
37 | }
38 |
39 | @Override
40 | protected void onDraw(Canvas canvas) {
41 | super.onDraw(canvas);
42 |
43 | int bitmapWidth = bitmap.getWidth();
44 | int bitmapHeight = bitmap.getHeight();
45 |
46 | canvas.save();
47 | matrix.reset();
48 | matrix.postScale(1.3f, 1.3f, point1.x + bitmapWidth / 2, point1.y + bitmapHeight / 2);
49 | canvas.concat(matrix);
50 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
51 | canvas.restore();
52 |
53 | canvas.save();
54 | matrix.reset();
55 | matrix.postScale(0.6f, 1.6f, point2.x + bitmapWidth / 2, point2.y + bitmapHeight / 2);
56 | canvas.concat(matrix);
57 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
58 | canvas.restore();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample12CameraRotateFixedView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Camera;
7 | import android.graphics.Canvas;
8 | import android.graphics.Matrix;
9 | import android.graphics.Paint;
10 | import android.graphics.Point;
11 | import android.support.annotation.Nullable;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 |
15 | import com.hencoder.hencoderpracticedraw4.R;
16 |
17 | public class Sample12CameraRotateFixedView extends View {
18 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
19 | Bitmap bitmap;
20 | Point point1 = new Point(200, 200);
21 | Point point2 = new Point(600, 200);
22 | Camera camera = new Camera();
23 | Matrix matrix = new Matrix();
24 |
25 | public Sample12CameraRotateFixedView(Context context) {
26 | super(context);
27 | }
28 |
29 | public Sample12CameraRotateFixedView(Context context, @Nullable AttributeSet attrs) {
30 | super(context, attrs);
31 | }
32 |
33 | public Sample12CameraRotateFixedView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | }
36 |
37 | {
38 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
39 | }
40 |
41 | @Override
42 | protected void onDraw(Canvas canvas) {
43 | super.onDraw(canvas);
44 |
45 | int bitmapWidth = bitmap.getWidth();
46 | int bitmapHeight = bitmap.getHeight();
47 | int center1X = point1.x + bitmapWidth / 2;
48 | int center1Y = point1.y + bitmapHeight / 2;
49 | int center2X = point2.x + bitmapWidth / 2;
50 | int center2Y = point2.y + bitmapHeight / 2;
51 |
52 | camera.save();
53 | matrix.reset();
54 | camera.rotateX(30);
55 | camera.getMatrix(matrix);
56 | camera.restore();
57 | matrix.preTranslate(-center1X, -center1Y);
58 | matrix.postTranslate(center1X, center1Y);
59 | canvas.save();
60 | canvas.concat(matrix);
61 | canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
62 | canvas.restore();
63 |
64 | camera.save();
65 | matrix.reset();
66 | camera.rotateY(30);
67 | camera.getMatrix(matrix);
68 | camera.restore();
69 | matrix.preTranslate(-center2X, -center2Y);
70 | matrix.postTranslate(center2X, center2Y);
71 | canvas.save();
72 | canvas.concat(matrix);
73 | canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
74 | canvas.restore();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice14FlipboardView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.Camera;
9 | import android.graphics.Canvas;
10 | import android.graphics.Paint;
11 | import android.support.annotation.Nullable;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 | import android.view.animation.LinearInterpolator;
15 |
16 | import com.hencoder.hencoderpracticedraw4.R;
17 |
18 | public class Practice14FlipboardView extends View {
19 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
20 | Bitmap bitmap;
21 | Camera camera = new Camera();
22 | int degree;
23 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "degree", 0, 180);
24 |
25 | public Practice14FlipboardView(Context context) {
26 | super(context);
27 | }
28 |
29 | public Practice14FlipboardView(Context context, @Nullable AttributeSet attrs) {
30 | super(context, attrs);
31 | }
32 |
33 | public Practice14FlipboardView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | }
36 |
37 | {
38 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
39 |
40 | animator.setDuration(2500);
41 | animator.setInterpolator(new LinearInterpolator());
42 | animator.setRepeatCount(ValueAnimator.INFINITE);
43 | animator.setRepeatMode(ValueAnimator.REVERSE);
44 | }
45 |
46 | @Override
47 | protected void onAttachedToWindow() {
48 | super.onAttachedToWindow();
49 | animator.start();
50 | }
51 |
52 | @Override
53 | protected void onDetachedFromWindow() {
54 | super.onDetachedFromWindow();
55 | animator.end();
56 | }
57 |
58 | @SuppressWarnings("unused")
59 | public void setDegree(int degree) {
60 | this.degree = degree;
61 | invalidate();
62 | }
63 |
64 | @Override
65 | protected void onDraw(Canvas canvas) {
66 | super.onDraw(canvas);
67 |
68 | int bitmapWidth = bitmap.getWidth();
69 | int bitmapHeight = bitmap.getHeight();
70 | int centerX = getWidth() / 2;
71 | int centerY = getHeight() / 2;
72 | int x = centerX - bitmapWidth / 2;
73 | int y = centerY - bitmapHeight / 2;
74 |
75 | canvas.save();
76 |
77 | camera.save();
78 | camera.rotateX(degree);
79 | canvas.translate(centerX, centerY);
80 | camera.applyToCanvas(canvas);
81 | canvas.translate(-centerX, -centerY);
82 | camera.restore();
83 |
84 | canvas.drawBitmap(bitmap, x, y, paint);
85 | canvas.restore();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/practice/Practice13CameraRotateHittingFaceView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.practice;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.Camera;
9 | import android.graphics.Canvas;
10 | import android.graphics.Matrix;
11 | import android.graphics.Paint;
12 | import android.graphics.Point;
13 | import android.support.annotation.Nullable;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 | import android.view.animation.LinearInterpolator;
17 |
18 | import com.hencoder.hencoderpracticedraw4.R;
19 |
20 | public class Practice13CameraRotateHittingFaceView extends View {
21 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
22 | Bitmap bitmap;
23 | Point point = new Point(200, 50);
24 | Camera camera = new Camera();
25 | Matrix matrix = new Matrix();
26 | int degree;
27 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "degree", 0, 360);
28 |
29 | public Practice13CameraRotateHittingFaceView(Context context) {
30 | super(context);
31 | }
32 |
33 | public Practice13CameraRotateHittingFaceView(Context context, @Nullable AttributeSet attrs) {
34 | super(context, attrs);
35 | }
36 |
37 | public Practice13CameraRotateHittingFaceView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
38 | super(context, attrs, defStyleAttr);
39 | }
40 |
41 | {
42 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
43 | Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * 2, bitmap.getHeight() * 2, true);
44 | bitmap.recycle();
45 | bitmap = scaledBitmap;
46 |
47 | animator.setDuration(5000);
48 | animator.setInterpolator(new LinearInterpolator());
49 | animator.setRepeatCount(ValueAnimator.INFINITE);
50 | }
51 |
52 | @Override
53 | protected void onAttachedToWindow() {
54 | super.onAttachedToWindow();
55 | animator.start();
56 | }
57 |
58 | @Override
59 | protected void onDetachedFromWindow() {
60 | super.onDetachedFromWindow();
61 | animator.end();
62 | }
63 |
64 | @SuppressWarnings("unused")
65 | public void setDegree(int degree) {
66 | this.degree = degree;
67 | invalidate();
68 | }
69 |
70 | @Override
71 | protected void onDraw(Canvas canvas) {
72 | super.onDraw(canvas);
73 |
74 | int bitmapWidth = bitmap.getWidth();
75 | int bitmapHeight = bitmap.getHeight();
76 | int centerX = point.x + bitmapWidth / 2;
77 | int centerY = point.y + bitmapHeight / 2;
78 |
79 | camera.save();
80 | matrix.reset();
81 | camera.rotateX(degree);
82 | camera.getMatrix(matrix);
83 | camera.restore();
84 | matrix.preTranslate(-centerX, -centerY);
85 | matrix.postTranslate(centerX, centerY);
86 | canvas.save();
87 | canvas.concat(matrix);
88 | canvas.drawBitmap(bitmap, point.x, point.y, paint);
89 | canvas.restore();
90 | }
91 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample14FlipboardView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.Camera;
9 | import android.graphics.Canvas;
10 | import android.graphics.Paint;
11 | import android.support.annotation.Nullable;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 | import android.view.animation.LinearInterpolator;
15 |
16 | import com.hencoder.hencoderpracticedraw4.R;
17 |
18 | public class Sample14FlipboardView extends View {
19 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
20 | Bitmap bitmap;
21 | Camera camera = new Camera();
22 | int degree;
23 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "degree", 0, 180);
24 |
25 | public Sample14FlipboardView(Context context) {
26 | super(context);
27 | }
28 |
29 | public Sample14FlipboardView(Context context, @Nullable AttributeSet attrs) {
30 | super(context, attrs);
31 | }
32 |
33 | public Sample14FlipboardView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | }
36 |
37 | {
38 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
39 |
40 | animator.setDuration(2500);
41 | animator.setInterpolator(new LinearInterpolator());
42 | animator.setRepeatCount(ValueAnimator.INFINITE);
43 | animator.setRepeatMode(ValueAnimator.REVERSE);
44 | }
45 |
46 | @Override
47 | protected void onAttachedToWindow() {
48 | super.onAttachedToWindow();
49 | animator.start();
50 | }
51 |
52 | @Override
53 | protected void onDetachedFromWindow() {
54 | super.onDetachedFromWindow();
55 | animator.end();
56 | }
57 |
58 | @SuppressWarnings("unused")
59 | public void setDegree(int degree) {
60 | this.degree = degree;
61 | invalidate();
62 | }
63 |
64 | @Override
65 | protected void onDraw(Canvas canvas) {
66 | super.onDraw(canvas);
67 |
68 | int bitmapWidth = bitmap.getWidth();
69 | int bitmapHeight = bitmap.getHeight();
70 | int centerX = getWidth() / 2;
71 | int centerY = getHeight() / 2;
72 | int x = centerX - bitmapWidth / 2;
73 | int y = centerY - bitmapHeight / 2;
74 |
75 | // 第一遍绘制:上半部分
76 | canvas.save();
77 | canvas.clipRect(0, 0, getWidth(), centerY);
78 | canvas.drawBitmap(bitmap, x, y, paint);
79 | canvas.restore();
80 |
81 | // 第二遍绘制:下半部分
82 | canvas.save();
83 |
84 | if (degree < 90) {
85 | canvas.clipRect(0, centerY, getWidth(), getHeight());
86 | } else {
87 | canvas.clipRect(0, 0, getWidth(), centerY);
88 | }
89 | camera.save();
90 | camera.rotateX(degree);
91 | canvas.translate(centerX, centerY);
92 | camera.applyToCanvas(canvas);
93 | canvas.translate(-centerX, -centerY);
94 | camera.restore();
95 |
96 | canvas.drawBitmap(bitmap, x, y, paint);
97 | canvas.restore();
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/sample/Sample13CameraRotateHittingFaceView.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4.sample;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.Camera;
9 | import android.graphics.Canvas;
10 | import android.graphics.Matrix;
11 | import android.graphics.Paint;
12 | import android.graphics.Point;
13 | import android.support.annotation.Nullable;
14 | import android.util.AttributeSet;
15 | import android.util.DisplayMetrics;
16 | import android.view.View;
17 | import android.view.animation.LinearInterpolator;
18 |
19 | import com.hencoder.hencoderpracticedraw4.R;
20 |
21 | public class Sample13CameraRotateHittingFaceView extends View {
22 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
23 | Bitmap bitmap;
24 | Point point = new Point(200, 50);
25 | Camera camera = new Camera();
26 | Matrix matrix = new Matrix();
27 | int degree;
28 | ObjectAnimator animator = ObjectAnimator.ofInt(this, "degree", 0, 360);
29 |
30 | public Sample13CameraRotateHittingFaceView(Context context) {
31 | super(context);
32 | }
33 |
34 | public Sample13CameraRotateHittingFaceView(Context context, @Nullable AttributeSet attrs) {
35 | super(context, attrs);
36 | }
37 |
38 | public Sample13CameraRotateHittingFaceView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
39 | super(context, attrs, defStyleAttr);
40 | }
41 |
42 | {
43 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.maps);
44 | Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * 2, bitmap.getHeight() * 2, true);
45 | bitmap.recycle();
46 | bitmap = scaledBitmap;
47 |
48 | animator.setDuration(5000);
49 | animator.setInterpolator(new LinearInterpolator());
50 | animator.setRepeatCount(ValueAnimator.INFINITE);
51 |
52 | DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
53 | float newZ = - displayMetrics.density * 6;
54 | camera.setLocation(0, 0, newZ);
55 | }
56 |
57 | @Override
58 | protected void onAttachedToWindow() {
59 | super.onAttachedToWindow();
60 | animator.start();
61 | }
62 |
63 | @Override
64 | protected void onDetachedFromWindow() {
65 | super.onDetachedFromWindow();
66 | animator.end();
67 | }
68 |
69 | @SuppressWarnings("unused")
70 | public void setDegree(int degree) {
71 | this.degree = degree;
72 | invalidate();
73 | }
74 |
75 | @Override
76 | protected void onDraw(Canvas canvas) {
77 | super.onDraw(canvas);
78 |
79 | int bitmapWidth = bitmap.getWidth();
80 | int bitmapHeight = bitmap.getHeight();
81 | int centerX = point.x + bitmapWidth / 2;
82 | int centerY = point.y + bitmapHeight / 2;
83 |
84 | camera.save();
85 | matrix.reset();
86 | camera.rotateX(degree);
87 | camera.getMatrix(matrix);
88 | camera.restore();
89 | matrix.preTranslate(-centerX, -centerY);
90 | matrix.postTranslate(centerX, centerY);
91 | canvas.save();
92 | canvas.concat(matrix);
93 | canvas.drawBitmap(bitmap, point.x, point.y, paint);
94 | canvas.restore();
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hencoder/hencoderpracticedraw4/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hencoder.hencoderpracticedraw4;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.LayoutRes;
5 | import android.support.annotation.StringRes;
6 | import android.support.design.widget.TabLayout;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.app.FragmentPagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.view.Menu;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 | TabLayout tabLayout;
18 | ViewPager pager;
19 | List pageModels = new ArrayList<>();
20 |
21 | {
22 | pageModels.add(new PageModel(R.layout.sample_clip_rect, R.string.title_clip_rect, R.layout.practice_clip_rect));
23 | pageModels.add(new PageModel(R.layout.sample_clip_path, R.string.title_clip_path, R.layout.practice_clip_path));
24 | pageModels.add(new PageModel(R.layout.sample_translate, R.string.title_translate, R.layout.practice_translate));
25 | pageModels.add(new PageModel(R.layout.sample_scale, R.string.title_scale, R.layout.practice_scale));
26 | pageModels.add(new PageModel(R.layout.sample_rotate, R.string.title_rotate, R.layout.practice_rotate));
27 | pageModels.add(new PageModel(R.layout.sample_skew, R.string.title_skew, R.layout.practice_skew));
28 | pageModels.add(new PageModel(R.layout.sample_matrix_translate, R.string.title_matrix_translate, R.layout.practice_matrix_translate));
29 | pageModels.add(new PageModel(R.layout.sample_matrix_scale, R.string.title_matrix_scale, R.layout.practice_matrix_scale));
30 | pageModels.add(new PageModel(R.layout.sample_matrix_rotate, R.string.title_matrix_rotate, R.layout.practice_matrix_rotate));
31 | pageModels.add(new PageModel(R.layout.sample_matrix_skew, R.string.title_matrix_skew, R.layout.practice_matrix_skew));
32 | pageModels.add(new PageModel(R.layout.sample_camera_rotate, R.string.title_camera_rotate, R.layout.practice_camera_rotate));
33 | pageModels.add(new PageModel(R.layout.sample_camera_rotate_fixed, R.string.title_camera_rotate_fixed, R.layout.practice_measure_text));
34 | pageModels.add(new PageModel(R.layout.sample_camera_rotate_hitting_face, R.string.title_camera_rotate_hitting_face, R.layout.practice_camera_rotate_hitting_face));
35 | pageModels.add(new PageModel(R.layout.sample_flipboard, R.string.title_flipboard, R.layout.practice_flipboard));
36 | }
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_main);
42 |
43 | pager = (ViewPager) findViewById(R.id.pager);
44 | pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
45 |
46 | @Override
47 | public Fragment getItem(int position) {
48 | PageModel pageModel = pageModels.get(position);
49 | return PageFragment.newInstance(pageModel.sampleLayoutRes, pageModel.practiceLayoutRes);
50 | }
51 |
52 | @Override
53 | public int getCount() {
54 | return pageModels.size();
55 | }
56 |
57 | @Override
58 | public CharSequence getPageTitle(int position) {
59 | return getString(pageModels.get(position).titleRes);
60 | }
61 | });
62 |
63 | tabLayout = (TabLayout) findViewById(R.id.tabLayout);
64 | tabLayout.setupWithViewPager(pager);
65 | }
66 |
67 | @Override
68 | public boolean onCreateOptionsMenu(Menu menu) {
69 | return super.onCreateOptionsMenu(menu);
70 | }
71 |
72 | private class PageModel {
73 | @LayoutRes int sampleLayoutRes;
74 | @StringRes int titleRes;
75 | @LayoutRes int practiceLayoutRes;
76 |
77 | PageModel(@LayoutRes int sampleLayoutRes, @StringRes int titleRes, @LayoutRes int practiceLayoutRes) {
78 | this.sampleLayoutRes = sampleLayoutRes;
79 | this.titleRes = titleRes;
80 | this.practiceLayoutRes = practiceLayoutRes;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------