浏览代码

[공통][New] Floating Action Button Manager 추가
- Presenter 에서 정의하고 이벤트도 처리한다.

hyodong.min 7 年之前
父节点
当前提交
374b309627

+ 6 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/activity/MainActivity.java

@@ -10,6 +10,7 @@ import android.util.Log;
 
 import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.manager.ActionBarManager;
+import kr.co.zumo.app.lifeplus.manager.ActionButtonManager;
 import kr.co.zumo.app.lifeplus.supervisor.DialogHelper;
 import kr.co.zumo.app.lifeplus.supervisor.FragmentChanger;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenChanger;
@@ -48,6 +49,9 @@ public class MainActivity extends AppCompatActivity {
     setSupportActionBar(findViewById(R.id.toolbar));
     ActionBarManager.getInstance().init(this, this.getSupportActionBar(), findViewById(R.id.layout_app_bar), findViewById(R.id.container_main));
 
+    // floating action button
+    ActionButtonManager.getInstance().init(findViewById(R.id.floating_action_button));
+
     ScreenChangerHelper.getInstance().setAppCompatActivity(this);
     ScreenChangerHelper.getInstance().setContainerId(R.id.container_main);
 
@@ -69,6 +73,7 @@ public class MainActivity extends AppCompatActivity {
     Log.w("APP# MainActivity | onDestroy", "| <<<<<<<<<<<<< " + this.getClass().getSimpleName());
 
     ActionBarManager.getInstance().destroy();
+    ActionButtonManager.getInstance().destroy();
 
     super.onDestroy();
   }
@@ -114,3 +119,4 @@ public class MainActivity extends AppCompatActivity {
 
 }
 
+

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/manager/ActionBarManager.java

@@ -172,7 +172,7 @@ public class ActionBarManager implements IActionBarListener {
   /**
    * 설정 초기화
    *
-   * @return ActionBarManager
+   * @return Builder
    */
   public Builder begin() {
     return new Builder();

+ 162 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/manager/ActionButtonManager.java

@@ -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();
+    }
+  }
+}

+ 22 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/manager/IActionButtonListener.java

@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.manager;
+
+/**
+ * IActionButtonListener
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018. 10. 22.]   [최초 작성]
+ * @since 2018. 10. 22.
+ */
+
+
+import android.support.design.widget.FloatingActionButton;
+
+public interface IActionButtonListener {
+  void onClickFloatingActionButton(FloatingActionButton floatingActionButton);
+}

+ 7 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/presenter/Presenter.java

@@ -10,6 +10,7 @@ import com.google.gson.Gson;
 
 import kr.co.zumo.app.lifeplus.ILifeCycle;
 import kr.co.zumo.app.lifeplus.manager.ActionBarManager;
+import kr.co.zumo.app.lifeplus.manager.ActionButtonManager;
 import kr.co.zumo.app.lifeplus.manager.IActionBarListener;
 import kr.co.zumo.app.lifeplus.model.IModelResult;
 import kr.co.zumo.app.lifeplus.model.Model;
@@ -44,6 +45,12 @@ public abstract class Presenter<M extends Model, V extends IView> implements ILi
     this.model.setListener(this);
     this.model.setPresenter(this);
     ActionBarManager.getInstance().setListener(this);
+
+    defineActionButton();
+  }
+
+  protected void defineActionButton() {
+    ActionButtonManager.getInstance().begin().hide();
   }
 
   @Override
@@ -150,7 +157,6 @@ public abstract class Presenter<M extends Model, V extends IView> implements ILi
   @Override
   public abstract void onResult(Event event);
 
