From 2c501bea52bbfd9d921854cc7861dcdb6eba8402 Mon Sep 17 00:00:00 2001 From: hupei Date: Thu, 16 Jun 2016 16:43:56 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8D=E7=94=A8?= =?UTF-8?q?=E7=BB=A7=E6=89=BF=20AutoLayoutActivity=20=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++ .../zhy/autolayout/AutoLayoutActivity.java | 37 +++---------------- .../autolayout/utils/AutoLayoutHelper.java | 23 ++++++++++++ 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 361ee21..8ac4ffa 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,15 @@ dependencies { * RelativeLayout -> AutoRelativeLayout * FrameLayout -> AutoFrameLayout +或者在 Activity 中重写 onCreateView +```java + @Override + public View onCreateView(String name, Context context, AttributeSet attrs) { + View view = AutoLayoutHelper.onCreateAutoLayoutView(name, context, attrs); + return view != null ? view : super.onCreateView(name, context, attrs); + } +``` + 这样也可以完成适配。 ## 目前支持属性 diff --git a/autolayout/src/main/java/com/zhy/autolayout/AutoLayoutActivity.java b/autolayout/src/main/java/com/zhy/autolayout/AutoLayoutActivity.java index a8e8d01..dc76ba8 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/AutoLayoutActivity.java +++ b/autolayout/src/main/java/com/zhy/autolayout/AutoLayoutActivity.java @@ -5,43 +5,16 @@ import android.util.AttributeSet; import android.view.View; -; +;import com.zhy.autolayout.utils.AutoLayoutHelper; /** * Created by zhy on 15/11/19. */ -public class AutoLayoutActivity extends AppCompatActivity -{ - private static final String LAYOUT_LINEARLAYOUT = "LinearLayout"; - private static final String LAYOUT_FRAMELAYOUT = "FrameLayout"; - private static final String LAYOUT_RELATIVELAYOUT = "RelativeLayout"; - +public class AutoLayoutActivity extends AppCompatActivity { @Override - public View onCreateView(String name, Context context, AttributeSet attrs) - { - View view = null; - if (name.equals(LAYOUT_FRAMELAYOUT)) - { - view = new AutoFrameLayout(context, attrs); - } - - if (name.equals(LAYOUT_LINEARLAYOUT)) - { - view = new AutoLinearLayout(context, attrs); - } - - if (name.equals(LAYOUT_RELATIVELAYOUT)) - { - view = new AutoRelativeLayout(context, attrs); - } - - if (view != null) return view; - - return super.onCreateView(name, context, attrs); + public View onCreateView(String name, Context context, AttributeSet attrs) { + View view = AutoLayoutHelper.onCreateAutoLayoutView(name, context, attrs); + return view != null ? view : super.onCreateView(name, context, attrs); } - - - - } diff --git a/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java b/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java index 9ac666e..9d43470 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java +++ b/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java @@ -22,7 +22,10 @@ import android.view.View; import android.view.ViewGroup; +import com.zhy.autolayout.AutoFrameLayout; import com.zhy.autolayout.AutoLayoutInfo; +import com.zhy.autolayout.AutoLinearLayout; +import com.zhy.autolayout.AutoRelativeLayout; import com.zhy.autolayout.R; import com.zhy.autolayout.attr.HeightAttr; import com.zhy.autolayout.attr.MarginAttr; @@ -88,6 +91,9 @@ public class AutoLayoutHelper private static final int INDEX_MIN_WIDTH = 15; private static final int INDEX_MIN_HEIGHT = 16; + private static final String LAYOUT_LINEARLAYOUT = "LinearLayout"; + private static final String LAYOUT_FRAMELAYOUT = "FrameLayout"; + private static final String LAYOUT_RELATIVELAYOUT = "RelativeLayout"; /** * move to other place? @@ -230,4 +236,21 @@ public interface AutoLayoutParams { AutoLayoutInfo getAutoLayoutInfo(); } + + public static View onCreateAutoLayoutView(String name, Context context, AttributeSet attrs) { + View view = null; + if (name.equals(LAYOUT_LINEARLAYOUT)) { + view = new AutoLinearLayout(context, attrs); + } + + if (name.equals(LAYOUT_FRAMELAYOUT)) { + view = new AutoFrameLayout(context, attrs); + } + + if (name.equals(LAYOUT_RELATIVELAYOUT)) { + view = new AutoRelativeLayout(context, attrs); + } + + return view; + } } From 9e31c3841ad6fdcb7ebe43f901a8f9a3cf106bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=A4=B4?= <48025211@qq.com> Date: Fri, 1 Jun 2018 15:27:35 +0800 Subject: [PATCH 2/3] releases 1.5.0 --- autolayout-widget/build.gradle | 13 +-- autolayout/build.gradle | 105 ++++-------------- .../com/zhy/autolayout/utils/AutoUtils.java | 100 ++++++++--------- build.gradle | 16 ++- config.gradle | 24 ++++ gradle/wrapper/gradle-wrapper.properties | 4 +- sample/build.gradle | 12 +- .../src/main/res/layout/fragment_gridview.xml | 16 +++ widgetsample/build.gradle | 12 +- 9 files changed, 139 insertions(+), 163 deletions(-) create mode 100644 config.gradle create mode 100644 sample/src/main/res/layout/fragment_gridview.xml diff --git a/autolayout-widget/build.gradle b/autolayout-widget/build.gradle index 12479e2..5cbf4ad 100644 --- a/autolayout-widget/build.gradle +++ b/autolayout-widget/build.gradle @@ -1,14 +1,13 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" - + compileSdkVersion rootProject.ext.android.compileSdkVersion + buildToolsVersion rootProject.ext.android.buildToolsVersion defaultConfig { - minSdkVersion 10 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode rootProject.ext.android.versionCode + versionName rootProject.ext.android.versionName } buildTypes { release { diff --git a/autolayout/build.gradle b/autolayout/build.gradle index d02e622..58fa20f 100644 --- a/autolayout/build.gradle +++ b/autolayout/build.gradle @@ -1,18 +1,15 @@ apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'com.jfrog.bintray' - -version = "1.4.5" +apply plugin: 'maven' +apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" - + compileSdkVersion rootProject.ext.android.compileSdkVersion + buildToolsVersion rootProject.ext.android.buildToolsVersion defaultConfig { - minSdkVersion 7 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode rootProject.ext.android.versionCode + versionName rootProject.ext.android.versionName } buildTypes { release { @@ -20,81 +17,23 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } -} - -def siteUrl = 'https://github.com/hongyangAndroid/AndroidAutoLayout' // #CONFIG# // project homepage -def gitUrl = 'https://github.com/hongyangAndroid/AndroidAutoLayout.git' // #CONFIG# // project git -group = "com.zhy" - -install { - repositories.mavenInstaller { - // This generates POM.xml with proper parameters - pom { - project { - packaging 'aar' - name 'AutoLayout' // #CONFIG# // project title - url siteUrl - // Set your license - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - developers { - developer { - id 'hongyangAndroid' // #CONFIG# // your user id (you can write your nickname) - name 'ZhangHongyang' // #CONFIG# // your user name - email '623565791@qq.com' // #CONFIG# // your email - } - } - scm { - connection gitUrl - developerConnection gitUrl - url siteUrl - } - } - } + productFlavors { } -} - -task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' -} - -task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives javadocJar - archives sourcesJar -} -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) -bintray { - user = properties.getProperty("bintray.user") - key = properties.getProperty("bintray.apikey") - configurations = ['archives'] - pkg { - repo = "maven" - name = "autolayout" // #CONFIG# project name in jcenter - websiteUrl = siteUrl - vcsUrl = gitUrl - licenses = ["Apache-2.0"] - publish = true + lintOptions { + abortOnError false + checkReleaseBuilds false } } - dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.0.1' + provided rootProject.ext.dependencies.appcompatV7 } + +publish { + userOrg = 'mylhyl' + groupId = 'com.mylhyl' + artifactId = 'autolayout' + version = rootProject.ext.publish.version + description = 'AndroidAutoLayout' + website = "https://github.com/mylhyl/AndroidAutoLayout" +} \ No newline at end of file diff --git a/autolayout/src/main/java/com/zhy/autolayout/utils/AutoUtils.java b/autolayout/src/main/java/com/zhy/autolayout/utils/AutoUtils.java index 1252648..f79bc1a 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/utils/AutoUtils.java +++ b/autolayout/src/main/java/com/zhy/autolayout/utils/AutoUtils.java @@ -11,138 +11,126 @@ /** * Created by zhy on 15/12/4. */ -public class AutoUtils -{ +public class AutoUtils { /** * 会直接将view的LayoutParams上设置的width,height直接进行百分比处理 * * @param view */ - public static void auto(View view) - { + public static void auto(View view) { autoSize(view); + autoMax(view); + autoMin(view); autoPadding(view); autoMargin(view); autoTextSize(view, AutoAttr.BASE_DEFAULT); } + public static void autoSize(View view) { + auto(view, Attrs.WIDTH | Attrs.HEIGHT, AutoAttr.BASE_DEFAULT); + } + + public static void autoMax(View view) { + auto(view, Attrs.MAX_WIDTH | Attrs.MAX_HEIGHT, AutoAttr.BASE_DEFAULT); + } + + public static void autoMin(View view) { + auto(view, Attrs.MIN_WIDTH | Attrs.MIN_HEIGHT, AutoAttr.BASE_DEFAULT); + } + + public static void autoPadding(View view) { + auto(view, Attrs.PADDING, AutoAttr.BASE_DEFAULT); + } + + public static void autoMargin(View view) { + auto(view, Attrs.MARGIN, AutoAttr.BASE_DEFAULT); + } + + public static void autoTextSize(View view, int base) { + auto(view, Attrs.TEXTSIZE, base); + } + /** * @param view * @param attrs #Attrs.WIDTH|Attrs.HEIGHT * @param base AutoAttr.BASE_WIDTH|AutoAttr.BASE_HEIGHT|AutoAttr.BASE_DEFAULT */ - public static void auto(View view, int attrs, int base) - { + public static void auto(View view, int attrs, int base) { AutoLayoutInfo autoLayoutInfo = AutoLayoutInfo.getAttrFromView(view, attrs, base); if (autoLayoutInfo != null) autoLayoutInfo.fillAttrs(view); } - public static void autoTextSize(View view) - { + public static void autoTextSize(View view) { auto(view, Attrs.TEXTSIZE, AutoAttr.BASE_DEFAULT); } - public static void autoTextSize(View view, int base) - { - auto(view, Attrs.TEXTSIZE, base); - } - - public static void autoMargin(View view) - { - auto(view, Attrs.MARGIN, AutoAttr.BASE_DEFAULT); - } - - public static void autoMargin(View view, int base) - { + public static void autoMargin(View view, int base) { auto(view, Attrs.MARGIN, base); } - public static void autoPadding(View view) - { - auto(view, Attrs.PADDING, AutoAttr.BASE_DEFAULT); - } - - public static void autoPadding(View view, int base) - { + public static void autoPadding(View view, int base) { auto(view, Attrs.PADDING, base); } - public static void autoSize(View view) - { - auto(view, Attrs.WIDTH | Attrs.HEIGHT, AutoAttr.BASE_DEFAULT); - } - - public static void autoSize(View view, int base) - { + public static void autoSize(View view, int base) { auto(view, Attrs.WIDTH | Attrs.HEIGHT, base); } - public static boolean autoed(View view) - { + public static boolean autoed(View view) { Object tag = view.getTag(R.id.id_tag_autolayout_size); if (tag != null) return true; view.setTag(R.id.id_tag_autolayout_size, "Just Identify"); return false; } - public static float getPercentWidth1px() - { + public static float getPercentWidth1px() { int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); return 1.0f * screenWidth / designWidth; } - public static float getPercentHeight1px() - { + public static float getPercentHeight1px() { int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); return 1.0f * screenHeight / designHeight; } - public static int getPercentWidthSize(int val) - { + public static int getPercentWidthSize(int val) { int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); return (int) (val * 1.0f / designWidth * screenWidth); } - public static int getPercentWidthSizeBigger(int val) - { + public static int getPercentWidthSizeBigger(int val) { int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); int res = val * screenWidth; - if (res % designWidth == 0) - { + if (res % designWidth == 0) { return res / designWidth; - } else - { + } else { return res / designWidth + 1; } } - public static int getPercentHeightSizeBigger(int val) - { + public static int getPercentHeightSizeBigger(int val) { int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); int res = val * screenHeight; - if (res % designHeight == 0) - { + if (res % designHeight == 0) { return res / designHeight; - } else - { + } else { return res / designHeight + 1; } } - public static int getPercentHeightSize(int val) - { + public static int getPercentHeightSize(int val) { int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); diff --git a/build.gradle b/build.gradle index c207088..e127966 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,28 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply from: "config.gradle" buildscript { repositories { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' - classpath 'com.github.dcendents:android-maven-plugin:1.2' + classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.novoda:bintray-release:0.3.4' } } allprojects { repositories { jcenter() + maven { url "https://jitpack.io" } + } + + tasks.withType(Javadoc) { + options { + encoding "UTF-8" + charSet 'UTF-8' + links "http://docs.oracle.com/javase/7/docs/api" + failOnError false + } } } diff --git a/config.gradle b/config.gradle new file mode 100644 index 0000000..bbd32eb --- /dev/null +++ b/config.gradle @@ -0,0 +1,24 @@ +ext { + + android = [ + compileSdkVersion: 23, + buildToolsVersion: "25.0.0", + minSdkVersion : 15, + targetSdkVersion : 23, + versionCode : 1, + versionName : "20180601" + ] + + dependVersion = [ + support: "23.4.0" + ] + + dependencies = [ + // support + appcompatV7 : "com.android.support:appcompat-v7:${dependVersion.support}", + recyclerview: "com.android.support:recyclerview-v7:${dependVersion.support}" + ] + publish =[ + version : "1.5.0" + ] +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 314e14e..481cbe7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Nov 19 16:52:41 GMT+08:00 2015 +#Fri Jun 01 15:21:24 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 6fc8339..203e44a 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" + compileSdkVersion rootProject.ext.android.compileSdkVersion + buildToolsVersion rootProject.ext.android.buildToolsVersion defaultConfig { applicationId "com.zhy.sample" - minSdkVersion 10 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode rootProject.ext.android.versionCode + versionName rootProject.ext.android.versionName } buildTypes { release { diff --git a/sample/src/main/res/layout/fragment_gridview.xml b/sample/src/main/res/layout/fragment_gridview.xml new file mode 100644 index 0000000..39a8048 --- /dev/null +++ b/sample/src/main/res/layout/fragment_gridview.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/widgetsample/build.gradle b/widgetsample/build.gradle index 513b9f8..01e5c87 100644 --- a/widgetsample/build.gradle +++ b/widgetsample/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" + compileSdkVersion rootProject.ext.android.compileSdkVersion + buildToolsVersion rootProject.ext.android.buildToolsVersion defaultConfig { applicationId "com.zhy.autolayout.test.widgets" - minSdkVersion 10 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode rootProject.ext.android.versionCode + versionName rootProject.ext.android.versionName } buildTypes { release { From 7c79e0ef987c8442ac293c5c1d263ec3a5b0536f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=A4=B4?= <48025211@qq.com> Date: Fri, 1 Jun 2018 15:59:57 +0800 Subject: [PATCH 3/3] lintOptions --- autolayout-widget/build.gradle | 4 ++++ autolayout/src/main/java/com/zhy/autolayout/attr/Attrs.java | 2 +- .../src/main/java/com/zhy/autolayout/utils/ScreenUtils.java | 2 +- sample/build.gradle | 4 ++++ .../java/com/zhy/sample/fragment/RecyclerViewFragment.java | 2 +- sample/src/main/res/layout/recyclerview_item.xml | 3 ++- widgetsample/build.gradle | 4 ++++ 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/autolayout-widget/build.gradle b/autolayout-widget/build.gradle index 5cbf4ad..7dddcdf 100644 --- a/autolayout-widget/build.gradle +++ b/autolayout-widget/build.gradle @@ -15,6 +15,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + lintOptions { + abortOnError false + } + } dependencies { diff --git a/autolayout/src/main/java/com/zhy/autolayout/attr/Attrs.java b/autolayout/src/main/java/com/zhy/autolayout/attr/Attrs.java index 774d803..9c894ca 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/attr/Attrs.java +++ b/autolayout/src/main/java/com/zhy/autolayout/attr/Attrs.java @@ -2,7 +2,7 @@ /** * Created by zhy on 15/12/5. - *

+ *

* 与attrs.xml中数值对应 */ public interface Attrs diff --git a/autolayout/src/main/java/com/zhy/autolayout/utils/ScreenUtils.java b/autolayout/src/main/java/com/zhy/autolayout/utils/ScreenUtils.java index d7db439..92135e6 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/utils/ScreenUtils.java +++ b/autolayout/src/main/java/com/zhy/autolayout/utils/ScreenUtils.java @@ -9,7 +9,7 @@ import android.view.WindowManager; /** - * Created by zhy on 15/12/4.
+ * Created by zhy on 15/12/4.
* form http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels/15699681#15699681 */ public class ScreenUtils diff --git a/sample/build.gradle b/sample/build.gradle index 203e44a..831ff99 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -17,6 +17,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + lintOptions { + abortOnError false + } + } dependencies { diff --git a/sample/src/main/java/com/zhy/sample/fragment/RecyclerViewFragment.java b/sample/src/main/java/com/zhy/sample/fragment/RecyclerViewFragment.java index 781a72b..cb85f40 100755 --- a/sample/src/main/java/com/zhy/sample/fragment/RecyclerViewFragment.java +++ b/sample/src/main/java/com/zhy/sample/fragment/RecyclerViewFragment.java @@ -60,7 +60,7 @@ public MyAdapter(Context context, List datas) public com.zhy.base.adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { com.zhy.base.adapter.ViewHolder viewHolder = super.onCreateViewHolder(parent, viewType); - AutoUtils.autoSize(viewHolder.getConvertView()); + AutoUtils.auto(viewHolder.getConvertView()); return viewHolder; } diff --git a/sample/src/main/res/layout/recyclerview_item.xml b/sample/src/main/res/layout/recyclerview_item.xml index 5648870..5c427eb 100755 --- a/sample/src/main/res/layout/recyclerview_item.xml +++ b/sample/src/main/res/layout/recyclerview_item.xml @@ -4,7 +4,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="244px" + android:layout_height="wrap_content" + android:minHeight="244px" android:orientation="vertical" >