<commit_before>package com.cradle.iitc_mobile;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;

import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

// provide communication between IITC script and android app
public class IITC_JSInterface {

    // context of main activity
    Context context;
    HashMap<String, String> layer_ids;
    boolean[] overlay_is_active;
    int active_base_layer;
    String[] overlay_layers, base_layers;
    int num_base_layers;
    int num_overlay_layers;

    IITC_JSInterface(Context c) {
        layer_ids = new HashMap<String, String>();
        context = c;
    }

    // send geo intent for navigation apps like gmaps or waze etc...
    @JavascriptInterface
    public void intentPosLink(String lat, String lng, String portal_name) {
        String uri = "geo:" + lat + "," + lng + "?q=" + lat + "," + lng
                + "%20(" + portal_name + ")";
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                Uri.parse(uri));
        context.startActivity(intent);
    }

    // disable javascript injection while spinner is enabled
    // prevent the spinner from closing automatically
    @JavascriptInterface
    public void spinnerEnabled(boolean en) {
        Log.d("iitcm", "disableJS? " + en);
        ((IITC_Mobile) context).getWebView().disableJS(en);
    }

    // copy link to specific portal to android clipboard
    @JavascriptInterface
    public void copy(String s) {
        ClipboardManager clipboard = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("Copied Text ", s);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT)
                .show();
    }

    @JavascriptInterface
    public void portalLongPressed() {
        final IITC_Mobile iitcm = (IITC_Mobile) context;
        iitcm.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                iitcm.handleMenuItemSelected(R.id.menu_info, true);
            }
        });
    }

    @JavascriptInterface
    public void dialogOpened(String id) {
        ((IITC_Mobile) context).dialogOpened(id);
    }

    // get layers and list them in a dialog
    @JavascriptInterface
    public void setLayers(String base_layer, String overlay_layer) {

        /*
         *  the layer strings have a form like:
         *  [{"layerId":27,"name":"MapQuest OSM","active":true},{"layerId":28,"name":"Default Ingress Map","active":false}]
         *  Put it in a JSONArray and parse it
         */
        JSONArray base_layersJSON = null;
        JSONArray overlay_layersJSON = null;
        Log.d("iitcm", base_layer);
        try {
            base_layersJSON = new JSONArray(base_layer);
            overlay_layersJSON = new JSONArray(overlay_layer);
        } catch (JSONException e) {<commit_msg>commit change of JSInterface too<commit_after>package com.cradle.iitc_mobile;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;

import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

// provide communication between IITC script and android app
public class IITC_JSInterface {

    // context of main activity
    Context context;
    HashMap<String, String> layer_ids;
    boolean[] overlay_is_active;
    int active_base_layer;
    String[] overlay_layers, base_layers;
    int num_base_layers;
    int num_overlay_layers;

    IITC_JSInterface(Context c) {
        layer_ids = new HashMap<String, String>();
        context = c;
    }

    // send geo intent for navigation apps like gmaps or waze etc...
    @JavascriptInterface
    public void intentPosLink(String lat, String lng, String portal_name) {
        String uri = "geo:" + lat + "," + lng + "?q=" + lat + "," + lng
                + "%20(" + portal_name + ")";
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                Uri.parse(uri));
        context.startActivity(intent);
    }

    // disable javascript injection while spinner is enabled
    // prevent the spinner from closing automatically
    @JavascriptInterface
    public void spinnerEnabled(boolean en) {
        Log.d("iitcm", "disableJS? " + en);
        ((IITC_Mobile) context).getWebView().disableJS(en);
    }

    // copy link to specific portal to android clipboard
    @JavascriptInterface
    public void copy(String s) {
        ClipboardManager clipboard = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("Copied Text ", s);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT)
                .show();
    }

    @JavascriptInterface
    public void portalLongPressed() {
        final IITC_Mobile iitcm = (IITC_Mobile) context;
        iitcm.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                iitcm.handleMenuItemSelected(R.id.menu_info, true);
            }
        });
    }

    @JavascriptInterface
    public void dialogOpened(String id, boolean open) {
        ((IITC_Mobile) context).dialogOpened(id, open);
    }

    // get layers and list them in a dialog
    @JavascriptInterface
    public void setLayers(String base_layer, String overlay_layer) {

        /*
         *  the layer strings have a form like:
         *  [{"layerId":27,"name":"MapQuest OSM","active":true},{"layerId":28,"name":"Default Ingress Map","active":false}]
         *  Put it in a JSONArray and parse it
         */
        JSONArray base_layersJSON = null;
        JSONArray overlay_layersJSON = null;
        Log.d("iitcm", base_layer);
        try {
            base_layersJSON = new JSONArray(base_layer);
            overlay_layersJSON = new JSONArray(overlay_layer);
        } catch (JSONException e) {
{'fraction_non_alphanumeric': 0.09764758100310697, 'fraction_numerical': 0.001775410563692854, 'mean_word_length': 2.9256678281068527, 'pattern_counts': {'":': 12, '<': 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': '6812378', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1870, 'n_words': 479}