<commit_before>package edu.ucla.cens.whatsinvasive;

import java.io.File;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.util.Linkify;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TwoLineListItem;
import android.widget.AdapterView.OnItemClickListener;
import edu.ucla.cens.whatsinvasive.data.PhotoDatabase;
import edu.ucla.cens.whatsinvasive.data.PhotoDatabase.OnChangeListener;
import edu.ucla.cens.whatsinvasive.data.PhotoDatabase.PhotoDatabaseRow;
import edu.ucla.cens.whatsinvasive.services.UploadService;
import edu.ucla.cens.whatsinvasive.tools.Media;

public class Queue extends ListActivity {
	private final int CONTEXT_SHOW_ON_MAP = 0;
	private final int CONTEXT_VIEW = 1;
	private final int CONTEXT_EDIT_NOTE = 2;
	private final int CONTEXT_REMOVE = 3;
	
	private static final int ACTIVITY_EDIT_NOTE = 0;
	
	private PhotoDatabase mDatabase;
	private Cursor mCursor;
	
	private Boolean uploadServiceWasStopped = false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//stop upload service while showing this view
		Intent service = new Intent(this, UploadService.class);
		uploadServiceWasStopped = this.stopService(service);

		this.setContentView(R.layout.queue);
		this.setTitle(R.string.title_queue);
        
        TextView extrat = new TextView(this);   
        extrat.setAutoLinkMask(Linkify.WEB_URLS);
        extrat.setText(getString(R.string.queue_message_full));
        extrat.setTextSize(22);
        extrat.setOnLongClickListener(new OnLongClickListener(){

            public boolean onLongClick(View v) {
                return false;
            }
            
        });     
        getListView().addFooterView(extrat);   
        getListView().setFooterDividersEnabled(true);
        
        mDatabase = new PhotoDatabase(this);
        mDatabase.addChangeListener(new OnChangeListener() {
            public void onDatabseChanged(PhotoDatabase source) {
                new Handler().post(new Runnable() {
                    public void run() {
                        if(Queue.this.mCursor != null)
                            Queue.this.mCursor.requery();
                    }
                });
            }
        });
		
