Giter Site home page Giter Site logo

robertlevonyan / media-picker Goto Github PK

View Code? Open in Web Editor NEW
191.0 6.0 35.0 725 KB

Easy customizable picker for all your needs in Android application

License: Apache License 2.0

Kotlin 100.00%
android android-application android-app android-library android-studio android-development android-ui androidstudio android-sdk android-architecture

media-picker's Introduction

    Universal Media Picker

Easy customizable picker for all your needs in Android application
Android Arsenal Android Arsenal API
PickerDialogVersion Maven Central
PickerComposeVersion Maven Central

Setup

Add following line of code to your project level gradle file

  repositories {
    mavenCentral()
  }

Gradle:

Add following line of code to your module(app) level gradle file

    implementation 'com.robertlevonyan.components:Picker:<PickerDialogVersion>'

Kotlin:

    implementation("com.robertlevonyan.components:Picker:$PickerDialogVersion")

Maven:

  <dependency>
    <groupId>com.robertlevonyan.components</groupId>
    <artifactId>Picker</artifactId>
    <version>PickerDialogVersion</version>
    <type>pom</type>
  </dependency>

For Jetpack Compose version

    implementation("com.robertlevonyan.compose:picker:$PickerComposeVersion")

Usage

Buildung picker

  // in fragment or activity
  pickerDialog {
    setTitle(...)          // String value or resource ID
    setTitleTextSize(...)  // Text size of title
    setTitleTextColor(...) // Color of title text
    setListType(...)       // Type of the picker, must be PickerDialog.TYPE_LIST or PickerDialog.TYPE_Grid
    setItems(...)          // List of ItemModel-s which should be in picker
 }.setPickerCloseListener { type: ItemType, uris: List<Uri> ->
   // Getting the result
   when (type) {
            ItemType.Camera -> /* do something with the photo you've taken */
            ItemType.Video -> /* do something with the video you've recorded */
            is ItemType.ImageGallery -> /* do something with the images you've chosen */
            is ItemType.AudioGallery -> /* do something with the audios you've chosen */
            is ItemType.VideoGallery -> /* do something with the videos you've chosen */
            is ItemType.Files -> /* do something with the files you've chosen */
        }
 }.show()

Creating items

  /*  Create a camera item, can be
      ItemType.Camera
      ItemType.Video
      ItemType.ImageGallery
      ItemType.AudioGallery
      ItemType.VideoGallery
      ItemType.Files
  */
  val itemModel = ItemModel(ItemModel.Camera)
  
  // Some optional parameters
  val itemModel = ItemModel(
                    ItemModel.Camera,
                    itemLabel, // Default value is "", in this case default text value will be set
                    itemIcon,  // Default value is 0, in this case default icon will be set
                    hasBackground, // draw a shape background over the icon, default value is true
                    backgroundType, // choose a type for icon background, only works if hasBackground is true, can have one of
                                    // this values: ItemType.TYPE_CIRCLE, ItemType.TYPE_SQUARE, ItemType.TYPE_ROUNDED_SQUARE
                    itemBackgroundColor, // custom color for background shape, only works if hasBackground is true, 
                                         // default color is accent color of your app
                    )

