com.hjq.toast.ToastUtils Java Examples

The following examples show how to use com.hjq.toast.ToastUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LanguageActivity.java    From MultiLanguages with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_language);

    findViewById(R.id.btn_language_auto).setOnClickListener(this);
    findViewById(R.id.btn_language_cn).setOnClickListener(this);
    findViewById(R.id.btn_language_tw).setOnClickListener(this);
    findViewById(R.id.btn_language_en).setOnClickListener(this);

    ((TextView) findViewById(R.id.tv_language_system)).setText(LanguagesManager.getLanguageString(this, LanguagesManager.getSystemLanguage(), R.string.current_language));

    Locale locale = LanguagesManager.getAppLanguage(this);
    if (LanguagesManager.equalsCountry(locale, Locale.CHINA)) {
        ToastUtils.show("简体");
    } else if (LanguagesManager.equalsCountry(locale, Locale.TAIWAN)) {
        ToastUtils.show("繁体");
    } else if (LanguagesManager.equalsLanguage(locale, Locale.ENGLISH)) {
        ToastUtils.show("英语");
    } else {
        ToastUtils.show("未知语种");
    }
}
 
Example #2
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRestart() {
    super.onRestart();
    // 请注意这段代码强烈建议不要放到实际开发中,因为用户屏蔽通知栏和开启应用状态下的概率极低,可以忽略不计

    // 如果通知栏的权限被手动关闭了
    if (!SupportToast.class.equals(ToastUtils.getToast().getClass()) &&
                    !NotificationManagerCompat.from(this).areNotificationsEnabled()) {
        // 因为吐司只有初始化的时候才会判断通知权限有没有开启,根据这个通知开关来显示原生的吐司还是兼容的吐司
        ToastUtils.setToast(new SupportToast(getApplication()));
        getWindow().getDecorView().postDelayed(new Runnable() {
            @Override
            public void run() {
                ToastUtils.show("检查到你手动关闭了通知权限,正在重新初始化 Toast");
            }
        }, 1000);
    }
}
 
Example #3
Source File: SelectDialog.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
@SingleClick
@SuppressWarnings("all")
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.tv_ui_confirm:
            HashMap<Integer, Object> data = mAdapter.getSelectSet();
            if (data.size() >= mAdapter.getMinSelect()) {
                autoDismiss();
                if (mListener != null) {
                    mListener.onSelected(getDialog(), data);
                }
            } else {
                ToastUtils.show(String.format(getString(R.string.select_min_hint), mAdapter.getMinSelect()));
            }
            break;
        case R.id.tv_ui_cancel:
            autoDismiss();
            if (mListener != null) {
                mListener.onCancel(getDialog());
            }
            break;
        default:
            break;
    }
}
 
Example #4
Source File: SelectDialog.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
/**
 * {@link BaseAdapter.OnItemClickListener}
 */

@Override
public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
    if (mSelectSet.containsKey(position)) {
        // 当前必须不是单选模式才能取消选中
        if (!isSingleSelect()) {
            mSelectSet.remove(position);
            notifyItemChanged(position);
        }
    } else {
        if (mMaxSelect == 1) {
            mSelectSet.clear();
            notifyDataSetChanged();
        }

        if (mSelectSet.size() < mMaxSelect) {
            mSelectSet.put(position, getItem(position));
            notifyItemChanged(position);
        } else {
            ToastUtils.show(String.format(getString(R.string.select_max_hint), mMaxSelect));
        }
    }
}
 
Example #5
Source File: CheckNetAspect.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
/**
 * 在连接点进行方法替换
 */
@Around("method() && @annotation(checkNet)")
public void aroundJoinPoint(ProceedingJoinPoint joinPoint, CheckNet checkNet) throws Throwable {
    Application application = ActivityStackManager.getInstance().getApplication();
    if (application != null) {
        ConnectivityManager manager = ContextCompat.getSystemService(application, ConnectivityManager.class);
        if (manager != null) {
            NetworkInfo info = manager.getActiveNetworkInfo();
            // 判断网络是否连接
            if (info == null || !info.isConnected()) {
                ToastUtils.show(R.string.common_network);
                return;
            }
        }
    }
    //执行原方法
    joinPoint.proceed();
}
 
