├── .gitignore
├── BlurPopupWindow
├── .gitignore
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── kyleduo
│ │ │ └── blurpopupwindow
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── kyleduo
│ │ │ │ └── blurpopupwindow
│ │ │ │ ├── BottomMenu.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── ShadowContainer.java
│ │ │ │ └── SharePopup.java
│ │ └── res
│ │ │ ├── drawable-xxhdpi
│ │ │ ├── doctor_app_shot.png
│ │ │ ├── facebook.png
│ │ │ ├── google_plus.png
│ │ │ ├── twitter.png
│ │ │ ├── wechat.png
│ │ │ └── weibo.png
│ │ │ ├── drawable
│ │ │ ├── dialog_button_bg.xml
│ │ │ ├── menu_item_bg_selector.xml
│ │ │ └── shadow.xml
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── item_entrance.xml
│ │ │ ├── layout_bottom_menu.xml
│ │ │ ├── layout_bottom_popup.xml
│ │ │ └── layout_dialog_like.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── values-v19
│ │ │ └── styles.xml
│ │ │ └── values
│ │ │ ├── attrs_shadow_container.xml
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── kyleduo
│ │ └── blurpopupwindow
│ │ └── ExampleUnitTest.java
├── blurpopupwindow
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── kyleduo
│ │ │ └── blurpopupwindow
│ │ │ └── library
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── kyleduo
│ │ │ │ └── blurpopupwindow
│ │ │ │ └── library
│ │ │ │ ├── BlurPopupWindow.java
│ │ │ │ └── BlurUtils.java
│ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── kyleduo
│ │ └── blurpopupwindow
│ │ └── library
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── LICENSE
├── README.md
└── preview
└── preview.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/BlurPopupWindow/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /.idea/
11 | /.gradle/
12 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.kyleduo.blurpopupwindow"
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | renderscriptTargetApi 25
15 | renderscriptSupportModeEnabled true
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | compile project(':blurpopupwindow')
28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
29 | exclude group: 'com.android.support', module: 'support-annotations'
30 | })
31 | //noinspection GradleCompatible
32 | compile 'com.android.support:appcompat-v7:25.3.0'
33 | compile 'com.android.support:recyclerview-v7:25.3.0'
34 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
35 | testCompile 'junit:junit:4.12'
36 | }
37 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/kyle/Documents/developer/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/androidTest/java/com/kyleduo/blurpopupwindow/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.kyleduo.blurpopupwindow", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/java/com/kyleduo/blurpopupwindow/BottomMenu.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 | import android.view.Gravity;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.ViewTreeObserver;
11 |
12 | import com.kyleduo.blurpopupwindow.library.BlurPopupWindow;
13 |
14 | /**
15 | * Created by kyle on 2017/3/14.
16 | */
17 |
18 | public class BottomMenu extends BlurPopupWindow {
19 | private static final String TAG = "IOSMenu";
20 |
21 | public BottomMenu(@NonNull Context context) {
22 | super(context);
23 | }
24 |
25 | @Override
26 | protected View createContentView(ViewGroup parent) {
27 | View menu = LayoutInflater.from(getContext()).inflate(R.layout.layout_bottom_menu, parent, false);
28 | LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
29 | lp.gravity = Gravity.BOTTOM;
30 | menu.setLayoutParams(lp);
31 | menu.setVisibility(INVISIBLE);
32 |
33 | menu.findViewById(R.id.cancel_action).setOnClickListener(new OnClickListener() {
34 | @Override
35 | public void onClick(View v) {
36 | dismiss();
37 | }
38 | });
39 | return menu;
40 | }
41 |
42 | @Override
43 | protected void onShow() {
44 | super.onShow();
45 | getContentView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
46 | @Override
47 | public void onGlobalLayout() {
48 | getViewTreeObserver().removeGlobalOnLayoutListener(this);
49 |
50 | getContentView().setVisibility(VISIBLE);
51 | int height = getContentView().getMeasuredHeight();
52 | ObjectAnimator.ofFloat(getContentView(), "translationY", height, 0).setDuration(getAnimationDuration()).start();
53 | }
54 | });
55 | }
56 |
57 | @Override
58 | protected ObjectAnimator createDismissAnimator() {
59 | int height = getContentView().getMeasuredHeight();
60 | return ObjectAnimator.ofFloat(getContentView(), "translationY", 0, height).setDuration(getAnimationDuration());
61 | }
62 |
63 | @Override
64 | protected ObjectAnimator createShowAnimator() {
65 | return null;
66 | }
67 |
68 | public static class Builder extends BlurPopupWindow.Builder {
69 | public Builder(Context context) {
70 | super(context);
71 | this.setBlurRadius(0).setTintColor(0x70000000);
72 | }
73 |
74 | @Override
75 | protected BottomMenu createPopupWindow() {
76 | return new BottomMenu(mContext);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/java/com/kyleduo/blurpopupwindow/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.Gravity;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | import com.kyleduo.blurpopupwindow.library.BlurPopupWindow;
16 |
17 | import static com.kyleduo.blurpopupwindow.R.id.container;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | private static int[][] sPalettes = new int[][]{
22 | {0xFFF98989, 0xFFE03535},
23 | {0xFFC1E480, 0xFF67CC34},
24 | {0xFFEDF179, 0xFFFFB314},
25 | {0xFF80DDE4, 0xFF286EDC},
26 | {0xFFE480C6, 0xFFDC285E},
27 | };
28 |
29 | private static String[] sTitle = new String[]{
30 | "Bottom Menu",
31 | "Share Popup",
32 | "Dialog like"
33 | };
34 |
35 | BottomMenu menu;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_main);
41 |
42 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
43 | setSupportActionBar(toolbar);
44 |
45 | RecyclerView rv = (RecyclerView) findViewById(R.id.recycler_view);
46 | rv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
47 | EntranceAdapter adapter = new EntranceAdapter();
48 | adapter.setOnItemClickListener(new EntranceAdapter.OnItemClickListener() {
49 | @Override
50 | public void onItemClicked(int index) {
51 | int pos = index % sTitle.length;
52 |
53 | switch (pos) {
54 | case 0:
55 | if (menu == null) {
56 | menu = new BottomMenu.Builder(MainActivity.this).setBlurRadius(2).build();
57 | }
58 | menu.show();
59 | break;
60 | case 1:
61 | new SharePopup.Builder(MainActivity.this).build().show();
62 | break;
63 | case 2:
64 | new BlurPopupWindow.Builder(MainActivity.this)
65 | .setContentView(R.layout.layout_dialog_like)
66 | .bindClickListener(new View.OnClickListener() {
67 | @Override
68 | public void onClick(View v) {
69 | Toast.makeText(v.getContext(), "Click Button", Toast.LENGTH_SHORT).show();
70 | }
71 | }, R.id.dialog_like_bt)
72 | .setGravity(Gravity.CENTER)
73 | .setScaleRatio(0.2f)
74 | .setBlurRadius(10)
75 | .setTintColor(0x30000000)
76 | .build()
77 | .show();
78 | break;
79 | }
80 | }
81 | });
82 | rv.setAdapter(adapter);
83 |
84 | }
85 |
86 | private static class EntranceViewHolder extends RecyclerView.ViewHolder {
87 | ShadowContainer shadowContainer;
88 | TextView nameTv;
89 |
90 | public EntranceViewHolder(View itemView, final EntranceAdapter.OnItemClickListener listener) {
91 | super(itemView);
92 | shadowContainer = (ShadowContainer) itemView.findViewById(container);
93 | nameTv = (TextView) itemView.findViewById(R.id.entrance_name_tv);
94 | itemView.setOnClickListener(new View.OnClickListener() {
95 | @Override
96 | public void onClick(View v) {
97 | if (listener != null) {
98 | listener.onItemClicked(getAdapterPosition());
99 | }
100 | }
101 | });
102 | }
103 | }
104 |
105 | private static class EntranceAdapter extends RecyclerView.Adapter {
106 |
107 | interface OnItemClickListener {
108 | void onItemClicked(int index);
109 | }
110 |
111 | private OnItemClickListener mOnItemClickListener;
112 |
113 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
114 | mOnItemClickListener = onItemClickListener;
115 | }
116 |
117 | @Override
118 | public EntranceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
119 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_entrance, parent, false);
120 | return new EntranceViewHolder(view, mOnItemClickListener);
121 | }
122 |
123 | @Override
124 | public void onBindViewHolder(EntranceViewHolder holder, int position) {
125 | holder.shadowContainer.setShadowColor(sPalettes[position][1]);
126 | holder.shadowContainer.setShadowRadius((int) (holder.shadowContainer.getResources().getDisplayMetrics().density * 6));
127 |
128 | ShadowContainer.ShadowDrawable shadowDrawable = holder.shadowContainer.getShadowDrawable();
129 | shadowDrawable.setCornerRadius((int) (holder.shadowContainer.getResources().getDisplayMetrics().density * 4));
130 | shadowDrawable.setColors(sPalettes[position]);
131 |
132 | holder.nameTv.setText(sTitle[position % sTitle.length]);
133 | }
134 |
135 | @Override
136 | public int getItemCount() {
137 | return sPalettes.length;
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/java/com/kyleduo/blurpopupwindow/ShadowContainer.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.ColorFilter;
7 | import android.graphics.LinearGradient;
8 | import android.graphics.Paint;
9 | import android.graphics.PixelFormat;
10 | import android.graphics.RectF;
11 | import android.graphics.Shader;
12 | import android.graphics.drawable.Drawable;
13 | import android.support.annotation.ColorInt;
14 | import android.support.annotation.IntRange;
15 | import android.support.annotation.NonNull;
16 | import android.support.annotation.Nullable;
17 | import android.support.annotation.Px;
18 | import android.util.AttributeSet;
19 | import android.widget.LinearLayout;
20 |
21 | /**
22 | * Created by kyle on 2017/3/23.
23 | */
24 |
25 | public class ShadowContainer extends LinearLayout {
26 | public static final int DEFAULT_SHADOW_COLOR = 0x20000000;
27 | public static final int DEFAULT_SHADOW_RADIUS_DP = 8;
28 |
29 | private int mShadowRadius;
30 | private int mShadowColor;
31 | private ShadowDrawable mShadowDrawable;
32 | private float mDensity;
33 |
34 | public ShadowContainer(Context context) {
35 | this(context, null);
36 | }
37 |
38 | public ShadowContainer(Context context, @Nullable AttributeSet attrs) {
39 | this(context, attrs, 0);
40 | }
41 |
42 | public ShadowContainer(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
43 | super(context, attrs, defStyleAttr);
44 | init(attrs);
45 | }
46 |
47 | protected void init(AttributeSet attrs) {
48 | setLayerType(LAYER_TYPE_SOFTWARE, null);
49 |
50 | mDensity = getResources().getDisplayMetrics().density;
51 |
52 | mShadowRadius = dp2px(DEFAULT_SHADOW_RADIUS_DP);
53 | mShadowColor = 0xE0BFCDE6;
54 |
55 | if (attrs != null) {
56 | TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.ShadowContainer);
57 | mShadowColor = ta.getColor(R.styleable.ShadowContainer_sc_shadowColor, mShadowColor);
58 | ta.recycle();
59 | }
60 |
61 | mShadowDrawable = new ShadowDrawable(mDensity);
62 | mShadowDrawable.setShadow(mShadowRadius, mShadowColor);
63 | mShadowDrawable.setInset(mShadowRadius, mShadowRadius);
64 | super.setBackgroundDrawable(mShadowDrawable);
65 |
66 | setPadding(
67 | getPaddingLeft(),
68 | getPaddingTop(),
69 | getPaddingRight(),
70 | getPaddingBottom());
71 | }
72 |
73 | private int dp2px(float dp) {
74 | return (int) (mDensity * dp);
75 | }
76 |
77 | @Override
78 | public void setBackgroundColor(@ColorInt int color) {
79 | mShadowDrawable.setBackgroundColor(color);
80 | }
81 |
82 | @Override
83 | public void setBackgroundDrawable(Drawable background) {
84 | // do nothing
85 | }
86 |
87 | public ShadowDrawable getShadowDrawable() {
88 | return mShadowDrawable;
89 | }
90 |
91 | @Override
92 | public void setPadding(@Px int left, @Px int top, @Px int right, @Px int bottom) {
93 | left += mShadowRadius;
94 | top += mShadowRadius;
95 | right += mShadowRadius;
96 | bottom += mShadowRadius;
97 | super.setPadding(left, top, right, bottom);
98 | }
99 |
100 | public void setShadowRadius(int shadowRadius) {
101 | int pl = getPaddingLeft() - mShadowRadius;
102 | int pt = getPaddingTop() - mShadowRadius;
103 | int pr = getPaddingRight() - mShadowRadius;
104 | int pb = getPaddingBottom() - mShadowRadius;
105 | mShadowRadius = shadowRadius;
106 | mShadowDrawable.setShadow(mShadowRadius, mShadowColor);
107 | mShadowDrawable.setInset(mShadowRadius, mShadowRadius);
108 | setPadding(pl, pt, pr, pb);
109 | }
110 |
111 | public void setShadowColor(int shadowColor) {
112 | mShadowColor = shadowColor;
113 | mShadowDrawable.setShadow(mShadowRadius, mShadowColor);
114 | invalidate();
115 | }
116 |
117 | @Override
118 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
119 | if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) {
120 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(
121 | (int) Math.min(MeasureSpec.getSize(widthMeasureSpec), getResources().getDisplayMetrics().widthPixels * 0.8f),
122 | MeasureSpec.AT_MOST
123 | );
124 | }
125 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
126 | }
127 |
128 | public static class ShadowDrawable extends Drawable {
129 | private Paint mPaint;
130 | private RectF mRectF;
131 | private int mBackgroundColor;
132 | private int mInsetX, mInsetY;
133 | private float mDensity;
134 | private int[] mBackgroundColors;
135 | private int mCornerRadius;
136 | private LinearGradient mLinearGradient;
137 |
138 | public ShadowDrawable(float density) {
139 | mDensity = density;
140 | mBackgroundColor = 0xFFFFFFFF;
141 |
142 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
143 | mRectF = new RectF();
144 |
145 | mPaint.setColor(mBackgroundColor);
146 | mPaint.setStyle(Paint.Style.FILL);
147 |
148 | mCornerRadius = dp2px(6);
149 | }
150 |
151 | public void setInset(int insetX, int insetY) {
152 | mInsetX = insetX;
153 | mInsetY = insetY;
154 | }
155 |
156 | private int dp2px(float dp) {
157 | return (int) (mDensity * dp);
158 | }
159 |
160 |
161 | @Override
162 | public void draw(@NonNull Canvas canvas) {
163 | mRectF.set(getBounds());
164 | mRectF.inset(mInsetX, mInsetY);
165 |
166 | if (mBackgroundColors != null) {
167 | mLinearGradient = new LinearGradient(mRectF.left, mRectF.top, mRectF.right, mRectF.bottom, mBackgroundColors, new float[]{0, 1.f}, Shader.TileMode.CLAMP);
168 | mPaint.setShader(mLinearGradient);
169 | }
170 |
171 | canvas.drawRoundRect(mRectF, mCornerRadius, mCornerRadius, mPaint);
172 | }
173 |
174 | @Override
175 | public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
176 | mPaint.setAlpha(alpha);
177 | }
178 |
179 | @Override
180 | public void setColorFilter(@Nullable ColorFilter colorFilter) {
181 | mPaint.setColorFilter(colorFilter);
182 | }
183 |
184 | @Override
185 | public int getOpacity() {
186 | return PixelFormat.TRANSLUCENT;
187 | }
188 |
189 | public void setShadow(int radius, int color) {
190 | mPaint.setShadowLayer(radius, 0, 0, color);
191 | invalidateSelf();
192 | }
193 |
194 | public void setBackgroundColor(int backgroundColor) {
195 | mBackgroundColor = backgroundColor;
196 | invalidateSelf();
197 | }
198 |
199 | public LinearGradient getLinearGradient() {
200 | return mLinearGradient;
201 | }
202 |
203 | public void setColors(int[] colors) {
204 | mBackgroundColors = colors;
205 | invalidateSelf();
206 | }
207 |
208 | public void setCornerRadius(int cornerRadius) {
209 | mCornerRadius = cornerRadius;
210 | invalidateSelf();
211 | }
212 | }
213 |
214 | }
215 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/java/com/kyleduo/blurpopupwindow/SharePopup.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 | import android.view.Gravity;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.ViewTreeObserver;
11 |
12 | import com.kyleduo.blurpopupwindow.library.BlurPopupWindow;
13 |
14 | /**
15 | * Created by kyle on 2017/3/25.
16 | */
17 |
18 | public class SharePopup extends BlurPopupWindow {
19 |
20 | public SharePopup(@NonNull Context context) {
21 | super(context);
22 | }
23 |
24 | @Override
25 | protected View createContentView(ViewGroup parent) {
26 | View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_bottom_popup, parent, false);
27 | LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
28 | lp.gravity = Gravity.BOTTOM;
29 | view.setLayoutParams(lp);
30 | view.setVisibility(INVISIBLE);
31 | return view;
32 | }
33 |
34 | @Override
35 | protected void onShow() {
36 | super.onShow();
37 | getContentView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
38 | @Override
39 | public void onGlobalLayout() {
40 | getViewTreeObserver().removeGlobalOnLayoutListener(this);
41 |
42 | getContentView().setVisibility(VISIBLE);
43 | int height = getContentView().getMeasuredHeight();
44 | ObjectAnimator.ofFloat(getContentView(), "translationY", height, 0).setDuration(getAnimationDuration()).start();
45 | }
46 | });
47 | }
48 |
49 | @Override
50 | protected ObjectAnimator createDismissAnimator() {
51 | int height = getContentView().getMeasuredHeight();
52 | return ObjectAnimator.ofFloat(getContentView(), "translationY", 0, height).setDuration(getAnimationDuration());
53 | }
54 |
55 | @Override
56 | protected ObjectAnimator createShowAnimator() {
57 | return null;
58 | }
59 |
60 | public static class Builder extends BlurPopupWindow.Builder {
61 | public Builder(Context context) {
62 | super(context);
63 | this.setScaleRatio(0.25f).setBlurRadius(8).setTintColor(0x30000000);
64 | }
65 |
66 | @Override
67 | protected SharePopup createPopupWindow() {
68 | return new SharePopup(mContext);
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/doctor_app_shot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/doctor_app_shot.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/facebook.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/facebook.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/google_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/google_plus.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/twitter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/twitter.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/wechat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/wechat.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/weibo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/drawable-xxhdpi/weibo.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable/dialog_button_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable/menu_item_bg_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 | -
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/drawable/shadow.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
20 |
21 |
25 |
26 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/layout/item_entrance.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
23 |
24 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/layout/layout_bottom_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
21 |
22 |
29 |
30 |
35 |
36 |
44 |
45 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/layout/layout_bottom_popup.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
29 |
30 |
38 |
39 |
42 |
43 |
46 |
47 |
48 |
51 |
52 |
55 |
56 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/layout/layout_dialog_like.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
17 |
21 |
22 |
30 |
31 |
39 |
40 |
51 |
52 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/values-v19/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/values/attrs_shadow_container.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFF98989
8 | #FFF55050
9 | #FFC1E480
10 | #FFA2DA3D
11 | #FFE4E480
12 | #FFD3DC28
13 | #FF80B5E4
14 | #FF286EDC
15 |
16 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BlurPopupWindow
3 | This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties. All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files. There are many specialized subclasses of views that act as controls or are capable of displaying text, images, or other content. Once you have created a tree of views, there are typically a few types of common operations you may wish to perform: Set properties: for example setting the text of a TextView. The available properties and the methods that set them will vary among the different subclasses of views. Note that properties that are known at build time can be set in the XML layout files. Set focus: The framework will handled moving focus in response to user input. To force focus to a specific view, call requestFocus(). Set up listeners: Views allow clients to set listeners that will be notified when something interesting happens to the view. For example, all views will let you set a listener to be notified when the view gains or loses focus. You can register such a listener using setOnFocusChangeListener(android.view.View.OnFocusChangeListener). Other view subclasses offer more specialized listeners. For example, a Button exposes a listener to notify clients when the button is clicked. Set visibility: You can hide or show views using setVisibility(int). Note: The Android framework is responsible for measuring, laying out and drawing views. You should not call methods that perform these actions on views yourself unless you are actually implementing a ViewGroup.
4 |
5 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
19 |
20 |
26 |
27 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/BlurPopupWindow/app/src/test/java/com/kyleduo/blurpopupwindow/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | def VERSION_NAME = "1.0.9"
6 | def VERSION_CODE = 3
7 | def GROUP = "com.kyleduo.blurpopupwindow"
8 |
9 | version = VERSION_NAME
10 | group = GROUP
11 |
12 | android {
13 | compileSdkVersion 25
14 | buildToolsVersion "25.0.2"
15 |
16 | defaultConfig {
17 | minSdkVersion 14
18 | targetSdkVersion 25
19 | versionCode VERSION_CODE
20 | versionName VERSION_NAME
21 |
22 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
23 |
24 | renderscriptTargetApi 25
25 | renderscriptSupportModeEnabled true
26 | }
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 | }
34 |
35 | dependencies {
36 | compile fileTree(dir: 'libs', include: ['*.jar'])
37 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
38 | exclude group: 'com.android.support', module: 'support-annotations'
39 | })
40 | //noinspection GradleCompatible
41 | compile 'com.android.support:appcompat-v7:25.3.0'
42 | testCompile 'junit:junit:4.12'
43 | }
44 |
45 | ext {
46 | POM_ARTIFACT_ID = 'blurpopupwindow'
47 | POM_NAME = 'BlurPopupWindow'
48 | POM_PACKAGING = 'aar'
49 | GIT_URL = 'https://github.com/kyleduo/BlurPopupWindow.git'
50 | PRJ_URL = 'https://github.com/kyleduo/BlurPopupWindow'
51 | }
52 |
53 | install {
54 | repositories.mavenInstaller {
55 | pom {
56 | //noinspection GroovyAssignabilityCheck
57 | project {
58 | packaging POM_PACKAGING
59 | groupId GROUP
60 | artifactId POM_ARTIFACT_ID
61 |
62 | // Add your description here
63 | name POM_NAME
64 | url PRJ_URL
65 |
66 | // Set your license
67 | licenses {
68 | license {
69 | name 'The Apache Software License, Version 2.0'
70 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
71 | }
72 | }
73 | developers {
74 | developer {
75 | id 'kyleduo'
76 | name 'kyleduo'
77 | email 'kyleduo@gmail.com'
78 | }
79 | }
80 | scm {
81 | connection GIT_URL
82 | developerConnection GIT_URL
83 | url PRJ_URL
84 |
85 | }
86 | }
87 | }
88 | }
89 | }
90 | if (project.getPlugins().hasPlugin('com.android.application') ||
91 | project.getPlugins().hasPlugin('com.android.library')) {
92 | task sourcesJar(type: Jar) {
93 | from android.sourceSets.main.java.srcDirs
94 | classifier = 'sources'
95 | }
96 |
97 | task javadoc(type: Javadoc) {
98 | source = android.sourceSets.main.java.srcDirs
99 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
100 | }
101 | } else {
102 | task sourcesJar(type: Jar, dependsOn: classes) {
103 | classifier = 'sources'
104 | from sourceSets.main.allSource
105 | }
106 | }
107 |
108 | task javadocJar(type: Jar, dependsOn: javadoc) {
109 | classifier = 'javadoc'
110 | from javadoc.destinationDir
111 | }
112 |
113 | artifacts {
114 | archives javadocJar
115 | archives sourcesJar
116 | }
117 |
118 | Properties properties = new Properties()
119 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
120 | bintray {
121 | user = properties.getProperty('bintray.user')
122 | key = properties.getProperty('bintray.apikey')
123 | configurations = ['archives']
124 | pkg {
125 | repo = 'maven'
126 | name = POM_NAME
127 | userOrg = 'kyleduo'
128 | licenses = ['Apache-2.0']
129 | websiteUrl = PRJ_URL
130 | vcsUrl = GIT_URL
131 | publicDownloadNumbers = true
132 | override = true
133 | publish = true
134 |
135 | version {
136 | name = VERSION_NAME
137 | desc = 'A library for Android for popup window with blur background.'
138 | released = new Date()
139 | vcsTag = version
140 | }
141 | }
142 | }
143 |
144 | bintrayUpload.dependsOn install
145 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/kyle/Documents/developer/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/src/androidTest/java/com/kyleduo/blurpopupwindow/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow.library;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.kyleduo.blurpopupwindow.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/src/main/java/com/kyleduo/blurpopupwindow/library/BlurPopupWindow.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow.library;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ObjectAnimator;
6 | import android.app.Activity;
7 | import android.content.Context;
8 | import android.graphics.Bitmap;
9 | import android.graphics.Canvas;
10 | import android.graphics.PixelFormat;
11 | import android.graphics.drawable.Drawable;
12 | import android.os.AsyncTask;
13 | import android.os.Build;
14 | import android.support.annotation.AnyThread;
15 | import android.support.annotation.CallSuper;
16 | import android.support.annotation.NonNull;
17 | import android.util.DisplayMetrics;
18 | import android.util.Log;
19 | import android.view.Display;
20 | import android.view.Gravity;
21 | import android.view.KeyEvent;
22 | import android.view.LayoutInflater;
23 | import android.view.MotionEvent;
24 | import android.view.View;
25 | import android.view.ViewGroup;
26 | import android.view.WindowManager;
27 | import android.widget.FrameLayout;
28 | import android.widget.ImageView;
29 |
30 | import java.lang.ref.WeakReference;
31 | import java.lang.reflect.Method;
32 |
33 | /**
34 | * PopupWindow with blurred below view.
35 | * Created by kyle on 2017/3/14.
36 | */
37 |
38 | @SuppressWarnings("ALL")
39 | public class BlurPopupWindow extends FrameLayout {
40 | private static final String TAG = "BlurPopupWindow";
41 |
42 | private static final float DEFAULT_BLUR_RADIUS = 10;
43 | private static final float DEFAULT_SCALE_RATIO = 0.4f;
44 | private static final long DEFAULT_ANIMATION_DURATION = 300;
45 |
46 | public interface OnDismissListener {
47 | void onDismiss(BlurPopupWindow popupWindow);
48 | }
49 |
50 | private Activity mActivity;
51 | protected ImageView mBlurView;
52 | protected FrameLayout mContentLayout;
53 | private boolean mAnimating;
54 |
55 | private WindowManager mWindowManager;
56 |
57 | private View mContentView;
58 | private int mTintColor;
59 | private View mAnchorView;
60 | private float mBlurRadius;
61 | private float mScaleRatio;
62 | private long mAnimationDuration;
63 | private boolean mDismissOnTouchBackground;
64 | private boolean mDismissOnClickBack;
65 | private OnDismissListener mOnDismissListener;
66 |
67 | public BlurPopupWindow(@NonNull Context context) {
68 | super(context);
69 | init();
70 | }
71 |
72 | private void init() {
73 | if (!(getContext() instanceof Activity)) {
74 | throw new IllegalArgumentException("Context must be Activity");
75 | }
76 | mActivity = (Activity) getContext();
77 | mWindowManager = mActivity.getWindowManager();
78 |
79 | mBlurRadius = DEFAULT_BLUR_RADIUS;
80 | mScaleRatio = DEFAULT_SCALE_RATIO;
81 | mAnimationDuration = DEFAULT_ANIMATION_DURATION;
82 |
83 | setFocusable(true);
84 | setFocusableInTouchMode(true);
85 |
86 | mContentLayout = new FrameLayout(getContext());
87 | LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
88 | addView(mContentLayout, lp);
89 |
90 | mBlurView = new ImageView(mActivity);
91 | mBlurView.setScaleType(ImageView.ScaleType.FIT_XY);
92 | lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
93 | lp.gravity = Gravity.BOTTOM;
94 | mBlurView.setLayoutParams(lp);
95 | mContentLayout.addView(mBlurView);
96 |
97 | mContentView = createContentView(mContentLayout);
98 | if (mContentView != null) {
99 | mContentLayout.addView(mContentView);
100 | }
101 | }
102 |
103 | /**
104 | * Override this to create custom content.
105 | *
106 | * @param parent the parent where content view would be.
107 | * @return
108 | */
109 | protected View createContentView(ViewGroup parent) {
110 | return null;
111 | }
112 |
113 | @Override
114 | public boolean onTouchEvent(MotionEvent event) {
115 | if (mAnimating || !mDismissOnTouchBackground) {
116 | return super.onTouchEvent(event);
117 | }
118 | if (event.getAction() == MotionEvent.ACTION_UP) {
119 | dismiss();
120 | }
121 | return true;
122 | }
123 |
124 | @Override
125 | public boolean onKeyUp(int keyCode, KeyEvent event) {
126 | if (mAnimating || !mDismissOnClickBack) {
127 | return super.onKeyUp(keyCode, event);
128 | }
129 | if (keyCode == KeyEvent.KEYCODE_BACK) {
130 | dismiss();
131 | return true;
132 | }
133 | return super.onKeyUp(keyCode, event);
134 | }
135 |
136 | public void setContentView(View contentView) {
137 | if (contentView == null) {
138 | throw new IllegalArgumentException("contentView can not be null");
139 | }
140 | if (mContentView != null) {
141 | if (mContentView.getParent() != null) {
142 | ((ViewGroup) mContentView.getParent()).removeView(mContentView);
143 | }
144 | mContentView = null;
145 | }
146 | mContentView = contentView;
147 | mContentLayout.addView(mContentView);
148 | }
149 |
150 | public View getContentView() {
151 | return mContentView;
152 | }
153 |
154 | public void show() {
155 | if (mAnimating) {
156 | return;
157 | }
158 |
159 | WindowManager.LayoutParams params = new WindowManager.LayoutParams();
160 | params.width = WindowManager.LayoutParams.MATCH_PARENT;
161 | params.height = WindowManager.LayoutParams.MATCH_PARENT;
162 | params.format = PixelFormat.RGBA_8888;
163 |
164 | int statusBarHeight = 0;
165 | int navigationBarHeight = BlurPopupWindow.getNaviHeight(mActivity);
166 | int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
167 | if (resourceId > 0) {
168 | statusBarHeight = getResources().getDimensionPixelSize(resourceId);
169 | }
170 |
171 | int trimTopHeight = statusBarHeight;
172 | int trimBottomHeight = 0;
173 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
174 |
175 | // No need to trim status bar height in SDK > 21.
176 | trimTopHeight = 0;
177 |
178 | WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
179 | if ((lp.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
180 | trimBottomHeight = navigationBarHeight;
181 | }
182 |
183 | // This line will cause decor view fill all the screen, even if FLAG_TRANSLUCENT_NAVIGATION
184 | // was not set.
185 | params.flags = lp.flags;
186 |
187 | if (trimBottomHeight > 0) {
188 |
189 | // If trimBottomHeight > 0, it means that we cut navigation bar off and we need shrink
190 | // popup windows' content height by increase bottom padding.
191 | setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom() + navigationBarHeight);
192 | } else {
193 |
194 | // If navigation is showing on the screen, whether translucent or not, we should move contentView
195 | // on top of it.
196 | boolean moveContent = false;
197 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
198 | moveContent = true;
199 | } else if (navigationBarHeight > 0 && (lp.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) {
200 | // Navigation feature diffs from v19 to v21.
201 | moveContent = true;
202 | }
203 | if (navigationBarHeight > 0 && moveContent) {
204 | if (mContentView != null) {
205 | MarginLayoutParams layoutParams = (MarginLayoutParams) mContentView.getLayoutParams();
206 | layoutParams.bottomMargin += navigationBarHeight;
207 | }
208 | }
209 | }
210 | }
211 |
212 | new BlurTask(mActivity.getWindow().getDecorView(), trimTopHeight, trimBottomHeight, this, new BlurTask.BlurTaskCallback() {
213 | @Override
214 | public void onBlurFinish(Bitmap bitmap) {
215 | onBlurredImageGot(bitmap);
216 | }
217 | }).execute();
218 |
219 | mWindowManager.addView(this, params);
220 |
221 | ObjectAnimator showAnimator = createShowAnimator();
222 | if (showAnimator != null) {
223 | mAnimating = true;
224 | showAnimator.addListener(new AnimatorListenerAdapter() {
225 | @Override
226 | public void onAnimationCancel(Animator animation) {
227 | mAnimating = false;
228 | requestFocus();
229 | }
230 |
231 | @Override
232 | public void onAnimationEnd(Animator animation) {
233 | mAnimating = false;
234 | requestFocus();
235 | }
236 | });
237 | showAnimator.start();
238 | }
239 | onShow();
240 | }
241 |
242 | public void dismiss() {
243 | if (mAnimating) {
244 | return;
245 | }
246 | onDismiss();
247 | ObjectAnimator animator = createDismissAnimator();
248 | if (animator == null) {
249 | mWindowManager.removeView(this);
250 | } else {
251 | mAnimating = true;
252 | ObjectAnimator.ofFloat(mBlurView, "alpha", mBlurView.getAlpha(), 0).setDuration(getAnimationDuration()).start();
253 | animator.addListener(new AnimatorListenerAdapter() {
254 | @Override
255 | public void onAnimationEnd(Animator animation) {
256 | removeSelf();
257 | }
258 |
259 | @Override
260 | public void onAnimationCancel(Animator animation) {
261 | removeSelf();
262 | }
263 |
264 | private void removeSelf() {
265 | try {
266 | mWindowManager.removeView(BlurPopupWindow.this);
267 | } catch (Exception e) {
268 | e.printStackTrace();
269 | } finally {
270 | mAnimating = false;
271 | }
272 | }
273 | });
274 | animator.start();
275 | }
276 | }
277 |
278 | protected void onBlurredImageGot(Bitmap bitmap) {
279 | mBlurView.setImageBitmap(bitmap);
280 | if (!mAnimating) {
281 | ObjectAnimator.ofFloat(mBlurView, "alpha", 0, 1f).setDuration(getAnimationDuration()).start();
282 | }
283 | }
284 |
285 | /**
286 | * When executing show method in this method, should override {@link BlurPopupWindow#createShowAnimator()}
287 | * and return null as well.
288 | */
289 | protected void onShow() {
290 | }
291 |
292 | /**
293 | * Do not start any animation in this method. use {@link BlurPopupWindow#createDismissAnimator()} instead.
294 | */
295 | @CallSuper
296 | protected void onDismiss() {
297 | if (mOnDismissListener != null) {
298 | mOnDismissListener.onDismiss(this);
299 | }
300 | }
301 |
302 | protected ObjectAnimator createShowAnimator() {
303 | return ObjectAnimator.ofFloat(mContentLayout, "alpha", 0, 1.f).setDuration(getAnimationDuration());
304 | }
305 |
306 | protected ObjectAnimator createDismissAnimator() {
307 | return ObjectAnimator.ofFloat(mContentLayout, "alpha", mContentLayout.getAlpha(), 0).setDuration(getAnimationDuration());
308 | }
309 |
310 | public int getTintColor() {
311 | return mTintColor;
312 | }
313 |
314 | public void setTintColor(int tintColor) {
315 | mTintColor = tintColor;
316 | }
317 |
318 | public View getAnchorView() {
319 | return mAnchorView;
320 | }
321 |
322 | public void setAnchorView(View anchorView) {
323 | mAnchorView = anchorView;
324 | }
325 |
326 | @AnyThread
327 | public float getBlurRadius() {
328 | return mBlurRadius;
329 | }
330 |
331 | public void setBlurRadius(float blurRadius) {
332 | mBlurRadius = blurRadius;
333 | }
334 |
335 | @AnyThread
336 | public float getScaleRatio() {
337 | return mScaleRatio;
338 | }
339 |
340 | public void setScaleRatio(float scaleRatio) {
341 | mScaleRatio = scaleRatio;
342 | }
343 |
344 | public long getAnimationDuration() {
345 | return mAnimationDuration;
346 | }
347 |
348 | public void setAnimationDuration(long animationDuration) {
349 | mAnimationDuration = animationDuration;
350 | }
351 |
352 | public boolean isDismissOnTouchBackground() {
353 | return mDismissOnTouchBackground;
354 | }
355 |
356 | public void setDismissOnTouchBackground(boolean dismissOnTouchBackground) {
357 | mDismissOnTouchBackground = dismissOnTouchBackground;
358 | }
359 |
360 | public boolean isDismissOnClickBack() {
361 | return mDismissOnClickBack;
362 | }
363 |
364 | public void setDismissOnClickBack(boolean dismissOnClickBack) {
365 | mDismissOnClickBack = dismissOnClickBack;
366 | }
367 |
368 | public OnDismissListener getOnDismissListener() {
369 | return mOnDismissListener;
370 | }
371 |
372 | public void setOnDismissListener(OnDismissListener onDismissListener) {
373 | mOnDismissListener = onDismissListener;
374 | }
375 |
376 | public static class Builder {
377 | private static final String TAG = "BlurPopupWindow.Builder";
378 | protected Context mContext;
379 | private View mContentView;
380 | private int mTintColor;
381 | private float mBlurRadius;
382 | private float mScaleRatio;
383 | private long mAnimationDuration;
384 | private boolean mDismissOnTouchBackground = true;
385 | private boolean mDismissOnClickBack = true;
386 | private int mGravity = -1;
387 | private OnDismissListener mOnDismissListener;
388 |
389 | public Builder(Context context) {
390 | mContext = context;
391 |
392 | mBlurRadius = BlurPopupWindow.DEFAULT_BLUR_RADIUS;
393 | mScaleRatio = BlurPopupWindow.DEFAULT_SCALE_RATIO;
394 | mAnimationDuration = BlurPopupWindow.DEFAULT_ANIMATION_DURATION;
395 | }
396 |
397 | public Builder setContentView(View contentView) {
398 | mContentView = contentView;
399 | return this;
400 | }
401 |
402 | public Builder setContentView(int resId) {
403 | View view = LayoutInflater.from(mContext).inflate(resId, new FrameLayout(mContext), false);
404 | mContentView = view;
405 | return this;
406 | }
407 |
408 | public Builder bindContentViewClickListener(View.OnClickListener listener) {
409 | if (mContentView != null) {
410 | mContentView.setClickable(true);
411 | mContentView.setOnClickListener(listener);
412 | }
413 | return this;
414 | }
415 |
416 | public Builder bindClickListener(View.OnClickListener listener, int... views) {
417 | if (mContentView != null) {
418 | for (int viewId : views) {
419 | View view = mContentView.findViewById(viewId);
420 | if (view != null) {
421 | view.setOnClickListener(listener);
422 | }
423 | }
424 | }
425 | return this;
426 | }
427 |
428 | public Builder setGravity(int gravity) {
429 | mGravity = gravity;
430 | return this;
431 | }
432 |
433 | public Builder setTintColor(int tintColor) {
434 | mTintColor = tintColor;
435 | return this;
436 | }
437 |
438 | public Builder setScaleRatio(float scaleRatio) {
439 | if (scaleRatio <= 0 || scaleRatio > 1) {
440 | Log.w(TAG, "scaleRatio invalid: " + scaleRatio + ". It can only be (0, 1]");
441 | return this;
442 | }
443 | mScaleRatio = scaleRatio;
444 | return this;
445 | }
446 |
447 | public Builder setBlurRadius(float blurRadius) {
448 | if (blurRadius < 0 || blurRadius > 25) {
449 | Log.w(TAG, "blurRadius invalid: " + blurRadius + ". It can only be [0, 25]");
450 | return this;
451 | }
452 | mBlurRadius = blurRadius;
453 | return this;
454 | }
455 |
456 | public Builder setAnimationDuration(long animatingDuration) {
457 | if (animatingDuration < 0) {
458 | Log.w(TAG, "animatingDuration invalid: " + animatingDuration + ". It can only be (0, ..)");
459 | return this;
460 | }
461 | mAnimationDuration = animatingDuration;
462 | return this;
463 | }
464 |
465 | public Builder setDismissOnTouchBackground(boolean dismissOnTouchBackground) {
466 | mDismissOnTouchBackground = dismissOnTouchBackground;
467 | return this;
468 | }
469 |
470 | public Builder setDismissOnClickBack(boolean dismissOnClickBack) {
471 | mDismissOnClickBack = dismissOnClickBack;
472 | return this;
473 | }
474 |
475 | public Builder setOnDismissListener(OnDismissListener onDismissListener) {
476 | mOnDismissListener = onDismissListener;
477 | return this;
478 | }
479 |
480 | protected T createPopupWindow() {
481 | //noinspection unchecked
482 | return (T) new BlurPopupWindow(mContext);
483 | }
484 |
485 | public T build() {
486 | T popupWindow = createPopupWindow();
487 | if (mContentView != null) {
488 | ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
489 | if (layoutParams == null || !(layoutParams instanceof FrameLayout.LayoutParams)) {
490 | layoutParams = new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height);
491 | }
492 | if (mGravity != -1) {
493 | ((LayoutParams) layoutParams).gravity = mGravity;
494 | }
495 | mContentView.setLayoutParams(layoutParams);
496 | popupWindow.setContentView(mContentView);
497 | }
498 | popupWindow.setTintColor(mTintColor);
499 | popupWindow.setAnimationDuration(mAnimationDuration);
500 | popupWindow.setBlurRadius(mBlurRadius);
501 | popupWindow.setScaleRatio(mScaleRatio);
502 | popupWindow.setDismissOnTouchBackground(mDismissOnTouchBackground);
503 | popupWindow.setDismissOnClickBack(mDismissOnClickBack);
504 | popupWindow.setOnDismissListener(mOnDismissListener);
505 | return popupWindow;
506 | }
507 | }
508 |
509 | private final static class BlurTask extends AsyncTask {
510 |
511 | private WeakReference mContextRef;
512 | private WeakReference mPopupWindowRef;
513 | private Bitmap mSourceBitmap;
514 | private BlurTaskCallback mBlurTaskCallback;
515 |
516 | interface BlurTaskCallback {
517 | void onBlurFinish(Bitmap bitmap);
518 | }
519 |
520 | BlurTask(View sourceView, int statusBarHeight, int navigationBarheight, BlurPopupWindow popupWindow, BlurTaskCallback blurTaskCallback) {
521 | mContextRef = new WeakReference<>(sourceView.getContext());
522 | mPopupWindowRef = new WeakReference<>(popupWindow);
523 | mBlurTaskCallback = blurTaskCallback;
524 |
525 | int height = sourceView.getHeight() - statusBarHeight - navigationBarheight;
526 | if (height < 0) {
527 | height = sourceView.getHeight();
528 | }
529 |
530 | Drawable background = sourceView.getBackground();
531 | mSourceBitmap = Bitmap.createBitmap(sourceView.getWidth(), height, Bitmap.Config.ARGB_8888);
532 | Canvas canvas = new Canvas(mSourceBitmap);
533 | int saveCount = 0;
534 | if (statusBarHeight != 0) {
535 | saveCount = canvas.save();
536 | canvas.translate(0, -statusBarHeight);
537 | }
538 | if (popupWindow.getBlurRadius() > 0) {
539 | if (background == null) {
540 | canvas.drawColor(0xffffffff);
541 | }
542 | sourceView.draw(canvas);
543 | }
544 | if (popupWindow.getTintColor() != 0) {
545 | canvas.drawColor(popupWindow.getTintColor());
546 | }
547 | if (statusBarHeight != 0 && saveCount != 0) {
548 | canvas.restoreToCount(saveCount);
549 | }
550 | }
551 |
552 | @Override
553 | protected Bitmap doInBackground(Void... params) {
554 | Context context = mContextRef.get();
555 | BlurPopupWindow popupWindow = mPopupWindowRef.get();
556 | if (context == null || popupWindow == null) {
557 | return null;
558 | }
559 | float scaleRatio = popupWindow.getScaleRatio();
560 | if (popupWindow.getBlurRadius() == 0) {
561 | return mSourceBitmap;
562 | }
563 | Bitmap scaledBitmap = Bitmap.createScaledBitmap(mSourceBitmap, (int) (mSourceBitmap.getWidth() * scaleRatio), (int) (mSourceBitmap.getHeight() * scaleRatio), false);
564 | float radius = popupWindow.getBlurRadius();
565 | Bitmap blurred = BlurUtils.blur(context, scaledBitmap, radius);
566 | return Bitmap.createScaledBitmap(blurred, mSourceBitmap.getWidth(), mSourceBitmap.getHeight(), true);
567 | }
568 |
569 | @Override
570 | protected void onPostExecute(Bitmap bitmap) {
571 | BlurPopupWindow popupWindow = mPopupWindowRef.get();
572 | if (popupWindow != null && popupWindow.getAnchorView() != null) {
573 | Canvas canvas = new Canvas(bitmap);
574 | View anchorView = popupWindow.getAnchorView();
575 | int[] location = new int[2];
576 | anchorView.getLocationInWindow(location);
577 | canvas.save();
578 | canvas.translate(location[0], location[1]);
579 | popupWindow.getAnchorView().draw(canvas);
580 | canvas.restore();
581 | }
582 | if (mBlurTaskCallback != null) {
583 | mBlurTaskCallback.onBlurFinish(bitmap);
584 | }
585 | }
586 | }
587 |
588 | private static int getNaviHeight(Activity activity) {
589 | if (activity == null) {
590 | return 0;
591 | }
592 | Display display = activity.getWindowManager().getDefaultDisplay();
593 | int contentHeight = activity.getResources().getDisplayMetrics().heightPixels;
594 | int realHeight = 0;
595 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
596 | final DisplayMetrics metrics = new DisplayMetrics();
597 | display.getRealMetrics(metrics);
598 | realHeight = metrics.heightPixels;
599 | } else {
600 | try {
601 | Method mGetRawH = Display.class.getMethod("getRawHeight");
602 | realHeight = (Integer) mGetRawH.invoke(display);
603 | } catch (Exception e) {
604 | e.printStackTrace();
605 | }
606 | }
607 | return realHeight - contentHeight;
608 | }
609 |
610 | }
611 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/src/main/java/com/kyleduo/blurpopupwindow/library/BlurUtils.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow.library;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.support.annotation.FloatRange;
7 | import android.support.annotation.MainThread;
8 | import android.support.v8.renderscript.Allocation;
9 | import android.support.v8.renderscript.RenderScript;
10 | import android.support.v8.renderscript.ScriptIntrinsicBlur;
11 | import android.view.View;
12 |
13 | /**
14 | * Created by kyle on 2017/3/14.
15 | */
16 |
17 | public class BlurUtils {
18 | @MainThread
19 | public static Bitmap blur(Context context, View view, @FloatRange(from = 0, to = 25) float radius) {
20 | Bitmap sourceBitmap = getScreenshot(view);
21 | return blur(context, sourceBitmap, radius);
22 | }
23 |
24 | public static Bitmap blur(Context context, Bitmap origin, @FloatRange(from = 0, to = 25) float radius) {
25 | Bitmap scaled = Bitmap.createScaledBitmap(origin, origin.getWidth(), origin.getHeight(), false);
26 | Bitmap output = Bitmap.createBitmap(scaled);
27 |
28 | RenderScript rs = RenderScript.create(context);
29 | Allocation allIn = Allocation.createFromBitmap(rs, scaled);
30 | Allocation allOut = Allocation.createFromBitmap(rs, output);
31 |
32 | ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, allIn.getElement());
33 |
34 | blur.setRadius(radius);
35 | blur.setInput(allIn);
36 | blur.forEach(allOut);
37 | allOut.copyTo(output);
38 | return output;
39 | }
40 |
41 | @MainThread
42 | private static Bitmap getScreenshot(View v) {
43 | Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
44 | Canvas c = new Canvas(b);
45 | v.draw(c);
46 | return b;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/BlurPopupWindow/blurpopupwindow/src/test/java/com/kyleduo/blurpopupwindow/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.kyleduo.blurpopupwindow.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/BlurPopupWindow/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/BlurPopupWindow/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/BlurPopupWindow/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/BlurPopupWindow/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/BlurPopupWindow/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 14 13:56:43 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/BlurPopupWindow/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/BlurPopupWindow/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/BlurPopupWindow/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':blurpopupwindow'
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BlurPopupWindow
2 |
3 | **BlurPopupWindow** is not actually a sub-class of PopupWindow. But we did run into some requirements that display a popup in current page with blurred background. Or you may want to display a custom dialog and you are in trouble with the difficulty and diffrent-result through different sdk version and roms. **It is possible to just put a simple custom View in current Window and do not bring that lots of other things in?**
4 |
5 | **BlurPopupWindow** is more like a pattern to implement these custom popup windows. By default BlurPopupWindow contains nothing but a blurred background. You need to, **and actually this is just you want**, design all the content and maybe custom the animation.
6 |
7 | 
8 |
9 |
10 |
11 | ### Features
12 |
13 | * Blur/Not blur background.
14 | * Support translucent status bar and translucent navigationbar.
15 | * Tint color.
16 |
17 |
18 |
19 | ### Use with Gradle
20 |
21 | ```groovy
22 | dependencies {
23 | compile 'com.kyleduo.blurpopupwindow:blurpopupwindow:1.0.9'
24 | }
25 | ```
26 |
27 | #### Enable support render script
28 |
29 | ```groovy
30 | android {
31 | defaultConfig {
32 | renderscriptTargetApi 25
33 | renderscriptSupportModeEnabled true
34 | }
35 | }
36 | ```
37 |
38 | ### Usage
39 |
40 | A typically usage would be like this:
41 |
42 | ```java
43 | new BlurPopupWindow.Builder(v.getContext())
44 | .setContentView(R.layout.layout_dialog_like)
45 | .bindClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View v) {
48 | Toast.makeText(v.getContext(), "Click Button", Toast.LENGTH_SHORT).show();
49 | }
50 | }, R.id.dialog_like_bt)
51 | .setGravity(Gravity.CENTER)
52 | .setScaleRatio(0.2f)
53 | .setBlurRadius(10)
54 | .setTintColor(0x30000000)
55 | .build()
56 | .show();
57 | ```
58 |
59 | And this would display a dialog-like popup window like**(1)**. The content display depends on you layout design.
60 |
61 | The blur effect is not that necessay and you can disable it by setting the `blurRadius` to `0`. And you got**(2)**
62 |
63 | Or you can tune the blur effect to what you want, like **(3)**.
64 |
65 |
66 |
67 | ### Builder
68 |
69 | The Builder class has some methods for change the behavior. Most of them are easy to understand by their name.
70 |
71 | ```
72 | builder
73 | .setContentView(resId)
74 | .setContentView(view)
75 | .setGravity(Gravity.CENTER)
76 | .setScaleRatio(0.2f)
77 | .setBlurRadius(10)
78 | .setAnimationDuration(300)
79 | // draw a color over background to dim, lighten, or coloring the background.
80 | .setTintColor(0x30000000)
81 | .setDismissOnClickBack(true)
82 | .setDismissOnTouchBackground(true)
83 | .setOnDismissListener(listener)
84 | // bind click listener to id1, id2, ...
85 | .bindClickListener(listener, id1, id2, ...)
86 | // bind click listener to content view
87 | .bindContentViewClickListener(listener)
88 | ```
89 |
90 |
91 |
92 | ### Customize
93 |
94 | As I mentioned before, BlurPupupWindow does not contains any content view. so you need to create one.
95 |
96 | The suggested way to customize a content is to create a class extends from BlurPopupWindow. And there are some methods for you to override. The source code of 3rd demo above would be like this.
97 |
98 | **There are some points you need to know:**
99 |
100 | * Create Builder class exten BlurPopupWindow.Builder and set generic type to your class.
101 | * In Builder class, override createPopupWindow method and return corrent instance.
102 | * You can override `onShow()`/`onDismiss()` to add your own animation.
103 | * `createShowAnimator()`/`createDisAnimator()` return alpha animation by default, override them and return null if you do not like that.
104 |
105 | ```java
106 | public class SharePopup extends BlurPopupWindow {
107 |
108 | public SharePopup(@NonNull Context context) {
109 | super(context);
110 | }
111 |
112 | @Override
113 | protected View createContentView(ViewGroup parent) {
114 | View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_bottom_popup, parent, false);
115 | LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
116 | lp.gravity = Gravity.BOTTOM;
117 | view.setLayoutParams(lp);
118 | view.setVisibility(INVISIBLE);
119 | return view;
120 | }
121 |
122 | @Override
123 | protected void onShow() {
124 | super.onShow();
125 | getContentView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
126 | @Override
127 | public void onGlobalLayout() {
128 | getViewTreeObserver().removeGlobalOnLayoutListener(this);
129 |
130 | getContentView().setVisibility(VISIBLE);
131 | int height = getContentView().getMeasuredHeight();
132 | ObjectAnimator.ofFloat(getContentView(), "translationY", height, 0).setDuration(getAnimationDuration()).start();
133 | }
134 | });
135 | }
136 |
137 | @Override
138 | protected ObjectAnimator createShowAnimator() {
139 | return null;
140 | }
141 |
142 | @Override
143 | protected ObjectAnimator createDismissAnimator() {
144 | int height = getContentView().getMeasuredHeight();
145 | return ObjectAnimator.ofFloat(getContentView(), "translationY", 0, height).setDuration(getAnimationDuration());
146 | }
147 |
148 | public static class Builder extends BlurPopupWindow.Builder {
149 | public Builder(Context context) {
150 | super(context);
151 | this.setScaleRatio(0.25f).setBlurRadius(8).setTintColor(0x30000000);
152 | }
153 |
154 | @Override
155 | protected SharePopup createPopupWindow() {
156 | return new SharePopup(mContext);
157 | }
158 | }
159 | }
160 | ```
161 |
162 | ### proguard
163 |
164 | ```
165 | ##---------------Begin: proguard configuration for RenderScript ----------
166 | -keep class android.support.v8.renderscript.** { *; }
167 | ##---------------End: proguard configuration for RenderScript ----------
168 | ```
169 |
170 | License
171 | ---
172 |
173 | ```
174 | Licensed under the Apache License, Version 2.0 (the "License");
175 | you may not use this file except in compliance with the License.
176 | You may obtain a copy of the License at
177 |
178 | http://www.apache.org/licenses/LICENSE-2.0
179 |
180 | Unless required by applicable law or agreed to in writing, software
181 | distributed under the License is distributed on an "AS IS" BASIS,
182 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183 | See the License for the specific language governing permissions and
184 | limitations under the License.
185 | ```
186 |
187 |
--------------------------------------------------------------------------------
/preview/preview.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kyleduo/BlurPopupWindow/7bb2f97d9acd5ae96ddacbb1701dc1646d516236/preview/preview.jpg
--------------------------------------------------------------------------------