Android Open Source - asecrypto-goes-mobile-app Main Activity






From Project

Back to project page asecrypto-goes-mobile-app.

License

The source code is released under:

GNU General Public License

If you think the Android project asecrypto-goes-mobile-app 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

package at.fhj.gaar.asecrypto.mobile.ui;
// ww w  .j  ava2 s  .  c  om
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;

import at.fhj.gaar.asecrypto.mobile.R;
import at.fhj.gaar.asecrypto.mobile.ui.apptasks.fermat.FermatTestFragment;
import at.fhj.gaar.asecrypto.mobile.ui.apptasks.millerrabin.MillerRabinTestFragment;
import at.fhj.gaar.asecrypto.mobile.ui.navigation.DrawerItemIdentifiers;
import at.fhj.gaar.asecrypto.mobile.ui.navigation.NavigationDrawerCallable;
import at.fhj.gaar.asecrypto.mobile.ui.navigation.NavigationDrawerFragment;

public class MainActivity extends Activity implements NavigationDrawerCallable, SectionAttachable {

    /**
     * Externally specified default fragment to open (by Intent).
     */
    public static final String ARG_INTENT_DEFAULT_FRAGMENT = "fragment_to_open";

    /**
     * Fragment managing the behaviors, interactions and presentation of the navigation drawer.
     */
    private NavigationDrawerFragment navigationDrawerFragment;

    /**
     * Used to store the last screen title. For use in {@link #restoreActionBar()}.
     */
    private CharSequence currentScreenTitle;

    private int expectedFragmentTaskId;

    private Object fragmentParameter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        navigationDrawerFragment = (NavigationDrawerFragment)
                getFragmentManager().findFragmentById(R.id.navigation_drawer);
        currentScreenTitle = getTitle();

        // Set up the drawer
        navigationDrawerFragment.setUp(
                R.id.navigation_drawer,
                (DrawerLayout) findViewById(R.id.drawer_layout));

        // Keep screen on for calculations
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    }

    @Override
    protected void onStart() {
        super.onStart();

        Intent intent = getIntent();
        if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
            int defaultItemNumber = intent.getIntExtra(ARG_INTENT_DEFAULT_FRAGMENT, 0);

            if (defaultItemNumber > 0) {
                navigationDrawerFragment.openItem(defaultItemNumber);
            }
        }
    }

    @Override
    public void onTaskItemSelected(int taskId, String taskName) {
        Fragment newFragment = FragmentFactory.getFragment(taskId, taskName);
        Fragment foundFragment = getFragmentManager().findFragmentById(R.id.container);

        // If the fragment class is the same, DO NOT replace it!
        // Reason: if e.g. the user has rotated his device, putting in a new fragment of the
        // same class will disturb the restoration of any saved instance state.
        if (foundFragment != null && newFragment.getClass().equals(foundFragment.getClass())) {
            Log.d("AseCrypto", String.format(
                    "MainActivity.onTaskItemSelected: fragments equal, no replacement needed"));
            return;
        }

        // update the main content by replacing fragments
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.container, newFragment)
                .commit();

        if (expectedFragmentTaskId == taskId
                && expectedFragmentTaskId == DrawerItemIdentifiers.TASK_FERMAT_TEST) {
            // set default number for Fermat test - given by Carmichael number generator
            ((FermatTestFragment) newFragment).setConcreteTestNumber((String) fragmentParameter);
        } else if (expectedFragmentTaskId == taskId
                && expectedFragmentTaskId == DrawerItemIdentifiers.TASK_MILLER_RABIN_TEST) {
            // set default number for Miller-Rabin test - given by Carmichael number generator
            ((MillerRabinTestFragment) newFragment)
                    .setConcreteTestNumber((String) fragmentParameter);
        }

        // reset
        expectedFragmentTaskId = 0;
        fragmentParameter = null;
    }

    @Override
    public void onSectionAttached(String title) {
        currentScreenTitle = title;

        if (getActionBar() == null) {
            return;
        }

        getActionBar().setTitle(title);
    }

    public void restoreActionBar() {
        ActionBar actionBar = getActionBar();
        if (actionBar == null) {
            return;
        }

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(currentScreenTitle);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (!navigationDrawerFragment.isDrawerOpen()) {
            restoreActionBar();
            return true;
        }

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // open navigation drawer if the user clicks on the app icon button
        if (item.getItemId() == android.R.id.home) {
            navigationDrawerFragment.toggleDrawer();
        }

        return super.onOptionsItemSelected(item);
    }

    public void openFermatTest(String number) {
        // is given to the Fragment in onTaskItemSelected
        fragmentParameter = number;
        expectedFragmentTaskId = DrawerItemIdentifiers.TASK_FERMAT_TEST;
        // after the fragment has been openen, onTaskItemSelected is called
        navigationDrawerFragment.openItem(DrawerItemIdentifiers.TASK_FERMAT_TEST);
    }

    public void openMillerRabinTest(String number) {
        // is given to the Fragment in onTaskItemSelected
        fragmentParameter = number;
        expectedFragmentTaskId = DrawerItemIdentifiers.TASK_MILLER_RABIN_TEST;
        // after the fragment has been openen, onTaskItemSelected is called
        navigationDrawerFragment.openItem(DrawerItemIdentifiers.TASK_MILLER_RABIN_TEST);
    }
}




