Single click to show icon hint

pull/183/head
M66B 5 years ago
parent 0ce1b9d1d4
commit af73e79e7e

@ -11,37 +11,24 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatImageView;
public class ViewImageHint extends AppCompatImageView implements View.OnLongClickListener { public class ViewImageHint extends AppCompatImageView implements View.OnClickListener {
private OnLongClickListener listener;
public ViewImageHint(@NonNull Context context) { public ViewImageHint(@NonNull Context context) {
super(context); super(context);
setOnLongClickListener(this); setOnClickListener(this);
} }
public ViewImageHint(@NonNull Context context, @Nullable AttributeSet attrs) { public ViewImageHint(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
setOnLongClickListener(this); setOnClickListener(this);
} }
public ViewImageHint(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { public ViewImageHint(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
setOnLongClickListener(this); setOnClickListener(this);
} }
@Override @Override
public void setOnLongClickListener(OnLongClickListener listener) { public void onClick(View v) {
if (listener == this) {
super.setOnLongClickListener(listener);
return;
}
this.listener = listener;
}
@Override
public boolean onLongClick(View v) {
if (listener == null || !listener.onLongClick(v)) {
String title = getContentDescription().toString(); String title = getContentDescription().toString();
if (!TextUtils.isEmpty(title)) { if (!TextUtils.isEmpty(title)) {
int[] pos = new int[2]; int[] pos = new int[2];
@ -50,11 +37,6 @@ public class ViewImageHint extends AppCompatImageView implements View.OnLongClic
Toast toast = ToastEx.makeText(getContext(), title, Toast.LENGTH_LONG); Toast toast = ToastEx.makeText(getContext(), title, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP | Gravity.START, pos[0], pos[1]); toast.setGravity(Gravity.TOP | Gravity.START, pos[0], pos[1]);
toast.show(); toast.show();
return true;
} }
} }
return false;
}
} }
Loading…
Cancel
Save