Browse Source

ComPDFKit Tools(Android) - goto page 框

libai 1 year ago
parent
commit
8ee4d2bf38

+ 166 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/dialog/CommonInputDialog.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 CommonInputDialog 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 CommonInputDialog(Context context) {
+        super(context);
+        initView(context);
+    }
+
+    public CommonInputDialog(Context context, int theme) {
+        super(context, theme);
+        initView(context);
+    }
+
+    protected CommonInputDialog(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 CommonInputDialog setTitle(String title) {
+        this.title = title;
+        titleTv.setText(title);
+        return this;
+    }
+
+    public CommonInputDialog setMessage(String message) {
+        this.messageStrTv = message;
+        messageTv.setText(message);
+        return this;
+    }
+
+    public CommonInputDialog setHintInputText(String message) {
+        this.message = message;
+        messageEt.setHint(message);
+        return this;
+    }
+
+    public CommonInputDialog setCancelCallback(String cancelStr, Runnable cancelCallback) {
+        this.cancelStr = cancelStr;
+        this.cancelCallback = cancelCallback;
+        return this;
+    }
+
+    public CommonInputDialog 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/GotoPageDialog.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 GotoPageDialog extends CommonInputDialog {
+
+    private OnGotoPageListener onGotoPageListener = null;
+
+    public GotoPageDialog(Context context) {
+        super(context);
+        initDialogView();
+    }
+
+    public GotoPageDialog(Context context, int theme) {
+        super(context, theme);
+        initDialogView();
+    }
+
+    protected GotoPageDialog(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);
+    }
+}

+ 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>

File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw213dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw320dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw360dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw384dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw400dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw420dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw432dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw480dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw533dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw560dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw600dp/dimens.xml


File diff suppressed because it is too large
+ 1285 - 0
compdfkit-tools/src/main/res/values-sw720dp/dimens.xml


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

@@ -0,0 +1,6 @@
+<?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>
+</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>