Android Open Source - android_google_image_searcher Settings Activity






From Project

Back to project page android_google_image_searcher.

License

The source code is released under:

GNU General Public License

If you think the Android project android_google_image_searcher 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.github.snambi.googleimagesearcher;
/*from  w w  w .j a  v a 2s . c  o  m*/
import android.R.anim;
import android.app.Activity;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

public class SettingsActivity extends Activity {
  
  public static final String COLOR="COLOR";
  public static final String TYPE="TYPE";
  public static final String SIZE="SIZE";
  public static final String SITE="SITE";

  private EditText etSite=null;
  private Spinner spnColorFilter=null;
  private Spinner spnImageFilter=null;
  private Spinner spnImageSize=null;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    
    spnColorFilter = (Spinner) findViewById(R.id.spnColorFilter);
    spnImageFilter = (Spinner) findViewById(R.id.spnImageFilter);
    spnImageSize = (Spinner) findViewById(R.id.spnImageSize);
    etSite = (EditText) findViewById(R.id.etSiteFilter);
    
    String[] colors = getResources().getStringArray(R.array.color_values);
    
    // get the inputs from "Search" screen
    String color = getIntent().getStringExtra(COLOR);
    String type = getIntent().getStringExtra(TYPE);
    String size = getIntent().getStringExtra(SIZE);
    String site = getIntent().getStringExtra(SITE);
    
    //create Adapter
    ArrayAdapter<CharSequence> colorAdapter = ArrayAdapter.createFromResource(this, R.array.color_values, R.layout.spinner_text_view);
    colorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    spnColorFilter.setAdapter(colorAdapter);
    
    ArrayAdapter<CharSequence> typeAdapter = ArrayAdapter.createFromResource(this, R.array.image_types, R.layout.spinner_text_view);
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    spnImageFilter.setAdapter(typeAdapter);
    
    ArrayAdapter<CharSequence> sizeAdapter = ArrayAdapter.createFromResource(this, R.array.image_sizes, R.layout.spinner_text_view);
    sizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    spnImageSize.setAdapter(sizeAdapter);
    
    // 
    setSelectedItem(color, spnColorFilter);
    setSelectedItem(type, spnImageFilter);
    setSelectedItem(size, spnImageSize);
    
    if( site != null && !site.trim().equals("")){
      etSite.setText(site);
    }
  }
  
  public static void setSelectedItem( String value, Spinner spinner){
    if( value != null && !value.trim().equals("") ){
      for( int i=0; i<spinner.getCount() ; i++ ){
        String item = (String) spinner.getItemAtPosition(i);
        if( item.equals(value)){
          spinner.setSelection(i);
          break;
        }
      }
    }
  }
  
  public void onClick( View view){
    
    String colorFilter = (String) spnColorFilter.getSelectedItem();
    String imageFilter = (String) spnImageFilter.getSelectedItem();
    String imageSize = (String) spnImageSize.getSelectedItem();
    String site = etSite.getText().toString();
    
    Intent intent = new Intent();
    
    intent.putExtra( COLOR, colorFilter);
    intent.putExtra( TYPE, imageFilter);
    intent.putExtra( SIZE, imageSize);
    intent.putExtra( SITE, site);
    
    setResult(RESULT_OK, intent);
    finish();
  }
}




Java Source Code List

com.github.snambi.googleimagesearcher.AndroidUtils.java
com.github.snambi.googleimagesearcher.EndlessScrollListener.java
com.github.snambi.googleimagesearcher.FullScreenActivity.java
com.github.snambi.googleimagesearcher.GoogleImageAdapter.java
com.github.snambi.googleimagesearcher.GoogleImageClient.java
com.github.snambi.googleimagesearcher.ImageUtil.java
com.github.snambi.googleimagesearcher.Image.java
com.github.snambi.googleimagesearcher.SearchActivity.java
com.github.snambi.googleimagesearcher.SettingsActivity.java
com.github.snambi.googleimagesearcher.SettingsDialog.java
com.github.snambi.googleimagesearcher.SettingsFragmentActivity.java
com.github.snambi.googleimagesearcher.SquareImage.java