public class Easy
{
    private static Easy easy = new Easy();
    private static Context context;

    /**
     * 返回 {@link Context}
     *
     * @return {@link Context}
     */
    public static Context getContext()
    {
        checkInitState();
        return context;
    }

    /**
     * 检测初始化状态。Easy类暂时定为静态初始化，所以直接检测contextRef是否已初始化，
     * 未初始化，直接抛出异常.
     */
    private static void checkInitState()
    {
        if(context == null)
        {
            throw new IllegalStateException("未初始化库异常，在使用之前，你需要在'Application.onCreate()'" +
                    "(或者其他位置)中调用'Easy.getDefault().initTag(Context)初始化。");
        }
    }

    private Easy()
    {
    }

    /**
     * 单例初始化 {@link Easy} 方法，并返回 {@link Easy} 对象
     *
     * @return {@link Easy} 对象
     */
    public static Easy getDefault()
    {
        return easy;
    }

    /**
     * 初始化Context
     *
     * @param context context
     */
    public void init(Context context)
    {
        if(context == null)
        {
            throw new NullPointerException("Argument Context is null(参数Context是null).");
        }

        Easy.context = context;
    }

    /**
     * 释放资源（可能用不到，但还是提供吧)
     */
    public void release()
    {
        context = null;
        easy = null;
    }

} public class ClipboardTool
{
    private static final String TEXT = "text";
    private static final String URI = "uri";
    private static final String INTENT = "intent";

    private ClipboardTool()
    {
        throw new UnsupportedOperationException();
    }

    /**
     * 设置文本到剪贴板
     *
     * @param text 文本
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void setText(CharSequence text)
    {
        ClipboardManager clipboardManager = getClipboardManager();
        clipboardManager.setPrimaryClip(ClipData.newPlainText(TEXT, text));
    }

    /**
     * 获取剪贴板的文本
     *
     * @return 剪贴板的文本
     */
    public static String getText()
    {
        return getText(null);
    }

    /**
     * 获取剪贴板文本，当获取到是空时，返回默认字符串
     *
     * @param textIfNull 剪贴板文本如果为空，返回这个字符串
     * @return 剪贴板文本
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static String getText(String textIfNull)
    {
        ClipboardManager clipboardManager = getClipboardManager();
        ClipData clipData = clipboardManager.getPrimaryClip();
        if(clipData != null && clipData.getItemCount() > 0)
        {
            return clipData.getItemAt(0).coerceToText(Easy.getContext()).toString();
        }

        return textIfNull;
    }

    /**
     * 设置uri到剪贴板
     *
     * @param uri uri
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void setUri(Uri uri)
    {
        ClipboardManager clipboardManager = Managers.getClipboardManager();
        clipboardManager.setPrimaryClip(
                ClipData.newUri(Easy.getContext().getContentResolver(), URI, uri));
    }

    /**
     * 获取剪贴板的uri
     *
     * @return 剪贴板的uri
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static Uri getUri()
    {
        ClipboardManager clipboardManager = Managers.getClipboardManager();
        ClipData clipData = clipboardManager.getPrimaryClip();
        if(clipData != null && clipData.getItemCount() > 0)
        {
            return clipData.getItemAt(0).getUri();
        }
        return null;
    }

    /**
     * 设置意图到剪贴板
     *
     * @param intent 意图
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void setIntent(Intent intent)
    {
        ClipboardManager clipboardManager = Managers.getClipboardManager();
        clipboardManager.setPrimaryClip(ClipData.newIntent(INTENT, intent));
    }

    /**
     * 获取剪贴板的意图
     *
     * @return 剪贴板的意图
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static Intent getIntent()
    {
        ClipboardManager clipboardManager = Managers.getClipboardManager();
        ClipData clipData = clipboardManager.getPrimaryClip();
        if(clipData != null && clipData.getItemCount() > 0)
        {
            return clipData.getItemAt(0).getIntent();
        }
        return null;
    }
} public class Managers
{
    @StringDef({
            POWER_SERVICE,
            WINDOW_SERVICE,
            LAYOUT_INFLATER_SERVICE,
            ACCOUNT_SERVICE,
            ACTIVITY_SERVICE,
            ALARM_SERVICE,
            NOTIFICATION_SERVICE,
            ACCESSIBILITY_SERVICE,
            CAPTIONING_SERVICE,
            KEYGUARD_SERVICE,
            LOCATION_SERVICE,
            SENSOR_SERVICE,
            STORAGE_SERVICE,
            WALLPAPER_SERVICE,
            VIBRATOR_SERVICE,
            NSD_SERVICE,
            AUDIO_SERVICE,
            FINGERPRINT_SERVICE,
            MEDIA_ROUTER_SERVICE,
            TELEPHONY_SERVICE,
            CARRIER_CONFIG_SERVICE,
            TELECOM_SERVICE,
            CLIPBOARD_SERVICE,
            INPUT_METHOD_SERVICE,
            TEXT_SERVICES_MANAGER_SERVICE,
            APPWIDGET_SERVICE,
            UI_MODE_SERVICE,
            DOWNLOAD_SERVICE,
            NFC_SERVICE,
            BLUETOOTH_SERVICE,
            LAUNCHER_APPS_SERVICE,
            DISPLAY_SERVICE,
            USER_SERVICE,
            RESTRICTIONS_SERVICE,
            APP_OPS_SERVICE,
            CAMERA_SERVICE,
            PRINT_SERVICE,
            CONSUMER_IR_SERVICE,
            MEDIA_SESSION_SERVICE,
            BATTERY_SERVICE,
            JOB_SCHEDULER_SERVICE,
            MIDI_SERVICE,
            HARDWARE_PROPERTIES_SERVICE,
    })
    @Retention(RetentionPolicy.SOURCE)
    private @interface ServiceName {}

    /**
     * 内部方法，根据名称获取各种Manager类.
     *
     * @param serviceName 服务名称
     * @return {@link android.content.Context#getSystemService(String)}
     */
    protected static Object get(@ServiceName String serviceName)
    {
        return getContext().getSystemService(serviceName);
    }

    /**
     * 返回 {@link AccountManager}
     */
    public static AccountManager getAccountManager()
    {
        return (AccountManager) get(ACCOUNT_SERVICE);
    }

    /**
     * 返回 {@link PackageManager}
     */
    public static PackageManager getPackageManager()
    {
        return getContext().getPackageManager();
    }

    /**
     * 返回 {@link ClipboardManager}
     */
    public static ClipboardManager getClipboardManager()
    {
        if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        {
            throw new UnsupportedOperationException("ClipboardManager can not be used when SDK_INT < 11\n" +
                    "剪贴板不能在SDK_IND < 11 的版本上使用.");
        }
        else
        {
            return (ClipboardManager) get(CLIPBOARD_SERVICE);
        }
    }

    /**
     * 返回 {@link WindowManager}
     */
    public static WindowManager getWindowManager()
    {
        return (WindowManager) get(WINDOW_SERVICE);
    }

    /**
     * 返回 {@link KeyguardManager}
     */
    public static KeyguardManager getKeyguardManager()
    {
        return (KeyguardManager) get(KEYGUARD_SERVICE);
    }

    /**
     * 返回 {@link PowerManager}
     */
    public static PowerManager getPowerManager()
    {
        return (PowerManager) get(POWER_SERVICE);
    }

    /**
     * 返回 {@link LayoutInflater}
     */
    public static LayoutInflater getLayoutInflater()
    {
        return (LayoutInflater) get(LAYOUT_INFLATER_SERVICE);
    }

    /**
     * 返回 {@link ActivityManager}
     */
    public static ActivityManager getActivityManager()
    {
        return (ActivityManager) get(ACTIVITY_SERVICE);
    }

    /**
     * 返回 {@link AlarmManager}
     */
    public static AlarmManager getAlarmManager()
    {
        return (AlarmManager) get(ALARM_SERVICE);
    }

    /**
     * 返回 {@link NotificationManager}
     */
    public static NotificationManager getNotificationManager()
    {
        return (NotificationManager) get(NOTIFICATION_SERVICE);
    }

    /**
     * 返回 {@link AccessibilityManager}
     */
    public static AccessibilityManager getAccessibilityManager()
    {
        return (AccessibilityManager) get(ACCESSIBILITY_SERVICE);
    }

    /**
     * 返回 {@link CaptioningManager}
     */
    public static CaptioningManager getCaptioningManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            return (CaptioningManager) getContext().getSystemService(CAPTIONING_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link LocationManager}
     */
    public static LocationManager getLocationManager()
    {
        return (LocationManager) get(LOCATION_SERVICE);
    }

    /**
     * 返回 {@link SensorManager}
     */
    public static SensorManager getSensorManager()
    {
        return (SensorManager) get(SENSOR_SERVICE);
    }

    /**
     * 返回 {@link StorageManager}
     */
    public static StorageManager getStorageManage()
    {
        return (StorageManager) get(STORAGE_SERVICE);
    }

    /**
     * 返回 {@link WallpaperManager}
     */
    public static WallpaperManager getWallpaperManager()
    {
        return (WallpaperManager) get(WALLPAPER_SERVICE);
    }

    /**
     * 返回 {@link Vibrator}
     */
    public static Vibrator getVibrator()
    {
        return (Vibrator) get(VIBRATOR_SERVICE);
    }

    /**
     * 返回 {@link NsdManager}
     */
    public static NsdManager getNsdManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        {
            return (NsdManager) get(NSD_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link AudioManager}
     */
    public static AudioManager getAudioManager()
    {
        return (AudioManager) get(AUDIO_SERVICE);
    }

    /**
     * 返回 {@link FingerprintManager}
     */
    public static FingerprintManager getFingerprintManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            return (FingerprintManager) get(FINGERPRINT_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link MediaRouter}
     */
    public static MediaRouter getMediaRouter()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        {
            return (MediaRouter) get(MEDIA_ROUTER_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link TelecomManager}
     */
    public static TelephonyManager getTelephonyManager()
    {
        return (TelephonyManager) get(TELEPHONY_SERVICE);
    }

    /**
     * 返回 {@link CarrierConfigManager}
     */
    public static CarrierConfigManager getCarrierConfigManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            return (CarrierConfigManager) get(CARRIER_CONFIG_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link TelecomManager}
     */
    public static TelecomManager getTelecomManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            return (TelecomManager) get(TELECOM_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link InputMethodManager}
     */
    public static InputMethodManager getInputMethodManager()
    {
        return (InputMethodManager) get(INPUT_METHOD_SERVICE);
    }

    /**
     * 返回 {@link TextServicesManager}
     */
    public static TextServicesManager getTextServicesManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        {
            return (TextServicesManager) get(TEXT_SERVICES_MANAGER_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link AppWidgetManager}
     */
    public static AppWidgetManager getAppWidgetManager()
    {
        return (AppWidgetManager) get(APPWIDGET_SERVICE);
    }

    /**
     * 返回 {@link UiModeManager}
     */
    public static UiModeManager getUiModeManager()
    {
        return (UiModeManager) get(UI_MODE_SERVICE);
    }

    /**
     * 返回 {@link DownloadManager}
     */
    public static DownloadManager getDownloadManager()
    {
        return (DownloadManager) get(DOWNLOAD_SERVICE);
    }

    /**
     * 返回 {@link NfcManager}
     */
    public static NfcManager getNfcManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1)
        {
            return (NfcManager) get(NFC_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link BluetoothManager}
     */
    public static BluetoothManager getBluetoothManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        {
            return (BluetoothManager) get(BLUETOOTH_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link LauncherApps}
     */
    public static LauncherApps getLauncherApps()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            return (LauncherApps) get(LAUNCHER_APPS_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link DisplayManager}
     */
    public static DisplayManager getDisplayManagerCompat()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        {
            return (DisplayManager) get(DISPLAY_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link UserManager}
     */
    public static UserManager getUserManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        {
            return (UserManager) get(USER_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link RestrictionsManager}
     */
    public static RestrictionsManager getRestrictionsManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            return (RestrictionsManager) get(RESTRICTIONS_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link AppOpsManager}
     */
    public static AppOpsManager getAppOpsManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            return (AppOpsManager) get(APP_OPS_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link CameraManager}
     */
    public static CameraManager getCameraManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            return (CameraManager) get(CAMERA_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link PrintManager}
     */
    public static PrintManager getPrintManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            return (PrintManager) get(PRINT_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link ConsumerIrManager}
     */
    public static ConsumerIrManager getConsumerIrManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            return (ConsumerIrManager) get(CONSUMER_IR_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link MediaSessionManager}
     */
    public static MediaSessionManager getMediaSessionManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            return (MediaSessionManager) get(MEDIA_SESSION_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link BatteryManager}
     */
    public static BatteryManager getBatteryManager()
    {
        return (BatteryManager) get(BATTERY_SERVICE);
    }

    /**
     * 返回 {@link JobScheduler}
     */
    public static JobScheduler getJobScheduler()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            return (JobScheduler) get(JOB_SCHEDULER_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link MidiManager}
     */
    public static MidiManager getMidiManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            return (MidiManager) get(MIDI_SERVICE);
        }

        throw new UnsupportedOperationException();
    }

    /**
     * 返回 {@link HardwarePropertiesManager}
     */
    public static HardwarePropertiesManager getHardwarePropertiesManager()
    {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        {
            return (HardwarePropertiesManager) get(HARDWARE_PROPERTIES_SERVICE);
        }

        throw new UnsupportedOperationException();
    }
} public class Res extends ResTool
{
    Res()
    {
        throw new UnsupportedOperationException();
    }
} public class ResTool
{
    ResTool()
    {
        throw new UnsupportedOperationException();
    }

    /**
     * 从资源中获取Drawable
     *
     * @param id Drawable资源id
     * @return Drawable
     */
    public static Drawable getDrawable(@DrawableRes int id)
    {
        //使用ContextCompat应是谷歌推荐的
        return ContextCompat.getDrawable(Easy.getContext(), id);
    }

    /**
     * 从资源中获取String
     *
     * @param id String资源id
     * @return String
     */
    public static String getString(@StringRes int id)
    {
        return Easy.getContext().getString(id);
    }

    /**
     * 从资源中获取String
     *
     * @param id   String id
     * @param args 格式化参数
     * @return String
     */
    public static String getString(@StringRes int id, Object... args)
    {
        return Easy.getContext().getString(id, args);
    }

    /**
     * 从资源中获取Dimension并返回
     *
     * @param id 尺寸资源id
     * @return 尺寸像素值
     */
    public static int getDimen(@DimenRes int id)
    {
        return (int) getDimenFloat(id);
    }

    /**
     * 从资源中获取Dimension并返回float类型
     *
     * @param id 尺寸资源id
     * @return 尺寸像素值
     */
    public static float getDimenFloat(@DimenRes int id)
    {
        return getResources().getDimension(id);
    }

    /**
     * 从资源中获取Dimension并返回
     *
     * @param id 像素资源id
     * @return 尺寸dp值
     */
    public static int getDimenToDp(@DimenRes int id)
    {
        return (int) getDimenFloat(id);
    }

    /**
     * 从资源中获取Dimension并返回float类型
     *
     * @param id 像素资源id
     * @return 尺寸dp值
     */
    public static float getDimenFloatToDp(@DimenRes int id)
    {
        return DensityTool.px2dp(Easy.getContext().getResources().getDimension(id));
    }

    /**
     * 从资源中获取Color
     *
     * @param id 颜色资源id
     * @return 颜色值
     */
    public static int getColor(@ColorRes int id)
    {
        return ContextCompat.getColor(Easy.getContext(), id);
    }

    /**
     * 获取 Configuration
     *
     * @return Configuration
     */
    public static Configuration getConfiguration()
    {
        return getResources().getConfiguration();
    }

    /**
     * 获取 Resources
     *
     * @return Resources
     */
    public static Resources getResources()
    {
        return Easy.getContext().getResources();
    }

    /**
     * 获取返回String array.
     *
     * @param id resource id
     * @return String array
     */
    public static String[] getStringArray(@ArrayRes int id)
    {
        return getResources().getStringArray(id);
    }

    /**
     * 获取返回int array.
     *
     * @param id resource id
     * @return int array
     */
    public static int[] getIntArray(@ArrayRes int id)
    {
        return getResources().getIntArray(id);
    }

    /**
     * 获取返回text id.
     *
     * @param id resource id
     * @return text array
     */
    public static CharSequence[] getTextArray(@ArrayRes int id)
    {
        return getResources().getTextArray(id);
    }

    /**
     * 获取返回TypedArray
     *
     * @param id resource id
     * @return TypedArray
     */
    public static TypedArray getTypedArray(@ArrayRes int id)
    {
        return getResources().obtainTypedArray(id);
    }

    /**
     * 获取返回Drawable Array，解决直接使用getIntArray获取Drawable数组时，所有item都为0的问题.
     *
     * @param id resource id
     * @return Drawable Array
     */
    public static Drawable[] getDrawableArray(@ArrayRes int id)
    {
        TypedArray typedArray = getTypedArray(id);
        //获取数量需要用这样的方法, TypedArray.getIndexCount() 获取的一直是0.
        int count = getTextArray(id).length;
        Drawable[] drawables = new Drawable[count];
        for(int i = 0; i < drawables.length; i++)
        {
            drawables[i] = typedArray.getDrawable(i);
        }
        typedArray.recycle();

        return drawables;
    }

    /**
     * 获取返回Drawable Id Array，因为主要原因是使用 {@link #getDrawableArray(int)} 时，用Glide直接加载
     * Drawable会报异常，这里提供一个获取drawable id array的方法解决这个问题.
     *
     * @param id Array id
     * @return Drawable id Array
     */
    public static int[] getDrawableIdArray(@ArrayRes int id)
    {
        TypedArray typedArray = getTypedArray(id);
        int length = getTextArray(id).length;
        int[] ids = new int[length];
        for(int i = 0; i < ids.length; i++)
        {
            ids[i] = typedArray.getResourceId(i, 0);
        }
        typedArray.recycle();

        return ids;
    }
} public class ToastTool
{
    /**
     * 改成1个Toast实例接受每次更改和显示。Toast显示时，多次点击同一个Toast，Toast不会重复显示；切换显示其他
     * Toast时，有动态切换的效果，很赞，推荐使用
     */
    private static Toast toast;

    private ToastTool()
    {
        throw new UnsupportedOperationException();
    }

    /**
     * 创建Toast并返回
     *
     * @param text Toast文本
     * @return Toast
     */
    public static Toast make(String text)
    {
        return create(text, Toast.LENGTH_SHORT);
    }

    /**
     * 创建并返回Toast.
     */
    @SuppressLint("ShowToast")
    private static Toast create(String text, int length)
    {
        if(toast == null)
        {
            toast = Toast.makeText(Easy.getContext(), text, length);
        }
        else
        {
            toast.setDuration(length);
            toast.setText(text);
        }

        return toast;
    }

    /**
     * 创建LENGTH_LONG Toast并返回
     *
     * @param text Toast文本
     * @return Toast
     */
    public static Toast makeLong(String text)
    {
        return create(text, Toast.LENGTH_LONG);
    }

    /**
     * 显示Toast
     *
     * @param text Toast文本
     */
    public static void show(String text)
    {
        make(text).show();
    }

    /**
     * 显示LENGTH_LONG Toast
     *
     * @param text Toast文本
     */
    public static void showLong(String text)
    {
        makeLong(text).show();
    }

    /**
     * 创建Toast并返回
     *
     * @param id string id
     * @return Toast
     */
    public static Toast make(@StringRes int id)
    {
        return create(id, Toast.LENGTH_SHORT);
    }

    /**
     * 创建并返回Toast.
     */
    @SuppressLint("ShowToast")
    private static Toast create(@StringRes int id, int length)
    {
        if(toast == null)
        {
            toast = Toast.makeText(Easy.getContext(), id, length);
        }
        else
        {
            toast.setDuration(length);
            toast.setText(id);
        }

        return toast;
    }

    /**
     * 创建LENGTH_LONG Toast并返回
     *
     * @param id string id
     * @return Toast
     */
    public static Toast makeLong(@StringRes int id)
    {
        return create(id, Toast.LENGTH_LONG);
    }

    /**
     * 显示Toast
     *
     * @param id string id
     */
    public static void show(@StringRes int id)
    {
        make(id).show();
    }

    /**
     * 显示LENGTH_LONG Toast
     *
     * @param id string id
     */
    public static void showLong(@StringRes int id)
    {
        makeLong(id).show();
    }
} public abstract class BaseActivity extends AppCompatActivity
{
    /**
     * 是否禁用Activity中sp为单位的字体随系统缩放而缩放。 true: 禁用字体随系统缩放; false:启用字体随系统缩放
     */
    private boolean isFontScaleDisabled = true;

    /**
     * 获取返回Context（还是此Activity)，讨厌每次在内部类写 *Activity.this.
     *
     * @return Context
     */
    public Context getContext()
    {
        return this;
    }

    /**
     * 获取返回Activity.
     *
     * @return Activity
     */
    public Activity getActivity()
    {
        return this;
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(getContentLayoutRes());

        init(savedInstanceState);
    }

    protected void init(@Nullable Bundle savedInstanceState)
    {
        initExtra();
        initView(savedInstanceState);
        initData();
    }

    /**
     * 返回Layout resource id，需要在子类实现.
     *
     * @return Layout resource id
     */
    @LayoutRes
    protected abstract int getContentLayoutRes();

    /**
     * 初始化数据
     */
    protected void initData()
    {

    }

    /**
     * 初始化View
     *
     * @param savedInstanceState Bundle
     */
    protected abstract void initView(Bundle savedInstanceState);

    /**
     * 初始化外部传入的Extra数据
     */
    protected void initExtra()
    {

    }

    /**
     * 是否禁用sp为单位的字体随系统缩放
     *
     * @param fontScaleDisabled 是否禁用sp为单位的字体随系统缩放
     * @see #isFontScaleDisabled
     */
    public void setFontScaleDisabled(boolean fontScaleDisabled)
    {
        isFontScaleDisabled = fontScaleDisabled;
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        if(isFontScaleDisabled)
        {
            //非默认值
            if(newConfig.fontScale != 1)
            {
                useFontScaleDisabledResources();
            }
        }
        super.onConfigurationChanged(newConfig);
    }


    /**
     * 禁用字体随系统缩放功能
     * @return {@link Resources}
     */
    public Resources useFontScaleDisabledResources()
    {
        Resources res = super.getResources();
        //非默认值
        if(res.getConfiguration().fontScale != 1)
        {
            Configuration newConfig = new Configuration();
            //设置默认
            newConfig.setToDefaults();
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
}
 public class TestFullScreenActivity extends AppCompatActivity
{

    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_full_screen);
        ButterKnife.bind(this);
        init();
    }

    private void init()
    {
        setSupportActionBar(toolbar);
        setTitle("测试AppCompatActivity");
        toolbar.setNavigationIcon(android.R.drawable.arrow_up_float);
        toolbar.setNavigationOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                finish();
            }
        });
        toolbar.setTitle(R.string.this_is_appcompatactivity);
    }

    public void onExitFullScreen(View view)
    {
        ScreenTool.switchFullScreen(this, false);
    }

    public void onEnterFullScreen(View view)
    {
        ScreenTool.switchFullScreen(this, true);
    }

    public void onTestActivityFullScreen(View view)
    {
        startActivity(new Intent(this, TestFullScreenActivity2.class));
    }

    public void onExitFullScreenWithActionBar(View view)
    {
        ScreenTool.switchFullScreenWithActionBar(this, false);
    }

    public void onEnterFullScreenWithActionBar(View view)
    {
        ScreenTool.switchFullScreenWithActionBar(this, true);
    }
}
 public class NetworkActivity extends BaseActivity
{
    @BindView(R.id.tv)
    TextView tv;
    @BindView(R.id.tvContent)
    TextView tvContent;

    @Override
    protected int getContentLayoutRes()
    {
        return R.layout.activity_network;
    }

    @Override
    protected void initView(Bundle savedInstanceState)
    {
        ButterKnife.bind(this);
        Network.getWeather("深圳", new Consumer<Weather>()
        {
            @Override
            public void accept(Weather weather) throws Exception
            {
                Weather.DataBean data = weather.getData();
                ToastTool.showLong(String.format("温度%s℃ %s", data.getWendu(), data.getGanmao()));
                tv.setText(data.getWendu());
                tvContent.setText(data.getGanmao());
            }
        });
    }
}
 public class BitmapActivity extends AppCompatActivity
{

    private ImageView iv1;
    private ImageView iv2;
    private ImageView iv3;
    private ImageView iv4;
    private ImageView iv5;
    private ImageView iv6;
    private ImageView iv9;
    private ImageView iv7;
    private ImageView iv8;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bitmap);
        initView();
    }

    private void initView()
    {
        iv1 = (ImageView) findViewById(R.id.iv1);
        iv2 = (ImageView) findViewById(R.id.iv2);
        iv3 = (ImageView) findViewById(R.id.iv3);
        iv4 = (ImageView) findViewById(R.id.iv4);
        iv5 = (ImageView) findViewById(R.id.iv5);
        iv6 = (ImageView) findViewById(R.id.iv6);
        iv7 = (ImageView) findViewById(R.id.iv7);
        iv8 = (ImageView) findViewById(R.id.iv8);
        iv9 = (ImageView) findViewById(R.id.iv9);

        Drawable drawable = ResTool.getDrawable(R.mipmap.ic_launcher);
        iv1.setImageDrawable(drawable);
        iv2.setImageBitmap(BitmapTool.toBitmap(R.mipmap.ic_launcher));
        iv3.setImageBitmap(BitmapTool.toBitmap(drawable));

        iv4.setImageBitmap(BitmapTool.zoom(drawable, 20, 30));
        iv5.setImageBitmap(BitmapTool.zoom(BitmapTool.toBitmap(drawable), 50, 30));
        iv6.setImageBitmap(BitmapTool.zoom(drawable, -1));

        iv7.setImageDrawable(BitmapTool.rotate2Drawable(drawable, 90));
        iv8.setImageBitmap(BitmapTool.rotate(drawable, 180));
        iv9.setImageBitmap(BitmapTool.rotate(BitmapTool.toBitmap(drawable), -90));
    }
} public class PackagesActivity extends AppCompatActivity
{
    private RecyclerView recyclerView;
    private PackageAdapter packageAdapter;

    private int filterType = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_packages);
        initView();
    }

    private void initView()
    {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        packageAdapter = new PackageAdapter();
        recyclerView.setAdapter(packageAdapter);
        packageAdapter.update();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.menu_packages, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch(item.getItemId())
        {
            case R.id.menu_id_all:
                filterType = 0;
                break;
            case R.id.menu_id_system:
                filterType = 1;
                break;
            case R.id.menu_id_user:
                filterType = 2;
                break;
        }
        packageAdapter.update();
        return super.onOptionsItemSelected(item);
    }

    public class PackageAdapter extends RecyclerView.Adapter<PackageAdapter.Vh>
    {
        private List<AppInfo> list = new ArrayList<>();

        @Override
        public Vh onCreateViewHolder(ViewGroup parent, int viewType)
        {
            return new Vh(LayoutInflater.from(parent.getContext())
                                        .inflate(R.layout.item_packagtes, parent, false));
        }

        @Override
        public void onBindViewHolder(Vh holder, int position)
        {
            holder.update(position);
        }

        @Override
        public int getItemCount()
        {
            return list.size();
        }

        public void update()
        {
            Observable
                    .create(new ObservableOnSubscribe<AppInfo>()
                    {
                        @Override
                        public void subscribe(ObservableEmitter<AppInfo> e) throws Exception
                        {
                            List<AppInfo> appInfo = Packages.getInstalledAppsInfo();
                            for(AppInfo a : appInfo)
                            {
                                e.onNext(a);
                            }
                            e.onComplete();
                        }
                    })
                    .subscribeOn(Schedulers.io())
                    .filter(new Predicate<AppInfo>()
                    {
                        @Override
                        public boolean test(AppInfo appInfo) throws Exception
                        {
                            switch(filterType)
                            {
                                case 1:
                                    return appInfo.isSystemApp;
                                case 2:
                                    return !appInfo.isSystemApp;
                                default:
                                    return true;
                            }
                        }
                    })
                    .toSortedList()
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<List<AppInfo>>()
                    {
                        @Override
                        public void accept(List<AppInfo> appInfos) throws Exception
                        {
                            list = appInfos;
                            notifyDataSetChanged();
                        }
                    });
        }

        public class Vh extends RecyclerView.ViewHolder
        {
            @BindView(R.id.iv)
            ImageView iv;
            @BindView(R.id.tvTitle)
            TextView tvTitle;
            @BindView(R.id.tvPackageName)
            TextView tvPackageName;

            public Vh(View itemView)
            {
                super(itemView);
                ButterKnife.bind(this, itemView);
            }

            public void update(int position)
            {
                AppInfo appInfo = list.get(position);
                tvTitle.setText(appInfo.label);
                appInfo.loadIconInto(iv);
                tvPackageName.setText(appInfo.packageName);
            }
        }

    }
}
 public class PopupWindowActivity extends AppCompatActivity
{

