|
@@ -0,0 +1,156 @@
|
|
|
+package com.sunwin.visitorapp.view;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.util.AttributeSet;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import androidx.annotation.ColorRes;
|
|
|
+import androidx.annotation.DrawableRes;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+
|
|
|
+import com.sunwin.visitorapp.R;
|
|
|
+
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * author : FLB
|
|
|
+ * date : 2020/7/30
|
|
|
+ * desc :
|
|
|
+ */
|
|
|
+public class UINav extends RelativeLayout {
|
|
|
+ private static @ColorRes
|
|
|
+ int navViewBackColor = R.color.NavBackgroundColor;
|
|
|
+ private static @ColorRes int navViewTextColor = R.color.NormalTextColorBlack;
|
|
|
+ public static void setNavColor(@ColorRes int rootViewBackColor,@ColorRes int navViewTextColor) {
|
|
|
+ UINav.navViewBackColor = rootViewBackColor;
|
|
|
+ UINav.navViewTextColor = navViewTextColor;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Context context;
|
|
|
+ // View rootView;
|
|
|
+ public UINav(Context context) {
|
|
|
+ this(context,null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public UINav(Context context, @Nullable AttributeSet attrs) {
|
|
|
+ this(context, attrs,0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public UINav(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
+ super(context, attrs, defStyleAttr);
|
|
|
+ initView(context, attrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ View UINavView;
|
|
|
+ TextView UINavTitle;
|
|
|
+ View UINavBack;
|
|
|
+ View UINavExtra;
|
|
|
+ TextView UINavExtraText;
|
|
|
+ ImageView UINavExtraImage;
|
|
|
+
|
|
|
+
|
|
|
+ private void initView(Context context, @Nullable AttributeSet attrs){
|
|
|
+ this.context = context;
|
|
|
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+ View rootView = Objects.requireNonNull(inflater).inflate(R.layout.ui_navigation, this, true);
|
|
|
+ UINavView = rootView.findViewById(R.id.UINavView);
|
|
|
+ UINavView.setBackgroundColor(getResources().getColor(navViewBackColor));
|
|
|
+ UINavTitle = rootView.findViewById(R.id.UINavTitle);
|
|
|
+ UINavTitle.setTextColor(getResources().getColor(navViewTextColor));
|
|
|
+ UINavBack =rootView.findViewById(R.id.UINavBack);
|
|
|
+// UINavBack.setColorFilter(getResources().getColor(navViewTextColor));
|
|
|
+ UINavExtra =rootView.findViewById(R.id.UINavExtra);
|
|
|
+ UINavExtraText =rootView.findViewById(R.id.UINavExtraText);
|
|
|
+ UINavExtraText.setTextColor(getResources().getColor(navViewTextColor));
|
|
|
+ UINavExtraImage =rootView.findViewById(R.id.UINavExtraImage);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ public static final String ExtraNone = "ExtraNone";
|
|
|
+ public static final String ExtraTextType = "ExtraTextType";
|
|
|
+ public static final String ExtraImgType = "ExtraImgType";
|
|
|
+
|
|
|
+ public void setMainData(OnClickListener backListener, String title){
|
|
|
+ setBack(backListener!=null,backListener);
|
|
|
+ UINavTitle.setText(title);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTitle(String title){
|
|
|
+ UINavTitle.setText(title);
|
|
|
+ }
|
|
|
+ public void setData(Activity activity,String title){
|
|
|
+ setMainData(v-> activity.finish(),title);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBack(OnClickListener listener){
|
|
|
+ UINavBack.setOnClickListener(listener);
|
|
|
+ }
|
|
|
+ public void setBack(boolean show, OnClickListener listener){
|
|
|
+ UINavBack.setVisibility(show?VISIBLE:GONE);
|
|
|
+ UINavBack.setOnClickListener(listener);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("UseCompatLoadingForDrawables")
|
|
|
+ public void setData(boolean showBack, OnClickListener listener, String title, String extraType, String extraTextZ, @DrawableRes int extraImageZ, OnClickListener extraListener){
|
|
|
+ UINavTitle.setText(title);
|
|
|
+ UINavBack.setVisibility(showBack?VISIBLE:GONE);
|
|
|
+ UINavBack.setOnClickListener(listener);
|
|
|
+ switch (extraType){
|
|
|
+ case ExtraNone:
|
|
|
+ UINavExtra.setVisibility(View.GONE);
|
|
|
+ break;
|
|
|
+ case ExtraTextType:{
|
|
|
+ UINavExtra.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraText.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraText.setText(extraTextZ);
|
|
|
+ UINavExtraImage.setVisibility(View.GONE);
|
|
|
+ UINavExtra.setOnClickListener(extraListener);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case ExtraImgType:{
|
|
|
+ UINavExtra.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraImage.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraImage.setImageDrawable(context.getResources().getDrawable(extraImageZ));
|
|
|
+ UINavExtraText.setVisibility(View.GONE);
|
|
|
+ UINavExtra.setOnClickListener(extraListener);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setExtraText(String extraTextZ, OnClickListener extraListener){
|
|
|
+ UINavExtra.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraText.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraText.setText(extraTextZ);
|
|
|
+ UINavExtraImage.setVisibility(View.GONE);
|
|
|
+ UINavExtra.setOnClickListener(extraListener);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setExtraText(String extraTextZ){
|
|
|
+ UINavExtraText.setText(extraTextZ);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public TextView getExtraText() {
|
|
|
+ return UINavExtraText;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("UseCompatLoadingForDrawables")
|
|
|
+ public void setExtraImage(@DrawableRes int extraImageZ, OnClickListener extraListener){
|
|
|
+ UINavExtra.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraImage.setVisibility(View.VISIBLE);
|
|
|
+ UINavExtraImage.setImageDrawable(context.getResources().getDrawable(extraImageZ));
|
|
|
+ UINavExtraText.setVisibility(View.GONE);
|
|
|
+ UINavExtra.setOnClickListener(extraListener);
|
|
|
+ }
|
|
|
+}
|