		getListView().setOnItemClickListener(new OnItemClickListener(){

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if(!(arg1 instanceof TextView) )
					arg1.performLongClick();
			}});
		getListView().setOnCreateContextMenuListener(new OnCreateContextMenuListener(){

			public void onCreateContextMenu(ContextMenu menu, View v,
					ContextMenuInfo menuInfo) {
				
					AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
					TagData data = (TagData) info.targetView.getTag();
					if(data != null){
						menu.setHeaderTitle(getString(R.string.queue_actions));						
						menu.add(0, CONTEXT_SHOW_ON_MAP, 0, getString(R.string.queue_show_map));
						menu.add(0, CONTEXT_VIEW, 1, getString(R.string.queue_view));
						if(data.uploaded == null) {
						    menu.add(0, CONTEXT_EDIT_NOTE, 2, getString(R.string.queue_edit_note));
							menu.add(0, CONTEXT_REMOVE, 3, getString(R.string.queue_do_not_upload));
						}
					}
				}				
		});
	}
	
	@Override
	protected void onResume() {
	    mDatabase.open();
        mCursor = mDatabase.getReadCursor();
	    
        startManagingCursor(mCursor);
        setListAdapter(new QueueAdapter(this, mCursor));
	    
        super.onResume();
	}
	
	@Override
	protected void onPause() {
	    // We have to close the database here so that the other 
	    // activities (e.g. ViewTag) can use the PhotoDatabase
	    mDatabase.close();
	    
	    super.onPause();
	}
	
	@Override
	protected void onStop() {
	    // We have to close the cursor here and not in the onPause method
	    // if we want to avoid the empty view from being displayed before the 
	    // view is killed
	    mCursor.close();
	    
	    super.onStop();
	}
	
	@Override
	protected void onDestroy() {
		//if upload service was stopped while showing this view, restart it
		if(uploadServiceWasStopped) {
		    Intent service = new Intent(this, UploadService.class);
		    this.startService(service);
		}
		
		super.onDestroy();
	}
	
	private void showOnMap(String lat, String lon){
		if(lat != null && lon != null){<commit_msg>The upload service is no longer stopped when viewing the upload queue<commit_after>package edu.ucla.cens.whatsinvasive;

import java.io.File;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.util.Linkify;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TwoLineListItem;
import android.widget.AdapterView.OnItemClickListener;
import edu.ucla.cens.whatsinvasive.data.PhotoDatabase;
import edu.ucla.cens.whatsinvasive.data.PhotoDatabase.OnChangeListener;
import edu.ucla.cens.whatsinvasive.data.PhotoDatabase.PhotoDatabaseRow;
import edu.ucla.cens.whatsinvasive.tools.Media;

public class Queue extends ListActivity {
	private final int CONTEXT_SHOW_ON_MAP = 0;
	private final int CONTEXT_VIEW = 1;
	private final int CONTEXT_EDIT_NOTE = 2;
	private final int CONTEXT_REMOVE = 3;
	
	private static final int ACTIVITY_EDIT_NOTE = 0;
	
	private PhotoDatabase mDatabase;
	private Cursor mCursor;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.queue);
		this.setTitle(R.string.title_queue);
        
        TextView extrat = new TextView(this);   
        extrat.setAutoLinkMask(Linkify.WEB_URLS);
        extrat.setText(getString(R.string.queue_message_full));
        extrat.setTextSize(22);
        extrat.setOnLongClickListener(new OnLongClickListener(){

            public boolean onLongClick(View v) {
                return false;
            }
            
        });     
        getListView().addFooterView(extrat);   
        getListView().setFooterDividersEnabled(true);
        
        mDatabase = new PhotoDatabase(this);
        mDatabase.addChangeListener(new OnChangeListener() {
            public void onDatabseChanged(PhotoDatabase source) {
                new Handler().post(new Runnable() {
                    public void run() {
                        if(Queue.this.mCursor != null)
                            Queue.this.mCursor.requery();
                    }
                });
            }
        });
		
		getListView().setOnItemClickListener(new OnItemClickListener(){

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if(!(arg1 instanceof TextView) )
					arg1.performLongClick();
			}});
		getListView().setOnCreateContextMenuListener(new OnCreateContextMenuListener(){

			public void onCreateContextMenu(ContextMenu menu, View v,
					ContextMenuInfo menuInfo) {
				
					AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
					TagData data = (TagData) info.targetView.getTag();
					if(data != null){
						menu.setHeaderTitle(getString(R.string.queue_actions));						
						menu.add(0, CONTEXT_SHOW_ON_MAP, 0, getString(R.string.queue_show_map));
						menu.add(0, CONTEXT_VIEW, 1, getString(R.string.queue_view));
						if(data.uploaded == null) {
						    menu.add(0, CONTEXT_EDIT_NOTE, 2, getString(R.string.queue_edit_note));
							menu.add(0, CONTEXT_REMOVE, 3, getString(R.string.queue_do_not_upload));
						}
					}
				}				
		});
	}
	
	@Override
	protected void onResume() {
	    mDatabase.open();
        mCursor = mDatabase.getReadCursor();
	    
        startManagingCursor(mCursor);
        setListAdapter(new QueueAdapter(this, mCursor));
	    
        super.onResume();
	}
	
	@Override
	protected void onPause() {
	    // We have to close the database here so that the other 
	    // activities (e.g. ViewTag) can use the PhotoDatabase
	    mDatabase.close();
	    
	    super.onPause();
	}
	
	@Override
	protected void onStop() {
	    // We have to close the cursor here and not in the onPause method
	    // if we want to avoid the empty view from being displayed before the 
	    // view is killed
	    mCursor.close();
	    
	    super.onStop();
	}
	
	private void showOnMap(String lat, String lon){
		if(lat != null && lon != null){
{'fraction_non_alphanumeric': 0.09688833385367884, 'fraction_numerical': 0.004370902279113331, 'mean_word_length': 3.2503317116320214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3858995', 'n_tokens_mistral': 3145, 'n_tokens_neox': 2751, 'n_words': 609}