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
@@ -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;
@@ -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;
}
}