Add custom text selection action to compose tweet from selected text

This commit is contained in:
Falih Mulyana 2020-08-28 23:36:18 +07:00
parent e324d849fc
commit 64c93b3ed9
2 changed files with 14 additions and 0 deletions

View File

@ -249,6 +249,13 @@
<data android:mimeType="image/*"/>
<data android:mimeType="text/plain"/>
</intent-filter>
<intent-filter android:label="@string/title_compose">
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"

View File

@ -32,6 +32,7 @@ import android.graphics.Canvas
import android.graphics.Rect
import android.location.*
import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.core.app.ActivityCompat
import androidx.core.widget.TextViewCompat
@ -1145,6 +1146,12 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
} else {
editText.setSelection(selection.coerceIn(0..editText.length()))
}
if (intent.hasExtra(Intent.EXTRA_PROCESS_TEXT) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
val charSequences = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT)
charSequences?.let {
editText.setText(it.toString())
}
}
editText.requestFocus()
return true
}