Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added selecting images and video at the same time #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ You can customize something ...<br />
#### Common

* `showVideoMedia()` : Not only load image, but also load video
* `showImageAndVideoMedia()` : Load both images and video
* `setPreviewMaxCount(Int) (default: 25)`
* `setPeekHeight(Int)`
* `setPeekHeightResId(R.dimen.xxx)`
Expand Down
117 changes: 62 additions & 55 deletions app/src/main/java/gun0912/tedbottompickerdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
Expand All @@ -28,80 +28,109 @@
import io.reactivex.disposables.Disposable;

public class MainActivity extends AppCompatActivity {

private ImageView iv_image;
private List<Uri> selectedUriList;
private Uri selectedUri;
private Disposable singleImageDisposable;
private Disposable multiImageDisposable;
private ViewGroup mSelectedImagesContainer;
private RequestManager requestManager;

private ImageView ivImage;
private TextView tvFilePath;
private ViewGroup selectedImagesContainer;

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

iv_image = findViewById(R.id.iv_image);
mSelectedImagesContainer = findViewById(R.id.selected_photos_container);
tvFilePath = findViewById(R.id.tv_path);
ivImage = findViewById(R.id.iv_image);
selectedImagesContainer = findViewById(R.id.selected_photos_container);
requestManager = Glide.with(this);
setImageAndVideoPickerButton();
setSingleShowButton();
setMultiShowButton();
setRxSingleShowButton();
setRxMultiShowButton();

}

private void setSingleShowButton() {

Button btnSingleShow = findViewById(R.id.btn_single_show);
btnSingleShow.setOnClickListener(view -> {
PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {

TedBottomPicker.with(MainActivity.this)
//.setPeekHeight(getResources().getDisplayMetrics().heightPixels/2)
.setSelectedUri(selectedUri)
//.showVideoMedia()
.setPeekHeight(1200)
.show(uri -> {
Log.d("ted", "uri: " + uri);
Log.d("ted", "uri.getPath(): " + uri.getPath());
selectedUri = uri;

iv_image.setVisibility(View.VISIBLE);
mSelectedImagesContainer.setVisibility(View.GONE);
tvFilePath.setText(selectedUri.toString());
ivImage.setVisibility(View.VISIBLE);
selectedImagesContainer.setVisibility(View.GONE);

requestManager
.load(uri)
.into(iv_image);
.into(ivImage);
});


}

@Override
public void onPermissionDenied(ArrayList<String> deniedPermissions) {
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
showNoPermissionToast(deniedPermissions);
}
};

checkPermission(permissionlistener);
});
}

private void setImageAndVideoPickerButton() {
Button btnSingleShow = findViewById(R.id.btn_single_image_video);
btnSingleShow.setOnClickListener(view -> {
PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {
TedBottomPicker.with(MainActivity.this)
.setSelectedUri(selectedUri)
.showImageAndVideoMedia()
.setPeekHeight(1200)
.show(uri -> {
selectedUri = uri;

tvFilePath.setText(selectedUri.toString());
ivImage.setVisibility(View.VISIBLE);
selectedImagesContainer.setVisibility(View.GONE);

requestManager
.load(uri)
.into(ivImage);
});
}

@Override
public void onPermissionDenied(ArrayList<String> deniedPermissions) {
showNoPermissionToast(deniedPermissions);
}
};

checkPermission(permissionlistener);
});
}

private void setMultiShowButton() {
private void showNoPermissionToast(ArrayList<String> deniedPermissions) {
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
}

private void setMultiShowButton() {
Button btnMultiShow = findViewById(R.id.btn_multi_show);
btnMultiShow.setOnClickListener(view -> {

PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {

TedBottomPicker.with(MainActivity.this)
//.setPeekHeight(getResources().getDisplayMetrics().heightPixels/2)
.setPeekHeight(1600)
Expand All @@ -113,74 +142,60 @@ public void onPermissionGranted() {
selectedUriList = uriList;
showUriList(uriList);
});


}

@Override
public void onPermissionDenied(ArrayList<String> deniedPermissions) {
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
showNoPermissionToast(deniedPermissions);
}


};

checkPermission(permissionlistener);

});

}


