Coder Social home page Coder Social logo

ssimagepicker's Introduction

📸SSImagePicker

Android-Studio API Language Kotlin Version Android Weekly Android Arsenal

Easy to use and configurable library to Pick an image from the Gallery or Capture image using Camera.

  • You can easily select image from camera and gallery and upload it wherever you want. We have created this library to simplify pick or capture image feature.
  • Handled permissions for camera and gallery, also supports scoped storage.
  • Returns contentUri of selected image.
  • Easy to use and supports all major devices.

Features :

  • Capture Image Using Camera
  • Pick Image From Gallery
  • Handle Runtime Permission For Storage And Camera
  • ImagePicker Bottomsheet
  • Retrieve Image Result In Uri Format
  • Crop Image
  • Rotate Image
  • Image Zoom In, Zoom Out
  • Customize Image Picker BottomSheet Options Like :
    • Customize only text of buttons
    • Customize only text color of buttons
    • Customize multiple values of buttons like:
      • Text color, size, font family, padding using your own styles.xml
    • Customize bottomsheet's background shape and color

🎬Preview

Capture Image Using Camera Pick Image From Gallery Customize Bottomsheet
Crop Image Rotate Image Image Zoom in, Zoom out

How it works:

  1. Gradle Dependency
  • Add the JitPack repository to your project's build.gradle file
    allprojects {
        repositories {
            ...
    	    maven { url 'https://jitpack.io' }
        }
    }
  • Add plugin in your app's build.gradle file
    plugins {
        ...
        id 'kotlin-kapt'
    } 
  • Add buildFeature in your app's build.gradle file
    android {
        ...
        buildFeatures {
            dataBinding = true
        }
    }
  • Add the dependency in your app's build.gradle file
    dependencies {
        implementation 'com.github.SimformSolutionsPvtLtd:SSImagePicker:1.8'
    }
  1. Implement ImagePickerBottomsheet.ItemClickListener, ImagePickerActivityClass.OnResult interface in your activity or fragment

  2. Use ImagePicker Bottomsheet To Choose Option For Pick Image From Gallery Or Camera

    val fragment = ImagePickerBottomsheet()
    fragment.show(FragmentManager, String) 
  1. Call ImagePickerActivityClass in your onCreate() To Handle Camera, Gallery Click And Permission Result. Pass Context, Request Permission Result Callback And activityResultRegistry, Activity or Fragment. :
    //From activity
    var imagePicker = ImagePickerActivityClass(context,onResult_Callback,activityResultRegistry,activity = this)

    //From fragment
    var imagePicker = ImagePickerActivityClass(context,onResult_Callback,activityResultRegistry,fragment = this)
  1. To Enable All Features(crop,rotate,zoomIn,zoomOut) call cropOptions(isAllCropFeaturesRequired: Boolean) And Pass true. By Default It's Set To False And Provides Only Crop Feature.
    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        imagePicker.cropOptions(true)
    }
  1. Allow Camera And Storage Permission To Pick Image And Send Your onRequestPermissionsResult To ImagePickerActivity
    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults) (required)
    }
  1. To Capture Image From Camera Use takePhotoFromCamera()
    imagePicker.takePhotoFromCamera()
  1. To Pick Image From Gallery Use choosePhotoFromGallary()
    imagePicker.choosePhotoFromGallary()
  1. Send Your onActivityResult to ImagePickerActivity
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)  (required)
        imagePicker.onActivityResult(requestCode, resultCode, data)
    }
  1. You Will Get Image Result In Uri Format In returnString() And Customize It To Upload
    override fun returnString(item: Uri?) {
        **Here You Will Get Your Image Result In Uri Format**
    }
  1. You can load image in your imageview using loadImage() func. (If you want to apply circleCrop() then pass isCircle = true, by default it's false)
    override fun returnString(item: Uri?) {
        imageViewEditProfile.loadImage(item, isCircle = true) {}
    }

To customize bottomsheet:

  • To customize bottomsheet, first override below method in your activity.
    override fun doCustomisations(fragment: ImagePickerBottomsheet) {
        //Do customizations here...
    }
  • To customize text of buttons in Bottomsheet.
    fragment.setButtonText("Select Camera","Select Gallery","Remove")
  • To only change text color of buttons in Bottomsheet.
    fragment.setButtonColors(ContextCompat.getColor(requireContext(), R.color.colorPrimary))
  • To customize multiple values of buttons (Text color, size, font family, padding), you need to create a style in your style.xml.
    fragment.setTextAppearance(R.style.fontForNotificationLandingPage)

In styles.xml (Note: parent must be "Widget.AppCompat.TextView")

    <style name="fontForNotificationLandingPage" parent="Widget.AppCompat.TextView">
        <item name="android:fontFamily">@font/poppins_medium</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">@dimen/_18ssp</item>
    </style>

Note: if setTextAppearance and setButtonColors both are used than whichever function is last called will override other one.

  • To change bottomsheet's background (shape, color).
    fragment.setBottomSheetBackgroundStyle(R.drawable.drawable_bottom_sheet_dialog)

You need to make one drawable file of type shape.

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners
            android:topLeftRadius="@dimen/_25sdp"
            android:topRightRadius="@dimen/_25sdp" />
        <padding android:top="@dimen/_5sdp" />
        <solid android:color="@color/colorPrimary" />
    </shape>

Other Library used:

Find this library useful? ❤️

Support it by joining stargazers for this repository. ⭐

🤝 How to Contribute

Whether you're helping us fix bugs, improve the docs, or a feature request, we'd love to have you! 💪

Check out our Contributing Guide for ideas on contributing.

Bugs and Feedback

For bugs, feature requests, and discussion please use GitHub Issues.

License

Copyright 2021 Simform Solutions

 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.

ssimagepicker's People

Contributors

abhishek-1-simform avatar birjuvachhani avatar mobile-simformsolutions avatar payalrajput-simform avatar shwetachauhan-simform avatar shwetachauhan18 avatar

Stargazers

 avatar

Watchers

 avatar

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.