app/src/main/java/me/zhanghai/android/douya/util/CheatSheetUtils.java
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*
* Copyright (c) 2015 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
* All Rights Reserved.
*/
/*
* From https://gist.github.com/romannurik/3982005
*/
package me.zhanghai.android.douya.util;
import android.content.Context;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;
/**
* Helper class for showing cheat sheets (tooltips) for icon-only UI elements on long-press. This is
* already default platform behavior for icon-only {@link android.app.ActionBar} items and tabs.
* This class provides this behavior for any other such UI element.
*
* <p>Based on the original action bar implementation in <a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/com/android/internal/view/menu/ActionMenuItemView.java">
* ActionMenuItemView.java</a>.
*/
public class CheatSheetUtils {
/**
* The estimated height of a toast, in dips (density-independent pixels). This is used to
* determine whether or not the toast should appear above or below the UI element.
*/
private static final int ESTIMATED_TOAST_HEIGHT_DIPS = 48;
/**
* Sets up a cheat sheet (tooltip) for the given view by setting its {@link
* View.OnLongClickListener}. When the view is long-pressed, a {@link Toast} with
* the view's {@link View#getContentDescription() content description} will be
* shown either above (default) or below the view (if there isn't room above it).
*
* @param view The view to add a cheat sheet for.
*/
public static void setup(View view) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return show(view, view.getContentDescription());
}
});
}
/**
* Sets up a cheat sheet (tooltip) for the given view by setting its {@link
* View.OnLongClickListener}. When the view is long-pressed, a {@link Toast} with
* the given text will be shown either above (default) or below the view (if there isn't room
* above it).
*
* @deprecated Use {@link #setup(View)} instead.
*
* @param view The view to add a cheat sheet for.
后面还有 84 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
