An MIT-Licensed Android library that provides a picker UI for choosing photos from Unsplash's photo collection. It uses the Unsplash API to show a list of photos and allows the user to choose one.
To add Picker for Unsplash Photos to your project in Android Studio,
simply add this line to the dependencies
block of the build.gradle
file in your app's module:
compile 'com.github.drmercer:unsplash:0.0.1'
You'll also need to add your Unsplash API app ID to your app's
AndroidManifest.xml
, as well as the string you'd like to use for the
utm_source
parameter in your attribution links (see the Unsplash API
guidelines
for more info about that):
<application>
<!-- ... -->
<meta-data
android:name="net.danmercer.unsplashpicker.unsplash_app_id"
android:value="<YOUR APP ID HERE>"/>
<meta-data
android:name="net.danmercer.unsplashpicker.unsplash_utm_source"
android:value="<YOUR UTM SOURCE NAME HERE>"/>
</application>
You can launch the image picker UI from your activity like so:
ImagePickHelper helper = new ImagePickHelper(this);
helper.launchPickerActivity();
And then in your Activity's onActivityResult()
method, do something
like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (pickHelper.handleActivityResult(requestCode, resultCode, data)) {
// Download the chosen image
pickHelper.download(new ImagePickHelper.OnBitmapDownloadedListener() {
@Override
public void onBitmapDownloaded(Bitmap bmp) {
// Do something with bitmap here
}
@Override
public void onBitmapDownloadError() {
// Handle error
}
});
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
To customize the look of the ImagePickActivity, add it to your app's
AndroidManifest.xml
with whatever attributes you want to override. For
example, to change the label and apply a special theme, do something
like this:
<activity
android:name="net.danmercer.unsplashpicker.ImagePickActivity"
android:theme="@style/YourTheme"
android:label="Your Label Text"
tools:replace="android:label,android:theme">
</activity>
To use a subclass of ImagePickActivity instead, replace the
android:name
attribute with the name of your subclass activity, and
then call
helper.setPickerActivityClass(YourSubclassActivity.class);
(where YourSubclassActivty
is your subclass) before calling
launchPickerActivity()
. Read the
ImagePickActivity source
to see what methods you can override in your subclass.
Check out the Trello board to see if I'm currently working on anything.
The library source code is licensed under the MIT License, except
as otherwise noted in certain files (i.e. the maven-push.gradle
file, which is not a part of the library
itself). The MIT License is a fairly permissive license, so it shouldn't be hard to integrate Picker for
Unsplash Photos into your Android project.