Back to project page trivial-password.
The source code is released under:
MIT License
If you think the Android project trivial-password listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.hbabcock.trivialpassword; //from w ww . j a va2 s . com import java.util.ArrayList; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.util.Log; import android.view.View; import android.widget.EditText; public class AccountEditorFragment extends DialogFragment { private static final String TAG = "AccountEditorFragment"; public static final String EXTRA_ACCOUNT_DATA = "org.hbabcock.trivialpassword.account_data"; public static final String EXTRA_ACCOUNT_MODE = "org.hbabcock.trivialpassword.edit_mode"; private Account mAccount = null; private View mView = null; public static AccountEditorFragment newInstance(Account account, boolean isNew){ Bundle args = new Bundle(); args.putString(EXTRA_ACCOUNT_DATA, account.toString()); args.putBoolean(EXTRA_ACCOUNT_MODE, isNew); AccountEditorFragment fragment = new AccountEditorFragment(); fragment.setArguments(args); return fragment; } @Override public Dialog onCreateDialog(Bundle savedInstanceState){ mAccount = new Account(getArguments().getString(EXTRA_ACCOUNT_DATA)); boolean isNew = getArguments().getBoolean(EXTRA_ACCOUNT_MODE); mView = getActivity().getLayoutInflater().inflate(R.layout.dialog_account_editor, null); ArrayList<String> fields = mAccount.getData(); if (fields.size() <= AccountFragment.sFieldIds.size()){ for (int i = 0; i < fields.size(); i++) { ((EditText) mView.findViewById(AccountFragment.sFieldIds.get(i))).setText(fields.get(i)); } } else{ Log.i(TAG, "field size error " + fields.size() + " " + AccountFragment.sFieldIds.size()); // create error here.. } Integer stringId; if (isNew){ stringId = R.string.account_editor_title_new; } else{ stringId = R.string.account_editor_title_edit; } return new AlertDialog.Builder(getActivity()) .setView(mView) .setTitle(stringId) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { sendResult(Activity.RESULT_OK); } }) .create(); } @Override public void onDismiss(DialogInterface dialog){ sendResult(Activity.RESULT_CANCELED); } private void sendResult(int resultCode){ if (getTargetFragment() == null) return; ArrayList<String> data = new ArrayList<String>(); for (int i = 0; i < AccountFragment.sFieldIds.size(); i++){ data.add(((EditText) mView.findViewById(AccountFragment.sFieldIds.get(i))).getText().toString()); } Account a = new Account(mAccount.getId(), data); Intent i = new Intent(); i.putExtra(EXTRA_ACCOUNT_DATA, a.toString()); getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, i); } }