Skip to content

Commit

Permalink
update v1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hantrungkien committed Oct 8, 2020
1 parent 08d77ee commit d9684f7
Show file tree
Hide file tree
Showing 54 changed files with 22,171 additions and 109,288 deletions.
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "htkien.autodimension"
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
Expand All @@ -21,6 +21,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation project(':autodimens')
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.12'
}
7 changes: 6 additions & 1 deletion app/src/main/java/htkien/autodimension/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package htkien.autodimension;

import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.text_dpi);
String dimenFileName = getString(R.string.dimenFileName);
textView.setText(dimenFileName);
}
}
5 changes: 4 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context="htkien.autodimension.MainActivity">

<TextView
android:id="@+id/text_dpi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
android:textSize="@dimen/_12sp"
tools:text="@string/dimenFileName" />

</LinearLayout>
54 changes: 31 additions & 23 deletions autodimens.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
* Created by kienht - 1.7.2017
*/
//./gradlew createDimen
public class AutoFactory extends DefaultTask {
class AutoFactory extends DefaultTask {
@TaskAction
def create() {}
}

public class DimenFactory extends DefaultTask {
class DimenFactory extends DefaultTask {

@Input
int[] dimens = [240, 320, 360, 384, 400, 411, 420, 432, 450, 480, 540, 560, 570, 600, 640, 660, 720, 750, 768, 800, 840, 854,
960, 1024, 1080, 1125, 1136, 1280, 1334, 1366, 1440, 1536, 1600, 1680, 1920, 2048, 2436, 2560, 3840];
int[] dimens = [320, 360, 384, 390, 400, 411, 420, 433, 450, 480, 533, 540, 561, 600, 640, 681, 720, 768, 800, 886, 960, 1024, 1080, 1280, 1366, 1440, 1920, 2560, 3840];
@Input
int fromDimen = 360;
@Input
double positiveMaxDP = 1200
double positiveMaxDP = 300
@Input
double positiveMaxSP = 200
double negativeMaxDP = 100
@Input
double negativeMaxDP = 200
double positiveMaxSP = 60

String resFolder = project.getProjectDir().getPath() + "/src/main/res/"

Expand All @@ -29,29 +29,38 @@ public class DimenFactory extends DefaultTask {

def autoCreateDimen() {
for (int dimen : dimens) {
String folder = resFolder + "values-sw" + (int) dimen + "dp";
String folderName = "values-sw" + (int) dimen + "dp";
String folder = resFolder + folderName
String fileName = folder + "/auto_dimens.xml";
new File(folder).mkdir();
new File(fileName).createNewFile();
PrintWriter printWriter = new PrintWriter(fileName);
printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
printWriter.println("<resources>");
String dimenFileName = "\t<string name=\"dimenFileName\">" + folderName + "</string>\r"
printWriter.println(dimenFileName);

for (int i = 1; i <= positiveMaxDP; i++) {
double ratio = i / fromDimen;
double sdp = ratio * dimen;
double haftSdp = (1 / fromDimen) * dimen * 0.5d;
printWriter.printf("\t<dimen name=\"_%ddp\">%.2fdp</dimen>\r\n", i, sdp);
printWriter.printf("\t<dimen name=\"_%d_5dp\">%.2fdp</dimen>\r\n", i, sdp + haftSdp);
double dp = ratio * dimen;
double haftDp = dp * 0.5d;
if (i == 1) {
printWriter.printf("\t<dimen name=\"_0_5dp\">%.2fdp</dimen>\r\n", haftDp);
}
printWriter.printf("\t<dimen name=\"_%ddp\">%.2fdp</dimen>\r\n", i, dp);
printWriter.printf("\t<dimen name=\"_%d_5dp\">%.2fdp</dimen>\r\n", i, dp + haftDp);
}
for (int i = 1; i <= positiveMaxSP; i++) {

for (int i = 1; i <= negativeMaxDP; i++) {
double ratio = i / fromDimen;
double sdp = ratio * dimen;
printWriter.printf("\t<dimen name=\"_%dsp\">%.2fsp</dimen>\r\n", i, sdp);
double dp = ratio * dimen;
printWriter.printf("\t<dimen name=\"minus_%ddp\">%.2fdp</dimen>\r\n", i, -dp);
}
for (int i = 1; i <= negativeMaxDP; i++) {

for (int i = 1; i <= positiveMaxSP; i++) {
double ratio = i / fromDimen;
double sdp = ratio * dimen;
printWriter.printf("\t<dimen name=\"minus_%ddp\">%.2fdp</dimen>\r\n", i, -sdp);
double sp = ratio * dimen;
printWriter.printf("\t<dimen name=\"_%dsp\">%.2fsp</dimen>\r\n", i, sp);
}

printWriter.println("</resources>");
Expand All @@ -63,10 +72,9 @@ public class DimenFactory extends DefaultTask {
task createDimen(type: DimenFactory) {}

createDimen {
dimens = [240, 320, 360, 384, 400, 411, 420, 432, 450, 480, 540, 560, 570, 600, 640, 660, 720, 750, 768, 800, 840, 854,
960, 1024, 1080, 1125, 1136, 1280, 1334, 1366, 1440, 1536, 1600, 1680, 1920, 2048, 2436, 2560, 3840];
dimens = [320, 360, 384, 390, 400, 411, 420, 433, 450, 480, 533, 540, 561, 600, 640, 681, 720, 768, 800, 886, 960, 1024, 1080, 1280, 1366, 1440, 1920, 2560, 3840];
fromDimen = 360
positiveMaxDP = 1200 //change to 600 or any other value if needed
positiveMaxSP = 200 //change to 600 or any other value if needed
negativeMaxDP = 200 //change to 600 or any other value if needed
positiveMaxDP = 300
negativeMaxDP = 100
positiveMaxSP = 60
}
9 changes: 4 additions & 5 deletions autodimens/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ apply plugin: 'com.android.library'
apply from: "../autodimens.gradle"

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "30.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

}
buildTypes {
Expand All @@ -27,6 +27,5 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
}
Loading

0 comments on commit d9684f7

Please sign in to comment.