Android Open Source - Android-Data-Binding View Binder






From Project

Back to project page Android-Data-Binding.

License

The source code is released under:

MIT License

If you think the Android project Android-Data-Binding listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.furkanbayraktar.databinding;
//w w  w. j  av  a 2 s.  co m
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import com.furkanbayraktar.databinding.common.resolver.FunctionResolver;
import com.furkanbayraktar.databinding.common.resolver.AssignmentResolver;
import com.furkanbayraktar.databinding.common.parser.Parser;
import com.furkanbayraktar.databinding.common.resolver.VisibilityResolver;
import com.furkanbayraktar.databinding.logging.Logger;
import com.furkanbayraktar.databinding.model.BasePOJO;

import java.util.HashMap;

/**
 * Created by Furkan Bayraktar.
 * Created at 8/15/14.
 *
 */
public class ViewBinder {

    public static final String TAG = "AndroidDataBinder";

    private static ViewBinder instance;

    private boolean logging;

    private ViewBinder(){}

    public static ViewBinder getInstance(){
        if(instance == null){
            instance = new ViewBinder();
        }
        return instance;
    }

    public void setLoggingEnabled(boolean enabled){
        logging = enabled;
        if(enabled){
            Logger.info("Logging enabled.");
        } else {
            Logger.info("Logging disabled.");
        }
    }

    public boolean isLoggingEnabled(){
        return logging;
    }

    public void bindView(BasePOJO object, View view, Context context, Integer rowLayoutId, Object actionObject){
        if(object == null){
            return;
        }
        if(isLoggingEnabled()) {
            Logger.info("Binding view...");
        }
        if(view instanceof ViewGroup){
            bindViewHelper(object, view, context, rowLayoutId, actionObject);
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                bindView(object, ((ViewGroup) view).getChildAt(i), context, rowLayoutId, actionObject);
            }
        }else{
            bindViewHelper(object, view, context, rowLayoutId, actionObject);
        }
    }

    public void bindView(BasePOJO object, View view, Context context, Integer rowLayoutId){
        bindView(object, view, context, rowLayoutId, null);
    }

    public void bindView(BasePOJO object, Activity activity, Integer rowLayoutId){
        View view = activity.findViewById(android.R.id.content);

        bindView(object, view, activity.getApplicationContext(), rowLayoutId, activity);
    }

    public void bindView(BasePOJO object, View view, Context context){
        bindView(object, view, context, null, null);
    }

    public void bindView(BasePOJO object, View view, Context context, Object actionObject){
        bindView(object, view, context, null, actionObject);
    }

    public void bindView(BasePOJO object, Activity activity){
        View view = activity.findViewById(android.R.id.content);

        bindView(object, view, activity.getApplicationContext(), null, activity);
    }

    private void bindViewHelper(BasePOJO object, View view, Context context, Integer rowLayoutId, Object actionObject){

        String viewTag = (String) view.getTag();

        if(viewTag == null){
            return;
        }

        HashMap<String, String> parsed = Parser.getInstance().parse(viewTag);

        if(parsed != null) {
            String tag = parsed.get("assign");

            if (tag != null) {
                AssignmentResolver.getInstance().resolve(view, tag, object, context, rowLayoutId, actionObject);
            }

            tag = parsed.get("visible");

            if (tag != null) {
                VisibilityResolver.getInstance().resolve(view, tag, object);
            }

            tag = parsed.get("func");

            if (tag != null) {
                FunctionResolver.getInstance().resolve(view, tag, object, actionObject);
            }
        } else {
            Logger.info("Cannot parse view tag.");
        }
    }
}




Java Source Code List

com.furkanbayraktar.databinding.ViewBinder.java
com.furkanbayraktar.databinding.annotations.BindedFunction.java
com.furkanbayraktar.databinding.common.adapter.BoundListAdapter.java
com.furkanbayraktar.databinding.common.external.Expression.java
com.furkanbayraktar.databinding.common.parser.ExpressionEvaluator.java
com.furkanbayraktar.databinding.common.parser.Parser.java
com.furkanbayraktar.databinding.common.resolver.AssignmentResolver.java
com.furkanbayraktar.databinding.common.resolver.FunctionResolver.java
com.furkanbayraktar.databinding.common.resolver.PathResolver.java
com.furkanbayraktar.databinding.common.resolver.ViewResolver.java
com.furkanbayraktar.databinding.common.resolver.VisibilityResolver.java
com.furkanbayraktar.databinding.exception.FunctionException.java
com.furkanbayraktar.databinding.exception.POJOParseException.java
com.furkanbayraktar.databinding.exception.ResolverException.java
com.furkanbayraktar.databinding.exception.UnsupportedObjectException.java
com.furkanbayraktar.databinding.exception.UnsupportedSyntaxError.java
com.furkanbayraktar.databinding.exception.UnsupportedViewException.java
com.furkanbayraktar.databinding.logging.Logger.java
com.furkanbayraktar.databinding.model.BasePOJO.java
com.furkanbayraktar.databindingprivate.app.ListActivity.java
com.furkanbayraktar.databindingprivate.app.MainActivity.java
com.furkanbayraktar.databindingprivate.app.model.news.Content.java
com.furkanbayraktar.databindingprivate.app.model.news.Entry.java
com.furkanbayraktar.databindingprivate.app.model.news.Feed.java
com.furkanbayraktar.databindingprivate.app.model.news.MediaGroup.java
com.furkanbayraktar.databindingprivate.app.model.news.ResponseData.java
com.furkanbayraktar.databindingprivate.app.model.news.ResponseObject.java
com.furkanbayraktar.databindingprivate.app.model.sample.SampleObject.java
com.furkanbayraktar.databindingprivate.app.network.GsonRequest.java