Android Open Source - android-grid-image-search Search Query






From Project

Back to project page android-grid-image-search.

License

The source code is released under:

MIT License

If you think the Android project android-grid-image-search 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.gemmakbarlow.gridimagesearch.model;
//from   w w w. ja v  a 2 s  .c o  m
import java.io.Serializable;

import android.net.Uri;
import android.util.Log;


public class SearchQuery implements Serializable {

  private static final long serialVersionUID = -1047055296751064250L;

  private String imageTypeValue;
  private String imageSizeValue;
  private String imageColorValue;
  private String baseQueryUrl;
  private String queryText;
  private int currentPageStartIndex = 0;
  private int resultsPerPage = 8;
  
  private static final String SEARCH_QUERY_LOG_TAG = "SearchQuery";
  
  
  public String getQueryText() {
    return queryText;
  }

  public void setQueryText(String queryText) {
    this.queryText = queryText;
  }

  /* Getters & Setters */
  public String getImageTypeValue() {
    return imageTypeValue;
  }

  public void setImageTypeValue(String imageTypeValue) {
    this.imageTypeValue = imageTypeValue;
  }
  
  // imgtype=face
  protected String getImageTypeParamString() {
    return createParamString("&imgtype=", this.getImageTypeValue());
  }



  public String getImageSizeValue() {
    return imageSizeValue;
  }

  public void setImageSizeValue(String imageSizeValue) {
    this.imageSizeValue = imageSizeValue;
  }
  
  //imgsz=xlarge
  protected String getImageSizeParamString() {
    return createParamString("&imgsz=", this.getImageSizeValue());
  }


  
  public String getImageColorValue() {
    return imageColorValue;
  }

  public void setImageColorValue(String imageColorValue) {
    this.imageColorValue = imageColorValue;
  }
  
  //imgcolor=gray
  protected String getImageColorParamString() {
    return createParamString("&imgcolor=", this.getImageColorValue());
  }


  public String getBaseQueryUrl() {
    return baseQueryUrl;
  }

  // NB - Assumes a validated URL coming in. 
  public void setBaseQueryUrl(String baseQueryUrl) {
    this.baseQueryUrl = baseQueryUrl;
  }

  // as_sitesearch=photobucket.com
  protected String getBaseQueryUrlParamString() {
    return createParamString("&as_sitesearch=", this.getBaseQueryUrl());
  }
  
  
  /* Final Query */
  
  public String getQueryUrl() {
    
    String finalQuery = 
        this.getMinimalQuery() +
        this.getImageTypeParamString() + 
        this.getImageSizeParamString() + 
        this.getImageColorParamString() +
        this.getBaseQueryUrlParamString();
    
    Log.d(SEARCH_QUERY_LOG_TAG, finalQuery);
    
    return finalQuery;
  }
  
  protected String getMinimalQuery() {
    return "https://ajax.googleapis.com/ajax/services/search/images?" +
                "rsz=" + this.getResultsPerPage() + "&start=" + this.getCurrentPageStartIndex() + "&v=1.0&q=" + Uri.encode(this.getQueryText());
  }
  
  
  /* Other */
  
  protected String createParamString(String paramPrefix, String queryValue) {
    String finalParamString = "";
    
    if(queryValue!=null && queryValue.trim().length() > 0) {
      finalParamString = paramPrefix + Uri.encode(queryValue.trim());
    }
    return finalParamString;
  }
  
  public String toString() {
    return this.getQueryUrl();
  }

  public int getCurrentPageStartIndex() {
    return currentPageStartIndex;
  }

  public void setCurrentPageStartIndex(int currentPageStartIndex) {
    this.currentPageStartIndex = currentPageStartIndex;
  }

  public int getResultsPerPage() {
    return resultsPerPage;
  }

  public void setResultsPerPage(int resultsPerPage) {
    this.resultsPerPage = resultsPerPage;
  }

  
}




Java Source Code List

com.gemmakbarlow.gridimagesearch.AdvancedFilterActivity.java
com.gemmakbarlow.gridimagesearch.EndlessScrollListener.java
com.gemmakbarlow.gridimagesearch.ImageDisplayActivity.java
com.gemmakbarlow.gridimagesearch.ImageResultArrayAdapter.java
com.gemmakbarlow.gridimagesearch.SearchActivity.java
com.gemmakbarlow.gridimagesearch.model.ImageResult.java
com.gemmakbarlow.gridimagesearch.model.SearchQuery.java