private void setRxSingleShowButton() {

Button btnSingleShow = findViewById(R.id.btn_rx_single_show);
btnSingleShow.setOnClickListener(view -> {
PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {

singleImageDisposable = TedRxBottomPicker.with(MainActivity.this)
//.setPeekHeight(getResources().getDisplayMetrics().heightPixels/2)
.setSelectedUri(selectedUri)
//.showVideoMedia()
.showVideoMedia()
.setPeekHeight(1200)
.show()
.subscribe(uri -> {
selectedUri = uri;

iv_image.setVisibility(View.VISIBLE);
mSelectedImagesContainer.setVisibility(View.GONE);
tvFilePath.setText(selectedUri.toString());
ivImage.setVisibility(View.VISIBLE);
selectedImagesContainer.setVisibility(View.GONE);

requestManager
.load(uri)
.into(iv_image);
}, Throwable::printStackTrace);

.into(ivImage);

}, Throwable::printStackTrace);
}

@Override
public void onPermissionDenied(ArrayList<String> deniedPermissions) {
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
showNoPermissionToast(deniedPermissions);
}


};

checkPermission(permissionlistener);
});
}


private void setRxMultiShowButton() {

Button btnRxMultiShow = findViewById(R.id.btn_rx_multi_show);
btnRxMultiShow.setOnClickListener(view -> {
PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {

multiImageDisposable = TedRxBottomPicker.with(MainActivity.this)
//.setPeekHeight(getResources().getDisplayMetrics().heightPixels/2)
.setPeekHeight(1600)
Expand All @@ -193,21 +208,16 @@ public void onPermissionGranted() {
selectedUriList = uris;
showUriList(uris);
}, Throwable::printStackTrace);


}

@Override
public void onPermissionDenied(ArrayList<String> deniedPermissions) {
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
showNoPermissionToast(deniedPermissions);
}


};

checkPermission(permissionlistener);
});

}

private void checkPermission(PermissionListener permissionlistener) {
Expand All @@ -221,17 +231,16 @@ private void checkPermission(PermissionListener permissionlistener) {
private void showUriList(List<Uri> uriList) {
// Remove all views before
// adding the new ones.
mSelectedImagesContainer.removeAllViews();
selectedImagesContainer.removeAllViews();

iv_image.setVisibility(View.GONE);
mSelectedImagesContainer.setVisibility(View.VISIBLE);
ivImage.setVisibility(View.GONE);
selectedImagesContainer.setVisibility(View.VISIBLE);

int widthPixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
int heightPixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());


for (Uri uri : uriList) {

View imageHolder = LayoutInflater.from(this).inflate(R.layout.image_item, null);
ImageView thumbnail = imageHolder.findViewById(R.id.media_image);

Expand All @@ -240,12 +249,10 @@ private void showUriList(List<Uri> uriList) {
.apply(new RequestOptions().fitCenter())
.into(thumbnail);

mSelectedImagesContainer.addView(imageHolder);
selectedImagesContainer.addView(imageHolder);

thumbnail.setLayoutParams(new FrameLayout.LayoutParams(widthPixel, heightPixel));

}

}

@Override
Expand Down
55 changes: 30 additions & 25 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,72 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="gun0912.tedbottompickerdemo.MainActivity">

<Button
android:id="@+id/btn_single_show"
android:layout_width="wrap_content"
android:id="@+id/btn_single_image_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Ted Bottom Picker(Single)" />
android:text="Show image/video picker" />

<Button
android:id="@+id/btn_single_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show image picker (Single)" />

<Button
android:id="@+id/btn_multi_show"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Ted Bottom Picker(Multi)" />


android:text="Show image picker (Multi)" />

<Button
android:id="@+id/btn_rx_single_show"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Show Ted Rx Bottom Picker(Single)" />


<Button
android:id="@+id/btn_rx_multi_show"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Ted Rx Bottom Picker(Multi)" />

<TextView
android:id="@+id/tv_path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp" />

<ImageView
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn_single_show"
android:layout_centerInParent="true"
android:layout_marginTop="@dimen/activity_vertical_margin" />


<HorizontalScrollView
android:id="@+id/hori_scroll_view"
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:fillViewport="false"
android:foregroundGravity="left"
>

android:foregroundGravity="left">

<LinearLayout
android:id="@+id/selected_photos_container"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_gravity="start"
android:animateLayoutChanges="true"
android:gravity="left"
android:gravity="start"
android:orientation="horizontal"
android:visibility="visible">


<!-- images will be added dynamicall to this layout -->
</LinearLayout>
</HorizontalScrollView>
Expand Down
Loading