mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 16:40:32 +00:00
Use a custom EditText everywhere to be able to share with ShareUtils the selected text
This EditText class extends the AppCompatEditText class from androidx. These changes (only in XML ressources) allow us to share the selected text by using ShareUtils.shareText, which opens the Android system chooser instead of the Huawei system chooser on EMUI devices.
This commit is contained in:
parent
a55acd38df
commit
411b3129f9
@ -0,0 +1,60 @@
|
|||||||
|
package org.schabi.newpipe.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.Selection;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.widget.AppCompatEditText;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||||
|
|
||||||
|
public class NewPipeEditText extends AppCompatEditText {
|
||||||
|
public NewPipeEditText(@NonNull final Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NewPipeEditText(@NonNull final Context context, @Nullable final AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NewPipeEditText(@NonNull final Context context,
|
||||||
|
@Nullable final AttributeSet attrs,
|
||||||
|
final int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTextContextMenuItem(final int id) {
|
||||||
|
final Spannable text = getText();
|
||||||
|
if (id == android.R.id.shareText) {
|
||||||
|
if (text != null) {
|
||||||
|
final String selectedText = getSelectedText(text).toString();
|
||||||
|
if (!selectedText.isEmpty()) {
|
||||||
|
ShareUtils.shareText(getContext(), "", selectedText);
|
||||||
|
}
|
||||||
|
Selection.setSelection(text, getSelectionEnd());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.onTextContextMenuItem(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private CharSequence getSelectedText(@NonNull final CharSequence charSequence) {
|
||||||
|
int min = 0;
|
||||||
|
int max = charSequence.length();
|
||||||
|
|
||||||
|
if (isFocused()) {
|
||||||
|
final int selStart = getSelectionStart();
|
||||||
|
final int selEnd = getSelectionEnd();
|
||||||
|
|
||||||
|
min = Math.max(0, Math.min(selStart, selEnd));
|
||||||
|
max = Math.max(0, Math.max(selStart, selEnd));
|
||||||
|
}
|
||||||
|
return charSequence.subSequence(min, max);
|
||||||
|
}
|
||||||
|
}
|
@ -109,7 +109,7 @@
|
|||||||
android:text="@string/your_comment"
|
android:text="@string/your_comment"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<EditText
|
<org.schabi.newpipe.views.NewPipeEditText
|
||||||
android:id="@+id/errorCommentBox"
|
android:id="@+id/errorCommentBox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
android:paddingTop="@dimen/video_item_search_padding"
|
android:paddingTop="@dimen/video_item_search_padding"
|
||||||
android:paddingRight="@dimen/video_item_search_padding">
|
android:paddingRight="@dimen/video_item_search_padding">
|
||||||
|
|
||||||
<EditText
|
<org.schabi.newpipe.views.NewPipeEditText
|
||||||
android:id="@+id/dialogEditText"
|
android:id="@+id/dialogEditText"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
app:layout_constraintStart_toEndOf="@+id/icon_preview"
|
app:layout_constraintStart_toEndOf="@+id/icon_preview"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<EditText
|
<org.schabi.newpipe.views.NewPipeEditText
|
||||||
android:id="@+id/group_name_input"
|
android:id="@+id/group_name_input"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
android:layout_marginBottom="6dp"
|
android:layout_marginBottom="6dp"
|
||||||
android:text="@string/msg_name" />
|
android:text="@string/msg_name" />
|
||||||
|
|
||||||
<EditText
|
<org.schabi.newpipe.views.NewPipeEditText
|
||||||
android:id="@+id/file_name"
|
android:id="@+id/file_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<EditText
|
<org.schabi.newpipe.views.NewPipeEditText
|
||||||
android:id="@+id/input_text"
|
android:id="@+id/input_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
tools:background="?attr/colorPrimary">
|
tools:background="?attr/colorPrimary">
|
||||||
|
|
||||||
<EditText
|
<org.schabi.newpipe.views.NewPipeEditText
|
||||||
android:id="@+id/toolbar_search_edit_text"
|
android:id="@+id/toolbar_search_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user