Skip to content

Commit

Permalink
兼容 Android 11 新特性
Browse files Browse the repository at this point in the history
  • Loading branch information
getActivity committed Jul 1, 2020
1 parent 4654e7b commit a46bfff
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#### 集成步骤

dependencies {
implementation 'com.hjq:toast:8.5'
implementation 'com.hjq:toast:8.6'
}

#### 初始化 Toast
Expand Down
Binary file modified ToastUtils.apk
Binary file not shown.
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/hjq/toast/demo/ToastActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ android {
defaultConfig {
minSdkVersion 3
targetSdkVersion 26
versionCode 85
versionName "8.5"
versionCode 86
versionName "8.6"
}
}

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"
}
Expand Down
8 changes: 6 additions & 2 deletions library/src/main/java/com/hjq/toast/BaseToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ public BaseToast(Application application) {
@Override
public void setView(View view) {
super.setView(view);
mMessageView = getMessageView(view);
setMessageView(findMessageView(view));
}

@Override
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) {
Expand Down
63 changes: 63 additions & 0 deletions library/src/main/java/com/hjq/toast/SupportToast.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hjq.toast;

import android.app.Application;
import android.view.View;

/**
* author : Android 轮子哥
Expand All @@ -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);
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions library/src/main/java/com/hjq/toast/ToastHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a46bfff

Please sign in to comment.