Downgrade to support library version 24.2.0, changes to themes

This commit is contained in:
Phillip Hsu 2016-09-27 00:00:52 -07:00
parent 3d873fa6c2
commit b38d69f01e
8 changed files with 132 additions and 67 deletions

View File

@ -67,11 +67,11 @@ dependencies {
testCompile 'org.robolectric:robolectric:3.0'
provided 'com.google.auto.value:auto-value:1.2'
apt 'com.google.auto.value:auto-value:1.2'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:gridlayout-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:support-v4:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:gridlayout-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.jakewharton:butterknife:7.0.1'
}

View File

@ -15,7 +15,6 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

View File

@ -7,7 +7,6 @@ import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
import android.support.annotation.IdRes;
import android.support.design.widget.CheckableImageButton;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.Log;
import android.view.View;
@ -37,7 +36,7 @@ public class ExpandedAlarmViewHolder extends BaseAlarmViewHolder {
@Bind(R.id.ok) Button mOk;
@Bind(R.id.delete) Button mDelete;
@Bind(R.id.ringtone) Button mRingtone;
@Bind(R.id.vibrate) CheckableImageButton mVibrate;
@Bind(R.id.vibrate) TempCheckableImageButton mVibrate;
@Bind({R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6})
ToggleButton[] mDays;

View File

@ -1,27 +1,107 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.philliphsu.clock2.alarms.ui;
import android.content.Context;
import android.support.design.widget.CheckableImageButton;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v7.widget.AppCompatImageButton;
import android.util.AttributeSet;
import android.view.SoundEffectConstants;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Checkable;
/**
* Created by Phillip Hsu on 9/26/2016.
*
* Temporary fix for design support library's CheckableImageButton that toggles itself when clicked.
*
* We have copied over the original source code, because the class only exists on v24.2 but we are
* experiencing a lot of bugs on that.
*
* TODO: Now that we have settled on v24 support libs, extend back from CheckableImageButton
* and get rid of the original code.
*/
public class TempCheckableImageButton extends CheckableImageButton {
public class TempCheckableImageButton extends AppCompatImageButton implements Checkable {
private static final int[] DRAWABLE_STATE_CHECKED = new int[]{android.R.attr.state_checked};
private boolean mChecked;
public TempCheckableImageButton(Context context) {
super(context);
this(context, null);
}
public TempCheckableImageButton(Context context, AttributeSet attrs) {
super(context, attrs);
this(context, attrs, android.support.v7.appcompat.R.attr.imageButtonStyle);
}
public TempCheckableImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
event.setChecked(isChecked());
}
@Override
public void onInitializeAccessibilityNodeInfo(View host,
AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.setCheckable(true);
info.setChecked(isChecked());
}
});
}
@Override
public void setChecked(boolean checked) {
if (mChecked != checked) {
mChecked = checked;
refreshDrawableState();
sendAccessibilityEvent(
AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED);
}
}
@Override
public boolean isChecked() {
return mChecked;
}
@Override
public void toggle() {
setChecked(!mChecked);
}
@Override
public int[] onCreateDrawableState(int extraSpace) {
if (mChecked) {
return mergeDrawableStates(
super.onCreateDrawableState(extraSpace + DRAWABLE_STATE_CHECKED.length),
DRAWABLE_STATE_CHECKED);
} else {
return super.onCreateDrawableState(extraSpace);
}
}
@Override // borrowed from CompoundButton#performClick()
@ -35,5 +115,4 @@ public class TempCheckableImageButton extends CheckableImageButton {
}
return handled;
}
}

View File

@ -12,7 +12,7 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
app:elevation="0dp"> <!--Must set this!-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"

View File

@ -1,5 +1,6 @@
<resources>
<!--TODO: Why is this here?-->
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
@ -17,4 +18,12 @@
<item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
<item name="android:gravity">center</item>
</style>
<style name="BaseTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:alertDialogTheme">@style/AlertDialogStyle</item>
</style>
<style name="AlertDialogStyle" parent="android:Theme.Material.Dialog.Alert">
<item name="android:colorAccent">@color/colorAccentInverse</item>
</style>
</resources>

View File

@ -4,9 +4,10 @@
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF5252</color>
<!--TODO: Use color int instead? This resource is defined in aosp_datetimepicker_colors file. -->
<color name="colorPrimaryInverse">@color/dark_gray</color>
<color name="colorPrimaryInverse">#212121</color>
<color name="colorPrimaryDarkInverse">@android:color/black</color>
<!-- Same as colorAccent, can't find a lighter accent color that looks red enough.. -->
<color name="colorAccentInverse">#FF5252</color>
<color name="card_background_color">#1fffffff</color> <!--12% white, not from MD spec-->
</resources>

