<commit_before>package com.synaptian.smoketracker.habits;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.dhappy.android.widget.Timer;

import com.synaptian.smoketracker.habits.contentprovider.MyHabitContentProvider;
import com.synaptian.smoketracker.habits.database.HabitTable;
import com.synaptian.smoketracker.habits.database.GoalTable;
import com.synaptian.smoketracker.habits.database.EventTable;

import android.app.ListFragment;
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.SimpleCursorAdapter.ViewBinder;
import android.widget.TextView;


public class EventListFragment extends ListFragment
        implements LoaderManager.LoaderCallbacks<Cursor> {
	private static final int MENU_DELETE = Menu.FIRST + 1;

    // This is the Adapter being used to display the list's data.
    SimpleCursorAdapter mAdapter;

    @Override public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // Give some text to display if there is no data.  In a real
        // application this would come from a resource.
        setEmptyText("No recorded events");

        // We have a menu item to show in action bar.
        setHasOptionsMenu(true);
        
        registerForContextMenu(getListView());

        String[] from = new String[] { HabitTable.COLUMN_NAME, EventTable.COLUMN_TIME };
        int[] to = new int[] { R.id.name, R.id.time };

        mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.event_row, null, from, to, 0);

        mAdapter.setViewBinder(new ViewBinder() {
    		@Override
    		public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    			if(columnIndex == 2) { // Time
                    long time = cursor.getInt(columnIndex);

                    Calendar eventTime = Calendar.getInstance();
                    eventTime.setTimeInMillis(time * 1000);
                    
                    SimpleDateFormat timeFormat = new SimpleDateFormat("H:mm:ss");
                    
                    TextView timeView = (TextView) view;
                    timeView.setText(timeFormat.format(eventTime.getTime()));
                    return true;
    			}

    			return false;
    		}
        });

        setListAdapter(mAdapter);

        // Start out with a progress indicator.
        setListShown(false);

        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getLoaderManager().initLoader(0, null, this);
    }

    @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        MenuItem item = menu.add("New");
        item.setIcon(android.R.drawable.ic_input_add);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        item.setIntent(new Intent(getActivity(), EventDetailActivity.class));
    }

    @Override  
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {  
    	super.onCreateContextMenu(menu, v, menuInfo);  
    	menu.setHeaderTitle("Event Options");
    	menu.add(0, MENU_DELETE, 0, "Delete");
    }

    @Override  
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case MENU_DELETE:
          AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
          Uri uri = Uri.parse(MyHabitContentProvider.EVENTS_URI + "/" + info.id);
          getActivity().getContentResolver().delete(uri, null, null);
          return true;
        }
        return super.onContextItemSelected(item);
    }
    
    @Override public void onListItemClick(ListView l, View v, int position, long id) {
    }

    // These are the rows that we will retrieve.
    static final String[] EVENTS_PROJECTION = new String[] {
    	EventTable.TABLE_EVENT + "." + EventTable.COLUMN_ID,
        HabitTable.COLUMN_NAME,
        EventTable.TABLE_EVENT + "." + EventTable.COLUMN_TIME
    };

    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        // Now create and return a CursorLoader that will take care of
        // creating a Cursor for the data being displayed.<commit_msg>trying alternate menu event listener<commit_after>package com.synaptian.smoketracker.habits;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.dhappy.android.widget.Timer;

import com.synaptian.smoketracker.habits.contentprovider.MyHabitContentProvider;
import com.synaptian.smoketracker.habits.database.HabitTable;
import com.synaptian.smoketracker.habits.database.GoalTable;
import com.synaptian.smoketracker.habits.database.EventTable;

import android.app.ListFragment;
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.SimpleCursorAdapter.ViewBinder;
import android.widget.TextView;


public class EventListFragment extends ListFragment
        implements LoaderManager.LoaderCallbacks<Cursor> {
	private static final int MENU_DELETE = Menu.FIRST + 1;

    // This is the Adapter being used to display the list's data.
    SimpleCursorAdapter mAdapter;

    @Override public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // Give some text to display if there is no data.  In a real
        // application this would come from a resource.
        setEmptyText("No recorded events");

        // We have a menu item to show in action bar.
        setHasOptionsMenu(true);
        
        registerForContextMenu(getListView());
        getListView().setOnCreateContextMenuListener(this);
        
        String[] from = new String[] { HabitTable.COLUMN_NAME, EventTable.COLUMN_TIME };
        int[] to = new int[] { R.id.name, R.id.time };

        mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.event_row, null, from, to, 0);

        mAdapter.setViewBinder(new ViewBinder() {
    		@Override
    		public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    			if(columnIndex == 2) { // Time
                    long time = cursor.getInt(columnIndex);

                    Calendar eventTime = Calendar.getInstance();
                    eventTime.setTimeInMillis(time * 1000);
                    
                    SimpleDateFormat timeFormat = new SimpleDateFormat("H:mm:ss");
                    
                    TextView timeView = (TextView) view;
                    timeView.setText(timeFormat.format(eventTime.getTime()));
                    return true;
    			}

    			return false;
    		}
        });

        setListAdapter(mAdapter);

        // Start out with a progress indicator.
        setListShown(false);

        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getLoaderManager().initLoader(0, null, this);
    }

    @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        MenuItem item = menu.add("New");
        item.setIcon(android.R.drawable.ic_input_add);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        item.setIntent(new Intent(getActivity(), EventDetailActivity.class));
    }

    @Override  
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {  
    	super.onCreateContextMenu(menu, v, menuInfo);  
    	menu.setHeaderTitle("Event Options");
    	menu.add(0, MENU_DELETE, 0, "Delete");
    }

    public boolean onMenuItemSelected(int featureId, MenuItem item) {
    	Toast.makeText(getActivity(), "onMenuItemSelected", Toast.LENGTH_LONG).show();
        switch (item.getItemId()) {
        case MENU_DELETE:
          AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
          Uri uri = Uri.parse(MyHabitContentProvider.EVENTS_URI + "/" + info.id);
          Toast.makeText(getActivity(), "Deleting: " + uri, Toast.LENGTH_LONG).show();

          getActivity().getContentResolver().delete(uri, null, null);
          return true;
        }
        return super.onContextItemSelected(item);
    }
    
    @Override public void onListItemClick(ListView l, View v, int position, long id) {
    }

    // These are the rows that we will retrieve.
    static final String[] EVENTS_PROJECTION = new String[] {
    	EventTable.TABLE_EVENT + "." + EventTable.COLUMN_ID,
        HabitTable.COLUMN_NAME,
        EventTable.TABLE_EVENT + "." + EventTable.COLUMN_TIME
    };

    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        // Now create and return a CursorLoader that will take care of
        // creating a Cursor for the data being displayed.
{'fraction_non_alphanumeric': 0.09296937953263497, 'fraction_numerical': 0.00201450443190975, 'mean_word_length': 3.0742716454657364, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '676318', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2725, 'n_words': 658}