From ceecb21fa100e036f78341f8ebf6b4859bd2b193 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 28 Feb 2016 23:10:01 +0100 Subject: [PATCH] mark the selected items --- .../simplemobiletools/gallery/activities/PhotosActivity.java | 4 +++- .../simplemobiletools/gallery/adapters/PhotosAdapter.java | 5 ++--- app/src/main/res/drawable/selected_mask.xml | 4 ++++ app/src/main/res/drawable/selected_pressed_mask.xml | 4 ++++ app/src/main/res/drawable/selector.xml | 5 +++++ app/src/main/res/layout/activity_photos.xml | 2 +- app/src/main/res/layout/photo_item.xml | 2 +- app/src/main/res/values/colors.xml | 2 ++ 8 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/selected_mask.xml create mode 100644 app/src/main/res/drawable/selected_pressed_mask.xml create mode 100644 app/src/main/res/drawable/selector.xml diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java index 99185e79b..3ce567956 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java @@ -26,6 +26,7 @@ import java.util.regex.Pattern; public class PhotosActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener { private List photos; private int selectedItemsCnt; + private GridView gridView; @Override protected void onCreate(Bundle savedInstanceState) { @@ -34,8 +35,8 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI photos = new ArrayList<>(); final String path = getIntent().getStringExtra(Constants.DIRECTORY); - final GridView gridView = (GridView) findViewById(R.id.photos_grid); final PhotosAdapter adapter = new PhotosAdapter(this, getPhotos(path)); + gridView = (GridView) findViewById(R.id.photos_grid); gridView.setAdapter(adapter); gridView.setOnItemClickListener(this); gridView.setMultiChoiceModeListener(this); @@ -45,6 +46,7 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI } private List getPhotos(final String path) { + photos.clear(); final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; final String where = MediaStore.Images.Media.DATA + " like ? "; final String[] args = new String[]{path + "%"}; diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java index 1a4188f31..9e1dab00b 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java @@ -8,11 +8,10 @@ import android.widget.BaseAdapter; import android.widget.ImageView; import com.bumptech.glide.Glide; +import com.simplemobiletools.gallery.R; import java.util.List; -import com.simplemobiletools.gallery.R; - public class PhotosAdapter extends BaseAdapter { private final Context context; private final List photos; @@ -36,7 +35,7 @@ public class PhotosAdapter extends BaseAdapter { } String path = photos.get(position); - Glide.with(context).load(path).centerCrop().crossFade().into(holder.photoThumbnail); + Glide.with(context).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail); return view; } diff --git a/app/src/main/res/drawable/selected_mask.xml b/app/src/main/res/drawable/selected_mask.xml new file mode 100644 index 000000000..50e6a28e4 --- /dev/null +++ b/app/src/main/res/drawable/selected_mask.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/selected_pressed_mask.xml b/app/src/main/res/drawable/selected_pressed_mask.xml new file mode 100644 index 000000000..aa5443835 --- /dev/null +++ b/app/src/main/res/drawable/selected_pressed_mask.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/selector.xml b/app/src/main/res/drawable/selector.xml new file mode 100644 index 000000000..480db1e64 --- /dev/null +++ b/app/src/main/res/drawable/selector.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_photos.xml b/app/src/main/res/layout/activity_photos.xml index d6a47b7a7..7b7649025 100644 --- a/app/src/main/res/layout/activity_photos.xml +++ b/app/src/main/res/layout/activity_photos.xml @@ -5,9 +5,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" + android:choiceMode="multipleChoiceModal" android:columnWidth="@dimen/photo_tmb_size" android:horizontalSpacing="1dp" android:numColumns="auto_fit" android:stretchMode="columnWidth" - android:choiceMode="multipleChoiceModal" android:verticalSpacing="1dp"/> diff --git a/app/src/main/res/layout/photo_item.xml b/app/src/main/res/layout/photo_item.xml index aee17950b..d2fed18bb 100644 --- a/app/src/main/res/layout/photo_item.xml +++ b/app/src/main/res/layout/photo_item.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/tmb_background"> + android:foreground="@drawable/selector"> #FF4081 #ff222222 #66000000 + #11000000 + #44000000