Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkSangGwon committed Sep 10, 2019
2 parents 7bdb530 + ad581f9 commit 420143e
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 39 deletions.
88 changes: 62 additions & 26 deletions README.md
@@ -1,65 +1,76 @@

# TedImagePicker [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-TedImagePicker-green.svg?style=flat )]( https://android-arsenal.com/details/1/7697 )

# TedImagePicker [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-TedImagePicker-green.svg?style=flat)](https://android-arsenal.com/details/1/7697)

TedImagePicker is **simple/beautiful/smart** image picker

- Support Image/Video
- Support Single/Multi select
- Support more configuration option


| Image Select | Select Album | Scroller |
|:------------------------------:|:---------------------------------:|:--------------------------------:|
|![](art/multi_select.png) |![](art/album.png) |![](art/scroll_handler.png)|

| Image Select | Select Album | Scroller |
| :-----------------------: | :----------------: | :-------------------------: |
| ![](art/multi_select.png) | ![](art/album.png) | ![](art/scroll_handler.png) |

</br></br>

## Demo

![](art/full.gif)

| Image Select | Select Album | Scroller |
|:------------------------------:|:---------------------------------:|:--------------------------------:|
|![](art/multi_select.gif) |![](art/album.gif) |![](art/scroll_handler.gif)|
| Image Select | Select Album | Scroller |
| :-----------------------: | :----------------: | :-------------------------: |
| ![](art/multi_select.gif) | ![](art/album.gif) | ![](art/scroll_handler.gif) |

</br></br>
## Setup

## Setup

### Gradle

