|
|
@@ -0,0 +1,162 @@
|
|
|
+/*
|
|
|
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
|
|
|
+ */
|
|
|
+package kr.co.zumo.app.lifeplus.manager;
|
|
|
+
|
|
|
+import android.support.annotation.DrawableRes;
|
|
|
+import android.support.design.widget.FloatingActionButton;
|
|
|
+import android.view.View;
|
|
|
+
|
|
|
+import kr.co.zumo.app.R;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ActionButtonManager
|
|
|
+ * <pre>
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @author 민효동
|
|
|
+ * @version 1.0
|
|
|
+ * @history 민효동 [2018. 10. 22.] [최초 작성]
|
|
|
+ * @since 2018. 10. 22.
|
|
|
+ */
|
|
|
+public class ActionButtonManager {
|
|
|
+ private static ActionButtonManager ourInstance = new ActionButtonManager();
|
|
|
+
|
|
|
+ public static ActionButtonManager getInstance() {
|
|
|
+ return ourInstance;
|
|
|
+ }
|
|
|
+
|
|
|
+ private FloatingActionButton floatingActionButton;
|
|
|
+
|
|
|
+ private Builder builder;
|
|
|
+
|
|
|
+ private IActionButtonListener listener;
|
|
|
+
|
|
|
+ private View.OnClickListener onClickListener = new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (null != listener) {
|
|
|
+ listener.onClickFloatingActionButton(floatingActionButton);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private ActionButtonManager() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void init(FloatingActionButton floatingActionButton) {
|
|
|
+ this.floatingActionButton = floatingActionButton;
|
|
|
+ this.floatingActionButton.setOnClickListener(onClickListener);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void show() {
|
|
|
+ floatingActionButton.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void hide() {
|
|
|
+ floatingActionButton.hide();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 설정 초기화
|
|
|
+ *
|
|
|
+ * @return Builder
|
|
|
+ */
|
|
|
+ public Builder begin() {
|
|
|
+ return new Builder();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void set(Builder newBuilder) {
|
|
|
+ if (null == builder) {
|
|
|
+ builder = new Builder();
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (newBuilder.type) {
|
|
|
+ case Builder.TYPE_PENCIL:
|
|
|
+ replaceIcon(R.drawable.icon_floating_inqurebtn);
|
|
|
+ break;
|
|
|
+ case Builder.TYPE_PLUS:
|
|
|
+ replaceIcon(R.drawable.icon_floating_plus);
|
|
|
+ break;
|
|
|
+ case Builder.TYPE_TRASH:
|
|
|
+ break;
|
|
|
+ case Builder.TYPE_NONE:
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.listener = newBuilder.listener;
|
|
|
+
|
|
|
+ builder = newBuilder;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void replaceIcon(@DrawableRes int icon) {
|
|
|
+ floatingActionButton.setImageResource(icon);
|
|
|
+ }
|
|
|
+
|
|
|
+ /***********************************
|
|
|
+ * life-cycle
|
|
|
+ ***********************************/
|
|
|
+
|
|
|
+ public void destroy() {
|
|
|
+ floatingActionButton.setOnClickListener(null);
|
|
|
+ floatingActionButton = null;
|
|
|
+ listener = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /***********************************
|
|
|
+ * Builder
|
|
|
+ ***********************************/
|
|
|
+ public static class Builder {
|
|
|
+ private static final int TYPE_NONE = -1;
|
|
|
+ private static final int TYPE_PENCIL = 0;
|
|
|
+ private static final int TYPE_PLUS = 1;
|
|
|
+ private static final int TYPE_TRASH = 2;
|
|
|
+
|
|
|
+ private int type = TYPE_NONE;
|
|
|
+
|
|
|
+ private IActionButtonListener listener = null;
|
|
|
+
|
|
|
+ public Builder() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder pencil(IActionButtonListener listener) {
|
|
|
+ type = TYPE_PENCIL;
|
|
|
+ this.listener = listener;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder plus(IActionButtonListener listener) {
|
|
|
+ type = TYPE_PLUS;
|
|
|
+ this.listener = listener;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder trash(IActionButtonListener listener) {
|
|
|
+ type = TYPE_TRASH;
|
|
|
+ this.listener = listener;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void set() {
|
|
|
+ ourInstance.set(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * show
|
|
|
+ */
|
|
|
+ public void show() {
|
|
|
+ set();
|
|
|
+ ourInstance.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * hide
|
|
|
+ */
|
|
|
+ public void hide() {
|
|
|
+ set();
|
|
|
+ ourInstance.hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|