|
@@ -7,37 +7,69 @@
|
|
|
* This notice may not be removed from this file.
|
|
|
*/
|
|
|
|
|
|
-package com.compdfkit.tools.pdfview;
|
|
|
+package com.compdfkit.tools.pdfview.view;
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
-import android.content.res.ColorStateList;
|
|
|
import android.content.res.TypedArray;
|
|
|
-import android.graphics.Color;
|
|
|
-import android.graphics.drawable.ColorDrawable;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.AttributeSet;
|
|
|
-import android.util.TypedValue;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
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 androidx.core.view.ViewCompat;
|
|
|
|
|
|
import com.compdfkit.tools.R;
|
|
|
-import com.google.android.material.shape.MaterialShapeDrawable;
|
|
|
+import com.compdfkit.tools.utils.viewutils.ViewUtils;
|
|
|
|
|
|
+
|
|
|
+/**
|
|
|
+ * pdf ui tool bar
|
|
|
+ * ︳------------------------------------------------︳
|
|
|
+ * ︳ title icon1 icon2 icon3 ︳
|
|
|
+ * ︳------------------------------------------------︳
|
|
|
+ * icon1: searchIcon
|
|
|
+ * icon2: boTaIcon
|
|
|
+ * icon3: moreIcon
|
|
|
+ *
|
|
|
+ * use samples:
|
|
|
+ * <com.compdfkit.tools.pdfview.view.CPDFToolBar
|
|
|
+ * android:id="@+id/pdf_tool_bar"
|
|
|
+ * android:layout_width="match_parent"
|
|
|
+ * android:layout_height="?android:attr/actionBarSize"
|
|
|
+ * app:tools_toolbar_title="@string/viewer_toolbar_title"
|
|
|
+ * app:tools_toolbar_bota_icon="@drawable/xxx"
|
|
|
+ * app:tools_toolbar_more_icon="@drawable/xxx"
|
|
|
+ * app:tools_toolbar_search_icon="@drawable/xxx"/>
|
|
|
+ *
|
|
|
+ * custom attrs:
|
|
|
+ * app:tools_toolbar_title="@string/xxx"
|
|
|
+ * app:tools_toolbar_search_icon="@drawable/xxx"
|
|
|
+ * app:tools_toolbar_bota_icon="@drawable/xxx"
|
|
|
+ * app:tools_toolbar_more_icon="@drawable/xxx"
|
|
|
+ *
|
|
|
+ * btn click listener
|
|
|
+ * searchBtnClick:
|
|
|
+ * @see CPDFToolBar#setSearchBtnClickListener(OnClickListener)
|
|
|
+ *
|
|
|
+ * botaBtnClick:
|
|
|
+ * @see CPDFToolBar#setBoTaBtnClickListener(OnClickListener)
|
|
|
+ *
|
|
|
+ * moreBtnClick:
|
|
|
+ * @see CPDFToolBar#setMoreBtnClickListener(OnClickListener)
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
public class CPDFToolBar extends FrameLayout {
|
|
|
|
|
|
private AppCompatTextView tvToolBarTitle;
|
|
|
private AppCompatImageView ivToolBarSearchBtn;
|
|
|
- private AppCompatImageView ivToolBarOutlineBtn;
|
|
|
+ private AppCompatImageView ivToolBarBoTaBtn;
|
|
|
private AppCompatImageView ivToolBarMoreBtn;
|
|
|
|
|
|
public CPDFToolBar(@NonNull Context context) {
|
|
@@ -50,8 +82,6 @@ public class CPDFToolBar extends FrameLayout {
|
|
|
|
|
|
public CPDFToolBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
-
|
|
|
-
|
|
|
initToolBar(context, attrs);
|
|
|
|
|
|
}
|
|
@@ -61,70 +91,45 @@ public class CPDFToolBar extends FrameLayout {
|
|
|
tvToolBarTitle = findViewById(R.id.tv_tool_bar_title);
|
|
|
ivToolBarMoreBtn = findViewById(R.id.iv_tool_bar_more);
|
|
|
ivToolBarSearchBtn = findViewById(R.id.iv_tool_bar_search);
|
|
|
- ivToolBarOutlineBtn = findViewById(R.id.iv_tool_bar_outline);
|
|
|
+ ivToolBarBoTaBtn = findViewById(R.id.iv_tool_bar_bota);
|
|
|
initAttributes(context, attrs);
|
|
|
}
|
|
|
|
|
|
private void initAttributes(Context context, @Nullable AttributeSet attrs) {
|
|
|
- TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Tools_CPDFToolBar);
|
|
|
+ TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CPDFToolBar);
|
|
|
if (typedArray != null) {
|
|
|
- String toolBarTitle = typedArray.getString(R.styleable.Tools_CPDFToolBar_tools_toolbar_title);
|
|
|
- typedArray.getResourceId(R.styleable.Tools_CPDFToolBar_tools_toolbar_search_icon, -1);
|
|
|
+ String toolBarTitle = typedArray.getString(R.styleable.CPDFToolBar_tools_toolbar_title);
|
|
|
+ typedArray.getResourceId(R.styleable.CPDFToolBar_tools_toolbar_search_icon, -1);
|
|
|
if (!TextUtils.isEmpty(toolBarTitle)) {
|
|
|
tvToolBarTitle.setText(toolBarTitle);
|
|
|
}
|
|
|
- Drawable searchIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CPDFToolBar_tools_toolbar_search_icon, R.drawable.tools_ic_search);
|
|
|
+ Drawable searchIconDrawable = ViewUtils.loadDrawableFromAttributes(getContext(), typedArray, R.styleable.CPDFToolBar_tools_toolbar_search_icon, R.drawable.tools_ic_search);
|
|
|
if (searchIconDrawable != null) {
|
|
|
ivToolBarSearchBtn.setImageDrawable(searchIconDrawable);
|
|
|
}
|
|
|
- Drawable outlineIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CPDFToolBar_tools_toolbar_outline_icon, R.drawable.tools_ic_outline);
|
|
|
- if (outlineIconDrawable != null) {
|
|
|
- ivToolBarOutlineBtn.setImageDrawable(outlineIconDrawable);
|
|
|
+ Drawable boTaIconDrawable = ViewUtils.loadDrawableFromAttributes(getContext(), typedArray, R.styleable.CPDFToolBar_tools_toolbar_bota_icon, R.drawable.tools_ic_outline);
|
|
|
+ if (boTaIconDrawable != null) {
|
|
|
+ ivToolBarBoTaBtn.setImageDrawable(boTaIconDrawable);
|
|
|
}
|
|
|
- Drawable moreIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CPDFToolBar_tools_toolbar_more_icon, R.drawable.tools_ic_more);
|
|
|
+ Drawable moreIconDrawable = ViewUtils.loadDrawableFromAttributes(getContext(), typedArray, R.styleable.CPDFToolBar_tools_toolbar_more_icon, R.drawable.tools_ic_more);
|
|
|
if (moreIconDrawable != null) {
|
|
|
ivToolBarMoreBtn.setImageDrawable(moreIconDrawable);
|
|
|
}
|
|
|
|
|
|
- int color;
|
|
|
- if (getBackground() != null && getBackground() instanceof ColorDrawable) {
|
|
|
- ColorDrawable colorDrawable = (ColorDrawable) getBackground();
|
|
|
- color = colorDrawable.getColor();
|
|
|
- } else {
|
|
|
- TypedValue typedValue = new TypedValue();
|
|
|
- getContext().getTheme().resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValue, true);
|
|
|
- color = typedValue.data;
|
|
|
- }
|
|
|
- MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
|
|
|
- materialShapeDrawable.setFillColor(ColorStateList.valueOf(color));
|
|
|
- materialShapeDrawable.initializeElevationOverlay(context);
|
|
|
- materialShapeDrawable.setElevation(ViewCompat.getElevation(this));
|
|
|
- ViewCompat.setBackground(this, materialShapeDrawable);
|
|
|
+ ViewUtils.applyViewBackground(this);
|
|
|
|
|
|
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 setSearchBtnClickListener(View.OnClickListener clickListener) {
|
|
|
ivToolBarSearchBtn.setOnClickListener(clickListener);
|
|
|
}
|
|
|
|
|
|
- public void setOutlineBtnClickListener(View.OnClickListener clickListener) {
|
|
|
- ivToolBarOutlineBtn.setOnClickListener(clickListener);
|
|
|
+ public void setBoTaBtnClickListener(View.OnClickListener clickListener) {
|
|
|
+ ivToolBarBoTaBtn.setOnClickListener(clickListener);
|
|
|
}
|
|
|
|
|
|
public void setMoreBtnClickListener(View.OnClickListener clickListener) {
|