Skip to content

Commit 225839d

Browse files
Merge pull request #47 from douglasjunior/issue-46
Fixing the changes in Dialog size. #46
2 parents a5f99e9 + dfbd8c6 commit 225839d

File tree

9 files changed

+48
-16
lines changed

9 files changed

+48
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ android:
44
components:
55
- tools
66
- platform-tools
7-
- build-tools-24.0.3
7+
- build-tools-25.0.0
88
- android-24
99
- extra-android-support
1010
- extra-android-m2repository

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
Before changing "Android Gradle Plugin" version, check he last estable version
1010
https://developer.android.com/studio/releases/gradle-plugin.html#revisions
1111
*/
12-
classpath 'com.android.tools.build:gradle:2.2.0'
12+
classpath 'com.android.tools.build:gradle:2.3.3'
1313
// NOTE: Do not place your application dependencies here; they belong
1414
// in the individual module build.gradle files
1515
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Oct 17 08:28:35 BRST 2016
1+
#Sun Jul 16 17:17:26 BRT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ group = 'com.github.douglasjunior'
55

66
android {
77
compileSdkVersion 24
8-
buildToolsVersion "24.0.3"
8+
buildToolsVersion '25.0.0'
99

1010
defaultConfig {
1111
minSdkVersion 7

library/src/main/java/io/github/douglasjunior/androidSimpleTooltip/SimpleTooltip.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public class SimpleTooltip implements PopupWindow.OnDismissListener {
100100
private final View mAnchorView;
101101
private final boolean mTransparentOverlay;
102102
private final float mOverlayOffset;
103+
private final boolean mOverlayMatchParent;
103104
private final float mMaxWidth;
104105
private View mOverlay;
105106
private ViewGroup mRootView;
@@ -132,6 +133,7 @@ private SimpleTooltip(Builder builder) {
132133
mAnchorView = builder.anchorView;
133134
mTransparentOverlay = builder.transparentOverlay;
134135
mOverlayOffset = builder.overlayOffset;
136+
mOverlayMatchParent = builder.overlayMatchParent;
135137
mMaxWidth = builder.maxWidth;
136138
mShowArrow = builder.showArrow;
137139
mArrowWidth = builder.arrowWidth;
@@ -145,7 +147,7 @@ private SimpleTooltip(Builder builder) {
145147
mOnDismissListener = builder.onDismissListener;
146148
mOnShowListener = builder.onShowListener;
147149
mFocusable = builder.focusable;
148-
mRootView = (ViewGroup) mAnchorView.getRootView();
150+
mRootView = SimpleTooltipUtils.findFrameLayout(mAnchorView);
149151
mHighlightShape = builder.highlightShape;
150152

151153
init();
@@ -192,7 +194,10 @@ private void verifyDismissed() {
192194

193195
private void createOverlay() {
194196
mOverlay = mTransparentOverlay ? new View(mContext) : new OverlayView(mContext, mAnchorView, mHighlightShape, mOverlayOffset);
195-
mOverlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
197+
if (mOverlayMatchParent)
198+
mOverlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
199+
else
200+
mOverlay.setLayoutParams(new ViewGroup.LayoutParams(mRootView.getWidth(), mRootView.getHeight()));
196201
mOverlay.setOnTouchListener(mOverlayTouchListener);
197202
mRootView.addView(mOverlay);
198203
}
@@ -546,6 +551,7 @@ public static class Builder {
546551
private int gravity = Gravity.BOTTOM;
547552
private boolean transparentOverlay = true;
548553
private float overlayOffset = -1;
554+
private boolean overlayMatchParent = true;
549555
private float maxWidth;
550556
private boolean showArrow = true;
551557
private Drawable arrowDrawable;
@@ -1052,5 +1058,20 @@ public Builder overlayOffset(@Dimension float overlayOffset) {
10521058
this.overlayOffset = overlayOffset;
10531059
return this;
10541060
}
1061+
1062+
/**
1063+
* <div class="pt">Define o comportamento do overlay. Utilizado para casos onde a view de Overlay não pode ser MATCH_PARENT.
1064+
* Como em uma Dialog ou DialogFragment.</div>
1065+
* <div class="en">Sets the behavior of the overlay view. Used for cases where the Overlay view can not be MATCH_PARENT.
1066+
* Like in a Dialog or DialogFragment.</div>
1067+
*
1068+
* @param overlayMatchParent <div class="pt">True se o overlay deve ser MATCH_PARENT. False se ele deve obter o mesmo tamanho do pai.</div>
1069+
* <div class="en">True if the overlay should be MATCH_PARENT. False if it should get the same size as the parent.</div>
1070+
* @return this
1071+
*/
1072+
public Builder overlayMatchParent(boolean overlayMatchParent) {
1073+
this.overlayMatchParent = overlayMatchParent;
1074+
return this;
1075+
}
10551076
}
10561077
}

library/src/main/java/io/github/douglasjunior/androidSimpleTooltip/SimpleTooltipUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import android.view.View;
3737
import android.view.ViewGroup;
3838
import android.view.ViewTreeObserver;
39+
import android.widget.FrameLayout;
3940
import android.widget.TextView;
4041

4142
/**
@@ -164,4 +165,19 @@ public static Drawable getDrawable(Context context, @DrawableRes int drawableRes
164165
return context.getResources().getDrawable(drawableRes);
165166
}
166167
}
168+
169+
/**
170+
* Verify if the first child of the rootView is a FrameLayout.
171+
* Used for cases where the Tooltip is created inside a Dialog or DialogFragment.
172+
*
173+
* @param anchorView
174+
* @return FrameLayout or anchorView.getRootView()
175+
*/
176+
public static ViewGroup findFrameLayout(View anchorView) {
177+
ViewGroup rootView = (ViewGroup) anchorView.getRootView();
178+
if (rootView.getChildCount() == 1 && rootView.getChildAt(0) instanceof FrameLayout) {
179+
rootView = (ViewGroup) rootView.getChildAt(0);
180+
}
181+
return rootView;
182+
}
167183
}

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 24
5-
buildToolsVersion "24.0.3"
5+
buildToolsVersion '25.0.0'
66

77
defaultConfig {
88
applicationId "io.github.douglasjunior.androidSimpleTooltip.sample"

sample/src/main/java/io/github/douglasjunior/androidSimpleTooltip/sample/MainActivity.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,6 @@ public void onClick(View v2) {
220220
dialog.setContentView(R.layout.dialog);
221221
dialog.show();
222222

223-
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
224-
lp.copyFrom(dialog.getWindow().getAttributes());
225-
lp.width = (int) SimpleTooltipUtils.pxFromDp(300);
226-
lp.height = (int) SimpleTooltipUtils.pxFromDp(300);
227-
dialog.getWindow().setAttributes(lp);
228-
229223
final Button btnInDialog = (Button) dialog.findViewById(R.id.btn_in_dialog);
230224
btnInDialog.setOnClickListener(new View.OnClickListener() {
231225
@Override
@@ -236,6 +230,7 @@ public void onClick(View v) {
236230
.gravity(Gravity.BOTTOM)
237231
.animated(true)
238232
.transparentOverlay(false)
233+
.overlayMatchParent(false)
239234
.build()
240235
.show();
241236
}

sample/src/main/res/layout/dialog.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:layout_height="match_parent"
66
android:background="@color/colorPrimary"
77
android:orientation="vertical"
8-
android:padding="10dp"
8+
android:padding="50dp"
99
tools:ignore="Overdraw">
1010

1111
<Button
@@ -24,7 +24,7 @@
2424
android:id="@+id/btn_close"
2525
android:layout_width="wrap_content"
2626
android:layout_height="wrap_content"
27-
android:layout_gravity="end"
27+
android:layout_gravity="center"
2828
android:text="@string/btn_close" />
2929

3030
</LinearLayout>

0 commit comments

Comments
 (0)