[ ![Download](https://api.bintray.com/packages/tkdrnjs0912/maven/tedimagepicker/images/download.svg) ](https://bintray.com/tkdrnjs0912/maven/tedimagepicker/_latestVersion)

```gradle
dependencies {
implementation 'gun0912.ted:tedimagepicker:x.y.z'
//implementation 'gun0912.ted:tedimagepicker:1.0.0'
}
```

If you think this library is useful, please press star button at upside. </br>
<img src="https://phaser.io/content/news/2015/09/10000-stars.png" width="200">



</br></br>

## How to use

### 1.Enable databinding

- TedImagePicker use databinding
- Set enable databinding in your app `build.gradle`

```
dataBinding {
enabled = true
}
```

### 2.Start TedImagePicker/TedRxImagePicker

- TedImagePicker support `Listener` and `RxJava`style

#### Listener

##### Single image

- Kotlin

```kotlin
TedImagePicker.with(this)
.start { uri -> showSingleImage(uri) }
```

- Java

```java
TedImagePicker.with(this)
.start(new OnSelectedListener() {
Expand All @@ -71,16 +82,20 @@ TedImagePicker.with(this)
TedImagePicker.with(this)
.start(uri -> {
showSingleImage(uri);
});
});
```

##### Multi image

- Kotlin

```kotlin
TedImagePicker.with(this)
.startMultiImage { uriList -> showMultiImage(uriList) }
```

- Java

```java
TedImagePicker.with(this)
.startMultiImage(new OnMultiSelectedListener() {
Expand All @@ -94,17 +109,22 @@ TedImagePicker.with(this)
showMultiImage(uriList);
});
```

<br/>

#### RxJava

##### Single image

```kotlin
TedRxImagePicker.with(this)
.start()
.subscribe({ uri ->
}, Throwable::printStackTrace)
```

##### Multi image

```kotlin
TedRxImagePicker.with(this)
.startMultiImage()
Expand All @@ -113,12 +133,15 @@ TedRxImagePicker.with(this)
```

</br></br>

## Customize

- You can customize what you want

### Function

#### Common

* `mediaType(MediaType)` : MediaType.IMAGE / MediaType.VIDEO
* `cameraTileBackground(R.color.xxx)`
* `cameraTileImage(R.drawable.xxx)`
Expand All @@ -130,32 +153,44 @@ TedRxImagePicker.with(this)
* `image()`
* `video()`

- `mediaType(MediaType)` : MediaType.IMAGE / MediaType.VIDEO
- `cameraTileBackground(R.color.xxx)`
- `cameraTileImage(R.drawable.xxx)`
- `showCameraTile(Boolean) (default: true)`
- `scrollIndicatorDateFormat(String)(default: YYYY.MM)`
- `title(String or R.string.xxx) (default: 'Select Image','사진 선택')`
- `backButton(R.drawable.xxx)`
- `zoomIndicator(Boolean) (default: true)`

#### Multi Select
* `selectedUri(List<Uri>)`
* `buttonGravity(ButtonGravity)`: You can change `done` button location top or bottom
* `buttonText(String or R.string.xxx) (default: 'Done','완료')`
* `max(Int, String or R.string.xxx)`
* `min(Int, String or R.string.xxx)`
</br></br>

- `selectedUri(List<Uri>)`
- `buttonGravity(ButtonGravity)`: You can change `done` button location top or bottom
- `buttonText(String or R.string.xxx) (default: 'Done','완료')`
- `buttonBackground(R.drawable.xxx) (default: Blue Background)`
- `buttonTextColor(R.color.xxx) (default: white)`
- `max(Int, String or R.string.xxx)`
- `min(Int, String or R.string.xxx)`
</br></br>

## FAQ

### - Do not need to check permissions?

- Yes, `TedImagePicker` automatically check permission.
: `TedImagePicker` use [TedPermission](https://github.com/ParkSangGwon/TedPermission)
: `TedImagePicker` use [TedPermission](https://github.com/ParkSangGwon/TedPermission)
- But If you need You can check permission before start `TedImagePicker`.

### - java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/databinding/DataBinderMapperImpl;

- You have to enable databinding
- Read [this](https://github.com/ParkSangGwon/TedImagePicker/blob/master/README.md#1enable-databinding)

</br></br>

## License


</br></br>
## License
```code
````code
Copyright 2019 Ted Park
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -169,3 +204,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.```
````
Expand Up @@ -45,6 +45,8 @@ class MainActivity : AppCompatActivity() {
//.mediaType(MediaType.IMAGE)
//.scrollIndicatorDateFormat("YYYYMMDD")
//.buttonGravity(ButtonGravity.BOTTOM)
//.buttonBackground(R.drawable.btn_sample_done_button)
//.buttonTextColor(R.color.sample_yellow)
.errorListener { message -> Log.d("ted", "message: $message") }
.selectedUri(selectedUriList)
.startMultiImage { list: List<Uri> -> showMultiImage(list) }
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/btn_sample_done_button.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="4dp" />
<solid android:color="@color/sample_white" />
</shape>
4 changes: 2 additions & 2 deletions app/src/main/res/values/colors.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>


<color name="sample_yellow">#EFDC05</color>
<color name="sample_white">#ffffff</color>
</resources>
Expand Up @@ -14,6 +14,7 @@ import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -100,9 +101,14 @@ internal class TedImagePickerActivity : AppCompatActivity() {
}

private fun setupButton() {
with(binding) {
buttonGravity = builder.buttonGravity
buttonText = builder.buttonText ?: getString(builder.buttonTextResId)
buttonTextColor = ContextCompat.getColor(this@TedImagePickerActivity, builder.buttonTextColorResId)
buttonBackground =
ContextCompat.getDrawable(this@TedImagePickerActivity, builder.buttonBackgroundResId)
}

binding.buttonGravity = builder.buttonGravity
binding.buttonText = builder.buttonText ?: getString(builder.buttonTextResId)
setupButtonVisibility()
}

Expand Down Expand Up @@ -415,6 +421,5 @@ internal class TedImagePickerActivity : AppCompatActivity() {
data.getParcelableArrayListExtra(EXTRA_SELECTED_URI_LIST)
}


}

Expand Up @@ -39,6 +39,10 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
internal var titleResId: Int = R.string.ted_image_picker_title,
internal var buttonGravity: ButtonGravity = ButtonGravity.TOP,
internal var buttonText: String? = null,
@DrawableRes
internal var buttonBackgroundResId: Int = R.drawable.btn_done_button,
@ColorRes
internal var buttonTextColorResId: Int = R.color.white,
@StringRes
internal var buttonTextResId: Int = R.string.ted_image_picker_done,
internal var selectedUriList: List<Uri>? = null,
Expand Down Expand Up @@ -150,7 +154,6 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
return this as B
}


fun buttonText(text: String): B {
this.buttonText = text
return this as B
Expand All @@ -161,6 +164,16 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
return this as B
}

fun buttonBackground(@DrawableRes buttonBackgroundResId: Int): B {
this.buttonBackgroundResId = buttonBackgroundResId
return this as B
}

fun buttonTextColor(@ColorRes buttonTextColorResId: Int): B {
this.buttonTextColorResId = buttonTextColorResId
return this as B
}

fun selectedUri(uriList: List<Uri>?): B {
this.selectedUriList = uriList
return this as B
Expand Down
18 changes: 16 additions & 2 deletions tedimagepicker/src/main/res/layout/activity_ted_image_picker.xml
Expand Up @@ -25,6 +25,14 @@
name="buttonText"
type="String" />

<variable
name="buttonBackground"
type="android.graphics.drawable.Drawable" />

<variable
name="buttonTextColor"
type="Integer" />

</data>

<LinearLayout
Expand All @@ -49,7 +57,10 @@
android:layout_gravity="end"
android:layout_marginEnd="@dimen/default_padding_small"
android:visibility="@{showButton &amp;&amp; buttonGravity == ButtonGravity.TOP ? View.VISIBLE : View.GONE}"
app:text="@{buttonText}" />
app:text="@{buttonText}"
app:textColor="@{buttonTextColor}"
android:background="@{buttonBackground}"
/>

</androidx.appcompat.widget.Toolbar>

Expand Down Expand Up @@ -80,7 +91,10 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:text="@{buttonText}" />
app:text="@{buttonText}"
app:textColor="@{buttonTextColor}"
android:background="@{buttonBackground}"
/>


<LinearLayout
Expand Down
15 changes: 10 additions & 5 deletions tedimagepicker/src/main/res/layout/layout_done_button.xml
Expand Up @@ -3,27 +3,32 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="text"
type="String" />

<variable
name="background"
type="android.graphics.drawable.Drawable" />

<variable
name="textColor"
type="Integer" />
</data>

<TextView
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:background="@{background}"
android:layout_height="wrap_content"
android:background="@drawable/btn_done_button"
android:gravity="center"
android:orientation="vertical"
android:paddingStart="@dimen/ted_image_picker_done_button_horizontal_padding"
android:paddingTop="@dimen/ted_image_picker_done_button_vertical_padding"
android:paddingEnd="@dimen/ted_image_picker_done_button_horizontal_padding"
android:paddingBottom="@dimen/ted_image_picker_done_button_vertical_padding"
android:text="@{text}"
android:textColor="@color/white"
tools:text="완료">
android:textColor="@{textColor}"
tools:text="완료" />

</TextView>
</layout>

0 comments on commit 420143e

Please sign in to comment.