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.creation; /*w w w .ja v a2s.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.presentation.EntryPresentActivity; import keepmysecretapp.app.com.keepmysecretapp.dao.Dao; import keepmysecretapp.app.com.keepmysecretapp.dao.EntryDao; import keepmysecretapp.app.com.keepmysecretapp.dao.GroupDao; import keepmysecretapp.app.com.keepmysecretapp.db.DbContext; import keepmysecretapp.app.com.keepmysecretapp.db.EntryType; import keepmysecretapp.app.com.keepmysecretapp.other.Constants; 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 CreateDataEntryFragment extends Fragment { private static String groupName; private Button createDataEntryButton; private TextView warningLabel; private Button generateButton; private Button copyPasswordButton; private EditText entryName; private EditText entryDescribe; private EditText entryPassword; public static CreateDataEntryFragment newInstance(String groupName) { CreateDataEntryFragment.groupName = groupName; return new CreateDataEntryFragment(); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_create_data_entry, container, false); entryName = (EditText) rootView.findViewById(R.id.entry_name_field); entryDescribe = (EditText) rootView.findViewById(R.id.entry_describe_field); entryPassword = (EditText) rootView.findViewById(R.id.entry_password_field); warningLabel = (TextView) rootView.findViewById(R.id.entryWarningTextView); createDataEntryButton = (Button) rootView.findViewById(R.id.createDataEntryButton); generateButton = (Button) rootView.findViewById(R.id.generate_button_create_text_data); copyPasswordButton = (Button) rootView.findViewById(R.id.create_text_entry_copy_button); generateButton.setOnClickListener( new GenerateButtonListener(entryPassword, getActivity().getFragmentManager())); copyPasswordButton.setOnClickListener(new CopyTextButtonListener(entryPassword, getActivity())); createButtonListener(createDataEntryButton); return rootView; } private void createButtonListener(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(entryName.getText().toString())) { warningLabel.setText("??????? ???? ??????"); warningLabel.setVisibility(View.VISIBLE); return; } DbContext dbContext = DbContext.getInstance(getActivity()); Dao dao = new GroupDao(dbContext); ListEntry group = new ListEntry(); group.setName(groupName); group = (ListEntry) dao.read(group); dao = new EntryDao(dbContext, group.getID()); ListEntry entry = new ListEntry(); entry.setName(entryName.getText().toString()); entry.setDescribe(entryDescribe.getText().toString()); entry.setPassword(entryPassword.getText().toString()); entry.setGroupID(group.getID()); if (dao.read(entry) != null) { warningLabel.setText("?????? ??????? ??? ????????????"); warningLabel.setVisibility(View.VISIBLE); } else { dao.create(entry); Intent toEntries = new Intent(getActivity(), EntryPresentActivity.class); toEntries.putExtra(Constants.ENTRY_TITLE, groupName); toEntries.putExtra(Constants.ENTRY_TYPE, EntryType.DATA.getName()); toEntries.putExtra(Constants.ENTRY_ID, group.getID()); startActivity(toEntries); } } }); } }