forked from getActivity/Toaster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
509 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.hjq.toast; | ||
|
||
import android.app.Application; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* author : HJQ | ||
* github : https://github.com/getActivity/ToastUtils | ||
* time : 2018/11/03 | ||
* desc : Toast基类 | ||
*/ | ||
abstract class BaseToast extends Toast implements Runnable { | ||
|
||
// 显示延迟时间,避免重复点击 | ||
static final int SHOW_DELAY_MILLIS = 300; | ||
|
||
// Toast 处理消息线程 | ||
private final Handler mHandler = new Handler(Looper.getMainLooper()); | ||
|
||
// 吐司消息View | ||
private TextView mMessageView; | ||
|
||
// 吐司显示的文本 | ||
private CharSequence mText; | ||
|
||
BaseToast(Application application) { | ||
super(application); | ||
} | ||
|
||
@Override | ||
public void setView(View view) { | ||
super.setView(view); | ||
if (view instanceof TextView) { | ||
mMessageView = (TextView) view; return; | ||
}else if (view.findViewById(R.id.toast_main_text_view_id) instanceof TextView) { | ||
mMessageView = ((TextView) view.findViewById(R.id.toast_main_text_view_id)); return; | ||
} else if (view instanceof ViewGroup) { | ||
if ((mMessageView = findTextView((ViewGroup) view)) != null) return; | ||
} | ||
// 如果设置的布局没有包含一个 TextView 则抛出异常,必须要包含一个 TextView 作为 Message View | ||
throw new IllegalArgumentException("The layout must contain a TextView"); | ||
} | ||
|
||
/*** | ||
* 获取当前 Handler 对象 | ||
*/ | ||
Handler getHandler() { | ||
return mHandler; | ||
} | ||
|
||
/** | ||
* 获取当前的消息 View | ||
*/ | ||
TextView getMessageView() { | ||
return mMessageView; | ||
} | ||
|
||
/** | ||
* 获取当前欲显示的文本 | ||
*/ | ||
CharSequence getText() { | ||
return mText; | ||
} | ||
|
||
@Override | ||
public void setText(CharSequence s) { | ||
// 记录本次吐司欲显示的文本 | ||
mText = s; | ||
} | ||
|
||
/** | ||
* 递归获取ViewGroup中的TextView对象 | ||
*/ | ||
private static TextView findTextView(ViewGroup group) { | ||
for (int i = 0; i < group.getChildCount(); i++) { | ||
View view = group.getChildAt(i); | ||
if ((view instanceof TextView)) { | ||
return (TextView) view; | ||
} else if (view instanceof ViewGroup) { | ||
TextView textView = findTextView((ViewGroup) view); | ||
if (textView != null) return textView; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.hjq.toast; | ||
|
||
import android.app.Application; | ||
|
||
/** | ||
* author : HJQ | ||
* github : https://github.com/getActivity/ToastUtils | ||
* time : 2018/11/02 | ||
* desc : 不需要通知栏权限的 Toast | ||
*/ | ||
final class SupportToast extends BaseToast { | ||
|
||
// 吐司弹窗显示辅助类 | ||
private ToastHelper mToastHelper; | ||
|
||
SupportToast(Application application) { | ||
super(application); | ||
mToastHelper = new ToastHelper(this, application); | ||
} | ||
|
||
@Override | ||
public void show() { | ||
// 移除之前显示吐司的任务 | ||
getHandler().removeCallbacks(this); | ||
// 添加一个显示吐司的任务 | ||
getHandler().postDelayed(this, SHOW_DELAY_MILLIS); | ||
} | ||
|
||
/** | ||
* {@link Runnable} | ||
*/ | ||
@Override | ||
public void run() { | ||
// 设置吐司文本 | ||
getMessageView().setText(getText()); | ||
// 显示吐司 | ||
mToastHelper.show(); | ||
} | ||
|
||
@Override | ||
public void cancel() { | ||
// 移除之前显示吐司的任务 | ||
getHandler().removeCallbacks(this); | ||
// 取消显示 | ||
mToastHelper.cancel(); | ||
} | ||
} |
Oops, something went wrong.