Android Open Source - fco-alerts-app Country Prefs






From Project

Back to project page fco-alerts-app.

License

The source code is released under:

MIT License

If you think the Android project fco-alerts-app 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 uk.co.eleusis.android.fcoalerts;
// w ww  .java  2 s  .c o  m
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.MultiSelectListPreference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.util.Log;

public class CountryPrefs extends PreferenceFragment
{
  private final static String TAG = "PreferenceActivity";
  
  private List<String> countries;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.addPreferencesFromResource(R.xml.preferences);

        setCountries();
    }

  private void setCountries()
  {
      AsyncTask<String, Integer, List<Map<String, Object>>> requestTask = 
          new AsyncTask<String, Integer, List<Map<String, Object>>>()
      {
        @Override
        protected List<Map<String, Object>> doInBackground(String... params) 
        {
              ServerComms comms = new ServerComms();
          String content = "";
          try 
          {
            content = comms.getRequest(params[0]);
          }
          catch (IOException e) 
          {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          return comms.parseJsonList(content);
        }
        
          protected void onPostExecute(List<Map<String, Object>> countries)
          {
            List<String> countryList = new ArrayList<String>();
            for (Map<String, Object> country : countries)
            {
              countryList.add((String)country.get("name"));
            }
            
            CountryPrefs.this.countries = countryList;
              PreferenceScreen root = CountryPrefs.this.getPreferenceScreen();
              MultiSelectListPreference list =
                  (MultiSelectListPreference) root.findPreference("countries");
              list.setEntries(countryList.toArray(new String[]{}));
              list.setEntryValues(countryList.toArray(new String[]{}));
              list.setEnabled(true);
              
              Log.i(TAG, "Got country list with " + countryList.size() + " entries.");
              Log.i(TAG, "First entry is " + countryList.get(0));
          }

      };
      
      requestTask.execute("http://fcoalerts.herokuapp.com/countries.json");

  }

}




Java Source Code List

uk.co.eleusis.android.fcoalerts.Constants.java
uk.co.eleusis.android.fcoalerts.CountryPrefs.java
uk.co.eleusis.android.fcoalerts.GCMRegistration.java
uk.co.eleusis.android.fcoalerts.GcmBroadcastReceiver.java
uk.co.eleusis.android.fcoalerts.GcmIntentService.java
uk.co.eleusis.android.fcoalerts.MainActivity.java
uk.co.eleusis.android.fcoalerts.NotificationDeleteReceiver.java
uk.co.eleusis.android.fcoalerts.NotificationForwardReceiver.java
uk.co.eleusis.android.fcoalerts.NotificationStore.java
uk.co.eleusis.android.fcoalerts.NotifiedAlert.java
uk.co.eleusis.android.fcoalerts.Notifier.java
uk.co.eleusis.android.fcoalerts.RegidChangeListener.java
uk.co.eleusis.android.fcoalerts.ServerComms.java
uk.co.eleusis.android.fcoalerts.SettingsDisplay.java