Back to project page KeepMySecret.
The source code is released under:
GNU General Public License
If you think the Android project KeepMySecret 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 keepmysecretapp.app.com.keepmysecretapp.fragments.edit; //from w w w . j ava2 s.c o m import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import keepmysecretapp.app.com.keepmysecretapp.R; import keepmysecretapp.app.com.keepmysecretapp.activities.MainActivity; import keepmysecretapp.app.com.keepmysecretapp.dao.Dao; import keepmysecretapp.app.com.keepmysecretapp.dao.EntryDao; import keepmysecretapp.app.com.keepmysecretapp.db.DbContext; import keepmysecretapp.app.com.keepmysecretapp.other.Tools; import keepmysecretapp.app.com.keepmysecretapp.types.CopyTextButtonListener; import keepmysecretapp.app.com.keepmysecretapp.types.GenerateButtonListener; import keepmysecretapp.app.com.keepmysecretapp.types.ListEntry; public class EditDataFragment extends Fragment { private static ListEntry entry; private Button editDataEntryButton; private Button generatePasswordButton; private Button copyPasswordButton; private TextView warningLabel; private EditText entryName; private EditText entryDescribe; private EditText entryPassword; public static EditDataFragment newInstance(ListEntry entry) { EditDataFragment.entry = entry; return new EditDataFragment(); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_text_data_edit, container, false); entryName = (EditText) rootView.findViewById(R.id.entry_name_field_edit); entryDescribe = (EditText) rootView.findViewById(R.id.entry_describe_field_edit); entryPassword = (EditText) rootView.findViewById(R.id.entry_password_field_edit); warningLabel = (TextView) rootView.findViewById(R.id.entryWarningTextViewEdit); editDataEntryButton = (Button) rootView.findViewById(R.id.edit_data_entry_button); entryName.setText(entry.getName()); entryPassword.setText(entry.getPassword()); entryDescribe.setText(entry.getDescribe()); initEditButtonListener(editDataEntryButton); generatePasswordButton = (Button) rootView.findViewById(R.id.generate_password_text_entry_button_edit); copyPasswordButton = (Button) rootView.findViewById(R.id.edit_text_entry_copy_button); generatePasswordButton.setOnClickListener(new GenerateButtonListener(entryPassword, getActivity().getFragmentManager())); copyPasswordButton.setOnClickListener(new CopyTextButtonListener(entryPassword, getActivity())); return rootView; } private void initEditButtonListener(Button button) { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (warningLabel.getVisibility() == View.VISIBLE) warningLabel.setVisibility(View.INVISIBLE); if (Tools.isStringEmpty(entry.getName())) { warningLabel.setText("??????? ???? ???????"); warningLabel.setVisibility(View.VISIBLE); return; } DbContext dbContext = DbContext.getInstance(getActivity()); Dao dao = new EntryDao(dbContext, entry.getGroupID()); ListEntry changedEntry = new ListEntry(); changedEntry.setID(entry.getID()); changedEntry.setName(entryName.getText().toString()); changedEntry.setDescribe(entryDescribe.getText().toString()); changedEntry.setPassword(entryPassword.getText().toString()); if (dao.read(changedEntry) != null) { warningLabel.setText("?????? ??????? ??? ????????????"); warningLabel.setVisibility(View.VISIBLE); } else { dao.update(changedEntry); Intent toMain = new Intent(getActivity(), MainActivity.class); startActivity(toMain); } } }); } }