-
   // IActionBarListener
   /*
   기본으로 처리하고 필요한 Presenter 에서 Override 한다.

+ 22 - 0
app/src/main/res/drawable/icon_floating_inqurebtn.xml

@@ -0,0 +1,22 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="44dp"
+        android:height="44dp"
+        android:viewportWidth="174"
+        android:viewportHeight="174">
+  <path
+    android:fillColor="#000"
+    android:fillType="evenOdd"
+    android:pathData="M87,0L87,0A87,87 0,0 1,174 87L174,87A87,87 0,0 1,87 174L87,174A87,87 0,0 1,0 87L0,87A87,87 0,0 1,87 0z"/>
+  <path
+    android:fillColor="#00000000"
+    android:fillType="nonZero"
+    android:pathData="M109.953,54.205l11.313,11.314 -46.304,46.304 -15.82,4.709 4.506,-16.022z"
+    android:strokeWidth="4"
+    android:strokeColor="#FFF"
+    android:strokeLineCap="round"
+    android:strokeLineJoin="round"/>
+  <path
+    android:fillColor="#FFF"
+    android:fillType="nonZero"
+    android:pathData="M104.449,61.262l10.606,10.607 -2.828,2.828 -10.607,-10.606z"/>
+</vector>

+ 17 - 7
app/src/main/res/drawable/icon_floating_plus.xml

@@ -1,8 +1,18 @@
-<vector android:height="44dp" android:viewportHeight="174"
-    android:viewportWidth="174" android:width="44dp" xmlns:android="http://schemas.android.com/apk/res/android">
-    <path android:fillAlpha="0.4" android:fillColor="#000"
-        android:fillType="evenOdd"
-        android:pathData="M87,0L87,0A87,87 0,0 1,174 87L174,87A87,87 0,0 1,87 174L87,174A87,87 0,0 1,0 87L0,87A87,87 0,0 1,87 0z" android:strokeAlpha="0.4"/>
-    <path android:fillColor="#00000000" android:fillType="nonZero"
-        android:pathData="M59,87h56M87,59v56" android:strokeColor="#FFF" android:strokeWidth="4"/>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="44dp"
+        android:height="44dp"
+        android:viewportWidth="174"
+        android:viewportHeight="174">
+  <path
+    android:fillAlpha="0.4"
+    android:fillColor="#000"
+    android:fillType="evenOdd"
+    android:pathData="M87,0L87,0A87,87 0,0 1,174 87L174,87A87,87 0,0 1,87 174L87,174A87,87 0,0 1,0 87L0,87A87,87 0,0 1,87 0z"
+    android:strokeAlpha="0.4"/>
+  <path
+    android:fillColor="#00000000"
+    android:fillType="nonZero"
+    android:pathData="M59,87h56M87,59v56"
+    android:strokeWidth="4"
+    android:strokeColor="#FFF"/>
 </vector>

+ 0 - 9
app/src/main/res/drawable/icon_inqurebtn.xml

@@ -1,9 +0,0 @@
-<vector android:height="43dp" android:viewportHeight="174"
-    android:viewportWidth="174" android:width="43dp" xmlns:android="http://schemas.android.com/apk/res/android">
-    <path android:fillColor="#000" android:fillType="evenOdd" android:pathData="M87,0L87,0A87,87 0,0 1,174 87L174,87A87,87 0,0 1,87 174L87,174A87,87 0,0 1,0 87L0,87A87,87 0,0 1,87 0z"/>
-    <path android:fillColor="#00000000" android:fillType="nonZero"
-        android:pathData="M109.953,54.205l11.313,11.314 -46.304,46.304 -15.82,4.709 4.506,-16.022z"
-        android:strokeColor="#FFF" android:strokeLineCap="round"
-        android:strokeLineJoin="round" android:strokeWidth="4"/>
-    <path android:fillColor="#FFF" android:fillType="nonZero" android:pathData="M104.449,61.262l10.606,10.607 -2.828,2.828 -10.607,-10.606z"/>
-</vector>

+ 1 - 1
app/src/main/res/layout/activity_faq.xml

@@ -37,7 +37,7 @@
     android:layout_gravity="bottom|end"
     android:layout_marginBottom="22dp"
     android:layout_marginEnd="22dp"
-    app:srcCompat="@drawable/icon_inqurebtn"
+    app:srcCompat="@drawable/icon_floating_inqurebtn"
     android:scaleType="center"
     />
 

+ 12 - 7
app/src/main/res/layout/activity_main.xml

@@ -55,12 +55,17 @@
     </RelativeLayout>
   </android.support.design.widget.AppBarLayout>
 
-  <!--<android.support.design.widget.FloatingActionButton-->
-  <!--android:id="@+id/fab"-->
-  <!--android:layout_width="wrap_content"-->
-  <!--android:layout_height="wrap_content"-->
-  <!--android:layout_gravity="bottom|end"-->
-  <!--android:layout_margin="@dimen/fab_margin"-->
-  <!--android:src="@android:drawable/ic_dialog_info"/>-->
+  <android.support.design.widget.FloatingActionButton
+    android:id="@+id/floating_action_button"
+    android:layout_width="44dp"
+    android:layout_height="44dp"
+    android:layout_gravity="bottom|end"
+    android:layout_margin="@dimen/fab_margin"
+    android:background="@null"
+    android:elevation="0dp"
+    android:scaleType="center"
+    app:elevation="0dp"
+    tools:srcCompat="@drawable/icon_floating_inqurebtn"
+    />
 
 </android.support.design.widget.CoordinatorLayout>

+ 14 - 14
app/src/main/res/layout/fragment_faq.xml

@@ -10,15 +10,15 @@
   android:orientation="vertical">
 
   <android.support.design.widget.TabLayout
-    android:background="@color/CFFFFFF"
     android:id="@+id/faq_tab_layout"
     android:layout_width="match_parent"
     android:layout_height="55dp"
     android:layout_marginLeft="25dp"
     android:layout_marginRight="25dp"
+    android:background="@color/CFFFFFF"
     app:tabBackground="@drawable/tab_indicator"
-    app:tabIndicatorColor="@color/C000000"
-    app:tabGravity="center"/>
+    app:tabGravity="center"
+    app:tabIndicatorColor="@color/C000000"/>
 
   <RelativeLayout
     android:layout_width="match_parent"
@@ -30,17 +30,17 @@
       android:layout_height="match_parent"/>
 
     <android.support.design.widget.FloatingActionButton
-    android:id="@+id/button_write_faq"
-    android:layout_width="44dp"
-    android:layout_height="44dp"
-    android:layout_alignParentBottom="true"
-    android:layout_alignParentEnd="true"
-    android:layout_gravity="bottom|end"
-    android:layout_marginBottom="22dp"
-    android:layout_marginEnd="22dp"
-    app:srcCompat="@drawable/icon_inqurebtn"
-    android:scaleType="center"
-    />
+      android:id="@+id/button_write_faq"
+      android:layout_width="44dp"
+      android:layout_height="44dp"
+      android:layout_alignParentEnd="true"
+      android:layout_alignParentBottom="true"
+      android:layout_gravity="bottom|end"
+      android:layout_marginEnd="22dp"
+      android:layout_marginBottom="22dp"
+      android:scaleType="center"
+      app:srcCompat="@drawable/icon_floating_inqurebtn"
+      />
 
   </RelativeLayout>