<commit_before>package com.shinewave.sopviewer;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.artifex.mupdfdemo.MuPDFCore;
import com.artifex.mupdfdemo.MuPDFPageAdapter;
import com.artifex.mupdfdemo.MuPDFReaderView;
import com.artifex.mupdfdemo.MuPDFView;
import com.artifex.mupdfdemo.OutlineActivityData;
import com.artifex.mupdfdemo.ReaderView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class PDFPlayActivity extends AppCompatActivity {

    private MuPDFCore core;
    private MuPDFReaderView mDocView;
    private View mButtonsView;
    private SeekBar mPageSlider;
    private int mPageSliderRes;
    private TextView mPageNumberView;
    private boolean mButtonsVisible;
    private Handler handler;
    private int playItemCount = 0;
    private int loopCount = 0;
    private PlayList plist;
    private static final int OUTER_TYPE_CONN = 1;
    private static final int OUTER_TYPE_PLAY = 2;
    private static final int OUTER_TYPE_CONN_AND_PLAY = 3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mButtonsView = getLayoutInflater().inflate(R.layout.buttons, null);
        //mPageSlider = (SeekBar) mButtonsView.findViewById(R.id.pageSlider);
        //mPageNumberView = (TextView) mButtonsView.findViewById(R.id.pageNumber);
        Intent it = getIntent();
        String playListName = "";
        if (it.getAction() != null && it.getAction().equals("com.shinewave.sopviewer.PDFPlayActivity")) {
            //外部傳入
            int type = it.getIntExtra("IntentType", 0);
            String jsonStr = getIntent().getStringExtra("Json");
            JSONObject obj = new JSONObject();
            try {
                obj = new JSONObject(jsonStr);
            } catch (Exception e) {
                Toast.makeText(PDFPlayActivity.this, getString(R.string.msg_json_error), Toast.LENGTH_LONG).show();
            }
            if (type == OUTER_TYPE_CONN) {
                //Conn
                String msg = doOuterConn(obj);
                Toast.makeText(PDFPlayActivity.this, msg, Toast.LENGTH_LONG).show();
            } else if (type == OUTER_TYPE_PLAY) {
                //Play
                String msg = doOuterPlay(obj);
                if (msg.startsWith(getString(R.string.dialog_succeed))) {
                    String[] nameArr = msg.split(",");
                    playListName = nameArr[1];
                } else {
                    Toast.makeText(PDFPlayActivity.this, msg, Toast.LENGTH_LONG).show();
                }
            } else if (type == OUTER_TYPE_CONN_AND_PLAY) {
                //Conn + Play
                String msgConn = doOuterConn(obj);
                if (msgConn.equals(getString(R.string.dialog_succeed))) {
                    String msgPlay = doOuterPlay(obj);
                    if (msgPlay.startsWith(getString(R.string.dialog_succeed))) {
                        String[] nameArr = msgPlay.split(",");
                        playListName = nameArr[1];
                    } else {
                        Toast.makeText(PDFPlayActivity.this, msgPlay, Toast.LENGTH_LONG).show();
                    }
                } else {
                    Toast.makeText(PDFPlayActivity.this, msgConn, Toast.LENGTH_LONG).show();
                }
            }
        } else {
            //內部
            playListName = getIntent().getStringExtra("PlayListName");
        }

        if (playListName == null || playListName.equals("")) {
            this.finish();
        } else {
            plist = DBManager.getPlayItem(playListName);
            if (plist != null && plist.playListItem.size() > 0) {
                mDocView = new MuPDFReaderView(this) {
                    @Override
                    protected void onMoveToChild(int i) {
                        mPageNumberView.setText(String.format("%d / %d", i + 1, core.countPages()));
                        mPageSlider.setMax((core.countPages() - 1) * mPageSliderRes);
                        mPageSlider.setProgress(i * mPageSliderRes);
                        super.onMoveToChild(i);
                    }

                    @Override
                    protected void onTapMainDocArea() {
                        if (!mButtonsVisible) {
                            showButtons();
                        } else {
                            hideButtons();
                        }
                    }

                    @Override
                    protected void onDocMotion() {
                        hideButtons();
                    }
                };

                RelativeLayout layout = new RelativeLayout(this);
                layout.addView(mDocView);
                layout.addView(mButtonsView);
                setContentView(layout);

                setup();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle(getString(R.string.title_error));
                builder.setMessage(getString(R.string.playlist_no_playitem));
                builder.setPositiveButton(getString(R.string.okay), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
                builder.create().show();
            }

            Button btnEdit = (Button) findViewById(R.id.btn_finish);
            btnEdit.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String message = "Save";
                    Intent intent = new Intent();
                    intent.putExtra("MESSAGE", message);
                    setResult(RESULT_OK, intent);
                    finish();
                }
            });
        }
    }

    private void setup() {
        if (playItemCount >= plist.playListItem.size()) {
            loopCount++;
            playItemCount = 0;
        }

        if (loopCount >= plist.loop) {
            Intent returnIntent = new Intent();
            returnIntent.putExtra("result", "FINISH");
            setResult(Activity.RESULT_OK, returnIntent);
            finish();<commit_msg>fixed btn name<commit_after>package com.shinewave.sopviewer;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.artifex.mupdfdemo.MuPDFCore;
import com.artifex.mupdfdemo.MuPDFPageAdapter;
import com.artifex.mupdfdemo.MuPDFReaderView;
import com.artifex.mupdfdemo.MuPDFView;
import com.artifex.mupdfdemo.OutlineActivityData;
import com.artifex.mupdfdemo.ReaderView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class PDFPlayActivity extends AppCompatActivity {

    private MuPDFCore core;
    private MuPDFReaderView mDocView;
    private View mButtonsView;
    private SeekBar mPageSlider;
    private int mPageSliderRes;
    private TextView mPageNumberView;
    private boolean mButtonsVisible;
    private Handler handler;
    private int playItemCount = 0;
    private int loopCount = 0;
    private PlayList plist;
    private static final int OUTER_TYPE_CONN = 1;
    private static final int OUTER_TYPE_PLAY = 2;
    private static final int OUTER_TYPE_CONN_AND_PLAY = 3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mButtonsView = getLayoutInflater().inflate(R.layout.buttons, null);
        //mPageSlider = (SeekBar) mButtonsView.findViewById(R.id.pageSlider);
        //mPageNumberView = (TextView) mButtonsView.findViewById(R.id.pageNumber);
        Intent it = getIntent();
        String playListName = "";
        if (it.getAction() != null && it.getAction().equals("com.shinewave.sopviewer.PDFPlayActivity")) {
            //外部傳入
            int type = it.getIntExtra("IntentType", 0);
            String jsonStr = getIntent().getStringExtra("Json");
            JSONObject obj = new JSONObject();
            try {
                obj = new JSONObject(jsonStr);
            } catch (Exception e) {
                Toast.makeText(PDFPlayActivity.this, getString(R.string.msg_json_error), Toast.LENGTH_LONG).show();
            }
            if (type == OUTER_TYPE_CONN) {
                //Conn
                String msg = doOuterConn(obj);
                Toast.makeText(PDFPlayActivity.this, msg, Toast.LENGTH_LONG).show();
            } else if (type == OUTER_TYPE_PLAY) {
                //Play
                String msg = doOuterPlay(obj);
                if (msg.startsWith(getString(R.string.dialog_succeed))) {
                    String[] nameArr = msg.split(",");
                    playListName = nameArr[1];
                } else {
                    Toast.makeText(PDFPlayActivity.this, msg, Toast.LENGTH_LONG).show();
                }
            } else if (type == OUTER_TYPE_CONN_AND_PLAY) {
                //Conn + Play
                String msgConn = doOuterConn(obj);
                if (msgConn.equals(getString(R.string.dialog_succeed))) {
                    String msgPlay = doOuterPlay(obj);
                    if (msgPlay.startsWith(getString(R.string.dialog_succeed))) {
                        String[] nameArr = msgPlay.split(",");
                        playListName = nameArr[1];
                    } else {
                        Toast.makeText(PDFPlayActivity.this, msgPlay, Toast.LENGTH_LONG).show();
                    }
                } else {
                    Toast.makeText(PDFPlayActivity.this, msgConn, Toast.LENGTH_LONG).show();
                }
            }
        } else {
            //內部
            playListName = getIntent().getStringExtra("PlayListName");
        }

        if (playListName == null || playListName.equals("")) {
            this.finish();
        } else {
            plist = DBManager.getPlayItem(playListName);
            if (plist != null && plist.playListItem.size() > 0) {
                mDocView = new MuPDFReaderView(this) {
                    @Override
                    protected void onMoveToChild(int i) {
                        mPageNumberView.setText(String.format("%d / %d", i + 1, core.countPages()));
                        mPageSlider.setMax((core.countPages() - 1) * mPageSliderRes);
                        mPageSlider.setProgress(i * mPageSliderRes);
                        super.onMoveToChild(i);
                    }

                    @Override
                    protected void onTapMainDocArea() {
                        if (!mButtonsVisible) {
                            showButtons();
                        } else {
                            hideButtons();
                        }
                    }

                    @Override
                    protected void onDocMotion() {
                        hideButtons();
                    }
                };

                RelativeLayout layout = new RelativeLayout(this);
                layout.addView(mDocView);
                layout.addView(mButtonsView);
                setContentView(layout);

                setup();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle(getString(R.string.title_error));
                builder.setMessage(getString(R.string.playlist_no_playitem));
                builder.setPositiveButton(getString(R.string.okay), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
                builder.create().show();
            }

            Button btnFinish = (Button) findViewById(R.id.btn_finish);
            btnFinish.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent returnIntent = new Intent();
                    returnIntent.putExtra("result", "FINISH");
                    setResult(Activity.RESULT_OK, returnIntent);
                    finish();
                }
            });
        }
    }

    private void setup() {
        if (playItemCount >= plist.playListItem.size()) {
            loopCount++;
            playItemCount = 0;
        }

        if (loopCount >= plist.loop) {
            Intent returnIntent = new Intent();
            returnIntent.putExtra("result", "FINISH");
            setResult(Activity.RESULT_OK, returnIntent);
            finish();
{'fraction_non_alphanumeric': 0.09859768945724043, 'fraction_numerical': 0.0018891230109714453, 'mean_word_length': 1.8089795918367346, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368475', 'n_tokens_mistral': 3717, 'n_tokens_neox': 3539, 'n_words': 684}