<commit_before>package com.jiahaoliuliu.spinnerwithtwoitems;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
import android.widget.Spinner;


/**
 * Demo using the built-in Android
 * <a href="http://developer.android.com/reference/android/R.layout.html#simple_list_item_2">
 * android.R.layout.simple_list_item_2</a> to display an
 * array of Java enum entries in the UI.
 * <p />
 * The demo displays a list of the original US 13 colonies and its state abbreviation,
 * in order of statehood.
 * <p />
 *  The basic technical steps are
 * <ol>
 * <li>Create class extending
 * <a href="http://developer.android.com/reference/android/app/ListActivity.html">ListActivity</a></li>
 * <li>Obtain data as a array of enum entries</li>
 * <li>Create a
 * <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>
 * that connects the array of enum entries to simple_list_item2</li>
 * <li>Bind the ListAdapter using the
 * <a href="http://developer.android.com/reference/android/app/ListActivity.html#setListAdapter(android.widget.ListAdapter)">ListActivity.setListAdapter</a> method</li>
 * </ol>
 *
 * Based on the example of Jirawat Uttayaya about the list view with two items
 * 		<a href="http://www.javajirawat.com/2013/03/android-listview-tutorial_12.html">Link</a>
 * @author <NAME> <a href="mailto:<EMAIL>"><EMAIL></a>
 * @version 1.0
 * @since 1.0
 *
 */
public class MainActivity extends Activity {
	/**
	 * The key in the SimpleAdapter Map<String, String> to map to
	 * <a href="http://developer.android.com/reference/android/R.id.html#text1">android.R.id.text1</a>.
	 */
	private static final String TEXT1 = "text1";
	/**
	 * The key in the SimpleAdapter Map<String, String> to map to
	 * <a href="http://developer.android.com/reference/android/R.id.html#text2">android.R.id.text2</a>.
	 */
	private static final String TEXT2 = "text2";

	/**
	 * The locale of the device. This allow to display the countries according to the
	 * language of the device.
	 */
	private Locale locale;

    /**
     * This overridden method initializes the ListActivity.
     * After calling the parent onCreate method, it binds the ListAdapter to the
     * ListActivity via setListAdapter method.
     *
     * @param savedInstanceState If the activity is being re-initialized
     * after previously being shut down then this Bundle contains the data
     * it most recently supplied in
     * {@link android.app.Activity#onSaveInstanceState(Bundle)}.
     * <b>Note: Otherwise it is null.</b>
     */
	@Override
	protected final void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		locale = getResources().getConfiguration().locale;

		final PhonePrefixes[] phonePrefixes = PhonePrefixes.values();
		final SimpleAdapter simpleAdpater = createSimpleAdapter(phonePrefixes);
		
		setContentView(R.layout.activity_main);
		Spinner simpleSpinner = (Spinner)findViewById(R.id.SimpleSpinner);
		
		simpleSpinner.setAdapter(simpleAdpater);
	}

	/**
     * A <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>
     * implements the interface <a href="http://developer.android.com/reference/android/widget/SpinnerAdapter.html">
     * SpinnerAdapter</a> which is used by <a href="http://developer.android.com/reference/android/widget/Spinner.html">
     * the spinner</a>
     * Note: This example also works if we replace the array of enum entries parameter
     * with an array or
     * <a href="http://docs.oracle.com/javase/6/docs/api/java/util/List.html">List</a>
     * of JavaBeans.
	 * @since 1.0
	 *
	 * @param states An array of {@link PhonePrefixes} enum entries
	 * @return A <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>
	 * using the
	 * <a href="http://developer.android.com/reference/android/R.layout.html#simple_list_item_2">simple_list_item_2</a>
	 * layout to display an array of enum entries
	 */
	private SimpleAdapter createSimpleAdapter(final PhonePrefixes[] phonePrefixes) {
		final String[] fromMapKey = new String[] {TEXT1, TEXT2};
		final int[] toLayoutId = new int[] {android.R.id.text1, android.R.id.text2};
		final List<Map<String, String>> list = convertToListItems(phonePrefixes);

		SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
				android.R.layout.simple_list_item_1, fromMapKey, toLayoutId);
		
		// Remove the follow line to 
		simpleAdapter.setDropDownViewResource(android.R.layout.simple_expandable_list_item_2);
		return simpleAdapter;
	}

	/**
	 * Convert an array of {@link PhonePrefixes} into a List of Map<String, String>.
	 * The List of Map<String, String> will be used as part of the constructor for
	 * a <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>.
	 * <p />
	 * Each element in the List will correspond to a entry in the Android UI list.<commit_msg>Set a different view (one line) for the normal view<commit_after>package com.jiahaoliuliu.spinnerwithtwoitems;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
import android.widget.Spinner;


/**
 * Demo using the built-in Android
 * <a href="http://developer.android.com/reference/android/R.layout.html#simple_list_item_2">
 * android.R.layout.simple_list_item_2</a> to display an
 * array of Java enum entries in the UI.
 * <p />
 * The demo displays a list of the original US 13 colonies and its state abbreviation,
 * in order of statehood.
 * <p />
 *  The basic technical steps are
 * <ol>
 * <li>Create class extending
 * <a href="http://developer.android.com/reference/android/app/ListActivity.html">ListActivity</a></li>
 * <li>Obtain data as a array of enum entries</li>
 * <li>Create a
 * <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>
 * that connects the array of enum entries to simple_list_item2</li>
 * <li>Bind the ListAdapter using the
 * <a href="http://developer.android.com/reference/android/app/ListActivity.html#setListAdapter(android.widget.ListAdapter)">ListActivity.setListAdapter</a> method</li>
 * </ol>
 *
 * Based on the example of Jirawat Uttayaya about the list view with two items
 * 		<a href="http://www.javajirawat.com/2013/03/android-listview-tutorial_12.html">Link</a>
 * @author <NAME> <a href="mailto:<EMAIL>"><EMAIL></a>
 * @version 1.0
 * @since 1.0
 *
 */
