Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

ChoosePhotoHelper develops a component which facilitates the source code of picking photos in your Android apps.

License

NotificationsYou must be signed in to change notification settings

aminography/ChoosePhotoHelper

Repository files navigation

Android ArsenalDownloadCodacy Badge

Picking an image as an avatar in Android apps needs to write a bunch of error-prone boilerplate codes.ChoosePhotoHelper develops a component which facilitates picking photos from gallery or taking an image with the camera without any boilerplate codes.It also internally handles some issues likerotation correction of the taken photos,permission request for camera and gallery (if needed),URI exposure problem, etc.

Take a PhotoChoose from Gallery

Download

ChoosePhotoHelper is available onbintray to download using build tools systems. Add the following lines to yourbuild.gradle file:

repositories {    jcenter()}dependencies {    implementation'com.aminography:choosephotohelper:1.3.1'}

Usage

First of all,ChoosePhotoHelper provides 3 types of result to access the chosen photo which are:

Builder MethodResult Type
asFilePath()String
asUri()Uri
asBitmap()Bitmap

Now, use it simply in 3 steps:

• First

Create an instance ofChoosePhotoHelper using its builder pattern specifying the result type:

choosePhotoHelper =ChoosePhotoHelper.with(activity)        .asFilePath()        .build(newChoosePhotoCallback<String>() {@OverridepublicvoidonChoose(Stringphoto) {Glide.with(imageView)                        .load(photo)                        .into(imageView);            }        });

• Second

OverrideonActivityResult andonRequestPermissionsResult in yourActivity /Fragment class, then forward their result to thechoosePhotoHelper instance:

@OverridepublicvoidonActivityResult(intrequestCode,intresultCode,@NullableIntentdata) {super.onActivityResult(requestCode,resultCode,data);choosePhotoHelper.onActivityResult(requestCode,resultCode,data);}@OverridepublicvoidonRequestPermissionsResult(intrequestCode,@NonNullString[]permissions,@NonNullint[]grantResults) {super.onRequestPermissionsResult(requestCode,permissions,grantResults);choosePhotoHelper.onRequestPermissionsResult(requestCode,permissions,grantResults);}

• Finally

CallshowChooser() method on thechoosePhotoHelper instance:

choosePhotoHelper.showChooser();

Here is a detailed example which is written inkotlin:

classMainActivity :AppCompatActivity() {privatelateinitvar choosePhotoHelper:ChoosePhotoHelperoverridefunonCreate(savedInstanceState:Bundle?) {super.onCreate(savedInstanceState)        setContentView(R.layout.activity_main)        choosePhotoHelper=ChoosePhotoHelper.with(this)            .asFilePath()            .withState(savedInstanceState)            .build {Glide.with(this)                    .load(it)                    .into(imageView)            }        button.setOnClickListener {            choosePhotoHelper.showChooser()        }    }overridefunonActivityResult(requestCode:Int,resultCode:Int,data:Intent?) {super.onActivityResult(requestCode, resultCode, data)        choosePhotoHelper.onActivityResult(requestCode, resultCode, data)    }overridefunonRequestPermissionsResult(requestCode:Int,permissions:Array<String>,grantResults:IntArray) {super.onRequestPermissionsResult(requestCode, permissions, grantResults)        choosePhotoHelper.onRequestPermissionsResult(requestCode, permissions, grantResults)    }overridefunonSaveInstanceState(outState:Bundle) {super.onSaveInstanceState(outState)        choosePhotoHelper.onSaveInstanceState(outState)    }}

Change Log

Version 1.3.0

  • Migrating to Kotlin 1.4.0.

Version 1.2.1

  • Some minor improvements.
  • Adding ability to always show remove photo option.

Version 1.2.0

  • File path problem targeting api 29 is fixed.

Version 1.1.0

  • Migrating to AndroidX.
  • AddingonSaveInstanceState to save and restore state.

License

Copyright 2019 Mohammad Amin Hassani.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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.

About

ChoosePhotoHelper develops a component which facilitates the source code of picking photos in your Android apps.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp