Sha256: 6efe0456db0e85a7152b8fd39f4395aa2ee0d0bb3f7e88bd74a83ffea27d774c

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

package sh.calaba.instrumentationbackend.query;

import static sh.calaba.instrumentationbackend.InstrumentationBackend.viewFetcher;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import sh.calaba.instrumentationbackend.query.ast.UIQueryEvaluator;
import sh.calaba.instrumentationbackend.query.ast.UIQueryUtils;
import android.view.View;

public class Query {

    private String queryString;
	@SuppressWarnings("rawtypes")
	private List arguments;

    public Query(String queryString) {        
        this.queryString = queryString;
        this.arguments = Collections.EMPTY_LIST;
        if (this.queryString == null || this.queryString.trim().equals("")) 
        {
        	throw new IllegalArgumentException("Illegal query: "+this.queryString);
        }
    }

    @SuppressWarnings("rawtypes")
	public Query(String queryString,List args) {
        this(queryString);
        this.arguments = args;
    }


    @SuppressWarnings({"unchecked", "rawtypes" })
	public QueryResult execute() {
        List result = new ArrayList();
        List<View> all = rootViews();
                
        List queryResults = UIQueryEvaluator.evaluateQueryWithOptions(this.queryString, all, this.arguments);
                     
        for (Object v : queryResults) {
            if (UIQueryUtils.isVisible(v)) {
            	System.out.println("Query result: "+v);
            	result.add(ViewMapper.extractDataFromView(v));
            }
            
        }
        return new QueryResult(result);
    }


    public List<View> allVisibleViews() {
        return viewFetcher.getAllViews(false);
    }

    public List<View> rootViews() {
    	Set<View> parents = new HashSet<View>(8);
    	for (View v : allVisibleViews()) 
    	{
    		parents.add(viewFetcher.getTopParent(v));
    	}
    	List<View> results = new ArrayList<View>();
    	results.addAll(parents);
    	return results;
    }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
testautoa-0.4.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java