Java Source Code List

at.fhj.gaar.asecrypto.mobile.crypto.AseInteger.java
at.fhj.gaar.asecrypto.mobile.crypto.RSAHelper.java
at.fhj.gaar.asecrypto.mobile.ui.FragmentFactory.java
at.fhj.gaar.asecrypto.mobile.ui.MainActivity.java
at.fhj.gaar.asecrypto.mobile.ui.SectionAttachable.java
at.fhj.gaar.asecrypto.mobile.ui.TaskFinishedCallable.java
at.fhj.gaar.asecrypto.mobile.ui.TaskIntermediateCallable.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.BaseFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.bezout.BezoutFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.bezout.BezoutIterativeTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.bezout.BezoutRecursiveTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.bezout.BezoutResult.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.carmichael.CarmichaelFinderTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.carmichael.CarmichaelGeneratorFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.carmichael.CarmichaelResult.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.euclid.EuclidFactorialTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.euclid.EuclidFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.euclid.EuclidIterativeTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.euclid.EuclidRecursiveTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.euclid.EuclidResult.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.exponentiation.ExponentiationResult.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.exponentiation.FastExponentiationFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.exponentiation.FastExponentiationTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.exponentiation.SlowExponentiationFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.exponentiation.SlowExponentiationTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.fermat.FermatProgress.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.fermat.FermatResult.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.fermat.FermatTaskArguments.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.fermat.FermatTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.fermat.FermatTestFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.millerrabin.MillerRabinArguments.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.millerrabin.MillerRabinProgress.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.millerrabin.MillerRabinResult.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.millerrabin.MillerRabinTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.millerrabin.MillerRabinTestFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.numbercounter.NumberCounterFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.numbercounter.NumberCounterTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.primitiveroots.FinderArguments.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.primitiveroots.PrimitiveRootFinderFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.primitiveroots.PrimitiveRootLookupTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.primitiveroots.PrimitiveRootResult.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.rsa.ParameterCalculationHelperTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.rsa.RSACalculationFragment.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.rsa.RSADecryptionParameters.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.rsa.RSADecryptionTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.rsa.RSAEncryptionParameters.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.rsa.RSAEncryptionTask.java
at.fhj.gaar.asecrypto.mobile.ui.apptasks.rsa.RSAResult.java
at.fhj.gaar.asecrypto.mobile.ui.navigation.DrawerItemIdentifiers.java
at.fhj.gaar.asecrypto.mobile.ui.navigation.DrawerItem.java
at.fhj.gaar.asecrypto.mobile.ui.navigation.NavigationDrawerCallable.java
at.fhj.gaar.asecrypto.mobile.ui.navigation.NavigationDrawerFragment.java
at.fhj.gaar.asecrypto.mobile.util.NumberChoiceSelector.java
at.fhj.gaar.asecrypto.mobile.util.NumberHelper.java
at.fhj.gaar.asecrypto.mobile.util.StopWatch.java