OSDN Git Service

長押しで画像の選択をできるようにしてみた。
authorMRSa <mrsa@myad.jp>
Fri, 15 Mar 2019 15:18:09 +0000 (00:18 +0900)
committerMRSa <mrsa@myad.jp>
Fri, 15 Mar 2019 15:18:09 +0000 (00:18 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/playback/ImageGridViewFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/MultiFileDownloadConfirmationDialog.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/CameraContentEx.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/grid/ImageGridCellViewHolder.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/grid/ImageGridViewAdapter.java
app/src/main/res/drawable/ic_check_green_24dp.xml [new file with mode: 0644]
app/src/main/res/drawable/ic_select_all_grey_24dp.xml [new file with mode: 0644]
app/src/main/res/layout/dialog_confirmation_batch_download.xml [new file with mode: 0644]
app/src/main/res/layout/view_grid_cell.xml
app/src/main/res/values/strings.xml
build.gradle

index bf15c59..ecba1e2 100644 (file)
@@ -50,7 +50,7 @@ import androidx.preference.PreferenceManager;
  *
  *
  */
-public class ImageGridViewFragment extends Fragment implements AdapterView.OnItemClickListener, AdapterView.OnItemSelectedListener, CompoundButton.OnCheckedChangeListener
+public class ImageGridViewFragment extends Fragment implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, AdapterView.OnItemSelectedListener, CompoundButton.OnCheckedChangeListener, MultiFileDownloadConfirmationDialog.Callback
 {
        private final String TAG = this.toString();
 
@@ -110,6 +110,7 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
             gridView = view.findViewById(R.id.gridView1);
             gridView.setAdapter(adapter);
             gridView.setOnItemClickListener(this);
+            gridView.setOnItemLongClickListener(this);
             gridView.setOnScrollListener(adapter);
         }
                return (view);
@@ -424,6 +425,45 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
         }
     }
 
