Skip to content
This repository has been archived by the owner on May 30, 2021. It is now read-only.

Commit

Permalink
- add VideoPickerHelper for Rx extension
Browse files Browse the repository at this point in the history
- refactor videoPicker and fix some issues
  • Loading branch information
alhazmy13 committed Mar 13, 2017
1 parent 2eeba40 commit 550ba56
Show file tree
Hide file tree
Showing 38 changed files with 1,130 additions and 652 deletions.
120 changes: 61 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Media Picker
![](https://img.shields.io/badge/Platform-Android-brightgreen.svg)
![](https://img.shields.io/hexpm/l/plug.svg)
![](https://img.shields.io/badge/version-2.2.5-blue.svg)
![](https://img.shields.io/badge/version-2.3.0-blue.svg)
[![ghit.me](https://ghit.me/badge.svg?repo=Alhazmy13/MediaPicker)](https://ghit.me/repo/Alhazmy13/MediaPicker)

**[Please let me know if your application go to production via this link](https://docs.google.com/forms/d/e/1FAIpQLSe4Y5Fwn1mlEoD4RxjXQzTvL4mofhESuBlTkAPQhI7J_WqMDQ/viewform?c=0&w=1)**
Expand All @@ -22,15 +22,15 @@ This build `2.x.x` will break backward compatibility and there are a lot of chan
<dependency>
<groupId>net.alhazmy13.MediaPicker</groupId>
<artifactId>libary</artifactId>
<version>2.2.5</version>
<version>2.3.0</version>
</dependency>
```


**Gradle**
```gradle
dependencies {
compile 'net.alhazmy13.MediaPicker:libary:2.2.5'
compile 'net.alhazmy13.MediaPicker:libary:2.3.0'
}
```

Expand All @@ -39,8 +39,8 @@ dependencies {
## Images
After adding the library, you need to:

1. Create an object from `ImagePicker`
2. Override `onActivityResult` to receive the path of image.
1. Create an object from `ImagePicker` or `VideoPicker`
2. Override `onActivityResult` to receive the path of image or videos.



Expand Down Expand Up @@ -119,85 +119,43 @@ In order to receive the path of image, you will need to override `onActivityResu
.enableDebuggingMode(true)
```

### RxJava for MediaPicker

It's an extenstion that allow you to return an observable from ImagePickerBuilder, all you need is to add below dependency and then return the observable from `ImagePickerHelper` class.


**Gradle**

```gradle
dependencies {
compile 'net.alhazmy13.MediaPicker:rxjava:(Last_version)'
}
```

```Java
new ImagePickerHelper(
new ImagePicker.Builder(Context)
...)
.getObservable()
.subscribe(new Subscriber<List<String>>() {
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted() called with: " + "");
}

@Override
public void onError(Throwable e) {
Log.d(TAG, "onError()");
}

@Override
public void onNext(List<String> imagePaths) {
Log.d(TAG, "onNext() ");
}
});
```

------

## Video
------

1. Create an object from `VideoPicker`
2. Override `onActivityResult` to receive the path of video.



### Create `VideoPicker`
### Create an `VideoPicker`
You will need to create a new instance of `VideoPicker`. Once the instance are configured, you can call `build()`.

```java
new VideoPicker.Builder(this)
.build();
new VideoPicker.Builder(MainActivity.this)
.mode(VideoPicker.Mode.CAMERA_AND_GALLERY)
.directory(VideoPicker.Directory.DEFAULT)
.extension(VideoPicker.Extension.MP4)
.enableDebuggingMode(true)
.build();
```
### Override `onActivityResult `
In order to receive the path of video, you will need to override `onActivityResult ` .
In order to receive the path of videos, you will need to override `onActivityResult ` .

```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == VideoPicker.VIDEO_PICKER_REQUEST_CODE && resultCode == RESULT_OK) {
String mPath = data.getStringExtra(VideoPicker.EXTRA_VIDEO_PATH);
List<String> mPaths = (List<String>) data.getSerializableExtra(ImagePicker.EXTRA_VIDEO_PATH);
//Your Code
}
}
```

### Additional Options
* `mode` to select the mode, you can chose one ot these `CAMERA`,`GALLERY` or `CAMERA_AND_GALLERY`
* `mode` to select the mode, you can choose one of these `CAMERA`,`GALLERY` or `CAMERA_AND_GALLERY`

```java
.mode(VideoPicker.Mode.CAMERA)
```

* `extension` You can change the extanion of image to `_MP4` , `_MKV` or `_3GP`
* `extension` You can change the extension of video to `MP4`

```java
.extension(VideoPicker.Extension._MP4)
.extension(VideoPicker.Extension.MP4)
```

* `directory` You can pass the storage path, or select `Directory.DEFAULT_DIR` to keep the default path.
Expand All @@ -211,6 +169,50 @@ In order to receive the path of video, you will need to override `onActivityResu

```

* `enableDebuggingMode` used to print Video Picker Log

```java
.enableDebuggingMode(true)
```

### RxJava for MediaPicker

It's an extenstion that allow you to return an observable from `ImagePickerBuilder` or `VideoPickerBuilder`, all you need is to add below dependency and then return the observable from `ImagePickerHelper` || `VideoPickerHelper` class.


**Gradle**

```gradle
dependencies {
compile 'net.alhazmy13.MediaPicker:rxjava:(Last_version)'
}
```

```Java
new ImagePickerHelper(
new ImagePicker.Builder(Context)
...)
.getObservable()
.subscribe(new Subscriber<List<String>>() {
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted() called with: " + "");
}

@Override
public void onError(Throwable e) {
Log.d(TAG, "onError()");
}

@Override
public void onNext(List<String> imagePaths) {
Log.d(TAG, "onNext() ");
}
});
```

------


## Theme the pickers

Expand Down
25 changes: 12 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
apply plugin: 'com.android.application'
apply from: '../deps.gradle'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion versions.TARGET_SDK_VERSION
buildToolsVersion versions.BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion versions.MIN_SDK_VERSION
targetSdkVersion versions.TARGET_SDK_VERSION
applicationId 'net.alhazmy13.mediapicker'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
}
debug{
shrinkResources true
}
}
productFlavors {
lintOptions {
abortOnError false
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile "com.android.support:appcompat-v7:25.2.0"
compile "com.android.support:design:25.2.0"
compile "com.android.support:support-v13:25.2.0"
compile project(':libary')
compile project(':rxjava')
}

This file was deleted.

109 changes: 109 additions & 0 deletions app/src/main/java/net/alhazmy13/mediapickerexample/ImageFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package net.alhazmy13.mediapickerexample;

import android.app.Fragment;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import net.alhazmy13.mediapicker.Image.ImagePicker;
import net.alhazmy13.mediapicker.rxjava.image.ImagePickerHelper;

import java.util.List;

import rx.Subscriber;

/**
* Created by alhazmy13 on 3/13/17.
*/

public class ImageFragment extends Fragment {
private ImageView imageView;
private TextView path;

private static final String TAG = "MainActivity";
private static final String IMAGE_PATH = "IMAGE_TAGS_IMAGE_PATH";
private String videoPath;
private List<String> mPath;


public ImageFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.image_layout, container, false);

// Find our View instances
imageView = (ImageView) view.findViewById(R.id.iv_image);
path = (TextView) view.findViewById(R.id.tv_path);
view.findViewById(R.id.bt_pick).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickImage();
}
});
return view;
}


private void pickImage() {
new ImagePickerHelper(
new ImagePicker.Builder(getActivity())
.mode(ImagePicker.Mode.CAMERA_AND_GALLERY)
.compressLevel(ImagePicker.ComperesLevel.MEDIUM)
.directory(ImagePicker.Directory.DEFAULT)
.extension(ImagePicker.Extension.PNG)
.scale(600, 600)
.allowMultipleImages(true)
.enableDebuggingMode(true))
.getObservable()
.subscribe(new Subscriber<List<String>>() {
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted() called with: " + "");
}

@Override
public void onError(Throwable e) {
Log.d(TAG, "onError() called with: " + "e = [" + e + "]");
e.printStackTrace();
}

@Override
public void onNext(List<String> imagePath) {
Log.d(TAG, "onNext() called with: " + "imagePath = [" + imagePath + "]");
mPath = imagePath;
loadImage();
}
});
}
//
// @Override
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
//
// if (requestCode == VideoPicker.VIDEO_PICKER_REQUEST_CODE && resultCode == RESULT_OK) {
// videoPath = data.getStringExtra(VideoPicker.EXTRA_VIDEO_PATH);
// loadImage();
// }
// else if(requestCode == ImagePicker.IMAGE_PICKER_REQUEST_CODE && resultCode == RESULT_OK) {
// mPath = (List<String>) data.getSerializableExtra(ImagePicker.EXTRA_IMAGE_PATH);
// loadImage();
// }
// }

private void loadImage() {
Log.d(TAG, "loadImage: " + mPath.size());
path.setText(mPath.get(0));
imageView.setImageBitmap(BitmapFactory.decodeFile(mPath.get(0)));
}

}
Loading

0 comments on commit 550ba56

Please sign in to comment.