Android Open Source - CoinFlip Self Test Activity






From Project

Back to project page CoinFlip.

License

The source code is released under:

GNU General Public License

If you think the Android project CoinFlip listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *========================================================================
 * SelfTestActivity.java/*w  w w .ja va2  s .  com*/
 * Jul 12, 2014 4:31 PM | variable
 * Copyright (c) 2013 Richard Banasiak
 *========================================================================
 * This file is part of CoinFlip.
 *
 *    CoinFlip is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    CoinFlip is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with CoinFlip.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.banasiak.coinflip;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import java.text.NumberFormat;

public class SelfTestActivity extends Activity {

    // debugging tag
    private static final String TAG = SelfTestActivity.class.getSimpleName();

    private long maxNumberFlips;

    private TextView headsValue;

    private TextView headsRatio;

    private TextView tailsValue;

    private TextView tailsRatio;

    private TextView totalValue;

    private TextView totalRatio;

    private TextView elapsedTime;

    private SelfTestTask backgroundTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate()");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.selftest);

        headsValue = (TextView) findViewById(R.id.heads_value_tv);
        headsRatio = (TextView) findViewById(R.id.heads_ratio_tv);
        tailsValue = (TextView) findViewById(R.id.tails_value_tv);
        tailsRatio = (TextView) findViewById(R.id.tails_ratio_tv);
        totalValue = (TextView) findViewById(R.id.total_value_tv);
        totalRatio = (TextView) findViewById(R.id.total_ratio_tv);
        elapsedTime = (TextView) findViewById(R.id.elapsed_time_tv);

        maxNumberFlips = Settings.getDiagnosticsPref(this);

        backgroundTask = new SelfTestTask(this);
        backgroundTask.execute(new SelfTestStatus());
    }

    @Override
    protected void onStop() {
        Log.d(TAG, "onStop()");
        super.onStop();
        backgroundTask.cancel(true);
    }

    // this method is called when the async task reports it has new information
    public void updateDialog(SelfTestStatus taskStatus) {
        //Log.d(TAG, "updateDialog()");

        final NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMaximumFractionDigits(2);

        headsValue.setText(Integer.toString(taskStatus.getHeads()));
        headsRatio.setText("("
                + percentFormat.format(taskStatus.getHeadsPercentage()) + ")");

        tailsValue.setText(Integer.toString(taskStatus.getTails()));
        tailsRatio.setText("("
                + percentFormat.format(taskStatus.getTailsPercentage()) + ")");

        totalValue.setText(Integer.toString(taskStatus.getTotal()));
        totalRatio.setText("("
                + percentFormat.format((double) taskStatus.getTotal() / maxNumberFlips)
                + ")");

        elapsedTime.setText(Long.toString(taskStatus.getElapsedTime()));
    }

    public long getMaxNumberFlips() {
        return maxNumberFlips;
    }

}




Java Source Code List

com.banasiak.coinflip.AboutActivity.java
com.banasiak.coinflip.CoinFlipActivity.java
com.banasiak.coinflip.CoinFlipWearActivity.java
com.banasiak.coinflip.DataLayerListenerService.java
com.banasiak.coinflip.InstallReceiver.java
com.banasiak.coinflip.SelfTestActivity.java
com.banasiak.coinflip.SelfTestStatus.java
com.banasiak.coinflip.SelfTestTask.java
com.banasiak.coinflip.Settings.java
com.banasiak.coinflip.ShakeListener.java
com.banasiak.coinflip.SliderPreference.java
com.banasiak.coinflip.lib.Animation.java
com.banasiak.coinflip.lib.ApplicationTest.java
com.banasiak.coinflip.lib.Coin.java
com.banasiak.coinflip.lib.CustomAnimationDrawable.java
com.banasiak.coinflip.lib.Util.java