Skip to content

Commit

Permalink
Sample supports media file path
Browse files Browse the repository at this point in the history
  • Loading branch information
gejiaheng committed May 24, 2017
1 parent bb6e9dc commit 426c0c4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
29 changes: 18 additions & 11 deletions sample/src/main/java/com/zhihu/matisse/sample/SampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void onNext(Boolean aBoolean) {
.choose(MimeType.ofAll(), false)
.countable(true)
.capture(true)
.captureStrategy(new CaptureStrategy(true, "com.zhihu.matisse.sample.fileprovider"))
.captureStrategy(new CaptureStrategy(true, "com.zhihu.matisse.sample" +
".fileprovider"))
.maxSelectable(9)
.addFilter(new GifSizeFilter(320, 320, 5 * Filter.K * Filter.K))
.gridExpectedSize(
Expand All @@ -99,7 +100,7 @@ public void onNext(Boolean aBoolean) {
.forResult(REQUEST_CODE_CHOOSE);
break;
}
mAdapter.setData(null);
mAdapter.setData(null, null);
} else {
Toast.makeText(SampleActivity.this, R.string.permission_request_denied, Toast.LENGTH_LONG)
.show();
Expand All @@ -122,30 +123,34 @@ public void onComplete() {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
mAdapter.setData(Matisse.obtainResult(data));
Toast.makeText(this, Matisse.obtainPathResult(data).get(0), Toast.LENGTH_SHORT).show();
mAdapter.setData(Matisse.obtainResult(data), Matisse.obtainPathResult(data));
}
}

private static class UriAdapter extends RecyclerView.Adapter<UriAdapter.UriViewHolder> {

private List<Uri> mUris;
private List<String> mPaths;

void setData(List<Uri> uris) {
void setData(List<Uri> uris, List<String> paths) {
mUris = uris;
mPaths = paths;
notifyDataSetChanged();
}

@Override
public UriViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new UriViewHolder(
(TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.uri_item, parent, false));
LayoutInflater.from(parent.getContext()).inflate(R.layout.uri_item, parent, false));
}

@Override
public void onBindViewHolder(UriViewHolder holder, int position) {
Uri uri = mUris.get(position);
holder.mUri.setText(uri.toString());
holder.mUri.setText(mUris.get(position).toString());
holder.mPath.setText(mPaths.get(position));

holder.mUri.setAlpha(position % 2 == 0 ? 1.0f : 0.54f);
holder.mPath.setAlpha(position % 2 == 0 ? 1.0f : 0.54f);
}

@Override
Expand All @@ -156,10 +161,12 @@ public int getItemCount() {
static class UriViewHolder extends RecyclerView.ViewHolder {

private TextView mUri;
private TextView mPath;

UriViewHolder(TextView uri) {
super(uri);
mUri = uri;
UriViewHolder(View contentView) {
super(contentView);
mUri = (TextView) contentView.findViewById(R.id.uri);
mPath = (TextView) contentView.findViewById(R.id.path);
}
}
}
Expand Down
52 changes: 37 additions & 15 deletions sample/src/main/res/layout/uri_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2017 Zhihu Inc.
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,16 +13,39 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingBottom="4dp"
android:paddingLeft="24dp"
android:paddingTop="4dp"
android:text="@+id/uri"
android:textColor="@android:color/white"
android:textSize="16sp"
tools:text="https://www.zhihu.com"
tools:textColor="@android:color/black"/>
<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="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/uri"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp"
android:text="@+id/uri"
android:textColor="@android:color/white"
android:textSize="16sp"
tools:text="content://media/external/images/media/12345"
tools:textColor="@android:color/black" />

<TextView
android:id="@+id/path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingBottom="4dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp"
android:text="@+id/uri"
android:textColor="@android:color/white"
android:textSize="16sp"
tools:text="/storage/emulated/0/Pictures/JPEG_20170516_12345.jpg"
tools:textColor="@android:color/black" />
</LinearLayout>

0 comments on commit 426c0c4

Please sign in to comment.