package info.wncoutdoors.northcarolinawaterfalls;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;

import com.actionbarsherlock.app.SherlockFragment;

public class SearchLocationFragment extends SherlockFragment implements OnClickListener{
    
    private final String TAG = "SearchHikeFragment";
    
    private Spinner locationDistanceSpinner;
    private Spinner locationReltoSpinner;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View locationSearchFragmentView = inflater.inflate(R.layout.fragment_location_search, container, false);
        setupSpinners(locationSearchFragmentView);
        
        // Up-set the Find button.
        Button b = (Button) locationSearchFragmentView.findViewById(R.id.search_location_find_button);
        b.setOnClickListener(this);
        
        return locationSearchFragmentView;
    }
    
    private void setupSpinners(View view){
        locationDistanceSpinner = (Spinner) view.findViewById(R.id.search_location_distance_spinner);
        ArrayAdapter<CharSequence> locationDistanceAdapter = ArrayAdapter.createFromResource(getActivity(),
                R.array.location_distance_options, android.R.layout.simple_spinner_item);
        locationDistanceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        locationDistanceSpinner.setAdapter(locationDistanceAdapter);
        
        locationReltoSpinner = (Spinner) view.findViewById(R.id.search_location_relto_spinner);
        ArrayAdapter<CharSequence> locationReltoAdapter = ArrayAdapter.createFromResource(getActivity(),
                R.array.location_relto_options, android.R.layout.simple_spinner_item);
        locationReltoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        locationReltoSpinner.setAdapter(locationReltoAdapter);

    }
    
    @Override
    public void onClick(View button) {
        switch (button.getId()) {
        case R.id.search_location_find_button:
            Log.d(TAG, "Button clicked: " + button.toString());
            
            // TODO: Collapse these
            // Get the text of the selected item in the Within (Distance) spinner
            Spinner locationDistanceSpinner =
                 (Spinner) getView().findViewById(R.id.search_location_distance_spinner);
            String distanceSelected = locationDistanceSpinner.getSelectedItem().toString();
            
            // Get the text of the selected item in the Of (Relto) spinner
            Spinner locationReltoSpinner =
                 (Spinner) getView().findViewById(R.id.search_location_relto_spinner);
            String reltoSelected = locationReltoSpinner.getSelectedItem().toString();

            // Get the text of the entry below Relto spinner
            EditText searchLocationReltoTextbox =
                 (EditText) getView().findViewById(R.id.search_location_relto_txt);
            String locationSearched = searchLocationReltoTextbox.getText().toString();
            
            // Get the state of the "Only falls I've Shared" checkbox
            CheckBox searchLocationSharedCheckbox =
                    (CheckBox) getView().findViewById(R.id.search_location_shared_checkbox);
            boolean isChecked = searchLocationSharedCheckbox.isChecked();
                       
            Log.d(TAG, "Button wuz clicked");
            Log.d(TAG, "Within: " + distanceSelected );
            Log.d(TAG, "Of: " + reltoSelected );
            Log.d(TAG, "Which is: " + locationSearched );
            Log.d(TAG, "Only shared: " + String.valueOf(isChecked));
            break;
        }
    }
    
}

@@ -70,16 +70,47 @@
 Bundle;%0A
+import android.text.InputType;%0A
 import a
@@ -126,16 +126,16 @@
 il.Log;%0A
-
 import a
@@ -257,24 +257,117 @@
 ckListener;%0A
+import android.widget.AdapterView;%0Aimport android.widget.AdapterView.OnItemSelectedListener;%0A
 import andro
@@ -2313,17 +2313,1902 @@
 apter);%0A
+        locationReltoSpinner.setOnItemSelectedListener(new SpinnerSelectionListener());%0A    %7D%0A    %0A    class SpinnerSelectionListener implements OnItemSelectedListener %7B%0A        // Listener for the Relto spinner to modify the EditText control appropriately%0A        public void onItemSelected(AdapterView%3C?%3E parent, View view, int pos, long id)%7B%0A            // An item was selected%0A            EditText searchLocationReltoTextbox =%0A                (EditText) getView().findViewById(R.id.search_location_relto_txt);%0A            String reltoSelected = parent.getItemAtPosition(pos).toString();%0A            Log.d(TAG, %22Relto spinner item selected: %22 + reltoSelected);%0A            searchLocationReltoTextbox.setText(%22%22);%0A            searchLocationReltoTextbox.setEnabled(true);%0A            searchLocationReltoTextbox.setFocusable(true);%0A            searchLocationReltoTextbox.setFocusableInTouchMode(true); // Because just focus isn't enough%0A            %0A            if(reltoSelected.equals(%22Current Location%22))%7B%0A                // Disable it%0A                searchLocationReltoTextbox.setInputType(InputType.TYPE_NULL);%0A                searchLocationReltoTextbox.setEnabled(false);%0A                searchLocationReltoTextbox.setFocusable(false);%0A            %7D else if(reltoSelected.equals(%22Address%22)) %7B%0A                searchLocationReltoTextbox.setInputType(InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);%0A            %7D else if(reltoSelected.equals(%22City%22)) %7B%0A                searchLocationReltoTextbox.setInputType(InputType.TYPE_CLASS_TEXT);%0A            %7D else if(reltoSelected.equals(%22Zip%22)) %7B%0A                searchLocationReltoTextbox.setInputType(InputType.TYPE_CLASS_NUMBER);%0A            %7D%0A        %7D%0A        %0A        public void onNothingSelected(AdapterView%3C?%3E parent)%7B%0A            // Another interface callback%0A            Log.d(TAG, %22Somehow, nothing was selected...%22);%0A        %7D
 %0A
-
     %7D%0A  
@@ -5668,27 +5668,16 @@
         
-           
 %0A       

Change EditText behavior based on relto spinner