public class MainActivity extends Activity {
	/**
	 * The key in the SimpleAdapter Map<String, String> to map to
	 * <a href="http://developer.android.com/reference/android/R.id.html#text1">android.R.id.text1</a>.
	 */
	private static final String TEXT1 = "text1";
	/**
	 * The key in the SimpleAdapter Map<String, String> to map to
	 * <a href="http://developer.android.com/reference/android/R.id.html#text2">android.R.id.text2</a>.
	 */
	private static final String TEXT2 = "text2";

	/**
	 * The locale of the device. This allow to display the countries according to the
	 * language of the device.
	 */
	private Locale locale;

    /**
     * This overridden method initializes the ListActivity.
     * After calling the parent onCreate method, it binds the ListAdapter to the
     * ListActivity via setListAdapter method.
     *
     * @param savedInstanceState If the activity is being re-initialized
     * after previously being shut down then this Bundle contains the data
     * it most recently supplied in
     * {@link android.app.Activity#onSaveInstanceState(Bundle)}.
     * <b>Note: Otherwise it is null.</b>
     */
	@Override
	protected final void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		locale = getResources().getConfiguration().locale;

		final PhonePrefixes[] phonePrefixes = PhonePrefixes.values();
		final SimpleAdapter simpleAdpater = createSimpleAdapter(phonePrefixes);
		
		setContentView(R.layout.activity_main);
		Spinner simpleSpinner = (Spinner)findViewById(R.id.SimpleSpinner);
		
		simpleSpinner.setAdapter(simpleAdpater);
	}

	/**
     * A <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>
     * implements the interface <a href="http://developer.android.com/reference/android/widget/SpinnerAdapter.html">
     * SpinnerAdapter</a> which is used by <a href="http://developer.android.com/reference/android/widget/Spinner.html">
     * the spinner</a>
     * Note: This example also works if we replace the array of enum entries parameter
     * with an array or
     * <a href="http://docs.oracle.com/javase/6/docs/api/java/util/List.html">List</a>
     * of JavaBeans.
	 * @since 1.0
	 *
	 * @param states An array of {@link PhonePrefixes} enum entries
	 * @return A <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>
	 * using the
	 * <a href="http://developer.android.com/reference/android/R.layout.html#simple_list_item_2">simple_list_item_2</a>
	 * layout to display an array of enum entries
	 */
	private SimpleAdapter createSimpleAdapter(final PhonePrefixes[] phonePrefixes) {
		final String[] fromMapKey = new String[] {TEXT1, TEXT2};
		final int[] toLayoutId = new int[] {android.R.id.text1, android.R.id.text2};
		final List<Map<String, String>> list = convertToListItems(phonePrefixes);

		SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
				android.R.layout.simple_list_item_1, fromMapKey, toLayoutId);
		
		// Remove the follow line to have the same view as dropdown view
		simpleAdapter.setDropDownViewResource(android.R.layout.simple_expandable_list_item_2);
		return simpleAdapter;
	}

	/**
	 * Convert an array of {@link PhonePrefixes} into a List of Map<String, String>.
	 * The List of Map<String, String> will be used as part of the constructor for
	 * a <a href="http://developer.android.com/reference/android/widget/SimpleAdapter.html">SimpleAdapter</a>.
	 * <p />
	 * Each element in the List will correspond to a entry in the Android UI list.
{'fraction_non_alphanumeric': 0.12194414919315875, 'fraction_numerical': 0.006957193931780848, 'mean_word_length': 4.201005025125628, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4151335', 'n_tokens_mistral': 3262, 'n_tokens_neox': 3069, 'n_words': 847}