|
|
@@ -1,254 +0,0 @@
|
|
|
-package kr.co.zumo.app.lifeplus.view.dialog;
|
|
|
-
|
|
|
-import android.content.DialogInterface;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.support.annotation.Nullable;
|
|
|
-import android.support.annotation.StringRes;
|
|
|
-import android.support.v4.app.DialogFragment;
|
|
|
-import android.util.Log;
|
|
|
-import android.view.LayoutInflater;
|
|
|
-import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
-import android.view.WindowManager;
|
|
|
-import android.widget.Button;
|
|
|
-import android.widget.ImageView;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
-
|
|
|
-import io.reactivex.disposables.Disposable;
|
|
|
-import kr.co.zumo.app.R;
|
|
|
-import kr.co.zumo.app.lifeplus.view.Event;
|
|
|
-
|
|
|
-/**
|
|
|
- * PinDialog
|
|
|
- * <pre>
|
|
|
- * </pre>
|
|
|
- *
|
|
|
- * @author 하세미
|
|
|
- * @version 1.0
|
|
|
- * @history 하세미 [2018-09-13] [최초 작성]
|
|
|
- * @since 2018-09-13
|
|
|
- */
|
|
|
-public class PinDialog extends DialogBase {
|
|
|
-
|
|
|
- private ArrayList<Integer> numberList;
|
|
|
- private ArrayList<Button> buttonList;
|
|
|
- private ArrayList<ImageView> imageList;
|
|
|
- private String password;
|
|
|
- @StringRes
|
|
|
- private int guideStringId = R.string.empty_string;
|
|
|
- @StringRes
|
|
|
- private int titleStringId = R.string.empty_string;
|
|
|
-
|
|
|
- private TextView textGuide;
|
|
|
- private TextView textTitle;
|
|
|
- private Disposable disposable;
|
|
|
- private Button buttonShuffle;
|
|
|
- private Button buttonDelete;
|
|
|
-
|
|
|
- public PinDialog() {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCreate(Bundle savedInstanceState) {
|
|
|
- setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
|
|
|
- setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCancel(DialogInterface dialog) {
|
|
|
- resultListener.onDialogCanceled(this);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 가이드 텍스트를 업데이트 한다.
|
|
|
- *
|
|
|
- * @param stringId
|
|
|
- */
|
|
|
- public void updateGuideText(@StringRes int stringId) {
|
|
|
- guideStringId = stringId;
|
|
|
-
|
|
|
- if (null != textGuide) {
|
|
|
- textGuide.setText(guideStringId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * title 텍스트를 업데이트 한다.
|
|
|
- *
|
|
|
- * @param stringId
|
|
|
- */
|
|
|
- public void updateTitleText(@StringRes int stringId) {
|
|
|
- titleStringId = stringId;
|
|
|
-
|
|
|
- if (null != textTitle) {
|
|
|
- textTitle.setText(titleStringId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDestroyView() {
|
|
|
- super.onDestroyView();
|
|
|
-
|
|
|
- if (null != disposable) {
|
|
|
- disposable.dispose();
|
|
|
- disposable = null;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Nullable
|
|
|
- @Override
|
|
|
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
|
|
-
|
|
|
- password = "";
|
|
|
-
|
|
|
- getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
|
-
|
|
|
- View view = inflater.inflate(R.layout.password_dialog, container, false);
|
|
|
-
|
|
|
- buttonShuffle = view.findViewById(R.id.button_shuffle);
|
|
|
- buttonDelete = view.findViewById(R.id.button_delete);
|
|
|
- textGuide = view.findViewById(R.id.text_guide);
|
|
|
- textTitle = view.findViewById(R.id.text_title);
|
|
|
-
|
|
|
- if (R.string.empty_string != guideStringId) {
|
|
|
- textGuide.setText(guideStringId);
|
|
|
- }
|
|
|
-
|
|
|
- if (R.string.empty_string != titleStringId) {
|
|
|
- textTitle.setText(titleStringId);
|
|
|
- }
|
|
|
-
|
|
|
- numberList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
|
|
|
- buttonList = createButtonListFromView(view);
|
|
|
- imageList = createImageListFromView(view);
|
|
|
-
|
|
|
- buttonShuffle.setOnClickListener(v -> shuffleKeyboard());
|
|
|
-
|
|
|
- buttonDelete.setOnClickListener(v -> doSomeAfterClickDeleteButton());
|
|
|
-
|
|
|
- int size = buttonList.size();
|
|
|
- for (int i = 0; i < size; ++i) {
|
|
|
- buttonList.get(i).setOnClickListener(v -> doSomeAfterClickNumberButton(v));
|
|
|
- }
|
|
|
-
|
|
|
- shuffleKeyboard();
|
|
|
-
|
|
|
- return view;
|
|
|
- }
|
|
|
-
|
|
|
- private ArrayList<Button> createButtonListFromView(View view) {
|
|
|
- ArrayList<Button> list = new ArrayList<Button>();
|
|
|
- list.add((Button) view.findViewById(R.id.button_0));
|
|
|
- list.add((Button) view.findViewById(R.id.button_1));
|
|
|
- list.add((Button) view.findViewById(R.id.button_2));
|
|
|
- list.add((Button) view.findViewById(R.id.button_3));
|
|
|
- list.add((Button) view.findViewById(R.id.button_4));
|
|
|
- list.add((Button) view.findViewById(R.id.button_5));
|
|
|
- list.add((Button) view.findViewById(R.id.button_6));
|
|
|
- list.add((Button) view.findViewById(R.id.button_7));
|
|
|
- list.add((Button) view.findViewById(R.id.button_8));
|
|
|
- list.add((Button) view.findViewById(R.id.button_9));
|
|
|
-
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- private ArrayList<ImageView> createImageListFromView(View view) {
|
|
|
- ArrayList<ImageView> list = new ArrayList<ImageView>();
|
|
|
- list.add((ImageView) view.findViewById(R.id.image_pin_code1));
|
|
|
- list.add((ImageView) view.findViewById(R.id.image_pin_code2));
|
|
|
- list.add((ImageView) view.findViewById(R.id.image_pin_code3));
|
|
|
- list.add((ImageView) view.findViewById(R.id.image_pin_code4));
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void shuffleKeyboard() {
|
|
|
-
|
|
|
- Collections.shuffle(numberList);
|
|
|
- int size = buttonList.size();
|
|
|
-
|
|
|
- for (int i = 0; i < size; ++i) {
|
|
|
- buttonList.get(i).setText(String.valueOf(numberList.get(i)));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void doSomeAfterAllPinCode() {
|
|
|
- String pin = password;
|
|
|
- password = "";
|
|
|
- resultListener.onDialogResult(this, new Event.Builder(Event.SUCCESS).string(pin).build());
|
|
|
- }
|
|
|
-
|
|
|
- private void doSomeAfterClickDeleteButton() {
|
|
|
- if (password.length() == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- password = password.substring(0, password.length() - 1);
|
|
|
- updateImageAfterPinInput();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void doSomeAfterClickNumberButton(View view) {
|
|
|
-
|
|
|
- int passwordSize = password.length();
|
|
|
-
|
|
|
- if (passwordSize < 4) {
|
|
|
- password += ((Button) view).getText().toString().charAt(0);
|
|
|
-
|
|
|
- updateImageAfterPinInput();
|
|
|
-
|
|
|
- passwordSize = password.length();
|
|
|
- if (passwordSize == 4) {
|
|
|
- Log.e("APP# PinDialog | onClick", "|" + "if(password.length == 4)");
|
|
|
- doSomeAfterAllPinCode();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void updateImageAfterPinInput() {
|
|
|
- int passwordSize = password.length();
|
|
|
- for (int i = 0; i < imageList.size(); ++i) {
|
|
|
- ImageView imageView = imageList.get(i);
|
|
|
- if (i < passwordSize) {
|
|
|
- imageView.setImageResource(R.drawable.circle_full);
|
|
|
- }
|
|
|
- else {
|
|
|
- imageView.setImageResource(R.drawable.circle_empty);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setEnabled() {
|
|
|
- setEnabled(true);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setDisabled() {
|
|
|
- setEnabled(false);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void restart() {
|
|
|
- shuffleKeyboard();
|
|
|
- updateImageAfterPinInput();
|
|
|
- setEnabled(true);
|
|
|
- }
|
|
|
-
|
|
|
- private void setEnabled(boolean enabled) {
|
|
|
- buttonDelete.setEnabled(enabled);
|
|
|
- buttonShuffle.setEnabled(enabled);
|
|
|
- for (Button button : buttonList) {
|
|
|
- button.setEnabled(enabled);
|
|
|
- }
|
|
|
- for (ImageView imageView : imageList) {
|
|
|
- imageView.setEnabled(enabled);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|