3 Komitmen e41bc10b33 ... 3a5984d1ff

Pembuat SHA1 Pesan Tanggal
  libai 3a5984d1ff ComPDFKit Tools(Android) - 修改类名 1 tahun lalu
  libai 425e8a1345 ComPDFKit Tools(Android) - search toolbar 1 tahun lalu
  libai 8ee4d2bf38 ComPDFKit Tools(Android) - goto page 框 1 tahun lalu
24 mengubah file dengan 15950 tambahan dan 0 penghapusan
  1. 166 0
      compdfkit-tools/src/main/java/com/compdfkit/tools/dialog/CCommonInputDialog.java
  2. 59 0
      compdfkit-tools/src/main/java/com/compdfkit/tools/dialog/CGotoPageDialog.java
  3. 77 0
      compdfkit-tools/src/main/java/com/compdfkit/tools/search/CSearchTextInfo.java
  4. 84 0
      compdfkit-tools/src/main/java/com/compdfkit/tools/search/CSearchToolbar.java
  5. 6 0
      compdfkit-tools/src/main/res/drawable/tool_button_click.xml
  6. 7 0
      compdfkit-tools/src/main/res/drawable/tool_button_normal.xml
  7. 7 0
      compdfkit-tools/src/main/res/drawable/tool_button_pressed.xml
  8. 71 0
      compdfkit-tools/src/main/res/layout/common_input_dialog_layout.xml
  9. 26 0
      compdfkit-tools/src/main/res/layout/search_toolbar.xml
  10. 1285 0
      compdfkit-tools/src/main/res/values-sw213dp/dimens.xml
  11. 1285 0
      compdfkit-tools/src/main/res/values-sw320dp/dimens.xml
  12. 1285 0
      compdfkit-tools/src/main/res/values-sw360dp/dimens.xml
  13. 1285 0
      compdfkit-tools/src/main/res/values-sw384dp/dimens.xml
  14. 1285 0
      compdfkit-tools/src/main/res/values-sw400dp/dimens.xml
  15. 1285 0
      compdfkit-tools/src/main/res/values-sw420dp/dimens.xml
  16. 1285 0
      compdfkit-tools/src/main/res/values-sw432dp/dimens.xml
  17. 1285 0
      compdfkit-tools/src/main/res/values-sw480dp/dimens.xml
  18. 1285 0
      compdfkit-tools/src/main/res/values-sw533dp/dimens.xml
  19. 1285 0
      compdfkit-tools/src/main/res/values-sw560dp/dimens.xml
  20. 1285 0
      compdfkit-tools/src/main/res/values-sw600dp/dimens.xml
  21. 1285 0
      compdfkit-tools/src/main/res/values-sw720dp/dimens.xml
  22. 8 0
      compdfkit-tools/src/main/res/values/colors.xml
  23. 7 0
      compdfkit-tools/src/main/res/values/strings.xml
  24. 12 0
      compdfkit-tools/src/main/res/values/styles.xml

+ 166 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/dialog/CCommonInputDialog.java