+
+    @Override
+    public boolean onItemLongClick(final AdapterView<?> parent, View view, int position, long id)
+    {
+        try
+        {
+            CameraContentEx infoEx = imageContentList.get(position);
+            if (infoEx != null)
+            {
+                boolean isChecked = infoEx.isSelected();
+                infoEx.setSelected(!isChecked);
+            }
+            view.invalidate();
+            runOnUiThread(new Runnable()
+            {
+                @Override
+                public void run()
+                {
+                    try
+                    {
+                        ImageGridViewAdapter adapter = (ImageGridViewAdapter) parent.getAdapter();
+                        adapter.notifyDataSetChanged();
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            });
+            return (true);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+
     // AdapterView.OnItemSelectedListener
     @Override
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
@@ -483,4 +523,49 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
             e.printStackTrace();
         }
     }
+
+    @Override
+    public void confirmSelection(int selectedButtonId, boolean withRaw)
+    {
+        Log.v(TAG, "confirmSelection : " + selectedButtonId + " (" + withRaw + ")");
+/*
+        float downloadSize;
+        switch (selectedButtonId)
+        {
+            case R.id.radio_download__1024x768:
+                downloadSize = OLYCamera.IMAGE_RESIZE_1024;
+                break;
+            case R.id.radio_download__1600x1200:
+                downloadSize = OLYCamera.IMAGE_RESIZE_1600;
+                break;
+            case R.id.radio_download__1920x1440:
+                downloadSize = OLYCamera.IMAGE_RESIZE_1920;
+                break;
+            case R.id.radio_download__2048x1536:
+                downloadSize = OLYCamera.IMAGE_RESIZE_2048;
+                break;
+
+            case R.id.radio_download__original_size:
+            default:
+                downloadSize = OLYCamera.IMAGE_RESIZE_NONE;
+                break;
+        }
+
+        List<OLYCameraContentInfoEx> contentList = contentListHolder.getSelectedContentList();
+        for (OLYCameraContentInfoEx item : contentList)
+        {
+            Log.v(TAG, "  " + item.getFileInfo().getFilename());
+        }
+
+        try
+        {
+            ImageDownloader downloader = new ImageDownloader(getActivity(), camera);
+            downloader.startDownloadMulti(contentList, downloadSize, withRaw, this);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+*/
+    }
 }
diff --git a/app/src/main/java/net/osdn/gokigen/pkremote/playback/MultiFileDownloadConfirmationDialog.java b/app/src/main/java/net/osdn/gokigen/pkremote/playback/MultiFileDownloadConfirmationDialog.java
new file mode 100644 (file)
index 0000000..3c619a2
--- /dev/null
@@ -0,0 +1,105 @@
+package net.osdn.gokigen.pkremote.playback;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.RadioGroup;
+import android.widget.TextView;
+
+import net.osdn.gokigen.pkremote.R;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.DialogFragment;
+
+/**
+ *   複数ファイルの一括ダウンロードを実施することを確認するダイアログ
+ *
+ */
+public class MultiFileDownloadConfirmationDialog extends DialogFragment
+{
+    private final String TAG = this.toString();
+
+    private Callback callback;
+    private int nofPictures;
+
+    public static MultiFileDownloadConfirmationDialog newInstance(@NonNull Callback callback, int nofPictures)
+    {
+        MultiFileDownloadConfirmationDialog instance = new MultiFileDownloadConfirmationDialog();
+        instance.prepare(callback, nofPictures);
+
+        return (instance);
+    }
+
+    private void prepare(Callback callback, int nofPictures)
+    {
+        this.callback = callback;
+        this.nofPictures = nofPictures;
+    }
+
+    @Override
+    public @NonNull Dialog onCreateDialog(Bundle savedInstanceState)
+    {
+        Activity activity = getActivity();
+        LayoutInflater inflater = activity.getLayoutInflater();
+        View view = inflater.inflate(R.layout.dialog_confirmation_batch_download, null, false);
+        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+        builder.setTitle(activity.getString(R.string.dialog_title_batch_download));
+        TextView textView = view.findViewById(R.id.label_batch_download_info);
+        if (textView != null)
+        {
+            String label = getString(R.string.dialog_label_batch_download) + nofPictures;
+            textView.setText(label);
+        }
+        final RadioGroup radio = view.findViewById(R.id.radio_group_select_category);
+        final CheckBox checkWithRaw = view.findViewById(R.id.radio_download__raw);
+
+        // ボタンを設定する(実行ボタン)
+        builder.setPositiveButton(activity.getString(R.string.dialog_positive_download),
+                new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int which) {
+                        int buttonId = 0;
+                        boolean withRaw = false;
+                        try {
+                            if (radio != null)
+                            {
+                                buttonId = radio.getCheckedRadioButtonId();
+                            }
+                            if (checkWithRaw != null)
+                            {
+                                withRaw = checkWithRaw.isChecked();
+                            }
+                        }
+                        catch (Exception e)
+                        {
+                            e.printStackTrace();
+                        }
+                        dialog.dismiss();
+                        //Log.v(TAG, "confirmSelection() " + buttonId + " [" + withRaw + "]");
+                        callback.confirmSelection(buttonId, withRaw);
+                     }
+                });
+
+        // ボタンを設定する (キャンセルボタン)
+        builder.setNegativeButton(activity.getString(R.string.dialog_negative_cancel),
+                new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int which) {
+                        dialog.cancel();
+                    }
+                });
+
+        builder.setView(view);
+        return (builder.create());
+    }
+
+    // コールバックインタフェース
+    public interface Callback
+    {
+        void confirmSelection(int selectedButtonId, boolean withRaw);
+    }
+
+}
index c179c22..de0728d 100644 (file)
@@ -10,12 +10,14 @@ public class CameraContentEx
     private static final String MOVIE_SUFFIX = ".mov";
     private String rawSuffix;
     private boolean hasRaw;
+    private boolean isSelected;
 
     public CameraContentEx(ICameraContent fileInfo, boolean hasRaw, String rawSuffix)
     {
         this.fileInfo = fileInfo;
         this.hasRaw = hasRaw;
         this.rawSuffix = rawSuffix;
+        this.isSelected = false;
     }
 
     public void setHasRaw(boolean value, String rawSuffix)
@@ -24,6 +26,11 @@ public class CameraContentEx
         this.rawSuffix = rawSuffix;
     }
 
