// Path: nightowllib/src/main/java/com/asha/nightowllib/handler/ISkinHandler.java
// public interface ISkinHandler {
//     void collect(int mode, View view, Context context, AttributeSet attrs);
//     void onSkinChanged(int skin, View 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: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static int[] getStaticFieldIntArraySafely(Field field){
//     try {
//         return (int[]) field.get(null);
//     } catch (IllegalAccessException e) {
//         e.printStackTrace();
//     }
//     return null;
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static void insertSkinBox(View view, ColorBox box){
//     view.setTag(NIGHT_OWL_VIEW_TAG, box);
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static ColorBox obtainSkinBox(View view){
//     Object box = view.getTag(NIGHT_OWL_VIEW_TAG);
//     checkNonNull(box,"wtf, it can't be null.");
//     if ( box instanceof ColorBox ){
//         return (ColorBox) box;
//     } else if ( box.equals(EMPTY_TAG) ) {
//         Log.d(TAG, "EMPTY_TAG...");
//         return null;
//     } else {
//         Log.e(TAG, "wtf, NIGHT_OWL_VIEW_TAG had been used by someone else.");
//     }
//     return null;
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/paint/OwlPaintManager.java
// public static IOwlPaint queryPaint(int attrWithScope){
//     Class< ? extends IOwlPaint> clz = sPaints.get(attrWithScope);
//     if ( clz == null ) return null;
//     IOwlPaint instance = sPaintInstances.get(clz);
//     if ( instance == null ){
//         instance = newInstanceSafely(clz);
//         sPaintInstances.put(clz,instance);
//     }
//     return instance;
// }


import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com.asha.nightowllib.handler.ISkinHandler;
import com.asha.nightowllib.handler.annotations.OwlAttrScope;
import com.asha.nightowllib.handler.annotations.OwlStyleable;
import com.asha.nightowllib.handler.annotations.OwlSysStyleable;
import com.asha.nightowllib.paint.ColorBox;
import com.asha.nightowllib.paint.IOwlPaint;
import java.lang.reflect.Field;
import static com.asha.nightowllib.NightOwlUtil.getStaticFieldIntArraySafely;
import static com.asha.nightowllib.NightOwlUtil.insertSkinBox;
import static com.asha.nightowllib.NightOwlUtil.obtainSkinBox;
import static com.asha.nightowllib.paint.OwlPaintManager.queryPaint;

            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
// Path: nightowllib/src/main/java/com/asha/nightowllib/handler/ISkinHandler.java
// public interface ISkinHandler {
//     void collect(int mode, View view, Context context, AttributeSet attrs);
//     void onSkinChanged(int skin, View 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: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static int[] getStaticFieldIntArraySafely(Field field){
//     try {
//         return (int[]) field.get(null);
//     } catch (IllegalAccessException e) {
//         e.printStackTrace();
//     }
//     return null;
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static void insertSkinBox(View view, ColorBox box){
//     view.setTag(NIGHT_OWL_VIEW_TAG, box);
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/NightOwlUtil.java
// public static ColorBox obtainSkinBox(View view){
//     Object box = view.getTag(NIGHT_OWL_VIEW_TAG);
//     checkNonNull(box,"wtf, it can't be null.");
//     if ( box instanceof ColorBox ){
//         return (ColorBox) box;
//     } else if ( box.equals(EMPTY_TAG) ) {
//         Log.d(TAG, "EMPTY_TAG...");
//         return null;
//     } else {
//         Log.e(TAG, "wtf, NIGHT_OWL_VIEW_TAG had been used by someone else.");
//     }
//     return null;
// }
// 
// Path: nightowllib/src/main/java/com/asha/nightowllib/paint/OwlPaintManager.java
// public static IOwlPaint queryPaint(int attrWithScope){
//     Class< ? extends IOwlPaint> clz = sPaints.get(attrWithScope);
//     if ( clz == null ) return null;
//     IOwlPaint instance = sPaintInstances.get(clz);
//     if ( instance == null ){
//         instance = newInstanceSafely(clz);
//         sPaintInstances.put(clz,instance);
//     }
//     return instance;
// }


// Path: nightowllib/src/main/java/com/asha/nightowllib/handler/impls/AbsSkinHandler.java
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com.asha.nightowllib.handler.ISkinHandler;
import com.asha.nightowllib.handler.annotations.OwlAttrScope;
import com.asha.nightowllib.handler.annotations.OwlStyleable;
import com.asha.nightowllib.handler.annotations.OwlSysStyleable;
import com.asha.nightowllib.paint.ColorBox;
import com.asha.nightowllib.paint.IOwlPaint;
import java.lang.reflect.Field;
import static com.asha.nightowllib.NightOwlUtil.getStaticFieldIntArraySafely;
import static com.asha.nightowllib.NightOwlUtil.insertSkinBox;
import static com.asha.nightowllib.NightOwlUtil.obtainSkinBox;
import static com.asha.nightowllib.paint.OwlPaintManager.queryPaint;


            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);