@@ -0,0 +1,166 @@
+package com.compdfkit.tools.dialog;
+
+import android.content.Context;
+import android.text.TextUtils;
+import android.view.Display;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import androidx.appcompat.app.AppCompatDialog;
+
+import com.compdfkit.tools.R;
+
+/**
+ * @author luozhipeng
+ * @classname CommonInputDialog
+ * @date 2020-02-21 11:42
+ * @description
+ */
+public class CCommonInputDialog extends AppCompatDialog {
+
+    private Context context;
+
+    private String title;
+    private String message;
+    private String cancelStr;
+    private String okStr;
+    private Runnable cancelCallback;
+    private OnInputConpleteListener onInputConpleteListener;
+
+    private View mView;
+
+    private TextView titleTv;
+    private View gap_1;
+
+    private TextView messageTv;
+    private String messageStrTv;
+    private View gap_3;
+
+    private EditText messageEt;
+    private View gap_2;
+    private Button cancelBt;
+    private Button okBt;
+
+    public CCommonInputDialog(Context context) {
+        super(context);
+        initView(context);
+    }
+
+    public CCommonInputDialog(Context context, int theme) {
+        super(context, theme);
+        initView(context);
+    }
+
+    protected CCommonInputDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
+        super(context, cancelable, cancelListener);
+        initView(context);
+    }
+
+    private void initView(Context context) {
+        this.context = context;
+
+        mView = View.inflate(context, R.layout.common_input_dialog_layout, null);
+
+        titleTv = mView.findViewById(R.id.common_input_dialog_title);
+        gap_1 = mView.findViewById(R.id.common_input_dialog_gap_1);
+
+        messageTv = mView.findViewById(R.id.common_input_dialog_message);
+        gap_3 = mView.findViewById(R.id.common_input_dialog_gap_3);
+
+        messageEt = mView.findViewById(R.id.common_input_dialog_et);
+        gap_2 = mView.findViewById(R.id.common_input_dialog_gap_2);
+        cancelBt = mView.findViewById(R.id.common_input_dialog_cancel);
+        okBt = mView.findViewById(R.id.common_input_dialog_ok);
+        cancelBt.setOnClickListener(v -> {
+            if (cancelCallback != null) {
+                cancelCallback.run();
+            }
+        });
+
+        okBt.setOnClickListener(v -> {
+            if (onInputConpleteListener != null) {
+                onInputConpleteListener.getInputText(messageEt.getText().toString());
+            }
+        });
+
+        setContentView(mView);
+
+        Window window = getWindow();
+        WindowManager m = window.getWindowManager();
+        Display display = m.getDefaultDisplay();
+        WindowManager.LayoutParams p = window.getAttributes();
+        p.width = (int) (display.getWidth() * 0.7);
+        window.setAttributes(p);
+    }
+
+    private void initVisibility() {
+        if (TextUtils.isEmpty(title)) {
+            titleTv.setVisibility(View.GONE);
+            gap_1.setVisibility(View.GONE);
+        } else {
+            titleTv.setVisibility(View.VISIBLE);
+            gap_1.setVisibility(View.VISIBLE);
+        }
+
+        if (TextUtils.isEmpty(messageStrTv)) {
+            messageTv.setVisibility(View.GONE);
+            gap_3.setVisibility(View.GONE);
+        } else {
+            messageTv.setVisibility(View.VISIBLE);
+            gap_3.setVisibility(View.VISIBLE);
+        }
+
+        if (cancelCallback != null) {
+            cancelBt.setVisibility(View.VISIBLE);
+        } else {
+            cancelBt.setVisibility(View.GONE);
+        }
+    }
+
+    public void setInputType(int type) {
+        messageEt.setInputType(type);
+    }
+
+    public CCommonInputDialog setTitle(String title) {
+        this.title = title;
+        titleTv.setText(title);
+        return this;
+    }
+
+    public CCommonInputDialog setMessage(String message) {
+        this.messageStrTv = message;
+        messageTv.setText(message);
+        return this;
+    }
+
+    public CCommonInputDialog setHintInputText(String message) {
+        this.message = message;
+        messageEt.setHint(message);
+        return this;
+    }
+
+    public CCommonInputDialog setCancelCallback(String cancelStr, Runnable cancelCallback) {
+        this.cancelStr = cancelStr;
+        this.cancelCallback = cancelCallback;
+        return this;
+    }
+
+    public CCommonInputDialog setOkCallback(String okStr, OnInputConpleteListener onInputConpleteListener) {
+        this.okStr = okStr;
+        this.onInputConpleteListener = onInputConpleteListener;
+        return this;
+    }
+
+    @Override
+    public void show() {
+        initVisibility();
+        super.show();
+    }
+
+    public interface OnInputConpleteListener {
+        void getInputText(String text);
+    }
+}

