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

Commit

Permalink
* update demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
alhazmy13 committed Apr 17, 2018
1 parent f10daf1 commit cf02aa8
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 118 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ android {
dependencies {
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.android.support:design:27.1.1"
implementation "com.android.support:support-v13:27.1.1"
implementation project(':libary')
implementation project(':rxjava')
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.alhazmy13.mediapickerexample" >
<uses-permission android:name="android.permission.CAMERA"/>
package="net.alhazmy13.mediapickerexample">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name="net.alhazmy13.mediapickerexample.MainActivity" >
android:theme="@style/AppTheme">
<activity
android:name="net.alhazmy13.mediapickerexample.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.alhazmy13.mediapickerexample;

import android.app.Fragment;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -11,13 +12,12 @@
import android.widget.TextView;

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

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import static android.app.Activity.RESULT_OK;


/**
Expand All @@ -38,8 +38,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
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);
imageView = view.findViewById(R.id.iv_image);
path = view.findViewById(R.id.tv_path);
view.findViewById(R.id.bt_pick).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -51,50 +51,36 @@ public void onClick(View v) {


private void pickImage() {
Observable<List<String>> x = new ImagePickerHelper(
new ImagePicker.Builder(getActivity())
.mode(ImagePicker.Mode.CAMERA_AND_GALLERY)
.allowMultipleImages(true)
.compressLevel(ImagePicker.ComperesLevel.MEDIUM)
.directory(ImagePicker.Directory.DEFAULT)
.extension(ImagePicker.Extension.PNG)
.allowOnlineImages(false)
.scale(600, 600)
.allowMultipleImages(true)
.enableDebuggingMode(true))
.getObservable();

x.subscribe(new Observer<List<String>>() {
@Override
public void onSubscribe(Disposable d) {

}

@Override
public void onNext(List<String> imagePath) {
Log.d(TAG, "onNext() called with: " + "imagePath = [" + imagePath + "]");
mPath = imagePath;
loadImage();
}

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

@Override
public void onComplete() {

}
});
new ImagePicker.Builder(getActivity())
.mode(ImagePicker.Mode.CAMERA_AND_GALLERY)
.allowMultipleImages(true)
.compressLevel(ImagePicker.ComperesLevel.MEDIUM)
.directory(ImagePicker.Directory.DEFAULT)
.extension(ImagePicker.Extension.PNG)
.allowOnlineImages(false)
.scale(600, 600)
.allowMultipleImages(true)
.enableDebuggingMode(true)
.build();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]");
if (requestCode == ImagePicker.IMAGE_PICKER_REQUEST_CODE && resultCode == RESULT_OK) {
mPath = data.getStringArrayListExtra(ImagePicker.EXTRA_IMAGE_PATH);
Log.d(TAG, "onActivityResult: ");
loadImage();
}
}

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

}
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
package net.alhazmy13.mediapickerexample;

import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.VisibleForTesting;
import android.support.design.widget.TabLayout;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {
private Fragment videoFragment;
private Fragment imageFragment;
private Fragment videoFragment = new VideoFragment();
private Fragment imageFragment = new ImageFragment();
private ViewPager mPager;
private PagerAdapter mPagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

PickerAdapter adapter = new PickerAdapter(getFragmentManager());
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(adapter);

setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
for (int i = 0; i < adapter.getCount(); i++)
tabLayout.getTabAt(i).setText(adapter.getTitle(i));
mPager = findViewById(R.id.pager);
mPagerAdapter = new PickerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mPager);
for (int i = 0; i < mPagerAdapter.getCount(); i++)
tabLayout.getTabAt(i).setText(mPagerAdapter.getPageTitle(i));
}

private class PickerAdapter extends FragmentPagerAdapter {
private class PickerAdapter extends FragmentStatePagerAdapter {
private static final int NUM_PAGES = 2;


PickerAdapter(FragmentManager fm) {
super(fm);
videoFragment = new VideoFragment();
imageFragment = new ImageFragment();
}

@Override
Expand All @@ -58,12 +56,12 @@ public Fragment getItem(int position) {
}

@VisibleForTesting
int getTitle(int position) {
public String getPageTitle(int position) {
switch (position) {
case 0:
return R.string.tab_title_video;
return getString(R.string.tab_title_video);
default:
return R.string.tab_title_image;
return getString(R.string.tab_title_image);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.alhazmy13.mediapickerexample;

import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class VideoFragment extends Fragment {


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.video_layout, container, false);
init(view);
Expand All @@ -41,12 +42,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

private void init(View view) {
// Find our View instances
videoView = (VideoView) view.findViewById(R.id.iv_video);
videoView = view.findViewById(R.id.iv_video);
MediaController mediaController = new MediaController(getActivity());
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.start();
path = (TextView) view.findViewById(R.id.tv_path);
path = view.findViewById(R.id.tv_path);
view.findViewById(R.id.bt_pick).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -71,14 +71,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]");
if (requestCode == VideoPicker.VIDEO_PICKER_REQUEST_CODE && resultCode == RESULT_OK) {
mPath = (List<String>) data.getSerializableExtra(VideoPicker.EXTRA_VIDEO_PATH);
Log.d(TAG, "onActivityResult: ");
mPath = data.getStringArrayListExtra(VideoPicker.EXTRA_VIDEO_PATH);
loadVideo();
}
}

private void loadVideo() {
Log.d(TAG, "loadVideo: "+ (mPath == null));
if (mPath != null && mPath.size() > 0) {
path.setText(mPath.get(0));
videoView.setVideoURI(Uri.parse(mPath.get(0)));
Expand Down
32 changes: 10 additions & 22 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"/>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_height="wrap_content"
android:layout_width="match_parent" />

</android.support.design.widget.AppBarLayout>
android:layout_height="wrap_content"
android:background="@color/colorPrimary" />

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
8 changes: 5 additions & 3 deletions app/src/main/res/layout/image_layout.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand All @@ -13,16 +13,18 @@
<ImageView
android:id="@+id/iv_image"
android:layout_width="match_parent"
android:layout_height="400dp"/>
android:layout_height="400dp" />

<Button
android:id="@+id/bt_pick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pick" />

<TextView
android:id="@+id/tv_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PATH: ..." />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</ScrollView>
8 changes: 5 additions & 3 deletions app/src/main/res/layout/video_layout.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand All @@ -13,16 +13,18 @@
<VideoView
android:id="@+id/iv_video"
android:layout_width="match_parent"
android:layout_height="400dp"/>
android:layout_height="400dp" />

<Button
android:id="@+id/bt_pick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pick" />

<TextView
android:id="@+id/tv_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PATH: ..." />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</ScrollView>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down
Loading

0 comments on commit cf02aa8

Please sign in to comment.