    private AlphaPopupWindow alphaPopupWindow;
    private TopPopupWindow topPopupWindow;
    private ToggleSoftInputPopupWindow tip;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_window);
        initView();
    }

    private void initView()
    {
        Easy.getDefault().init(this);
        alphaPopupWindow = new AlphaPopupWindow(this, R.layout.pw_main,
                getResources().getColor(R.color.colorPrimary),
                R.style.defPwAnimStyle);
        alphaPopupWindow.getContentView().findViewById(R.id.btnPopupWindow).setOnClickListener(
                new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v)
                    {
                        ToastTool.showLong("popupWindow显示啦！");
                    }
                });
        topPopupWindow = new TopPopupWindow(this, R.layout.pw_main, ResTool.getColor(R.color.colorPrimary),
                R.style.defPwAnimStyle);
        topPopupWindow.setWidth(DensityTool.dp2px(100));
        topPopupWindow.getContentView().findViewById(R.id.btnPopupWindow).setOnClickListener(
                new View.OnClickListener()
                {
                    @Override
                    public void onClick(View v)
                    {
                        ToastTool.showLong("popupWindow显示啦！");
                    }
                });
        tip = new ToggleSoftInputPopupWindow(this, R.layout.pw_input, Color.WHITE, R.style.defPwAnimStyle);
        tip.getContentView().findViewById(R.id.btnClose).setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                tip.show();
            }
        });
    }

    public void onClickShowPopupWindow(View view)
    {
        alphaPopupWindow.show();
    }

    public void onClickShowTopPopupWindow(View view)
    {
        topPopupWindow.showTopRight();
    }

    public void onInputMethodPopupWindow(View view)
    {
        tip.show();
    }
} public class SystemInfoActivity extends AppCompatActivity
{
    @BindView(R.id.tv)
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_info);
        ButterKnife.bind(this);

        init();
    }

    private void init()
    {
        StringBuffer sb = new StringBuffer();
        sb.append(Build.BOARD);
        sb.append("\n");
        sb.append(Build.BOOTLOADER);
        sb.append("\n");
        sb.append(Build.BRAND);
        tv.setText(sb.toString());
    }
}
 public class StickyHeaderActivity extends AppCompatActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sticky_header);
        ButterKnife.bind(this);
    }

    public void onBasic(View view)
    {
        startActivity(new Intent(this, BasicStickyHeaderActivity.class));
    }

    public void onCustom1(View view)
    {
        startActivity(new Intent(this, TestStickyActivity1.class));
    }

    public void onCustom2(View view)
    {
        startActivity(new Intent(this, TestStickyActivity2.class));
    }
}
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.afollestad.materialdialogs.MaterialDialog;
import com.ayvytr.easyandroid.Easy;
import com.ayvytr.easyandroid.tools.withcontext.ClipboardTool;
import com.ayvytr.easyandroid.tools.withcontext.Managers;
import com.ayvytr.easyandroid.tools.withcontext.Res;
import com.ayvytr.easyandroid.tools.withcontext.ResTool;
import com.ayvytr.easyandroid.tools.withcontext.ToastTool;
import com.ayvytr.easyandroid.view.activity.BaseActivity;
import com.ayvytr.easyandroidtest.customview.AuthEditTextActivity2;
import com.ayvytr.easyandroidtest.customview.QuickIndexViewActivity;
import com.ayvytr.easyandroidtest.fullscreen.TestFullScreenActivity;
import com.ayvytr.easyandroidtest.network.NetworkActivity;
import com.ayvytr.easyandroidtest.other.BitmapActivity;
import com.ayvytr.easyandroidtest.other.PackagesActivity;
import com.ayvytr.easyandroidtest.other.PopupWindowActivity;
import com.ayvytr.easyandroidtest.other.SystemInfoActivity;
import com.ayvytr.easyandroidtest.other.WebViewActivity;
import com.ayvytr.easyandroidtest.stickyheader.StickyHeaderActivity;
import com.ayvytr.logger.L;
import butterknife.BindView;
import butterknife.ButterKnife;
package com.ayvytr.easyandroidtest;




