Android Open Source - sqlite-provider Find Firework With Pk Fragment

From Project

Back to project page sqlite-provider.


The source code is released under:

Apache License

If you think the Android project sqlite-provider 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 com.novoda.sqliteprovider.demo.ui.fragment;
// w  ww. ja  v  a  2s  .  com
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;

import com.novoda.sqliteprovider.demo.R;
import com.novoda.sqliteprovider.demo.domain.Firework;
import com.novoda.sqliteprovider.demo.ui.base.NovodaActivity;
import com.novoda.sqliteprovider.demo.ui.input.OnPrimaryKeyInputError;

public class FindFireworkWithPkFragment extends Fragment {

    public interface OnFireworkFound {
        void onFireworkFound(Firework firework);

    private EditText primaryKeyEditText;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_find_firework_with_pk, container, false);

        primaryKeyEditText = (EditText) root.findViewById(;

        return root;

    private final OnClickListener onFindButtonClick = new OnClickListener() {
        public void onClick(View v) {

    public void onFindFireworkWithPkClick() {
        if (userHasEnteredSomething()) {
            try {
                int primaryKey = getPrimaryKey();

                Firework firework = getFirework(primaryKey);

            } catch (NumberFormatException e) {

    private boolean userHasEnteredSomething() {
        return !TextUtils.isEmpty(primaryKeyEditText.getText());

    private int getPrimaryKey() {
        return Integer.parseInt(primaryKeyEditText.getText().toString());

    private Firework getFirework(int primaryKey) {
        return ((NovodaActivity) getActivity()).getApp().getFireworkReader().getFirework(primaryKey);

    private void informActivityFireworkFound(Firework firework) {
        if (getActivity() instanceof OnFireworkFound) {
            ((OnFireworkFound) getActivity()).onFireworkFound(firework);

    private void informActivityPublicKeyInvalid() {
        if (getActivity() instanceof OnPrimaryKeyInputError) {
            ((OnPrimaryKeyInputError) getActivity()).onPrimaryKeyInvalid();

Java Source Code List