+ 59 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/dialog/CGotoPageDialog.java

@@ -0,0 +1,59 @@
+package com.compdfkit.tools.dialog;
+
+import android.content.Context;
+import android.text.InputType;
+import android.text.TextUtils;
+
+import com.compdfkit.tools.R;
+
+public class CGotoPageDialog extends CCommonInputDialog {
+
+    private OnGotoPageListener onGotoPageListener = null;
+
+    public CGotoPageDialog(Context context) {
+        super(context);
+        initDialogView();
+    }
+
+    public CGotoPageDialog(Context context, int theme) {
+        super(context, theme);
+        initDialogView();
+    }
+
+    protected CGotoPageDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
+        super(context, cancelable, cancelListener);
+        initDialogView();
+    }
+
+    public void setTotoPageListener(OnGotoPageListener onGotoPageListener) {
+        this.onGotoPageListener = onGotoPageListener;
+    }
+
+    private void initDialogView() {
+        setTitle(R.string.goto_page_dialog_title);
+        setMessage(getContext().getResources().getText(R.string.goto_page_dialog_msg).toString());
+        setHintInputText(getContext().getResources().getText(R.string.goto_page_dialog_hint).toString());
+        setInputType(InputType.TYPE_CLASS_NUMBER);
+        setOkCallback(getContext().getResources().getText(R.string.common_okay).toString(), text -> {
+            if (null != onGotoPageListener && (!TextUtils.isEmpty(text))) {
+               int page = -1;
+               try {
+                   page = Integer.parseInt(text);
+               } catch (NumberFormatException e) {
+
+               }
+                if (page >= 0) {
+                    onGotoPageListener.onGotoPage(page);
+                }
+            }
+            dismiss();
+        });
+        setCancelCallback(getContext().getResources().getText(R.string.common_cancel).toString(), ()-> {
+            dismiss();
+        });
+    }
+
+    public interface OnGotoPageListener {
+        public void onGotoPage(int page);
+    }
+}

+ 77 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/search/CSearchTextInfo.java

