[
  {
    "path": ".gitignore",
    "content": "#Android generated\nbin\ngen\ngen*\n\n#Eclipse\n.project\n.classpath\n.settings\n\n#IntelliJ IDEA\n.idea\n*.iml\n*.ipr\n*.iws\nout\n\n#Maven\ntarget\nrelease.properties\npom.xml.*\n\n#Ant\nbuild.xml\nlocal.properties\nproguard.cfg\n\n#Gradle\n.gradle\nbuild\n\n#OSX\n.DS_Store\n\n#Personal Files\nsigning.\n\n\n# Built application files\n*.apk\n*.ap_\n\n# Files for the Dalvik VM\n*.dex\n\n# Java class files\n*.class\n\n# Generated files\nbin/\ngen/\n\n# Gradle files\n.gradle/\nbuild/\n\n# Local configuration file (sdk path, etc)\nlocal.properties\n\n# Proguard folder generated by Eclipse\nproguard/\n\n# Log Files\n*.log\n\ngradle.properties\ngradle/\ngradlew\ngradlew.bat"
  },
  {
    "path": "README.md",
    "content": "# Android-ScaleLayout\n\nA Simple & Convenience MultiScreen-Support-Library for Android\n\n## The essence is percent scaling.\n\n### different from ``android-percent-support-lib``\n\n1. **More reliable**      \n    ``android-percent-support-lib`` The percentage of the parent and child views.       \n    ``Android-ScaleLayout`` The percentage of the design and devices screens.       \n\n2. **More convenience**       \n    ``android-percent-support-lib`` need to calculate percent.      \n    ``Android-ScaleLayout`` directly write the design size on ``layout.xml``.       \n\n\n## How to look?\n\n![screenhot](/screenhot.png)\n\n\n## Principle\n\n```java\nfloat realPixel = percent * designPixel\n```\n\n### Pix Mode\n\n```java\nfloat realPixel = percent * designPixel\n\nfloat percent = mScreenWidth / designScreenWidth\n\nfloat designPixel = res.getDimensionPixelSize()\n```\n```java\nfloat realPixel = mScreenWidth * res.getDimensionPixelSize() / designScreenWidth\n```\n\n### DP Mode\n```java\nfloat realPixel = percent * designPixel\n\nfloat percent = mScreenWidth / designScreenWidth\nfloat designPixel = designDP * designDensity // dp to pixel\n\nfloat designDP = res.getDimensionPixelSize() / mDensity\n```\n```java\nfloat realPixel = (mScreenWidth * designDensity * getPixelSize()) / (designScreenWidth * mDensity)\n```\n\n## Usage\n\n### 0. dependencies\n\n```\ndependencies {\n    compile 'cn.gavinliu.android.lib:ScaleLayout:1.0.4'\n}\n```\n\n### 1. Initialize\n\n```java\npublic class MyApplication extends Application {\n\n    @Override\n    public void onCreate() {\n        ScaleConfig.create(this,\n            1080, // Design Width\n            1920, // Design Height\n            3,    // Design Density\n            3,    // Design FontScale\n            ScaleConfig.DIMENS_UNIT_DP);\n    }\n}\n```\n\n> ``TypedValue.COMPLEX_UNIT_SP`` is Android FontSize unit, the ``fontscale``:\n> float fontScale = ctx.getResources().getDisplayMetrics().scaledDensity;\n\n### 2. Scale***Layout\n\nOnly need to replace ``FrameLayout`` ``LinearLayout`` ``RelativeLayout`` to ``ScaleFrameLayout`` ``ScaleLinearLayout`` ``ScaleRelativeLayout``.\n\n### 3. Scale by width or height\n\nWidth is default, you can also changed using attr.\n\n```xml\n<attr name=\"layout_scale_by\" format=\"enum\">\n    <enum name=\"width\" value=\"0\"/>\n    <enum name=\"height\" value=\"1\"/>\n</attr>\n```\n```xml\napp:layout_scale_by=\"width\"\n```\n\n### Support Attrs\n\n```xml\n<attr name=\"android:layout_width\"/>\n<attr name=\"android:layout_height\"/>\n\n<attr name=\"android:layout_margin\"/>\n<attr name=\"android:layout_marginLeft\"/>\n<attr name=\"android:layout_marginTop\"/>\n<attr name=\"android:layout_marginRight\"/>\n<attr name=\"android:layout_marginBottom\"/>\n<attr name=\"android:layout_marginStart\"/>\n<attr name=\"android:layout_marginEnd\"/>\n\n<attr name=\"android:padding\"/>\n<attr name=\"android:paddingLeft\"/>\n<attr name=\"android:paddingTop\"/>\n<attr name=\"android:paddingRight\"/>\n<attr name=\"android:paddingBottom\"/>\n<attr name=\"android:paddingStart\"/>\n<attr name=\"android:paddingEnd\"/>\n\n<!-- TextView -->\n<attr name=\"android:textSize\"/>\n```\n\n## License\n\nMIT\n"
  },
  {
    "path": "README_zh.md",
    "content": "# Android-ScaleLayout\n\n一个简单的,方便的多屏适配的Android库\n\n## 本质就是百分比缩放\n\n### 和 android-percent-support-lib 的不同\n\n1. **更科学**      \n    ``android-percent-support-lib`` 是父控件和子控件的百分比关系      \n    ``Android-ScaleLayout`` 是设计界面和设备界面的百分比关系      \n\n2. **更方便**\n    ``android-percent-support-lib`` 需要把设计尺寸算成百分比      \n    ``Android-ScaleLayout`` 直接把设计尺寸填入``layou.xml``即可      \n\n\n## How to look?\n\n![screenhot](/screenhot.png)\n\n\n## 原理\n\n```java\nfloat realPixel = percent * designPixel\n```\n\n### Pix Mode\n\n```java\nfloat realPixel = percent * designPixel\n\nfloat percent = mScreenWidth / designScreenWidth\n\nfloat designPixel = res.getDimensionPixelSize()\n```\n```java\nfloat realPixel = mScreenWidth * res.getDimensionPixelSize() / designScreenWidth\n```\n\n### DP Mode\n```java\nfloat realPixel = percent * designPixel\n\nfloat percent = mScreenWidth / designScreenWidth\nfloat designPixel = designDP * designDensity // dp to pixel\n\nfloat designDP = res.getDimensionPixelSize() / mDensity\n```\n```java\nfloat realPixel = (mScreenWidth * designDensity * getPixelSize()) / (designScreenWidth * mDensity)\n```\n\n## 使用\n\n### 0. 依赖\n\n```\ndependencies {\n    compile 'cn.gavinliu.android.lib:ScaleLayout:1.0.4'\n}\n```\n\n### 1. 初始化\n\n```java\npublic class MyApplication extends Application {\n\n    @Override\n    public void onCreate() {\n        ScaleConfig.create(this,\n            1080, // Design Width\n            1920, // Design Height\n            3,    // Design Density\n            3,    // Design FontScale\n            ScaleConfig.DIMENS_UNIT_DP);\n    }\n}\n```\n\n> Android 文字大小的单位是 ``sp``，字体的缩放方式需要 FontScale：\n> float fontScale = ctx.getResources().getDisplayMetrics().scaledDensity;\n\n### 2. Scale***Layout\n\n只需要把 ``FrameLayout`` ``LinearLayout`` ``RelativeLayout`` 替换成 ``ScaleFrameLayout`` ``ScaleLinearLayout`` ``ScaleRelativeLayout``.\n\n### 3. Scale by width or height\n\n默认是 width，当然你可以用属性修改。\n\n```xml\n<attr name=\"layout_scale_by\" format=\"enum\">\n    <enum name=\"width\" value=\"0\"/>\n    <enum name=\"height\" value=\"1\"/>\n</attr>\n```\n```xml\napp:layout_scale_by=\"width\"\n```\n\n### 支持的属性\n\n```xml\n<attr name=\"android:layout_width\"/>\n<attr name=\"android:layout_height\"/>\n\n<attr name=\"android:layout_margin\"/>\n<attr name=\"android:layout_marginLeft\"/>\n<attr name=\"android:layout_marginTop\"/>\n<attr name=\"android:layout_marginRight\"/>\n<attr name=\"android:layout_marginBottom\"/>\n<attr name=\"android:layout_marginStart\"/>\n<attr name=\"android:layout_marginEnd\"/>\n\n<attr name=\"android:padding\"/>\n<attr name=\"android:paddingLeft\"/>\n<attr name=\"android:paddingTop\"/>\n<attr name=\"android:paddingRight\"/>\n<attr name=\"android:paddingBottom\"/>\n<attr name=\"android:paddingStart\"/>\n<attr name=\"android:paddingEnd\"/>\n\n<!-- TextView -->\n<attr name=\"android:textSize\"/>\n```\n\n## License\n\nMIT\n"
  },
  {
    "path": "Sample/.gitignore",
    "content": "/build\n"
  },
  {
    "path": "Sample/build.gradle",
    "content": "apply plugin: 'com.android.application'\n\nandroid {\n    compileSdkVersion 24\n    buildToolsVersion \"24.0.1\"\n\n    defaultConfig {\n        applicationId \"cn.gavinliu.android_scalelayout\"\n        minSdkVersion 9\n        targetSdkVersion 24\n        versionCode 1\n        versionName \"1.0\"\n    }\n    buildTypes {\n        release {\n            minifyEnabled false\n            proguardFiles 'proguard-rules.pro'\n        }\n    }\n}\n\ndependencies {\n//    compile project(':ScaleLayout')\n    compile 'cn.gavinliu.android.lib:ScaleLayout:1.0.4'\n\n    compile 'com.android.support:appcompat-v7:24.2.0'\n}\n"
  },
  {
    "path": "Sample/proguard-rules.pro",
    "content": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /home/gavin/Develop/android-sdk/tools/proguard/proguard-android.txt\n# You can edit the include path and order by changing the proguardFiles\n# directive in build.gradle.\n#\n# For more details, see\n#   http://developer.android.com/guide/developing/tools/proguard.html\n\n# Add any project specific keep options here:\n\n# If your project uses WebView with JS, uncomment the following\n# and specify the fully qualified class name to the JavaScript interface\n# class:\n#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\n#   public *;\n#}\n"
  },
  {
    "path": "Sample/src/androidTest/java/cn/gavinliu/android_scalelayout/ApplicationTest.java",
    "content": "package cn.gavinliu.android_scalelayout;\n\nimport android.app.Application;\nimport android.test.ApplicationTestCase;\n\n/**\n * <a href=\"http://d.android.com/tools/testing/testing_android.html\">Testing Fundamentals</a>\n */\npublic class ApplicationTest extends ApplicationTestCase<Application> {\n    public ApplicationTest() {\n        super(Application.class);\n    }\n}"
  },
  {
    "path": "Sample/src/main/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n          package=\"cn.gavinliu.android_scalelayout\">\n\n    <application\n        android:name=\".MainApplication\"\n        android:allowBackup=\"true\"\n        android:configChanges=\"keyboardHidden|orientation|screenSize|locale\"\n        android:icon=\"@mipmap/ic_launcher\"\n        android:label=\"@string/app_name\"\n        android:theme=\"@style/AppTheme\">\n        <activity\n            android:name=\".MainActivity\"\n            android:label=\"@string/app_name\">\n            <intent-filter>\n                <action android:name=\"android.intent.action.MAIN\"/>\n\n                <category android:name=\"android.intent.category.LAUNCHER\"/>\n            </intent-filter>\n        </activity>\n\n        <activity\n            android:name=\".DemoActivity\"\n            android:label=\"Demo\"/>\n\n        <activity\n            android:name=\".DemoListActivity\"\n            android:label=\"Demo List\"/>\n\n    </application>\n\n</manifest>\n"
  },
  {
    "path": "Sample/src/main/java/cn/gavinliu/android_scalelayout/DemoActivity.java",
    "content": "package cn.gavinliu.android_scalelayout;\n\nimport android.os.Bundle;\nimport android.support.annotation.Nullable;\nimport android.support.v7.app.AppCompatActivity;\n\n/**\n * Created by Gavin on 2016/11/20.\n */\n\npublic class DemoActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(@Nullable Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_demo);\n    }\n}\n"
  },
  {
    "path": "Sample/src/main/java/cn/gavinliu/android_scalelayout/DemoListActivity.java",
    "content": "package cn.gavinliu.android_scalelayout;\n\nimport android.content.Context;\nimport android.os.Bundle;\nimport android.support.annotation.NonNull;\nimport android.support.annotation.Nullable;\nimport android.support.v7.app.AppCompatActivity;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.widget.BaseAdapter;\nimport android.widget.ListView;\n\n/**\n * Created by Gavin on 2016/11/20.\n */\n\npublic class DemoListActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(@Nullable Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_demo_list);\n\n        ListView listView = (ListView) findViewById(R.id.list);\n        listView.setAdapter(new Adapter(getApplicationContext()));\n    }\n\n    @NonNull\n    @Override\n    public LayoutInflater getLayoutInflater() {\n        return super.getLayoutInflater();\n    }\n\n    private static class Adapter extends BaseAdapter {\n\n        private Context ctx;\n\n        private Adapter(Context ctx) {\n            this.ctx = ctx;\n        }\n\n        @Override\n        public int getCount() {\n            return 20;\n        }\n\n        @Override\n        public Object getItem(int position) {\n            return null;\n        }\n\n        @Override\n        public long getItemId(int position) {\n            return position;\n        }\n\n        @Override\n        public View getView(int position, View convertView, ViewGroup parent) {\n            if (convertView == null) {\n                convertView = LayoutInflater.from(ctx).inflate(R.layout.item_demo_list, parent, false);\n            }\n            return convertView;\n        }\n    }\n\n}\n"
  },
  {
    "path": "Sample/src/main/java/cn/gavinliu/android_scalelayout/MainActivity.java",
    "content": "package cn.gavinliu.android_scalelayout;\n\nimport android.content.Intent;\nimport android.os.Bundle;\nimport android.support.v7.app.AppCompatActivity;\nimport android.view.View;\n\npublic class MainActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n    }\n\n    public void demo(View view) {\n        Intent intent = new Intent(this, DemoActivity.class);\n        startActivity(intent);\n    }\n\n    public void demoList(View view) {\n        Intent intent = new Intent(this, DemoListActivity.class);\n        startActivity(intent);\n    }\n\n}\n"
  },
  {
    "path": "Sample/src/main/java/cn/gavinliu/android_scalelayout/MainApplication.java",
    "content": "package cn.gavinliu.android_scalelayout;\n\nimport android.app.Application;\n\nimport cn.gavinliu.android.lib.scale.config.ScaleConfig;\n\n/**\n * Created by Gavin on 16-11-10.\n */\n\npublic class MainApplication extends Application {\n\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        ScaleConfig.create(this,\n                1080, // Design Width\n                1920, // Design Height\n                3,    // Design Density\n                3,    // Design FontScale\n                ScaleConfig.DIMENS_UNIT_DP);\n        ScaleConfig.getInstance().setDebug(true);\n    }\n}\n"
  },
  {
    "path": "Sample/src/main/res/layout/activity_demo.xml",
    "content": "<cn.gavinliu.android.lib.scale.ScaleRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:id=\"@+id/container\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingTop=\"2dp\">\n\n    <cn.gavinliu.android.lib.scale.ScaleLinearLayout\n        android:id=\"@+id/view\"\n        android:layout_width=\"300dp\"\n        android:layout_height=\"100dp\"\n        android:layout_marginTop=\"6dp\"\n        android:background=\"#ccc\"\n        android:orientation=\"vertical\">\n\n        <TextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginLeft=\"12dp\"\n            android:layout_marginStart=\"12dp\"\n            android:layout_marginTop=\"8dp\"\n            android:background=\"#46b34b\"\n            android:paddingLeft=\"10dp\"\n            android:paddingTop=\"10dp\"\n            android:text=\"@string/app_name\"\n            android:textSize=\"14sp\" />\n\n        <TextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginLeft=\"12dp\"\n            android:layout_marginStart=\"12dp\"\n            android:layout_marginTop=\"8dp\"\n            android:background=\"#46b34b\"\n            android:paddingBottom=\"10dp\"\n            android:paddingTop=\"10dp\"\n            android:text=\"@string/hello_world\" />\n\n    </cn.gavinliu.android.lib.scale.ScaleLinearLayout>\n\n    <cn.gavinliu.android.lib.scale.ScaleFrameLayout\n        android:layout_width=\"360dp\"\n        android:layout_height=\"300dp\"\n        android:layout_below=\"@id/view\"\n        android:layout_marginTop=\"8dp\"\n        android:background=\"#46b\"\n        android:paddingTop=\"8dp\">\n\n        <TextView\n            android:layout_width=\"166dp\"\n            android:layout_height=\"120dp\"\n            android:layout_marginLeft=\"12dp\"\n            android:layout_marginTop=\"8dp\"\n            android:background=\"#46b34b\" />\n\n    </cn.gavinliu.android.lib.scale.ScaleFrameLayout>\n\n</cn.gavinliu.android.lib.scale.ScaleRelativeLayout>\n"
  },
  {
    "path": "Sample/src/main/res/layout/activity_demo_list.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\">\n\n    <ListView\n        android:id=\"@+id/list\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"/>\n\n</LinearLayout>"
  },
  {
    "path": "Sample/src/main/res/layout/activity_main.xml",
    "content": "<cn.gavinliu.android.lib.scale.ScaleLinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:id=\"@+id/container\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\">\n\n    <Button\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginTop=\"10dp\"\n        android:onClick=\"demo\"\n        android:text=\"Demo\"/>\n\n    <Button\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginTop=\"10dp\"\n        android:onClick=\"demoList\"\n        android:text=\"Demo List\"/>\n\n</cn.gavinliu.android.lib.scale.ScaleLinearLayout>\n"
  },
  {
    "path": "Sample/src/main/res/layout/item_demo_list.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<cn.gavinliu.android.lib.scale.ScaleLinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"horizontal\"\n    android:padding=\"12dp\">\n\n    <ImageView\n        android:id=\"@+id/imageView\"\n        android:layout_width=\"50dp\"\n        android:layout_height=\"50dp\"\n        android:src=\"@mipmap/ic_launcher\"/>\n\n    <TextView\n        android:id=\"@+id/textView\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginLeft=\"10dp\"\n        android:layout_marginStart=\"10dp\"\n        android:minHeight=\"50dp\"\n        android:text=\"@string/hello_world\"\n        android:textColor=\"#000000\"/>\n\n</cn.gavinliu.android.lib.scale.ScaleLinearLayout>"
  },
  {
    "path": "Sample/src/main/res/menu/menu_main.xml",
    "content": "<menu xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    xmlns:tools=\"http://schemas.android.com/tools\" tools:context=\".MainActivity\">\n    <item android:id=\"@+id/action_settings\" android:title=\"@string/action_settings\"\n        android:orderInCategory=\"100\" app:showAsAction=\"never\" />\n</menu>\n"
  },
  {
    "path": "Sample/src/main/res/values/dimens.xml",
    "content": "<resources>\n\n</resources>\n"
  },
  {
    "path": "Sample/src/main/res/values/strings.xml",
    "content": "<resources>\n    <string name=\"app_name\">Android-ScaleLayout</string>\n\n    <string name=\"hello_world\">Hello world!</string>\n    <string name=\"action_settings\">Settings</string>\n</resources>\n"
  },
  {
    "path": "Sample/src/main/res/values/styles.xml",
    "content": "<resources>\n\n    <!-- Base application theme. -->\n    <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\">\n        <!-- Customize your theme here. -->\n    </style>\n\n</resources>\n"
  },
  {
    "path": "Sample/src/main/res/values-w820dp/dimens.xml",
    "content": "<resources>\n    <!-- Example customization of dimensions originally defined in res/values/dimens.xml\n         (such as screen margins) for screens with more than 820dp of available width. This\n         would include 7\" and 10\" devices in landscape (~960dp and ~1280dp respectively). -->\n    <dimen name=\"activity_horizontal_margin\">64dp</dimen>\n</resources>\n"
  },
  {
    "path": "ScaleLayout/.gitignore",
    "content": "/build\n"
  },
  {
    "path": "ScaleLayout/build.gradle",
    "content": "apply plugin: 'com.android.library'\n\nandroid {\n    compileSdkVersion 24\n    buildToolsVersion \"24.0.1\"\n\n    defaultConfig {\n        minSdkVersion 9\n        targetSdkVersion 24\n        versionCode 5\n        versionName \"1.0.4\"\n    }\n    buildTypes {\n        release {\n            minifyEnabled false\n            proguardFiles 'proguard-rules.pro'\n        }\n    }\n}\n\ndependencies {\n    compile 'com.android.support:support-v4:24.2.0'\n}\n\napply plugin: 'com.github.dcendents.android-maven'\napply plugin: 'com.jfrog.bintray'\n\ndef siteUrl = 'https://github.com/gavinliu/Android-ScaleLayout' // 项目的主页\ndef gitUrl = 'https://github.com/gavinliu/Android-ScaleLayout.git' // Git仓库的url\n\nversion = \"1.0.4\"\ngroup = \"cn.gavinliu.android.lib\"\n\ninstall {\n    repositories.mavenInstaller {\n        pom {\n            project {\n                packaging 'aar'\n\n                //添加项目描述\n                name 'ScaleLayout: A MultiScreen-Support-Library for Android'\n                url siteUrl\n\n                //设置开源证书信息\n                licenses {\n                    license {\n                        name 'The MIT License (MIT)'\n                        url 'http://mit-license.org/'\n                    }\n                }\n                //添加开发者信息\n                developers {\n                    developer {\n                        id 'gavin6liu'\n                        name 'Gavin.Liu'\n                        email 'gavin6liu@gmail.com'\n                    }\n                }\n\n                scm {\n                    connection gitUrl\n                    developerConnection gitUrl\n                    url siteUrl\n                }\n            }\n        }\n    }\n}\n\ntask sourcesJar(type: Jar) {\n    from android.sourceSets.main.java.srcDirs\n    classifier = 'sources'\n}\n\ntask javadoc(type: Javadoc) {\n    source = android.sourceSets.main.java.srcDirs\n    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))\n}\n\ntask javadocJar(type: Jar, dependsOn: javadoc) {\n    classifier = 'javadoc'\n    from javadoc.destinationDir\n}\n\nartifacts {\n    archives javadocJar\n    archives sourcesJar\n}\n\nProperties properties = new Properties()\nproperties.load(project.rootProject.file('local.properties').newDataInputStream())\n\nbintray {\n    user = properties.getProperty(\"bintray.user\")\n    key = properties.getProperty(\"bintray.apikey\")\n\n    configurations = ['archives']\n\n    pkg {\n        repo = \"maven\"//上传的中央仓库名称\n        name = \"ScaleLayout\"//上传的项目的名字\n        websiteUrl = siteUrl\n        vcsUrl = gitUrl\n        licenses = [\"MIT\"]\n        publish = true  //是否发布\n    }\n}"
  },
  {
    "path": "ScaleLayout/proguard-rules.pro",
    "content": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /home/gavin/Develop/android-sdk/tools/proguard/proguard-android.txt\n# You can edit the include path and order by changing the proguardFiles\n# directive in build.gradle.\n#\n# For more details, see\n#   http://developer.android.com/guide/developing/tools/proguard.html\n\n# Add any project specific keep options here:\n\n# If your project uses WebView with JS, uncomment the following\n# and specify the fully qualified class name to the JavaScript interface\n# class:\n#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\n#   public *;\n#}\n"
  },
  {
    "path": "ScaleLayout/src/androidTest/java/cn/gavinliu/android/lib/scale/ApplicationTest.java",
    "content": "package cn.gavinliu.android.lib.scale;\n\nimport android.app.Application;\nimport android.test.ApplicationTestCase;\n\n/**\n * <a href=\"http://d.android.com/tools/testing/testing_android.html\">Testing Fundamentals</a>\n */\npublic class ApplicationTest extends ApplicationTestCase<Application> {\n    public ApplicationTest() {\n        super(Application.class);\n    }\n}"
  },
  {
    "path": "ScaleLayout/src/main/AndroidManifest.xml",
    "content": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"cn.gavinliu.android.lib.scale\">\n\n    <application android:allowBackup=\"true\" android:label=\"@string/app_name\">\n\n    </application>\n\n</manifest>\n"
  },
  {
    "path": "ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/ScaleFrameLayout.java",
    "content": "package cn.gavinliu.android.lib.scale;\n\nimport android.content.Context;\nimport android.content.res.TypedArray;\nimport android.util.AttributeSet;\nimport android.widget.FrameLayout;\n\nimport cn.gavinliu.android.lib.scale.helper.ScaleLayoutHelper;\n\n/**\n * Created by GavinLiu on 2015-08-10\n */\npublic class ScaleFrameLayout extends FrameLayout {\n\n    private ScaleLayoutHelper mHelper;\n\n    public ScaleFrameLayout(Context context) {\n        this(context, null);\n    }\n\n    public ScaleFrameLayout(Context context, AttributeSet attrs) {\n        this(context, attrs, 0);\n    }\n\n    public ScaleFrameLayout(Context context, AttributeSet attrs, int defStyle) {\n        super(context, attrs, defStyle);\n        if (!isInEditMode()) {\n            mHelper = ScaleLayoutHelper.create(this, attrs);\n        }\n    }\n\n    @Override\n    protected LayoutParams generateDefaultLayoutParams() {\n        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);\n    }\n\n    @Override\n    public LayoutParams generateLayoutParams(AttributeSet attrs) {\n        return new LayoutParams(this.getContext(), attrs, isInEditMode());\n    }\n\n    @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        if (!isInEditMode()) {\n            this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);\n            this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);\n        }\n\n        super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n//        if (this.mHelper.handleMeasuredStateTooSmall()) {\n//            super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n//        }\n    }\n\n    @Override\n    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {\n        super.onLayout(changed, left, top, right, bottom);\n//        this.mHelper.restoreOriginalParams();\n    }\n\n    public static class LayoutParams extends FrameLayout.LayoutParams implements ScaleLayoutHelper.ScaleLayoutParams {\n        private ScaleLayoutHelper.ScaleLayoutInfo mPercentLayoutInfo;\n\n        public LayoutParams(Context c, AttributeSet attrs) {\n            super(c, attrs);\n            this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);\n        }\n\n        private LayoutParams(Context c, AttributeSet attrs, boolean isInEditMode) {\n            super(c, attrs);\n            if (!isInEditMode) {\n                this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);\n            }\n        }\n\n        public LayoutParams(int width, int height) {\n            super(width, height);\n        }\n\n        public LayoutParams(android.view.ViewGroup.LayoutParams source) {\n            super(source);\n        }\n\n        public LayoutParams(MarginLayoutParams source) {\n            super(source);\n        }\n\n        @Override\n        public ScaleLayoutHelper.ScaleLayoutInfo getScaleLayoutInfo() {\n            return this.mPercentLayoutInfo;\n        }\n\n        @Override\n        protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) {\n            ScaleLayoutHelper.fetchWidthAndHeight(this, a, widthAttr, heightAttr);\n        }\n\n        @Override\n        public void setMargins(int left, int top, int right, int bottom) {\n            super.setMargins(left, top, right, bottom);\n            if (mPercentLayoutInfo != null) {\n                mPercentLayoutInfo.setMargins(left, top, right, bottom);\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/ScaleLinearLayout.java",
    "content": "package cn.gavinliu.android.lib.scale;\n\nimport android.annotation.TargetApi;\nimport android.content.Context;\nimport android.content.res.TypedArray;\nimport android.os.Build;\nimport android.util.AttributeSet;\nimport android.widget.LinearLayout;\n\nimport cn.gavinliu.android.lib.scale.helper.ScaleLayoutHelper;\n\n/**\n * Created by Gavin on 16-9-20.\n */\npublic class ScaleLinearLayout extends LinearLayout {\n\n    private ScaleLayoutHelper mHelper;\n\n    public ScaleLinearLayout(Context context) {\n        this(context, null);\n    }\n\n    public ScaleLinearLayout(Context context, AttributeSet attrs) {\n        this(context, attrs, 0);\n    }\n\n    @TargetApi(Build.VERSION_CODES.HONEYCOMB)\n    public ScaleLinearLayout(Context context, AttributeSet attrs, int defStyle) {\n        super(context, attrs, defStyle);\n        if (!isInEditMode()) {\n            mHelper = ScaleLayoutHelper.create(this, attrs);\n        }\n    }\n\n    @Override\n    protected LayoutParams generateDefaultLayoutParams() {\n        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);\n    }\n\n    @Override\n    public LayoutParams generateLayoutParams(AttributeSet attrs) {\n        return new LayoutParams(this.getContext(), attrs, isInEditMode());\n    }\n\n    @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        if (!isInEditMode()) {\n            this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);\n            this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);\n        }\n        super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n//        if (this.mHelper.handleMeasuredStateTooSmall()) {\n//            super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n//        }\n    }\n\n    @Override\n    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {\n        super.onLayout(changed, left, top, right, bottom);\n//        this.mHelper.restoreOriginalParams();\n    }\n\n    public static class LayoutParams extends LinearLayout.LayoutParams implements ScaleLayoutHelper.ScaleLayoutParams {\n        private ScaleLayoutHelper.ScaleLayoutInfo mPercentLayoutInfo;\n\n        public LayoutParams(Context c, AttributeSet attrs) {\n            super(c, attrs);\n            this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);\n        }\n\n        private LayoutParams(Context c, AttributeSet attrs, boolean isInEditMode) {\n            super(c, attrs);\n            if (!isInEditMode) {\n                this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);\n            }\n        }\n\n        public LayoutParams(int width, int height) {\n            super(width, height);\n        }\n\n        public LayoutParams(android.view.ViewGroup.LayoutParams source) {\n            super(source);\n        }\n\n        public LayoutParams(MarginLayoutParams source) {\n            super(source);\n        }\n\n        @Override\n        public ScaleLayoutHelper.ScaleLayoutInfo getScaleLayoutInfo() {\n            return this.mPercentLayoutInfo;\n        }\n\n        @Override\n        protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) {\n            ScaleLayoutHelper.fetchWidthAndHeight(this, a, widthAttr, heightAttr);\n        }\n\n        @Override\n        public void setMargins(int left, int top, int right, int bottom) {\n            super.setMargins(left, top, right, bottom);\n            if (mPercentLayoutInfo != null) {\n                mPercentLayoutInfo.setMargins(left, top, right, bottom);\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/ScaleRelativeLayout.java",
    "content": "package cn.gavinliu.android.lib.scale;\n\nimport android.content.Context;\nimport android.content.res.TypedArray;\nimport android.util.AttributeSet;\nimport android.widget.RelativeLayout;\n\nimport cn.gavinliu.android.lib.scale.helper.ScaleLayoutHelper;\n\n/**\n * Created by GavinLiu on 2015-08-10\n */\npublic class ScaleRelativeLayout extends RelativeLayout {\n\n    private ScaleLayoutHelper mHelper;\n\n    public ScaleRelativeLayout(Context context) {\n        this(context, null);\n    }\n\n    public ScaleRelativeLayout(Context context, AttributeSet attrs) {\n        this(context, attrs, 0);\n    }\n\n    public ScaleRelativeLayout(Context context, AttributeSet attrs, int defStyle) {\n        super(context, attrs, defStyle);\n        if (!isInEditMode()) {\n            mHelper = ScaleLayoutHelper.create(this, attrs);\n        }\n    }\n\n    @Override\n    protected LayoutParams generateDefaultLayoutParams() {\n        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);\n    }\n\n    @Override\n    public LayoutParams generateLayoutParams(AttributeSet attrs) {\n        return new LayoutParams(this.getContext(), attrs, isInEditMode());\n    }\n\n    @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        if (!isInEditMode()) {\n            this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);\n            this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);\n        }\n\n        super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n//        if (this.mHelper.handleMeasuredStateTooSmall()) {\n//            super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n//        }\n    }\n\n    @Override\n    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {\n        super.onLayout(changed, left, top, right, bottom);\n//        this.mHelper.restoreOriginalParams();\n    }\n\n    public static class LayoutParams extends android.widget.RelativeLayout.LayoutParams implements ScaleLayoutHelper.ScaleLayoutParams {\n        private ScaleLayoutHelper.ScaleLayoutInfo mPercentLayoutInfo;\n\n        public LayoutParams(Context c, AttributeSet attrs) {\n            super(c, attrs);\n            this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);\n        }\n\n        private LayoutParams(Context c, AttributeSet attrs, boolean isInEditMode) {\n            super(c, attrs);\n            if (!isInEditMode) {\n                this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);\n            }\n        }\n\n        public LayoutParams(int width, int height) {\n            super(width, height);\n        }\n\n        public LayoutParams(android.view.ViewGroup.LayoutParams source) {\n            super(source);\n        }\n\n        public LayoutParams(MarginLayoutParams source) {\n            super(source);\n        }\n\n        @Override\n        public ScaleLayoutHelper.ScaleLayoutInfo getScaleLayoutInfo() {\n            return this.mPercentLayoutInfo;\n        }\n\n        @Override\n        protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) {\n            ScaleLayoutHelper.fetchWidthAndHeight(this, a, widthAttr, heightAttr);\n        }\n\n        @Override\n        public void setMargins(int left, int top, int right, int bottom) {\n            super.setMargins(left, top, right, bottom);\n            if (mPercentLayoutInfo != null) {\n                mPercentLayoutInfo.setMargins(left, top, right, bottom);\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/config/ScaleConfig.java",
    "content": "package cn.gavinliu.android.lib.scale.config;\n\nimport android.content.Context;\n\n/**\n * Created by Gavin on 16-9-20.\n */\npublic class ScaleConfig {\n\n    private int mDesignWidth;\n    private int mDesignHeight;\n    private float mDesignDensity;\n\n    private int mScreenWidth;\n    private int mScreenHeight;\n    private float mScreenDensity;\n\n    private float mDesignFontScale;\n    private float mScreenFontScale;\n\n    private int mDimensionUnit;\n\n    public static final int DIMENS_UNIT_DP = 0;\n    public static final int DIMENS_UNIT_PIX = 1;\n\n    private boolean mDebug;\n\n    private static ScaleConfig mInstance;\n\n    /**\n     * @param ctx             Context\n     * @param designWidth     Design Width (Pixel)\n     * @param designHeight    Design Height (Pixel)\n     * @param designDensity   Design Density\n     * @param designFontScale Design FontScale (getDisplayMetrics().scaledDensity)\n     * @param dimensionUnit   DIMENS_UNIT_DP or DIMENS_UNIT_PIX\n     * @return Single instance\n     */\n    public static ScaleConfig create(Context ctx, int designWidth, int designHeight, float designDensity, float designFontScale, int dimensionUnit) {\n        if (mInstance == null) {\n            mInstance = new ScaleConfig(ctx, designWidth, designHeight, designDensity, designFontScale, dimensionUnit);\n        }\n\n        return mInstance;\n    }\n\n    public static ScaleConfig getInstance() {\n        if (mInstance == null)\n            throw new IllegalArgumentException(\"You must call ScaleConfig.create first\");\n\n        return mInstance;\n    }\n\n    private ScaleConfig(Context ctx) {\n        final int width = ctx.getResources().getDisplayMetrics().widthPixels;\n        final int height = ctx.getResources().getDisplayMetrics().heightPixels;\n        final float density = ctx.getResources().getDisplayMetrics().density;\n        final float fontScale = ctx.getResources().getDisplayMetrics().scaledDensity;\n\n        mScreenWidth = width;\n        mScreenHeight = height;\n        mScreenDensity = density;\n        mScreenFontScale = fontScale;\n    }\n\n    private ScaleConfig(Context ctx, int designWidth, int designHeight, float designDensity, float designFontScale, int dimensionUnit) {\n        this(ctx);\n        mDesignWidth = designWidth;\n        mDesignHeight = designHeight;\n        mDesignDensity = designDensity;\n        mDesignFontScale = designFontScale;\n        mDimensionUnit = dimensionUnit;\n    }\n\n    public boolean isDebug() {\n        return mDebug;\n    }\n\n    public void setDebug(boolean debug) {\n        mDebug = debug;\n    }\n\n    public boolean isDimensUnitByDp() {\n        return mDimensionUnit == DIMENS_UNIT_DP;\n    }\n\n    public int getDesignWidth() {\n        return mDesignWidth;\n    }\n\n    public int getDesignHeight() {\n        return mDesignHeight;\n    }\n\n    public float getDesignDensity() {\n        return mDesignDensity;\n    }\n\n    public float getScreenDensity() {\n        return mScreenDensity;\n    }\n\n    public float getDesignFontScale() {\n        return mDesignFontScale;\n    }\n\n    public float getScreenFontScale() {\n        return mScreenFontScale;\n    }\n\n    public int getScreenWidth() {\n        return mScreenWidth;\n    }\n\n    public int getScreenHeight() {\n        return mScreenHeight;\n    }\n}\n"
  },
  {
    "path": "ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/helper/ScaleLayoutHelper.java",
    "content": "package cn.gavinliu.android.lib.scale.helper;\n\nimport android.content.Context;\nimport android.content.res.TypedArray;\nimport android.support.v4.view.MarginLayoutParamsCompat;\nimport android.support.v4.view.ViewCompat;\nimport android.util.AttributeSet;\nimport android.util.Log;\nimport android.util.TypedValue;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.widget.TextView;\n\nimport cn.gavinliu.android.lib.scale.R;\nimport cn.gavinliu.android.lib.scale.config.ScaleConfig;\n\n/**\n * Created by GavinLiu on 2015-08-10\n */\npublic class ScaleLayoutHelper {\n\n    private static final String TAG = \"ScaleLayoutHelper\";\n\n    private final ViewGroup mHost;\n    private final ScaleLayoutInfo mHostLayoutInfo;\n\n    public interface ScaleLayoutParams {\n        ScaleLayoutInfo getScaleLayoutInfo();\n    }\n\n    public ScaleLayoutHelper(ViewGroup host, ScaleLayoutInfo layoutInfo) {\n        this.mHost = host;\n        this.mHostLayoutInfo = layoutInfo;\n    }\n\n    public static ScaleLayoutHelper create(ViewGroup view, AttributeSet attrs) {\n        return new ScaleLayoutHelper(view, getScaleLayoutInfo(view.getContext(), attrs));\n    }\n\n    public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {\n        int i = 0;\n        for (int N = this.mHost.getChildCount(); i < N; ++i) {\n            View view = this.mHost.getChildAt(i);\n            ViewGroup.LayoutParams params = view.getLayoutParams();\n\n            if (params instanceof ScaleLayoutParams) {\n                ScaleLayoutInfo info = ((ScaleLayoutParams) params).getScaleLayoutInfo();\n                if (ScaleConfig.getInstance().isDebug()) {\n                    Log.d(TAG, \"adjustChildren using \" + info + \" \" + view);\n                }\n                if (info != null && mHostLayoutInfo != null) {\n                    if (params instanceof ViewGroup.MarginLayoutParams) {\n                        info.fillMarginLayoutParams(view, (ViewGroup.MarginLayoutParams) params);\n                    } else {\n                        info.fillLayoutParams(view, params);\n                    }\n\n                    info.fillView(view);\n                }\n            }\n        }\n    }\n\n    public void adjustHost(int widthMeasureSpec, int heightMeasureSpec) {\n        if (mHostLayoutInfo != null) {\n            ViewGroup.LayoutParams params = mHost.getLayoutParams();\n            if (params instanceof ViewGroup.MarginLayoutParams) {\n                mHostLayoutInfo.fillMarginLayoutParams(mHost, (ViewGroup.MarginLayoutParams) params);\n            } else {\n                mHostLayoutInfo.fillLayoutParams(mHost, params);\n            }\n        }\n    }\n\n    public void restoreOriginalParams() {\n        int i = 0;\n\n        for (int N = this.mHost.getChildCount(); i < N; ++i) {\n            View view = this.mHost.getChildAt(i);\n            ViewGroup.LayoutParams params = view.getLayoutParams();\n\n            if (params instanceof ScaleLayoutParams) {\n                ScaleLayoutInfo info = ((ScaleLayoutParams) params).getScaleLayoutInfo();\n                if (ScaleConfig.getInstance().isDebug()) {\n                    Log.d(TAG, \"restoreOriginalParams using \" + info);\n                }\n\n                if (info != null) {\n                    if (params instanceof ViewGroup.MarginLayoutParams) {\n                        info.restoreMarginLayoutParams((ViewGroup.MarginLayoutParams) params);\n                    } else {\n                        info.restoreLayoutParams(params);\n                    }\n                }\n            }\n        }\n\n    }\n\n    public static void fetchWidthAndHeight(ViewGroup.LayoutParams params, TypedArray array, int widthAttr, int heightAttr) {\n        params.width = array.getLayoutDimension(widthAttr, 0);\n        params.height = array.getLayoutDimension(heightAttr, 0);\n    }\n\n    public static ScaleLayoutInfo getScaleLayoutInfo(Context context, AttributeSet attrs) {\n        ScaleLayoutInfo info = new ScaleLayoutInfo(context);\n\n        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ScaleLayout);\n\n        int value = array.getInt(R.styleable.ScaleLayout_layout_scale_by, 0);\n        if (value != 0) {\n            info.scaleBy = value;\n        }\n\n        try {\n            value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_width, 0);\n            if (value != 0) {\n                info.width = value;\n            }\n        } catch (Exception e) {\n        }\n\n        try {\n            value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_height, 0);\n            if (value != 0) {\n                info.height = value;\n            }\n        } catch (Exception e) {\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_margin, 0);\n        if (value != 0) {\n            info.leftMargin = value;\n            info.topMargin = value;\n            info.rightMargin = value;\n            info.bottomMargin = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_marginLeft, 0);\n        if (value != 0) {\n            info.leftMargin = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_marginTop, 0);\n        if (value != 0) {\n            info.topMargin = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_marginRight, 0);\n        if (value != 0) {\n            info.rightMargin = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_marginBottom, 0);\n        if (value != 0) {\n            info.bottomMargin = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_marginStart, 0);\n        if (value != 0) {\n            info.startMargin = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_layout_marginEnd, 0);\n        if (value != 0) {\n            info.endMargin = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_padding, 0);\n        if (value != 0) {\n            info.leftPadding = value;\n            info.topPadding = value;\n            info.rightPadding = value;\n            info.bottomPadding = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_paddingLeft, 0);\n        if (value != 0) {\n            info.leftPadding = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_paddingTop, 0);\n        if (value != 0) {\n            info.topPadding = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_paddingRight, 0);\n        if (value != 0) {\n            info.rightPadding = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_paddingBottom, 0);\n        if (value != 0) {\n            info.bottomPadding = value;\n        }\n\n        value = array.getDimensionPixelSize(R.styleable.ScaleLayout_android_textSize, 0);\n        if (value != 0) {\n            info.textSize = value;\n        }\n\n        array.recycle();\n\n        if (ScaleConfig.getInstance().isDebug()) {\n            Log.d(TAG, \"constructed: \" + info);\n        }\n        return info;\n    }\n\n    public boolean handleMeasuredStateTooSmall() {\n        boolean needsSecondMeasure = false;\n        int i = 0;\n\n        for (int N = this.mHost.getChildCount(); i < N; ++i) {\n            View view = this.mHost.getChildAt(i);\n            ViewGroup.LayoutParams params = view.getLayoutParams();\n\n            if (params instanceof ScaleLayoutParams) {\n                ScaleLayoutInfo info = ((ScaleLayoutParams) params).getScaleLayoutInfo();\n                if (info != null) {\n                    if (shouldHandleMeasuredWidthTooSmall(view, info)) {\n                        needsSecondMeasure = true;\n                        params.width = ViewGroup.LayoutParams.WRAP_CONTENT;\n                    }\n\n                    if (shouldHandleMeasuredHeightTooSmall(view, info)) {\n                        needsSecondMeasure = true;\n                        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;\n                    }\n                }\n            }\n        }\n\n        if (ScaleConfig.getInstance().isDebug()) {\n            Log.d(TAG, \"should trigger second measure pass: \" + needsSecondMeasure);\n        }\n\n        return needsSecondMeasure;\n    }\n\n    private static boolean shouldHandleMeasuredWidthTooSmall(View view, ScaleLayoutInfo info) {\n        int state = ViewCompat.getMeasuredWidthAndState(view) & ViewCompat.MEASURED_STATE_MASK;\n        return state == ViewCompat.MEASURED_STATE_TOO_SMALL && info.width >= 0.0F && info.mPreservedParams.width == ViewGroup.LayoutParams.WRAP_CONTENT;\n    }\n\n    private static boolean shouldHandleMeasuredHeightTooSmall(View view, ScaleLayoutInfo info) {\n        int state = ViewCompat.getMeasuredHeightAndState(view) & ViewCompat.MEASURED_STATE_MASK;\n        return state == ViewCompat.MEASURED_STATE_TOO_SMALL && info.height >= 0.0F && info.mPreservedParams.height == ViewGroup.LayoutParams.WRAP_CONTENT;\n    }\n\n    public static class ScaleLayoutInfo {\n        private int designWidth;\n        private int designHeight;\n\n        private int screenW;\n        private int screenH;\n\n        public int width = 0;\n        public int height = 0;\n\n        private int scaleBy = ScaleByWidth;\n        private static final int ScaleByWidth = 0;\n        private static final int ScaleByHeight = 1;\n\n        private int leftMargin;\n        private int topMargin;\n        private int rightMargin;\n        private int bottomMargin;\n        private int startMargin;\n        private int endMargin;\n\n        private int leftPadding;\n        private int topPadding;\n        private int rightPadding;\n        private int bottomPadding;\n\n        private int textSize;\n\n        final ViewGroup.MarginLayoutParams mPreservedParams = new ViewGroup.MarginLayoutParams(0, 0);\n\n        public ScaleLayoutInfo(Context ctx) {\n            designWidth = ScaleConfig.getInstance().getDesignWidth();\n            designHeight = ScaleConfig.getInstance().getDesignHeight();\n\n            screenW = ctx.getResources().getDisplayMetrics().widthPixels;\n            screenH = ctx.getResources().getDisplayMetrics().heightPixels;\n        }\n\n        public void fillLayoutParams(View view, ViewGroup.LayoutParams params) {\n            this.mPreservedParams.width = params.width;\n            this.mPreservedParams.height = params.height;\n\n            if (this.width > 0.0) {\n                params.width = getRealPixelSize(this.width);\n            }\n\n            if (this.height > 0.0) {\n                params.height = getRealPixelSize(this.height);\n            }\n\n            int paddingL = 0, paddingT = 0, paddingR = 0, paddingB = 0;\n\n            if (this.leftPadding > 0.0) {\n                paddingL = getRealPixelSize(this.leftPadding);\n            }\n\n            if (this.topPadding > 0.0) {\n                paddingT = getRealPixelSize(this.topPadding);\n            }\n\n            if (this.rightPadding > 0.0) {\n                paddingR = getRealPixelSize(this.rightPadding);\n            }\n\n            if (this.bottomPadding > 0.0) {\n                paddingB = getRealPixelSize(this.bottomPadding);\n            }\n\n            view.setPadding(paddingL, paddingT, paddingR, paddingB);\n        }\n\n        public void fillMarginLayoutParams(View view, ViewGroup.MarginLayoutParams params) {\n            this.fillLayoutParams(view, params);\n            this.mPreservedParams.leftMargin = params.leftMargin;\n            this.mPreservedParams.topMargin = params.topMargin;\n            this.mPreservedParams.rightMargin = params.rightMargin;\n            this.mPreservedParams.bottomMargin = params.bottomMargin;\n            MarginLayoutParamsCompat.setMarginStart(this.mPreservedParams, MarginLayoutParamsCompat.getMarginStart(params));\n            MarginLayoutParamsCompat.setMarginEnd(this.mPreservedParams, MarginLayoutParamsCompat.getMarginEnd(params));\n\n            if (this.leftMargin > 0.0F) {\n                params.leftMargin = getRealPixelSize(this.leftMargin);\n            }\n\n            if (this.topMargin > 0.0F) {\n                params.topMargin = getRealPixelSize(this.topMargin);\n            }\n\n            if (this.rightMargin > 0.0F) {\n                params.rightMargin = getRealPixelSize(this.rightMargin);\n            }\n\n            if (this.bottomMargin > 0.0F) {\n                params.bottomMargin = getRealPixelSize(this.bottomMargin);\n            }\n\n            if (this.startMargin > 0.0F) {\n                MarginLayoutParamsCompat.setMarginStart(params, getRealPixelSize(this.startMargin));\n            }\n\n            if (this.endMargin > 0.0F) {\n                MarginLayoutParamsCompat.setMarginEnd(params, getRealPixelSize(this.endMargin));\n            }\n\n        }\n\n        public void fillView(View view) {\n            if (view instanceof TextView) {\n                if (this.textSize > 0) {\n                    int newTextSize = getRealFontSize(this.textSize);\n                    ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, newTextSize);\n                }\n            }\n        }\n\n        public void restoreMarginLayoutParams(ViewGroup.MarginLayoutParams params) {\n            this.restoreLayoutParams(params);\n            params.leftMargin = this.mPreservedParams.leftMargin;\n            params.topMargin = this.mPreservedParams.topMargin;\n            params.rightMargin = this.mPreservedParams.rightMargin;\n            params.bottomMargin = this.mPreservedParams.bottomMargin;\n            MarginLayoutParamsCompat.setMarginStart(params, MarginLayoutParamsCompat.getMarginStart(this.mPreservedParams));\n            MarginLayoutParamsCompat.setMarginEnd(params, MarginLayoutParamsCompat.getMarginEnd(this.mPreservedParams));\n        }\n\n        public void restoreLayoutParams(ViewGroup.LayoutParams params) {\n            params.width = this.mPreservedParams.width;\n            params.height = this.mPreservedParams.height;\n        }\n\n        public void setMargins(int left, int top, int right, int bottom) {\n            leftPadding = left;\n            topPadding = top;\n            rightPadding = right;\n            bottomPadding = bottom;\n        }\n\n        private int getRealFontSize(int pix) {\n            int screen, design;\n            switch (scaleBy) {\n                case ScaleByHeight:\n                    screen = screenH;\n                    design = designHeight;\n                    break;\n                default:\n                    screen = screenW;\n                    design = designWidth;\n                    break;\n            }\n\n            return getRealPixelSizeBySP(pix, screen, design);\n        }\n\n        private int getRealPixelSize(int pix) {\n            int screen, design;\n            switch (scaleBy) {\n                case ScaleByHeight:\n                    screen = screenH;\n                    design = designHeight;\n                    break;\n                default:\n                    screen = screenW;\n                    design = designWidth;\n                    break;\n            }\n\n            if (ScaleConfig.getInstance().isDimensUnitByDp()) {\n                return getRealPixelSizeByDp(pix, screen, design);\n            } else {\n                return getRealPixelSizeByPix(pix, screen, design);\n            }\n        }\n\n        private int getRealPixelSizeByPix(int pix, int screen, int design) {\n            int result;\n\n            int res = pix * screen;\n\n            if (res % design == 0) {\n                result = res / design;\n            } else {\n                result = res / design + 1;\n            }\n\n            if (ScaleConfig.getInstance().isDebug())\n                Log.i(TAG, \"pix:\" + pix + \",result:\" + result);\n            return result;\n        }\n\n        private int getRealPixelSizeByDp(int pix, int screen, int design) {\n            float density = ScaleConfig.getInstance().getScreenDensity();\n            float designDensity = ScaleConfig.getInstance().getDesignDensity();\n\n            int designDp = convertPix2Dp(density, pix);\n            int designPix = convertDp2Pix(designDensity, designDp);\n\n            int result;\n\n            int res = designPix * screen;\n\n            if (res % design == 0) {\n                result = res / design;\n            } else {\n                result = res / design + 1;\n            }\n\n            if (ScaleConfig.getInstance().isDebug())\n                Log.i(TAG, \"pix:\" + pix + \",dp:\" + designDp + \",result:\" + result);\n            return result;\n        }\n\n        private int getRealPixelSizeBySP(int pix, int screen, int design) {\n            float density = ScaleConfig.getInstance().getScreenFontScale();\n            float designDensity = ScaleConfig.getInstance().getDesignFontScale();\n\n            int designDp = convertPix2Sp(density, pix);\n            int designPix = convertSp2Pix(designDensity, designDp);\n\n            int result;\n\n            int res = designPix * screen;\n\n            if (res % design == 0) {\n                result = res / design;\n            } else {\n                result = res / design + 1;\n            }\n\n            if (ScaleConfig.getInstance().isDebug())\n                Log.i(TAG, \"pix:\" + pix + \",sp:\" + designDp + \",result:\" + result);\n            return result;\n        }\n\n        private static int convertPix2Dp(float density, int px) {\n            return (int) (px / density + 0.5f);\n        }\n\n        private static int convertDp2Pix(float density, int dip) {\n            return (int) (dip * density + 0.5f);\n        }\n\n        private static int convertPix2Sp(float fontScale, float pxValue) {\n            return (int) (pxValue / fontScale + 0.5f);\n        }\n\n        private static int convertSp2Pix(float fontScale, float spValue) {\n            return (int) (spValue * fontScale + 0.5f);\n        }\n    }\n\n}\n"
  },
  {
    "path": "ScaleLayout/src/main/res/values/attrs.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <declare-styleable name=\"ScaleLayout\">\n\n        <attr name=\"layout_scale_by\" format=\"enum\">\n            <enum name=\"width\" value=\"0\"/>\n            <enum name=\"height\" value=\"1\"/>\n        </attr>\n\n        <attr name=\"android:layout_width\"/>\n        <attr name=\"android:layout_height\"/>\n\n        <attr name=\"android:layout_margin\"/>\n        <attr name=\"android:layout_marginLeft\"/>\n        <attr name=\"android:layout_marginTop\"/>\n        <attr name=\"android:layout_marginRight\"/>\n        <attr name=\"android:layout_marginBottom\"/>\n        <attr name=\"android:layout_marginStart\"/>\n        <attr name=\"android:layout_marginEnd\"/>\n\n        <attr name=\"android:padding\"/>\n        <attr name=\"android:paddingLeft\"/>\n        <attr name=\"android:paddingTop\"/>\n        <attr name=\"android:paddingRight\"/>\n        <attr name=\"android:paddingBottom\"/>\n        <attr name=\"android:paddingStart\"/>\n        <attr name=\"android:paddingEnd\"/>\n\n        <!-- TextView -->\n        <attr name=\"android:textSize\"/>\n\n    </declare-styleable>\n\n</resources>"
  },
  {
    "path": "ScaleLayout/src/main/res/values/strings.xml",
    "content": "<resources>\n    <string name=\"app_name\">ScaleLayout</string>\n</resources>\n"
  },
  {
    "path": "build.gradle",
    "content": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:2.2.2'\n\n        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'\n        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.2'\n\n        // NOTE: Do not place your application dependencies here; they belong\n        // in the individual module build.gradle files\n    }\n}\n\nallprojects {\n    repositories {\n        jcenter()\n    }\n}\n\ntask clean(type: Delete) {\n    delete rootProject.buildDir\n}\n"
  },
  {
    "path": "settings.gradle",
    "content": "include ':Sample', ':ScaleLayout'\n"
  }
]