Single click to show icon hint

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

@ -11,50 +11,32 @@ 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) { String title = getContentDescription().toString();
super.setOnLongClickListener(listener); if (!TextUtils.isEmpty(title)) {
return; int[] pos = new int[2];
getLocationOnScreen(pos);
Toast toast = ToastEx.makeText(getContext(), title, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP | Gravity.START, pos[0], pos[1]);
toast.show();
} }
this.listener = listener;
}
@Override
public boolean onLongClick(View v) {
if (listener == null || !listener.onLongClick(v)) {
String title = getContentDescription().toString();
if (!TextUtils.isEmpty(title)) {
int[] pos = new int[2];
getLocationOnScreen(pos);
Toast toast = ToastEx.makeText(getContext(), title, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP | Gravity.START, pos[0], pos[1]);
toast.show();
return true;
}
}
return false;
} }
} }
Loading…
Cancel
Save