Android Open Source - sqlite-provider Find Fireworks From One Shop 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;
/*from  w  w  w .j  a va  2  m*/
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.domain.Shop;
import com.novoda.sqliteprovider.demo.ui.base.NovodaActivity;
import com.novoda.sqliteprovider.demo.ui.input.OnPrimaryKeyInputError;

import java.util.List;

public class FindFireworksFromOneShopFragment extends Fragment {

    public interface OnShopFound {
        void onShopFound(Shop shop);

    private EditText primaryKeyEditText;

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

        primaryKeyEditText = (EditText) root.findViewById(;

        return root;

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

    public void onFindShopFireworks(){
            try {
                int primaryKey = getPrimaryKey();

                List<Firework> fireworks = getFireworks(primaryKey);

                Shop shop = new Shop("", "Below are the Fireworks with shop primary key: "+ primaryKey, fireworks);

            } catch (NumberFormatException e) {

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

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

    private List<Firework> getFireworks(int primaryKey) {
        return ((NovodaActivity) getActivity()).getApp().getFireworkReader().getFireworksForShop(primaryKey);

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

    private void informActivityShopFound(Shop shop) {
        if(getActivity() instanceof OnShopFound){
            ((OnShopFound) getActivity()).onShopFound(shop);

Java Source Code List