From 34e48224f726dcab76de4556009bbd95278d303e Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Fri, 31 May 2024 13:47:17 +0200 Subject: [PATCH] Rework options dialogs --- .../test/espresso/BaseViewerActivityTest.kt | 12 +- .../constellation/orion/viewer/Action.java | 14 +- .../constellation/orion/viewer/MainMenu.kt | 113 +++--- .../orion/viewer/OrionBaseActivity.kt | 12 - .../orion/viewer/OrionBookmarkActivity.kt | 4 +- .../orion/viewer/OrionViewerActivity.kt | 337 +++++++----------- .../orion/viewer/dialog/CropDialogBuilder.kt | 13 +- .../viewer/prefs/OrionKeyBinderActivity.java | 4 +- .../res/layout-sw600dp/options_dialog.xml | 9 - ...d_bookmark.xml => add_bookmark_dialog.xml} | 23 +- .../src/main/res/layout/crop_dialog.xml | 18 +- .../src/main/res/layout/dialog_animator.xml | 153 -------- .../src/main/res/layout/goto_dialog.xml | 50 +++ .../res/layout/option_dialog_bottom_panel.xml | 27 ++ .../src/main/res/layout/options_dialog.xml | 9 - .../src/main/res/layout/zoom_dialog.xml | 56 +++ 16 files changed, 362 insertions(+), 492 deletions(-) delete mode 100644 orion-viewer/src/main/res/layout-sw600dp/options_dialog.xml rename orion-viewer/src/main/res/layout/{add_bookmark.xml => add_bookmark_dialog.xml} (68%) delete mode 100644 orion-viewer/src/main/res/layout/dialog_animator.xml create mode 100644 orion-viewer/src/main/res/layout/goto_dialog.xml create mode 100644 orion-viewer/src/main/res/layout/option_dialog_bottom_panel.xml delete mode 100644 orion-viewer/src/main/res/layout/options_dialog.xml create mode 100644 orion-viewer/src/main/res/layout/zoom_dialog.xml diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/BaseViewerActivityTest.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/BaseViewerActivityTest.kt index c5a849dcb..19615ac8e 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/BaseViewerActivityTest.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/BaseViewerActivityTest.kt @@ -97,14 +97,14 @@ abstract class BaseViewerActivityTest( protected fun applyZoom() { - onView(ViewMatchers.withId(R.id.zoom_preview)).perform(ViewActions.click()) - onView(ViewMatchers.withId(R.id.zoom_picker_close)).perform(ViewActions.click()) + onView(ViewMatchers.withId(R.id.option_dialog_bottom_apply)).perform(ViewActions.click()) + onView(ViewMatchers.withId(R.id.option_dialog_bottom_close)).perform(ViewActions.click()) } protected fun applyGoTo() { if (!globalOptions.isNewUI) { - onView(ViewMatchers.withId(R.id.page_preview)).perform(ViewActions.click()) - onView(ViewMatchers.withId(R.id.page_picker_close)).perform(ViewActions.click()) + onView(ViewMatchers.withId(R.id.option_dialog_bottom_apply)).perform(ViewActions.click()) + onView(ViewMatchers.withId(R.id.option_dialog_bottom_close)).perform(ViewActions.click()) } else { onView(ViewMatchers.withId(R.id.view)).perform(ViewActions.click()) } @@ -123,8 +123,8 @@ abstract class BaseViewerActivityTest( } fun applyCrop() { - onView(ViewMatchers.withId(R.id.crop_preview)).perform(ViewActions.click()) - onView(ViewMatchers.withId(R.id.crop_close)).perform(ViewActions.click()) + onView(ViewMatchers.withId(R.id.option_dialog_bottom_apply)).perform(ViewActions.click()) + onView(ViewMatchers.withId(R.id.option_dialog_bottom_close)).perform(ViewActions.click()) } private fun openMenuAndSelect(id: Int, resId: Int) { diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/Action.java b/orion-viewer/src/main/java/universe/constellation/orion/viewer/Action.java index 63b51fd93..da5bd826e 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/Action.java +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/Action.java @@ -201,7 +201,7 @@ public void doAction(Controller controller, OrionViewerActivity activity, Object BOOK_OPTIONS (R.string.action_book_options, R.integer.action_book_options) { @Override - public void doAction(Controller controller, OrionViewerActivity activity, Object parameter) { + public void doAction(OrionBaseActivity activity) { Intent intent = new Intent(activity, OrionBookPreferencesActivityX.class); activity.startActivity(intent); } @@ -215,9 +215,9 @@ public void doAction(Controller controller, OrionViewerActivity activity, Object }, PAGE_LAYOUT (R.string.action_layout_page, R.integer.action_page_layout) { - @Override - public void doAction(Controller controller, OrionViewerActivity activity, Object parameter) { - activity.showOrionDialog(OrionViewerActivity.PAGE_LAYOUT_SCREEN, null, null); + @Override + public void doAction(OrionBaseActivity activity) { + BOOK_OPTIONS.doAction(activity); } }, @@ -237,9 +237,9 @@ public void doAction(Controller controller, OrionViewerActivity activity, Object }, ROTATION (R.string.action_rotation_page, R.integer.action_rotation_page) { - @Override - public void doAction(Controller controller, OrionViewerActivity activity, Object parameter) { - activity.showOrionDialog(OrionViewerActivity.ROTATION_SCREEN, null, null); + @Override + public void doAction(OrionBaseActivity activity) { + BOOK_OPTIONS.doAction(activity); } }, diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/MainMenu.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/MainMenu.kt index 371645a6a..e521f3b09 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/MainMenu.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/MainMenu.kt @@ -13,7 +13,7 @@ import android.widget.LinearLayout import android.widget.SeekBar import android.widget.TextView -class MainMenu(private val mainMenu: View, val orionViewerActivity: OrionViewerActivity) { +class MainMenu(private val mainMenu: View, val activity: OrionViewerActivity) { private val pageSeeker = mainMenu.findViewById(R.id.page_picker_seeker)!! private val pageCount = mainMenu.findViewById(R.id.page_count)!! @@ -29,37 +29,14 @@ class MainMenu(private val mainMenu: View, val orionViewerActivity: OrionViewerA hideMenu() } - pageSeeker.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - if (fromUser) { - openPage(progress) - } - curPage.setGotoSpannable((progress + 1).toString()) - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) {} - - override fun onStopTrackingTouch(seekBar: SeekBar?) {} - }) - mainMenu.findViewById(R.id.menu_top_actions).setOnClickListener {} mainMenu.findViewById(R.id.menu_botton_actions_all).setOnClickListener {} - mainMenu.findViewById(R.id.page_picker_minus).setOnClickListener { - if (pageSeeker.progress - 1 >= 0) { - pageSeeker.progress -= 1 - openPage(pageSeeker.progress) - } - } - mainMenu.findViewById(R.id.page_picker_plus).setOnClickListener { - if (pageSeeker.progress + 1 <= pageSeeker.max) { - pageSeeker.progress += 1 - openPage(pageSeeker.progress) - } - } - } - private fun openPage(pageNum: Int) { - orionViewerActivity.controller?.drawPage(pageNum, isTapNavigation = true) + val minus = mainMenu.findViewById(R.id.page_picker_minus) + val plus = mainMenu.findViewById(R.id.page_picker_plus) + initPageNavControls(activity, pageSeeker, minus, plus, curPage) { + setGotoSpannable(it.toString()) + } } private fun initImageViewActions(view: View, id: Int) { @@ -88,7 +65,7 @@ class MainMenu(private val mainMenu: View, val orionViewerActivity: OrionViewerA topExtraPanel.visibility = newVisibility } else { hideMenu() - orionViewerActivity.doMenuAction(viewId) + activity.doMenuAction(viewId) } } @@ -98,17 +75,11 @@ class MainMenu(private val mainMenu: View, val orionViewerActivity: OrionViewerA fun showMenu() { - val controller = orionViewerActivity.controller - if (controller != null) { - pageSeeker.max = controller.pageCount - 1 - pageSeeker.progress = controller.currentPage - pageCount.setGotoSpannable(controller.pageCount.toString()) - } else { - pageSeeker.max = 1 - pageSeeker.progress = 1 - pageCount.text = "1" + val controller = activity.controller + initPageNavigationValues(controller, pageSeeker, pageCount) { + setGotoSpannable(controller!!.pageCount.toString()) } - mainMenu.visibility = View.VISIBLE + mainMenu.visibility = VISIBLE } private fun TextView.setGotoSpannable(text: String) { @@ -116,11 +87,71 @@ class MainMenu(private val mainMenu: View, val orionViewerActivity: OrionViewerA val onClick = object : ClickableSpan() { override fun onClick(widget: View) { hideMenu() - orionViewerActivity.doMenuAction(R.id.goto_menu_item) + activity.doMenuAction(R.id.goto_menu_item) } } spannable.setSpan(onClick, 0, spannable.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); this.text = spannable this.movementMethod = LinkMovementMethod.getInstance(); } +} + +fun initPageNavigationValues( + controller: Controller?, + pageSeeker: SeekBar, + pageCount: TextView, + setTextAction: TextView.(page: Int) -> Unit = { text = it.toString() } +) { + if (controller != null) { + pageSeeker.max = controller.pageCount - 1 + pageSeeker.progress = controller.currentPage + pageCount.setTextAction(controller.pageCount) + } else { + pageSeeker.max = 1 + pageSeeker.progress = 1 + pageCount.text = "1" + } +} + +fun initPageNavControls( + activity: OrionViewerActivity, + pageSeeker: SeekBar, + minus: View, + plus: View, + curPage: TextView, + setTextAction: TextView.(page: Int) -> Unit = { + text = it.toString() + } +) { + pageSeeker.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + if (fromUser) { + openPage(activity.controller, progress) + } + curPage.setTextAction(progress + 1) + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) {} + + override fun onStopTrackingTouch(seekBar: SeekBar?) {} + }) + + + minus.setOnClickListener { + if (pageSeeker.progress - 1 >= 0) { + pageSeeker.progress -= 1 + openPage(activity.controller, pageSeeker.progress) + } + } + + plus.setOnClickListener { + if (pageSeeker.progress + 1 <= pageSeeker.max) { + pageSeeker.progress += 1 + openPage(activity.controller, pageSeeker.progress) + } + } +} + +private fun openPage(controller: Controller?, pageNum: Int) { + controller?.drawPage(pageNum, isTapNavigation = true) } \ No newline at end of file diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt index fcc6bc303..48c9f264e 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt @@ -132,18 +132,6 @@ abstract class OrionBaseActivity(createDevice: Boolean = true, val viewerType: I device?.onUserInteraction() } - protected open fun findMyViewById(id: Int): View { - return findViewById(id) - } - - protected open fun onAnimatorCancel() { - - } - - protected open fun onApplyAction() { - - } - fun showWarning(warning: String) { Toast.makeText(this, warning, Toast.LENGTH_SHORT).show() } diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBookmarkActivity.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBookmarkActivity.kt index 493dcf22a..a1875a663 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBookmarkActivity.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBookmarkActivity.kt @@ -52,7 +52,7 @@ class OrionBookmarkActivity : OrionBaseActivity(false) { onNewIntent(intent) - val view = findMyViewById(R.id.bookmarks) as ListView + val view = findViewById(R.id.bookmarks) view.onItemClickListener = AdapterView.OnItemClickListener { parent, _, position, _ -> val bookmark = parent.getItemAtPosition(position) as Bookmark val result = Intent() @@ -72,7 +72,7 @@ class OrionBookmarkActivity : OrionBaseActivity(false) { private fun updateView(bookId: Long) { val accessor = orionContext.getBookmarkAccessor() val bookmarks = accessor.selectBookmarks(bookId) - val view = findMyViewById(R.id.bookmarks) as ListView + val view = findViewById(R.id.bookmarks) view.adapter = object : ArrayAdapter(this, R.layout.bookmark_entry, R.id.bookmark_entry, bookmarks) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { var convertView = convertView diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt index 56efb249d..559328d05 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt @@ -48,12 +48,8 @@ enum class MyState { class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVITY) { - private var dialog: AppCompatDialog? = null - internal val subscriptionManager = SubscriptionManager() - private var animator: ViewAnimator? = null - private var lastPageInfo: LastPageInfo? = null var controller: Controller? = null @@ -127,8 +123,6 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT OptionActions.SHOW_TIME_ON_STATUS_BAR.doAction(this, !globalOptions.isShowClockOnStatusBar, globalOptions.isShowClockOnStatusBar) fullScene.setDrawOffPage(globalOptions.isDrawOffPage) - initDialogs() - newTouchProcessor = NewTouchProcessorWithScale(view, this) view.setOnTouchListener{ _, event -> newTouchProcessor!!.onTouch(event) @@ -146,35 +140,6 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } } - private fun initDialogs() { - initOptionDialog() - - initGoToPageScreen() - - initZoomScreen() - - initPageLayoutScreen() - - initAddBookmarkScreen() - } - - fun updatePageLayout() { - val walkOrder = controller!!.direction - val lid = controller!!.layout - (findMyViewById(R.id.layoutGroup) as RadioGroup).check(if (lid == 0) R.id.layout1 else if (lid == 1) R.id.layout2 else R.id.layout3) - //((RadioGroup) findMyViewById(R.id.directionGroup)).check(did == 0 ? R.id.direction1 : did == 1 ? R.id.direction2 : R.id.direction3); - - val group = findMyViewById(R.id.directionGroup) as RadioGroup - for (i in 0 until group.childCount) { - val child = group.getChildAt(i) - if (child is universe.constellation.orion.viewer.android.RadioButton) { - if (walkOrder == child.walkOrder) { - group.check(child.id) - } - } - } - } - internal fun onNewIntentInternal(intent: Intent) { onNewIntent(intent) } @@ -421,78 +386,40 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } } - private fun initGoToPageScreen() { - val pageSeek = findMyViewById(R.id.page_picker_seeker) as SeekBar - - subscriptionManager.addDocListeners(object : DocumentViewAdapter() { - override fun documentOpened(controller: Controller) { - pageSeek.max = controller.pageCount - 1 - } - - override fun pageChanged(newPage: Int, pageCount: Int) { - pageSeek.progress = newPage - } - }) - - + private fun AppCompatDialog.initGoToPageScreen() { + val pageSeeker = findMyViewById(R.id.page_picker_seeker) as SeekBar val pageNumberText = findMyViewById(R.id.page_picker_message) as TextView - pageNumberText.text = 1.toString() - - pageSeek.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - @SuppressLint("SetTextI18n") - override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { - pageNumberText.text = (progress + 1).toString() - } - - override fun onStartTrackingTouch(seekBar: SeekBar) {} - - override fun onStopTrackingTouch(seekBar: SeekBar) {} - }) - val plus = findMyViewById(R.id.page_picker_plus) as ImageButton - plus.setOnClickListener { - if (pageSeek.progress != pageSeek.max) { - pageSeek.incrementProgressBy(1) - } - } - val minus = findMyViewById(R.id.page_picker_minus) as ImageButton - minus.setOnClickListener { - if (pageSeek.progress != 0) { - pageSeek.incrementProgressBy(-1) - } - } + initPageNavControls(this@OrionViewerActivity, pageSeeker, minus, plus, pageNumberText) + initPageNavigationValues(controller, pageSeeker, pageNumberText) + pageNumberText.text = ((controller?.currentPage ?: 0) + 1).toString() - val closePagePeeker = findMyViewById(R.id.page_picker_close) as ImageButton + val closePagePeeker = findMyViewById(R.id.option_dialog_bottom_close) as ImageButton closePagePeeker.setOnClickListener { - onAnimatorCancel() + dismiss() } - val pagePreview = findMyViewById(R.id.page_preview) as ImageButton + val pagePreview = findMyViewById(R.id.option_dialog_bottom_apply) as ImageButton pagePreview.setOnClickListener { - onApplyAction() if (pageNumberText.text.isNotEmpty()) { try { val userPage = Integer.valueOf(pageNumberText.text.toString()) val newPage = MathUtils.clamp(userPage, 1, controller!!.pageCount) - controller!!.drawPage(newPage - 1) + if (newPage != controller?.currentPage) { + controller?.drawPage(newPage - 1, isTapNavigation = true) + pageSeeker.progress = newPage - 1 + } + dismiss() } catch (ex: NumberFormatException) { - showAndLogError(this, "Couldn't parse " + pageNumberText.text, ex) + showAndLogError(this@OrionViewerActivity, "Couldn't parse " + pageNumberText.text, ex) } } } + pageNumberText.requestFocus() } - private fun updatePageSeeker() { - val pageSeek = findMyViewById(R.id.page_picker_seeker) as SeekBar - pageSeek.progress = controller!!.currentPage - val view = findMyViewById(R.id.page_picker_message) as TextView - view.text = (controller!!.currentPage + 1).toString() - view.clearFocus() - view.requestFocus() - } - - private fun initZoomScreen() { + private fun AppCompatDialog.initZoomScreen() { //zoom screen val spinner = findMyViewById(R.id.zoom_spinner) as Spinner val zoomValueAsText = findMyViewById(R.id.zoom_picker_message) as EditText @@ -521,12 +448,12 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } } - val closeZoomPicker = findMyViewById(R.id.zoom_picker_close) as ImageButton + val closeZoomPicker = findMyViewById(R.id.option_dialog_bottom_close) as ImageButton closeZoomPicker.setOnClickListener { - onAnimatorCancel() + dismiss() } - val zoomPreview = findMyViewById(R.id.zoom_preview) as ImageButton + val zoomPreview = findMyViewById(R.id.option_dialog_bottom_apply) as ImageButton zoomPreview.setOnClickListener { onApplyAction() val index = spinner.selectedItemPosition @@ -561,9 +488,10 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT //by width spinner.setSelection(1) + actualizeZoomOptions() } - private fun actualizeZoomOptions() { + private fun AppCompatDialog.actualizeZoomOptions() { val zoomSeek = findMyViewById(R.id.zoom_picker_seeker) as SeekBar val textView = findMyViewById(R.id.zoom_picker_message) as TextView val spinner = findMyViewById(R.id.zoom_spinner) as Spinner @@ -581,57 +509,30 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT spinner.setSelection(spinnerIndex) } - - private fun initPageLayoutScreen() { - val close = findMyViewById(R.id.options_close) as ImageButton - close.setOnClickListener { - onAnimatorCancel() - updatePageLayout() - } - - - val view = findMyViewById(R.id.options_apply) as ImageButton - view.setOnClickListener { - onApplyAction() - val group = findMyViewById(R.id.directionGroup) as RadioGroup - val walkOrderButtonId = group.checkedRadioButtonId - val button = group.findViewById(walkOrderButtonId) as universe.constellation.orion.viewer.android.RadioButton - val lid = (findMyViewById(R.id.layoutGroup) as RadioGroup).checkedRadioButtonId - controller!!.setDirectionAndLayout(button.walkOrder, if (lid == R.id.layout1) 0 else if (lid == R.id.layout2) 1 else 2) - } - - subscriptionManager.addDocListeners(object : DocumentViewAdapter() { - override fun documentOpened(controller: Controller) { - updatePageLayout() - } - }) - } - - - private fun initAddBookmarkScreen() { - val close = findMyViewById(R.id.add_bookmark_close) as ImageButton + private fun AppCompatDialog.initAddBookmarkScreen() { + val close = findMyViewById(R.id.option_dialog_bottom_close) as ImageButton close.setOnClickListener { //main menu - onAnimatorCancel() + dismiss() } - val view = findMyViewById(R.id.add_bookmark_apply) as ImageButton + val view = findMyViewById(R.id.option_dialog_bottom_apply) as ImageButton view.setOnClickListener { val text = findMyViewById(R.id.add_bookmark_text) as EditText try { insertBookmark(controller!!.currentPage, text.text.toString()) - onApplyAction(true) + dismiss() } catch (e: Exception) { e.printStackTrace() - val activity = this@OrionViewerActivity - val buider = createThemedAlertBuilder() - buider.setTitle(activity.resources.getString(R.string.ex_msg_operation_failed)) + analytics.error(e) - val input = EditText(activity) + //TODO show common error dialog + val buider = createThemedAlertBuilder() + buider.setTitle(resources.getString(R.string.ex_msg_operation_failed)) + val input = EditText(this@OrionViewerActivity) input.setText(e.message) buider.setView(input) - buider.setNeutralButton("OK") { dialog, _ -> dialog.dismiss() } buider.create().show() } @@ -655,10 +556,6 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT super.onDestroy() log("onDestroy") destroyController() - - if (dialog != null) { - dialog!!.dismiss() - } orionContext.destroyMainActivity() } @@ -798,12 +695,41 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT return true } - private fun initOptionDialog() { - val dialog = AppCompatDialog(this).also { this.dialog = it } - dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE) - dialog.setContentView(R.layout.options_dialog) - animator = dialog.findViewById(R.id.viewanim) as ViewAnimator? - dialog.setCanceledOnTouchOutside(true) + private fun createOptionDialog(screenId: Int): AppCompatDialog { + val dialog = if (CROP_SCREEN == screenId) { + create(this, controller!!.margins) + } else { + val dialog = AppCompatDialog(this) + dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE) + dialog.setCanceledOnTouchOutside(true) + + when (screenId) { + PAGE_SCREEN -> { + dialog.setContentView(R.layout.goto_dialog) + dialog.initGoToPageScreen() + } + + ZOOM_SCREEN -> { + dialog.setContentView(R.layout.zoom_dialog) + dialog.initZoomScreen() + } + + ADD_BOOKMARK_SCREEN -> { + dialog.setContentView(R.layout.add_bookmark_dialog) + dialog.initAddBookmarkScreen() + } + + else -> errorInDebugOr("Unknown id = $screenId") { return dialog } + } + + dialog.window?.setLayout( + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.WRAP_CONTENT + ) + dialog + } + + return dialog } fun doAction(actionCode: Int) { @@ -817,22 +743,13 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT action.doAction(controller, this, null) } - - override fun findMyViewById(id: Int): View { - return dialog!!.findViewById(id) as View - } - - public override fun onAnimatorCancel() { - dialog!!.cancel() + fun AppCompatDialog.findMyViewById(id: Int): View { + return findViewById(id) as View } - override fun onApplyAction() { - onApplyAction(false) - } - - private fun onApplyAction(close: Boolean) { - if (close || globalOptions.isApplyAndClose) { - onAnimatorCancel() + fun AppCompatDialog.onApplyAction() { + if (globalOptions.isApplyAndClose) { + dismiss() } } @@ -854,7 +771,8 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT val info = lastPageInfo!! var bookId: Long? = orionContext.tempOptions!!.bookId if (bookId == null || bookId == -1L) { - bookId = orionContext.getBookmarkAccessor().insertOrUpdate(info.simpleFileName, info.fileSize) + bookId = orionContext.getBookmarkAccessor() + .insertOrUpdate(info.simpleFileName, info.fileSize) orionContext.tempOptions!!.bookId = bookId } return bookId.toInt().toLong() @@ -863,7 +781,8 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT private fun insertBookmark(page: Int, text: String): Boolean { val id = insertOrGetBookId() if (id != -1L) { - val bokmarkId = orionContext.getBookmarkAccessor().insertOrUpdateBookmark(id, page, text) + val bokmarkId = + orionContext.getBookmarkAccessor().insertOrUpdateBookmark(id, page, text) return bokmarkId != -1L } return false @@ -871,15 +790,15 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT fun doubleClickAction(x: Int, y: Int) { SelectionAutomata.selectText( - this, true, true, selectionAutomata.dialog, - SelectionAutomata.getSelectionRectangle( - x, - y, - 0, - 0, - true, - controller!!.pageLayoutManager - ) + this, true, true, selectionAutomata.dialog, + SelectionAutomata.getSelectionRectangle( + x, + y, + 0, + 0, + true, + controller!!.pageLayoutManager + ) ) } @@ -899,6 +818,7 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } } } + SAVE_FILE_RESULT -> { if (resultCode == Activity.RESULT_OK) { val inputFileIntentData = intent.data @@ -922,41 +842,31 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } processIntentAndCheckPermission(intent ?: return) } + PERMISSION_READ_RESULT -> processIntentAndCheckPermission(intent ?: return) } } fun showOrionDialog(screenId: Int, action: Action?, parameter: Any?) { - if (screenId == CROP_SCREEN) { - val cropDialog = create(this, controller!!.margins) - cropDialog.show() - return - } if (screenId != -1) { - when (screenId) { - PAGE_LAYOUT_SCREEN -> { - updatePageLayout() - updatePageSeeker() - } - PAGE_SCREEN -> updatePageSeeker() - ZOOM_SCREEN -> actualizeZoomOptions() - } + val dialog = createOptionDialog(screenId) if (action === Action.ADD_BOOKMARK) { val parameterText = parameter as String? val page = controller!!.currentPage - val newText = orionContext.getBookmarkAccessor().selectExistingBookmark(bookId, page, parameterText) + val newText = orionContext.getBookmarkAccessor() + .selectExistingBookmark(bookId, page, parameterText) val notOverride = parameterText == null || parameterText == newText - findMyViewById(R.id.warn_text_override).visibility = if (notOverride) View.GONE else View.VISIBLE + dialog.findMyViewById(R.id.warn_text_override).visibility = + if (notOverride) View.GONE else View.VISIBLE - (findMyViewById(R.id.add_bookmark_text) as EditText).setText(if (notOverride) newText else parameterText) + (dialog.findMyViewById(R.id.add_bookmark_text) as EditText).setText(if (notOverride) newText else parameterText) } - animator!!.displayedChild = screenId - 1 - dialog!!.show() + dialog.show() } } @@ -966,12 +876,16 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } private class MyArrayAdapter(context: Context) : - ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, context.resources.getTextArray(R.array.fits)), SpinnerAdapter { + ArrayAdapter( + context, + R.layout.support_simple_spinner_dropdown_item, + context.resources.getTextArray(R.array.fits) + ), SpinnerAdapter { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View = - convertView ?: TextView(parent.context).apply { - text = " % " - } + convertView ?: TextView(parent.context).apply { + text = " % " + } } private suspend fun askPassword(controller: Controller): Boolean { @@ -1022,7 +936,12 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT globalOptions.saveBooleanProperty(GlobalOptions.SHOW_TAP_HELP, false) analytics.dialog(TAP_HELP_DIALOG, true) } - controller?.drawPage(lastPageInfo1.pageNumber, lastPageInfo1.newOffsetX, lastPageInfo1.newOffsetY, lastPageInfo1.isSinglePageMode) + controller?.drawPage( + lastPageInfo1.pageNumber, + lastPageInfo1.newOffsetX, + lastPageInfo1.newOffsetY, + lastPageInfo1.isSinglePageMode + ) controller?.pageLayoutManager?.updateCacheAndRender() } } @@ -1050,8 +969,10 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } if (intent.hasExtra(GlobalOptions.TEST_SCREEN_WIDTH) && intent.hasExtra(GlobalOptions.TEST_SCREEN_HEIGHT)) { - val newWidth = intent.getIntExtra(GlobalOptions.TEST_SCREEN_WIDTH, view.layoutParams.width) - val newHeigth = intent.getIntExtra(GlobalOptions.TEST_SCREEN_HEIGHT, view.layoutParams.height) + val newWidth = + intent.getIntExtra(GlobalOptions.TEST_SCREEN_WIDTH, view.layoutParams.width) + val newHeigth = + intent.getIntExtra(GlobalOptions.TEST_SCREEN_HEIGHT, view.layoutParams.height) view.layoutParams.width = newWidth view.layoutParams.height = newHeigth view.requestLayout() @@ -1151,7 +1072,8 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT private fun showErrorPanel(show: Boolean) { invalidateOptionsMenu() - findViewById(R.id.orion_full_scene)!!.visibility = if (!show) View.VISIBLE else View.INVISIBLE + findViewById(R.id.orion_full_scene)!!.visibility = + if (!show) View.VISIBLE else View.INVISIBLE findViewById(R.id.problem_view)!!.visibility = if (show) View.VISIBLE else View.GONE if (show) { view.pageLayoutManager = null @@ -1160,16 +1082,17 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT companion object { - val BOOK_MENU_ITEMS = setOf(R.id.search_menu_item, - R.id.crop_menu_item, - R.id.zoom_menu_item, - R.id.add_bookmark_menu_item, - R.id.goto_menu_item, - R.id.select_text_menu_item, - R.id.book_options_menu_item, - R.id.outline_menu_item, - R.id.bookmarks_menu_item, - R.id.open_dictionary_menu_item + val BOOK_MENU_ITEMS = setOf( + R.id.search_menu_item, + R.id.crop_menu_item, + R.id.zoom_menu_item, + R.id.add_bookmark_menu_item, + R.id.goto_menu_item, + R.id.select_text_menu_item, + R.id.book_options_menu_item, + R.id.outline_menu_item, + R.id.bookmarks_menu_item, + R.id.open_dictionary_menu_item ) const val OPEN_BOOKMARK_ACTIVITY_RESULT = 1 @@ -1178,17 +1101,13 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT const val PERMISSION_READ_RESULT = Permissions.ASK_READ_PERMISSION_FOR_BOOK_OPEN - const val ROTATION_SCREEN = 0 - - const val PAGE_SCREEN = 1 - - const val ZOOM_SCREEN = 2 + const val PAGE_SCREEN = 0 - const val CROP_SCREEN = 3 + const val ZOOM_SCREEN = 1 - const val PAGE_LAYOUT_SCREEN = 4 + const val CROP_SCREEN = 2 - const val ADD_BOOKMARK_SCREEN = 5 + const val ADD_BOOKMARK_SCREEN = 3 const val CROP_RESTRICTION_MIN = -10 diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/CropDialogBuilder.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/CropDialogBuilder.kt index 6f3a276e8..e9fd9ecbf 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/CropDialogBuilder.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/CropDialogBuilder.kt @@ -16,7 +16,7 @@ fun CropMargins.toDialogMargins() = intArrayOf(left, right, top, bottom, evenLef fun IntArray.toMargins(evenCrop: Boolean, cropMode: Int) = CropMargins(this[0], this[1], this[2], this[3], this[4], this[5], evenCrop, cropMode) -class CropDialog(cropMargins: CropMargins, val context: OrionViewerActivity) : AppCompatDialog(context) { +class CropDialog(cropMargins: CropMargins, val activity: OrionViewerActivity) : AppCompatDialog(activity) { private val cropMargins = cropMargins.toDialogMargins() private val evenCrop = cropMargins.evenCrop @@ -94,18 +94,21 @@ class CropDialog(cropMargins: CropMargins, val context: OrionViewerActivity) : A } } - val preview = findViewById(R.id.crop_preview) as ImageButton + val preview = findViewById(R.id.option_dialog_bottom_apply) as ImageButton val radioGroup = findViewById(R.id.crop_mode) as RadioGroup preview.setOnClickListener { - context.onAnimatorCancel() + with(activity) { + this@CropDialog.onApplyAction() + } + val radioButtonId = radioGroup.checkedRadioButtonId val radioButton = radioGroup.findViewById(radioButtonId) val mode = radioGroup.indexOfChild(radioButton) - context.controller?.changeCropMargins(cropMargins.toMargins(checkBox.isChecked, mode)) + activity.controller?.changeCropMargins(cropMargins.toMargins(checkBox.isChecked, mode)) } - val close = findViewById(R.id.crop_close) as ImageButton + val close = findViewById(R.id.option_dialog_bottom_close) as ImageButton close.setOnClickListener { dismiss() } diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/OrionKeyBinderActivity.java b/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/OrionKeyBinderActivity.java index d4402714f..d079663f6 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/OrionKeyBinderActivity.java +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/OrionKeyBinderActivity.java @@ -62,9 +62,9 @@ protected void onCreate(Bundle savedInstanceState) { adapter.clear(); }); - statusText = (TextView) findMyViewById(R.id.key_binder_message); + statusText = findViewById(R.id.key_binder_message); defaultColor = statusText.getTextColors().getDefaultColor(); - bindedKeys = (ListView) findMyViewById(R.id.binded_keys); + bindedKeys = findViewById(R.id.binded_keys); Map props = (Map) getOrionContext().getKeyBinding().getAllProperties(); adapter = new KeyListAdapter(this, props); bindedKeys.setAdapter(adapter); diff --git a/orion-viewer/src/main/res/layout-sw600dp/options_dialog.xml b/orion-viewer/src/main/res/layout-sw600dp/options_dialog.xml deleted file mode 100644 index 9db029204..000000000 --- a/orion-viewer/src/main/res/layout-sw600dp/options_dialog.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/orion-viewer/src/main/res/layout/add_bookmark.xml b/orion-viewer/src/main/res/layout/add_bookmark_dialog.xml similarity index 68% rename from orion-viewer/src/main/res/layout/add_bookmark.xml rename to orion-viewer/src/main/res/layout/add_bookmark_dialog.xml index 1a4d330cf..cad66b535 100644 --- a/orion-viewer/src/main/res/layout/add_bookmark.xml +++ b/orion-viewer/src/main/res/layout/add_bookmark_dialog.xml @@ -6,7 +6,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_gravity="center" android:gravity="center" - android:orientation="vertical"> + android:orientation="vertical" + android:padding="@dimen/root_padding"> - - - - - - + \ No newline at end of file diff --git a/orion-viewer/src/main/res/layout/crop_dialog.xml b/orion-viewer/src/main/res/layout/crop_dialog.xml index 992f85c7e..b4af6da4e 100644 --- a/orion-viewer/src/main/res/layout/crop_dialog.xml +++ b/orion-viewer/src/main/res/layout/crop_dialog.xml @@ -50,24 +50,8 @@ - + - - - - \ No newline at end of file diff --git a/orion-viewer/src/main/res/layout/dialog_animator.xml b/orion-viewer/src/main/res/layout/dialog_animator.xml deleted file mode 100644 index f509f81c1..000000000 --- a/orion-viewer/src/main/res/layout/dialog_animator.xml +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/orion-viewer/src/main/res/layout/goto_dialog.xml b/orion-viewer/src/main/res/layout/goto_dialog.xml new file mode 100644 index 000000000..ca8062cb2 --- /dev/null +++ b/orion-viewer/src/main/res/layout/goto_dialog.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/orion-viewer/src/main/res/layout/option_dialog_bottom_panel.xml b/orion-viewer/src/main/res/layout/option_dialog_bottom_panel.xml new file mode 100644 index 000000000..bebb5aab1 --- /dev/null +++ b/orion-viewer/src/main/res/layout/option_dialog_bottom_panel.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/orion-viewer/src/main/res/layout/options_dialog.xml b/orion-viewer/src/main/res/layout/options_dialog.xml deleted file mode 100644 index c84a8d941..000000000 --- a/orion-viewer/src/main/res/layout/options_dialog.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/orion-viewer/src/main/res/layout/zoom_dialog.xml b/orion-viewer/src/main/res/layout/zoom_dialog.xml new file mode 100644 index 000000000..1332de97c --- /dev/null +++ b/orion-viewer/src/main/res/layout/zoom_dialog.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file