+    public void setSelected(boolean isSelected)
+    {
+        this.isSelected = isSelected;
+    }
+
     public boolean hasRaw()
     {
         return (hasRaw);
@@ -35,6 +42,11 @@ public class CameraContentEx
         return (contentName.endsWith(MOVIE_SUFFIX));
     }
 
+    public boolean isSelected()
+    {
+        return (isSelected);
+    }
+
     public String getRawSuffix()
     {
         return (rawSuffix);
index 50aef24..817b268 100644 (file)
@@ -6,11 +6,13 @@ class ImageGridCellViewHolder
 {
     private ImageView imageView;
     private ImageView iconView;
+    private ImageView selectView;
 
-    ImageGridCellViewHolder(ImageView image, ImageView icon)
+    ImageGridCellViewHolder(ImageView image, ImageView icon, ImageView selection)
     {
         this.imageView = image;
         this.iconView = icon;
+        this.selectView = selection;
     }
 
     ImageView getImageView()
@@ -23,4 +25,9 @@ class ImageGridCellViewHolder
         return (iconView);
     }
 
+    ImageView getSelectView()
+    {
+        return (selectView);
+    }
+
 }
index 2dc9a62..9322b16 100644 (file)
@@ -89,7 +89,7 @@ public class ImageGridViewAdapter extends BaseAdapter implements AbsListView.OnS
             convertView = inflater.inflate(R.layout.view_grid_cell, parent, false);
             if (convertView != null)
             {
-                viewHolder = new ImageGridCellViewHolder((ImageView) convertView.findViewById(R.id.imageViewY), (ImageView) convertView.findViewById(R.id.imageViewZ));
+                viewHolder = new ImageGridCellViewHolder((ImageView) convertView.findViewById(R.id.imageViewY), (ImageView) convertView.findViewById(R.id.imageViewZ), (ImageView) convertView.findViewById(R.id.imageViewX));
                 convertView.setTag(viewHolder);
             }
             else
@@ -110,6 +110,7 @@ public class ImageGridViewAdapter extends BaseAdapter implements AbsListView.OnS
         {
             viewHolder.getImageView().setImageResource(R.drawable.ic_satellite_grey_24dp);
             viewHolder.getIconView().setImageDrawable(null);
+            viewHolder.getSelectView().setImageDrawable(null);
             return (convertView);
         }
         String path = new File(item.getContentPath(), item.getContentName()).getPath();
@@ -118,6 +119,7 @@ public class ImageGridViewAdapter extends BaseAdapter implements AbsListView.OnS
         {
             viewHolder.getImageView().setImageResource(R.drawable.ic_satellite_grey_24dp);
             viewHolder.getIconView().setImageDrawable(null);
+            viewHolder.getSelectView().setImageDrawable(null);
             if (!gridViewIsScrolling)
             {
                 if (executor.isShutdown())
@@ -142,6 +144,14 @@ public class ImageGridViewAdapter extends BaseAdapter implements AbsListView.OnS
             {
                 viewHolder.getIconView().setImageDrawable(null);
             }
+            if (infoEx.isSelected())
+            {
+                viewHolder.getSelectView().setImageResource(R.drawable.ic_check_green_24dp);
+            }
+            else
+            {
+                viewHolder.getSelectView().setImageDrawable(null);
+            }
         }
         return (convertView);
     }
