Android Open Source - Android-Data-Binding Assignment Resolver






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.common.resolver;
/*w  w  w. j a v  a2 s  .  c o m*/
import android.content.Context;
import android.view.View;
import com.furkanbayraktar.databinding.common.parser.ExpressionEvaluator;
import com.furkanbayraktar.databinding.exception.ResolverException;
import com.furkanbayraktar.databinding.logging.Logger;
import com.furkanbayraktar.databinding.model.BasePOJO;

import java.math.BigDecimal;

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

    private static AssignmentResolver instance;

    private AssignmentResolver(){
        Logger.info("AssignmentResolver object created.");
    }

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

    public void resolve(View view, String tag, BasePOJO object, Context context, Integer rowLayoutId, Object actionObject){

        try {
            Logger.info("Resolving assignments for tag: " + tag);

            if (tag.contains("(")) {
                Logger.info("Assignment contains expression. Evaluating expression...");

                BigDecimal result = ExpressionEvaluator.getInstance().evaluate(tag, object);

                if (result != null) {
                    if (result.equals(new BigDecimal(0))) {
                        ViewResolver.getInstance().resolve(view, "0", context, rowLayoutId, actionObject);
                    } else if (result.equals(new BigDecimal(1))) {
                        ViewResolver.getInstance().resolve(view, "1", context, rowLayoutId, actionObject);
                    } else {
                        ResolverException ex = new ResolverException("Expected results are 0 or 1. Found: " + result);
                        Logger.error("Unexpected result.", ex);
                    }
                } else {
                    ResolverException ex = new ResolverException("Cannot evaluate expression.");
                    Logger.error("Unsupported expression syntax.", ex);
                }

                Logger.info("Evaluation completed.");
            } else {
                Object value = PathResolver.getInstance().resolve(tag, object);

                if (value == null) {
                    ResolverException ex = new ResolverException();
                    Logger.warn("Cannot resolve value for tag:" + tag, ex);
                }

                Logger.info("Value corresponding to given tag has been found. Assigning to view...");

                ViewResolver.getInstance().resolve(view, value, context, rowLayoutId, actionObject);

                Logger.info("View assignment completed.");
            }
        } catch (Exception ex){
            Logger.error("Unexpected error.", ex);
        }
    }

}




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