Skip to content

Commit

Permalink
Merge branch 'release-2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
philliphsu committed Nov 10, 2016
2 parents 348afda + b0407ce commit 8408d2c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 61 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ supporting API level 14 and up.
Add the following dependency to your module's `build.gradle`:
```groovy
dependencies {
compile 'com.philliphsu:bottomsheetpickers:2.0.1'
compile 'com.philliphsu:bottomsheetpickers:2.0.2'
}
```

Expand Down Expand Up @@ -117,6 +117,12 @@ You can specify whether to use a light (default) or dark theme:

> **NOTE:** `setThemeDark(boolean dark)` overwrites the value specified in XML.
### Additional Options
`NumberPadTimePickerDialog` exposes the following additional APIs:
* `setHint(String hint)` or `setHint(@StringRes int resid)`: Sets the hint of the input time TextView.
* `setInputTextSize(int textSize)`: Sets the text size in px of the input time TextView.
* `getInputTextView()`: Returns the `TextView` that stores the inputted time.

## Attribution

This library is based on code from the following AOSP repositories:
Expand Down
2 changes: 1 addition & 1 deletion bottomsheetpickers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/philliphsu/BottomSheetPickers'
gitUrl = 'https://github.com/philliphsu/BottomSheetPickers.git'

libraryVersion = '2.0.1'
libraryVersion = '2.0.2'

developerId = 'philliphsu'
developerName = 'Phillip Hsu'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import android.support.annotation.AttrRes;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.text.format.Time;
import android.view.View;
Expand Down Expand Up @@ -73,16 +70,29 @@ public class Utils {
static {
if (isJellybeanOrLater()) {
SANS_SERIF_LIGHT = Typeface.create("sans-serif-light", 0);
} else {
SANS_SERIF_LIGHT = null;
}

if (isLollipopOrLater()) {
HIGHLIGHT_TYPEFACE = Typeface.create(SANS_SERIF_LIGHT, Typeface.BOLD);
SELECTED_TYPEFACE = Typeface.create("sans-serif-thin", Typeface.BOLD);
} else {
SANS_SERIF_LIGHT = null;
SELECTED_TYPEFACE = HIGHLIGHT_TYPEFACE = Typeface.DEFAULT_BOLD;
if (SANS_SERIF_LIGHT != null) {
SELECTED_TYPEFACE = SANS_SERIF_LIGHT;
} else {
SELECTED_TYPEFACE = Typeface.DEFAULT;
}
HIGHLIGHT_TYPEFACE = Typeface.DEFAULT;
}
}

public static boolean isJellybeanOrLater() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
}

public static boolean isLollipopOrLater() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}

/**
Expand Down Expand Up @@ -234,29 +244,6 @@ public static void setTint(Drawable drawable, @ColorInt int color) {
DrawableCompat.setTint(drawable, color);
}

/**
* Returns a tinted drawable from the given drawable resource, if {@code tintList != null}.
* Otherwise, no tint will be applied.
*/
public static Drawable getTintedDrawable(@NonNull Context context,
@DrawableRes int drawableRes,
@Nullable ColorStateList tintList) {
Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(context, drawableRes).mutate());
DrawableCompat.setTintList(d, tintList);
return d;
}

/**
* Returns a tinted drawable from the given drawable resource and color resource.
*/
public static Drawable getTintedDrawable(@NonNull Context context,
@DrawableRes int drawableRes,
@ColorInt int colorInt) {
Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(context, drawableRes).mutate());
DrawableCompat.setTint(d, colorInt);
return d;
}

/**
* Sets the color on the {@code view}'s {@code selectableItemBackground} or the
* borderless variant, whichever was set as the background.
Expand Down Expand Up @@ -313,21 +300,4 @@ private static boolean resolveBoolean(Context context, @AttrRes int attr, boolea
a.recycle();
}
}

public static int darkenColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
// Decreasing the scale factor (i.e. 0.8f here) makes the color more light
hsv[2] = hsv[2] * 0.8f; // value component
return Color.HSVToColor(hsv);
}

public static int lightenColor(int color) {
// http://stackoverflow.com/a/4928826/5055032
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
// Decreasing the scale factor (i.e. -0.1f here) makes the color increasingly lighter
hsv[2] = 1.0f - 0.1f * (1.0f - hsv[2]);
return Color.HSVToColor(hsv);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
package com.philliphsu.bottomsheetpickers.time.grid;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.philliphsu.bottomsheetpickers.R;
import com.philliphsu.bottomsheetpickers.Utils;
Expand Down Expand Up @@ -86,20 +89,17 @@ public void setSelection(int value) {
@Override
void setTheme(Context context, boolean themeDark) {
super.setTheme(context, themeDark);
if (themeDark) {
// Resources default to dark-themed color (#FFFFFF)
// If vector fill color is transparent, programmatically tinting will not work.
// Since dark-themed active icon color is fully opaque, use that color as the
// base color and tint at runtime as needed.
mMinusButton.setImageResource(R.drawable.ic_minus_circle_24dp);
mPlusButton.setImageResource(R.drawable.ic_add_circle_24dp);
} else {
// Tint drawables
if (!themeDark) {
final int colorActiveLight = ContextCompat.getColor(context, R.color.icon_color_active_light);
mMinusButton.setImageDrawable(Utils.getTintedDrawable(
context, R.drawable.ic_minus_circle_24dp, colorActiveLight));
mPlusButton.setImageDrawable(Utils.getTintedDrawable(
context, R.drawable.ic_add_circle_24dp, colorActiveLight));
applyTint(mMinusButton, colorActiveLight);
applyTint(mPlusButton, colorActiveLight);
}
}

// TODO: Consider moving this to Utils.
private static void applyTint(ImageView view, @ColorInt int color) {
Drawable drawable = view.getDrawable();
Utils.setTint(drawable, color);
view.setImageDrawable(drawable);
}
}

0 comments on commit 8408d2c

Please sign in to comment.