├── Sample ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── drawable-xxxhdpi │ │ │ └── miao.png │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── dimens.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ └── layout │ │ │ ├── activity_main.xml │ │ │ ├── activity_see_logcat.xml │ │ │ ├── activity_test_custom_view.xml │ │ │ ├── item_main.xml │ │ │ └── activity_test_rorate3d_animation.xml │ │ ├── java │ │ └── com │ │ │ └── gcssloop │ │ │ └── test │ │ │ ├── base │ │ │ └── BaseActivity.java │ │ │ ├── viewsupport │ │ │ ├── TestCanvasAidUtilsActivity.java │ │ │ ├── TestCustomViewActivity.java │ │ │ ├── TestMorionEventHelperActivity.java │ │ │ ├── TestApiHelperActivity.java │ │ │ └── TestRotate3dAnimationActivity.java │ │ │ ├── date │ │ │ └── MainMenu.java │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ ├── ViewHolder.java │ │ │ └── CommonAdapter.java │ │ │ └── utils │ │ │ └── CrashHandler.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro ├── build.gradle └── Sample.iml ├── Library ├── .gitignore ├── proguard-rules.pro ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── gcssloop │ │ └── view │ │ ├── utils │ │ ├── CanvasUtils.java │ │ ├── DensityUtils.java │ │ ├── MathUtils.java │ │ ├── ViewUtils.java │ │ └── CanvasAidUtils.java │ │ ├── CustomView.java │ │ ├── helper │ │ ├── MotionEventHelper.java │ │ └── ApiHelper.java │ │ └── animation │ │ └── Rotate3dAnimation.java ├── build.gradle └── Library.iml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── ViewSupport.iml ├── gradle.properties ├── gradlew.bat ├── README-EN.md ├── README.md ├── gradlew └── LICENSE /Sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GcsSloop/ViewSupport/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Sample/src/main/res/drawable-xxxhdpi/miao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GcsSloop/ViewSupport/HEAD/Sample/src/main/res/drawable-xxxhdpi/miao.png -------------------------------------------------------------------------------- /Sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GcsSloop/ViewSupport/HEAD/Sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GcsSloop/ViewSupport/HEAD/Sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GcsSloop/ViewSupport/HEAD/Sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GcsSloop/ViewSupport/HEAD/Sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GcsSloop/ViewSupport/HEAD/Sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | -------------------------------------------------------------------------------- /Library/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/GcsSloop/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 | -------------------------------------------------------------------------------- /Sample/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/GcsSloop/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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | include ':Sample', ':Library' 21 | -------------------------------------------------------------------------------- /Library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | Library 22 | 23 | -------------------------------------------------------------------------------- /Sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | ViewSupport 22 | 23 | -------------------------------------------------------------------------------- /Sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 | 16dp 23 | 16dp 24 | 25 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 GcsSloop 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Last modified 2016-12-03 22:55:54 17 | # 18 | # 19 | 20 | #Mon Oct 31 01:52:12 CST 2016 21 | distributionBase=GRADLE_USER_HOME 22 | distributionPath=wrapper/dists 23 | zipStoreBase=GRADLE_USER_HOME 24 | zipStorePath=wrapper/dists 25 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 26 | -------------------------------------------------------------------------------- /Sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | #F99E7F 23 | #DF9C81 24 | #FF4081 25 | 26 | -------------------------------------------------------------------------------- /ViewSupport.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 22 | 23 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 24 | 64dp 25 | 26 | -------------------------------------------------------------------------------- /Sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 | 23 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 28 | 29 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | apply plugin: 'com.android.application' 21 | 22 | android { 23 | compileSdkVersion 23 24 | buildToolsVersion "23.0.3" 25 | 26 | defaultConfig { 27 | applicationId "com.gcssloop.viewsupport" 28 | minSdkVersion 9 29 | targetSdkVersion 23 30 | versionCode 1 31 | versionName "1.0" 32 | } 33 | buildTypes { 34 | release { 35 | minifyEnabled false 36 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 37 | } 38 | } 39 | } 40 | 41 | dependencies { 42 | compile fileTree(include: ['*.jar'], dir: 'libs') 43 | testCompile 'junit:junit:4.12' 44 | compile 'com.android.support:appcompat-v7:23.4.0' 45 | compile project(':Library') 46 | compile 'com.android.support:cardview-v7:23.4.0' 47 | } 48 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 GcsSloop 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Last modified 2016-12-03 22:55:55 17 | # 18 | # 19 | 20 | # Project-wide Gradle settings. 21 | 22 | # IDE (e.g. Android Studio) users: 23 | # Gradle settings configured through the IDE *will override* 24 | # any settings specified in this file. 25 | 26 | # For more details on how to configure your build environment visit 27 | # http://www.gradle.org/docs/current/userguide/build_environment.html 28 | 29 | # Specifies the JVM arguments used for the daemon process. 30 | # The setting is particularly useful for tweaking memory settings. 31 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 32 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 33 | 34 | # When configured, Gradle will run in incubating parallel mode. 35 | # This option should only be used with decoupled projects. More details, visit 36 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 37 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /Library/src/main/java/com/gcssloop/view/utils/CanvasUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | package com.gcssloop.view.utils; 21 | 22 | import android.graphics.Canvas; 23 | import android.graphics.Paint; 24 | import android.graphics.Point; 25 | import android.graphics.PointF; 26 | 27 | public class CanvasUtils { 28 | 29 | 30 | private CanvasUtils() { 31 | } 32 | 33 | /** 34 | * Draw a straight line through the points. 35 | */ 36 | public static void drawLine(Point p1, Point p2, Canvas canvas, Paint paint) { 37 | canvas.save(); 38 | canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint); 39 | canvas.restore(); 40 | } 41 | 42 | /** 43 | * Draw a straight line through the points 44 | */ 45 | public static void drawLine(PointF p1, PointF p2, Canvas canvas, Paint paint) { 46 | canvas.save(); 47 | canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint); 48 | canvas.restore(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:54 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.base; 21 | 22 | import android.os.Bundle; 23 | import android.support.annotation.Nullable; 24 | import android.support.v7.app.AppCompatActivity; 25 | import android.view.MenuItem; 26 | 27 | 28 | public class BaseActivity extends AppCompatActivity { 29 | 30 | @Override 31 | protected void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | // Title显示当前类名 34 | this.setTitle(this.getClass().getSimpleName()); 35 | } 36 | 37 | // 监听重载 ActionBar 左上角按钮事件。 38 | @Override 39 | public boolean onOptionsItemSelected(MenuItem item) 40 | { 41 | // TODO Auto-generated method stub 42 | if(item.getItemId() == android.R.id.home) { 43 | finish(); 44 | return true; 45 | } 46 | return super.onOptionsItemSelected(item); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sample/src/main/res/layout/activity_see_logcat.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 32 | 33 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Sample/src/main/res/layout/activity_test_custom_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 31 | 32 | 39 | 40 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Sample/src/main/res/layout/item_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 29 | 30 | 39 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/viewsupport/TestCanvasAidUtilsActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-05 23:34:36 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.viewsupport; 21 | 22 | import android.content.Context; 23 | import android.graphics.Canvas; 24 | import android.os.Bundle; 25 | import android.support.annotation.Nullable; 26 | 27 | import com.gcssloop.test.base.BaseActivity; 28 | import com.gcssloop.view.CustomView; 29 | import com.gcssloop.view.utils.CanvasAidUtils; 30 | 31 | public class TestCanvasAidUtilsActivity extends BaseActivity { 32 | 33 | @Override 34 | protected void onCreate(@Nullable Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(new TestCanvasAidUtilsView(this)); 37 | } 38 | } 39 | 40 | class TestCanvasAidUtilsView extends CustomView { 41 | 42 | public TestCanvasAidUtilsView(Context context) { 43 | super(context); 44 | 45 | } 46 | 47 | @Override 48 | protected void onDraw(Canvas canvas) { 49 | super.onDraw(canvas); 50 | 51 | // 平移坐标系 52 | canvas.translate(mViewWidth/2, mViewHeight/2); 53 | 54 | // 重置坐标轴长度 55 | CanvasAidUtils.set2DAxisLength(mViewWidth/2*0.8f, mViewHeight/2*0.8f); 56 | 57 | // 绘制辅助坐标系 58 | CanvasAidUtils.draw2DCoordinateSpace(canvas); 59 | } 60 | } -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/viewsupport/TestCustomViewActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.viewsupport; 21 | 22 | import android.content.Context; 23 | import android.graphics.Canvas; 24 | import android.graphics.Color; 25 | import android.graphics.Paint; 26 | import android.os.Bundle; 27 | 28 | import com.gcssloop.test.base.BaseActivity; 29 | import com.gcssloop.view.CustomView; 30 | 31 | public class TestCustomViewActivity extends BaseActivity { 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(new MyView(this)); 37 | } 38 | 39 | public class MyView extends CustomView{ 40 | 41 | public MyView(Context context) { 42 | super(context); 43 | mDeafultPaint.setColor(Color.GRAY); // 获得一个默认的画笔 44 | mDeafultPaint.setTextSize(42); 45 | mDeafultPaint.setTextAlign(Paint.Align.CENTER); 46 | } 47 | 48 | @Override 49 | protected void onDraw(Canvas canvas) { 50 | canvas.translate(mViewWidth/2,mViewHeight/2); // 获得视图宽高 51 | 52 | canvas.drawCircle(0, -100, 100, mDeafultPaint); 53 | canvas.drawText("用默认画笔绘制一个圆", 0, 60, mDeafultPaint); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/date/MainMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:54 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.date; 21 | 22 | import com.gcssloop.test.viewsupport.TestApiHelperActivity; 23 | import com.gcssloop.test.viewsupport.TestCanvasAidUtilsActivity; 24 | import com.gcssloop.test.viewsupport.TestCustomViewActivity; 25 | import com.gcssloop.test.viewsupport.TestMorionEventHelperActivity; 26 | import com.gcssloop.test.viewsupport.TestRotate3dAnimationActivity; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class MainMenu { 32 | public static List menu = new ArrayList(); 33 | 34 | static{ 35 | menu.add(new MenuEntity("CustomView测试", TestCustomViewActivity.class)) ; 36 | menu.add(new MenuEntity("Rotate3dAnimation测试", TestRotate3dAnimationActivity.class)) ; 37 | menu.add(new MenuEntity("ApiHelper测试", TestApiHelperActivity.class)) ; 38 | menu.add(new MenuEntity("MotionEventHelper测试", TestMorionEventHelperActivity.class)) ; 39 | menu.add(new MenuEntity("CanvasAidUtils测试", TestCanvasAidUtilsActivity.class)) ; 40 | } 41 | 42 | public static class MenuEntity{ 43 | public String info; 44 | public Class goClass; 45 | public MenuEntity(String info,Class goClass) { 46 | this.info=info; 47 | this.goClass=goClass; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/viewsupport/TestMorionEventHelperActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-05 18:44:07 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.viewsupport; 21 | 22 | import android.graphics.Matrix; 23 | import android.os.Bundle; 24 | import android.support.annotation.Nullable; 25 | import android.util.Log; 26 | import android.view.MotionEvent; 27 | import android.widget.TextView; 28 | 29 | import com.gcssloop.test.base.BaseActivity; 30 | import com.gcssloop.view.helper.MotionEventHelper; 31 | import com.gcssloop.viewsupporttest.R; 32 | 33 | public class TestMorionEventHelperActivity extends BaseActivity { 34 | private static final String TAG = "TestMorionEventHelper"; 35 | Matrix mMatrix; 36 | 37 | @Override 38 | protected void onCreate(@Nullable Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_see_logcat); 41 | TextView text = (TextView) findViewById(R.id.custom_view_text); 42 | text.append("\n在屏幕上触摸,查看坐标变化。\nx,y坐标均增加100"); 43 | 44 | mMatrix = new Matrix(); 45 | mMatrix.postTranslate(100,100); 46 | } 47 | 48 | @Override 49 | public boolean onTouchEvent(MotionEvent event) { 50 | Log.i(TAG, "转换前 > "+event.getX()+" : "+event.getY()); 51 | MotionEvent e = MotionEventHelper.transformEvent(event, mMatrix); 52 | Log.i(TAG, "转换后 > "+e.getX()+" : "+e.getY()); 53 | Log.i(TAG, "-------------------------"); 54 | return true; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Library/src/main/java/com/gcssloop/view/CustomView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | package com.gcssloop.view; 21 | 22 | import android.content.Context; 23 | import android.graphics.Paint; 24 | import android.text.TextPaint; 25 | import android.util.AttributeSet; 26 | import android.view.View; 27 | 28 | public class CustomView extends View { 29 | 30 | /** 31 | * the context of current view 32 | */ 33 | protected Context mCurrentContext; 34 | 35 | /** 36 | * the width of current view. 37 | */ 38 | protected int mViewWidth; 39 | 40 | /** 41 | * the height of current view. 42 | */ 43 | protected int mViewHeight; 44 | 45 | /** 46 | * default Paint. 47 | */ 48 | protected Paint mDeafultPaint = new Paint(); 49 | 50 | /** 51 | * default TextPaint 52 | */ 53 | protected TextPaint mDefaultTextPaint = new TextPaint(); 54 | 55 | 56 | public CustomView(Context context) { 57 | this(context, null); 58 | } 59 | 60 | public CustomView(Context context, AttributeSet attrs) { 61 | this(context, attrs, 0); 62 | } 63 | 64 | public CustomView(Context context, AttributeSet attrs, int defStyleAttr) { 65 | super(context, attrs, defStyleAttr); 66 | this.mCurrentContext = context; 67 | } 68 | 69 | 70 | @Override 71 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 72 | super.onSizeChanged(w, h, oldw, oldh); 73 | mViewWidth = w; 74 | mViewHeight = h; 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /Library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | apply plugin: 'com.android.library' 21 | apply plugin: 'com.github.dcendents.android-maven' // ADD THIS 22 | 23 | group='com.github.GcsSloop' 24 | 25 | android { 26 | compileSdkVersion 23 27 | buildToolsVersion "23.0.3" 28 | 29 | defaultConfig { 30 | minSdkVersion 9 31 | targetSdkVersion 23 32 | versionCode 1 33 | versionName "1.0" 34 | } 35 | buildTypes { 36 | release { 37 | minifyEnabled false 38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 39 | } 40 | } 41 | } 42 | 43 | // encoding 44 | tasks.withType(JavaCompile) { 45 | options.encoding = "UTF-8" 46 | } 47 | 48 | dependencies { 49 | compile fileTree(dir: 'libs', include: ['*.jar']) 50 | testCompile 'junit:junit:4.12' 51 | compile 'com.android.support:appcompat-v7:23.4.0' 52 | } 53 | 54 | // build a jar with source files 55 | task sourcesJar(type: Jar) { 56 | from android.sourceSets.main.java.srcDirs 57 | classifier = 'sources' 58 | } 59 | 60 | task javadoc(type: Javadoc) { 61 | failOnError false 62 | source = android.sourceSets.main.java.sourceFiles 63 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 64 | classpath += configurations.compile 65 | } 66 | 67 | // build a jar with javadoc 68 | task javadocJar(type: Jar, dependsOn: javadoc) { 69 | classifier = 'javadoc' 70 | from javadoc.destinationDir 71 | } 72 | 73 | artifacts { 74 | archives sourcesJar 75 | archives javadocJar 76 | } 77 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/viewsupport/TestApiHelperActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-04 03:39:58 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.viewsupport; 21 | 22 | import android.os.Bundle; 23 | import android.support.annotation.Nullable; 24 | import android.util.Log; 25 | 26 | import com.gcssloop.test.base.BaseActivity; 27 | import com.gcssloop.view.helper.ApiHelper; 28 | import com.gcssloop.viewsupporttest.R; 29 | 30 | public class TestApiHelperActivity extends BaseActivity{ 31 | private static final String TAG = "TestApiHelper"; 32 | 33 | @Override 34 | protected void onCreate(@Nullable Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_see_logcat); 37 | 38 | Class testClass = com.gcssloop.test.viewsupport.MyClass.class; 39 | 40 | Log.i(TAG, "-----------------------"); 41 | 42 | // 测试某个类是否包含该字段 43 | Log.i(TAG, "hasField - (T): "+ApiHelper.hasField(testClass, "mSloop")); 44 | Log.i(TAG, "hasField - (F): "+ApiHelper.hasField(testClass, "mField")); 45 | 46 | Log.i(TAG, "-----------------------"); 47 | 48 | // 测试某个类是否包含该方法 49 | Log.i(TAG, "hasMethod - (T): "+ApiHelper.hasMethod("com.gcssloop.test.viewsupport.MyClass", "MyMethod")); 50 | Log.i(TAG, "hasMethod - (T): "+ApiHelper.hasMethod(testClass, "MyMethod")); 51 | Log.i(TAG, "hasMethod - (T): "+ApiHelper.hasMethod(testClass, "MyMethod", String.class)); 52 | Log.i(TAG, "hasMethod - (F): "+ApiHelper.hasMethod(testClass, "MyMethod", int.class)); 53 | 54 | } 55 | } 56 | 57 | /** 58 | * 一个被测试的类 59 | */ 60 | class MyClass { 61 | int mSloop = 8; 62 | 63 | 64 | int MyMethod(){ 65 | return 0; 66 | } 67 | 68 | int MyMethod(String haha){ 69 | return 0; 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | package com.gcssloop.test; 21 | 22 | import android.annotation.TargetApi; 23 | import android.content.Intent; 24 | import android.os.Build; 25 | import android.os.Bundle; 26 | import android.view.View; 27 | import android.widget.AdapterView; 28 | import android.widget.ListView; 29 | import android.widget.TextView; 30 | 31 | import com.gcssloop.test.adapter.CommonAdapter; 32 | import com.gcssloop.test.adapter.ViewHolder; 33 | import com.gcssloop.test.base.BaseActivity; 34 | import com.gcssloop.test.date.MainMenu; 35 | import com.gcssloop.test.utils.CrashHandler; 36 | import com.gcssloop.viewsupporttest.R; 37 | 38 | public class MainActivity extends BaseActivity { 39 | private static final String TAG = "MainActivity"; 40 | 41 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_main); 46 | CrashHandler.getInstance().init(this.getApplicationContext()); 47 | 48 | ListView listView = (ListView) findViewById(R.id.main_list); 49 | 50 | assert listView != null; 51 | listView.setAdapter(new CommonAdapter(this, MainMenu.menu, R.layout.item_main) { 52 | @Override 53 | public void convert(int position, ViewHolder holder, MainMenu.MenuEntity bean) { 54 | TextView textView = holder.getView(R.id.item_main_text); 55 | textView.setText(bean.info); 56 | } 57 | }); 58 | 59 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 60 | @Override 61 | public void onItemClick(AdapterView parent, View view, int position, long id) { 62 | startActivity(new Intent(MainActivity.this, MainMenu.menu.get(position).goClass)); 63 | } 64 | }); 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/adapter/ViewHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:54 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.adapter; 21 | 22 | import android.content.Context; 23 | import android.util.SparseArray; 24 | import android.view.LayoutInflater; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | 28 | public class ViewHolder { 29 | 30 | private SparseArray mViews; 31 | private View mConvertView; 32 | 33 | private ViewHolder(Context context, ViewGroup parent, int layoutId, int position) { 34 | this.mViews = new SparseArray(); 35 | mConvertView = LayoutInflater.from(context).inflate(layoutId, parent, false); 36 | mConvertView.setTag(this); //setTag 37 | } 38 | 39 | /** 40 | * 获取ViewHolder的实例 41 | * 42 | * @param context 上下文 43 | * @param convertView 布局 44 | * @param parent 父布局 45 | * @param layoutId 布局ID 46 | * @param position 位置 47 | * @return ViewHolder实例 48 | */ 49 | public static ViewHolder getInstance(Context context, View convertView, ViewGroup parent, int layoutId, int 50 | position) { 51 | if (convertView == null) { 52 | return new ViewHolder(context, parent, layoutId, position); 53 | } else { 54 | return (ViewHolder) convertView.getTag(); 55 | } 56 | } 57 | 58 | /** 59 | * 通过View的id来获取子View 60 | * 61 | * @param resId view的id 62 | * @param 泛型 63 | * @return 子View 64 | */ 65 | public T getView(int resId) { 66 | View view = mViews.get(resId); 67 | 68 | //如果该View没有缓存过,则查找View并缓存 69 | if (view == null) { 70 | view = mConvertView.findViewById(resId); 71 | mViews.put(resId, view); 72 | } 73 | 74 | return (T) view; 75 | } 76 | 77 | /** 78 | * 获取布局View 79 | * 80 | * @return 布局View 81 | */ 82 | public View getConvertView() { 83 | return mConvertView; 84 | } 85 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Sample/src/main/java/com/gcssloop/test/adapter/CommonAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:54 17 | * 18 | */ 19 | 20 | package com.gcssloop.test.adapter; 21 | 22 | import android.content.Context; 23 | import android.support.annotation.NonNull; 24 | import android.view.LayoutInflater; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.widget.BaseAdapter; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | public abstract class CommonAdapter extends BaseAdapter { 33 | 34 | private LayoutInflater mInflater; 35 | private Context mContext; 36 | private List mDatas = new ArrayList<>(); 37 | private int mLayoutId; 38 | 39 | /** 40 | * @param context 上下文 41 | * @param datas 数据集 42 | * @param layoutId 布局ID 43 | */ 44 | public CommonAdapter(@NonNull Context context, List datas, @NonNull int layoutId) { 45 | mInflater = LayoutInflater.from(context); 46 | this.mContext = context; 47 | this.mLayoutId = layoutId; 48 | if(datas!=null){ 49 | this.mDatas = datas; 50 | } 51 | } 52 | 53 | public void addDatas(List datas){ 54 | this.mDatas.addAll(datas); 55 | notifyDataSetChanged(); 56 | } 57 | 58 | public void clearDatas(){ 59 | this.mDatas.clear(); 60 | notifyDataSetChanged(); 61 | } 62 | 63 | public T getDataById(int position){ 64 | return mDatas.get(position); 65 | } 66 | 67 | @Override 68 | public int getCount() { 69 | return mDatas.size(); 70 | } 71 | 72 | @Override 73 | public T getItem(int position) { 74 | return mDatas.get(position); 75 | } 76 | 77 | @Override 78 | public long getItemId(int position) { 79 | return position; 80 | } 81 | 82 | @Override 83 | public View getView(int position, View convertView, ViewGroup parent) { 84 | //实例化一个ViewHolder 85 | ViewHolder holder = ViewHolder.getInstance(mContext, convertView, parent, mLayoutId, position); 86 | //需要自定义的部分 87 | convert(position, holder, getItem(position)); 88 | 89 | return holder.getConvertView(); 90 | } 91 | 92 | /** 93 | * 需要处理的部分,在这里给View设置值 94 | * 95 | * @param holder ViewHolder 96 | * @param bean 数据集 97 | */ 98 | public abstract void convert(int position, ViewHolder holder, T bean); 99 | } -------------------------------------------------------------------------------- /Library/src/main/java/com/gcssloop/view/utils/DensityUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | package com.gcssloop.view.utils; 21 | 22 | import android.content.Context; 23 | 24 | public class DensityUtils { 25 | 26 | public DensityUtils() { 27 | } 28 | 29 | /** 30 | * convert the dp to px depend on the device density. 31 | * 32 | * @param context the context 33 | * @param dpValue a value of dp 34 | * @return the result of px 35 | */ 36 | public static int dip2px(Context context, float dpValue) { 37 | return (int) (dpValue * getDensity(context) + 0.5f); 38 | } 39 | 40 | /** 41 | * convert the px to dp depend on the device density. 42 | * 43 | * @param context the context 44 | * @param pxValue a value of px 45 | * @return the result of dp 46 | */ 47 | public static int px2dip(Context context, float pxValue) { 48 | return (int) (pxValue / getDensity(context) + 0.5f); 49 | } 50 | 51 | /** 52 | * convert the sp to px depend on the device scaledDensity. 53 | * 54 | * @param context the context 55 | * @param spValue a value of sp 56 | * @return the result of px 57 | */ 58 | public static int sp2px(Context context, float spValue) { 59 | return (int) (spValue * getFontDensity(context) + 0.5); 60 | } 61 | 62 | /** 63 | * convert the px to sp depend on the device scaledDensity. 64 | * 65 | * @param context the context 66 | * @param pxValue a value of px 67 | * @return the result of sp 68 | */ 69 | public static int px2sp(Context context, float pxValue) { 70 | return (int) (pxValue / getFontDensity(context) + 0.5); 71 | } 72 | 73 | /** 74 | * get the density of device screen. 75 | * 76 | * @param context the context 77 | * @return the screen density 78 | */ 79 | public static float getDensity(Context context) { 80 | return context.getResources().getDisplayMetrics().density; 81 | } 82 | 83 | /** 84 | * get the scale density of device screen. 85 | * usually this value is the same as density. 86 | * but it can adjust by user. 87 | * 88 | * @param context the context 89 | * @return the screen scale density. 90 | */ 91 | public static float getFontDensity(Context context) { 92 | return context.getResources().getDisplayMetrics().scaledDensity; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Library/src/main/java/com/gcssloop/view/utils/MathUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 GcsSloop 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Last modified 2016-12-03 22:55:55 17 | * 18 | */ 19 | 20 | package com.gcssloop.view.utils; 21 | 22 | import android.graphics.Point; 23 | import android.graphics.PointF; 24 | 25 | public class MathUtils { 26 | 27 | public MathUtils() { 28 | } 29 | 30 | /** 31 | * Get the distance between two points. 32 | * 33 | * @param A Point A 34 | * @param B Point B 35 | * @return the distance between point A and point B. 36 | */ 37 | public static int getDistance(PointF A, PointF B) { 38 | return (int) Math.sqrt(Math.pow(A.x - B.x, 2) + Math.pow(A.y - B.y, 2)); 39 | } 40 | 41 | /** 42 | * Get the distance between two points. 43 | */ 44 | public static int getDistance(float x1, float y1, float x2, float y2) { 45 | return (int) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); 46 | } 47 | 48 | /** 49 | * Get the coordinates of a point on the line by cut length. 50 | * 51 | * @param A Point A 52 | * @param B Point B 53 | * @param cutLength cut length 54 | * @return the point. 55 | */ 56 | public static Point getPointByCutLength(Point A, Point B, int cutLength) { 57 | float radian = getRadian(A, B); 58 | return new Point(A.x + (int) (cutLength * Math.cos(radian)), A.y + (int) (cutLength * Math.sin(radian))); 59 | } 60 | 61 | /** 62 | * Get the radian between current line(determined by point A and B) and horizontal line. 63 | * 64 | * @param A point A 65 | * @param B point B 66 | * @return the radian 67 | */ 68 | public static float getRadian(Point A, Point B) { 69 | float lenA = B.x - A.x; 70 | float lenB = B.y - A.y; 71 | float lenC = (float) Math.sqrt(lenA * lenA + lenB * lenB); 72 | float radian = (float) Math.acos(lenA / lenC); 73 | radian = radian * (B.y < A.y ? -1 : 1); 74 | return radian; 75 | } 76 | 77 | 78 | /** 79 | * angle to radian 80 | * 81 | * @param angle angle 82 | * @return radian 83 | */ 84 | public static double angle2Radian(double angle) { 85 | return angle / 180 * Math.PI; 86 | } 87 | 88 | /** 89 | * radian to angle 90 | * 91 | * @param radian radian 92 | * @return angle 93 | */ 94 | public static double radian2Angle(double radian) { 95 | return radian / Math.PI * 180; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /README-EN.md: -------------------------------------------------------------------------------- 1 | # ViewSupport 2 | 3 | [![License](https://img.shields.io/badge/license-Apache%202-green.svg)](https://www.apache.org/licenses/LICENSE-2.0) 4 | ![](https://img.shields.io/badge/Support-7%2B-green.svg) 5 | [![](https://jitpack.io/v/GcsSloop/ViewSupport.svg)](https://jitpack.io/#GcsSloop/ViewSupport) 6 | 7 | ### Weibo: [@GcsSloop](http://weibo.com/GcsSloop) 8 | 9 | This is a library for View and CustomView,it has some tools can help you operate view or help you custom view easily. 10 | 11 | ***** 12 | 13 | ## Tools list 14 | 15 | you can click the tools name to see the source. 16 | 17 | Utils | Summary 18 | ----------------|---------------------------------- 19 | CanvasAidUtils | Canvas Aid util, you can use it draw a coordinate system to help you check the view position. 20 | DensityUtils | A utils of screen density. it can help you convert the different unit.
*E.g: dp -> px ps->dp sp->px px->sp* 21 | MathUtils | A Math utils, It can help you make some common calculations.
*E.g: Get the distance between two points; angle2Radian; radian2Angle and others* 22 | ViewUtils | Utils for view. it can help you measure view, if you want get the view size before it not measured. or you can use it set view margin on code. 23 | 24 | 25 | 26 | ## Get it 27 | 28 | #### Gradle: 29 | 30 | **Step 1. Add the JitPack repository to your build file** 31 | 32 | Add it in your root build.gradle at the end of repositories: 33 | 34 | ``` gradle 35 | allprojects { 36 | repositories { 37 | ... 38 | maven { url "https://jitpack.io" } 39 | } 40 | } 41 | ``` 42 | 43 | **Step 2. Add the dependency** 44 | 45 | ``` gradle 46 | dependencies { 47 | compile 'com.github.GcsSloop:ViewSupport:v1.0.3' 48 | } 49 | ``` 50 | 51 | #### Maven 52 | 53 | **Step 1. Add the JitPack repository to your build file** 54 | 55 | Add it in your root build.gradle at the end of repositories: 56 | 57 | ``` maven 58 | 59 | 60 | jitpack.io 61 | https://jitpack.io 62 | 63 | 64 | ``` 65 | 66 | **Step 2. Add the dependency** 67 | 68 | ``` maven 69 | 70 | com.github.GcsSloop 71 | ViewSupport 72 | v1.0.2 73 | 74 | ``` 75 | 76 | ## About Me 77 | 78 | ### Weibo: [@GcsSloop](http://weibo.com/GcsSloop) 79 | 80 | 81 | 82 | ## License 83 | 84 | ``` 85 | Copyright (c) 2016 GcsSloop 86 | 87 | Licensed under the Apache License, Version 2.0 (the "License"); 88 | you may not use this file except in compliance with the License. 89 | You may obtain a copy of the License at 90 | 91 | http://www.apache.org/licenses/LICENSE-2.0 92 | 93 | Unless required by applicable law or agreed to in writing, software 94 | distributed under the License is distributed on an "AS IS" BASIS, 95 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 96 | See the License for the specific language governing permissions and 97 | limitations under the License. 98 | ``` 99 | -------------------------------------------------------------------------------- /Sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | 43 | 44 | 46 | 47 | 50 | 51 | 53 | 54 | 57 | 58 | 60 | 61 | 64 | 65 | 67 | 68 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Sample/src/main/res/layout/activity_test_rorate3d_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 28 | 29 | 37 | 38 | 44 | 52 | 59 | 66 | 67 |