Skip to content

Commit 76e9c03

Browse files
Merge branch 'trunk' into feature/background-color-span-support-v3-upstream
2 parents a583de2 + 8ce8c78 commit 76e9c03

30 files changed

+926
-153
lines changed

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ agents:
66
common_params:
77
# Common plugin settings to use with the `plugins` key.
88
- &common_plugins
9-
- automattic/bash-cache#2.11.0
9+
- automattic/a8c-ci-toolkit#2.14.0
1010

1111
steps:
1212
- label: "Gradle Wrapper Validation"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
Aztec (which extends EditText) is a rich-text editor component for writing HTML
66
documents in Android.
77

8-
Supports Android 4.1+ (API 16 - Jelly Bean)
8+
## Minimum Android Supported Version
9+
10+
You can check the minimum Android version supported by looking at the `minSdkVersion` configuration within [build.gradle](https://github.com/wordpress-mobile/AztecEditor-Android/blob/trunk/build.gradle).
911

1012
<img align="center" width=360px height=640px src="https://github.com/wordpress-mobile/AztecEditor-Android/raw/trunk/visual_editor.png" alt="Visual Editor"/> <img align="center" width=360px height=640px src="https://github.com/wordpress-mobile/AztecEditor-Android/raw/trunk/code_editor.png" alt="Visual Editor"/>
1113

app/src/main/AndroidManifest.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77

88
<!-- Required for adding media and requested at runtime -->
99
<uses-permission android:name="android.permission.CAMERA" />
10-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
10+
<!-- Allows for storing and retrieving screenshots, photos, videos and audios -->
11+
<uses-permission
12+
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
13+
android:maxSdkVersion="29" />
14+
<uses-permission
15+
android:name="android.permission.READ_EXTERNAL_STORAGE"
16+
android:maxSdkVersion="32" />
17+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
18+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
19+
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
1120

1221
<application
1322
android:label="@string/app_name"
@@ -44,4 +53,12 @@
4453

4554
</application>
4655

56+
<queries>
57+
<intent>
58+
<action android:name="android.intent.action.MAIN" />
59+
</intent>
60+
<!-- required for Android 11 (API level 30) or higher -->
61+
<package android:name="com.wordpress.aztec" />
62+
</queries>
63+
4764
</manifest>

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ import android.graphics.drawable.BitmapDrawable
1414
import android.graphics.drawable.ColorDrawable
1515
import android.graphics.drawable.Drawable
1616
import android.net.Uri
17+
import android.os.Build
1718
import android.os.Bundle
1819
import android.os.Environment
1920
import android.os.Handler
21+
import android.os.Looper
2022
import android.provider.MediaStore
2123
import android.util.DisplayMetrics
24+
import android.util.Log
2225
import android.view.Gravity
2326
import android.view.Menu
2427
import android.view.MenuItem
2528
import android.view.MotionEvent
2629
import android.view.View
2730
import android.widget.PopupMenu
2831
import android.widget.ToggleButton
32+
import androidx.activity.OnBackPressedCallback
2933
import androidx.appcompat.app.AlertDialog
3034
import androidx.appcompat.app.AppCompatActivity
3135
import androidx.appcompat.content.res.AppCompatResources
@@ -265,6 +269,7 @@ open class MainActivity : AppCompatActivity(),
265269
val options = BitmapFactory.Options()
266270
options.inDensity = DisplayMetrics.DENSITY_DEFAULT
267271
val bitmap = BitmapFactory.decodeFile(mediaPath, options)
272+
Log.d("MediaPath", mediaPath)
268273
insertImageAndSimulateUpload(bitmap, mediaPath)
269274
}
270275
REQUEST_MEDIA_PHOTO -> {
@@ -377,11 +382,11 @@ open class MainActivity : AppCompatActivity(),
377382
}
378383
}
379384

380-
Handler().post(runnable)
381-
Handler().postDelayed(runnable, 2000)
382-
Handler().postDelayed(runnable, 4000)
383-
Handler().postDelayed(runnable, 6000)
384-
Handler().postDelayed(runnable, 8000)
385+
Handler(Looper.getMainLooper()).post(runnable)
386+
Handler(Looper.getMainLooper()).postDelayed(runnable, 2000)
387+
Handler(Looper.getMainLooper()).postDelayed(runnable, 4000)
388+
Handler(Looper.getMainLooper()).postDelayed(runnable, 6000)
389+
Handler(Looper.getMainLooper()).postDelayed(runnable, 8000)
385390

386391
aztec.visualEditor.refreshText()
387392
}
@@ -390,6 +395,20 @@ open class MainActivity : AppCompatActivity(),
390395
super.onCreate(savedInstanceState)
391396
setContentView(R.layout.activity_main)
392397

