// Path: src/com/kk/binding/view/BindViewUtil.java
// public class BindViewUtil {
//     private static final String TAG = "Bind-BindViewUtil";
//     private static Converter converter;
// 
//     private static Converter defaultConverter = new Converter() {
//         @Override
//         public Object from(String string, Type type) {
//             return JSON.parseObject(string);//JSON.parseObject(string, type);
//         }
// 
//         @Override
//         public Object from(byte[] data, Type type) {
//             return JSON.parseObject(new String(data));//JSON.parseObject(data, type);
//         }
//     };
// 
//     public static void setConverter(Converter converter) {
//         BindViewUtil.converter = converter;
//     }
// 
//     // for design use
//     public static View inflateView(Context context, int layoutId, ViewGroup parent, boolean attachToRoot) {
//         injectInflater(context);
//         return LayoutInflater.from(context).inflate(layoutId, parent, attachToRoot);
//     }
// 
//     /**
//      * inject inflater with our binding view factory
//      *
//      * @param context
//      */
//     public static void injectInflater(Context context) {
//         LayoutInflater inflater = LayoutInflater.from(context);
//         if (inflater.getFactory() == null) {
//             BindLog.d(TAG, "did injectInflater");
//             ViewFactory factory = new ViewFactory(inflater);
//             inflater.setFactory(factory);
//         }
//     }
// 
//     public static DependencyObject getDependencyObject(View view) {
//         DependencyObject dpo = (DependencyObject) view.getTag(R.id.tag_for_attach_property);
//         if (dpo == null) {
//             dpo = new DependencyObject();
//             dpo.setOriginTarget(view);
//             view.setTag(R.id.tag_for_attach_property, dpo);
//         }
//         return dpo;
//     }
// 
//     public static void setDataContext(View view, String string, Type claszz) {
//         IConverter c = converter == null ? defaultConverter : converter;
//         Object obj = null;
//         try {
//             obj = c.from(string, claszz);
//         } catch (Exception e) {
// 
//         }
//         setDataContext(view, obj);
//     }
// 
//     public static void setDataContext(View view, byte[] data, Type claszz) {
//         IConverter c = converter == null ? defaultConverter : converter;
//         Object obj = null;
//         try {
//             obj = c.from(data, claszz);
//         } catch (Exception e) {
// 
//         }
//         setDataContext(view, obj);
//     }
// 
//     private static void setDataContextInner(final View view, final Object dataContext) {
//         if (view == null || getBindDataObject(view) == dataContext)
//             return;
//         // view.toString() will throw exception when you set a view's id in xml
// //        BindLog.d(TAG, "setDataContext : view(" + level + ") = \n"
// //                + (view.isInEditMode() ? view.getClass().getName() : view.toString())
// //                + "\n dataContext= " + (dataContext != null ? dataContext.toString() : null));
//         view.setTag(R.id.tag_for_binding_data_object, dataContext);
// 
//         DependencyObject dpo = getDependencyObject(view);
//         boolean handled = dpo.setDataContext(dataContext);
//         if (handled) return;
// 
//         if (view instanceof ViewGroup) {
//             Object targetObject = dpo.getResolvedTargetObject();
//             ViewGroup vg = (ViewGroup) view;
//             int count = vg.getChildCount();
//             for (int i = 0; i < count; i++) {
//                 View v = vg.getChildAt(i);
//                 setDataContext(v, targetObject);
//             }
//         }
//     }
// 
//     public static void setDataContext(final View view, final Object dataContext) {
//         long start = 0;
//         if (BindLog.isLogOpen()) {
//             start = System.nanoTime();
//         }
// 
//         setDataContextInner(view, dataContext);
// 
//         if (BindLog.isLogOpen()) {
//             long end = System.nanoTime();
//             long delta = TimeUnit.NANOSECONDS.toMillis(end - start);
//             BindLog.w(TAG, "setDataContext for view (" + view.getClass().getSimpleName() + "), time(ms) = " + delta);
//         }
//     }
// 
//     public static Object getBindDataObject(View view) {
//         return view.getTag(R.id.tag_for_binding_data_object);
//     }
// }


import android.content.Context;
import android.view.View;
import com.kk.binding.view.BindViewUtil;
import java.util.Arrays;
import java.util.List;
/*
 * Copyright (C) 2013 kk-team.com.
 *
 * 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.kk.binding.adapter;



/**
 * Created by xj on 13-7-6.
 */
public class SimpleBindListAdapter extends SimpleListAdapter<Object> {
    private static final String TAG = "Binding-SimpleBindListAdapter";

    public SimpleBindListAdapter(Context context, int resId, List<Object> data) {
        super(context, resId, data);
    }

    public SimpleBindListAdapter(Context context, int mResId, Object[] obj) {
        this(context, mResId, Arrays.asList(obj));
    }

