diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..22a4ace --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +Change Log +=============================================================================== +Version 1.0 *(2015-01-28)* +---------------------------- +Initial release. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..25d6ca7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 - 2015 Intuit Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2bef8ea --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# SSP - a scalable size unit for texts +An android SDK that provides a new size unit - ssp (scalable sp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens. + +# Attention +Use it carefully! for example, in most cases you still need to design a different layout for tablets. + +# Example +[Here](https://github.com/intuit/ssp/blob/master/ssp-android/src/main/res/layout/ssp_example.xml) is a single layout built using ssp: + +![ssp example](https://github.com/intuit/ssp/blob/master/ssp_example.png) + +And [here](https://github.com/intuit/ssp/blob/master/ssp-android/src/main/res/layout/sp_example.xml) is the same layout built using sp: + +![sp example](https://github.com/intuit/ssp/blob/master/sp_example.png) + +You can see that ssp scales with the screen size and the sp stays with the same size on all screen sizes. + +# Getting Started + +To add ssp to your Android Studio project: + + add compile 'com.intuit.ssp:ssp-android:1.0.4’ to your build.gradle dependencies block. + + for example: + + ``` + dependencies { + compile 'com.intuit.ssp:ssp-android:1.0.4’ + } + ``` + +See the [ssp_example.xml](https://github.com/intuit/ssp/blob/master/ssp-android/src/main/res/layout/ssp_example.xml) to see how to use to the ssp size unit. + +# Note +The ssp size unit calculation includes some approximation due to some performance and usability constraints. diff --git a/sp_example.png b/sp_example.png new file mode 100644 index 0000000..2e4a0b8 Binary files /dev/null and b/sp_example.png differ diff --git a/ssp-android/build.gradle b/ssp-android/build.gradle new file mode 100644 index 0000000..2a364b4 --- /dev/null +++ b/ssp-android/build.gradle @@ -0,0 +1,142 @@ +apply plugin: 'com.android.library' +apply plugin: 'maven' +apply plugin: 'signing' + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.2' + } +} + + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.1" + + defaultConfig { + minSdkVersion 13 + targetSdkVersion 25 + } +} + +public class SSPFactory extends DefaultTask { + + @Input + String unit = "sp" + @Input + double positiveMax = 600 + @Input + double negativeMax = 60 + + @TaskAction + def create() { + String resFolder = project.getProjectDir().getPath() + "/src/main/res/"; + for(double dimen = 300; dimen <= 800 ; dimen = dimen + 30){ + createPositive(resFolder, dimen) + } + for(double dimen = 300; dimen <= 800; dimen = dimen + 30){ + createNegative(resFolder, dimen) + } + createPositive(resFolder, 1080) + createNegative(resFolder, 1080) + } + + private void createNegative(String resFolder, double dimen) { + String folder = resFolder + "values-sw" + (int) dimen + "dp"; + String fileName = folder + "/negative_ssps.xml"; + new File(folder).mkdir(); + new File(fileName).createNewFile(); + PrintWriter printWriter = new PrintWriter(fileName); + printWriter.println(""); + printWriter.println(""); + for (int i = 1; i <= negativeMax; i++) { + double ratio = i / 300d; + double ssp = ratio * dimen; + printWriter.printf("\t%.2f" + unit + "\r\n", i, -ssp); + } + printWriter.println(""); + printWriter.close(); + } + + private void createPositive(String resFolder, double dimen) { + String folder = resFolder + "values-sw" + (int) dimen + "dp"; + String fileName = folder + "/positive_ssps.xml"; + new File(folder).mkdir(); + new File(fileName).createNewFile(); + PrintWriter printWriter = new PrintWriter(fileName); + printWriter.println(""); + printWriter.println(""); + for (int i = 1; i <= positiveMax; i++) { + double ratio = i / 300d; + double ssp = ratio * dimen; + printWriter.printf("\t%.2f" + unit + "\r\n", i, ssp); + } + printWriter.println(""); + printWriter.close(); + } +} + +task createSSP(type: SSPFactory) { +} + +//uncomment next line to edit values +preBuild.dependsOn createSSP + +createSSP{ + unit = "sp"//change to "sp" if needed + positiveMax = 600//change to 600 or any other value if needed + negativeMax = 60//change to 600 or any other value if needed +} + +signing { + required { gradle.taskGraph.hasTask("uploadArchives") } + sign configurations.archives +} + +//uploadArchives { +// configuration = configurations.archives +// repositories.mavenDeployer { +// beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } +// +// repository(url: sonatypeRepo) { +// authentication(userName: sonatypeUsername, +// password: sonatypePassword) +// } +// +// pom.groupId = 'com.intuit.ssp' +// pom.artifactId = 'ssp-android' +// pom.version = '1.0.4' +// +// pom.project { +// name 'ssp' +// packaging 'aar' +// description 'A scalable size unit for Andorid' +// url 'https://github.com/intuit/ssp' +// +// scm { +// url 'https://github.com/intuit/ssp' +// connection 'scm:git@github.com:intuit/ssp.git' +// developerConnection 'scm:git@github.com:intuit/ssp.git' +// } +// +// licenses { +// license { +// name 'The MIT License (MIT)' +// url 'https://github.com/intuit/ssp/blob/master/LICENSE' +// distribution 'repo' +// } +// } +// +// developers { +// developer { +// id developerID +// name developerName +// email developerEmail +// } +// } +// } +// } +//} diff --git a/ssp-android/src/main/AndroidManifest.xml b/ssp-android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..685a2a0 --- /dev/null +++ b/ssp-android/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + diff --git a/ssp-android/src/main/project.properties b/ssp-android/src/main/project.properties new file mode 100644 index 0000000..03d0617 --- /dev/null +++ b/ssp-android/src/main/project.properties @@ -0,0 +1,15 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-10 +android.library=true diff --git a/ssp-android/src/main/res/layout/sp_example.xml b/ssp-android/src/main/res/layout/sp_example.xml new file mode 100644 index 0000000..81dbb8e --- /dev/null +++ b/ssp-android/src/main/res/layout/sp_example.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + +