Android Open Source - asecrypto-goes-mobile-app Base Fragment






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.apptasks;
/*  w  w w. ja  v  a  2 s.c  om*/
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import java.math.BigInteger;
import java.util.Random;

import at.fhj.gaar.asecrypto.mobile.crypto.AseInteger;
import at.fhj.gaar.asecrypto.mobile.ui.SectionAttachable;
import at.fhj.gaar.asecrypto.mobile.util.NumberChoiceSelector;
import at.fhj.gaar.asecrypto.mobile.util.NumberHelper;

/**
 * Base fragment.
 */
public class BaseFragment extends Fragment {

    /**
     * The fragment argument representing the section number for this fragment.
     */
    public static final String ARG_SECTION_NUMBER = "section_number";

    /**
     * The fragment argument representing the section title for this fragment.
     */
    public static final String ARG_SECTION_TITLE = "section_title";

    public BaseFragment() {
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        // sets the title of the fragment on the activity
        ((SectionAttachable) activity).onSectionAttached(getArguments()
                .getString(ARG_SECTION_TITLE));
    }

    /**
     * @link http://stackoverflow.com/a/7696791
     */
    protected void closeSoftKeyboard() {
        InputMethodManager inputManager = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);

        //check if no view has focus:
        View v = getActivity().getCurrentFocus();
        if(v == null) {
            return;
        }

        inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }

    protected AseInteger retrieveAseInteger(RadioButton bitChoiceButton, EditText bitField,
                                            RadioButton numberChoiceButton, EditText numberField,
                                            String whichNumberField) {

        NumberChoiceSelector selector = new NumberChoiceSelector(bitChoiceButton, bitField,
                numberChoiceButton, numberField);

        String userMessage;

        try {
            return selector.retrieveNumber();
        } catch (NumberChoiceSelector.InvalidNumberException e) {
            userMessage = "You have to input a valid target number!";
        } catch (NumberChoiceSelector.InvalidBitsException e) {
            userMessage = "You have to input a valid number of bits!";
        } catch (NumberChoiceSelector.InvalidChoiceException e) {
            userMessage = "Please select a mode of operation using the radio boxes!";
        }

        Toast.makeText(getActivity(), String.format("%s: %s", whichNumberField, userMessage),
                Toast.LENGTH_LONG).show();
        return null;
    }

    protected Long retrieveLong(EditText field, String fieldName) {
        try {
            long result = Long.parseLong(field.getText().toString());

            if (result <= 0) {
                throw new IllegalArgumentException();
            }

            return result;
        } catch (IllegalArgumentException e) { // also catches NumberFormatException
            Toast.makeText(getActivity(),
                    String.format("%s: You have to input a valid number larger than zero!",
                            fieldName), Toast.LENGTH_LONG).show();
        }

        return null;
    }
}




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