<commit_before>package motocitizen.app.general.popups;

import android.annotation.TargetApi;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TableLayout;
import android.widget.TableRow;

import motocitizen.app.general.Accident;
import motocitizen.main.R;
import motocitizen.network.requests.AccidentChangeState;
import motocitizen.startup.Startup;

class PopupWindowGeneral {

    static final String CALL_PREFIX = "Вызов: ";
    static final String SMS_PREFIX = "СМС: ";

    static final TableRow.LayoutParams lp = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    static TableLayout content;
    static PopupWindow pw;
    static String textToCopy;
    private static Context context;
    private static final OnClickListener copyButtonListener = new OnClickListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onClick(View v) {
            ClipboardManager myClipboard;
            myClipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData myClip;
            myClip = ClipData.newPlainText("text", textToCopy);
            myClipboard.setPrimaryClip(myClip);
            pw.dismiss();
        }
    };
    private static Accident point;
    private static final OnClickListener dialButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            Intent intent = new Intent(Intent.ACTION_DIAL);
            String number = (String) ((Button) v).getText();
            intent.setData(Uri.parse("tel:" + number.replace(CALL_PREFIX, "")));
            context.startActivity(intent);
        }
    };
    private static final OnClickListener smsButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            Intent intent = new Intent(Intent.ACTION_VIEW);
            String number = (String) ((Button) v).getText();
            intent.setData(Uri.parse("sms:" + number.replace(SMS_PREFIX, "")));
            context.startActivity(intent);
        }
    };
    private static final OnClickListener finishButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            if (point.isEnded()) {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.ACTIVE);
            } else {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.ENDED);
            }
        }
    };
    private static final OnClickListener hideButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            if (point.isHidden()) {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.ACTIVE);
            } else {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.HIDE);
            }
        }
    };

    private static final OnClickListener shareButtonListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, textToCopy);
            sendIntent.setType("text/plain");
            context.startActivity(sendIntent);
            pw.dismiss();
        }
    };

    static TableRow shareMessage(Context outerContext){
        context = outerContext;
        TableRow tr = new TableRow(content.getContext());
        Button b = new Button(content.getContext());
        b.setText(R.string.share);
        b.setOnClickListener(shareButtonListener);
        tr.addView(b, lp);
        return tr;
    }

    static TableRow copyButtonRow() {
        TableRow tr = new TableRow(content.getContext());
        Button b = new Button(content.getContext());
        b.setText(R.string.copy);
        b.setOnClickListener(copyButtonListener);
        tr.addView(b, lp);
        return tr;
    }

    static TableRow phoneButtonRow(String phone) {
        Button dial = new Button(content.getContext());
        dial.setText(CALL_PREFIX + phone);
        dial.setOnClickListener(dialButtonListener);
        TableRow tr = new TableRow(content.getContext());
        tr.addView(dial, lp);
        return tr;
    }

    static TableRow smsButtonRow(String raw) {
        String phone = "+7" + raw.substring(1);
        Button dial = new Button(content.getContext());
        dial.setText(SMS_PREFIX + phone);
        dial.setOnClickListener(smsButtonListener);
        TableRow tr = new TableRow(content.getContext());
        tr.addView(dial, lp);
        return tr;
    }

    static TableRow finishButtonRow(Accident p) {
        point = p;
        Button finish = new Button(content.getContext());
        if (point.isEnded()) {
            finish.setText(R.string.unfinish);
        } else {
            finish.setText(R.string.finish);
        }

        finish.setOnClickListener(finishButtonListener);
        TableRow tr = new TableRow(content.getContext());
        tr.addView(finish, lp);
        return tr;
    }

    static TableRow hideButtonRow(Accident p) {
        point = p;
        Button finish = new Button(content.getContext());<commit_msg>В контекстном меню в главном списке "СМС" идет с лишней лидирующей семеркой https://github.com/rjhdby/motocitizen/issues/336<commit_after>package motocitizen.app.general.popups;

import android.annotation.TargetApi;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TableLayout;
import android.widget.TableRow;

import motocitizen.app.general.Accident;
import motocitizen.main.R;
import motocitizen.network.requests.AccidentChangeState;
import motocitizen.startup.Startup;

class PopupWindowGeneral {

    static final String CALL_PREFIX = "Вызов: ";
    static final String SMS_PREFIX = "СМС: ";

    static final TableRow.LayoutParams lp = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    static TableLayout content;
    static PopupWindow pw;
    static String textToCopy;
    private static Context context;
    private static final OnClickListener copyButtonListener = new OnClickListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onClick(View v) {
            ClipboardManager myClipboard;
            myClipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData myClip;
            myClip = ClipData.newPlainText("text", textToCopy);
            myClipboard.setPrimaryClip(myClip);
            pw.dismiss();
        }
    };
    private static Accident point;
    private static final OnClickListener dialButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            Intent intent = new Intent(Intent.ACTION_DIAL);
            String number = (String) ((Button) v).getText();
            intent.setData(Uri.parse("tel:" + number.replace(CALL_PREFIX, "")));
            context.startActivity(intent);
        }
    };
    private static final OnClickListener smsButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            Intent intent = new Intent(Intent.ACTION_VIEW);
            String number = (String) ((Button) v).getText();
            intent.setData(Uri.parse("sms:" + number.replace(SMS_PREFIX, "")));
            context.startActivity(intent);
        }
    };
    private static final OnClickListener finishButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            if (point.isEnded()) {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.ACTIVE);
            } else {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.ENDED);
            }
        }
    };
    private static final OnClickListener hideButtonListener = new OnClickListener() {
        public void onClick(View v) {
            pw.dismiss();
            if (point.isHidden()) {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.ACTIVE);
            } else {
                new AccidentChangeState(null, context, point.getId(), AccidentChangeState.HIDE);
            }
        }
    };

    private static final OnClickListener shareButtonListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, textToCopy);
            sendIntent.setType("text/plain");
            context.startActivity(sendIntent);
            pw.dismiss();
        }
    };

    static TableRow shareMessage(Context outerContext){
        context = outerContext;
        TableRow tr = new TableRow(content.getContext());
        Button b = new Button(content.getContext());
        b.setText(R.string.share);
        b.setOnClickListener(shareButtonListener);
        tr.addView(b, lp);
        return tr;
    }

    static TableRow copyButtonRow() {
        TableRow tr = new TableRow(content.getContext());
        Button b = new Button(content.getContext());
        b.setText(R.string.copy);
        b.setOnClickListener(copyButtonListener);
        tr.addView(b, lp);
        return tr;
    }

    static TableRow phoneButtonRow(String phone) {
        Button dial = new Button(content.getContext());
        dial.setText(CALL_PREFIX + phone);
        dial.setOnClickListener(dialButtonListener);
        TableRow tr = new TableRow(content.getContext());
        tr.addView(dial, lp);
        return tr;
    }

    static TableRow smsButtonRow(String raw) {
        String phone = raw.substring(1);
        Button dial = new Button(content.getContext());
        dial.setText(SMS_PREFIX + phone);
        dial.setOnClickListener(smsButtonListener);
        TableRow tr = new TableRow(content.getContext());
        tr.addView(dial, lp);
        return tr;
    }

    static TableRow finishButtonRow(Accident p) {
        point = p;
        Button finish = new Button(content.getContext());
        if (point.isEnded()) {
            finish.setText(R.string.unfinish);
        } else {
            finish.setText(R.string.finish);
        }

        finish.setOnClickListener(finishButtonListener);
        TableRow tr = new TableRow(content.getContext());
        tr.addView(finish, lp);
        return tr;
    }

    static TableRow hideButtonRow(Accident p) {
        point = p;
        Button finish = new Button(content.getContext());
{'fraction_non_alphanumeric': 0.10058027079303675, 'fraction_numerical': 0.0005275189027606822, 'mean_word_length': 2.662266580811333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6721583', 'n_tokens_mistral': 3068, 'n_tokens_neox': 3032, 'n_words': 674}