@@ -0,0 +1,77 @@
+package com.compdfkit.tools.search;
+
+import android.content.Context;
+import android.text.Spannable;
+import android.text.SpannableStringBuilder;
+import android.text.style.BackgroundColorSpan;
+import android.text.style.CharacterStyle;
+
+import androidx.core.content.ContextCompat;
+
+import com.compdfkit.core.page.CPDFTextPage;
+import com.compdfkit.core.page.CPDFTextRange;
+import com.compdfkit.tools.R;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @classname:SearchTextInfo
+ * @date:2018/8/23 下午1:46
+ * @description:
+ */
+public class CSearchTextInfo {
+
+    private Context context;
+    public int page;
+    public String keyword;
+    public SpannableStringBuilder stringBuilder;
+    public boolean isHeader;
+    public int textRangeIndex;
+
+    public CSearchTextInfo(Context context, int page, String keyword, CPDFTextPage textPage, CPDFTextRange textRange, int textRangeIndex, boolean isHeader) {
+        this.context = context;
+        this.page = page;
+        this.keyword = keyword;
+        this.isHeader = isHeader;
+        this.textRangeIndex = textRangeIndex;
+
+        if (isHeader) {
+            return;
+        }
+
+        int targetStart = textRange.location - 20;
+        int length;
+        if (targetStart > 0) {
+            length = textRange.length + 40;
+        } else {
+            length = textRange.length + 40 + targetStart;
+            targetStart = 0;
+        }
+        CPDFTextRange targetTextRange = new CPDFTextRange(targetStart, length);
+        String target = textPage.getText(targetTextRange);
+
+        this.stringBuilder = highlight(target.toLowerCase(), keyword.toLowerCase());
+    }
+
+    /**
+     * 关键字高亮显示
+     *
+     * @param text   需要显示的文字
+     * @param target 需要高亮的关键字
+     * @return spannable 处理完后的结果,记得不要toString(),否则没有效果
+     */
+    private SpannableStringBuilder highlight(String text, String target) {
+        SpannableStringBuilder spannable = new SpannableStringBuilder(text);
+        CharacterStyle span;
+        Pattern p = Pattern.compile(target);
+        Matcher m = p.matcher(text);
+        int backGroundColor = ContextCompat.getColor(context, R.color.search_result_text_highlight);
+        while (m.find()) {
+            /****** 需要重复 ******/
+            span = new BackgroundColorSpan(backGroundColor);
+            spannable.setSpan(span, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+        }
+        return spannable;
+    }
+}

+ 84 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/search/CSearchToolbar.java

@@ -0,0 +1,84 @@
+package com.compdfkit.tools.search;
+
+import android.content.Context;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+
+import com.compdfkit.tools.R;
+
+import java.util.List;
+
+public class CSearchToolbar extends RelativeLayout implements View.OnClickListener {
+    private Button completeBt;
+    private EditText searchEdit;
+    private ImageView leftImage;
+    private ImageView rightImage;
+    private ImageView listImage;
+
+    private Context context;
+
+    OnSearchListener onSearchListener = null;
+    List<CSearchTextInfo> searchTextInfos = null;
+
+    public CSearchToolbar(Context context) {
+        super(context);
+        init(context);
+    }
+
+    public CSearchToolbar(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(context);
+    }
+
+    public CSearchToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        init(context);
+    }
+
+    public CSearchToolbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+        init(context);
+    }
+
+    private void init(Context context) {
+        this.context = context;
+        inflate(context, R.layout.search_toolbar, this);
+        completeBt = findViewById(R.id.complete);
+        searchEdit = findViewById(R.id.search_word);
+        leftImage = findViewById(R.id.left);
+        rightImage = findViewById(R.id.right);
+        listImage = findViewById(R.id.list);
+        completeBt.setOnClickListener(this);
+        leftImage.setOnClickListener(this);
+        rightImage.setOnClickListener(this);
+    }
+
+    @Override
+    public void onClick(View view) {
+        int id = view.getId();
+        if (id == R.id.complete) {
+            if (null != onSearchListener && (!TextUtils.isEmpty(searchEdit.getText().toString()))) {
+                searchTextInfos = onSearchListener.onSearch(searchEdit.getText().toString());
+            }
+        } else if (id == R.id.left) {
+
+        } else if (id == R.id.right) {
+
+        } else if (id == R.id.list) {
+
+        }
+    }
+
+    public void setSearchListener(OnSearchListener onSearchListener) {
+        this.onSearchListener = onSearchListener;
+    }
+
+    public interface OnSearchListener {
+        List<CSearchTextInfo> onSearch(String word);
+    }
+}

+ 6 - 0
compdfkit-tools/src/main/res/drawable/tool_button_click.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android" >
+    <item android:state_pressed="true" android:drawable="@drawable/tool_button_pressed"/>
+    <item android:state_selected="true" android:drawable="@drawable/tool_button_pressed"/>
+    <item android:state_enabled="true" android:drawable="@drawable/tool_button_normal"/>
+</selector>

+ 7 - 0
compdfkit-tools/src/main/res/drawable/tool_button_normal.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle" >
+
+    <solid android:color="@color/reader_tools_button_normal" />
+
+</shape>

+ 7 - 0
compdfkit-tools/src/main/res/drawable/tool_button_pressed.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle" >
+
+    <solid android:color="@color/reader_tools_button_clicked" />
+
+</shape>

