|
1 | 1 | package com.hackware.mormont.notebook |
2 | 2 |
|
3 | | -import android.support.v7.app.AppCompatActivity |
| 3 | +import android.annotation.SuppressLint |
| 4 | +import androidx.appcompat.app.AppCompatActivity |
| 5 | +import android.content.res.Configuration |
4 | 6 | import android.os.Bundle |
| 7 | +import android.view.MotionEvent |
| 8 | +import android.view.View |
| 9 | +import org.wordpress.android.util.ToastUtils |
| 10 | +import org.wordpress.aztec.Aztec |
| 11 | +import org.wordpress.aztec.AztecText |
| 12 | +import org.wordpress.aztec.IHistoryListener |
| 13 | +import org.wordpress.aztec.ITextFormat |
| 14 | +import org.wordpress.aztec.plugins.CssUnderlinePlugin |
| 15 | +import org.wordpress.aztec.source.SourceViewEditText |
| 16 | +import org.wordpress.aztec.toolbar.AztecToolbar |
| 17 | +import org.wordpress.aztec.toolbar.IAztecToolbarClickListener |
| 18 | +import org.xml.sax.Attributes |
5 | 19 |
|
6 | | -class Editor : AppCompatActivity() { |
| 20 | + |
| 21 | +open class Editor : AppCompatActivity(), |
| 22 | + View.OnTouchListener, |
| 23 | + IHistoryListener, |
| 24 | + IAztecToolbarClickListener { |
| 25 | + |
| 26 | + |
| 27 | + override fun onUndoEnabled() { |
| 28 | + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
| 29 | + } |
| 30 | + |
| 31 | + override fun onRedoEnabled() { |
| 32 | + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
| 33 | + } |
| 34 | + |
| 35 | + protected lateinit var aztec: Aztec |
| 36 | + |
| 37 | + private var mIsKeyboardOpen = true |
| 38 | + private var mHideActionBarOnSoftKeyboardUp = false |
| 39 | + |
| 40 | + @SuppressLint("ClickableViewAccessibility") |
| 41 | + override fun onTouch(v: View, event: MotionEvent): Boolean { |
| 42 | + if (event.action == MotionEvent.ACTION_UP) { |
| 43 | + // If the WebView or EditText has received a touch event, the keyboard will be displayed and the action bar |
| 44 | + // should hide |
| 45 | + mIsKeyboardOpen = true |
| 46 | + hideActionBarIfNeeded() |
| 47 | + } |
| 48 | + return false } |
7 | 49 |
|
8 | 50 | override fun onCreate(savedInstanceState: Bundle?) { |
9 | 51 | super.onCreate(savedInstanceState) |
10 | 52 | setContentView(R.layout.activity_editor) |
11 | 53 |
|
| 54 | + if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 55 | + mHideActionBarOnSoftKeyboardUp = true |
| 56 | + } |
| 57 | + val visualEditor = findViewById<AztecText>(R.id.aztec) |
| 58 | + val toolbar = findViewById<AztecToolbar>(R.id.formatting_toolbar) |
| 59 | + |
| 60 | + |
| 61 | + aztec = Aztec.with(visualEditor, toolbar, this) |
| 62 | + .setOnTouchListener(this) |
| 63 | + |
| 64 | + // aztec.visualEditor.setCalypsoMode(true) |
| 65 | + |
| 66 | + aztec.addPlugin(CssUnderlinePlugin()) |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + override fun onPause() { |
| 71 | + super.onPause() |
| 72 | + mIsKeyboardOpen = false |
| 73 | + } |
| 74 | + |
| 75 | + override fun onResume() { |
| 76 | + super.onResume() |
| 77 | + |
| 78 | + showActionBarIfNeeded() |
| 79 | + } |
| 80 | + |
| 81 | + override fun onBackPressed() { |
| 82 | + mIsKeyboardOpen = false |
| 83 | + showActionBarIfNeeded() |
| 84 | + |
| 85 | + return super.onBackPressed() |
| 86 | + } |
| 87 | + |
| 88 | + private fun isHardwareKeyboardPresent(): Boolean { |
| 89 | + val config = resources.configuration |
| 90 | + var returnValue = false |
| 91 | + if (config.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 92 | + returnValue = true |
| 93 | + } |
| 94 | + return returnValue |
| 95 | + } |
| 96 | + |
| 97 | + private fun hideActionBarIfNeeded() { |
| 98 | + |
| 99 | + val actionBar = supportActionBar |
| 100 | + if (actionBar != null |
| 101 | + && !isHardwareKeyboardPresent() |
| 102 | + && mHideActionBarOnSoftKeyboardUp |
| 103 | + && mIsKeyboardOpen |
| 104 | + && actionBar.isShowing) { |
| 105 | + actionBar.hide() |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Show the action bar if needed. |
| 111 | + */ |
| 112 | + private fun showActionBarIfNeeded() { |
| 113 | + |
| 114 | + val actionBar = supportActionBar |
| 115 | + if (actionBar != null && !actionBar.isShowing) { |
| 116 | + actionBar.show() |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + override fun onToolbarCollapseButtonClicked() { |
| 121 | + } |
| 122 | + |
| 123 | + override fun onToolbarExpandButtonClicked() { |
| 124 | + } |
| 125 | + |
| 126 | + override fun onToolbarFormatButtonClicked(format: ITextFormat, isKeyboardShortcut: Boolean) { |
| 127 | + } |
| 128 | + |
| 129 | + override fun onToolbarHeadingButtonClicked() { |
| 130 | + } |
| 131 | + |
| 132 | + override fun onToolbarHtmlButtonClicked() { |
| 133 | + } |
| 134 | + |
| 135 | + override fun onToolbarListButtonClicked() { |
| 136 | + } |
| 137 | + |
| 138 | + override fun onToolbarMediaButtonClicked(): Boolean { |
| 139 | + return false |
12 | 140 | } |
13 | 141 | } |
| 142 | + |
| 143 | + |
0 commit comments