// Path: nightowllib/src/main/java/com/asha/nightowllib/handler/impls/AbsSkinHandler.java
// public abstract class AbsSkinHandler implements ISkinHandler {
//     private final static String ANDROID_XML = "http://schemas.android.com/apk/res/android";
//     private static final String TAG = "AbsSkinHandler";
// 
//     @Override
//     public void collect(int mode, View view, Context context, AttributeSet attrs) {
//         Log.d(TAG, String.format("collected %s %s %s", view, context, attrs));
//         ColorBox box = ColorBox.newInstance();
//         onBeforeCollect(view,context,attrs,box);
// 
//         final Resources.Theme theme = context.getTheme();
//         int systemStyleResId = 0;
//         Class clz = this.getClass();
// 
//         // SystemStyleable
//         OwlSysStyleable systemStyleable = (OwlSysStyleable) clz.getAnnotation(OwlSysStyleable.class);
//         if ( systemStyleable != null ){
//             String value = systemStyleable.value();
//             systemStyleResId = attrs.getAttributeResourceValue(ANDROID_XML, value, 0);
//         }
// 
//         // OwlStyleable
//         Field[] fields = clz.getFields();
//         for ( Field field : fields ){
//             OwlStyleable owlStyleable = field.getAnnotation(OwlStyleable.class);
//             if ( owlStyleable == null ) continue;
// 
//             Class scopeClz = field.getDeclaringClass();
//             OwlAttrScope owlAttrScope = (OwlAttrScope) scopeClz.getAnnotation(OwlAttrScope.class);
//             if ( owlAttrScope == null ) continue;
// 
//             int scope = owlAttrScope.value();
//             int[] styleableResId = getStaticFieldIntArraySafely(field);
//             if ( styleableResId == null )  continue;
// 
//             TypedArray a = theme.obtainStyledAttributes(attrs, styleableResId, 0, systemStyleResId);
//             if ( a != null ){
//                 obtainStyle(view, box, scope, a);
//                 a.recycle();
//             }
//         }
// 
//         onAfterCollect(view,context,attrs,box);
//         insertSkinBox(view, box);
// 
//         // first refresh
//         box.refreshSkin(mode, view, true);
//     }
// 
//     private void obtainStyle(View view
//             , ColorBox box
//             , int scope
//             , TypedArray a
//             ){
// 
//         int n = a.getIndexCount();
//         for (int i = 0; i < n; i++) {
//             int attr = a.getIndex(i);
// 
//             // look for attr
//             IOwlPaint paint = queryPaint(attr+scope);
//             if ( paint == null) {
//                 Log.d(TAG, "Can't find paint of attr:" + attr + " scope:" + scope); continue; }
//             Object[] values = paint.setup(view,a,attr);
//             if ( values != null ) box.put(attr, scope, values);
//         }
//     }
// 
//     protected void onBeforeCollect(View view, Context context, AttributeSet attrs, ColorBox box){}
// 
//     protected void onAfterCollect(View view, Context context, AttributeSet attrs, ColorBox box){}
// 
//     @Override
//     final public void onSkinChanged(int skin, View view) {
//         ColorBox box = obtainSkinBox(view);
//         if ( box != null ) box.refreshSkin(skin, view);
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/paint/ColorBox.java
// public class ColorBox {
//     private int mMode = -1;
//     // may override the value, so we use SparseArray
//     private SparseArray<Object[]> mBox;
//     private ColorBox() {
//         mBox = new SparseArray<>(4);
//     }
// 
//     public void put(int attr, int scope, Object... objects){
//         mBox.put(attr + scope, objects);
//     }
// 
//     public void refreshSkin(int mode, View view, boolean force){
//         if ( force ) mMode = -1;
//         refreshSkin(mode,view);
//     }
// 
//     public Object[] get(int attr, int scope){
//         return mBox.get( attr + scope );
//     }
// 
//     public void refreshSkin(int mode, View view){
//         if ( mMode != mode ){
//             int size = mBox.size();
//             for (int i = 0; i < size; i++) {
//                 int attrWithScope = mBox.keyAt(i);
//                 Object[] res = mBox.valueAt(i);
//                 IOwlPaint paint = queryPaint(attrWithScope);
//                 if ( paint != null ) paint.draw(view, res[mode]);
//             }
//         }
//         mMode = mode;
//     }
// 
//     public int getMode() {
//         return mMode;
//     }
// 
//     public static ColorBox newInstance() {
//         return new ColorBox();
//     }
// 
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/paint/IOwlPaint.java
// public interface IOwlPaint {
//     void draw(View view, Object value);
//     Object[] setup(View view, TypedArray a, int attr);
// }


import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.View;
import com.asha.nightowl.R;
import com.asha.nightowllib.handler.annotations.OwlHandle;
import com.asha.nightowllib.handler.impls.AbsSkinHandler;
import com.asha.nightowllib.paint.ColorBox;
import com.asha.nightowllib.paint.IOwlPaint;
package com.asha.nightowl.custom;



/**
 * Created by hzqiujiadi on 15/11/12.
 * hzqiujiadi ashqalcn@gmail.com
 */
@OwlHandle(CardView.class)
public class CardViewHandler extends AbsSkinHandler implements OwlCustomTable.OwlCardView {

