|
@@ -0,0 +1,93 @@
|
|
|
+/**
|
|
|
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
|
|
|
+ * <p>
|
|
|
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
|
|
|
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
|
|
|
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
|
|
|
+ * This notice may not be removed from this file.
|
|
|
+ */
|
|
|
+
|
|
|
+package com.compdfkit.tools.utils.view;
|
|
|
+
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.content.res.TypedArray;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.AttributeSet;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.appcompat.content.res.AppCompatResources;
|
|
|
+import androidx.appcompat.widget.AppCompatImageView;
|
|
|
+import androidx.appcompat.widget.AppCompatTextView;
|
|
|
+
|
|
|
+import com.compdfkit.tools.R;
|
|
|
+
|
|
|
+public class CToolBar extends FrameLayout {
|
|
|
+
|
|
|
+ private AppCompatTextView tvToolBarTitle;
|
|
|
+ private AppCompatImageView ivToolBarBackBtn;
|
|
|
+
|
|
|
+ public CToolBar(@NonNull Context context) {
|
|
|
+ super(context);
|
|
|
+ initToolBar(context, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CToolBar(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
|
+ super(context, attrs);
|
|
|
+ initToolBar(context, attrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CToolBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
+ super(context, attrs, defStyleAttr);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initToolBar(Context context, @Nullable AttributeSet attrs) {
|
|
|
+ LayoutInflater.from(getContext()).inflate(R.layout.tools_ctool_bar, this);
|
|
|
+ setBackgroundColor(Color.WHITE);
|
|
|
+ setElevation(8);
|
|
|
+ tvToolBarTitle = findViewById(R.id.tv_tool_bar_title);
|
|
|
+ ivToolBarBackBtn = findViewById(R.id.iv_tool_bar_back);
|
|
|
+ initAttributes(context, attrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initAttributes(Context context, @Nullable AttributeSet attrs) {
|
|
|
+ TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Tools_CToolBar);
|
|
|
+ if (typedArray != null) {
|
|
|
+ String toolBarTitle = typedArray.getString(R.styleable.Tools_CToolBar_tools_toolbar_title);
|
|
|
+ if (!TextUtils.isEmpty(toolBarTitle)) {
|
|
|
+ tvToolBarTitle.setText(toolBarTitle);
|
|
|
+ }
|
|
|
+ Drawable backIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CToolBar_tools_toolbar_back_icon, R.drawable.tools_ic_back);
|
|
|
+ if (backIconDrawable != null) {
|
|
|
+ ivToolBarBackBtn.setImageDrawable(backIconDrawable);
|
|
|
+ }
|
|
|
+ typedArray.recycle();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Drawable loadImageFromAttributes(TypedArray typedArray, int index, int defValue){
|
|
|
+ Drawable drawable = null;
|
|
|
+ try {
|
|
|
+ int resId = typedArray.getResourceId(index, defValue);
|
|
|
+ if (resId != -1){
|
|
|
+ drawable = AppCompatResources.getDrawable(getContext(), resId);
|
|
|
+ }
|
|
|
+ return drawable;
|
|
|
+ }catch (Exception e){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setBackBtnClickListener(OnClickListener clickListener){
|
|
|
+ ivToolBarBackBtn.setOnClickListener(clickListener);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|