Skip to content

Commit a1af761

Browse files
committed
add show view
1 parent ce42d74 commit a1af761

File tree

15 files changed

+470
-113
lines changed

15 files changed

+470
-113
lines changed

PhotoPicker-release.aar

880 Bytes
Binary file not shown.

PhotoPicker/src/main/java/me/iwf/photopicker/PhotoPagerActivity.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
import java.util.List;
2020

2121
import me.iwf.photopicker.fragment.ImagePagerFragment;
22+
import me.iwf.photopicker.widget.MultiPickResultView;
2223
import me.iwf.photopicker.widget.Titlebar;
2324

2425
import static me.iwf.photopicker.PhotoPicker.KEY_SELECTED_PHOTOS;
2526
import static me.iwf.photopicker.PhotoPreview.EXTRA_CURRENT_ITEM;
2627
import static me.iwf.photopicker.PhotoPreview.EXTRA_PHOTOS;
2728
import static me.iwf.photopicker.PhotoPreview.EXTRA_SHOW_DELETE;
29+
import static me.iwf.photopicker.PhotoPreview.EXTRA_ACTION;
2830

2931
/**
3032
* Created by donglua on 15/6/24.
@@ -45,6 +47,7 @@ public class PhotoPagerActivity extends AppCompatActivity {
4547
int currentItem = getIntent().getIntExtra(EXTRA_CURRENT_ITEM, 0);
4648
List<String> paths = getIntent().getStringArrayListExtra(EXTRA_PHOTOS);
4749
showDelete = getIntent().getBooleanExtra(EXTRA_SHOW_DELETE, true);
50+
int action = getIntent().getIntExtra(EXTRA_ACTION, MultiPickResultView.ACTION_ONLY_SHOW);
4851

4952
if (pagerFragment == null) {
5053
pagerFragment =
@@ -53,6 +56,18 @@ public class PhotoPagerActivity extends AppCompatActivity {
5356
pagerFragment.setPhotos(paths, currentItem);
5457
titlebar = (Titlebar) findViewById(R.id.titlebar);
5558
titlebar.init(this);
59+
if (action == MultiPickResultView.ACTION_SELECT){
60+
titlebar.setRitht(getApplicationContext().getResources().getDrawable(R.drawable.__picker_delete), "", new View.OnClickListener() {
61+
@Override
62+
public void onClick(View v) {
63+
int position = pagerFragment.getViewPager().getCurrentItem();
64+
pagerFragment.getPaths().remove(position);
65+
pagerFragment.getViewPager().getAdapter().notifyDataSetChanged();
66+
67+
}
68+
});
69+
}
70+
5671
titlebar.setTitle(getString(R.string.__picker_preview));
5772

5873

@@ -75,7 +90,7 @@ public class PhotoPagerActivity extends AppCompatActivity {
7590
pagerFragment.getViewPager().addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
7691
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
7792

78-
titlebar.getTvRight().setText(getString(R.string.__picker_image_index, pagerFragment.getViewPager().getCurrentItem() + 1,
93+
titlebar.setTitle(getString(R.string.__picker_preview) +" "+getString(R.string.__picker_image_index, pagerFragment.getViewPager().getCurrentItem() + 1,
7994
pagerFragment.getPaths().size()));
8095
// updateActionBarTitle();
8196
}

PhotoPicker/src/main/java/me/iwf/photopicker/PhotoPickUtils.java

+23-12
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,56 @@ public static void onActivityResult(int requestCode, int resultCode, Intent data
1414

1515
if (resultCode == Activity.RESULT_OK) {
1616
if (requestCode == PhotoPicker.REQUEST_CODE) {//第一次,选择图片后返回
17-
1817
if (data != null) {
1918
ArrayList<String> photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
20-
if (photos != null){
19+
pickHandler.onPickSuccess(photos);
20+
/* if (photos != null){
2121
if (photos.size() >0){
22-
pickHandler.onSuccess(photos);
22+
2323
}else {
24-
pickHandler.onFail("未选择图片1");
24+
pickHandler.onPickFail("未选择图片1");
2525
}
2626
}else {
27-
pickHandler.onFail("未选择图片2");
28-
}
27+
pickHandler.onPickFail("未选择图片2");
28+
}*/
29+
} else {
30+
pickHandler.onPickFail("选择图片失败");
31+
}
32+
}else if (requestCode == PhotoPreview.REQUEST_CODE){//如果是预览与删除后返回
33+
if (data != null) {
34+
ArrayList<String> photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
35+
pickHandler.onPreviewBack(photos);
2936
} else {
30-
pickHandler.onFail("选择图片失败3");
37+
// pickHandler.onPickFail("选择图片失败");
3138
}
39+
3240
}
3341
}else {
42+
3443
if (requestCode == PhotoPicker.REQUEST_CODE){
35-
pickHandler.onCancle();
44+
pickHandler.onPickCancle();
3645
}
3746
}
3847