diff --git a/app/src/main/res/drawable/ic_check_green_24dp.xml b/app/src/main/res/drawable/ic_check_green_24dp.xml
new file mode 100644 (file)
index 0000000..2513654
--- /dev/null
@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#80FA80"
+    android:viewportHeight="24.0" android:viewportWidth="24.0"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_select_all_grey_24dp.xml b/app/src/main/res/drawable/ic_select_all_grey_24dp.xml
new file mode 100644 (file)
index 0000000..d8ab502
--- /dev/null
@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#C0C0C0"
+    android:viewportHeight="24.0" android:viewportWidth="24.0"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M3,5h2L5,3c-1.1,0 -2,0.9 -2,2zM3,13h2v-2L3,11v2zM7,21h2v-2L7,19v2zM3,9h2L5,7L3,7v2zM13,3h-2v2h2L13,3zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM5,21v-2L3,19c0,1.1 0.9,2 2,2zM3,17h2v-2L3,15v2zM9,3L7,3v2h2L9,3zM11,21h2v-2h-2v2zM19,13h2v-2h-2v2zM19,21c1.1,0 2,-0.9 2,-2h-2v2zM19,9h2L21,7h-2v2zM19,17h2v-2h-2v2zM15,21h2v-2h-2v2zM15,5h2L17,3h-2v2zM7,17h10L17,7L7,7v10zM9,9h6v6L9,15L9,9z"/>
+</vector>
diff --git a/app/src/main/res/layout/dialog_confirmation_batch_download.xml b/app/src/main/res/layout/dialog_confirmation_batch_download.xml
new file mode 100644 (file)
index 0000000..bb67162
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_height="match_parent"
+    android:layout_width="match_parent"
+    android:orientation="vertical"
+    >
+    <TextView
+        android:id="@+id/label_batch_download_info_margin"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/blank"
+        />
+    <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/radio_group_select_category"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:orientation="vertical">
+        <RadioButton
+            android:id="@+id/radio_download__original_size"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/action_download_original_size"
+            android:checked="true"
+            android:textSize="8pt"
+            />
+        <RadioButton android:id="@+id/radio_download__2048x1536"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/action_download_2048x1536"
+            android:checked="false"
+            android:textSize="8pt"
+            />
+        <RadioButton android:id="@+id/radio_download__1920x1440"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/action_download_1920x1440"
+            android:checked="false"
+            android:textSize="8pt"
+            />
+        <RadioButton android:id="@+id/radio_download__1600x1200"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/action_download_1600x1200"
+            android:checked="false"
+            android:textSize="8pt"
+            />
+        <RadioButton android:id="@+id/radio_download__1024x768"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/action_download_1024x768"
+            android:checked="false"
+            android:textSize="8pt"
+            />
+    </RadioGroup>
+    <CheckBox android:id="@+id/radio_download__raw"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/action_download_with_raw"
+        android:checked="false"
+        android:textSize="8pt"
+        />
+
+    <TextView
+        android:id="@+id/label_batch_download_info"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/blank"
+        android:layout_gravity="end"
+        android:layout_marginRight="10dp"
+        android:layout_marginEnd="10dp"
+        android:padding="4dp"
+        />
+
+    <TextView
+        android:id="@+id/label_batch_download_message"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/blank"
+        />
+
+</LinearLayout>
index a82d8ff..2e710d8 100644 (file)
         android:scaleType="centerCrop"
         android:src="@null"
         tools:ignore="ContentDescription" />
+
+    <ImageView
+        android:id="@+id/imageViewX"
+        android:layout_width="50dp"
+        android:layout_height="50dp"
+        android:layout_alignParentTop="true"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true"
+        android:layout_marginLeft="15dp"
+        android:layout_marginStart="15dp"
+        android:layout_marginTop="15dp"
+        android:scaleType="centerCrop"
+        android:src="@null"
+        tools:ignore="ContentDescription" />
+
+
 </RelativeLayout>
\ No newline at end of file
index 94378c2..3bbdbfb 100644 (file)
 
     <string name="select_radio_date">Date</string>
     <string name="select_radio_path">Path</string>
+
+    <string name="action_download_with_raw">Download with RAW</string>
+    <string name="dialog_title_batch_download">Batch Download(select size)</string>
+    <string name="dialog_positive_download">Download</string>
+    <string name="dialog_label_batch_download">Selected : </string>
+    <string name="dialog_label_select_size"> </string>
+    <string name="message_download_finished_pics">Finished. Number of Pics. : </string>
+    <string name="message_download_finished_pics_with_failure">Finished. # of Pics. : </string>
+    <string name="message_download_failure_count"> Failures : </string>
+    <string name="message_download_finished_but_failed">Download was failed&#8230; </string>
 </resources>
index 3c23acc..e11a5b3 100644 (file)
@@ -7,7 +7,7 @@ buildscript {
         
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.3.1'
+        classpath 'com.android.tools.build:gradle:3.3.2'
         
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files