<commit_before>package org.sana.android.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AlphabetIndexer;
import android.widget.SectionIndexer;
import android.widget.TextView;

import org.sana.R;
import org.sana.android.Constants;
import org.sana.android.app.Locales;
import org.sana.android.app.Preferences;
import org.sana.android.content.Intents;
import org.sana.android.provider.AmbulanceDrivers;
import org.sana.android.widget.ScrollCompleteListener;
import org.sana.util.StringUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;

/**
 * A placeholder fragment containing a simple view.
 */
public class AmbulanceDriverListFragment extends ListFragment implements
        LoaderManager.LoaderCallbacks<Cursor>, AdapterView.OnItemClickListener {
    public static final String TAG = AmbulanceDriverListFragment.class.getName();

    static final String[] mProjection = new String[] {
            AmbulanceDrivers.Contract._ID,
            AmbulanceDrivers.Contract.FIRST_NAME,
            AmbulanceDrivers.Contract.LAST_NAME,
            AmbulanceDrivers.Contract.PHONE_NUMBER
    };
    private Uri mUri;
    private AmbulanceDriverCursorAdapter mAdapter;
    private OnDriverSelectedListener mListener;
    private int delta =1000*60;
    public static ArrayList<String> data = new ArrayList<String>();

    public AmbulanceDriverListFragment() {

    }

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

        mUri = getActivity().getIntent().getData();
        if (mUri == null) {
            mUri = AmbulanceDrivers.CONTENT_URI;
        }
        // initialize fields that depend on the Activity Context
        // i.e. the Adapter

        mAdapter = new AmbulanceDriverCursorAdapter(getActivity(), null, 0);
        setListAdapter(mAdapter);

        LoaderManager.enableDebugLogging(true);
        getActivity().getSupportLoaderManager().initLoader(2, null, this);
        // set the list item click listener
        getListView().setOnItemClickListener(this);
    }

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

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        CursorLoader loader = new CursorLoader(getActivity(),
                mUri,
                mProjection,
                null, null, AmbulanceDrivers.FIRST_NAME_SORT_ORDER);
        return loader;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        if (cursor == null || (cursor !=null && cursor.getCount() == 0)) {
            setEmptyText(getString(R.string.msg_drivers_vht));
        }
        if(cursor != null){
            //mAdapter.swapCursor(cursor);
            ((AmbulanceDriverCursorAdapter) this.getListAdapter()).swapCursor(cursor);
        }

    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {

        ((AmbulanceDriverCursorAdapter) this.getListAdapter()).swapCursor(null);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // Implement click to call functionality
        Object number = view.getTag();
        if(number != null){
            // TODO Should probably check that number is valid pattern
            Intent intent = new Intent(Intent.ACTION_DIAL,
                    Uri.parse("tel:" + String.valueOf(number)));
            startActivityForResult(intent,0);
        } else {
            if (mListener != null)<commit_msg>fixed the calling action<commit_after>package org.sana.android.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AlphabetIndexer;
import android.widget.SectionIndexer;
import android.widget.TextView;
import android.widget.Toast;

import org.sana.R;
import org.sana.android.Constants;
import org.sana.android.app.Locales;
import org.sana.android.app.Preferences;
import org.sana.android.content.Intents;
import org.sana.android.provider.AmbulanceDrivers;
import org.sana.android.widget.ScrollCompleteListener;
import org.sana.util.StringUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;

/**
 * A placeholder fragment containing a simple view.
 */
public class AmbulanceDriverListFragment extends ListFragment implements
        LoaderManager.LoaderCallbacks<Cursor>, AdapterView.OnItemClickListener {
    public static final String TAG = AmbulanceDriverListFragment.class.getName();

    static final String[] mProjection = new String[] {
            AmbulanceDrivers.Contract._ID,
            AmbulanceDrivers.Contract.FIRST_NAME,
            AmbulanceDrivers.Contract.LAST_NAME,
            AmbulanceDrivers.Contract.PHONE_NUMBER
    };
    private Uri mUri;
    private AmbulanceDriverCursorAdapter mAdapter;
    private OnDriverSelectedListener mListener;
    private int delta =1000*60;
    public static ArrayList<String> data = new ArrayList<String>();

    public AmbulanceDriverListFragment() {

    }

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

        mUri = getActivity().getIntent().getData();
        if (mUri == null) {
            mUri = AmbulanceDrivers.CONTENT_URI;
        }
        // initialize fields that depend on the Activity Context
        // i.e. the Adapter

        mAdapter = new AmbulanceDriverCursorAdapter(getActivity(), null, 0);
        setListAdapter(mAdapter);

        LoaderManager.enableDebugLogging(true);
        getActivity().getSupportLoaderManager().initLoader(2, null, this);
        // set the list item click listener
        getListView().setOnItemClickListener(this);
    }

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

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        CursorLoader loader = new CursorLoader(getActivity(),
                mUri,
                mProjection,
                null, null, AmbulanceDrivers.FIRST_NAME_SORT_ORDER);
        return loader;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        if (cursor == null || (cursor !=null && cursor.getCount() == 0)) {
            setEmptyText(getString(R.string.msg_drivers_vht));
        }
        if(cursor != null){
            //mAdapter.swapCursor(cursor);
            ((AmbulanceDriverCursorAdapter) this.getListAdapter()).swapCursor(cursor);
        }

    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {

        ((AmbulanceDriverCursorAdapter) this.getListAdapter()).swapCursor(null);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // Implement click to call functionality
        Object number = view.getTag();
        if(number != null){
            // TODO Should probably check that number is valid pattern
            Intent intent = new Intent(Intent.ACTION_CALL,
                    Uri.parse("tel:" + String.valueOf(number)));
//            Log.v(TAG, "the telephone number is" +String.valueOf(number));
            if(number.toString().length() == 10){
                startActivity(intent);
            }else {
                Toast.makeText(AmbulanceDriverListFragment.this.getContext(), "invalid phone number", Toast.LENGTH_SHORT).show();
            }

        } else {
            if (mListener != null)
{'fraction_non_alphanumeric': 0.09790906073680716, 'fraction_numerical': 0.0034295829184644317, 'mean_word_length': 3.187123668364984, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5565814', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2375, 'n_words': 534}