3948

4049
}
4150

42-
public static void startPick(Activity context){
51+
public static void startPick(Activity context,ArrayList<String> photos){
4352
PhotoPicker.builder()
4453
.setPhotoCount(9)
4554
.setShowCamera(true)
4655
.setShowGif(true)
56+
.setSelected(photos)
4757
.setPreviewEnabled(true)
4858
.start(context, PhotoPicker.REQUEST_CODE);
4959
}
5060

5161

5262

5363
public interface PickHandler{
54-
void onSuccess(ArrayList<String> photos);
55-
void onFail(String error);
56-
void onCancle();
64+
void onPickSuccess(ArrayList<String> photos);
65+
void onPreviewBack(ArrayList<String> photos);
66+
void onPickFail(String error);
67+
void onPickCancle();
5768
}
5869
}

PhotoPicker/src/main/java/me/iwf/photopicker/PhotoPreview.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class PhotoPreview {
1919
public final static String EXTRA_PHOTOS = "photos";
2020
public final static String EXTRA_SHOW_DELETE = "show_delete";
2121

22+
public final static String EXTRA_ACTION = "action";
23+
2224

2325
public static PhotoPreviewBuilder builder() {
2426
return new PhotoPreviewBuilder();
@@ -88,6 +90,11 @@ public PhotoPreviewBuilder setPhotos(ArrayList<String> photoPaths) {
8890
return this;
8991
}
9092

93+
public PhotoPreviewBuilder setAction(int action) {
94+
mPreviewOptionsBundle.putInt(EXTRA_ACTION, action);
95+
return this;
96+
}
97+
9198
public PhotoPreviewBuilder setCurrentItem(int currentItem) {
9299
mPreviewOptionsBundle.putInt(EXTRA_CURRENT_ITEM, currentItem);
93100
return this;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.iwf.photopicker.utils;
2+
3+
import android.media.ExifInterface;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* Created by Administrator on 2016/8/15 0015.
9+
*/
10+
public class ExifUtils {
11+
12+
public static void clearSensitiveInfo(String filePath){
13+
ExifInterface exifInterface = null;
14+
try {
15+
exifInterface = new ExifInterface(filePath);
16+
exifInterface.setAttribute(ExifInterface.TAG_DATETIME ,"0");
17+
exifInterface.setAttribute(ExifInterface.TAG_MAKE ,"0");
18+
exifInterface.setAttribute(ExifInterface.TAG_MODEL ,"0");
19+
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE ,"0");
20+
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE ,"0");
21+
exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF ,"0");
22+
exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF ,"0");
23+
exifInterface.setAttribute(ExifInterface.TAG_APERTURE ,"0");
24+
exifInterface.setAttribute(ExifInterface.TAG_ISO ,"0");
25+
exifInterface.setAttribute(ExifInterface.TAG_SUBSEC_TIME ,"0");
26+
exifInterface.setAttribute(ExifInterface.TAG_SUBSEC_TIME_ORIG ,"0");
27+
exifInterface.setAttribute(ExifInterface.TAG_SUBSEC_TIME_DIG ,"0");
28+
exifInterface.setAttribute(ExifInterface.TAG_GPS_ALTITUDE ,"0");
29+
exifInterface.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF ,"0");
30+
exifInterface.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP ,"0");
31+
exifInterface.setAttribute(ExifInterface.TAG_GPS_DATESTAMP ,"0");
32+
exifInterface.setAttribute(ExifInterface.TAG_WHITE_BALANCE ,"0");
33+
exifInterface.setAttribute(ExifInterface.TAG_FOCAL_LENGTH ,"0");
34+
exifInterface.setAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD ,"0");
35+
exifInterface.saveAttributes();
36+
} catch (IOException e) {
37+
e.printStackTrace();
38+
}
39+
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package me.iwf.photopicker.widget;
2+
3+
import android.annotation.TargetApi;
4+
import android.app.Activity;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
import android.os.Build;
8+
import android.support.annotation.IntDef;
9+
import android.support.v7.widget.OrientationHelper;
10+
import android.support.v7.widget.StaggeredGridLayoutManager;
11+
import android.util.AttributeSet;
12+
import android.widget.FrameLayout;
13+
import android.widget.Toast;
14+
15+
import java.lang.annotation.Retention;
16+
import java.lang.annotation.RetentionPolicy;
17+
import java.util.ArrayList;
18+
19+
import me.iwf.photopicker.PhotoPickUtils;
20+
21+
/**
22+
* Created by Administrator on 2016/8/15 0015.
23+
*/
24+
public class MultiPickResultView extends FrameLayout {
25+
26+
@IntDef({ACTION_SELECT, ACTION_ONLY_SHOW})
27+
28+
//Tell the compiler not to store annotation data in the .class file
29+
@Retention(RetentionPolicy.SOURCE)
30+
31+
//Declare the NavigationMode annotation
32+
public @interface MultiPicAction {}
33+
34+
35+
36+
37+
public static final int ACTION_SELECT = 1;//该组件用于图片选择
38+
public static final int ACTION_ONLY_SHOW = 2;//该组件仅用于图片显示
39+
40+
private int action;
41+
42+
private int maxCount;
43+
44+
45+
android.support.v7.widget.RecyclerView recyclerView;
46+
PhotoAdapter photoAdapter;
47+
ArrayList<String> selectedPhotos;
48+
public MultiPickResultView(Context context) {
49+
this(context,null,0);
50+
}
51+
52+
public MultiPickResultView(Context context, AttributeSet attrs) {
53+
this(context, attrs,0);
54+
}
55+
56+
public MultiPickResultView(Context context, AttributeSet attrs, int defStyleAttr) {
57+
super(context, attrs, defStyleAttr);
58+
initView(context,attrs);
59+
initData(context,attrs);
60+
initEvent(context,attrs);
61+
}
62+
63+
private void initEvent(Context context, AttributeSet attrs) {
64+
65+
}
66+
67+
private void initData(Context context, AttributeSet attrs) {
68+
69+
}
70+
71+
private void initView(Context context, AttributeSet attrs) {
72+
73+
recyclerView = new android.support.v7.widget.RecyclerView(context,attrs);
74+
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, OrientationHelper.VERTICAL));
75+
this.addView(recyclerView);
76+
}
77+
78+
79+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
80+
public MultiPickResultView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
81+
this(context, attrs, defStyleAttr);
82+
}
83+
84+
public void init(Activity context,@MultiPicAction int action, ArrayList<String> photos){
85+
this.action = action;
86+
87+
selectedPhotos = new ArrayList<>();
88+
89+
this.action = action;
90+
if (photos != null && photos.size() >0){
91+
selectedPhotos.addAll(photos);
92+
}
93+
photoAdapter = new PhotoAdapter(context, selectedPhotos);
94+
photoAdapter.setAction(action);
95+
recyclerView.setAdapter(photoAdapter);
96+
97+
98+
}
99+
100+
101+
102+
103+
104+
public void onActivityResult(int requestCode, int resultCode, Intent data){
105+
if (action == ACTION_SELECT){
106+
PhotoPickUtils.onActivityResult(requestCode, resultCode, data, new PhotoPickUtils.PickHandler() {
107+
@Override
108+
public void onPickSuccess(ArrayList<String> photos) {
109+
photoAdapter.refresh(photos);
110+
}
111+
112+
@Override
113+
public void onPreviewBack(ArrayList<String> photos) {
114+
photoAdapter.refresh(photos);
115+
}
116+
117+
@Override
118+
public void onPickFail(String error) {
119+
Toast.makeText(getContext(),error,Toast.LENGTH_LONG).show();
120+
selectedPhotos.clear();
121+
photoAdapter.notifyDataSetChanged();
122+
}
123+
124+
@Override
125+
public void onPickCancle() {
126+
//Toast.makeText(getContext(),"取消选择",Toast.LENGTH_LONG).show();
127+
}
128+
});
129+
}
130+
131+
}
132+
133+
134+
public ArrayList<String> getPhotos() {
135+
return selectedPhotos;
136+
}
137+
138+
139+
}

0 commit comments

Comments
 (0)