Now you can set custom file types for pickers

 MimeType.Audio.All
 MimeType.Audio.Mp3
 MimeType.Audio.M4a
 MimeType.Audio.Wav
 MimeType.Audio.Amr
 MimeType.Audio.Awb
 MimeType.Audio.Ogg
 MimeType.Audio.Aac
 MimeType.Audio.Mka
 MimeType.Audio.Midi
 MimeType.Audio.Flac

 MimeType.Video.All
 MimeType.Video.Mpeg
 MimeType.Video.Mp4
 MimeType.Video.`3gp
 MimeType.Video.Mkv
 MimeType.Video.Webm
 MimeType.Video.Avi

 MimeType.Image.All
 MimeType.Image.Jpeg
 MimeType.Image.Png
 MimeType.Image.Gif
 MimeType.Image.Bmp
 MimeType.Image.Webp

 MimeType.Files.All
 MimeType.Files.Txt
 MimeType.Files.Html
 MimeType.Files.Pdf
 MimeType.Files.Doc
 MimeType.Files.Xls
 MimeType.Files.Ppt
 MimeType.Files.Zip

 MimeType.Custom() // if you can't find your desired file type you can use this one

For Jetpack Compose version

setContent {
 val coroutine = rememberCoroutineScope()

 PickerDialog(
   dialogTitle = stringResource(id = R.string.app_name),
   dialogTitleSize = 22.sp,
   dialogListType = ListType.TYPE_GRID,
   dialogGridSpan = 3,
   dialogItems = setOf(
     ItemModel(ItemType.Camera, backgroundType = ShapeType.TYPE_ROUNDED_SQUARE, itemBackgroundColor = Color.Red),
     ItemModel(ItemType.Video),
     ItemModel(ItemType.ImageGallery()),
     ItemModel(ItemType.AudioGallery()),
     ItemModel(ItemType.VideoGallery()),
     ItemModel(ItemType.Files())
   ),
   onItemSelected = { selectedUris ->
    // get uris
   }
 ) { bottomSheetState ->
   Column {
     Button(onClick = {
       coroutine.launch {
         if (bottomSheetState.isVisible) {
           bottomSheetState.hide()
         } else {
           bottomSheetState.show()
         }
       }
     }) {
       Text(text = "Open picker")
     }
   }
 }
}

And the result is

List picker Grid picker

Versions

2.2.0

More customizable item types

2.1.2 - 2.1.6

Update to Java 11 SDK 31 ready Minor updates

2.1.1

Single picker issue fixed

2.1.0

Migration to mavenCentral

2.0.1 - 2.0.2

Refactoring and some UI changes

2.0.0

New version of library. Mostly rewritten. Now supports multiple selection.

1.0.1 - 1.1.5

Refactoring and some UI changes

1.0.0

First version of library

Compose versions

1.1.0

More customizable item types

1.0.0

First version of library

Contact

Special thanks to @chimzycash for createing an amazing logo for this project ☺️

Licence

    Universal Media Picker©
    Copyright 2021 Robert Levonyan
    Url: https://github.com/robertlevonyan/MediaPicker

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    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.

media-picker's People

Contributors

robertlevonyan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

media-picker's Issues

Failure when try to pick image from camera

Hi great project!!))) But I have this failure when try to pick image from camera (Android 4.4)
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=66637, result=-1, data=null} to activity {app.nmn.com.easyappclient/app.nmn.com.easyappclient.activity.RegistrationActivity}: java.lang.IllegalStateException: BitmapFactory.decodeFile…context!!).path, options) must not be null
at android.app.ActivityThread.deliverResults(ActivityThread.java:3519)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3562)
at android.app.ActivityThread.access$1300(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1291)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5426)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: BitmapFactory.decodeFile…context!!).path, options) must not be null
at com.robertlevonyan.components.picker.PickerDialog.takePhoto(PickerDialog.kt:462)
at com.robertlevonyan.components.picker.PickerDialog.onActivityResult(PickerDialog.kt:445)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156)
at android.app.Activity.dispatchActivityResult(Activity.java:5488)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3562) 
at android.app.ActivityThread.access$1300(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1291) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5426) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
at dalvik.system.NativeStart.main(Native Method) 
How can I solve this?

KotlinNullPointerException when opening Camera or Gallery

Hi!
Great idea your project!

I found out that, when I try to open the Camera I get this error:
04-20 09:06:12.062 6638-6638/app.com.app E/AndroidRuntime: FATAL EXCEPTION: main Process: app.com.app, PID: 6638 kotlin.KotlinNullPointerException at com.robertlevonyan.components.picker.PickerDialog$createList$2.invoke(PickerDialog.kt:252) at com.robertlevonyan.components.picker.PickerDialog$createList$2.invoke(PickerDialog.kt:36) at com.robertlevonyan.components.picker.BaseAdapter$onBindViewHolder$1.onClick(BaseAdapter.kt:25) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22433) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6186) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

When trying to open Gallery I get this error:

04-20 09:07:24.597 6812-6812/app.com.app E/AndroidRuntime: FATAL EXCEPTION: main Process: app.com.app, PID: 6812 kotlin.KotlinNullPointerException at com.robertlevonyan.components.picker.PickerDialog$createList$2.invoke(PickerDialog.kt:266) at com.robertlevonyan.components.picker.PickerDialog$createList$2.invoke(PickerDialog.kt:36) at com.robertlevonyan.components.picker.BaseAdapter$onBindViewHolder$1.onClick(BaseAdapter.kt:25) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22433) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6186) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Why did I get these errors? How can I fix them?

Center title

Hi, thanks for the great library. Is there any way to center the title ?

Take Photo

onPickerClosed not called

Crashing App
Activity Restarted

Picker Version :: 1.2.5
Android Device :: xiaomi redmi 7 Android 9 API 28

Custom item model

Hi,
when use Custom item model background is not change.
hasBackround value is true and color value is setted but item using default color

Version 2.2.0 did not import components

I am using the kotlin version when updating to the new version 2.2.0, it is not importing the pickerDialog class, Captura de Tela 2022-04-04 às 14 34 35

it seems that it imports the compose folder.
Captura de Tela 2022-04-04 às 14 44 34

unused file provider, conflict between apps

Hy, you are declaring a file provider but your are not using it. However the "android::authority" of this provider on the manifest is going to be the same in whatever app you implement your package, which means only one can be installed. You could delete it.

Option of a new Item in the list

I would like to have the option to add a new item that is not in the enum, for example an item with the name of AUDIO, which when clicking I can call my function to capture audios.

Selecting Multiple Images/Videos

Hi,

I am very interested in giving this library a try. I would like to know if this library supports the selection of multiple images and/or videos

Thanks.

Video duration

It was pleasured to use this library in my project. I have one question can we limited the video duration for example capture video just for 60sec or pick from library with 60sec.

OOM - Samsung galaxy GT-I9300 Android 4.3

Great Library, Working really well except this OOM issue on the device above
It can be fixed but the problem is inside PickerDialog.kt the function takePhoto at line:452 is private so It cant overridden.
Normally I deal with this by using method to tweak the bitmap before rotating which should fix this issue (Java)
`{

    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        options.inDither = true;
        Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);

        ExifInterface exif = new ExifInterface(file.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
        Matrix matrix = new Matrix();
        if (orientation == 6) {
            matrix.postRotate(90);
        }
        else if (orientation == 3) {
            matrix.postRotate(180);
        }
        else if (orientation == 8) {
            matrix.postRotate(270);
        }
        myBitmap = Bitmap.createBitmap(myBitmap, 0, 0, myBitmap.getWidth(), myBitmap.getHeight(), matrix, true); // rotating bitmap
        imageView.setImageBitmap(myBitmap);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}`

And here is Stacktrace
03-29 15:01:32.110 11420-11420/com.go.app.dev E/AndroidRuntime: FATAL EXCEPTION: main java.lang.OutOfMemoryError at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:726) at android.graphics.Bitmap.createBitmap(Bitmap.java:703) at android.graphics.Bitmap.createBitmap(Bitmap.java:636) at com.robertlevonyan.components.picker.ExtensionsKt.rotate(Extensions.kt:76) at com.robertlevonyan.components.picker.PickerDialog.takePhoto(PickerDialog.kt:462) at com.robertlevonyan.components.picker.PickerDialog.onActivityResult(PickerDialog.kt:444) at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156) at android.app.Activity.dispatchActivityResult(Activity.java:5563) at android.app.ActivityThread.deliverResults(ActivityThread.java:3496) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3543) at android.app.ActivityThread.access$1200(ActivityThread.java:159) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) at dalvik.system.NativeStart.main(Native Method)

Permissions not granted in Android 13

For Android 13, even after granting the app permissions for the gallery and camera, the permissions are not granted by Android. It shows "Camera permission not granted" and "Cannot access gallery" in the logcat.

Cannot take photo or record video ?

cannot take photo or record video from camera, i try using device LG, android 6
after select not open camera, always display pop up, but when to take image or video from gallery working fine

Android10 Crash!

Caused by: java.lang.IllegalStateException: BitmapFactory.decodeFile…context!!).path, options) must not be null
        at com.robertlevonyan.components.picker.PickerDialog.pickPhoto(PickerDialog.kt:529)
        at com.robertlevonyan.components.picker.PickerDialog.onActivityResult(PickerDialog.kt:485)
        at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:170)
        at android.app.Activity.dispatchActivityResult(Activity.java:8110)

https://developer.android.com/about/versions/10/privacy/changes#scoped-storage

Custom Items

Does it have custom item. Like for example I have a default sound.. Is there an option to choose "Use default" in item list?

When I trying to open dialog then it's crash and I got this error.

I used latest version 2.0.2

Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.activity.result.contract.ActivityResultContracts$RequestMultiplePermissions" on path: DexPathList[[zip file "/data/app/com.xxx.xxxxx-BiLH_ikskpr6kaGBsJ4yNQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxxxx-BiLH_ikskpr6kaGBsJ4yNQ==/lib/arm64, /system/lib64, /system/product/lib64]]

Code

pickerDialog {
            setTitle(R.string.capture_or_upload_picture)
            setTitleTextSize(15F)  // Text size of title
            setTitleTextColor(Color.BLACK) // Color of title text
            setListType(PickerDialog.ListType.TYPE_GRID)
            setItems(
                setOf(
                    ItemModel(
                        ItemType.ITEM_CAMERA,
                        backgroundType = ShapeType.TYPE_CIRCLE,
                        itemBackgroundColor = ContextCompat.getColor(
                            this@CreatePostActivity,
                            R.color.colorPrimary
                        )
                    ),
                    ItemModel(
                        ItemType.ITEM_GALLERY,
                        backgroundType = ShapeType.TYPE_CIRCLE,
                        itemBackgroundColor = ContextCompat.getColor(
                            this@CreatePostActivity,
                            R.color.colorPrimary
                        )
                    )
                )
            )
        }.setPickerCloseListener { type: ItemType, uris: List<Uri> ->
            //I do some stuff here
        }.show()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.