This commit is contained in:
Mariotaku Lee 2017-04-04 12:37:44 +08:00
parent ab96713b8e
commit add7cf309d
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 54 additions and 20 deletions

View File

@ -30,6 +30,7 @@ import android.content.DialogInterface
import android.content.Intent
import android.graphics.Canvas
import android.graphics.PorterDuff.Mode
import android.graphics.Rect
import android.location.*
import android.net.Uri
import android.os.AsyncTask
@ -54,7 +55,6 @@ import android.view.View.OnClickListener
import android.view.View.OnLongClickListener
import android.view.animation.DecelerateInterpolator
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import com.bumptech.glide.Glide
import com.twitter.Extractor
@ -559,13 +559,11 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
when (ev.actionMasked) {
MotionEvent.ACTION_DOWN -> {
val x = ev.rawX
val y = ev.rawY
if (isAccountSelectorVisible && !TwidereViewUtils.hitView(x, y, accountSelectorButton)) {
if (isAccountSelectorVisible && !TwidereViewUtils.hitView(ev, accountSelectorButton)) {
var clickedItem = false
val layoutManager = accountSelector.layoutManager
for (i in 0..layoutManager.childCount - 1) {
if (TwidereViewUtils.hitView(x, y, layoutManager.getChildAt(i))) {
if (TwidereViewUtils.hitView(ev, layoutManager.getChildAt(i))) {
clickedItem = true
break
}
@ -582,10 +580,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN) {
val x = event.rawX
val y = event.rawY
val window = window
if (!TwidereViewUtils.hitView(x, y, window.decorView)
if (!TwidereViewUtils.hitView(event, window.decorView)
&& window.peekDecorView() != null && !hasComposingStatus()) {
onBackPressed()
return true
@ -833,6 +829,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
})
editText.customSelectionActionModeCallback = this
editTextContainer.touchDelegate = ComposeEditTextTouchDelegate(editTextContainer, editText)
}
override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean {
@ -1365,6 +1362,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
}
override fun onSetAltText(position: Int, altText: String?) {
mediaPreviewAdapter.setAltText(position, altText)
}
private fun setRecentLocation(location: ParcelableLocation?) {
if (location != null) {
val attachPreciseLocation = kPreferences[attachPreciseLocationKey]
@ -1869,10 +1870,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
internal class NoAddress
}
override fun onSetAltText(position: Int, altText: String?) {
mediaPreviewAdapter.setAltText(position, altText)
}
class RetweetProtectedStatusWarnFragment : BaseDialogFragment(), DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface, which: Int) {
@ -1995,6 +1992,38 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
}
private class ComposeEditTextTouchDelegate(
val parentView: View, val delegateView: View
) : TouchDelegate(Rect(), delegateView) {
private var delegateTargeted: Boolean = false
override fun onTouchEvent(event: MotionEvent): Boolean {
var sendToDelegate = false
var handled = false
when (event.action) {
MotionEvent.ACTION_DOWN -> {
if (TwidereViewUtils.hitView(event, parentView)) {
delegateTargeted = true
sendToDelegate = true
}
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_MOVE -> {
sendToDelegate = delegateTargeted
}
MotionEvent.ACTION_CANCEL -> {
sendToDelegate = delegateTargeted
delegateTargeted = false
}
}
if (sendToDelegate) {
handled = delegateView.dispatchTouchEvent(event)
}
return handled
}
}
companion object {
// Constants

View File

@ -597,7 +597,7 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks<AccountsInfo>,
fun shouldDisableDrawerSlide(e: MotionEvent): Boolean {
if (accountsSelector == null) return false
return TwidereViewUtils.hitView(e.rawX, e.rawY, accountsSelector)
return TwidereViewUtils.hitView(e, accountsSelector)
}
internal class AccountSpaceViewHolder(itemView: View) : RecyclerPagerAdapter.ViewHolder(itemView)

View File

@ -1,6 +1,8 @@
package org.mariotaku.twidere.util
import android.graphics.RectF
import android.support.annotation.UiThread
import android.view.MotionEvent
import android.view.View
/**
@ -8,11 +10,14 @@ import android.view.View
*/
object TwidereViewUtils {
private val location = IntArray(2)
private val rect = RectF()
@UiThread
fun hitView(x: Float, y: Float, view: View): Boolean {
val location = IntArray(2)
fun hitView(event: MotionEvent, view: View): Boolean {
view.getLocationOnScreen(location)
return x in (location[0] until location[0] + view.width)
&& y in (location[1] until location[1] + view.height)
rect.set(location[0].toFloat(), location[1].toFloat(), location[0].toFloat() + view.width,
location[1].toFloat() + view.height)
return rect.contains(event.rawX, event.rawY)
}
}

View File

@ -33,7 +33,6 @@
android:layout_weight="1">
<org.mariotaku.twidere.view.MaxHeightScrollView
android:id="@+id/editTextContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="240dp">
@ -53,7 +52,8 @@
android:padding="@dimen/element_spacing_normal"
tools:text="In reply to name: A quick brown fox jumps over the lazy dog"/>
<LinearLayout
<org.mariotaku.twidere.view.ExtendedLinearLayout
android:id="@+id/editTextContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="160dp"
@ -101,7 +101,7 @@
app:iabIconWidth="20dp"
tools:text="11.4, 51.4"/>
</LinearLayout>
</org.mariotaku.twidere.view.ExtendedLinearLayout>
</LinearLayout>
</org.mariotaku.twidere.view.MaxHeightScrollView>