<commit_before>package org.bitcoin.authenticator;

import java.io.IOException;
import java.util.ArrayList;

import javax.crypto.SecretKey;

import org.bitcoin.authenticator.Events.GlobalEvents;
import org.bitcoin.authenticator.GcmUtil.GcmIntentService;
import org.bitcoin.authenticator.GcmUtil.ProcessGCMRequest;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.Html;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;

/**
 * This class creates the Wallet_list activity which serves as the main activity after the user pairs a wallet.
 * It loads the wallet metadata from shared preferences and creates a listview of paired wallets.
 * In the background it opens a connection to the wallet and waits for transactions. When a transaction is received
 * it displays a dialog box to the user asking for authorization. If it's authorized, it calculates the signature
 * and sends it back to the wallet.
 */
public class Wallet_list extends Activity {
	ListView lv1;
	private PopupMenu popupMenu;
	public static JSONObject req;
	public static Connection conn; 
	private CustomListAdapter listAdapter;
	public GlobalEvents singletonEvents;

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wallet_list);
        //Create the list view
        try { setListView(); } catch (InterruptedException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); }
        //Start the AsyncTask which waits for new transactions
  		new ConnectToWallets().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 
  		
  		/**
  		 * Events
  		 */
  		this.singletonEvents = GlobalEvents.SharedGlobal();
  		singletonEvents.onSetPendingGCMRequestToSeen.AddListener(this, "onSetPendingGCMRequestToSeen");
    }

	/**Creates the listview component and defines behavior to a long press on a list item.
	 * @throws JSONException 
	 * @throws InterruptedException */
	void setListView() throws InterruptedException, JSONException{
        ArrayList walletList = getListData();
        lv1 = (ListView) findViewById(R.id.custom_list);
        lv1.setLongClickable(true);
        listAdapter = new CustomListAdapter(this, walletList);
        lv1.setAdapter(listAdapter);
        //registerForContextMenu(lv1);
        lv1.setOnItemClickListener(new OnItemClickListener()
        {
           @Override
           public void onItemClick(AdapterView<?> adapter, View v, int position,
                 long arg3) 
           {
        	   final int index = position;
        	   ArrayList<BAPopupMenu.PopupButton> buttons = new ArrayList<BAPopupMenu.PopupButton>();
        	   buttons.add(new BAPopupMenu.PopupButton("Show Pending Requests",false));
        	   buttons.add(new BAPopupMenu.PopupButton("Re-pair",true));
        	   buttons.add(new BAPopupMenu.PopupButton("Rename",true));
        	   buttons.add(new BAPopupMenu.PopupButton("Delete",true));
        	   
                new BAPopupMenu(getApplicationContext(),v)
                .setButtons(buttons)
                .setActionsListener(new BAPopupMenu.ActionsListener(){
					@Override
					public void pressed(MenuItem item) {
						onPopupMenuItemSelected(item.getTitle().toString(),index);
					}
                }).show();
           }
        });
        new ProcessGCMInBackground().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	
	public void updatePendingGCMRequest(){
		try {
			listAdapter.updateData(getGCMPendingRequests(listAdapter.listData));
		} catch (InterruptedException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); }
	}

	/**Inflates the menu and adds it to the action bar*/
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);<commit_msg>fixed show pending req context menu<commit_after>package org.bitcoin.authenticator;

import java.io.IOException;
import java.util.ArrayList;

import javax.crypto.SecretKey;

import org.bitcoin.authenticator.Events.GlobalEvents;
import org.bitcoin.authenticator.GcmUtil.GcmIntentService;
import org.bitcoin.authenticator.GcmUtil.ProcessGCMRequest;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.Html;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;

/**
 * This class creates the Wallet_list activity which serves as the main activity after the user pairs a wallet.
 * It loads the wallet metadata from shared preferences and creates a listview of paired wallets.
 * In the background it opens a connection to the wallet and waits for transactions. When a transaction is received
 * it displays a dialog box to the user asking for authorization. If it's authorized, it calculates the signature
 * and sends it back to the wallet.
 */
public class Wallet_list extends Activity {
	ListView lv1;
	private PopupMenu popupMenu;
	public static JSONObject req;
	public static Connection conn; 
	private CustomListAdapter listAdapter;
	public GlobalEvents singletonEvents;

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wallet_list);
        //Create the list view
        try { setListView(); } catch (InterruptedException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); }
        //Start the AsyncTask which waits for new transactions
  		new ConnectToWallets().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 
  		
  		/**
  		 * Events
  		 */
  		this.singletonEvents = GlobalEvents.SharedGlobal();
  		singletonEvents.onSetPendingGCMRequestToSeen.AddListener(this, "onSetPendingGCMRequestToSeen");
    }

	/**Creates the listview component and defines behavior to a long press on a list item.
	 * @throws JSONException 
	 * @throws InterruptedException */
	void setListView() throws InterruptedException, JSONException{
        ArrayList walletList = getListData();
        lv1 = (ListView) findViewById(R.id.custom_list);
        lv1.setLongClickable(true);
        listAdapter = new CustomListAdapter(this, walletList);
        lv1.setAdapter(listAdapter);
        //registerForContextMenu(lv1);
        lv1.setOnItemClickListener(new OnItemClickListener()
        {
           @Override
           public void onItemClick(AdapterView<?> adapter, View v, int position,
                 long arg3) 
           {
        	   final int index = position;
        	   ArrayList<BAPopupMenu.PopupButton> buttons = new ArrayList<BAPopupMenu.PopupButton>();
        	   int cnt = ((WalletItem)listAdapter.getItem(index)).getPendingGCMRequests().size();
        	   boolean showPending = cnt>0? true:false;
        	   buttons.add(new BAPopupMenu.PopupButton("Show Pending Requests",showPending));
        	   buttons.add(new BAPopupMenu.PopupButton("Re-pair",true));
        	   buttons.add(new BAPopupMenu.PopupButton("Rename",true));
        	   buttons.add(new BAPopupMenu.PopupButton("Delete",true));
        	   
                new BAPopupMenu(getApplicationContext(),v)
                .setButtons(buttons)
                .setActionsListener(new BAPopupMenu.ActionsListener(){
					@Override
					public void pressed(MenuItem item) {
						onPopupMenuItemSelected(item.getTitle().toString(),index);
					}
                }).show();
           }
        });
        new ProcessGCMInBackground().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	
	public void updatePendingGCMRequest(){
		try {
			listAdapter.updateData(getGCMPendingRequests(listAdapter.listData));
		} catch (InterruptedException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); }
	}

	/**Inflates the menu and adds it to the action bar*/
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
{'fraction_non_alphanumeric': 0.08939840134623475, 'fraction_numerical': 0.0015776188472864956, 'mean_word_length': 3.9526041666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '520724', 'n_tokens_mistral': 2689, 'n_tokens_neox': 2586, 'n_words': 651}