Skip to content

Commit

Permalink
Merge pull request #15 from andremion/development
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
andremion authored Jul 3, 2017
2 parents b4ba712 + 7e4511c commit 4a18075
Show file tree
Hide file tree
Showing 38 changed files with 380 additions and 165 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Then, add the library in your app module `build.gradle`

```groovy
dependencies{
compile 'com.github.andremion:louvre:1.0.1'
compile 'com.github.andremion:louvre:1.2.0'
}
```

Expand Down Expand Up @@ -96,13 +96,28 @@ Louvre.init(myActivity)
.open();
```

You can also use a `Fragment` to open the **Louvre**. In this case, the `Fragment` will get the `onActivityResult` callback.

```java
Louvre.init(myFragment)
.setRequestCode(LOUVRE_REQUEST_CODE)
.open();
```

But you can customize the picker:

######Setting the max images allowed to pick
```java
louvre.setMaxSelection(10)
```

######Setting the current selected items
```java
List<Uri> selection;
...
louvre.setSelection(selection)
```

######Setting the media type to filter the query with a combination of one of these types: `Louvre.IMAGE_TYPE_BMP`, `Louvre.IMAGE_TYPE_JPEG`, `Louvre.IMAGE_TYPE_PNG`
```java
louvre.setMediaTypeFilter(Louvre.IMAGE_TYPE_JPEG, Louvre.IMAGE_TYPE_PNG)
Expand All @@ -116,8 +131,8 @@ See more at the [sample](https://github.com/andremion/Louvre/tree/master/sample)
The Design package provides APIs to support adding material design components and patterns to your apps.
* [CounterFab](https://github.com/andremion/CounterFab)
A FloatingActionButton subclass that shows a counter badge on right top corner.
* [Picasso](https://github.com/square/picasso)
A powerful image downloading and caching library for Android
* [Glide](https://github.com/bumptech/glide)
An image loading and caching library for Android focused on smooth scrolling
* [PhotoView](https://github.com/chrisbanes/PhotoView)
Implementation of ImageView for Android that supports zooming, by various touch gestures.

Expand Down
Binary file added art/sample_optimized.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 11 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}
Expand All @@ -18,21 +18,22 @@ allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
project.ext {

compileSdkVersion = 25
buildToolsVersion = '25.0.2'
minSdkVersion = 19
targetSdkVersion = 25
compileSdkVersion = 26
buildToolsVersion = '26.0.0'
minSdkVersion = 16
targetSdkVersion = 26

versionCode = 2
versionName = "1.0.1"
versionCode = 7
versionName = "1.2.0"

supportLibraryVersion = '25.1.0'
supportLibraryVersion = '25.4.0'
counterFabVersion = '1.0.1'
picassoVersion = '2.5.2'
photoViewVersion = '1.3.1'
glideVersion = '3.8.0'
photoViewVersion = '2.0.0'

junitVersion = '4.12'
espressoVersion = '2.2.+'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Tue May 23 10:17:32 WEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Empty file modified gradlew
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion louvre/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
compile "com.github.andremion:counterfab:$counterFabVersion"
compile "com.squareup.picasso:picasso:$picassoVersion"
compile "com.github.bumptech.glide:glide:$glideVersion"
compile "com.github.chrisbanes:PhotoView:$photoViewVersion"

testCompile "junit:junit:$junitVersion"
Expand Down
30 changes: 28 additions & 2 deletions louvre/src/main/java/com/andremion/louvre/Louvre.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.StringDef;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatDelegate;

import com.andremion.louvre.home.GalleryActivity;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
* A small customizable image picker. Useful to handle an image pick action built-in
Expand All @@ -47,20 +50,31 @@ public class Louvre {
@interface MediaType {
}

private final Activity mActivity;
private Activity mActivity;
private Fragment mFragment;
private int mRequestCode;
private int mMaxSelection;
private List<Uri> mSelection;
private String[] mMediaTypeFilter;

private Louvre(@NonNull Activity activity) {
mActivity = activity;
mRequestCode = -1;
}

private Louvre(@NonNull Fragment fragment) {
mFragment = fragment;
mRequestCode = -1;
}

public static Louvre init(@NonNull Activity activity) {
return new Louvre(activity);
}

public static Louvre init(@NonNull Fragment fragment) {
return new Louvre(fragment);
}

/**
* Set the request code to return on {@link Activity#onActivityResult(int, int, Intent)}
*/
Expand All @@ -77,6 +91,14 @@ public Louvre setMaxSelection(@IntRange(from = 0) int maxSelection) {
return this;
}

/**
* Set the current selected items
*/
public Louvre setSelection(@NonNull List<Uri> selection) {
mSelection = selection;
return this;
}

/**
* Set the media type to filter the query with a combination of one of these types: {@link #IMAGE_TYPE_BMP}, {@link #IMAGE_TYPE_JPEG}, {@link #IMAGE_TYPE_PNG}
*/
Expand All @@ -89,7 +111,11 @@ public void open() {
if (mRequestCode == -1) {
throw new IllegalArgumentException("You need to define a request code in setRequestCode(int) method");
}
GalleryActivity.startActivity(mActivity, mRequestCode, mMaxSelection, mMediaTypeFilter);
if (mActivity != null) {
GalleryActivity.startActivity(mActivity, mRequestCode, mMaxSelection, mSelection, mMediaTypeFilter);
} else {
GalleryActivity.startActivity(mFragment, mRequestCode, mMaxSelection, mSelection, mMediaTypeFilter);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public abstract class StoragePermissionActivity extends AppCompatActivity {

private static final int REQUEST_READ_EXTERNAL_STORAGE = 0;
private static final int REQUEST_READ_EXTERNAL_STORAGE = 4321;
private static final int REQUEST_APP_SETTINGS = 1234;

public void askForPermission() {
Expand Down Expand Up @@ -102,18 +102,26 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
* </p>
*/
private void showExplanation() {
Snackbar.make(getWindow().getDecorView(), getString(R.string.activity_gallery_permission_request_explanation), Snackbar.LENGTH_INDEFINITE)
Snackbar.make(findSuitableView(), getString(R.string.activity_gallery_permission_request_explanation), Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.activity_gallery_permission_request_settings, new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", getPackageName(), null));
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intent, REQUEST_APP_SETTINGS);
}
})
.show();
}

private View findSuitableView() {
View view = findViewById(R.id.coordinator_layout);
if (view == null) {
view = getWindow().getDecorView();
}
return view;
}

}
Loading

0 comments on commit 4a18075

Please sign in to comment.