<commit_before>package com.audacious_software.passive_data_kit.activities;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.audacious_software.passive_data_kit.Logger;
import com.audacious_software.passive_data_kit.generators.Generator;
import com.audacious_software.pdk.passivedatakit.R;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

public class DataDisclosureDetailActivity extends AppCompatActivity {
    public static class Action {
        public String title;
        public String subtitle;

        public View view;
    }

    public static final String GENERATOR_CLASS_NAME = "com.audacious_software.passive_data_kit.activities.DataDisclosureDetailActivity.GENERATOR_CLASS_NAME";

    private Class<? extends Generator> mGeneratorClass = null;

    @SuppressWarnings({"unchecked", "TryWithIdenticalCatches", "ConstantConditions"})
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final DataDisclosureDetailActivity me = this;

        this.setContentView(R.layout.layout_data_disclosure_detail_pdk);
        this.getSupportActionBar().setSubtitle(R.string.title_data_disclosure);
        this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        try {
            this.mGeneratorClass = (Class<? extends Generator>) Class.forName(this.getIntent().getStringExtra(DataDisclosureDetailActivity.GENERATOR_CLASS_NAME));
        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
        }

        if (this.mGeneratorClass != null) {
            try {
                Method getGeneratorTitle = this.mGeneratorClass.getDeclaredMethod("getGeneratorTitle", Context.class);

                String title = (String) getGeneratorTitle.invoke(null, this);
                this.getSupportActionBar().setTitle(title);

                Method getDisclosureActions = this.mGeneratorClass.getDeclaredMethod("getDisclosureActions", Context.class);

                final List<Action> actions = (List<Action>) getDisclosureActions.invoke(null, this);

                ListView actionsList = (ListView) this.findViewById(R.id.disclosure_actions);
                ArrayAdapter<Action> adapter = new ArrayAdapter<Action>(this, R.layout.row_disclosure_action_pdk, actions) {
                    @NonNull
                    @SuppressLint("InflateParams")
                    public View getView (int position, View convertView, @NonNull ViewGroup parent) {
                        if (convertView == null) {
                            convertView = LayoutInflater.from(me).inflate(R.layout.row_disclosure_action_pdk, null);
                        }

                        Action action = actions.get(position);

                        TextView title = (TextView) convertView.findViewById(R.id.action_title);
                        title.setText(action.title);

                        TextView description = (TextView) convertView.findViewById(R.id.action_description);
                        description.setText(action.subtitle);<commit_msg>Fixes NPE when data disclosure detail called from emulator<commit_after>package com.audacious_software.passive_data_kit.activities;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.audacious_software.passive_data_kit.Logger;
import com.audacious_software.passive_data_kit.generators.Generator;
import com.audacious_software.pdk.passivedatakit.R;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

public class DataDisclosureDetailActivity extends AppCompatActivity {
    public static class Action {
        public String title;
        public String subtitle;

        public View view;
    }

    public static final String GENERATOR_CLASS_NAME = "com.audacious_software.passive_data_kit.activities.DataDisclosureDetailActivity.GENERATOR_CLASS_NAME";

    private Class<? extends Generator> mGeneratorClass = null;

    @SuppressWarnings({"unchecked", "TryWithIdenticalCatches", "ConstantConditions"})
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String generatorClassName = this.getIntent().getStringExtra(DataDisclosureDetailActivity.GENERATOR_CLASS_NAME);

        if (generatorClassName == null) {
            this.finish();

            return;
        }

        final DataDisclosureDetailActivity me = this;

        this.setContentView(R.layout.layout_data_disclosure_detail_pdk);
        this.getSupportActionBar().setSubtitle(R.string.title_data_disclosure);
        this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        try {
            this.mGeneratorClass = (Class<? extends Generator>) Class.forName(generatorClassName);
        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
        }

        if (this.mGeneratorClass != null) {
            try {
                Method getGeneratorTitle = this.mGeneratorClass.getDeclaredMethod("getGeneratorTitle", Context.class);

                String title = (String) getGeneratorTitle.invoke(null, this);
                this.getSupportActionBar().setTitle(title);

                Method getDisclosureActions = this.mGeneratorClass.getDeclaredMethod("getDisclosureActions", Context.class);

                final List<Action> actions = (List<Action>) getDisclosureActions.invoke(null, this);

                ListView actionsList = (ListView) this.findViewById(R.id.disclosure_actions);
                ArrayAdapter<Action> adapter = new ArrayAdapter<Action>(this, R.layout.row_disclosure_action_pdk, actions) {
                    @NonNull
                    @SuppressLint("InflateParams")
                    public View getView (int position, View convertView, @NonNull ViewGroup parent) {
                        if (convertView == null) {
                            convertView = LayoutInflater.from(me).inflate(R.layout.row_disclosure_action_pdk, null);
                        }

                        Action action = actions.get(position);

                        TextView title = (TextView) convertView.findViewById(R.id.action_title);
                        title.setText(action.title);

                        TextView description = (TextView) convertView.findViewById(R.id.action_description);
                        description.setText(action.subtitle);
{'fraction_non_alphanumeric': 0.08631810072732263, 'fraction_numerical': 0.0002744613695622341, 'mean_word_length': 3.1527065527065528, 'pattern_counts': {'":': 0, '<': 15, '<?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': '6820787', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1809, 'n_words': 339}