1 package jp.sfjp.gokigen.a01c.liveview.dialog;
3 import android.content.Context;
4 import android.graphics.Canvas;
5 import android.graphics.Color;
6 import android.graphics.Paint;
7 import android.graphics.RectF;
8 import android.util.Log;
10 import java.util.Locale;
12 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ICameraPropertyLoadSaveOperations;
20 public class FavoriteSettingSelectionDialog implements IDialogDrawer
22 private final String TAG = toString();
23 private final ICameraPropertyLoadSaveOperations propertyOperation;
24 private final IDialogDismissedNotifier dismissNotifier;
25 private final Context context;
26 private final float WIDE_MARGIN = 10.0f;
27 private final float HEIGHT_MARGIN = 27.0f;
28 private int selectedId = 0;
29 private boolean isSaveOperation = false; // loadはfalse, saveがtrue
37 public FavoriteSettingSelectionDialog(Context context, ICameraPropertyLoadSaveOperations operation, IDialogDismissedNotifier dismissNotifier)
39 this.context = context;
40 this.propertyOperation = operation;
41 this.dismissNotifier = dismissNotifier;
51 public void drawDialog(Canvas canvas)
54 final float STROKE_WIDTH = 2.0f;
56 float width = canvas.getWidth();
57 float height = canvas.getHeight();
59 float height_unit = (height - 2.0f * (HEIGHT_MARGIN)) / 20.0f;
60 float width_unit = (width - 2.0f * (WIDE_MARGIN)) / 21.0f;
62 Paint paint = new Paint();
63 paint.setAntiAlias(true);
66 paint.setColor(Color.BLACK);
67 paint.setStyle(Paint.Style.FILL);
68 canvas.drawRect(WIDE_MARGIN, HEIGHT_MARGIN, (width - WIDE_MARGIN), (height - HEIGHT_MARGIN), paint);
71 paint.setColor(Color.WHITE);
72 paint.setStyle(Paint.Style.STROKE);
73 paint.setStrokeWidth(STROKE_WIDTH);
74 canvas.drawRect(WIDE_MARGIN, HEIGHT_MARGIN, (width - WIDE_MARGIN), (height - HEIGHT_MARGIN), paint);
75 canvas.drawLine(WIDE_MARGIN, ((height - HEIGHT_MARGIN) - (height_unit * 4.0f)), (width - WIDE_MARGIN),((height - HEIGHT_MARGIN) - (height_unit * 4.0f)), paint);
76 canvas.drawLine((width / 2.0f), ((height - HEIGHT_MARGIN) - (height_unit * 4.0f)), (width / 2.0f), (height - HEIGHT_MARGIN), paint);
77 canvas.drawLine(WIDE_MARGIN, (HEIGHT_MARGIN + (height_unit * 3.0f)), (width - WIDE_MARGIN), (HEIGHT_MARGIN + (height_unit * 3.0f)), paint);
82 style = (isSaveOperation) ? Paint.Style.STROKE : Paint.Style.FILL;
83 paint.setStyle(style);
84 canvas.drawRect((WIDE_MARGIN + (width_unit * 1.0f)), HEIGHT_MARGIN + 4.0f * height_unit, (WIDE_MARGIN + width_unit * (1.0f + 9.0f)), HEIGHT_MARGIN + 8.0f * height_unit, paint);
87 style = (!isSaveOperation) ? Paint.Style.STROKE : Paint.Style.FILL;
88 paint.setStyle(style);
89 canvas.drawRect((WIDE_MARGIN + (width_unit * 11.0f)), HEIGHT_MARGIN + 4.0f * height_unit, (WIDE_MARGIN + width_unit * (11.0f + 9.0f)), HEIGHT_MARGIN + 8.0f * height_unit, paint);
92 style = (selectedId != 0) ? Paint.Style.STROKE : Paint.Style.FILL;
93 paint.setStyle(style);
94 canvas.drawRect((WIDE_MARGIN + (width_unit * 1.0f)), HEIGHT_MARGIN + 9.0f * height_unit, (WIDE_MARGIN + width_unit * (1.0f + 3.0f)), HEIGHT_MARGIN + 15.0f * height_unit, paint);
97 style = (selectedId != 1) ? Paint.Style.STROKE : Paint.Style.FILL;
98 paint.setStyle(style);
99 canvas.drawRect((WIDE_MARGIN + (width_unit * 5.0f)), HEIGHT_MARGIN + 9.0f * height_unit, (WIDE_MARGIN + width_unit * (5.0f + 3.0f)), HEIGHT_MARGIN + 15.0f * height_unit, paint);
102 style = (selectedId != 2) ? Paint.Style.STROKE : Paint.Style.FILL;
103 paint.setStyle(style);
104 canvas.drawRect((WIDE_MARGIN + (width_unit * 9.0f)), HEIGHT_MARGIN + 9.0f * height_unit, (WIDE_MARGIN + width_unit * (9.0f + 3.0f)), HEIGHT_MARGIN + 15.0f * height_unit, paint);
107 style = (selectedId != 3) ? Paint.Style.STROKE : Paint.Style.FILL;
108 paint.setStyle(style);
109 canvas.drawRect((WIDE_MARGIN + (width_unit * 13.0f)), HEIGHT_MARGIN + 9.0f * height_unit, (WIDE_MARGIN + width_unit * (13.0f + 3.0f)), HEIGHT_MARGIN + 15.0f * height_unit, paint);
112 style = (selectedId != 4) ? Paint.Style.STROKE : Paint.Style.FILL;
113 paint.setStyle(style);
114 canvas.drawRect((WIDE_MARGIN + (width_unit * 17.0f)), HEIGHT_MARGIN + 9.0f * height_unit, (WIDE_MARGIN + width_unit * (17.0f + 3.0f)), HEIGHT_MARGIN + 15.0f * height_unit, paint);
120 * 画面でボタンが押された(押された位置 0.0f ~ 1.0f)
122 * @param posX X座標 (左~右)
123 * @param posY Y座標(上~下)
125 * @return true : ボタンなどがあるエリアだった / false : 何もしなかった
128 public boolean touchedPosition(float posX, float posY)
130 Log.v(TAG, " FavoriteSettingSelectionDialog::touchedPosition() [" + posX + "," + posY + "]");
133 if (posY > (16.0f / 20.0f))
135 // 画面下部のOK or Cancelが押された
139 if ((posY >= (4.0f / 20.0f))&&(posY <= (8.0f / 20.0f)))
141 // Load/Saveボタンの領域が押された
142 isSaveOperation = (posX >= (10.0f / 21.0f));
145 if ((posY >= (9.0f / 20.0f))&&(posY <= (15.0f / 20.0f)))
148 selectedIdArea(posX);
158 private void selectedIdArea(float posX)
160 if (posX <= (4.0f / 21.0f))
164 else if (posX <= ((4.0f * 2.0f) / 21.0f))
168 else if (posX <= ((4.0f * 3.0f) / 21.0f))
172 else if (posX <= ((4.0f * 4.0f) / 21.0f))
176 else //if (posX <= ((4.0f * 5.0f) / 21.0f))
188 private void saveProperties(int id)
192 propertyOperation.saveProperties(String.format(Locale.ENGLISH, "%03d", id), "a01c:" + id);
205 private void loadProperties(int id)
209 propertyOperation.loadProperties(String.format(Locale.ENGLISH, "%03d", id), "a01c:" + id);
220 * @param posX : ボタンが押された位置
222 private void dismiss(float posX)
224 boolean isExecute = (posX > 0.5f);
227 Log.v(TAG, " EXECUTE OPERATION : " + selectedId + " " + isSaveOperation);
233 saveProperties(selectedId + 1);
238 loadProperties(selectedId + 1);
242 if (dismissNotifier != null)
244 dismissNotifier.dialogDismissed(isExecute);