+ 71 - 0
compdfkit-tools/src/main/res/layout/common_input_dialog_layout.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <TextView
+        android:id="@+id/common_input_dialog_title"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textColor="@android:color/black"
+        android:gravity="center_vertical|left"
+        android:padding="@dimen/qb_px_10"
+        android:textSize="@dimen/qb_px_16"/>
+
+    <View
+        android:id="@+id/common_input_dialog_gap_1"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/qb_px_1"
+        android:background="@color/upgrade_diff_line"/>
+
+    <TextView
+        android:id="@+id/common_input_dialog_message"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textColor="@android:color/black"
+        android:gravity="center_vertical|left"
+        android:padding="@dimen/qb_px_10"
+        android:textSize="@dimen/qb_px_16"/>
+
+    <View
+        android:id="@+id/common_input_dialog_gap_3"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/qb_px_1"
+        android:background="@color/upgrade_diff_line"/>
+
+    <EditText
+        android:id="@+id/common_input_dialog_et"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textColor="@android:color/black"
+        android:gravity="center"
+        android:padding="@dimen/qb_px_10"
+        android:textSize="@dimen/qb_px_16"/>
+
+    <View
+        android:id="@+id/common_input_dialog_gap_2"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/qb_px_1"
+        android:background="@color/upgrade_diff_line"/>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <Button
+            android:id="@+id/common_input_dialog_cancel"
+            style="@style/dialog_button_style"
+            android:textAllCaps="false"
+            android:text="@string/common_cancel"/>
+
+        <Button
+            android:id="@+id/common_input_dialog_ok"
+            style="@style/dialog_button_style"
+            android:textAllCaps="false"
+            android:text="@string/common_okay"/>
+
+    </LinearLayout>
+
+</LinearLayout>

+ 26 - 0
compdfkit-tools/src/main/res/layout/search_toolbar.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <Button
+        android:id="@+id/complete"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"/>
+    <EditText
+        android:id="@+id/search_word"
+        android:layout_width="@dimen/qb_px_60"
+        android:layout_height="wrap_content"/>
+    <ImageView
+        android:id="@+id/left"
+        android:layout_width="@dimen/qb_px_30"
+        android:layout_height="@dimen/qb_px_30"/>
+    <ImageView
+        android:id="@+id/right"
+        android:layout_width="@dimen/qb_px_30"
+        android:layout_height="@dimen/qb_px_30"/>
+    <ImageView
+        android:id="@+id/list"
+        android:layout_width="@dimen/qb_px_30"
+        android:layout_height="@dimen/qb_px_30"/>
+</LinearLayout>

File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw213dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw320dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw360dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw384dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw400dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw420dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw432dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw480dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw533dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw560dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw600dp/dimens.xml


File diff ditekan karena terlalu besar
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw720dp/dimens.xml


+ 8 - 0
compdfkit-tools/src/main/res/values/colors.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="upgrade_diff_line">#14000000</color>
+    <color name="reader_tools_button_normal">#F5F5F5</color>
+    <color name="reader_tools_button_clicked">#1E0071EE</color>
+    <color name="search_result_text_color">#333333</color>
+    <color name="search_result_text_highlight">#FFAB00</color>
+</resources>

+ 7 - 0
compdfkit-tools/src/main/res/values/strings.xml

@@ -0,0 +1,7 @@
+<resources xmlns:tools="http://schemas.android.com/tools">
+    <string name="common_okay">OK</string>
+    <string name="common_cancel">Cancel</string>
+    <string name="goto_page_dialog_title">Go To Page</string>
+    <string name="goto_page_dialog_msg">Enter a page number</string>
+    <string name="goto_page_dialog_hint">input page</string>
+</resources>

+ 12 - 0
compdfkit-tools/src/main/res/values/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <style name="dialog_button_style">
+        <item name="android:layout_width">@dimen/qb_px_0</item>
+        <item name="android:layout_height">match_parent</item>
+        <item name="android:layout_weight">1</item>
+        <item name="android:paddingTop">@dimen/qb_px_10</item>
+        <item name="android:textSize">@dimen/qb_px_12</item>
+        <item name="android:background">@drawable/tool_button_click</item>
+    </style>
+
+</resources>