Skip to content

Commit 6371f9a

Browse files
committed
editor added
1 parent 2f382bf commit 6371f9a

File tree

2 files changed

+203
-17
lines changed

2 files changed

+203
-17
lines changed
Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,143 @@
11
package com.hackware.mormont.notebook
22

3-
import android.support.v7.app.AppCompatActivity
3+
import android.annotation.SuppressLint
4+
import androidx.appcompat.app.AppCompatActivity
5+
import android.content.res.Configuration
46
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
519

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 }
749

850
override fun onCreate(savedInstanceState: Bundle?) {
951
super.onCreate(savedInstanceState)
1052
setContentView(R.layout.activity_editor)
1153

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
12140
}
13141
}
142+
143+
Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,73 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
tools:context=".Editor">
8-
<android.support.design.widget.AppBarLayout android:layout_width="wrap_content"
9-
android:layout_height="wrap_content">
10-
<android.support.v7.widget.Toolbar
11-
android:layout_width="wrap_content"
12-
android:layout_height="wrap_content"
2+
3+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:aztec="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
6+
android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto">
7+
8+
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
9+
android:layout_alignParentTop="true"
10+
android:id="@+id/linlau">
11+
<androidx.appcompat.widget.Toolbar
12+
android:id="@+id/toolbar"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent"
1315
android:layout_margin="10dp"
14-
>
15-
</android.support.v7.widget.Toolbar>
16-
</android.support.design.widget.AppBarLayout>
17-
</android.support.constraint.ConstraintLayout>
16+
app:theme="@style/CustomToolbar"
17+
app:title="@string/app_name"
18+
android:elevation="10dp">
19+
</androidx.appcompat.widget.Toolbar>
20+
</LinearLayout>
21+
<org.wordpress.aztec.toolbar.AztecToolbar
22+
android:id="@+id/formatting_toolbar"
23+
android:layout_width="match_parent"
24+
android:layout_height="@dimen/aztec_format_bar_height"
25+
android:layout_alignParentBottom="true">
26+
</org.wordpress.aztec.toolbar.AztecToolbar>
27+
28+
<ScrollView
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:layout_above="@+id/formatting_toolbar"
32+
android:fillViewport="true" android:layout_alignParentStart="true"
33+
android:layout_below="@+id/title">
34+
35+
<FrameLayout
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content">
38+
39+
<org.wordpress.aztec.AztecText
40+
android:id="@+id/aztec"
41+
android:layout_width="match_parent"
42+
android:layout_height="match_parent"
43+
android:layout_marginStart="20dp"
44+
android:layout_marginEnd="10dp"
45+
android:gravity="top|start"
46+
android:hint="@string/NoteEditorHint"
47+
android:paddingEnd="16dp"
48+
android:paddingLeft="16dp"
49+
android:paddingRight="16dp"
50+
android:paddingTop="16dp"
51+
android:scrollbars="vertical"
52+
android:imeOptions="flagNoExtractUi"
53+
aztec:historyEnable="true"
54+
aztec:historySize="10"
55+
aztec:textColor="@color/primaryTextColor"
56+
aztec:bulletColor="@color/primaryLightColor"/>
57+
</FrameLayout>
58+
59+
</ScrollView>
60+
61+
<EditText
62+
android:layout_width="match_parent"
63+
android:layout_height="wrap_content"
64+
android:layout_marginStart="20dp"
65+
android:layout_marginEnd="10dp"
66+
android:imeOptions="flagNavigateNext"
67+
android:textStyle="bold"
68+
android:backgroundTint="@android:color/transparent"
69+
android:inputType="textCapSentences|textMultiLine"
70+
android:hint="@string/titleHint"
71+
android:layout_alignParentStart="true" android:layout_below="@+id/linlau"
72+
android:id="@+id/title" tools:ignore="Autofill"/>
73+
</RelativeLayout>

0 commit comments

Comments
 (0)