    @Override
// Path: nightowllib/src/main/java/com/asha/nightowllib/handler/impls/AbsSkinHandler.java
// public abstract class AbsSkinHandler implements ISkinHandler {
//     private final static String ANDROID_XML = "http://schemas.android.com/apk/res/android";
//     private static final String TAG = "AbsSkinHandler";
// 
//     @Override
//     public void collect(int mode, View view, Context context, AttributeSet attrs) {
//         Log.d(TAG, String.format("collected %s %s %s", view, context, attrs));
//         ColorBox box = ColorBox.newInstance();
//         onBeforeCollect(view,context,attrs,box);
// 
//         final Resources.Theme theme = context.getTheme();
//         int systemStyleResId = 0;
//         Class clz = this.getClass();
// 
//         // SystemStyleable
//         OwlSysStyleable systemStyleable = (OwlSysStyleable) clz.getAnnotation(OwlSysStyleable.class);
//         if ( systemStyleable != null ){
//             String value = systemStyleable.value();
//             systemStyleResId = attrs.getAttributeResourceValue(ANDROID_XML, value, 0);
//         }
// 
//         // OwlStyleable
//         Field[] fields = clz.getFields();
//         for ( Field field : fields ){
//             OwlStyleable owlStyleable = field.getAnnotation(OwlStyleable.class);
//             if ( owlStyleable == null ) continue;
// 
//             Class scopeClz = field.getDeclaringClass();
//             OwlAttrScope owlAttrScope = (OwlAttrScope) scopeClz.getAnnotation(OwlAttrScope.class);
//             if ( owlAttrScope == null ) continue;
// 
//             int scope = owlAttrScope.value();
//             int[] styleableResId = getStaticFieldIntArraySafely(field);
//             if ( styleableResId == null )  continue;
// 
//             TypedArray a = theme.obtainStyledAttributes(attrs, styleableResId, 0, systemStyleResId);
//             if ( a != null ){
//                 obtainStyle(view, box, scope, a);
//                 a.recycle();
//             }
//         }
// 
//         onAfterCollect(view,context,attrs,box);
//         insertSkinBox(view, box);
// 
//         // first refresh
//         box.refreshSkin(mode, view, true);
//     }
// 
//     private void obtainStyle(View view
//             , ColorBox box
//             , int scope
//             , TypedArray a
//             ){
// 
//         int n = a.getIndexCount();
//         for (int i = 0; i < n; i++) {
//             int attr = a.getIndex(i);
// 
//             // look for attr
//             IOwlPaint paint = queryPaint(attr+scope);
//             if ( paint == null) {
//                 Log.d(TAG, "Can't find paint of attr:" + attr + " scope:" + scope); continue; }
//             Object[] values = paint.setup(view,a,attr);
//             if ( values != null ) box.put(attr, scope, values);
//         }
//     }
// 
//     protected void onBeforeCollect(View view, Context context, AttributeSet attrs, ColorBox box){}
// 
//     protected void onAfterCollect(View view, Context context, AttributeSet attrs, ColorBox box){}
// 
//     @Override
//     final public void onSkinChanged(int skin, View view) {
//         ColorBox box = obtainSkinBox(view);
//         if ( box != null ) box.refreshSkin(skin, view);
//     }
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/paint/ColorBox.java
// public class ColorBox {
//     private int mMode = -1;
//     // may override the value, so we use SparseArray
//     private SparseArray<Object[]> mBox;
//     private ColorBox() {
//         mBox = new SparseArray<>(4);
//     }
// 
//     public void put(int attr, int scope, Object... objects){
//         mBox.put(attr + scope, objects);
//     }
// 
//     public void refreshSkin(int mode, View view, boolean force){
//         if ( force ) mMode = -1;
//         refreshSkin(mode,view);
//     }
// 
//     public Object[] get(int attr, int scope){
//         return mBox.get( attr + scope );
//     }
// 
//     public void refreshSkin(int mode, View view){
//         if ( mMode != mode ){
//             int size = mBox.size();
//             for (int i = 0; i < size; i++) {
//                 int attrWithScope = mBox.keyAt(i);
//                 Object[] res = mBox.valueAt(i);
//                 IOwlPaint paint = queryPaint(attrWithScope);
//                 if ( paint != null ) paint.draw(view, res[mode]);
//             }
//         }
//         mMode = mode;
//     }
// 
//     public int getMode() {
//         return mMode;
//     }
// 
//     public static ColorBox newInstance() {
//         return new ColorBox();
//     }
// 
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/paint/IOwlPaint.java
// public interface IOwlPaint {
//     void draw(View view, Object value);
//     Object[] setup(View view, TypedArray a, int attr);
// }


// Path: app/src/main/java/com/asha/nightowl/custom/CardViewHandler.java
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.View;
import com.asha.nightowl.R;
import com.asha.nightowllib.handler.annotations.OwlHandle;
import com.asha.nightowllib.handler.impls.AbsSkinHandler;
import com.asha.nightowllib.paint.ColorBox;
import com.asha.nightowllib.paint.IOwlPaint;

package com.asha.nightowl.custom;



/**
 * Created by hzqiujiadi on 15/11/12.
 * hzqiujiadi ashqalcn@gmail.com
 */
@OwlHandle(CardView.class)
public class CardViewHandler extends AbsSkinHandler implements OwlCustomTable.OwlCardView {

    @Override
    protected void onAfterCollect(View view, Context context, AttributeSet attrs, ColorBox box) {