View File

@ -1,49 +1,40 @@
<resources>
<!--TODO: DayNight parent-->
<style name="BaseTheme" parent="Theme.AppCompat.NoActionBar">
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>
<style name="BaseAppTheme" parent="BaseTheme">
<item name="bottomSheetDialogTheme">@style/BottomSheetDialogTheme</item>
<!--Don't need to use `@color/icon_color` ColorStateList resource because icons tinted by this
- attribute will only ever be in the active state.
- Secondly, using a ColorStateList resource via XML for the tint attribute of an ImageView
- is not supported below 21.
-->
<!--TODO: Remove all light variants of colors.-->
<item name="themedIconTint">@color/icon_color_active_dark</item>
<!--TODO: Copy this resource over, because it will be going to BottomSheetTimePickers.-->
<item name="android:textColorHint">@color/text_color_disabled_dark</item>
<item name="themedPopupOverlay">@style/ThemeOverlay.AppCompat.Dark</item>
<!--BottomSheetTimePickers-->
<item name="themeDark">true</item>
<item name="cardBackgroundColor">@color/card_background_color</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme" parent="BaseAppTheme">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- TODO: This doesn't work for BottomSheetDialogs. Verify this works for other types of dialogs. -->
<!--<item name="dialogTheme">@style/AppCompatDialogTheme</item>-->
<!-- This theme is applied to appcompat AlertDialogs. -->
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<!-- This theme is applied to standard `android.app.AlertDialog`s. -->
<item name="android:alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<item name="bottomSheetDialogTheme">@style/BottomSheetDialogTheme</item>
<!--The icons that need to be tinted with this attribute will only ever be in
the active state, so we don't need to use @color/icon_color ColorStateList resource.
Secondly, using a ColorStateList resource via XML for the tint attribute of an ImageView
is not supported below 21. -->
<item name="themedIconTint">@color/icon_color_active_light</item>
<item name="android:textColorHint">@color/text_color_disabled_light</item>
<item name="themedPopupOverlay">@style/ThemeOverlay.AppCompat.Light</item>
<!-- For BottomSheetTimePickers -->
<item name="themeDark">false</item>
<item name="android:windowBackground">@color/colorPrimary</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<style name="AppTheme.Dark" parent="BaseAppTheme">
<item name="colorPrimary">@color/colorPrimaryInverse</item>
<item name="colorPrimaryDark">@color/colorPrimaryDarkInverse</item>
<item name="colorAccent">@color/colorAccentInverse</item>
<!-- TODO: This doesn't work for BottomSheetDialogs. Verify this works for other types of dialogs. -->
<!--<item name="dialogTheme">@style/AppCompatDialogTheme.Dark</item>-->
<!-- This theme is applied to appcompat AlertDialogs. -->
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle.Dark</item>
<!-- This theme is applied to standard `android.app.AlertDialog`s. -->
<item name="android:alertDialogTheme">@style/AppCompatAlertDialogStyle.Dark</item>
<!--TODO: Dark theme-->
<item name="bottomSheetDialogTheme">@style/BottomSheetDialogTheme</item>
<!--The icons that need to be tinted with this attribute will only ever be in
the active state, so we don't need to use @color/icon_color_dark ColorStateList resource
Secondly, using a ColorStateList resource via XML for the tint attribute of an ImageView
is not supported below 21.-->
<item name="themedIconTint">@color/icon_color_active_dark</item>
<item name="android:textColorHint">@color/text_color_disabled_dark</item>
<item name="themedPopupOverlay">@style/ThemeOverlay.AppCompat.Dark</item>
<!-- For BottomSheetTimePickers -->
<item name="themeDark">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
@ -146,21 +137,8 @@
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
</style>
<!-- Style for AppCompatDialog from the v7 support library -->
<style name="AppCompatDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppCompatDialogTheme.Dark" parent="Theme.AppCompat.Dialog">
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<!-- Trying to use the colorAccent attribute (whether from ?android:attr or ?attr) WILL CRASH.-->
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppCompatAlertDialogStyle.Dark" parent="Theme.AppCompat.Dialog.Alert">
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Dialog.Alert">
<!-- Trying to use the colorAccent attribute (whether from ?android:attr or ?attr) WILL CRASH.-->
<item name="colorAccent">@color/colorAccentInverse</item>
</style>