Skip to content

Commit

Permalink
prepare 1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kienht committed Oct 5, 2021
1 parent beda58a commit e1de637
Show file tree
Hide file tree
Showing 9 changed files with 2,542 additions and 33 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,41 @@ Auto Dimension
[![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html)
[![](https://jitpack.io/v/hantrungkien/AutoDimension.svg)](https://jitpack.io/#hantrungkien/AutoDimension)

### install:
## install:

**via JitPack (to get current code)**

project/build.gradle
````gradle
```gradle
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
````
```
module/build.gradle
````gradle
compile 'com.github.hantrungkien:AutoDimension:1.0.8'
````
``gradle
compile 'com.github.hantrungkien:AutoDimension:1.0.9'
```
#### How to use:
## How to use:
````xml
```xml
<TextView
android:id="@+id/work_time_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/_1dp"/>
````
```

### Contribution
## Extensions

```kotlin
Context.dpToPx(dp: Number)
Context.pxToDp(px: Number)
```

## Contribution

If you've found an error, please file an issue.

Expand Down
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 29
Expand All @@ -22,6 +23,8 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':autodimens')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation 'androidx.appcompat:appcompat:1.3.1'
testImplementation 'junit:junit:4.12'
}
18 changes: 0 additions & 18 deletions app/src/main/java/htkien/autodimension/MainActivity.java

This file was deleted.

22 changes: 22 additions & 0 deletions app/src/main/java/htkien/autodimension/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package htkien.autodimension

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView = findViewById<TextView>(R.id.text_dpi)
val dimenFileName = getString(R.string.dimenFileName)
textView.text = dimenFileName

Log.e(TAG, "onCreate: ${resources.configuration.smallestScreenWidthDp}")
}

companion object {
private val TAG = MainActivity::class.java.simpleName
}
}
4 changes: 2 additions & 2 deletions autodimens.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AutoFactory extends DefaultTask {
class DimensionFactory extends DefaultTask {

@Input
int[] dimens = [0, 320, 360, 384, 390, 400, 411, 420, 433, 450, 480, 533, 540, 561, 600, 640, 681, 720, 768, 800, 840, 886, 960, 1024, 1080, 1280, 1366, 1440, 1600, 1920, 2560, 3840];
int[] dimens = [0, 320, 360, 384, 390, 400, 411, 420, 433, 450, 480, 533, 540, 561, 600, 640, 673, 681, 720, 768, 800, 840, 886, 960, 1024, 1080, 1280, 1366, 1440, 1600, 1920, 2560, 3840];
@Input
int fromDimension = 360;
@Input
Expand Down Expand Up @@ -79,7 +79,7 @@ class DimensionFactory extends DefaultTask {
task createDimension(type: DimensionFactory) {}

createDimension {
dimens = [0, 320, 360, 384, 390, 400, 411, 420, 433, 450, 480, 533, 540, 561, 600, 640, 681, 720, 768, 800, 840, 886, 960, 1024, 1080, 1280, 1366, 1440, 1600, 1920, 2560, 3840];
dimens = [0, 320, 360, 384, 390, 400, 411, 420, 433, 450, 480, 533, 540, 561, 600, 640, 673, 681, 720, 768, 800, 840, 886, 960, 1024, 1080, 1280, 1366, 1440, 1600, 1920, 2560, 3840];
fromDimension = 360
positiveMaxDP = 600
negativeMaxDP = 600
Expand Down
11 changes: 11 additions & 0 deletions autodimens/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply from: "../autodimens.gradle"

android {
Expand All @@ -23,9 +24,19 @@ android {
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testImplementation 'junit:junit:4.12'
}
16 changes: 16 additions & 0 deletions autodimens/src/main/java/com/kienht/autodimen/AutoDimenExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.kienht.autodimen

import android.content.Context
import android.util.DisplayMetrics

/**
* @author kienht
* @since 29/09/2021
*/
fun Context.dpToPx(dp: Number): Float {
return dp.toFloat() * (resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)
}

fun Context.pxToDp(px: Number): Float {
return px.toFloat() / (resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)
}
Loading

0 comments on commit e1de637

Please sign in to comment.