From 56a50657420d261a220f7287bf06178fe5d2b80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=D0=BDt=40r=D1=8C?= Date: Fri, 14 Feb 2020 02:37:21 +0200 Subject: [PATCH] Updated library to 1.0.0-alpha06-SNAPSHOT PopupWindow#showAtLocation for android 10 to fast fix tooltip position updating #60 Fixed setting compound drawables for pre 17 API for simple Tooltip --- build.gradle | 2 +- core/src/main/java/com/tooltip/core/Tooltip.java | 7 ++++++- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- library/src/main/java/com/tooltip/Tooltip.java | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 9b71875..c8703ad 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.0-rc01' + classpath 'com.android.tools.build:gradle:4.0.0-alpha09' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/core/src/main/java/com/tooltip/core/Tooltip.java b/core/src/main/java/com/tooltip/core/Tooltip.java index 091da84..fd768a2 100644 --- a/core/src/main/java/com/tooltip/core/Tooltip.java +++ b/core/src/main/java/com/tooltip/core/Tooltip.java @@ -31,6 +31,7 @@ import android.graphics.RectF; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.os.Build; import android.support.v4.view.ViewTreeObserverCompat; import android.util.Log; import android.view.Gravity; @@ -203,7 +204,11 @@ public void show() { mAnchorView.addOnAttachStateChangeListener(mOnAttachStateChangeListener); mAnchorView.post(() -> { if (mAnchorView.isShown()) { - mPopupWindow.showAsDropDown(mAnchorView); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + mPopupWindow.showAtLocation(mAnchorView, Gravity.NO_GRAVITY, 0, 0); + } else { + mPopupWindow.showAsDropDown(mAnchorView); + } } else { Log.e(TAG, "Tooltip cannot be shown, root view is invalid or has been closed"); } diff --git a/gradle.properties b/gradle.properties index f076a53..9904512 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ android.useAndroidX=true android.enableJetifier=true #-SNAPSHOT -version=1.0.0-alpha05-SNAPSHOT +version=1.0.0-alpha06-SNAPSHOT group=com.github.vihtarb POM_DESCRIPTION=Android Tooltips library based on PopupWindow. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 61c0a37..4679a95 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jan 02 16:30:15 EET 2020 +#Fri Feb 14 00:41:25 EET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-rc-1-all.zip diff --git a/library/src/main/java/com/tooltip/Tooltip.java b/library/src/main/java/com/tooltip/Tooltip.java index bb39472..24e5917 100644 --- a/library/src/main/java/com/tooltip/Tooltip.java +++ b/library/src/main/java/com/tooltip/Tooltip.java @@ -48,6 +48,7 @@ import androidx.appcompat.widget.AppCompatTextView; import androidx.core.content.res.ResourcesCompat; import androidx.core.view.ViewCompat; +import androidx.core.widget.TextViewCompat; /** * Simple text {@code Tooltip} implementation @@ -62,11 +63,11 @@ private Tooltip(Builder builder) { protected View createContentView(@NonNull Builder builder) { AppCompatTextView textView = new AppCompatTextView(mContext); textView.setTextAppearance(mContext, builder.mTextAppearance); - textView.setCompoundDrawablesRelativeWithIntrinsicBounds(builder.mDrawableStart, builder.mDrawableTop, builder.mDrawableEnd, builder.mDrawableBottom); textView.setText(builder.mText); textView.setPadding(builder.mPadding, builder.mPadding, builder.mPadding, builder.mPadding); textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier); textView.setCompoundDrawablePadding(builder.mDrawablePadding); + TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(textView, builder.mDrawableStart, builder.mDrawableTop, builder.mDrawableEnd, builder.mDrawableBottom); if (builder.mTextStyle >= 0) { textView.setTypeface(Typeface.create(textView.getTypeface(), builder.mTextStyle));