diff --git a/README.md b/README.md index 7859275..eea0a9b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ #### 集成步骤 dependencies { - implementation 'com.hjq:toast:8.5' + implementation 'com.hjq:toast:8.6' } #### 初始化 Toast diff --git a/ToastUtils.apk b/ToastUtils.apk index f72a6e5..732ee21 100644 Binary files a/ToastUtils.apk and b/ToastUtils.apk differ diff --git a/app/build.gradle b/app/build.gradle index ca6c608..3db9afa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 30 defaultConfig { applicationId "com.hjq.toast.demo" minSdkVersion 14 - targetSdkVersion 28 - versionCode 85 - versionName "8.5" + targetSdkVersion 30 + versionCode 86 + versionName "8.6" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -22,7 +22,8 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation project(':library') - implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'androidx.appcompat:appcompat:1.3.0-alpha01' + implementation 'com.google.android.material:material:1.3.0-alpha01' // 标题栏:https://github.com/getActivity/TitleBar implementation 'com.hjq:titlebar:6.5' // 悬浮窗:https://github.com/getActivity/XToast diff --git a/app/src/main/java/com/hjq/toast/demo/ToastActivity.java b/app/src/main/java/com/hjq/toast/demo/ToastActivity.java index 3a23287..bd6ff3f 100644 --- a/app/src/main/java/com/hjq/toast/demo/ToastActivity.java +++ b/app/src/main/java/com/hjq/toast/demo/ToastActivity.java @@ -1,12 +1,12 @@ package com.hjq.toast.demo; import android.os.Bundle; -import android.os.Handler; -import android.support.v4.app.NotificationManagerCompat; -import android.support.v7.app.AppCompatActivity; import android.view.Gravity; import android.view.View; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.NotificationManagerCompat; + import com.hjq.toast.SupportToast; import com.hjq.toast.ToastUtils; import com.hjq.toast.style.ToastAliPayStyle; diff --git a/library/build.gradle b/library/build.gradle index 3271c29..2a3f658 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 3 targetSdkVersion 26 - versionCode 85 - versionName "8.5" + versionCode 86 + versionName "8.6" } } @@ -16,7 +16,7 @@ publish { userOrg = 'getactivity' groupId = 'com.hjq' artifactId = 'toast' - version = '8.5' + version = '8.6' description = 'This is a very functional Toast' website = "https://github.com/getActivity/ToastUtils" } diff --git a/library/src/main/java/com/hjq/toast/BaseToast.java b/library/src/main/java/com/hjq/toast/BaseToast.java index a2f618c..b08e77c 100644 --- a/library/src/main/java/com/hjq/toast/BaseToast.java +++ b/library/src/main/java/com/hjq/toast/BaseToast.java @@ -24,7 +24,7 @@ public BaseToast(Application application) { @Override public void setView(View view) { super.setView(view); - mMessageView = getMessageView(view); + setMessageView(findMessageView(view)); } @Override @@ -32,10 +32,14 @@ public void setText(CharSequence s) { mMessageView.setText(s); } + void setMessageView(TextView textView) { + mMessageView = textView; + } + /** * 智能获取用于显示消息的 TextView */ - private static TextView getMessageView(View view) { + static TextView findMessageView(View view) { if (view instanceof TextView) { return (TextView) view; } else if (view.findViewById(android.R.id.message) instanceof TextView) { diff --git a/library/src/main/java/com/hjq/toast/SupportToast.java b/library/src/main/java/com/hjq/toast/SupportToast.java index 247bbe4..800d58e 100644 --- a/library/src/main/java/com/hjq/toast/SupportToast.java +++ b/library/src/main/java/com/hjq/toast/SupportToast.java @@ -1,6 +1,7 @@ package com.hjq.toast; import android.app.Application; +import android.view.View; /** * author : Android 轮子哥 @@ -13,6 +14,19 @@ public final class SupportToast extends BaseToast { /** 吐司弹窗显示辅助类 */ private final ToastHelper mToastHelper; + /** Toast 的视图 */ + private View mView; + /** Toast 的重心 */ + private int mGravity; + /** 水平偏移 */ + private int mXOffset; + /** 垂直偏移 */ + private int mYOffset; + /** 水平间距百分比 */ + private float mHorizontalMargin; + /** 垂直间距百分比 */ + private float mVerticalMargin; + public SupportToast(Application application) { super(application); mToastHelper = new ToastHelper(this, application); @@ -29,4 +43,53 @@ public void cancel() { // 取消显示 mToastHelper.cancel(); } + + @Override + public void setView(View view) { + mView = view; + setMessageView(findMessageView(view)); + } + + @Override + public View getView() { + return mView; + } + + @Override + public void setGravity(int gravity, int xOffset, int yOffset) { + mGravity = gravity; + mXOffset = xOffset; + mYOffset = yOffset; + } + + @Override + public int getGravity() { + return mGravity; + } + + @Override + public int getXOffset() { + return mXOffset; + } + + @Override + public int getYOffset() { + return mYOffset; + } + + @Override + public void setMargin(float horizontalMargin, float verticalMargin) { + mHorizontalMargin = horizontalMargin; + mVerticalMargin = verticalMargin; + } + + @Override + public float getHorizontalMargin() { + return mHorizontalMargin; + } + + @Override + public float getVerticalMargin() { + return mVerticalMargin; + } } \ No newline at end of file diff --git a/library/src/main/java/com/hjq/toast/ToastHelper.java b/library/src/main/java/com/hjq/toast/ToastHelper.java index 54b26d5..0099955 100644 --- a/library/src/main/java/com/hjq/toast/ToastHelper.java +++ b/library/src/main/java/com/hjq/toast/ToastHelper.java @@ -95,6 +95,8 @@ void show() { params.gravity = mToast.getGravity(); params.x = mToast.getXOffset(); params.y = mToast.getYOffset(); + params.verticalMargin = mToast.getVerticalMargin(); + params.horizontalMargin = mToast.getHorizontalMargin(); try { Activity topActivity = mWindowHelper.getTopActivity();