public class MainActivity extends BaseActivity
{
    @BindView(R.id.btn)
    Button btn;
    @BindView(R.id.iv)
    ImageView iv;
    @BindView(R.id.iv2)
    ImageView iv2;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        Easy.getDefault().init(getContext());
        L.getSettings().justShowMessage(true);
        init();
    }

    @Override
    protected int getContentLayoutRes()
    {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(Bundle savedInstanceState)
    {

    }

    private void init()
    {
        Drawable[] drawableArray = Res.getDrawableArray(R.array.testArray);
        iv.setImageDrawable(drawableArray[0]);
        int[] drawableIdArray = Res.getDrawableIdArray(R.array.testArray);
        iv2.setImageResource(drawableIdArray[0]);
    }

    public void onGetClipboard(View view)
    {
        String text = ClipboardTool.getText("没获得");
        ToastTool.show(text);
    }

    public void onSetClipboard(View view)
    {
        ClipboardTool.setText("hello");
        ToastTool.show("已设置Hello到剪贴板");
    }

    public void onGetAppName(View view)
    {
        Managers.getVibrator().vibrate(1000);
        String string = ResTool.getString(R.string.app_name);
        ToastTool.show("获取到Res中APP名称:" + string);
    }

    public void onSeePopupWindow(View view)
    {
        startActivity(new Intent(this, PopupWindowActivity.class));
    }

    public void onPerformClick(View view)
    {
        ToastTool.show("performClick");
    }

    public void onSeePackages(View view)
    {
        startActivity(new Intent(this, PackagesActivity.class));
    }

    public void onSystemInfo(View view)
    {
        startActivity(new Intent(this, SystemInfoActivity.class));
    }

    public void onBitmap(View view)
    {
        startActivity(new Intent(this, BitmapActivity.class));