Skip to content

Commit d55720b

Browse files
committed
Fix how half day compound drawables are retrieved and set
1 parent e5b670f commit d55720b

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

bottomsheetpickers/src/main/java/com/philliphsu/bottomsheetpickers/time/grid/GridTimePickerDialog.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.Typeface;
2424
import android.os.Bundle;
2525
import android.support.design.widget.FloatingActionButton;
26+
import android.support.graphics.drawable.VectorDrawableCompat;
2627
import android.util.Log;
2728
import android.view.KeyCharacterMap;
2829
import android.view.KeyEvent;
@@ -281,10 +282,17 @@ public void onClick(View v) {
281282
mSecondHalfDayToggle.setText(R.string.hours_12_23);
282283
// We need different drawable resources for each case, not a single one that we
283284
// just tint differently, because the orientation of each one is different.
284-
final int icon1 = mThemeDark? R.drawable.ic_half_day_1_dark_24dp : R.drawable.ic_half_day_1_24dp;
285-
final int icon2 = mThemeDark? R.drawable.ic_half_day_2_dark_24dp : R.drawable.ic_half_day_2_24dp;
286-
mFirstHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(0, icon1, 0, 0);
287-
mSecondHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(0, icon2, 0, 0);
285+
final int iconRes1 = mThemeDark? R.drawable.ic_half_day_1_dark_24dp : R.drawable.ic_half_day_1_24dp;
286+
final int iconRes2 = mThemeDark? R.drawable.ic_half_day_2_dark_24dp : R.drawable.ic_half_day_2_24dp;
287+
VectorDrawableCompat icon1 = VectorDrawableCompat.create(res, iconRes1, ctx.getTheme());
288+
VectorDrawableCompat icon2 = VectorDrawableCompat.create(res, iconRes2, ctx.getTheme());
289+
if (Utils.checkApiLevel(17)) {
290+
mFirstHalfDayToggle.setCompoundDrawablesRelativeWithIntrinsicBounds(null, icon1, null, null);
291+
mSecondHalfDayToggle.setCompoundDrawablesRelativeWithIntrinsicBounds(null, icon2, null, null);
292+
} else {
293+
mFirstHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(null, icon1, null, null);
294+
mSecondHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(null, icon2, null, null);
295+
}
288296
} else {
289297
mAmPmTextView.setVisibility(View.VISIBLE);
290298
mAmPmHitspace.setOnClickListener(new OnClickListener() {

bottomsheetpickers/src/main/res/drawable/ic_half_day_1_dark_24dp.xml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515
~ limitations under the License.
1616
-->
1717

18-
<!-- http://stackoverflow.com/a/8716798/5055032 -->
19-
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
20-
android:fromDegrees="180"
21-
android:toDegrees="180"
22-
android:pivotX="50%"
23-
android:pivotY="50%"
24-
android:drawable="@drawable/ic_half_day_2_dark_24dp">
25-
</rotate>
18+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:width="24dp"
20+
android:height="24dp"
21+
android:viewportWidth="24.0"
22+
android:viewportHeight="24.0">
23+
<group
24+
android:pivotX="12.0"
25+
android:pivotY="12.0"
26+
android:rotation="180">
27+
<path
28+
android:fillColor="#FFFFFF"
29+
android:pathData="M20,15.31L23.31,12 20,8.69V4h-4.69L12,0.69 8.69,4H4v4.69L0.69,12 4,15.31V20h4.69L12,23.31 15.31,20H20v-4.69zM12,18V6c3.31,0 6,2.69 6,6s-2.69,6 -6,6z"/>
30+
</group>
31+
</vector>

bottomsheetpickers/src/main/res/drawable/ic_half_day_2_24dp.xml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515
~ limitations under the License.
1616
-->
1717

18-
<!-- http://stackoverflow.com/a/8716798/5055032 -->
19-
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
20-
android:fromDegrees="180"
21-
android:toDegrees="180"
22-
android:pivotX="50%"
23-
android:pivotY="50%"
24-
android:drawable="@drawable/ic_half_day_1_24dp">
25-
</rotate>
18+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:width="24dp"
20+
android:height="24dp"
21+
android:viewportWidth="24.0"
22+
android:viewportHeight="24.0">
23+
<group
24+
android:pivotX="12.0"
25+
android:pivotY="12.0"
26+
android:rotation="180">
27+
<path
28+
android:fillColor="#8a000000"
29+
android:pathData="M20,15.31L23.31,12 20,8.69V4h-4.69L12,0.69 8.69,4H4v4.69L0.69,12 4,15.31V20h4.69L12,23.31 15.31,20H20v-4.69zM12,18V6c3.31,0 6,2.69 6,6s-2.69,6 -6,6z"/>
30+
</group>
31+
</vector>

0 commit comments

Comments
 (0)