|
@@ -4,6 +4,8 @@ import android.annotation.SuppressLint;
|
|
|
import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.graphics.RectF;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextWatcher;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.widget.AdapterView;
|
|
@@ -13,6 +15,7 @@ import android.widget.EditText;
|
|
|
import android.widget.ImageButton;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
|
|
|
import androidx.appcompat.widget.AppCompatEditText;
|
|
@@ -20,20 +23,75 @@ import androidx.appcompat.widget.AppCompatRadioButton;
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
|
|
import com.compdfkit.pdfviewer.R;
|
|
|
+import com.compdfkit.pdfviewer.activities.BackgroundActivity;
|
|
|
import com.compdfkit.pdfviewer.activities.HeaderFooterActivity;
|
|
|
import com.compdfkit.pdfviewer.customview.picker.FontColorPicker;
|
|
|
+import com.compdfkit.pdfviewer.entity.BackgroundSetting;
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
+import com.google.android.material.slider.Slider;
|
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
|
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
public class DialogManager {
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
public static void showBackgroundSettingDialog(Context context) {
|
|
|
+ BackgroundActivity activity = (BackgroundActivity) context;
|
|
|
+
|
|
|
LayoutInflater inflater = LayoutInflater.from(context);
|
|
|
- final ConstraintLayout globalSettingLayout = (ConstraintLayout) inflater.inflate(R.layout.background_setting_panel, null);
|
|
|
+ final ConstraintLayout backgroundSettingLayout = (ConstraintLayout) inflater.inflate(R.layout.background_setting_panel, null);
|
|
|
final Button[] positiveButton = new Button[1];
|
|
|
+ boolean isCustomRange = true;
|
|
|
+
|
|
|
+ BackgroundSetting currentSetting = BackgroundHandle.getBackgroundSetting();
|
|
|
+
|
|
|
+ TextInputEditText xOffset = backgroundSettingLayout.findViewById(R.id.x_offset);
|
|
|
+ xOffset.setText(String.valueOf(currentSetting.getxOffset()));
|
|
|
+ TextInputEditText yOffset = backgroundSettingLayout.findViewById(R.id.y_offset);
|
|
|
+ yOffset.setText(String.valueOf(currentSetting.getyOffset()));
|
|
|
+
|
|
|
+ Slider opacitySlider = backgroundSettingLayout.findViewById(R.id.opacity_slider);
|
|
|
+ opacitySlider.setValue(currentSetting.getOpacity() * 100);
|
|
|
+ Slider sizeSlider = backgroundSettingLayout.findViewById(R.id.size_slider);
|
|
|
+ sizeSlider.setValue(currentSetting.getScale() * 100);
|
|
|
+ Slider rotationSlider = backgroundSettingLayout.findViewById(R.id.rotation_slider);
|
|
|
+ rotationSlider.setValue((float) Math.toDegrees(currentSetting.getRotation()));
|
|
|
+
|
|
|
+ TextView opacityText = backgroundSettingLayout.findViewById(R.id.opacity_text);
|
|
|
+ opacityText.setText((int) opacitySlider.getValue() + "%");
|
|
|
+ TextView sizeText = backgroundSettingLayout.findViewById(R.id.size_text);
|
|
|
+ sizeText.setText((int) sizeSlider.getValue() + "%");
|
|
|
+ TextView rotationText = backgroundSettingLayout.findViewById(R.id.rotation_text);
|
|
|
+ rotationText.setText((int) rotationSlider.getValue() + "°");
|
|
|
+
|
|
|
+ ImageButton pageRangeBtn = backgroundSettingLayout.findViewById(R.id.page_range_button);
|
|
|
+ TextView pageRangeMsg = backgroundSettingLayout.findViewById(R.id.page_range_msg);
|
|
|
+ isCustomRange = !BackgroundHandle.getSettingPages().equals("0-" + (activity.getPageCount() - 1));
|
|
|
+
|
|
|
+ boolean finalIsCustomRange = isCustomRange;
|
|
|
+ pageRangeBtn.setOnClickListener((view) -> showPageRangeDialog(context, 3, finalIsCustomRange, BackgroundHandle.getSettingPages(), pageRangeMsg, activity.getPageCount()));
|
|
|
+
|
|
|
+ opacitySlider.addOnChangeListener((slider, value, fromUser) -> opacityText.setText((int) value + "%"));
|
|
|
+ sizeSlider.addOnChangeListener((slider, value, fromUser) -> sizeText.setText((int) value + "%"));
|
|
|
+ rotationSlider.addOnChangeListener((slider, value, fromUser) -> rotationText.setText((int) value + "°"));
|
|
|
|
|
|
MaterialAlertDialogBuilder inputDialog = new MaterialAlertDialogBuilder(context);
|
|
|
- inputDialog.setTitle("Background setting").setView(globalSettingLayout);
|
|
|
- inputDialog.setPositiveButton(R.string.done, (dialogInterface, i) -> {});
|
|
|
+ inputDialog.setTitle(R.string.background_setting).setView(backgroundSettingLayout);
|
|
|
+ inputDialog.setPositiveButton(R.string.done, (dialogInterface, i) -> {
|
|
|
+ BackgroundHandle.setSettingMsg(
|
|
|
+ Float.parseFloat(xOffset.getText().toString()),
|
|
|
+ Float.parseFloat(yOffset.getText().toString()),
|
|
|
+ opacitySlider.getValue() / 100,
|
|
|
+ sizeSlider.getValue() / 100,
|
|
|
+ (float) Math.toRadians(rotationSlider.getValue()));
|
|
|
+
|
|
|
+ activity.setBackgroundLayerAttr(
|
|
|
+ Float.parseFloat(xOffset.getText().toString()),
|
|
|
+ Float.parseFloat(yOffset.getText().toString()),
|
|
|
+ opacitySlider.getValue() / 100,
|
|
|
+ sizeSlider.getValue() / 100,
|
|
|
+ -rotationSlider.getValue());
|
|
|
+ });
|
|
|
|
|
|
inputDialog.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {});
|
|
|
|
|
@@ -72,10 +130,10 @@ public class DialogManager {
|
|
|
pageRangeMsg.setText(HeaderFooterHandle.getSettingPages(type));
|
|
|
|
|
|
boolean finalIsCustomRange = isCustomRange;
|
|
|
- pageRangeBtn.setOnClickListener((view) -> showPageRangeDialog(context, type, finalIsCustomRange, HeaderFooterHandle.getSettingPages(type), pageRangeMsg));
|
|
|
+ pageRangeBtn.setOnClickListener((view) -> showPageRangeDialog(context, type, finalIsCustomRange, HeaderFooterHandle.getSettingPages(type), pageRangeMsg, activity.getPageCount()));
|
|
|
|
|
|
MaterialAlertDialogBuilder inputDialog = new MaterialAlertDialogBuilder(context);
|
|
|
- inputDialog.setTitle("Global header-footer setting").setView(globalSettingLayout);
|
|
|
+ inputDialog.setTitle(R.string.global_header_footer_setting).setView(globalSettingLayout);
|
|
|
inputDialog.setPositiveButton(R.string.done, (dialogInterface, i) -> {
|
|
|
float top = Float.parseFloat(topMargin.getText().toString());
|
|
|
float bottom = Float.parseFloat(bottomMargin.getText().toString());
|
|
@@ -130,7 +188,7 @@ public class DialogManager {
|
|
|
startPagePicker.setText(String.valueOf(HeaderFooterHandle.getIndexStartPageNumber(index)));
|
|
|
|
|
|
MaterialAlertDialogBuilder inputDialog = new MaterialAlertDialogBuilder(context);
|
|
|
- inputDialog.setTitle("HeaderFooter setting").setView(commonSettingLayout);
|
|
|
+ inputDialog.setTitle(R.string.headerfooter_setting).setView(commonSettingLayout);
|
|
|
|
|
|
inputDialog.setPositiveButton(R.string.done, (dialogInterface, i) -> {
|
|
|
HeaderFooterHandle.setSettingColor(0, index, fontColorText.getCurrentTextColor());
|
|
@@ -177,7 +235,7 @@ public class DialogManager {
|
|
|
digitsEdit.setText(String.valueOf(HeaderFooterHandle.getIndexDigits(index)));
|
|
|
|
|
|
MaterialAlertDialogBuilder inputDialog = new MaterialAlertDialogBuilder(context);
|
|
|
- inputDialog.setTitle("Global bates number setting").setView(batesSettingLayout);
|
|
|
+ inputDialog.setTitle(R.string.global_bates_setting).setView(batesSettingLayout);
|
|
|
inputDialog.setPositiveButton(R.string.done, (dialogInterface, i) -> {
|
|
|
HeaderFooterHandle.setSettingColor(1, index, fontColorText.getCurrentTextColor());
|
|
|
HeaderFooterHandle.setSettingFontName(1, index, fontPicker.getText().toString());
|
|
@@ -200,13 +258,11 @@ public class DialogManager {
|
|
|
positiveButton[0] = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
|
}
|
|
|
|
|
|
- public static void showPageRangeDialog(Context context, int type, boolean isCustomRange, String pageRange, TextView textView) {
|
|
|
+ public static void showPageRangeDialog(Context context, int type, boolean isCustomRange, String pageRange, TextView textView, int pageCount) {
|
|
|
LayoutInflater inflater = LayoutInflater.from(context);
|
|
|
final ConstraintLayout rangeSelectLayout = (ConstraintLayout) inflater.inflate(R.layout.range_selector, null);
|
|
|
final Button[] positiveButton = new Button[1];
|
|
|
|
|
|
- HeaderFooterActivity activity = (HeaderFooterActivity) context;
|
|
|
-
|
|
|
AppCompatRadioButton customRadioBtn = rangeSelectLayout.findViewById(R.id.custom_range);
|
|
|
customRadioBtn.setChecked(isCustomRange);
|
|
|
|
|
@@ -215,15 +271,42 @@ public class DialogManager {
|
|
|
if (isCustomRange)
|
|
|
rangeEditText.setText(pageRange);
|
|
|
|
|
|
+ customRadioBtn.setOnCheckedChangeListener((compoundButton, b) -> {
|
|
|
+ rangeEditText.setEnabled(b);
|
|
|
+ if (b && Objects.requireNonNull(rangeEditText.getText()).toString().equals(""))
|
|
|
+ positiveButton[0].setEnabled(false);
|
|
|
+ });
|
|
|
+
|
|
|
+ rangeEditText.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+ positiveButton[0].setEnabled(!rangeEditText.getText().toString().equals(""));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
MaterialAlertDialogBuilder inputDialog = new MaterialAlertDialogBuilder(context);
|
|
|
inputDialog.setTitle(R.string.setting_range).setView(rangeSelectLayout);
|
|
|
|
|
|
inputDialog.setPositiveButton(R.string.done, (dialogInterface, i) -> {
|
|
|
if (customRadioBtn.isChecked()) {
|
|
|
- HeaderFooterHandle.setSettingPages(type, rangeEditText.getText().toString());
|
|
|
+ if (type != 3)
|
|
|
+ HeaderFooterHandle.setSettingPages(type, rangeEditText.getText().toString());
|
|
|
+ else
|
|
|
+ BackgroundHandle.setSettingPages(rangeEditText.getText().toString());
|
|
|
+
|
|
|
textView.setText(rangeEditText.getText().toString());
|
|
|
} else {
|
|
|
- HeaderFooterHandle.setSettingPages(type, "0-" + (activity.getPageCount() - 1));
|
|
|
+ if (type != 3)
|
|
|
+ HeaderFooterHandle.setSettingPages(type, "0-" + (pageCount - 1));
|
|
|
+ else
|
|
|
+ BackgroundHandle.setSettingPages("0-" + (pageCount - 1));
|
|
|
+
|
|
|
textView.setText(R.string.all_pages);
|
|
|
}
|
|
|
});
|