Skip to content

Commit 5e848e8

Browse files
committed
backup,change choince listener
1 parent 4baf08e commit 5e848e8

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

app/src/main/java/cc/fotoplace/fotoplacegallery/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
3434
}
3535

3636
public void onClickButton(View view) {
37-
Picker.from(this).count(0,1000).setEnableCamera(true).forResult(1);
37+
Picker.from(this).count(0,3).setEnableCamera(true).singleChoice().forResult(1);
3838
}
3939
}

gallery/src/main/java/io/valuesfeng/picker/ImageSelectActivity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ protected void onCreate(Bundle savedInstanceState) {
6464
mCapturePhotoUriHolder = savedInstanceState != null ? savedInstanceState.getString(STATE_CAPTURE_PHOTO_URI) : "";
6565
selectionSpec = getIntent().getParcelableExtra(ImageSelectActivity.EXTRA_SELECTION_SPEC);
6666
mMediaStoreCompat = new MediaStoreCompat(this, new Handler(Looper.getMainLooper()));
67+
6768
mCollection.onCreate(savedInstanceState);
6869
mCollection.prepareSelectionSpec(selectionSpec);
6970
mCollection.setDefaultSelection(getIntent().<Uri>getParcelableArrayListExtra(EXTRA_RESUME_LIST));
71+
mCollection.setOnSelectionChange(new SelectedUriCollection.OnSelectionChange() {
72+
@Override
73+
public void onChange(int maxCount, int selectCount) {
74+
commit.setText("确定("+selectCount+"/"+maxCount+")");
75+
}
76+
});
77+
7078
mGridView = (GridView) findViewById(R.id.gridView);
7179
mGridView.setOnScrollListener(new PauseOnScrollListener(ImageLoader.getInstance(),false,true));
80+
7281
mListView = (ListView) findViewById(R.id.listView);
7382
btnBack = (ImageView) findViewById(R.id.btn_back);
7483
mListViewGroup = findViewById(R.id.listViewParent);
@@ -77,12 +86,18 @@ protected void onCreate(Bundle savedInstanceState) {
7786
galleryTip = (ImageView) findViewById(R.id.gallery_tip);
7887
LinearLayout selectFold = (LinearLayout) findViewById(R.id.selectFold);
7988
commit = (Button) findViewById(R.id.commit);
89+
commit.setText("确定(0/"+selectionSpec.getMaxSelectable()+")");
90+
if (selectionSpec.isSingleChoose()){
91+
commit.setVisibility(View.GONE);
92+
}
8093
mFoldName.setText("最近图片");
8194
selectFold.setOnClickListener(mOnClickFoldName);
95+
8296
albumCollection.onCreate(ImageSelectActivity.this,this,selectionSpec,mListView);
8397
albumCollection.loadAlbums();
8498
mPhotoCollection.onCreate(ImageSelectActivity.this,mGridView,mCollection,selectionSpec);
8599
mPhotoCollection.loadAllPhoto();
100+
86101
commit.setOnClickListener(new View.OnClickListener() {
87102
@Override
88103
public void onClick(View v) {

gallery/src/main/java/io/valuesfeng/picker/adapter/PictureAdapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
*/
3535
public class PictureAdapter extends CursorAdapter {
3636
LayoutInflater mInflater;
37-
Context mContext;
3837
SelectedUriCollection mCollection;
3938

4039
public PictureAdapter(Context context, Cursor c, SelectedUriCollection mCollection) {
4140
super(context, c, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
4241
mInflater = LayoutInflater.from(context);
43-
mContext = context;
4442
this.mCollection = mCollection;
4543
}
4644

gallery/src/main/java/io/valuesfeng/picker/control/SelectedUriCollection.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class SelectedUriCollection {
3737
private final WeakReference<Context> mContext;
3838
private Set<Uri> mUris;
3939
private SelectionSpec mSpec;
40+
private OnSelectionChange onSelectionChange;
4041

4142
public SelectedUriCollection(Context context) {
4243
mContext = new WeakReference<>(context);
@@ -64,10 +65,14 @@ public void onSaveInstanceState(Bundle outState) {
6465
}
6566

6667
public boolean add(Uri uri) {
68+
if (onSelectionChange!=null)
69+
onSelectionChange.onChange(maxCount(),count()+1);
6770
return mUris.add(uri);
6871
}
6972

7073
public boolean remove(Uri uri) {
74+
if (onSelectionChange!=null)
75+
onSelectionChange.onChange(maxCount(),count()-1);
7176
return mUris.remove(uri);
7277
}
7378

@@ -103,4 +108,11 @@ public boolean isSingleChoose() {
103108
return mSpec.isSingleChoose();
104109
}
105110

111+
public void setOnSelectionChange(OnSelectionChange onSelectionChange) {
112+
this.onSelectionChange = onSelectionChange;
113+
}
114+
115+
public interface OnSelectionChange{
116+
void onChange(int maxCount,int selectCount);
117+
}
106118
}

gallery/src/main/res/layout/activity_image_select.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
32
android:layout_width="match_parent"
43
android:layout_height="match_parent">
54

gallery/src/main/res/layout/include_select_image_top.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
4-
android:layout_height="38dip"
5-
android:background="#0f0f0f"
6-
android:orientation="vertical">
4+
android:layout_height="wrap_content"
5+
android:background="#0f0f0f">
76

87
<ImageView
98
android:id="@+id/btn_back"
@@ -46,19 +45,19 @@
4645
<Button
4746
android:id="@+id/commit"
4847
android:layout_width="wrap_content"
49-
android:layout_height="wrap_content"
48+
android:layout_height="match_parent"
5049
android:layout_alignParentRight="true"
5150
android:layout_centerVertical="true"
52-
android:layout_marginRight="16dp"
51+
android:layout_marginRight="10dp"
52+
android:background="@null"
5353
android:minHeight="1dp"
5454
android:minWidth="1dp"
5555
android:paddingBottom="5dp"
5656
android:paddingLeft="10dp"
5757
android:paddingRight="10dp"
5858
android:paddingTop="5dp"
59-
android:text="确定"
60-
android:textSize="14sp"
61-
android:visibility="gone" />
62-
59+
android:text="确定(3/4)"
60+
android:textColor="#d6d6d6"
61+
android:textSize="14dp" />
6362

6463
</RelativeLayout>

0 commit comments

Comments
 (0)