    @Override protected void onBindData(View view, Object data, int position) {
// Path: src/com/kk/binding/view/BindViewUtil.java
// public class BindViewUtil {
//     private static final String TAG = "Bind-BindViewUtil";
//     private static Converter converter;
// 
//     private static Converter defaultConverter = new Converter() {
//         @Override
//         public Object from(String string, Type type) {
//             return JSON.parseObject(string);//JSON.parseObject(string, type);
//         }
// 
//         @Override
//         public Object from(byte[] data, Type type) {
//             return JSON.parseObject(new String(data));//JSON.parseObject(data, type);
//         }
//     };
// 
//     public static void setConverter(Converter converter) {
//         BindViewUtil.converter = converter;
//     }
// 
//     // for design use
//     public static View inflateView(Context context, int layoutId, ViewGroup parent, boolean attachToRoot) {
//         injectInflater(context);
//         return LayoutInflater.from(context).inflate(layoutId, parent, attachToRoot);
//     }
// 
//     /**
//      * inject inflater with our binding view factory
//      *
//      * @param context
//      */
//     public static void injectInflater(Context context) {
//         LayoutInflater inflater = LayoutInflater.from(context);
//         if (inflater.getFactory() == null) {
//             BindLog.d(TAG, "did injectInflater");
//             ViewFactory factory = new ViewFactory(inflater);
//             inflater.setFactory(factory);
//         }
//     }
// 
//     public static DependencyObject getDependencyObject(View view) {
//         DependencyObject dpo = (DependencyObject) view.getTag(R.id.tag_for_attach_property);
//         if (dpo == null) {
//             dpo = new DependencyObject();
//             dpo.setOriginTarget(view);
//             view.setTag(R.id.tag_for_attach_property, dpo);
//         }
//         return dpo;
//     }
// 
//     public static void setDataContext(View view, String string, Type claszz) {
//         IConverter c = converter == null ? defaultConverter : converter;
//         Object obj = null;
//         try {
//             obj = c.from(string, claszz);
//         } catch (Exception e) {
// 
//         }
//         setDataContext(view, obj);
//     }
// 
//     public static void setDataContext(View view, byte[] data, Type claszz) {
//         IConverter c = converter == null ? defaultConverter : converter;
//         Object obj = null;
//         try {
//             obj = c.from(data, claszz);
//         } catch (Exception e) {
// 
//         }
//         setDataContext(view, obj);
//     }
// 
//     private static void setDataContextInner(final View view, final Object dataContext) {
//         if (view == null || getBindDataObject(view) == dataContext)
//             return;
//         // view.toString() will throw exception when you set a view's id in xml
// //        BindLog.d(TAG, "setDataContext : view(" + level + ") = \n"
// //                + (view.isInEditMode() ? view.getClass().getName() : view.toString())
// //                + "\n dataContext= " + (dataContext != null ? dataContext.toString() : null));
//         view.setTag(R.id.tag_for_binding_data_object, dataContext);
// 
//         DependencyObject dpo = getDependencyObject(view);
//         boolean handled = dpo.setDataContext(dataContext);
//         if (handled) return;
// 
//         if (view instanceof ViewGroup) {
//             Object targetObject = dpo.getResolvedTargetObject();
//             ViewGroup vg = (ViewGroup) view;
//             int count = vg.getChildCount();
//             for (int i = 0; i < count; i++) {
//                 View v = vg.getChildAt(i);
//                 setDataContext(v, targetObject);
//             }
//         }
//     }
// 
//     public static void setDataContext(final View view, final Object dataContext) {
//         long start = 0;
//         if (BindLog.isLogOpen()) {
//             start = System.nanoTime();
//         }
// 
//         setDataContextInner(view, dataContext);
// 
//         if (BindLog.isLogOpen()) {
//             long end = System.nanoTime();
//             long delta = TimeUnit.NANOSECONDS.toMillis(end - start);
//             BindLog.w(TAG, "setDataContext for view (" + view.getClass().getSimpleName() + "), time(ms) = " + delta);
//         }
//     }
// 
//     public static Object getBindDataObject(View view) {
//         return view.getTag(R.id.tag_for_binding_data_object);
//     }
// }


// Path: src/com/kk/binding/adapter/SimpleBindListAdapter.java
import android.content.Context;
import android.view.View;
import com.kk.binding.view.BindViewUtil;
import java.util.Arrays;
import java.util.List;

/*
 * Copyright (C) 2013 kk-team.com.
 *
 * 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.kk.binding.adapter;



/**
 * Created by xj on 13-7-6.
 */
public class SimpleBindListAdapter extends SimpleListAdapter<Object> {
    private static final String TAG = "Binding-SimpleBindListAdapter";

    public SimpleBindListAdapter(Context context, int resId, List<Object> data) {
        super(context, resId, data);
    }

    public SimpleBindListAdapter(Context context, int mResId, Object[] obj) {
        this(context, mResId, Arrays.asList(obj));
    }

    @Override protected void onBindData(View view, Object data, int position) {
        BindViewUtil.setDataContext(view, data);