Example #6
Source File: MainActivity.java    From XXPermissions with Apache License 2.0 5 votes vote down vote up
public void hasPermission(View view) {
    if (XXPermissions.hasPermission(MainActivity.this, Permission.Group.STORAGE)) {
        ToastUtils.show("已经获取到权限,不需要再次申请了");
    }else {
        ToastUtils.show("还没有获取到权限或者部分权限未授予");
    }
}
 
Example #7
Source File: BaseApplication.java    From MultiLanguages with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ToastUtils.init(this);
    // 在 Application 中初始化
    LanguagesManager.init(this);
}
 
Example #8
Source File: MainActivity.java    From XXPermissions with Apache License 2.0 5 votes vote down vote up
public void requestPermission(View view) {
    XXPermissions.with(this)
            // 可设置被拒绝后继续申请,直到用户授权或者永久拒绝
            //.constantRequest()
            // 支持请求6.0悬浮窗权限8.0请求安装权限
            //.permission(Permission.REQUEST_INSTALL_PACKAGES)
            // 不指定权限则自动获取清单中的危险权限
            .permission(Permission.Group.STORAGE, Permission.Group.CALENDAR)
            .request(new OnPermission() {

                @Override
                public void hasPermission(List<String> granted, boolean all) {
                    if (all) {
                        ToastUtils.show("获取权限成功");
                    }else {
                        ToastUtils.show("获取权限成功,部分权限未正常授予");
                    }
                }

                @Override
                public void noPermission(List<String> denied, boolean quick) {
                    if(quick) {
                        ToastUtils.show("被永久拒绝授权,请手动授予权限");
                        //如果是被永久拒绝就跳转到应用权限系统设置页面
                        XXPermissions.startPermissionActivity(MainActivity.this);
                    } else {
                        ToastUtils.show("获取权限失败");
                    }
                }
            });
}
 
Example #9
Source File: MainActivity.java    From XXPermissions with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //初始化吐司工具类
    ToastUtils.init(getApplication(), new ToastWhiteStyle(getApplicationContext()));
}
 
Example #10
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 5 votes vote down vote up
public void show8(View v) {
    new XToast(ToastActivity.this)
            .setDuration(1000)
            .setView(ToastUtils.getToast().getView())
            .setAnimStyle(android.R.style.Animation_Translucent)
            .setText(android.R.id.message, "就问你溜不溜")
            .show();
}
 
Example #11
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 5 votes vote down vote up
public void show2(View v) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            ToastUtils.show("我是子线程中弹出的吐司");
        }
    }).start();
}
 
Example #12
Source File: PermissionsAspect.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 在连接点进行方法替换
 */
@Around("method() && @annotation(permissions)")
public void aroundJoinPoint(final ProceedingJoinPoint joinPoint, Permissions permissions) {
    XXPermissions.with(ActivityStackManager.getInstance().getTopActivity())
            .permission(permissions.value())
            .request(new OnPermission() {

                @Override
                public void hasPermission(List<String> granted, boolean all) {
                    if (all) {
                        try {
                            // 获得权限,执行原方法
                            joinPoint.proceed();
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                }

                @Override
                public void noPermission(List<String> denied, boolean quick) {
                    if (quick) {
                        ToastUtils.show(R.string.common_permission_fail);
                        XXPermissions.gotoPermissionSettings(ActivityStackManager.getInstance().getTopActivity(), false);
                    } else {
                        ToastUtils.show(R.string.common_permission_hint);
                    }
                }
            });
}
 
Example #13
Source File: ShareDialog.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * {@link BaseAdapter.OnItemClickListener}
 */
@Override
public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
    Platform platform = mAdapter.getItem(position).getSharePlatform();
    if (platform != null) {
        UmengClient.share(getActivity(), platform, mData, mListener);
    } else {
        // 复制到剪贴板
        getSystemService(ClipboardManager.class).setPrimaryClip(ClipData.newPlainText("url", mData.getShareUrl()));
        ToastUtils.show(R.string.share_platform_copy_hint);
    }
    dismiss();
}
 
Example #14
Source File: MainApplication.java    From TitleBar with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // 初始化 Toast
    ToastUtils.init(this);

    // 初始化 TitleBar 样式
    TitleBar.initStyle(new TitleBarLightStyle(this));
}
 
