<commit_before>package net.justdave.mcstatus;

import java.util.ArrayList;
import java.util.ListIterator;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;

public class MainActivity extends Activity {
    private static final String TAG = MainActivity.class.getSimpleName();

    final private ArrayList<MinecraftServer> serverlist = new ArrayList<>();
    private ServerListViewAdapter adapter;
    private ListView listView;
    private ServerDB database;
    private MenuItem refreshItem;
    private int currentlyRefreshing = 0;
    private final Object refreshLock = new Object();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        database = new ServerDB(this);
        database.open();

        database.getAllServers(serverlist);
        adapter = new ServerListViewAdapter(getApplicationContext(), serverlist);
        setContentView(R.layout.activity_main);
        listView = findViewById(R.id.server_list);
        listView.setAdapter(adapter);
        adapter.setListView(listView);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        listView.setItemsCanFocus(false);
        listView.setDescendantFocusability(ListView.FOCUS_BLOCK_DESCENDANTS);
        listView.setEmptyView(findViewById(R.id.empty));
        listView.addStatesFromChildren();
        listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.selectionbar, menu);
                return true;
            }

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return true;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_editserver:
                        Log.i(TAG, "EDIT selection:");
                        @SuppressLint("InflateParams") View promptsView = LayoutInflater.from(MainActivity.this).inflate(
                                R.layout.addserver_dialog, null);
                        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                                MainActivity.this,
                                android.R.style.Theme_DeviceDefault_Dialog_Alert);
                        alertDialogBuilder.setView(promptsView);

                        final EditText serverName = promptsView
                                .findViewById(R.id.edit_server_name);
                        final EditText serverAddress = promptsView
                                .findViewById(R.id.edit_server_address);
                        SparseBooleanArray selected = listView
                                .getCheckedItemPositions();
                        for (final MinecraftServer thisServer : serverlist) {
                            if (selected.get(serverlist
                                    .indexOf(thisServer))) {
                                serverName.setText(thisServer.serverName());
                                serverAddress.setText(thisServer.serverAddress());
                                alertDialogBuilder
                                        .setCancelable(false)
                                        .setTitle("Edit Server: ".concat(thisServer.serverName()))
                                        .setPositiveButton("OK",
                                                new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog,
                                                                        int id) {
                                                        // get user input
                                                        database.update(thisServer.serverAddress(),
                                                                serverAddress.getText().toString(),
                                                                serverName.getText().toString());
                                                        database.getAllServers(serverlist);
                                                        refresh();
                                                    }
                                                })
                                        .setNegativeButton("Cancel",
                                                new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog,
                                                                        int id) {
                                                        dialog.cancel();
                                                    }
                                                });
                                AlertDialog alertDialog = alertDialogBuilder.create();
                                alertDialog.show();
                                listView.setItemChecked(
                                        serverlist
                                                .indexOf(thisServer),
                                        false);
                            }
                        }

                        break;
                    case R.id.action_deleteserver:
                        AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(
                                MainActivity.this,
                                android.R.style.Theme_DeviceDefault_Dialog_Alert);
                        myAlertDialog
                                .setCancelable(false)
                                .setTitle("Delete Server(s)")
                                .setMessage(
                                        "You are about to delete the selected server(s).")
                                .setPositiveButton("Cancel",
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(
                                                    DialogInterface arg0, int arg1) {
                                                // do something when the Cancel
                                                // button
                                                // is clicked
                                                Log.i(TAG, "Cancel picked");
                                            }
                                        })
                                .setNegativeButton("Delete",
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(
                                                    DialogInterface arg0, int arg1) {
                                                // do something when the Delete
                                                // button is clicked
                                                Log.i(TAG, "Delete picked");
                                                SparseBooleanArray selected = listView
                                                        .getCheckedItemPositions();
                                                for (MinecraftServer thisServer : serverlist) {
                                                    if (selected.get(serverlist
                                                            .indexOf(thisServer))) {
                                                        database.delete(thisServer
                                                                .serverAddress());
                                                        listView.setItemChecked(
                                                                serverlist
                                                                        .indexOf(thisServer),
                                                                false);
                                                    }
                                                }
                                                database.getAllServers(serverlist);
                                                refresh();
                                                adapter.notifyDataSetInvalidated();
                                            }
                                        }).create().show();
                        break;
                }
                return false;
            }

            @Override
            public void onItemCheckedStateChanged(ActionMode mode,
                                                  int position, long id, boolean checked) {
                // listView.setItemChecked(position, checked);
                mode.getMenu().findItem(R.id.action_editserver)
                        .setVisible(listView.getCheckedItemCount() == 1);
                mode.setTitle(listView.getCheckedItemCount()
                        + " selected");
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
                listView.clearChoices();
            }
        });

    }

    public void refresh() {
        LayoutInflater inflater = (LayoutInflater) getApplicationContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        assert inflater != null;
        ImageView iv = (ImageView) inflater.inflate(R.layout.refresh_animation,
                null);

        Animation rotation = AnimationUtils.loadAnimation(
                getApplicationContext(), R.anim.refresh_rotate);
        rotation.setRepeatCount(Animation.INFINITE);

        ListIterator<MinecraftServer> iterator = serverlist.listIterator();
        if (iterator.hasNext()) {
            if (refreshItem != null) {
                refreshItem.setActionView(iv);
            }
            iv.startAnimation(rotation);
        }
        while (iterator.hasNext()) {
            iterator.next().setDescription("Loading...           ");
        }
        adapter.notifyDataSetChanged();
        iterator = serverlist.listIterator();
        while (iterator.hasNext()) {
            final MinecraftServer mcs = iterator.next();
            Thread thread = new Thread(new Runnable() {
                @Override<commit_msg>use correct view inflation method for a non-parented object (lint)<commit_after>package net.justdave.mcstatus;

import java.util.ArrayList;
import java.util.ListIterator;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;

public class MainActivity extends Activity {
    private static final String TAG = MainActivity.class.getSimpleName();

    final private ArrayList<MinecraftServer> serverlist = new ArrayList<>();
    private ServerListViewAdapter adapter;
    private ListView listView;
    private ServerDB database;
    private MenuItem refreshItem;
    private int currentlyRefreshing = 0;
    private final Object refreshLock = new Object();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        database = new ServerDB(this);
        database.open();

        database.getAllServers(serverlist);
        adapter = new ServerListViewAdapter(getApplicationContext(), serverlist);
        setContentView(R.layout.activity_main);
        listView = findViewById(R.id.server_list);
        listView.setAdapter(adapter);
        adapter.setListView(listView);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        listView.setItemsCanFocus(false);
        listView.setDescendantFocusability(ListView.FOCUS_BLOCK_DESCENDANTS);
        listView.setEmptyView(findViewById(R.id.empty));
        listView.addStatesFromChildren();
        listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.selectionbar, menu);
                return true;
            }

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return true;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_editserver:
                        Log.i(TAG, "EDIT selection:");
                        @SuppressLint("InflateParams") View promptsView = LayoutInflater.from(MainActivity.this).inflate(
                                R.layout.addserver_dialog, null);
                        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                                MainActivity.this,
                                android.R.style.Theme_DeviceDefault_Dialog_Alert);
                        alertDialogBuilder.setView(promptsView);

                        final EditText serverName = promptsView
                                .findViewById(R.id.edit_server_name);
                        final EditText serverAddress = promptsView
                                .findViewById(R.id.edit_server_address);
                        SparseBooleanArray selected = listView
                                .getCheckedItemPositions();
                        for (final MinecraftServer thisServer : serverlist) {
                            if (selected.get(serverlist
                                    .indexOf(thisServer))) {
                                serverName.setText(thisServer.serverName());
                                serverAddress.setText(thisServer.serverAddress());
                                alertDialogBuilder
                                        .setCancelable(false)
                                        .setTitle("Edit Server: ".concat(thisServer.serverName()))
                                        .setPositiveButton("OK",
                                                new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog,
                                                                        int id) {
                                                        // get user input
                                                        database.update(thisServer.serverAddress(),
                                                                serverAddress.getText().toString(),
                                                                serverName.getText().toString());
                                                        database.getAllServers(serverlist);
                                                        refresh();
                                                    }
                                                })
                                        .setNegativeButton("Cancel",
                                                new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog,
                                                                        int id) {
                                                        dialog.cancel();
                                                    }
                                                });
                                AlertDialog alertDialog = alertDialogBuilder.create();
                                alertDialog.show();
                                listView.setItemChecked(
                                        serverlist
                                                .indexOf(thisServer),
                                        false);
                            }
                        }

                        break;
                    case R.id.action_deleteserver:
                        AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(
                                MainActivity.this,
                                android.R.style.Theme_DeviceDefault_Dialog_Alert);
                        myAlertDialog
                                .setCancelable(false)
                                .setTitle("Delete Server(s)")
                                .setMessage(
                                        "You are about to delete the selected server(s).")
                                .setPositiveButton("Cancel",
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(
                                                    DialogInterface arg0, int arg1) {
                                                // do something when the Cancel
                                                // button
                                                // is clicked
                                                Log.i(TAG, "Cancel picked");
                                            }
                                        })
                                .setNegativeButton("Delete",
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(
                                                    DialogInterface arg0, int arg1) {
                                                // do something when the Delete
                                                // button is clicked
                                                Log.i(TAG, "Delete picked");
                                                SparseBooleanArray selected = listView
                                                        .getCheckedItemPositions();
                                                for (MinecraftServer thisServer : serverlist) {
                                                    if (selected.get(serverlist
                                                            .indexOf(thisServer))) {
                                                        database.delete(thisServer
                                                                .serverAddress());
                                                        listView.setItemChecked(
                                                                serverlist
                                                                        .indexOf(thisServer),
                                                                false);
                                                    }
                                                }
                                                database.getAllServers(serverlist);
                                                refresh();
                                                adapter.notifyDataSetInvalidated();
                                            }
                                        }).create().show();
                        break;
                }
                return false;
            }

            @Override
            public void onItemCheckedStateChanged(ActionMode mode,
                                                  int position, long id, boolean checked) {
                // listView.setItemChecked(position, checked);
                mode.getMenu().findItem(R.id.action_editserver)
                        .setVisible(listView.getCheckedItemCount() == 1);
                mode.setTitle(listView.getCheckedItemCount()
                        + " selected");
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
                listView.clearChoices();
            }
        });

    }

    public void refresh() {
        ImageView iv = (ImageView) View.inflate(getApplicationContext(), R.layout.refresh_animation,
                null);

        Animation rotation = AnimationUtils.loadAnimation(
                getApplicationContext(), R.anim.refresh_rotate);
        rotation.setRepeatCount(Animation.INFINITE);

        ListIterator<MinecraftServer> iterator = serverlist.listIterator();
        if (iterator.hasNext()) {
            if (refreshItem != null) {
                refreshItem.setActionView(iv);
            }
            iv.startAnimation(rotation);
        }
        while (iterator.hasNext()) {
            iterator.next().setDescription("Loading...           ");
        }
        adapter.notifyDataSetChanged();
        iterator = serverlist.listIterator();
        while (iterator.hasNext()) {
            final MinecraftServer mcs = iterator.next();
            Thread thread = new Thread(new Runnable() {
                @Override
{'fraction_non_alphanumeric': 0.06467120181405896, 'fraction_numerical': 0.0005442176870748299, 'mean_word_length': 0.9822905429701546, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 228, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3831362', 'n_tokens_mistral': 3975, 'n_tokens_neox': 3736, 'n_words': 775}