Add support for paste image to SearchBar
This commit is contained in:
1 parent
7de5be135f
commit
fcd2f2ac23
4 files changed
+55
-10
No files matched your search
@@ -26,6 +26,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.text.Spannable;
|
||||
@@ -1391,6 +1392,16 @@ public final class GalleryListScene extends BaseScene
|
||||
onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveContent(Uri uri) {
|
||||
if (mSearchLayout == null || uri == null) {
|
||||
return;
|
||||
}
|
||||
mSearchLayout.setSearchMode(SearchLayout.SEARCH_MODE_IMAGE);
|
||||
mSearchLayout.setImageUri(uri);
|
||||
setState(STATE_SEARCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartDragHandler() {
|
||||
// Lock right drawer
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.text.Editable;
|
||||
@@ -467,6 +468,11 @@ public class SearchBar extends MaterialCardView implements View.OnClickListener,
|
||||
mHelper.onSearchEditTextBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveContent(Uri uri) {
|
||||
mHelper.onReceiveContent(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
final Bundle state = new Bundle();
|
||||
@@ -496,6 +502,11 @@ public class SearchBar extends MaterialCardView implements View.OnClickListener,
|
||||
void onApplySearch(String query);
|
||||
|
||||
void onSearchEditTextBackPressed();
|
||||
|
||||
default void onReceiveContent(Uri uri) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface OnStateChangeListener {
|
||||
|
||||
@@ -16,12 +16,18 @@
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ContentInfo;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.widget.AppCompatEditText;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
@@ -89,9 +95,24 @@ public class SearchEditText extends AppCompatEditText {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.S)
|
||||
@Nullable
|
||||
@Override
|
||||
public ContentInfo onReceiveContent(@NonNull ContentInfo payload) {
|
||||
ClipData clipData = payload.getClip();
|
||||
if (clipData.getItemCount() == 1) {
|
||||
if (mListener != null) {
|
||||
mListener.onReceiveContent(clipData.getItemAt(0).getUri());
|
||||
}
|
||||
}
|
||||
return super.onReceiveContent(payload);
|
||||
}
|
||||
|
||||
public interface SearchEditTextListener {
|
||||
void onClick();
|
||||
|
||||
void onBackPressed();
|
||||
|
||||
void onReceiveContent(Uri uri);
|
||||
}
|
||||
}
|
||||
@@ -282,20 +282,22 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
post(() -> {
|
||||
int oldItemCount = mAdapter.getItemCount();
|
||||
post(() -> setSearchMode(tab.getPosition()));
|
||||
}
|
||||
|
||||
mSearchMode = tab.getPosition();
|
||||
public void setSearchMode(@SearchMode int mode) {
|
||||
int oldItemCount = mAdapter.getItemCount();
|
||||
|
||||
int newItemCount = mAdapter.getItemCount();
|
||||
mSearchMode = mode;
|
||||
|
||||
mAdapter.notifyItemRangeRemoved(0, oldItemCount - 1);
|
||||
mAdapter.notifyItemRangeInserted(0, newItemCount - 1);
|
||||
int newItemCount = mAdapter.getItemCount();
|
||||
|
||||
if (mHelper != null) {
|
||||
mHelper.onChangeSearchMode();
|
||||
}
|
||||
});
|
||||
mAdapter.notifyItemRangeRemoved(0, oldItemCount - 1);
|
||||
mAdapter.notifyItemRangeInserted(0, newItemCount - 1);
|
||||
|
||||
if (mHelper != null) {
|
||||
mHelper.onChangeSearchMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user