1. 修改TipToast背景为渐变
2. 增加左侧带图片的TipToast
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -4,7 +4,7 @@
|
|||||||
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
|
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
|
||||||
<groovy codeStyle="LEGACY" />
|
<groovy codeStyle="LEGACY" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,6 +4,8 @@ import android.app.Application;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.alibaba.android.arouter.launcher.ARouter;
|
import com.alibaba.android.arouter.launcher.ARouter;
|
||||||
@@ -17,6 +19,7 @@ import com.mogo.commons.network.ParamsUtil;
|
|||||||
import com.mogo.commons.network.X509TrustManagerImpl;
|
import com.mogo.commons.network.X509TrustManagerImpl;
|
||||||
import com.mogo.commons.storage.SpStorage;
|
import com.mogo.commons.storage.SpStorage;
|
||||||
import com.mogo.utils.ThreadPoolService;
|
import com.mogo.utils.ThreadPoolService;
|
||||||
|
import com.mogo.utils.TipDrawable;
|
||||||
import com.mogo.utils.TipToast;
|
import com.mogo.utils.TipToast;
|
||||||
import com.mogo.utils.network.NetConfig;
|
import com.mogo.utils.network.NetConfig;
|
||||||
|
|
||||||
@@ -65,13 +68,26 @@ public class AbsMogoApplication extends Application {
|
|||||||
ARouter.openLog();
|
ARouter.openLog();
|
||||||
}
|
}
|
||||||
ARouter.init( sApp );
|
ARouter.init( sApp );
|
||||||
TipToast.init( this, ( ( context, message ) -> {
|
TipToast.init( this, ( ( context, message, tipDrawable ) -> {
|
||||||
if ( TextUtils.isEmpty( message ) ) {
|
if ( TextUtils.isEmpty( message ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
View contentView = LayoutInflater.from( context ).inflate( R.layout.module_commons_layout_toast, null );
|
View contentView;
|
||||||
TextView txt = contentView.findViewById( R.id.module_commons_toast_msg );
|
if(tipDrawable==null) {
|
||||||
txt.setText( message );
|
contentView = LayoutInflater.from(context).inflate(R.layout.module_commons_layout_toast, null);
|
||||||
|
TextView txt = contentView.findViewById(R.id.module_commons_toast_msg);
|
||||||
|
txt.setText(message);
|
||||||
|
}else{
|
||||||
|
// 有图片,使用带图片的布局,当前只实现了左侧图片
|
||||||
|
contentView = LayoutInflater.from(context).inflate(R.layout.module_commons_layout_toast_with_left_drawable, null);
|
||||||
|
TextView txt = contentView.findViewById(R.id.module_commons_toast_msg);
|
||||||
|
ImageView img = contentView.findViewById(R.id.module_commons_toast_left_drawable);
|
||||||
|
img.setImageDrawable(tipDrawable.getDrawable());
|
||||||
|
ViewGroup.LayoutParams params = img.getLayoutParams();
|
||||||
|
params.width = tipDrawable.getWidth();
|
||||||
|
params.height = tipDrawable.getHeight();
|
||||||
|
txt.setText(message);
|
||||||
|
}
|
||||||
return contentView;
|
return contentView;
|
||||||
} ) );
|
} ) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<corners android:radius="90dp" />
|
<corners android:radius="90dp" />
|
||||||
<gradient
|
<gradient
|
||||||
android:angle="270"
|
android:angle="180"
|
||||||
android:endColor="#F2161616"
|
android:endColor="#FF3F4057"
|
||||||
android:startColor="#F2161616" />
|
android:startColor="#FF5E6079" />
|
||||||
</shape>
|
</shape>
|
||||||
@@ -1,27 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/module_commons_toast_bkg"
|
android:background="@drawable/module_commons_toast_bkg"
|
||||||
android:orientation="vertical">
|
android:paddingTop="@dimen/module_commons_toast_marginTop"
|
||||||
|
android:paddingBottom="@dimen/module_commons_toast_marginBottom"
|
||||||
|
android:paddingLeft="@dimen/module_commons_toast_marginLeft"
|
||||||
|
android:paddingRight="@dimen/module_commons_toast_marginRight">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/module_commons_toast_msg"
|
android:id="@+id/module_commons_toast_msg"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginLeft="@dimen/module_commons_toast_marginLeft"
|
|
||||||
android:layout_marginTop="@dimen/module_commons_toast_marginTop"
|
|
||||||
android:layout_marginRight="@dimen/module_commons_toast_marginRight"
|
|
||||||
android:layout_marginBottom="@dimen/module_commons_toast_marginBottom"
|
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:drawablePadding="@dimen/module_commons_toast_space_between_icon_and_msg"
|
||||||
android:maxWidth="@dimen/module_commons_toast_maxWidth"
|
android:maxWidth="@dimen/module_commons_toast_maxWidth"
|
||||||
android:maxLength="20"
|
android:maxLength="20"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:minWidth="@dimen/module_commons_toast_minWidth"
|
|
||||||
android:textColor="#FFFF"
|
android:textColor="#FFFF"
|
||||||
android:textSize="@dimen/module_commons_toast_textSize"
|
android:textSize="@dimen/module_commons_toast_textSize"
|
||||||
tools:text="测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试" />
|
tools:text="测试测试测试" />
|
||||||
</LinearLayout>
|
|
||||||
|
<!-- android:minWidth="@dimen/module_commons_toast_minWidth"-->
|
||||||
|
</FrameLayout>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/module_commons_toast_bkg"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="@dimen/module_commons_toast_with_left_drawable_marginLeft"
|
||||||
|
android:paddingTop="@dimen/module_commons_toast_with_left_drawable_marginTop"
|
||||||
|
android:paddingRight="@dimen/module_commons_toast_marginRight"
|
||||||
|
android:paddingBottom="@dimen/module_commons_toast_with_left_drawable_marginBottom">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/module_commons_toast_left_drawable"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="@dimen/module_commons_toast_space_between_icon_and_msg"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/module_commons_toast_msg"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:drawablePadding="@dimen/module_commons_toast_space_between_icon_and_msg"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:gravity="center"
|
||||||
|
android:maxWidth="@dimen/module_commons_toast_maxWidth"
|
||||||
|
android:maxLength="20"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="#FFFF"
|
||||||
|
android:textSize="@dimen/module_commons_toast_textSize"
|
||||||
|
tools:text="测试测试测试" />
|
||||||
|
|
||||||
|
<!-- android:minWidth="@dimen/module_commons_toast_minWidth"-->
|
||||||
|
</LinearLayout>
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="module_commons_toast_marginLeft">50px</dimen>
|
<dimen name="module_commons_toast_marginLeft">63px</dimen>
|
||||||
<dimen name="module_commons_toast_marginRight">50px</dimen>
|
<dimen name="module_commons_toast_with_left_drawable_marginLeft">30px</dimen>
|
||||||
|
<dimen name="module_commons_toast_marginRight">63px</dimen>
|
||||||
<dimen name="module_commons_toast_marginTop">32px</dimen>
|
<dimen name="module_commons_toast_marginTop">32px</dimen>
|
||||||
<dimen name="module_commons_toast_marginBottom">32px</dimen>
|
<dimen name="module_commons_toast_marginBottom">32px</dimen>
|
||||||
|
<dimen name="module_commons_toast_with_left_drawable_marginTop">19px</dimen>
|
||||||
|
<dimen name="module_commons_toast_with_left_drawable_marginBottom">19px</dimen>
|
||||||
<dimen name="module_commons_toast_textSize">40px</dimen>
|
<dimen name="module_commons_toast_textSize">40px</dimen>
|
||||||
<dimen name="module_commons_toast_minWidth">698px</dimen>
|
<dimen name="module_commons_toast_minWidth">698px</dimen>
|
||||||
<dimen name="module_commons_toast_maxWidth">900px</dimen>
|
<dimen name="module_commons_toast_maxWidth">900px</dimen>
|
||||||
<dimen name="module_commons_toast_y_offset">130px</dimen>
|
<dimen name="module_commons_toast_y_offset">130px</dimen>
|
||||||
|
<dimen name="module_commons_toast_icon_width">94px</dimen>
|
||||||
|
<dimen name="module_commons_toast_space_between_icon_and_msg">21px</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="module_commons_toast_marginLeft">30px</dimen>
|
<dimen name="module_commons_toast_marginLeft">33px</dimen>
|
||||||
<dimen name="module_commons_toast_marginRight">30px</dimen>
|
<dimen name="module_commons_toast_with_left_drawable_marginLeft">17px</dimen>
|
||||||
|
<dimen name="module_commons_toast_marginRight">33px</dimen>
|
||||||
<dimen name="module_commons_toast_marginTop">16px</dimen>
|
<dimen name="module_commons_toast_marginTop">16px</dimen>
|
||||||
<dimen name="module_commons_toast_marginBottom">16px</dimen>
|
<dimen name="module_commons_toast_marginBottom">16px</dimen>
|
||||||
|
<dimen name="module_commons_toast_with_left_drawable_marginTop">10px</dimen>
|
||||||
|
<dimen name="module_commons_toast_with_left_drawable_marginBottom">10px</dimen>
|
||||||
<dimen name="module_commons_toast_textSize">22px</dimen>
|
<dimen name="module_commons_toast_textSize">22px</dimen>
|
||||||
<dimen name="module_commons_toast_minWidth">371px</dimen>
|
<dimen name="module_commons_toast_minWidth">371px</dimen>
|
||||||
<dimen name="module_commons_toast_maxWidth">500px</dimen>
|
<dimen name="module_commons_toast_maxWidth">500px</dimen>
|
||||||
<dimen name="module_commons_toast_y_offset">72px</dimen>
|
<dimen name="module_commons_toast_y_offset">72px</dimen>
|
||||||
|
<dimen name="module_commons_toast_icon_width">50px</dimen>
|
||||||
|
<dimen name="module_commons_toast_space_between_icon_and_msg">10px</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.mogo.utils;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TipToast弹出框的图片资源封装类
|
||||||
|
* 当前只支持添加一张图片,可添加到文字的 左{@link #TIP_DRAWABLE_GRAVITY_LEFT}, 上{@link #TIP_DRAWABLE_GRAVITY_TOP}, 右{@link #TIP_DRAWABLE_GRAVITY_RIGHT}, 下{@link #TIP_DRAWABLE_GRAVITY_BOTTOM}
|
||||||
|
*
|
||||||
|
* 当前仅支持添加左侧图片,所以{@link #gravity} 这个参数形同虚设
|
||||||
|
*
|
||||||
|
* @author tongchenfei
|
||||||
|
*/
|
||||||
|
public class TipDrawable {
|
||||||
|
public static final int TIP_DRAWABLE_GRAVITY_LEFT = 1;
|
||||||
|
public static final int TIP_DRAWABLE_GRAVITY_TOP = 2;
|
||||||
|
public static final int TIP_DRAWABLE_GRAVITY_RIGHT = 3;
|
||||||
|
public static final int TIP_DRAWABLE_GRAVITY_BOTTOM = 4;
|
||||||
|
private Drawable drawable;
|
||||||
|
private int gravity;
|
||||||
|
private int width;
|
||||||
|
private int height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认图片居左,宽高使用{@link Drawable#getIntrinsicWidth()}和{@link Drawable#getIntrinsicHeight()}
|
||||||
|
* @param drawable 要展示的图片
|
||||||
|
*/
|
||||||
|
public TipDrawable(Drawable drawable) {
|
||||||
|
this(drawable, TIP_DRAWABLE_GRAVITY_LEFT,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认图片居左
|
||||||
|
* @param drawable 要展示的图片
|
||||||
|
* @param width 要展示的图片宽度
|
||||||
|
* @param height 要展示的图片高度
|
||||||
|
*/
|
||||||
|
public TipDrawable(Drawable drawable, int width, int height) {
|
||||||
|
this(drawable, TIP_DRAWABLE_GRAVITY_LEFT,width,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认宽高使用{@link Drawable#getIntrinsicWidth()}和{@link Drawable#getIntrinsicHeight()}
|
||||||
|
* @param drawable 要展示的图片
|
||||||
|
* @param gravity 左{@link #TIP_DRAWABLE_GRAVITY_LEFT}, 上{@link #TIP_DRAWABLE_GRAVITY_TOP}, 右{@link #TIP_DRAWABLE_GRAVITY_RIGHT}, 下{@link #TIP_DRAWABLE_GRAVITY_BOTTOM}
|
||||||
|
*/
|
||||||
|
public TipDrawable(Drawable drawable, int gravity) {
|
||||||
|
this(drawable, gravity,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可自定义展示位置
|
||||||
|
* @param drawable 要展示的图片
|
||||||
|
* @param gravity 左{@link #TIP_DRAWABLE_GRAVITY_LEFT}, 上{@link #TIP_DRAWABLE_GRAVITY_TOP}, 右{@link #TIP_DRAWABLE_GRAVITY_RIGHT}, 下{@link #TIP_DRAWABLE_GRAVITY_BOTTOM}
|
||||||
|
*/
|
||||||
|
public TipDrawable(Drawable drawable, int gravity, int width, int height) {
|
||||||
|
this.drawable = drawable;
|
||||||
|
this.gravity = gravity;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable getDrawable() {
|
||||||
|
return drawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGravity() {
|
||||||
|
return gravity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,10 @@ package com.mogo.utils;
|
|||||||
* 2016/1/1 by congtaowang
|
* 2016/1/1 by congtaowang
|
||||||
*
|
*
|
||||||
* @Version 1.0
|
* @Version 1.0
|
||||||
|
*
|
||||||
|
* 增加了图片支持
|
||||||
|
*
|
||||||
|
* @Version 1.1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -45,17 +49,17 @@ public final class TipToast {
|
|||||||
sGenerator = null;
|
sGenerator = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void tip( final String message, int duration ) {
|
private static void tip( final String message, int duration ,TipDrawable tipDrawable) {
|
||||||
if ( !checkParams() ) {
|
if ( !checkParams() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( TextUtils.isEmpty( message ) ) {
|
if ( TextUtils.isEmpty( message ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new ToastThread( new StringToastRunnable( sContext, message, duration ) ).start();
|
new ToastThread(new StringToastRunnable(sContext, message, duration, tipDrawable)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void tip( final int msgId, int duration ) {
|
private static void tip( final int msgId, int duration,TipDrawable tipDrawable ) {
|
||||||
if ( !checkParams() ) {
|
if ( !checkParams() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -66,7 +70,7 @@ public final class TipToast {
|
|||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tip( ResourcesHelper.getString( sContext, msgId ), duration );
|
tip( ResourcesHelper.getString( sContext, msgId ), duration ,tipDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkParams() {
|
private static boolean checkParams() {
|
||||||
@@ -82,27 +86,53 @@ public final class TipToast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void tip( final String message ) {
|
public static void tip( final String message ) {
|
||||||
tip( message, Toast.LENGTH_SHORT );
|
tip( message, Toast.LENGTH_SHORT,null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tip( final int msgId ) {
|
public static void tip( final int msgId ) {
|
||||||
tip( msgId, Toast.LENGTH_SHORT );
|
tip( msgId, Toast.LENGTH_SHORT ,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void longTip( String message ) {
|
public static void longTip( String message ) {
|
||||||
tip( message, Toast.LENGTH_LONG );
|
tip( message, Toast.LENGTH_LONG ,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void longTip( int msgId ) {
|
public static void longTip( int msgId ) {
|
||||||
tip( msgId, Toast.LENGTH_LONG );
|
tip( msgId, Toast.LENGTH_LONG ,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void shortTip( String message ) {
|
public static void shortTip( String message ) {
|
||||||
tip( message, Toast.LENGTH_SHORT );
|
tip( message, Toast.LENGTH_SHORT ,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void shortTip( int msgId ) {
|
public static void shortTip( int msgId ) {
|
||||||
tip( msgId, Toast.LENGTH_SHORT );
|
tip( msgId, Toast.LENGTH_SHORT ,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -===带图片的方法===-
|
||||||
|
|
||||||
|
public static void tip( final String message,TipDrawable tipDrawable ) {
|
||||||
|
tip( message, Toast.LENGTH_SHORT,tipDrawable );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tip( final int msgId,TipDrawable tipDrawable ) {
|
||||||
|
tip( msgId, Toast.LENGTH_SHORT ,tipDrawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void longTip( String message,TipDrawable tipDrawable ) {
|
||||||
|
tip( message, Toast.LENGTH_LONG ,tipDrawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void longTip( int msgId ,TipDrawable tipDrawable) {
|
||||||
|
tip( msgId, Toast.LENGTH_LONG ,tipDrawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shortTip( String message,TipDrawable tipDrawable ) {
|
||||||
|
tip( message, Toast.LENGTH_SHORT ,tipDrawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shortTip( int msgId,TipDrawable tipDrawable ) {
|
||||||
|
tip( msgId, Toast.LENGTH_SHORT ,tipDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ToastThread extends Thread {
|
static class ToastThread extends Thread {
|
||||||
@@ -117,11 +147,13 @@ public final class TipToast {
|
|||||||
Context context;
|
Context context;
|
||||||
String msg;
|
String msg;
|
||||||
int duration;
|
int duration;
|
||||||
|
TipDrawable tipDrawable;
|
||||||
|
|
||||||
public StringToastRunnable( Context context, String msg, int duration ) {
|
public StringToastRunnable( Context context, String msg, int duration,TipDrawable tipDrawable ) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
|
this.tipDrawable = tipDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -131,44 +163,40 @@ public final class TipToast {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sHandler.post( new Runnable() {
|
sHandler.post(() -> {
|
||||||
|
synchronized ( sSyncObject ) {
|
||||||
|
|
||||||
@Override
|
if ( context == null ) {
|
||||||
public void run() {
|
return;
|
||||||
synchronized ( sSyncObject ) {
|
}
|
||||||
|
|
||||||
if ( context == null ) {
|
if ( sToast != null ) {
|
||||||
return;
|
sToast.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( sToast != null ) {
|
if ( sGenerator == null ) {
|
||||||
sToast.cancel();
|
sToast = Toast.makeText( context, msg, duration );
|
||||||
}
|
} else {
|
||||||
|
sToast = new Toast( context );
|
||||||
if ( sGenerator == null ) {
|
final View view = sGenerator.make( context, msg, tipDrawable );
|
||||||
sToast = Toast.makeText( context, msg, duration );
|
if ( view != null ) {
|
||||||
|
sToast.setView( view );
|
||||||
|
sToast.setGravity( sGenerator.gravity(), sGenerator.xOffset(), sGenerator.yOffset() );
|
||||||
|
sToast.setDuration( duration );
|
||||||
} else {
|
} else {
|
||||||
sToast = new Toast( context );
|
sToast = Toast.makeText( context, msg, duration );
|
||||||
final View view = sGenerator.make( context, msg );
|
|
||||||
if ( view != null ) {
|
|
||||||
sToast.setView( view );
|
|
||||||
sToast.setGravity( sGenerator.gravity(), sGenerator.xOffset(), sGenerator.yOffset() );
|
|
||||||
sToast.setDuration( duration );
|
|
||||||
} else {
|
|
||||||
sToast = Toast.makeText( context, msg, duration );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( sToast != null ) {
|
|
||||||
sToast.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( sToast != null ) {
|
||||||
|
sToast.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ToastViewGenerator {
|
public interface ToastViewGenerator {
|
||||||
View make( Context context, String message );
|
View make( Context context, String message,TipDrawable tipDrawable );
|
||||||
|
|
||||||
default int gravity() {
|
default int gravity() {
|
||||||
return Gravity.CENTER;
|
return Gravity.CENTER;
|
||||||
@@ -182,5 +210,4 @@ public final class TipToast {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ import com.mogo.service.statusmanager.StatusDescriptor;
|
|||||||
import com.mogo.service.windowview.IMogoTopViewStatusListener;
|
import com.mogo.service.windowview.IMogoTopViewStatusListener;
|
||||||
import com.mogo.utils.LaunchUtils;
|
import com.mogo.utils.LaunchUtils;
|
||||||
import com.mogo.utils.ResourcesHelper;
|
import com.mogo.utils.ResourcesHelper;
|
||||||
|
import com.mogo.utils.TipDrawable;
|
||||||
|
import com.mogo.utils.TipToast;
|
||||||
import com.mogo.utils.UiThreadHandler;
|
import com.mogo.utils.UiThreadHandler;
|
||||||
import com.mogo.utils.glide.GlideApp;
|
import com.mogo.utils.glide.GlideApp;
|
||||||
import com.mogo.utils.logger.Logger;
|
import com.mogo.utils.logger.Logger;
|
||||||
@@ -595,6 +597,19 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
|||||||
tv.setText("entrance add");
|
tv.setText("entrance add");
|
||||||
mApis.getEntranceButtonController().addBottomLayerView(tv, 50, 50);
|
mApis.getEntranceButtonController().addBottomLayerView(tv, 50, 50);
|
||||||
});
|
});
|
||||||
|
findViewById(R.id.btnShowTextTip).setOnClickListener(v-> TipToast.tip("分享成功"));
|
||||||
|
|
||||||
|
findViewById(R.id.btnShowDrawableTip).setOnClickListener(v->{
|
||||||
|
TipDrawable drawable =
|
||||||
|
new TipDrawable(getResources().getDrawable(R.drawable.model_ext_default_user_head), 150, 150);
|
||||||
|
TipToast.tip("分享成功",drawable);
|
||||||
|
});
|
||||||
|
|
||||||
|
findViewById(R.id.btnShowDrawableTipNoSize).setOnClickListener(v->{
|
||||||
|
TipDrawable drawable =
|
||||||
|
new TipDrawable(getResources().getDrawable(R.drawable.model_ext_default_user_head));
|
||||||
|
TipToast.tip("分享成功",drawable);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -174,6 +174,7 @@
|
|||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnDebugCtrlTopView"
|
android:id="@+id/btnDebugCtrlTopView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -210,11 +211,37 @@
|
|||||||
app:layout_constraintBottom_toTopOf="@id/btnDebugCtrlNaviView"
|
app:layout_constraintBottom_toTopOf="@id/btnDebugCtrlNaviView"
|
||||||
app:layout_constraintLeft_toLeftOf="parent" />
|
app:layout_constraintLeft_toLeftOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnShowTextTip"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="显示文字tip"
|
||||||
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/btnDebugAddBottomLayerView"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnShowDrawableTip"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="显示图文tip"
|
||||||
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/btnShowTextTip"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnShowDrawableTipNoSize"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="显示图文tip,没有大小"
|
||||||
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/btnShowDrawableTip"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Group
|
<androidx.constraintlayout.widget.Group
|
||||||
android:id="@+id/groupTopViewDebug"
|
android:id="@+id/groupTopViewDebug"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:constraint_referenced_ids="btnDebugCtrlNaviView,btnDebugCtrlSubView,btnDebugCtrlTopView,btnDebugAddBottomLayerView" />
|
app:constraint_referenced_ids="btnShowDrawableTipNoSize,btnShowDrawableTip,btnShowTextTip,btnDebugCtrlNaviView,btnDebugCtrlSubView,btnDebugCtrlTopView,btnDebugAddBottomLayerView" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -94,6 +94,7 @@ import com.mogo.service.module.MogoAction;
|
|||||||
import com.mogo.service.statusmanager.IMogoStatusManager;
|
import com.mogo.service.statusmanager.IMogoStatusManager;
|
||||||
import com.mogo.service.windowview.IMogoTopViewStatusListener;
|
import com.mogo.service.windowview.IMogoTopViewStatusListener;
|
||||||
import com.mogo.utils.NetworkUtils;
|
import com.mogo.utils.NetworkUtils;
|
||||||
|
import com.mogo.utils.TipDrawable;
|
||||||
import com.mogo.utils.TipToast;
|
import com.mogo.utils.TipToast;
|
||||||
import com.mogo.utils.WorkThreadHandler;
|
import com.mogo.utils.WorkThreadHandler;
|
||||||
import com.mogo.utils.logger.Logger;
|
import com.mogo.utils.logger.Logger;
|
||||||
|
|||||||
Reference in New Issue
Block a user