Skip to content

Commit

Permalink
添加LemonBubble生命周期的代理类的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuRi committed Feb 21, 2017
1 parent a0312fc commit 6a0d9f3
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import net.lemonsoft.lemonbubble.LemonBubbleView;
import net.lemonsoft.lemonbubble.enums.LemonBubbleLayoutStyle;
import net.lemonsoft.lemonbubble.enums.LemonBubbleLocationStyle;
import net.lemonsoft.lemonbubble.interfaces.LemonBubbleLifeCycleDelegate;
import net.lemonsoft.lemonbubble.interfaces.LemonBubbleMaskOnTouchContext;
import net.lemonsoft.lemonbubble.interfaces.LemonBubblePaintContext;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
Expand All @@ -43,6 +45,32 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

LemonBubbleView.defaultBubbleView().setLifeCycleDelegate(new LemonBubbleLifeCycleDelegate.Adapter() {
@Override
public void willShow(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {
super.willShow(bubbleView, bubbleInfo);
System.out.println("BUBBLE WILL SHOW~");
}

@Override
public void alreadyShow(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {
super.alreadyShow(bubbleView, bubbleInfo);
System.out.println("BUBBLE ALREADY SHOW!");
}

@Override
public void willHide(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {
super.willHide(bubbleView, bubbleInfo);
System.out.println("BUBBLE WILL HIDE~");
}

@Override
public void alreadyHide(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {
super.alreadyHide(bubbleView, bubbleInfo);
System.out.println("BUBBLE ALREADY HIDE!");
}
});

button1 = (LinearLayout) findViewById(R.id.btn1);
button2 = (LinearLayout) findViewById(R.id.btn2);
button3 = (LinearLayout) findViewById(R.id.btn3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.os.Build;
import android.os.Handler;
import android.view.Gravity;
Expand All @@ -16,6 +17,8 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import net.lemonsoft.lemonbubble.interfaces.LemonBubbleLifeCycleDelegate;

/**
* 柠檬泡泡控件
* Created by LiuRi on 2016/12/23.
Expand Down Expand Up @@ -50,6 +53,10 @@ public class LemonBubbleView {
private int _frameAnimationPlayIndex;
// 帧动画播放指针切换动画器
private ValueAnimator _framePlayIndexAnimator;
/**
* 生命周期代理,可以通过生命周期代理来处理一些提示框显示或消失等节点的特殊事件
*/
private LemonBubbleLifeCycleDelegate lifeCycleDelegate;

// 是否已经初始化过了,避免重新创建控件
private boolean haveInit = false;
Expand Down Expand Up @@ -112,7 +119,14 @@ private void initContainerAndRootLayout() {
_currentBubbleInfo.isShowStatusBar() ?
android.R.style.Theme_NoTitleBar :
android.R.style.Theme_NoTitleBar_Fullscreen
);// 创建对话框对象并设置无标题栏主题
) {
@Override
public void dismiss() {
super.dismiss();
if (lifeCycleDelegate != null)
lifeCycleDelegate.alreadyHide(LemonBubbleView.this, _currentBubbleInfo);
}
};// 创建对话框对象并设置无标题栏主题
if (_currentBubbleInfo.isShowStatusBar()) {
Window window = _container.getWindow();// 设置
if (window != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -313,6 +327,8 @@ public void showBubbleInfo(android.support.v4.app.Fragment fragment, LemonBubble
* @param bubbleInfo 泡泡信息描述对象
*/
public void showBubbleInfo(Context context, LemonBubbleInfo bubbleInfo) {
if (lifeCycleDelegate != null)
lifeCycleDelegate.willShow(this, bubbleInfo);
if (_context != null && !_context.equals(context))
haveInit = false;
_currentBubbleInfo = bubbleInfo;// 现将泡泡信息对象保存起来
Expand All @@ -321,6 +337,13 @@ public void showBubbleInfo(Context context, LemonBubbleInfo bubbleInfo) {
_container.show();
}
initContentPanel(bubbleInfo);// 根据泡泡信息对象对正文内容面板进行初始化
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (lifeCycleDelegate != null)
lifeCycleDelegate.alreadyShow(LemonBubbleView.this, _currentBubbleInfo);
}
}, 300);// 300是动画播放duration的默认时间
}

/**
Expand All @@ -345,6 +368,8 @@ public void run() {
* 隐藏当前正在显示的泡泡控件
*/
public void hide() {
if (lifeCycleDelegate != null)
lifeCycleDelegate.willHide(this, _currentBubbleInfo);
_PAT.setAlpha(_rootLayout, 0);// 动画设置根视图不透明
_PAT.setAlpha(_contentPanel, 0);// 动画设置内容面板不透明
_PAT.setSize(_contentPanel, 0, 0);// 动画设置面板的大小为0,0
Expand Down Expand Up @@ -373,4 +398,11 @@ public void forceHide() {
this.haveInit = false;
}

public LemonBubbleLifeCycleDelegate getLifeCycleDelegate() {
return lifeCycleDelegate;
}

public void setLifeCycleDelegate(LemonBubbleLifeCycleDelegate lifeCycleDelegate) {
this.lifeCycleDelegate = lifeCycleDelegate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package net.lemonsoft.lemonbubble.interfaces;

import net.lemonsoft.lemonbubble.LemonBubbleInfo;
import net.lemonsoft.lemonbubble.LemonBubbleView;

/**
* LemonBubble的生命周期支持
* Created by LiuRi on 2017/2/21.
*/

public interface LemonBubbleLifeCycleDelegate {

/**
* LemonBubble将要被显示
*/
void willShow(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo);

/**
* LemonBubble已经被显示完毕
*/
void alreadyShow(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo);

/**
* LemonBubble即将被关闭
*/
void willHide(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo);

/**
* LemonBubble已经被关闭
*/
void alreadyHide(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo);

abstract class Adapter implements LemonBubbleLifeCycleDelegate {
@Override
public void willShow(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {

}

@Override
public void alreadyShow(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {

}

@Override
public void willHide(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {

}

@Override
public void alreadyHide(LemonBubbleView bubbleView, LemonBubbleInfo bubbleInfo) {

}

}

}

0 comments on commit 6a0d9f3

Please sign in to comment.