Skip to content
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.

Bug/deprecation warnings #332

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 24
buildToolsVersion "24.0.3"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
targetSdkVersion 24
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
}
Expand All @@ -25,6 +25,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:24.2.1'
}

apply from: '../gradle-mvn-push.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
Expand Down Expand Up @@ -798,7 +799,7 @@ public void setImageDrawable(Drawable drawable) {

@Override
public void setImageResource(int resId) {
Drawable drawable = getResources().getDrawable(resId);
Drawable drawable = ContextCompat.getDrawable(getContext(), resId);
if (mIcon != drawable) {
mIcon = drawable;
updateBackground();
Expand Down Expand Up @@ -850,7 +851,7 @@ public void setColorNormal(int color) {
}

public void setColorNormalResId(int colorResId) {
setColorNormal(getResources().getColor(colorResId));
setColorNormal(ContextCompat.getColor(getContext(), colorResId));
}

public int getColorNormal() {
Expand All @@ -865,7 +866,7 @@ public void setColorPressed(int color) {
}

public void setColorPressedResId(int colorResId) {
setColorPressed(getResources().getColor(colorResId));
setColorPressed(ContextCompat.getColor(getContext(), colorResId));
}

public int getColorPressed() {
Expand All @@ -880,7 +881,7 @@ public void setColorRipple(int color) {
}

public void setColorRippleResId(int colorResId) {
setColorRipple(getResources().getColor(colorResId));
setColorRipple(ContextCompat.getColor(getContext(), colorResId));
}

public int getColorRipple() {
Expand All @@ -895,7 +896,7 @@ public void setColorDisabled(int color) {
}

public void setColorDisabledResId(int colorResId) {
setColorDisabled(getResources().getColor(colorResId));
setColorDisabled(ContextCompat.getColor(getContext(), colorResId));
}

public int getColorDisabled() {
Expand Down Expand Up @@ -1010,7 +1011,7 @@ public int getShadowYOffset() {
}

public void setShadowColorResource(int colorResId) {
int shadowColor = getResources().getColor(colorResId);
int shadowColor = ContextCompat.getColor(getContext(), colorResId);
if (mShadowColor != shadowColor) {
mShadowColor = shadowColor;
updateBackground();
Expand Down
24 changes: 19 additions & 5 deletions library/src/main/java/com/github/clans/fab/FloatingActionMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.IntegerRes;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
Expand All @@ -24,6 +28,7 @@
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -158,7 +163,7 @@ private void init(Context context, AttributeSet attrs) {
mAnimationDelayPerItem = attr.getInt(R.styleable.FloatingActionMenu_menu_animationDelayPerItem, 50);
mIcon = attr.getDrawable(R.styleable.FloatingActionMenu_menu_icon);
if (mIcon == null) {
mIcon = getResources().getDrawable(R.drawable.fab_add);
mIcon = ContextCompat.getDrawable(getContext(), R.drawable.fab_add);
}
mLabelsSingleLine = attr.getBoolean(R.styleable.FloatingActionMenu_menu_labels_singleLine, false);
mLabelsEllipsize = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_ellipsize, 0);
Expand Down Expand Up @@ -473,6 +478,15 @@ public void onClick(View v) {
}
}

@SuppressWarnings("deprecation")
private void setTextAppearanceCompat(TextView textView, @IntegerRes int textAppearance) {
if(Build.VERSION.SDK_INT >= 23) {
textView.setTextAppearance(mLabelsStyle);
} else {
textView.setTextAppearance(getContext(), mLabelsStyle);
}
}

private void addLabel(FloatingActionButton fab) {
String text = fab.getLabelText();

Expand All @@ -485,7 +499,7 @@ private void addLabel(FloatingActionButton fab) {
label.setHideAnimation(AnimationUtils.loadAnimation(getContext(), mLabelsHideAnimation));

if (mLabelsStyle > 0) {
label.setTextAppearance(getContext(), mLabelsStyle);
setTextAppearanceCompat(label, mLabelsStyle);
label.setShowShadow(false);
label.setUsingStyle(true);
} else {
Expand Down Expand Up @@ -922,7 +936,7 @@ public void setMenuButtonColorNormal(int color) {
}

public void setMenuButtonColorNormalResId(int colorResId) {
mMenuColorNormal = getResources().getColor(colorResId);
mMenuColorNormal = ContextCompat.getColor(getContext(), colorResId);
mMenuButton.setColorNormalResId(colorResId);
}

Expand All @@ -936,7 +950,7 @@ public void setMenuButtonColorPressed(int color) {
}

public void setMenuButtonColorPressedResId(int colorResId) {
mMenuColorPressed = getResources().getColor(colorResId);
mMenuColorPressed = ContextCompat.getColor(getContext(), colorResId);
mMenuButton.setColorPressedResId(colorResId);
}

Expand All @@ -950,7 +964,7 @@ public void setMenuButtonColorRipple(int color) {
}

public void setMenuButtonColorRippleResId(int colorResId) {
mMenuColorRipple = getResources().getColor(colorResId);
mMenuColorRipple = ContextCompat.getColor(getContext(), colorResId);
mMenuButton.setColorRippleResId(colorResId);
}

Expand Down