398+
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
399+
override fun handleOnBackPressed() {
400+
mIsKeyboardOpen = false
401+
showActionBarIfNeeded()
402+
403+
// Disable the callback temporarily to allow the system to handle the back pressed event. This usage
404+
// breaks predictive back gesture behavior and should be reviewed before enabling the predictive back
405+
// gesture feature.
406+
isEnabled = false
407+
onBackPressedDispatcher.onBackPressed()
408+
isEnabled = true
409+
}
410+
})
411+
393412
// Setup hiding the action bar when the soft keyboard is displayed for narrow viewports
394413
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
395414
&& !resources.getBoolean(R.bool.is_large_tablet_landscape)) {
@@ -486,7 +505,7 @@ open class MainActivity : AppCompatActivity(),
486505
aztec.initSourceEditorHistory()
487506
}
488507

489-
invalidateOptionsHandler = Handler()
508+
invalidateOptionsHandler = Handler(Looper.getMainLooper())
490509
invalidateOptionsRunnable = Runnable { invalidateOptionsMenu() }
491510
}
492511

@@ -520,15 +539,13 @@ open class MainActivity : AppCompatActivity(),
520539
}
521540
}
522541

523-
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
542+
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
524543
super.onRestoreInstanceState(savedInstanceState)
525544

526545
aztec.initSourceEditorHistory()
527546

528-
savedInstanceState?.let {
529-
if (savedInstanceState.getBoolean("isMediaUploadDialogVisible")) {
530-
showMediaUploadDialog()
531-
}
547+
if (savedInstanceState.getBoolean("isMediaUploadDialogVisible")) {
548+
showMediaUploadDialog()
532549
}
533550
}
534551

@@ -586,13 +603,6 @@ open class MainActivity : AppCompatActivity(),
586603
return false
587604
}
588605

589-
override fun onBackPressed() {
590-
mIsKeyboardOpen = false
591-
showActionBarIfNeeded()
592-
593-
return super.onBackPressed()
594-
}
595-
596606
/**
597607
* Intercept back button press while soft keyboard is visible.
598608
*/
@@ -651,9 +661,20 @@ open class MainActivity : AppCompatActivity(),
651661
if (PermissionUtils.checkAndRequestCameraAndStoragePermissions(this, MEDIA_CAMERA_PHOTO_PERMISSION_REQUEST_CODE)) {
652662
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
653663

654-
mediaFile = "wp-" + System.currentTimeMillis() + ".jpg"
655-
mediaPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() +
656-
File.separator + "Camera" + File.separator + mediaFile
664+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
665+
mediaFile = "wp-" + System.currentTimeMillis()
666+
mediaPath = File.createTempFile(
667+
mediaFile,
668+
".jpg",
669+
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
670+
).absolutePath
671+
672+
} else {
673+
mediaFile = "wp-" + System.currentTimeMillis() + ".jpg"
674+
@Suppress("DEPRECATION")
675+
mediaPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() +
676+
File.separator + "Camera" + File.separator + mediaFile
677+
}
657678
intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(this,
658679
BuildConfig.APPLICATION_ID + ".provider", File(mediaPath)))
659680

aztec/src/main/kotlin/org/wordpress/aztec/Aztec.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ open class Aztec private constructor(
3636
onMediaDeletedListeners.forEach { it.beforeMediaDeleted(attrs) }
3737
}
3838
}
39+
private var beforeBackSpaceListeners: MutableList<AztecText.BeforeBackSpaceListener> = mutableListOf()
40+
private val beforeBackSpaceListener = object : AztecText.BeforeBackSpaceListener {
41+
override fun shouldOverrideBackSpace(position: Int): Boolean {
42+
return beforeBackSpaceListeners.any { it.shouldOverrideBackSpace(position) }
43+
}
44+
}
3945
private var onVideoInfoRequestedListener: AztecText.OnVideoInfoRequestedListener? = null
4046
private var onLinkTappedListener: AztecText.OnLinkTappedListener? = null
4147
private var isLinkTapEnabled: Boolean = false
@@ -145,6 +151,12 @@ open class Aztec private constructor(
145151
return this
146152
}
147153

154+
fun addBeforeBackSpaceListener(beforeBackSpaceListener: AztecText.BeforeBackSpaceListener): Aztec {
155+
this.beforeBackSpaceListeners.add(beforeBackSpaceListener)
156+
initBeforeBackSpaceListener()
157+
return this
158+
}
159+
148160
fun setOnVideoInfoRequestedListener(onVideoInfoRequestedListener: AztecText.OnVideoInfoRequestedListener): Aztec {
149161
this.onVideoInfoRequestedListener = onVideoInfoRequestedListener
150162
initVideoInfoRequestedListener()
@@ -253,6 +265,10 @@ open class Aztec private constructor(
253265
visualEditor.setOnMediaDeletedListener(onMediaDeletedListener)
254266
}
255267

268+
private fun initBeforeBackSpaceListener() {
269+
visualEditor.setBeforeBackSpaceListener(beforeBackSpaceListener)
270+
}
271+
256272
private fun initVideoInfoRequestedListener() {
257273
if (onVideoInfoRequestedListener != null) {
258274
visualEditor.setOnVideoInfoRequestedListener(onVideoInfoRequestedListener!!)

0 commit comments

Comments
 (0)