Skip to content

Commit

Permalink
支持GIF + 修复activity finish的时候remove view crash
Browse files Browse the repository at this point in the history
  • Loading branch information
denglin03 committed Oct 4, 2018
1 parent c628bb5 commit 971d7a4
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 93 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation project(':toast')
implementation 'com.facebook.fresco:fresco:1.10.0'
implementation 'com.facebook.fresco:animated-gif:1.10.0'
// implementation 'com.github.bboylin:UniversalToast:v1.0.6'
//memory leak
// debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.bboylin.universaltoast">
package="xyz.bboylin.demo">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
Expand All @@ -18,6 +18,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"/>
</application>

</manifest>
55 changes: 36 additions & 19 deletions app/src/main/java/xyz/bboylin/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.widget.ArrayAdapter;
import android.widget.ListView;

import xyz.bboylin.universaltoast.R;
import xyz.bboylin.universialtoast.UniversalToast;

public class MainActivity extends AppCompatActivity {
Expand All @@ -22,7 +21,7 @@ public class MainActivity extends AppCompatActivity {
public static final String[] ITEMS = {"通用toast", "强调toast", "可点击toast"
, "通用 + 成功toast", "通用 + 警告toast", "通用 + 错误toast"
, "强调 + 成功toast", "强调 + 警告toast", "强调 + 错误toast"
, "可点击 + 成功toast", "可点击 + 警告toast", "可点击 + 错误toast"};
, "可点击 + 成功toast", "可点击 + 警告toast", "可点击 + 错误toast", "支持gif的toast"};
private static final int REQUEST_PERMISSION_CODE = 123;

@Override
Expand All @@ -45,22 +44,27 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}
switch (position) {
case 0:
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT, UniversalToast.UNIVERSAL)
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT,
UniversalToast.UNIVERSAL)
.setGravity(Gravity.CENTER, 0, 0)
.setIcon(R.drawable.ic_done_white_24dp)
.setLeftIconRes(R.drawable.ic_done_white_24dp)
.show();
break;
case 1:
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT, UniversalToast.EMPHASIZE)
.setIcon(R.drawable.ic_check_circle_white_24dp)
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT,
UniversalToast.EMPHASIZE)
.setLeftIconRes(R.drawable.ic_check_circle_white_24dp)
.show();
break;
case 2:
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT, UniversalToast.CLICKABLE)
.setIcon(R.drawable.ic_done_white_24dp)
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT,
UniversalToast.CLICKABLE)
.setLeftIconRes(R.drawable.ic_done_white_24dp)
.setGravity(Gravity.TOP, 0, 0)
.setClickCallBack("查看", onClickListener)
.setClickCallback("查看", onClickListener)
.show();
// startActivity(new Intent(MainActivity.this, SecondActivity.class));
// finish();
break;
case 3:
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT).showSuccess();
Expand All @@ -72,29 +76,41 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
UniversalToast.makeText(MainActivity.this, "关注失败", UniversalToast.LENGTH_SHORT).showError();
break;
case 6:
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT, UniversalToast.EMPHASIZE).showSuccess();
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT,
UniversalToast.EMPHASIZE).showSuccess();
break;
case 7:
UniversalToast.makeText(MainActivity.this, "请先登录", UniversalToast.LENGTH_SHORT, UniversalToast.EMPHASIZE).showWarning();
UniversalToast.makeText(MainActivity.this, "请先登录", UniversalToast.LENGTH_SHORT,
UniversalToast.EMPHASIZE).showWarning();
break;
case 8:
UniversalToast.makeText(MainActivity.this, "关注失败", UniversalToast.LENGTH_SHORT, UniversalToast.EMPHASIZE).showError();
UniversalToast.makeText(MainActivity.this, "关注失败", UniversalToast.LENGTH_SHORT,
UniversalToast.EMPHASIZE).showError();
break;
case 9:
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT, UniversalToast.CLICKABLE)
.setClickCallBack("查看", onClickListener)
UniversalToast.makeText(MainActivity.this, "关注成功", UniversalToast.LENGTH_SHORT,
UniversalToast.CLICKABLE)
.setClickCallback("查看", onClickListener)
.showSuccess();
break;
case 10:
UniversalToast.makeText(MainActivity.this, "请先登录", UniversalToast.LENGTH_SHORT, UniversalToast.CLICKABLE)
.setClickCallBack("查看", onClickListener)
UniversalToast.makeText(MainActivity.this, "请先登录", UniversalToast.LENGTH_SHORT,
UniversalToast.CLICKABLE)
.setClickCallback("查看", onClickListener)
.showWarning();
break;
case 11:
UniversalToast.makeText(MainActivity.this, "关注失败", UniversalToast.LENGTH_SHORT, UniversalToast.CLICKABLE)
.setClickCallBack("查看", onClickListener)
UniversalToast.makeText(MainActivity.this, "关注失败", UniversalToast.LENGTH_SHORT,
UniversalToast.CLICKABLE)
.setClickCallback("查看", onClickListener)
.showError();
break;
case 12:
UniversalToast.makeText(MainActivity.this, "正在加载", UniversalToast.LENGTH_SHORT,
UniversalToast.UNIVERSAL)
.setGravity(Gravity.CENTER, 0, 0)
.setLeftGifUri(Uri.parse("res:///" + R.drawable.loading))
.show();
default:
}
}
Expand All @@ -105,7 +121,8 @@ private boolean requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (!Settings.canDrawOverlays(this)) {
UniversalToast.makeText(this, "请允许悬浮窗权限", UniversalToast.LENGTH_SHORT).showWarning();
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" +
getPackageName()));
startActivityForResult(intent, REQUEST_PERMISSION_CODE);
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/xyz/bboylin/demo/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.app.Application;

import com.facebook.drawee.backends.pipeline.Fresco;

/**
* Created by lin on 2018/3/2.
*/
Expand All @@ -10,6 +12,7 @@ public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
// if (LeakCanary.isInAnalyzerProcess(this)) {
// // This process is dedicated to LeakCanary for heap analysis.
// // You should not init your app in this process.
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/xyz/bboylin/demo/SecondActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xyz.bboylin.demo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;


public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
Binary file added app/src/main/res/drawable/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions app/src/main/res/layout/activity_second.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"/>
</LinearLayout>
1 change: 1 addition & 0 deletions toast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
provided 'com.facebook.fresco:fresco:1.10.0'
}
Loading

0 comments on commit 971d7a4

Please sign in to comment.