<commit_before>package edu.nyu.cs.omnidroid.ui;

import java.util.HashMap;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import edu.nyu.cs.omnidroid.R;
import edu.nyu.cs.omnidroid.util.AGParser;
import edu.nyu.cs.omnidroid.util.UGParser;

/**
 * This class will present an interface for the user to input data that they want the
 * <code>ActionThrowerActions</code> to access.
 * 
 * @author acase
 */
public class ActionThrowerData extends Activity implements OnClickListener {
  private String eventApp;
  private String eventName;
  private String throwerApp;
  private String throwerName;
  private EditText appData;
  private EditText instanceName;

  /**
   *  Ask the user for data about the OmniHandler
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.action_thrower_data);

    // Get data passed to us
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    if (extras != null) {
      eventApp = extras.getString(AGParser.KEY_APPLICATION);
      eventName = extras.getString(UGParser.KEY_EventName);
      throwerApp = extras.getString(UGParser.KEY_ActionApp);
      throwerName = extras.getString(UGParser.KEY_ActionName);
    } else {
      // TODO (acase): Throw exception
    }

    // Setup our UI
    Button save = (Button) findViewById(R.id.save);
    appData = (EditText) findViewById(R.id.data);
    instanceName = (EditText) findViewById(R.id.Iname);

    // Listen for the save button click
    save.setOnClickListener(this);
  }

  /*
   * (non-Javadoc)
   * Add OmniHandler to OmniDroid if appropriate
   *  
   * @see android.view.View.OnClickListener#onClick(android.view.View)
   */
  public void onClick(View v) {
    // Get data from our user
    String iName = instanceName.getText().toString();
    String aData = appData.getText().toString();

    // Add OmniHandler to OmniDroid
    if (iName.length() > 0 && aData.length() > 0) {

      // Add OmniHandler to the CP
      ContentValues values = new ContentValues();
      values.put("i_name", iName);
      values.put("a_data", aData);
      Uri uri = getContentResolver().insert(
          Uri.parse("content://edu.nyu.cs.omnidroid.core.maincp/CP"), values);

      // Add OmniHandler to the UGConfig
      UGParser ug = new UGParser(getApplicationContext());
      HashMap<String, String> HM = new HashMap<String, String>();
      HM.put(UGParser.KEY_InstanceName, iName);
      HM.put(UGParser.KEY_EventName, eventName);
      HM.put(UGParser.KEY_EventApp, eventApp);
      HM.put(UGParser.KEY_ActionName, throwerName);
      HM.put(UGParser.KEY_ActionApp, throwerApp);
      HM.put(UGParser.KEY_EnableInstance, "True");
      HM.put(UGParser.KEY_ActionData, uri.toString());
      // TODO: get these from the user
      HM.put("FilterType", "");
      HM.put("FilterData", "");
      //HM.put("FilterType", "S_PhoneNum");
      //HM.put("FilterData", "212-555-1234");
      ug.writeRecord(HM);
<commit_msg>changes<commit_after>package edu.nyu.cs.omnidroid.ui;

import java.util.HashMap;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import edu.nyu.cs.omnidroid.R;
import edu.nyu.cs.omnidroid.util.AGParser;
import edu.nyu.cs.omnidroid.util.UGParser;

/**
 * This class will present an interface for the user to input data that they want the
 * <code>ActionThrowerActions</code> to access.
 * 
 * @author acase
 */
public class ActionThrowerData extends Activity implements OnClickListener {
  private String eventApp;
  private String eventName;
  private String throwerApp;
  private String throwerName;
  private EditText appData;
  private EditText instanceName;

  /**
   *  Ask the user for data about the OmniHandler
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.action_thrower_data);

    // Get data passed to us
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    if (extras != null) {
      eventApp = extras.getString(AGParser.KEY_APPLICATION);
      eventName = extras.getString(UGParser.KEY_EventName);
      throwerApp = extras.getString(UGParser.KEY_ActionApp);
      throwerName = extras.getString(UGParser.KEY_ActionName);
    } else {
      // TODO (acase): Throw exception
    }

    // Setup our UI
    Button save = (Button) findViewById(R.id.save);
    appData = (EditText) findViewById(R.id.data);
    instanceName = (EditText) findViewById(R.id.Iname);

    // Listen for the save button click
    save.setOnClickListener(this);
  }

  /*
   * (non-Javadoc)
   * Add OmniHandler to OmniDroid if appropriate
   *  
   * @see android.view.View.OnClickListener#onClick(android.view.View)
   */
  public void onClick(View v) {
    // Get data from our user
    String iName = instanceName.getText().toString();
    String aData = appData.getText().toString();

    // Add OmniHandler to OmniDroid
    if (iName.length() > 0 && aData.length() > 0) {

      // Add OmniHandler to the CP
      ContentValues values = new ContentValues();
      values.put("i_name", iName);
      values.put("a_data", aData);
      Uri uri = getContentResolver().insert(
          Uri.parse("content://edu.nyu.cs.omnidroid.core.maincp/CP"), values);

      // Add OmniHandler to the UGConfig
      UGParser ug = new UGParser(getApplicationContext());
      HashMap<String, String> HM = new HashMap<String, String>();
      HM.put(UGParser.KEY_InstanceName, iName);
      HM.put(UGParser.KEY_EventName, eventName);
      HM.put(UGParser.KEY_EventApp, eventApp);
      HM.put(UGParser.KEY_ActionName, throwerName);
      HM.put(UGParser.KEY_ActionApp, throwerApp);
      HM.put(UGParser.KEY_EnableInstance, "False");
      HM.put(UGParser.KEY_ActionData, uri.toString());
      // TODO: get these from the user
      //HM.put("FilterType", "");
      //HM.put("FilterData", "");
      HM.put("FilterType", "s_ph_no");
      HM.put("FilterData", "212-555-1234");
      ug.writeRecord(HM);

{'fraction_non_alphanumeric': 0.12115621156211562, 'fraction_numerical': 0.0036900369003690036, 'mean_word_length': 3.4646533973919014, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '4147398', 'n_tokens_mistral': 2112, 'n_tokens_neox': 2041, 'n_words': 462}