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;
/*www.java2s.com*/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.
*/publicclass BaseFragment extends Fragment {
/**
* The fragment argument representing the section number for this fragment.
*/publicstaticfinal String ARG_SECTION_NUMBER = "section_number";
/**
* The fragment argument representing the section title for this fragment.
*/publicstaticfinal String ARG_SECTION_TITLE = "section_title";
public BaseFragment() {
}
@Override
publicvoid 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
*/protectedvoid 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) {
thrownew 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;
}
}