|
|
@ -2,6 +2,7 @@ package com.common.commonlib.view;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
@ -16,9 +17,9 @@ import com.common.commonlib.utils.DisplayUtils;
|
|
|
|
|
|
|
|
|
|
|
|
public class CommonTitleView extends FrameLayout implements View.OnClickListener {
|
|
|
|
public class CommonTitleView extends FrameLayout implements View.OnClickListener {
|
|
|
|
private Context mContext;
|
|
|
|
private Context mContext;
|
|
|
|
private ImageView ivBack;
|
|
|
|
private ImageView ivLeft;
|
|
|
|
private TextView tv_title;
|
|
|
|
private TextView tv_title;
|
|
|
|
private ImageView ivAdd;
|
|
|
|
private ImageView ivRight;
|
|
|
|
private TextView tv_edit;
|
|
|
|
private TextView tv_edit;
|
|
|
|
private int showStyle;
|
|
|
|
private int showStyle;
|
|
|
|
|
|
|
|
|
|
|
@ -36,9 +37,12 @@ public class CommonTitleView extends FrameLayout implements View.OnClickListener
|
|
|
|
private int fixedHeight;
|
|
|
|
private int fixedHeight;
|
|
|
|
|
|
|
|
|
|
|
|
private static final int DEFAULT_HEIGHT = 48;
|
|
|
|
private static final int DEFAULT_HEIGHT = 48;
|
|
|
|
private View rlBackHotZone;
|
|
|
|
private View rlLeftHotZone;
|
|
|
|
private View rlAddHotZone;
|
|
|
|
private View rlRightHotZone;
|
|
|
|
private View rlEditZone;
|
|
|
|
private View rlEditZone;
|
|
|
|
|
|
|
|
private Drawable leftDrawable;
|
|
|
|
|
|
|
|
private Drawable rightDrawable;
|
|
|
|
|
|
|
|
private int bgColor;
|
|
|
|
|
|
|
|
|
|
|
|
public CommonTitleView(Context context) {
|
|
|
|
public CommonTitleView(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
this(context, null);
|
|
|
@ -56,18 +60,42 @@ public class CommonTitleView extends FrameLayout implements View.OnClickListener
|
|
|
|
|
|
|
|
|
|
|
|
private void init(AttributeSet attrs) {
|
|
|
|
private void init(AttributeSet attrs) {
|
|
|
|
initAttrs(attrs);
|
|
|
|
initAttrs(attrs);
|
|
|
|
LayoutInflater.from(mContext).inflate(R.layout.common_title_view, this, true);
|
|
|
|
View inflate = LayoutInflater.from(mContext).inflate(R.layout.common_title_view, this, true);
|
|
|
|
ivBack = findViewById(R.id.iv_back);
|
|
|
|
View root_view = findViewById(R.id.root_view);
|
|
|
|
ivAdd = findViewById(R.id.iv_add);
|
|
|
|
ivLeft = findViewById(R.id.iv_left);
|
|
|
|
|
|
|
|
ivRight = findViewById(R.id.iv_right);
|
|
|
|
tv_title = findViewById(R.id.tv_title);
|
|
|
|
tv_title = findViewById(R.id.tv_title);
|
|
|
|
rlBackHotZone = findViewById(R.id.rl_back_hot_zone);
|
|
|
|
rlLeftHotZone = findViewById(R.id.rl_left_hot_zone);
|
|
|
|
rlAddHotZone = findViewById(R.id.rl_add_hot_zone);
|
|
|
|
rlRightHotZone = findViewById(R.id.rl_add_hot_zone);
|
|
|
|
tv_edit = findViewById(R.id.tv_edit);
|
|
|
|
tv_edit = findViewById(R.id.tv_edit);
|
|
|
|
rlEditZone = findViewById(R.id.rl_edit_hot_zone);
|
|
|
|
rlEditZone = findViewById(R.id.rl_edit_hot_zone);
|
|
|
|
|
|
|
|
root_view.setBackgroundColor(bgColor);
|
|
|
|
|
|
|
|
if (leftDrawable != null) {
|
|
|
|
|
|
|
|
ivLeft.setImageDrawable(leftDrawable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rightDrawable != null) {
|
|
|
|
|
|
|
|
ivRight.setImageDrawable(rightDrawable);
|
|
|
|
|
|
|
|
}
|
|
|
|
initStyle();
|
|
|
|
initStyle();
|
|
|
|
setTitle(title);
|
|
|
|
setTitle(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initAttrs(AttributeSet attrs) {
|
|
|
|
|
|
|
|
TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.CommonTitleView);
|
|
|
|
|
|
|
|
showStyle = typedArray.getInt(R.styleable.CommonTitleView_show_style, STYLE_MIDDLE);
|
|
|
|
|
|
|
|
title = typedArray.getString(R.styleable.CommonTitleView_title);
|
|
|
|
|
|
|
|
isFixedHeight = typedArray.getBoolean(R.styleable.CommonTitleView_is_fixed_height, true);
|
|
|
|
|
|
|
|
fixedHeight = typedArray.getInteger(R.styleable.CommonTitleView_fixed_height, DisplayUtils.INSTANCE.dp2px(mContext, DEFAULT_HEIGHT));
|
|
|
|
|
|
|
|
leftDrawable = typedArray.getDrawable(R.styleable.CommonTitleView_drawableLeft);
|
|
|
|
|
|
|
|
rightDrawable = typedArray.getDrawable(R.styleable.CommonTitleView_drawableRight);
|
|
|
|
|
|
|
|
bgColor = typedArray.getColor(R.styleable.CommonTitleView_bgColor, getResources().getColor(R.color.title_bar_bg_color));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedArray.recycle();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
if (isFixedHeight) {
|
|
|
|
if (isFixedHeight) {
|
|
|
@ -81,80 +109,69 @@ public class CommonTitleView extends FrameLayout implements View.OnClickListener
|
|
|
|
private void initStyle() {
|
|
|
|
private void initStyle() {
|
|
|
|
switch (showStyle) {
|
|
|
|
switch (showStyle) {
|
|
|
|
case STYLE_LEFT:
|
|
|
|
case STYLE_LEFT:
|
|
|
|
ivBack.setVisibility(VISIBLE);
|
|
|
|
ivLeft.setVisibility(VISIBLE);
|
|
|
|
rlBackHotZone.setOnClickListener(this);
|
|
|
|
rlLeftHotZone.setOnClickListener(this);
|
|
|
|
tv_title.setVisibility(INVISIBLE);
|
|
|
|
tv_title.setVisibility(INVISIBLE);
|
|
|
|
tv_title.setText("");
|
|
|
|
tv_title.setText("");
|
|
|
|
ivAdd.setVisibility(INVISIBLE);
|
|
|
|
ivRight.setVisibility(INVISIBLE);
|
|
|
|
rlAddHotZone.setOnClickListener(null);
|
|
|
|
rlRightHotZone.setOnClickListener(null);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case STYLE_LEFT_MIDDLE:
|
|
|
|
case STYLE_LEFT_MIDDLE:
|
|
|
|
ivBack.setVisibility(VISIBLE);
|
|
|
|
ivLeft.setVisibility(VISIBLE);
|
|
|
|
rlBackHotZone.setOnClickListener(this);
|
|
|
|
rlLeftHotZone.setOnClickListener(this);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setText("");
|
|
|
|
tv_title.setText("");
|
|
|
|
ivAdd.setVisibility(INVISIBLE);
|
|
|
|
ivRight.setVisibility(INVISIBLE);
|
|
|
|
rlAddHotZone.setOnClickListener(null);
|
|
|
|
rlRightHotZone.setOnClickListener(null);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case STYLE_MIDDLE_RIGHT:
|
|
|
|
case STYLE_MIDDLE_RIGHT:
|
|
|
|
ivBack.setVisibility(INVISIBLE);
|
|
|
|
ivLeft.setVisibility(INVISIBLE);
|
|
|
|
rlBackHotZone.setOnClickListener(null);
|
|
|
|
rlLeftHotZone.setOnClickListener(null);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setText("");
|
|
|
|
tv_title.setText("");
|
|
|
|
ivAdd.setVisibility(VISIBLE);
|
|
|
|
ivRight.setVisibility(VISIBLE);
|
|
|
|
rlAddHotZone.setOnClickListener(this);
|
|
|
|
rlRightHotZone.setOnClickListener(this);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case STYLE_RIGHT:
|
|
|
|
case STYLE_RIGHT:
|
|
|
|
ivBack.setVisibility(INVISIBLE);
|
|
|
|
ivLeft.setVisibility(INVISIBLE);
|
|
|
|
rlBackHotZone.setOnClickListener(null);
|
|
|
|
rlLeftHotZone.setOnClickListener(null);
|
|
|
|
tv_title.setVisibility(INVISIBLE);
|
|
|
|
tv_title.setVisibility(INVISIBLE);
|
|
|
|
tv_title.setText("");
|
|
|
|
tv_title.setText("");
|
|
|
|
ivAdd.setVisibility(VISIBLE);
|
|
|
|
ivRight.setVisibility(VISIBLE);
|
|
|
|
rlAddHotZone.setOnClickListener(this);
|
|
|
|
rlRightHotZone.setOnClickListener(this);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case STYLE_LEFT_MIDDLE_RIGHT:
|
|
|
|
case STYLE_LEFT_MIDDLE_RIGHT:
|
|
|
|
ivBack.setVisibility(VISIBLE);
|
|
|
|
ivLeft.setVisibility(VISIBLE);
|
|
|
|
rlBackHotZone.setOnClickListener(this);
|
|
|
|
rlLeftHotZone.setOnClickListener(this);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setText("");
|
|
|
|
tv_title.setText("");
|
|
|
|
ivAdd.setVisibility(VISIBLE);
|
|
|
|
ivRight.setVisibility(VISIBLE);
|
|
|
|
rlAddHotZone.setOnClickListener(this);
|
|
|
|
rlRightHotZone.setOnClickListener(this);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case STYLE_EDIT:
|
|
|
|
case STYLE_EDIT:
|
|
|
|
ivBack.setVisibility(VISIBLE);
|
|
|
|
ivLeft.setVisibility(VISIBLE);
|
|
|
|
rlBackHotZone.setOnClickListener(this);
|
|
|
|
rlLeftHotZone.setOnClickListener(this);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setText("");
|
|
|
|
tv_title.setText("");
|
|
|
|
ivAdd.setVisibility(GONE);
|
|
|
|
ivRight.setVisibility(GONE);
|
|
|
|
rlAddHotZone.setVisibility(GONE);
|
|
|
|
rlRightHotZone.setVisibility(GONE);
|
|
|
|
rlAddHotZone.setOnClickListener(null);
|
|
|
|
rlRightHotZone.setOnClickListener(null);
|
|
|
|
tv_edit.setVisibility(VISIBLE);
|
|
|
|
tv_edit.setVisibility(VISIBLE);
|
|
|
|
rlEditZone.setVisibility(VISIBLE);
|
|
|
|
rlEditZone.setVisibility(VISIBLE);
|
|
|
|
rlEditZone.setOnClickListener(this);
|
|
|
|
rlEditZone.setOnClickListener(this);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case STYLE_MIDDLE:
|
|
|
|
case STYLE_MIDDLE:
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
ivBack.setVisibility(INVISIBLE);
|
|
|
|
ivLeft.setVisibility(INVISIBLE);
|
|
|
|
rlBackHotZone.setOnClickListener(null);
|
|
|
|
rlLeftHotZone.setOnClickListener(null);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setVisibility(VISIBLE);
|
|
|
|
tv_title.setText("");
|
|
|
|
tv_title.setText("");
|
|
|
|
ivAdd.setVisibility(INVISIBLE);
|
|
|
|
ivRight.setVisibility(INVISIBLE);
|
|
|
|
rlAddHotZone.setOnClickListener(null);
|
|
|
|
rlRightHotZone.setOnClickListener(null);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initAttrs(AttributeSet attrs) {
|
|
|
|
|
|
|
|
TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.CommonTitleView);
|
|
|
|
|
|
|
|
showStyle = typedArray.getInt(R.styleable.CommonTitleView_show_style, STYLE_MIDDLE);
|
|
|
|
|
|
|
|
title = typedArray.getString(R.styleable.CommonTitleView_title);
|
|
|
|
|
|
|
|
isFixedHeight = typedArray.getBoolean(R.styleable.CommonTitleView_is_fixed_height, true);
|
|
|
|
|
|
|
|
fixedHeight = typedArray.getInteger(R.styleable.CommonTitleView_fixed_height, DisplayUtils.INSTANCE.dp2px(mContext, DEFAULT_HEIGHT));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedArray.recycle();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setTitle(String title) {
|
|
|
|
public void setTitle(String title) {
|
|
|
|
this.title = title;
|
|
|
|
this.title = title;
|
|
|
|
tv_title.setText(title);
|
|
|
|
tv_title.setText(title);
|
|
|
@ -164,15 +181,13 @@ public class CommonTitleView extends FrameLayout implements View.OnClickListener
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
int viewId = v.getId();
|
|
|
|
int viewId = v.getId();
|
|
|
|
if (viewId == R.id.rl_back_hot_zone) {
|
|
|
|
if (viewId == R.id.rl_left_hot_zone) {
|
|
|
|
if (backButtonListener != null) {
|
|
|
|
if (leftIconListener != null) {
|
|
|
|
backButtonListener.onClick();
|
|
|
|
leftIconListener.onClick();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Navigation.findNavController(this).navigateUp();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (viewId == R.id.rl_add_hot_zone) {
|
|
|
|
} else if (viewId == R.id.rl_add_hot_zone) {
|
|
|
|
if (addListener != null) {
|
|
|
|
if (rightIconListener != null) {
|
|
|
|
addListener.onClick();
|
|
|
|
rightIconListener.onClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (viewId == R.id.rl_edit_hot_zone) {
|
|
|
|
} else if (viewId == R.id.rl_edit_hot_zone) {
|
|
|
|
if (editListener != null) {
|
|
|
|
if (editListener != null) {
|
|
|
@ -181,24 +196,24 @@ public class CommonTitleView extends FrameLayout implements View.OnClickListener
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface BackButtonListener {
|
|
|
|
public interface LeftIconListener {
|
|
|
|
void onClick();
|
|
|
|
void onClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private BackButtonListener backButtonListener;
|
|
|
|
private LeftIconListener leftIconListener;
|
|
|
|
|
|
|
|
|
|
|
|
public void setBackButtonListener(BackButtonListener backButtonListener) {
|
|
|
|
public void setLeftIconListener(LeftIconListener leftIconListener) {
|
|
|
|
this.backButtonListener = backButtonListener;
|
|
|
|
this.leftIconListener = leftIconListener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface AddListener {
|
|
|
|
public interface RightIconListener {
|
|
|
|
void onClick();
|
|
|
|
void onClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private AddListener addListener;
|
|
|
|
private RightIconListener rightIconListener;
|
|
|
|
|
|
|
|
|
|
|
|
public void setAddListener(AddListener addListener) {
|
|
|
|
public void setRightIconListener(RightIconListener rightIconListener) {
|
|
|
|
this.addListener = addListener;
|
|
|
|
this.rightIconListener = rightIconListener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface EditListener {
|
|
|
|
public interface EditListener {
|
|
|
|