package com.notipon;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {
    private TextView descriptionView;
    private TextView locationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String item = "Space needle, Seattle";

        Log.d("MainActivity", "Hello world!");
        setContentView(R.layout.activity_main);

        descriptionView = (TextView) findViewById(R.id.description_text);
        locationView    = (TextView) findViewById(R.id.location_text);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
        startService(new Intent(this, MainService.class));

        //DownloadImagesTask task = new DownloadImagesTask();
        //task.execute();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void onButtonClick(View view) {
        setTestFilter();
    }

    private void setTestFilter() {
        SharedPreferences settings = getSharedPreferences(MainService.PACKAGE_NAME, MODE_PRIVATE);

        Filter exampleFilter = new Filter("Clearly Comfortable Smiles", "Seattle");
        exampleFilter.setActiveFilter(settings);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

@@ -2047,16 +2047,18 @@
         
+//
 setTestF
@@ -2062,24 +2062,288 @@
 stFilter();%0A
+        SharedPreferences settings = getSharedPreferences(MainService.PACKAGE_NAME, MODE_PRIVATE);%0A        Filter exampleFilter = new Filter(descriptionView.getText().toString(), locationView.getText().toString());%0A        exampleFilter.setActiveFilter(settings);%0A
     %7D%0A%0A    p

Set the filter from TextView