OSDN Git Service

CSV一覧表示にアクションバーが出なかった不具合を修正、画像出力時のタイトルをライトグレー化する。
authorMRSa <mrsa@myad.jp>
Thu, 12 Jul 2018 15:40:06 +0000 (00:40 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 12 Jul 2018 15:40:06 +0000 (00:40 +0900)
app/src/main/AndroidManifest.xml
app/src/main/java/jp/sourceforge/gokigen/memoma/SymbolListArrayAdapter.java
app/src/main/java/jp/sourceforge/gokigen/memoma/drawers/MeMoMaCanvasDrawer.java
app/src/main/java/jp/sourceforge/gokigen/memoma/extension/ExtensionActivity.java
app/src/main/java/jp/sourceforge/gokigen/memoma/extension/ExtensionActivityListener.java
app/src/main/java/jp/sourceforge/gokigen/memoma/fileio/ObjectLayoutCaptureExporter.java

index d712df3..567fac3 100644 (file)
@@ -18,6 +18,7 @@
         </activity>
         <activity android:name=".extension.ExtensionActivity"
             android:label="@string/extent_name"
+            android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
             android:screenOrientation="landscape">
             <intent-filter>
                 <action android:name="jp.sfjp.gokigen.memoma.extension.activity" />
index 4fc0a13..aa3c62a 100644 (file)
@@ -3,6 +3,8 @@ package jp.sourceforge.gokigen.memoma;
 import java.util.List;
 
 import android.content.Context;
+import android.graphics.Color;
+import android.support.annotation.NonNull;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -12,9 +14,9 @@ import android.widget.TextView;
 
 public class SymbolListArrayAdapter extends ArrayAdapter<SymbolListArrayItem>
 {
-    private LayoutInflater inflater = null;
-    private int textViewResourceId = 0;
-    private List<SymbolListArrayItem> listItems = null;
+    private final LayoutInflater inflater;
+    private final int textViewResourceId;
+    private final List<SymbolListArrayItem> listItems;
     
     /**
      * コンストラクタ
@@ -35,9 +37,9 @@ public class SymbolListArrayAdapter extends ArrayAdapter<SymbolListArrayItem>
      * 
      */
     @Override
-    public View getView(int position, View convertView, ViewGroup parent)
+    public @NonNull View getView(int position, View convertView, @NonNull ViewGroup parent)
     {
-        View view = null;
+        View view;
         if(convertView != null)
         {
             view = convertView;
@@ -49,26 +51,28 @@ public class SymbolListArrayAdapter extends ArrayAdapter<SymbolListArrayItem>
 
         SymbolListArrayItem item = listItems.get(position);
         
-        ImageView imageView = (ImageView) view.findViewWithTag("icon");
+        ImageView imageView = view.findViewWithTag("icon");
         imageView.setImageResource(item.getIconResource());
 
         int subIcon = item.getSubIconResource();
         //if (subIcon != 0)
         {
-            ImageView subImage = (ImageView) view.findViewWithTag("subIcon");
+            ImageView subImage = view.findViewWithTag("subIcon");
             subImage.setImageResource(subIcon);
         }            
 
-        TextView titleView = (TextView)view.findViewWithTag("title");
+        TextView titleView = view.findViewWithTag("title");
+        titleView.setTextColor(Color.LTGRAY);
         titleView.setText(item.getTextResource1st());
 
-        TextView detailView = (TextView)view.findViewWithTag("detail");
+        TextView detailView = view.findViewWithTag("detail");
+        detailView.setTextColor(Color.LTGRAY);
         detailView.setText(item.getTextResource2nd());
 
-        /**
-        TextView optionView = (TextView)view.findViewWithTag("option");
+        /*
+        TextView optionView = view.findViewWithTag("option");
         optionView.setText(item.getTextResource3rd());
-        **/
+        */
         return (view);
     }
 }
index 57d57fc..d2575cb 100644 (file)
@@ -307,6 +307,12 @@ public class MeMoMaCanvasDrawer implements ICanvasDrawer,  GestureDetector.OnGes
                        // タイトルとめもまのアイコンを表示する : 文字の色は黒でいいのかな...
                        Bitmap bitmap = BitmapFactory.decodeResource(parent.getResources(), R.drawable.icon1);
                        canvas.drawBitmap(bitmap, 2.0f, 2.0f, paint);
+
+                // 文字をライトグレー、ちょっと影付きにする
+                paint.setColor(Color.LTGRAY);
+                paint.setStyle(Paint.Style.FILL_AND_STROKE);
+                paint.setShadowLayer(0.5f, 0.5f, 0.5f, Color.DKGRAY);
+
                        canvas.drawText(objectHolder.getDataTitle(), (bitmap.getWidth() + 10.0f), 32.0f, paint);
 
                }
index e0d4a5c..dc29ab5 100644 (file)
@@ -1,5 +1,6 @@
 package jp.sourceforge.gokigen.memoma.extension;
 
+import android.app.ActionBar;
 import android.app.Activity;
 import android.app.Dialog;
 import android.content.Intent;
@@ -31,16 +32,16 @@ public class ExtensionActivity extends  Activity
     {
           super.onCreate(savedInstanceState);
 
-          /** リスナクラスを生成する **/
-          listener = new ExtensionActivityListener((Activity) this);
+          // リスナクラスを生成する
+          listener = new ExtensionActivityListener(this);
 
-          /** レイアウトを設定する **/
-          setContentView(R.layout.extensionview);
+        // レイアウトを設定する
+        setContentView(R.layout.extensionview);
 
-          /** リスナクラスの準備 **/
-          listener.prepareExtraDatas(getIntent());
-          listener.prepareListener(); 
-     }
+        // リスナクラスの準備
+        listener.prepareExtraDatas(getIntent());
+        listener.prepareListener();
+    }
 
     /**
      *  メニューの生成
@@ -48,7 +49,7 @@ public class ExtensionActivity extends  Activity
     @Override
     public boolean onCreateOptionsMenu(Menu menu)
     {
-       menu = listener.onCreateOptionsMenu(menu);
+        menu = listener.onCreateOptionsMenu(menu);
        return (super.onCreateOptionsMenu(menu));
     }
     
index bde0119..1e23e40 100644 (file)
@@ -5,14 +5,15 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.Locale;
 
+import android.app.ActionBar;
 import android.app.Activity;
 import android.app.Dialog;
 import android.content.Intent;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
-import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.AdapterView;
@@ -42,27 +43,27 @@ import jp.sourceforge.gokigen.memoma.SymbolListArrayItem;
  */
 public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLoadingProcess.IResultReceiver, MeMoMaFileExportCsvProcess.IResultReceiver, FileSelectionDialog.IResultReceiver, MeMoMaFileImportCsvProcess.IResultReceiver
 {
-    public final int MENU_ID_EXPORT= (Menu.FIRST + 1);
-    public final int MENU_ID_SHARE = (Menu.FIRST + 2);
-    public final int MENU_ID_IMPORT = (Menu.FIRST + 3);
+    private final int MENU_ID_EXPORT= (Menu.FIRST + 1);
+    private final int MENU_ID_SHARE = (Menu.FIRST + 2);
+    private final int MENU_ID_IMPORT = (Menu.FIRST + 3);
 
-    private final String EXTENSION_DIRECTORY = "/exported";
+    private static final String EXTENSION_DIRECTORY = "/exported";
     
-    private ExternalStorageFileUtility fileUtility = null;
-       private MeMoMaObjectHolder objectHolder = null;
+    private ExternalStorageFileUtility fileUtility;
+       private MeMoMaObjectHolder objectHolder;
        private FileSelectionDialog fileSelectionDialog = null;
        
        private boolean isShareExportedData = false;
 
        private List<SymbolListArrayItem> listItems = null;
     
-    private Activity parent = null;  // 親分
+    private final Activity parent;  // 親分
        
        /**
      *  コンストラクタ
-     * @param argument
+     * @param argument parent activity
      */
-    public ExtensionActivityListener(Activity argument)
+       ExtensionActivityListener(Activity argument)
     {
         parent = argument;
         fileUtility = new ExternalStorageFileUtility(Main.APP_BASEDIR);
@@ -71,7 +72,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
     /**
      *  起動時にデータを準備する
      * 
-     * @param myIntent
+     * @param myIntent intent information
      */
     public void prepareExtraDatas(Intent myIntent)
     {
@@ -97,7 +98,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
     public void prepareListener()
     {
         // フィルタ設定ボタン
-        final ImageButton filterButton = (ImageButton) parent.findViewById(R.id.SetFilterButton);
+        final ImageButton filterButton = parent.findViewById(R.id.SetFilterButton);
         filterButton.setOnClickListener(this);
 
     }
@@ -117,7 +118,15 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
     {
                Log.v(Main.APP_IDENTIFIER, "ExtensionActivityListener::prepareToStart() : "  + objectHolder.getDataTitle());
 
-               // ファイルをロードする!
+               //  アクションバーを表示する
+        ActionBar bar = parent.getActionBar();
+        if (bar != null)
+        {
+            bar.show();
+            bar.setTitle(objectHolder.getDataTitle());
+        }
+
+        // ファイルをロードする!
                // (AsyncTaskを使ってデータを読み込む)
                MeMoMaFileLoadingProcess asyncTask = new MeMoMaFileLoadingProcess(parent, fileUtility, this);
         asyncTask.execute(objectHolder);
@@ -142,13 +151,13 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
     
     /**
      *  他画面から戻ってきたとき...
-     * @param requestCode
-     * @param resultCode
-     * @param data
+     *
+     *
      */
     public void onActivityResult(int requestCode, int resultCode, Intent data)
     {
         // なにもしない...
+        Log.v(Main.APP_IDENTIFIER, "rc: " + requestCode + " rs: " + resultCode + " it: "  + data.getDataString());
     }
 
     /**
@@ -160,25 +169,28 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
         if (id == R.id.SetFilterButton)
         {
                 // フィルタ設定ボタンが押された!
+            Log.v(Main.APP_IDENTIFIER, "Selected Filter");
         }
     }
     
-    /**
+/*
+    **
      *   触られたときの処理
-     * 
-     */
+     *
+     *
     public boolean onTouch(View v, MotionEvent event)
     {
+        Log.v(Main.APP_IDENTIFIER, " " + v.toString() + " " + event.toString());
         // int id = v.getId();
         // int action = event.getAction();
 
         return (false);
     }
+*/
 
     /**
      *   メニューへのアイテム追加
-     * @param menu
-     * @return
+     *
      */
     public Menu onCreateOptionsMenu(Menu menu)
     {
@@ -199,26 +211,22 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
     
     /**
      *   メニュー表示前の処理
-     * @param menu
-     * @return
+     *
      */
     public void onPrepareOptionsMenu(Menu menu)
     {
        menu.findItem(MENU_ID_SHARE).setVisible(true);
        menu.findItem(MENU_ID_EXPORT).setVisible(true);
        menu.findItem(MENU_ID_IMPORT).setVisible(true);
-
-       return;
     }
 
     /**
      *   メニューのアイテムが選択されたときの処理
-     * @param item
-     * @return
+     *
      */
     public boolean onOptionsItemSelected(MenuItem item)
     {
-       boolean result = false;
+       boolean result;
        switch (item.getItemId())
        {
           case MENU_ID_EXPORT:
@@ -245,6 +253,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
        return (result);
     }
 
+
     /**
      *   CSV形式でデータをインポートする
      * 
@@ -280,13 +289,13 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
                return (fileSelectionDialog.getDialog());
        }
 
-/**
+      /*
        if (id == R.id.info_about_gokigen)
        {
                CreditDialog dialog = new CreditDialog(parent);
                return (dialog.getDialog());
        }
-**/
+      */
            return (null);
     }
 
@@ -296,7 +305,15 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
      */
     private void prepareFileSelectionDialog(Dialog dialog)
     {
-       fileSelectionDialog.prepare("", EXTENSION_DIRECTORY);
+        try
+        {
+            Log.v(Main.APP_IDENTIFIER, " " + dialog.toString());
+            fileSelectionDialog.prepare("", EXTENSION_DIRECTORY);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -309,7 +326,6 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
         {
                // CSVインポートダイアログを準備する
                prepareFileSelectionDialog(dialog);
-               return;
         }
     }
 
@@ -323,7 +339,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
                {
                // リストに表示するアイテムを生成する
                listItems = null;
-               listItems = new ArrayList<SymbolListArrayItem>();
+               listItems = new ArrayList<>();
 
                // TODO: 何らかの法則に従って並べ替えをする。
 
@@ -337,7 +353,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
                    int objectStyleIcon = MeMoMaObjectHolder .getObjectDrawStyleIcon(pos.drawStyle);
                    
                    // ユーザチェックの有無表示
-                   int userCheckedIcon = (pos.userChecked == true) ? R.drawable.btn_checked : R.drawable.btn_notchecked;
+                   int userCheckedIcon = (pos.userChecked) ? R.drawable.btn_checked : R.drawable.btn_notchecked;
 
                    // TODO: アイテム選択時の情報エリアは(ArrayItem側には)用意しているが未使用。
                    SymbolListArrayItem listItem = new SymbolListArrayItem(userCheckedIcon, pos.label, pos.detail, "", objectStyleIcon);
@@ -382,7 +398,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
                String outputMessage = parent.getString(R.string.export_csv) + " " + objectHolder.getDataTitle() + " " + detail;
         Toast.makeText(parent, outputMessage, Toast.LENGTH_SHORT).show();
         
-        if (isShareExportedData == true)
+        if (isShareExportedData)
         {
                // エクスポートしたファイルを共有する
             shareContent(exportedFileName);
@@ -398,7 +414,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
        try
        {
                // リストアダプターを生成し、設定する
-            ListView listView = (ListView) parent.findViewById(R.id.ExtensionView);
+            ListView listView = parent.findViewById(R.id.ExtensionView);
             ListAdapter adapter = new SymbolListArrayAdapter(parent,  R.layout.listarrayitems, listItems);
             listView.setAdapter(adapter);
 
@@ -425,7 +441,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
     /**
      *    エクスポートしたファイルを共有する
      * 
-     * @param fileName
+     *
      */
     private void shareContent(String fileName)
     {
@@ -434,7 +450,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
         {
                // 現在の時刻を取得する
             Calendar calendar = Calendar.getInstance();
-               SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+               SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
             String date =  outFormat.format(calendar.getTime());
 
             // メールタイトル
@@ -450,7 +466,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
         }
         catch (Exception ex)
         {
-               
+            ex.printStackTrace();
         }
     }
     
@@ -468,8 +484,7 @@ public class ExtensionActivityListener  implements OnClickListener, MeMoMaFileLo
 
     /**
      *    インポート結果の受信
-     * 
-     * @param detail
+     *
      */
     public void onImportedResult(String detail)
     {
index f6e22c8..c780c1b 100644 (file)
@@ -6,6 +6,7 @@ import java.io.OutputStream;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Enumeration;
+import java.util.Locale;
 
 import android.app.Activity;
 import android.app.ProgressDialog;
@@ -42,27 +43,32 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
        
        private static final int MINIMUM_WIDTH = 800;
        private static final int MINIMUM_HEIGHT = 600;
-       
-       private Activity parent = null;
-       private ICaptureLayoutExporter receiver = null;
-       private ExternalStorageFileUtility fileUtility = null;
+
+       private ICaptureLayoutExporter receiver;
+       private ExternalStorageFileUtility fileUtility;
        private String exportedFileName = null; 
-       private MeMoMaObjectHolder objectHolder = null;
-       private MeMoMaCanvasDrawer canvasDrawer = null;
-       private ProgressDialog savingDialog = null;
+       private MeMoMaObjectHolder objectHolder;
+       private MeMoMaCanvasDrawer canvasDrawer;
+       private ProgressDialog savingDialog;
        private float offsetX = 0.0f;
        private float offsetY = 0.0f;
+       private int displayWidth;
+       private int displayHeight;
 
        /**
         *   コンストラクタ
         */
-    public ObjectLayoutCaptureExporter(Activity context, ExternalStorageFileUtility utility,  MeMoMaObjectHolder holder, MeMoMaCanvasDrawer drawer, ICaptureLayoutExporter resultReceiver)
+       ObjectLayoutCaptureExporter(Activity context, ExternalStorageFileUtility utility,  MeMoMaObjectHolder holder, MeMoMaCanvasDrawer drawer, ICaptureLayoutExporter resultReceiver)
     {
        receiver = resultReceiver;
        fileUtility = utility;
        objectHolder = holder;
        canvasDrawer = drawer;
-       parent = context;
+
+        // 現在の画面サイズを取得
+        Display display = context.getWindowManager().getDefaultDisplay();
+        displayWidth = display.getWidth();
+        displayHeight = display.getHeight();
 
         //  プログレスダイアログ(「保存中...」)を表示する。
        savingDialog = new ProgressDialog(context);
@@ -72,9 +78,12 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
        savingDialog.setCancelable(false);
        savingDialog.show();
 
-       /** ファイルをバックアップするディレクトリを作成する **/
+       // ファイルをバックアップするディレクトリを作成する
        File dir = new File(fileUtility.getGokigenDirectory() + "/exported");
-       dir.mkdir();
+       if (!dir.mkdir())
+        {
+            Log.v(Main.APP_IDENTIFIER, "mkdir is failed.");
+        }
     }
        
     /**
@@ -89,10 +98,8 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
     
     /**
      *    ビットマップデータを(PNG形式で)保管する。
-     * 
-     * @param fileName
-     * @param objectHolder
-     * @return
+     *
+     *
      */
     private String exportToFile(String fileName, Bitmap targetBitmap)
     {
@@ -107,7 +114,7 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
                
                // エクスポートするファイル名を決定する
             Calendar calendar = Calendar.getInstance();
-            SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
+            SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
             exportedFileName = fileName + "_" + outFormat.format(calendar.getTime()) + ".png";
 
             // PNG形式でファイル出力を行う。
@@ -128,7 +135,7 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
     /**
      *    キャンバスの大きさがどれくらい必要か、チェックする。
      * 
-     * @return
+     *
      */
     private Rect checkCanvasSize()
     {
@@ -166,26 +173,26 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
         canvasSize.sort();
 
         // 現在の画面サイズを取得
-        Display display = parent.getWindowManager().getDefaultDisplay();
-        int width = display.getWidth();
-        int height = display.getHeight();
-        if (width < MINIMUM_WIDTH)
+        //Display display = parent.getWindowManager().getDefaultDisplay();
+        //int width = display.getWidth();
+        //int height = display.getHeight();
+        if (displayWidth < MINIMUM_WIDTH)
         {
-               width = MINIMUM_WIDTH;
+            displayWidth = MINIMUM_WIDTH;
         }
-        if (height < MINIMUM_HEIGHT)
+        if (displayHeight < MINIMUM_HEIGHT)
         {
-               height = MINIMUM_HEIGHT;
+            displayHeight = MINIMUM_HEIGHT;
         }        
 
         // 出力の最小サイズを(表示画面サイズに)設定
-        if (canvasSize.width() < width)
+        if (canvasSize.width() < displayWidth)
         {
-               canvasSize.right = canvasSize.left + width;
+               canvasSize.right = canvasSize.left + displayWidth;
         }
-        if (canvasSize.height() < height)
+        if (canvasSize.height() < displayHeight)
         {
-               canvasSize.bottom = canvasSize.top + height;
+               canvasSize.bottom = canvasSize.top + displayHeight;
         }
         
         
@@ -206,21 +213,27 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
     @Override
     protected String doInBackground(String... datas)
     {
-       Rect canvasSize = checkCanvasSize();
-       Bitmap targetBitmap = Bitmap.createBitmap(canvasSize.width(), canvasSize.height(), Bitmap.Config.RGB_565);
-       Canvas targetCanvas = new Canvas(targetBitmap);
-       
-       // オブジェクトをビットマップの中に書き込む
-       canvasDrawer.drawOnBitmapCanvas(targetCanvas, offsetX, offsetY);
+       String result = "";
+       try
+        {
+            Rect canvasSize = checkCanvasSize();
+            Bitmap targetBitmap = Bitmap.createBitmap(canvasSize.width(), canvasSize.height(), Bitmap.Config.RGB_565);
+            Canvas targetCanvas = new Canvas(targetBitmap);
 
-       // ファイル名の設定 ... (拡張子なし)
-       String fileName = fileUtility.getGokigenDirectory() + "/exported/" + datas[0];
+            // オブジェクトをビットマップの中に書き込む
+            canvasDrawer.drawOnBitmapCanvas(targetCanvas, offsetX, offsetY);
 
-       // データを保管する
-        String result = exportToFile(fileName, targetBitmap);
+            // ファイル名の設定 ... (拡張子なし)
+            String fileName = fileUtility.getGokigenDirectory() + "/exported/" + datas[0];
 
+            // データを保管する
+            result = exportToFile(fileName, targetBitmap);
+        }
+        catch (Throwable t)
+        {
+            t.printStackTrace();
+        }
         System.gc();
-
         return (result);
     }
 
@@ -257,7 +270,6 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
        {
             savingDialog.dismiss();
        }
-       return;
     }     
  
     /**
@@ -268,7 +280,7 @@ public class ObjectLayoutCaptureExporter extends AsyncTask<String, Integer, Stri
      */
     public interface ICaptureLayoutExporter
     {
-        /**  保存結果の報告 **/
-        public abstract void onCaptureLayoutExportedResult(String exportedFileName, String detail);
+        //  保存結果の報告
+        void onCaptureLayoutExportedResult(String exportedFileName, String detail);
     }
 }