Skip to content

Commit 2891f47

Browse files
committed
add ipc and graphics
1 parent 90abb35 commit 2891f47

File tree

90 files changed

+1944
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1944
-0
lines changed

AndroidGraphics/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

AndroidGraphics/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Android graphics 2D绘图机制学习
2+
3+
- [Matrix原理及其API](notes/Matrix.md)

AndroidGraphics/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

AndroidGraphics/app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
buildToolsVersion "26.0.1"
6+
defaultConfig {
7+
applicationId "com.java.bobomee.androidgraphics"
8+
minSdkVersion 15
9+
targetSdkVersion 26
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:26.+'
28+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
29+
testCompile 'junit:junit:4.12'
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/bobomee/Library/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
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.java.bobomee.androidgraphics;
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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest {
18+
@Test public void useAppContext() throws Exception {
19+
// Context of the app under test.
20+
Context appContext = InstrumentationRegistry.getTargetContext();
21+
22+
assertEquals("com.java.bobomee.androidgraphics", appContext.getPackageName());
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.java.bobomee.androidgraphics">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN"/>
15+
16+
<category android:name="android.intent.category.LAUNCHER"/>
17+
</intent-filter>
18+
</activity>
19+
20+
<activity android:name=".matrix.ui.MatrixActivity"/>
21+
<activity android:name=".matrix.ui.MatrixMapActivity"/>
22+
<activity android:name=".matrix.ui.MatrixSetPolyActivity"/>
23+
<activity android:name=".matrix.ui.MatrixSetRectActivity"/>
24+
</application>
25+
26+
</manifest>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.java.bobomee.androidgraphics;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.View;
7+
import com.java.bobomee.androidgraphics.matrix.ui.MatrixActivity;
8+
9+
public class MainActivity extends AppCompatActivity {
10+
11+
@Override protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.activity_main);
14+
}
15+
16+
public void matrix(View v) {
17+
start(MatrixActivity.class);
18+
}
19+
20+
private void start(Class c) {
21+
Intent intent = new Intent(this, c);
22+
startActivity(intent);
23+
}
24+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.java.bobomee.androidgraphics.matrix.ui;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
import com.java.bobomee.androidgraphics.R;
9+
10+
public class MatrixActivity extends AppCompatActivity {
11+
12+
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
15+
setContentView(R.layout.matrix_navigatino_layout);
16+
}
17+
18+
public void map(View v) {
19+
start(MatrixMapActivity.class);
20+
}
21+
22+
public void poly(View v) {
23+
start(MatrixSetPolyActivity.class);
24+
}
25+
26+
public void rect(View v) {
27+
start(MatrixSetRectActivity.class);
28+
}
29+
30+
private void start(Class c) {
31+
Intent intent = new Intent(this, c);
32+
startActivity(intent);
33+
}
34+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.java.bobomee.androidgraphics.matrix.ui;
2+
3+
import android.graphics.Matrix;
4+
import android.graphics.RectF;
5+
import android.os.Bundle;
6+
import android.support.annotation.Nullable;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.util.Log;
9+
import com.java.bobomee.androidgraphics.R;
10+
import java.util.Arrays;
11+
12+
public class MatrixMapActivity extends AppCompatActivity {
13+
14+
private static final String TAG = "MatrixMapActivity";
15+
16+
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.matrix_map_layout);
19+
20+
testMapPoints();
21+
22+
testMapRadius();
23+
24+
testMapRect();
25+
26+
testMapVectors();
27+
}
28+
29+
private void testMapVectors() {
30+
float[] src = new float[] { 1000, 800 };
31+
float[] dst = new float[2];
32+
33+
// 构造一个matrix
34+
Matrix matrix = new Matrix();
35+
matrix.setScale(0.5f, 1f);
36+
matrix.postTranslate(100, 100);
37+
38+
// 计算向量, 不受位移影响
39+
matrix.mapVectors(dst, src);
40+
Log.i(TAG, "mapVectors: " + Arrays.toString(dst));
41+
42+
// 计算点
43+
matrix.mapPoints(dst, src);
44+
Log.i(TAG, "mapPoints: " + Arrays.toString(dst));
45+
}
46+
47+
private void testMapRect() {
48+
RectF rect = new RectF(400, 400, 1000, 800);
49+
50+
// 构造一个matrix
51+
Matrix matrix = new Matrix();
52+
matrix.setScale(0.5f, 1f);
53+
matrix.postSkew(1, 0);
54+
55+
Log.i(TAG, "mapRadius: " + rect.toString());
56+
57+
boolean result = matrix.mapRect(rect);
58+
59+
Log.i(TAG, "mapRadius: " + rect.toString());
60+
Log.e(TAG, "isRect: " + result);
61+
}
62+
63+
private void testMapRadius() {
64+
float radius = 100;
65+
float result = 0;
66+
67+
// 构造一个matrix,x坐标缩放0.5
68+
Matrix matrix = new Matrix();
69+
matrix.setScale(0.5f, 1f);
70+
71+
Log.i(TAG, "mapRadius: " + radius);
72+
73+
result = matrix.mapRadius(radius);
74+
75+
Log.i(TAG, "mapRadius: " + result);
76+
}
77+
78+
private void testMapPoints() {
79+
// 初始数据为三个点 (0, 0) (80, 100) (400, 300)
80+
float[] pts = new float[] { 0, 0, 80, 100, 400, 300 };
81+
82+
// 构造一个matrix,x坐标缩放0.5
83+
Matrix matrix = new Matrix();
84+
matrix.setScale(0.5f, 1f);
85+
86+
// 输出pts计算之前数据
87+
Log.i(TAG, "before: " + Arrays.toString(pts));
88+
89+
// 调用map方法计算
90+
matrix.mapPoints(pts);
91+
92+
// 输出pts计算之后数据
93+
Log.i(TAG, "after : " + Arrays.toString(pts));
94+
}
95+
}

0 commit comments

Comments
 (0)