|
@@ -1,15 +1,29 @@
|
|
|
|
+/**
|
|
|
|
+ * 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.pdfview;
|
|
package com.compdfkit.tools.pdfview;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.content.res.TypedArray;
|
|
|
|
+import android.graphics.Color;
|
|
|
|
+import android.graphics.drawable.Drawable;
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
|
+import android.view.View;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.FrameLayout;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.Nullable;
|
|
|
|
+import androidx.appcompat.content.res.AppCompatResources;
|
|
|
|
+import androidx.appcompat.widget.AppCompatImageView;
|
|
import androidx.appcompat.widget.AppCompatTextView;
|
|
import androidx.appcompat.widget.AppCompatTextView;
|
|
|
|
|
|
import com.compdfkit.tools.R;
|
|
import com.compdfkit.tools.R;
|
|
@@ -17,6 +31,9 @@ import com.compdfkit.tools.R;
|
|
public class CPDFToolBar extends FrameLayout {
|
|
public class CPDFToolBar extends FrameLayout {
|
|
|
|
|
|
private AppCompatTextView tvToolBarTitle;
|
|
private AppCompatTextView tvToolBarTitle;
|
|
|
|
+ private AppCompatImageView ivToolBarSearchBtn;
|
|
|
|
+ private AppCompatImageView ivToolBarOutlineBtn;
|
|
|
|
+ private AppCompatImageView ivToolBarMoreBtn;
|
|
|
|
|
|
public CPDFToolBar(@NonNull Context context) {
|
|
public CPDFToolBar(@NonNull Context context) {
|
|
super(context);
|
|
super(context);
|
|
@@ -32,20 +49,66 @@ public class CPDFToolBar extends FrameLayout {
|
|
super(context, attrs, defStyleAttr);
|
|
super(context, attrs, defStyleAttr);
|
|
}
|
|
}
|
|
|
|
|
|
- private void initToolBar(Context context, @Nullable AttributeSet attrs){
|
|
|
|
|
|
+ private void initToolBar(Context context, @Nullable AttributeSet attrs) {
|
|
LayoutInflater.from(getContext()).inflate(R.layout.tools_cpdf_tool_bar, this);
|
|
LayoutInflater.from(getContext()).inflate(R.layout.tools_cpdf_tool_bar, this);
|
|
|
|
+ setBackgroundColor(Color.WHITE);
|
|
|
|
+ setElevation(8);
|
|
tvToolBarTitle = findViewById(R.id.tv_tool_bar_title);
|
|
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);
|
|
initAttributes(context, attrs);
|
|
initAttributes(context, attrs);
|
|
}
|
|
}
|
|
|
|
|
|
- private void initAttributes(Context context, @Nullable AttributeSet 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.Tools_CPDFToolBar);
|
|
if (typedArray != null) {
|
|
if (typedArray != null) {
|
|
String toolBarTitle = typedArray.getString(R.styleable.Tools_CPDFToolBar_tools_toolbar_title);
|
|
String toolBarTitle = typedArray.getString(R.styleable.Tools_CPDFToolBar_tools_toolbar_title);
|
|
|
|
+ typedArray.getResourceId(R.styleable.Tools_CPDFToolBar_tools_toolbar_search_icon, -1);
|
|
if (!TextUtils.isEmpty(toolBarTitle)) {
|
|
if (!TextUtils.isEmpty(toolBarTitle)) {
|
|
tvToolBarTitle.setText(toolBarTitle);
|
|
tvToolBarTitle.setText(toolBarTitle);
|
|
}
|
|
}
|
|
|
|
+ Drawable searchIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_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 moreIconDrawable = loadImageFromAttributes(typedArray, R.styleable.Tools_CPDFToolBar_tools_toolbar_more_icon, R.drawable.tools_ic_more);
|
|
|
|
+ if (moreIconDrawable != null) {
|
|
|
|
+ ivToolBarMoreBtn.setImageDrawable(moreIconDrawable);
|
|
|
|
+ }
|
|
|
|
+ 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 setMoreBtnClickListener(View.OnClickListener clickListener){
|
|
|
|
+ ivToolBarMoreBtn.setOnClickListener(clickListener);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|