Android Open Source - Android-Data-Binding Visibility 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;
//from w ww.  j  a  v  a  2 s  .c  o m
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 VisibilityResolver {

    private static VisibilityResolver instance;

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

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

    public void resolve(View view, String tag, BasePOJO object){

        try {
            Logger.info("Resolving views for visibility...");

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

            if (result != null) {
                if (result.equals(new BigDecimal(0))) {
                    view.setVisibility(View.GONE);
                } else if (result.equals(new BigDecimal(1))) {
                    view.setVisibility(View.VISIBLE);
                } else {
                    throw new ResolverException("Expected results are 0 or 1. Found: " + result);
                }
            } else {
                ResolverException ex = new ResolverException("Cannot evaluate expression.");
                Logger.error("Cannot evaluate expression.", ex);
            }

            Logger.info("Views resolved successfully.");
        } 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