Android Open Source - Android-Project-Manager Spinner Util






From Project

Back to project page Android-Project-Manager.

License

The source code is released under:

GNU General Public License

If you think the Android project Android-Project-Manager 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.vaquerosisd.utils;
/* w  ww.j a  v  a2 s  . c o  m*/
import java.util.ArrayList;
import java.util.Collections;

import com.vaquerosisd.dialog.CustomStatus;

import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;

public class SpinnerUtil {
  
  public static ArrayAdapter<CharSequence> setSpinnerAdapter(Context context, String spinnerFileName, Spinner spinnerObject, boolean sort) {
    FileOperations fO = new FileOperations(context);
    String spinnerItems = fO.readFile(spinnerFileName);
    ArrayList<String> spinnerItemsArray = fO.convertToStringList(spinnerItems);
    if(sort)
      Collections.sort(spinnerItemsArray.subList(0, spinnerItemsArray.size()));
    
    //Set the adapter for the status spinner 
    final ArrayAdapter<CharSequence> spinnerAdapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerAdapter.addAll(spinnerItemsArray);
    spinnerObject.setAdapter(spinnerAdapter);
    
    return spinnerAdapter;
  }
  
  public static ArrayAdapter<CharSequence> setCustomSpinnerAdapter (final Context context, final Fragment fragment, 
      final FragmentManager fragmentManager, String spinnerFileName, Spinner spinner, boolean sort) {
    FileOperations fO = new FileOperations(context);
    
    String spinnerItems = fO.readFile(spinnerFileName);
    ArrayList<String> spinnerItemsArray = fO.convertToStringList(spinnerItems);
    if(sort)
      Collections.sort(spinnerItemsArray.subList(0, spinnerItemsArray.size()));
    spinnerItemsArray.add("Custom...");
    
    //Set the adapter for the status spinner 
    final ArrayAdapter<CharSequence> spinnerAdapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerAdapter.addAll(spinnerItemsArray);
    spinner.setAdapter(spinnerAdapter);
    
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        if( "Custom...".equals((String) spinnerAdapter.getItem(position))) {
          DialogFragment customStatusDialog = new CustomStatus();
          customStatusDialog.setTargetFragment(fragment, 0);
          customStatusDialog.show(fragmentManager, "Custom Status Dialog");
        }
      }
      @Override
      public void onNothingSelected(AdapterView<?> arg0) { }
    });
    
    return spinnerAdapter;
  }
  
  public static void addStatusOption(Context context, String spinnerFileName, String statusOption, 
      ArrayAdapter<CharSequence> spinnerAdapter, Spinner spinner){
    FileOperations fO = new FileOperations(context);
    fO.appendText(spinnerFileName, statusOption + "\n");
    String statusOptions = fO.readFile(spinnerFileName);
    ArrayList<String> statusOptionsArray = fO.convertToStringList(statusOptions);
    Collections.sort(statusOptionsArray.subList(0, statusOptionsArray.size()));
    statusOptionsArray.add("Custom...");
    spinnerAdapter.clear();
    spinnerAdapter.addAll(statusOptionsArray);
    spinnerAdapter.notifyDataSetChanged();
    
    int statusPosition = spinnerAdapter.getPosition(statusOption);
    spinner.setSelection(statusPosition, true);
  }

}




Java Source Code List

com.vaquerosisd.adapters.ProjectListViewAdapter.java
com.vaquerosisd.adapters.TaskListViewAdapter.java
com.vaquerosisd.adapters.VideoNoteGridViewAdapter.java
com.vaquerosisd.adapters.VoiceNoteGridViewAdapter.java
com.vaquerosisd.database.DatabaseHelper.java
com.vaquerosisd.database.ProjectOperations.java
com.vaquerosisd.dialog.CustomStatus.java
com.vaquerosisd.dialog.DatePickerFragment.java
com.vaquerosisd.dialog.DeleteDialog.java
com.vaquerosisd.dialog.DeletePhotoDialog.java
com.vaquerosisd.dialog.DeleteTaskDialog.java
com.vaquerosisd.dialog.EditProject.java
com.vaquerosisd.fragments.TaskDescriptionFragment.java
com.vaquerosisd.fragments.VideoNotesFragment.java
com.vaquerosisd.fragments.VoiceNotesFragment.java
com.vaquerosisd.object.JsonWrapper.java
com.vaquerosisd.object.PhotoRef.java
com.vaquerosisd.object.Project.java
com.vaquerosisd.object.Task.java
com.vaquerosisd.object.User.java
com.vaquerosisd.object.WebServiceManager.java
com.vaquerosisd.projectmanager.About.java
com.vaquerosisd.projectmanager.ContentTask.java
com.vaquerosisd.projectmanager.Login.java
com.vaquerosisd.projectmanager.MainActivity.java
com.vaquerosisd.projectmanager.NewAccount.java
com.vaquerosisd.projectmanager.NewProject.java
com.vaquerosisd.projectmanager.NewTask.java
com.vaquerosisd.projectmanager.OnSwipeListener.java
com.vaquerosisd.projectmanager.PhotoManager.java
com.vaquerosisd.projectmanager.ProjectList.java
com.vaquerosisd.projectmanager.TaskList.java
com.vaquerosisd.projectmanager.WebserviceCallback.java
com.vaquerosisd.utils.FileOperations.java
com.vaquerosisd.utils.OnSwipeListener.java
com.vaquerosisd.utils.SpinnerUtil.java
com.vaquerosisd.utils.TabListener.java