// Path: sample/src/main/java/org/codeandmagic/promise/sample/Utils.java
// public static class Sample {
//     public final String title;
//     public final String subtitle;
//     public final Class<? extends Activity> activity;
// 
//     public Sample(String title, String subtitle, Class<Activity> activity) {
//         this.title = title;
//         this.subtitle = subtitle;
//         this.activity = activity;
//     }
// }
// 
// Path: sample/src/main/java/org/codeandmagic/promise/sample/Utils.java
// public static List<Sample> parseSamples(Resources resources) {
//     BufferedReader reader = null;
//     try {
//         reader = new BufferedReader(new InputStreamReader(resources.openRawResource(R.raw.samples)));
//         final StringBuilder json = new StringBuilder();
// 
//         String line;
//         while ((line = reader.readLine()) != null) {
//             json.append(line);
//         }
//         final List<Sample> samples = new ArrayList<Sample>();
//         final JSONArray array = new JSONArray(json.toString());
//         final int length = array.length();
//         for (int i = 0; i < length; ++i) {
//             samples.add(parseSample(array.getJSONObject(i)));
//         }
//         return samples;
// 
//     } catch (Exception e) {
//         Log.e("PROMISE", "Can't parse the samples!", e);
//         return Collections.emptyList();
//     } finally {
//         if (reader != null) {
//             try {
//                 reader.close();
//             } catch (IOException e) {
//                 e.printStackTrace();
//             }
//         }
//     }
// }


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TwoLineListItem;
import java.util.List;
import static org.codeandmagic.promise.sample.Utils.Sample;
import static org.codeandmagic.promise.sample.Utils.parseSamples;
package org.codeandmagic.promise.sample;




/**
 * Created by evelina on 05/03/2014.
 */
public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        final ListView listView = (ListView) findViewById(android.R.id.list);
        listView.setAdapter(new DemoAdapter(this, parseSamples(getResources())));
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Path: sample/src/main/java/org/codeandmagic/promise/sample/Utils.java
// public static class Sample {
//     public final String title;
//     public final String subtitle;
//     public final Class<? extends Activity> activity;
// 
//     public Sample(String title, String subtitle, Class<Activity> activity) {
//         this.title = title;
//         this.subtitle = subtitle;
//         this.activity = activity;
//     }
// }
// 
// Path: sample/src/main/java/org/codeandmagic/promise/sample/Utils.java
// public static List<Sample> parseSamples(Resources resources) {
//     BufferedReader reader = null;
//     try {
//         reader = new BufferedReader(new InputStreamReader(resources.openRawResource(R.raw.samples)));
//         final StringBuilder json = new StringBuilder();
// 
//         String line;
//         while ((line = reader.readLine()) != null) {
//             json.append(line);
//         }
//         final List<Sample> samples = new ArrayList<Sample>();
//         final JSONArray array = new JSONArray(json.toString());
//         final int length = array.length();
//         for (int i = 0; i < length; ++i) {
//             samples.add(parseSample(array.getJSONObject(i)));
//         }
//         return samples;
// 
//     } catch (Exception e) {
//         Log.e("PROMISE", "Can't parse the samples!", e);
//         return Collections.emptyList();
//     } finally {
//         if (reader != null) {
//             try {
//                 reader.close();
//             } catch (IOException e) {
//                 e.printStackTrace();
//             }
//         }
//     }
// }


// Path: sample/src/main/java/org/codeandmagic/promise/sample/MainActivity.java
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TwoLineListItem;
import java.util.List;
import static org.codeandmagic.promise.sample.Utils.Sample;
import static org.codeandmagic.promise.sample.Utils.parseSamples;

package org.codeandmagic.promise.sample;




/**
 * Created by evelina on 05/03/2014.
 */
public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        final ListView listView = (ListView) findViewById(android.R.id.list);
        listView.setAdapter(new DemoAdapter(this, parseSamples(getResources())));
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(MainActivity.this, ((Sample) parent.getItemAtPosition(position)).activity));