Example #15
Source File: MyApplication.java    From EasyHttp with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ToastUtils.init(this);

    // 网络请求框架初始化
    IRequestServer server;
    if (BuildConfig.DEBUG) {
        server = new TestServer();
    } else {
        server = new ReleaseServer();
    }

    EasyConfig.with(new OkHttpClient())
            // 是否打印日志
            //.setLogEnabled(BuildConfig.DEBUG)
            // 设置服务器配置
            .setServer(server)
            // 设置请求处理策略
            .setHandler(new RequestHandler(this))
            // 设置请求重试次数
            .setRetryCount(1)
            // 添加全局请求参数
            //.addParam("token", "6666666")
            // 添加全局请求头
            //.addHeader("time", "20191030")
            .into();
}
 
Example #16
Source File: MainActivity.java    From EasyHttp with Apache License 2.0 5 votes vote down vote up
@Override
public void noPermission(List<String> denied, boolean quick) {
    if (quick) {
        ToastUtils.show("授权失败,请手动授予权限");
        XXPermissions.startPermissionActivity(this, true);
    } else {
        ToastUtils.show("请先授予权限");
        requestPermission();
    }
}
 
Example #17
Source File: MainActivity.java    From XToast with Apache License 2.0 5 votes vote down vote up
public void show7(View v) {
    // 这里需要先初始化 ToastUtils,实际开发中这句代码应当放在 Application.onCreate 方法中
    ToastUtils.init(getApplication());
    // 将 ToastUtils 中的 View 转移给 XToast 来显示
    new XToast(MainActivity.this)
            .setDuration(1000)
            .setView(ToastUtils.getToast().getView())
            .setAnimStyle(android.R.style.Animation_Translucent)
            .setText(android.R.id.message, "就问你溜不溜")
            .show();
}
 
Example #18
Source File: ToastAction.java    From AndroidProject with Apache License 2.0 4 votes vote down vote up
default void toast(CharSequence text) {
    ToastUtils.show(text);
}
 
Example #19
Source File: ToastAction.java    From AndroidProject with Apache License 2.0 4 votes vote down vote up
default void toast(@StringRes int id) {
    ToastUtils.show(id);
}
 
Example #20
Source File: ToastAction.java    From AndroidProject with Apache License 2.0 4 votes vote down vote up
default void toast(Object object) {
    ToastUtils.show(object);
}
 
Example #21
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
public void show1(View v) {
    for (int i = 0; i < 3; i++) {
        ToastUtils.show("我是第" + (i + 1) + "个吐司");
    }
}
 
Example #22
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
public void show3(View v) {
    ToastUtils.initStyle(new ToastWhiteStyle(getApplication()));
    ToastUtils.show("动态切换白色吐司样式成功");
}
 
Example #23
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
public void show4(View v) {
    ToastUtils.initStyle(new ToastBlackStyle(getApplication()));
    ToastUtils.show("动态切换黑色吐司样式成功");
}
 
Example #24
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
public void show5(View v) {
    ToastUtils.initStyle(new ToastQQStyle(getApplication()));
    ToastUtils.show("QQ那种还不简单,分分钟的事");
}
 
Example #25
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
public void show6(View v) {
    ToastUtils.initStyle(new ToastAliPayStyle(getApplication()));
    ToastUtils.show("支付宝那种还不简单,分分钟的事");
}
 
Example #26
Source File: ToastActivity.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
public void show7(View v) {
    // ToastUtils.setView(View.inflate(getApplication(), R.layout.toast_custom_view, null));
    ToastUtils.setView(R.layout.toast_custom_view);
    ToastUtils.setGravity(Gravity.CENTER, 0, 0);
    ToastUtils.show("我是自定义Toast");
}
 
Example #27
Source File: BaseActivity.java    From EasyHttp with Apache License 2.0 4 votes vote down vote up
@Override
public void onFail(Exception e) {
    ToastUtils.show(e.getMessage());
}
 
Example #28
Source File: BaseActivity.java    From EasyHttp with Apache License 2.0 4 votes vote down vote up
@Override
public void onSucceed(Object result) {
    if (result instanceof HttpData) {
        ToastUtils.show(((HttpData) result).getMessage());
    }
}