<commit_before>/*
 * Copyright (c) 2014, 2015 Data4All
 * 
 * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 * 
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 * 
 * <p>Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package io.github.data4all.activity;

import io.github.data4all.R;
import io.github.data4all.handler.DataBaseHandler;
import io.github.data4all.logger.Log;
import io.github.data4all.model.data.AbstractDataElement;
import io.github.data4all.model.data.Node;
import io.github.data4all.service.UploadService;

import java.util.List;

import org.json.JSONException;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * 
 * @author tbrose
 *
 */
public class UploadActivity extends BasicActivity {

    public static final String TAG = UploadActivity.class.getSimpleName();
    private ProgressBar progress;
    private TextView countText;
    private View uploadButton;
    private View cancleButton;

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload);
        progress = (ProgressBar) findViewById(R.id.upload_progress);
        countText = (TextView) findViewById(R.id.upload_count_text);
        uploadButton = findViewById(R.id.upload_upload_button);
        cancleButton = findViewById(R.id.upload_cancle_button);
        this.readObjectCount();
    }

    /**
     * Reads the number of Objects to Upload.
     */
    private void readObjectCount() {
        final DataBaseHandler db = new DataBaseHandler(this);
        final int count = db.getDataElementCount();
        db.close();

        countText.setText(Integer.toString(count));
        if (count > 0) {
            uploadButton.setEnabled(true);
        } else {
            uploadButton.setEnabled(false);
        }
    }

    /**
     * Show or hide the progress bar.
     * 
     * @param show
     *            Whether or not the progress bar should be shown
     */
    private void showProgress(boolean show) {
        if (show) {
            progress.setVisibility(View.VISIBLE);

            this.uploadButton.setEnabled(false);
            this.uploadButton.setVisibility(View.GONE);
            this.cancleButton.setEnabled(true);
            this.cancleButton.setVisibility(View.VISIBLE);
        } else {
            progress.setVisibility(View.INVISIBLE);
            progress.setIndeterminate(true);

            this.cancleButton.setEnabled(false);
            this.cancleButton.setVisibility(View.GONE);
            this.uploadButton.setEnabled(true);
            this.uploadButton.setVisibility(View.VISIBLE);
        }
    }

    /**
     * Called when the upload succeeds
     */
    public void onSuccess() {
        this.showProgress(false);
        final String msg = "Successfully uploaded";
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

    /**
     * Called when the upload fails.
     * 
     * @param msg
     *            The description of the error
     */
    public void onError(String msg) {
        this.showProgress(false);
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

    /**
     * Starts the upload process.
     * 
     * @param v
     *            The view which was clicked
     */<commit_msg>More statechanging when show and hide progress refs #3158<commit_after>/*
 * Copyright (c) 2014, 2015 Data4All
 * 
 * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 * 
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 * 
 * <p>Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package io.github.data4all.activity;

import io.github.data4all.R;
import io.github.data4all.handler.DataBaseHandler;
import io.github.data4all.logger.Log;
import io.github.data4all.model.data.AbstractDataElement;
import io.github.data4all.model.data.Node;
import io.github.data4all.service.UploadService;

import java.util.List;

import org.json.JSONException;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * 
 * @author tbrose
 *
 */
public class UploadActivity extends BasicActivity {

    public static final String TAG = UploadActivity.class.getSimpleName();
    private ProgressBar progress;
    private TextView countText;
    private View uploadButton;
    private View cancleButton;

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload);
        progress = (ProgressBar) findViewById(R.id.upload_progress);
        countText = (TextView) findViewById(R.id.upload_count_text);
        uploadButton = findViewById(R.id.upload_upload_button);
        cancleButton = findViewById(R.id.upload_cancle_button);
        this.readObjectCount();
    }

    /**
     * Reads the number of Objects to Upload.
     */
    private void readObjectCount() {
        final DataBaseHandler db = new DataBaseHandler(this);
        final int count = db.getDataElementCount();
        db.close();

        countText.setText(Integer.toString(count));
        if (count > 0) {
            uploadButton.setEnabled(true);
        } else {
            uploadButton.setEnabled(false);
        }
    }

    /**
     * Show or hide the progress bar.
     * 
     * @param show
     *            Whether or not the progress bar should be shown
     */
    private void showProgress(boolean show) {
        if (show) {
            this.progress.setMax(0);
            this.progress.setProgress(0);
            this.progress.setIndeterminate(true);
            this.progress.setVisibility(View.VISIBLE);

            this.uploadButton.setEnabled(false);
            this.uploadButton.setVisibility(View.GONE);
            this.cancleButton.setEnabled(true);
            this.cancleButton.setVisibility(View.VISIBLE);
        } else {
            this.progress.setVisibility(View.INVISIBLE);

            this.cancleButton.setEnabled(false);
            this.cancleButton.setVisibility(View.GONE);
            this.uploadButton.setEnabled(true);
            this.uploadButton.setVisibility(View.VISIBLE);
        }
    }

    /**
     * Called when the upload succeeds.
     */
    public void onSuccess() {
        this.showProgress(false);
        final String msg = "Successfully uploaded";
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

    /**
     * Called when the upload fails.
     * 
     * @param msg
     *            The description of the error
     */
    public void onError(String msg) {
        this.showProgress(false);
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

    /**
     * Starts the upload process.
     * 
     * @param v
     *            The view which was clicked
     */
{'fraction_non_alphanumeric': 0.09959274342835987, 'fraction_numerical': 0.005923731951129212, 'mean_word_length': 2.616242748772869, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4553979', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2247, 'n_words': 558}