2021-09-04 19:32:38 +02:00
|
|
|
package org.schabi.newpipe.views;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2022-07-16 13:33:25 +02:00
|
|
|
import android.text.method.MovementMethod;
|
2021-09-04 19:32:38 +02:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.widget.AppCompatTextView;
|
|
|
|
|
2021-10-02 19:53:17 +02:00
|
|
|
import org.schabi.newpipe.util.NewPipeTextViewHelper;
|
2021-09-04 19:32:38 +02:00
|
|
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
|
|
|
|
2021-09-14 20:19:17 +02:00
|
|
|
/**
|
|
|
|
* An {@link AppCompatTextView} which uses {@link ShareUtils#shareText(Context, String, String)}
|
|
|
|
* when sharing selected text by using the {@code Share} command of the floating actions.
|
2022-07-16 13:33:25 +02:00
|
|
|
*
|
2021-09-14 20:19:17 +02:00
|
|
|
* <p>
|
2022-07-16 13:33:25 +02:00
|
|
|
* This class allows NewPipe to show Android share sheet instead of EMUI share sheet when sharing
|
|
|
|
* text from {@link AppCompatTextView} on EMUI devices and also to keep movement method set when a
|
|
|
|
* text change occurs, if the text cannot be selected and text links are clickable.
|
2021-09-14 20:19:17 +02:00
|
|
|
* </p>
|
|
|
|
*/
|
2021-09-04 19:32:38 +02:00
|
|
|
public class NewPipeTextView extends AppCompatTextView {
|
|
|
|
|
|
|
|
public NewPipeTextView(@NonNull final Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public NewPipeTextView(@NonNull final Context context, @Nullable final AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public NewPipeTextView(@NonNull final Context context,
|
|
|
|
@Nullable final AttributeSet attrs,
|
|
|
|
final int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
}
|
|
|
|
|
2022-07-16 13:33:25 +02:00
|
|
|
@Override
|
|
|
|
public void setText(final CharSequence text, final BufferType type) {
|
|
|
|
// We need to set again the movement method after a text change because Android resets the
|
|
|
|
// movement method to the default one in the case where the text cannot be selected and
|
|
|
|
// text links are clickable (which is the default case in NewPipe).
|
|
|
|
final MovementMethod movementMethod = this.getMovementMethod();
|
|
|
|
super.setText(text, type);
|
|
|
|
setMovementMethod(movementMethod);
|
|
|
|
}
|
|
|
|
|
2021-09-04 19:32:38 +02:00
|
|
|
@Override
|
|
|
|
public boolean onTextContextMenuItem(final int id) {
|
|
|
|
if (id == android.R.id.shareText) {
|
2021-10-02 19:53:17 +02:00
|
|
|
NewPipeTextViewHelper.shareSelectedTextWithShareUtils(this);
|
|
|
|
return true;
|
2021-09-04 19:32:38 +02:00
|
|
|
}
|
2021-09-24 20:14:31 +02:00
|
|
|
return super.onTextContextMenuItem(id);
|
2021-09-04 19:32:38 +02:00
|
|
|
}
|
|
|
|
}
|