Android Open Source - amulet Drink Diary Fragment






From Project

Back to project page amulet.

License

The source code is released under:

MIT License

If you think the Android project amulet 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 scamell.michael.amulet;
/*from w  ww .j  a v  a 2 s.c om*/
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;


public class DrinkDiaryFragment extends ListFragment {

    public static final int REQUEST_CODE = 1234;

    private DrinkDiaryEntries dDE = new DrinkDiaryEntries();
    private DrinkDiaryEntryAdapter adapter;
    private DrinkDiaryFavouriteDrinksDialogFragment drinkDiaryFavouriteDrinksDialogFragment;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_drink_diary, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setHasOptionsMenu(true);

        dDE = DrinkDiaryEntries.createDrinkDiaryEntriesFromStorage(getActivity(), "DrinkDiaryEntries.json");
        if (dDE != null) {
            adapter = new DrinkDiaryEntryAdapter(getActivity(), dDE);
            setListAdapter(adapter);
        }

        try {
            //noinspection ConstantConditions
            getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                    if (!dDE.getSelectedStatus(position)) {
                        //set the drink entries selected status to track it for deletion
                        dDE.setSelectedStatus(position, true);
                    }
                    view.setBackgroundResource(R.color.AmuletBlue);
                    return true;
                }
            });
        } catch (Exception e) {
            Log.e("ERROR_NULL_POINTER", "Couldn't get view onLongItemClick");
            e.printStackTrace();
        }
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.action_bar_drink_diary, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // handle item selection
        switch (item.getItemId()) {
            case R.id.action_add:
                UnitCalculatorFragment unitCalculatorFragment = new UnitCalculatorFragment();
                FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                Bundle args = new Bundle();
                args.putBoolean("drink_diary_unit_calculator", true);
                unitCalculatorFragment.setArguments(args);
                fragmentManager.beginTransaction().replace(R.id.content_frame, unitCalculatorFragment, "unit_calculator").addToBackStack("Unit Calculator").commit();
                return true;
            case R.id.action_add_favourite:
                drinkDiaryFavouriteDrinksDialogFragment = new DrinkDiaryFavouriteDrinksDialogFragment();
                drinkDiaryFavouriteDrinksDialogFragment.setTargetFragment(this, REQUEST_CODE);
                drinkDiaryFavouriteDrinksDialogFragment.show(getFragmentManager(), "FavouriteDrinksDialogFragment");
                //delete drink diary item code
//            case R.id.action_delete:
//                for(int i = 0; i < dDE.getNumEntries(); i++)  {
//                    if(dDE.getEntry(i).isSelected) {
//                        dDE.removeEntry(i);
//                    }
//                }
//                dDE.saveToStorage(getActivity());
//                adapter.notifyDataSetChanged();
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == 1234) {
            dDE.removeAllEntries();
            DrinkDiaryEntries drinkDiaryEntries = DrinkDiaryEntries.createDrinkDiaryEntriesFromStorage(getActivity(), "DrinkDiaryEntries.json");
            for (int i = 0; i < drinkDiaryEntries.getNumEntries(); i++) {
                dDE.addEntry(drinkDiaryEntries.getEntry(i));
            }
            adapter.updateView(dDE);
        }
    }

}




Java Source Code List

scamell.michael.amulet.AboutDialogFragment.java
scamell.michael.amulet.AccountDetailsFragment.java
scamell.michael.amulet.ChangePasswordDialogFragment.java
scamell.michael.amulet.CoolveticaTextView.java
scamell.michael.amulet.DateAndTime.java
scamell.michael.amulet.DrinkDiaryEntries.java
scamell.michael.amulet.DrinkDiaryEntryAdapter.java
scamell.michael.amulet.DrinkDiaryEntry.java
scamell.michael.amulet.DrinkDiaryFavouriteDrinksDialogFragment.java
scamell.michael.amulet.DrinkDiaryFragment.java
scamell.michael.amulet.ExampleDrinksDialogFragment.java
scamell.michael.amulet.FavouriteDrinkUtility.java
scamell.michael.amulet.HomeFragment.java
scamell.michael.amulet.InspectionTaskActivity.java
scamell.michael.amulet.InspectionTaskInstructions1Fragment.java
scamell.michael.amulet.InspectionTaskInstructions2Fragment.java
scamell.michael.amulet.LastTaskInstructionFragment.java
scamell.michael.amulet.LoginActivity.java
scamell.michael.amulet.LogoutDialogFragment.java
scamell.michael.amulet.MainActivity.java
scamell.michael.amulet.OnPostHttpData.java
scamell.michael.amulet.OnRetrieveHttpData.java
scamell.michael.amulet.PostHTTPDataAsync.java
scamell.michael.amulet.RegisterActivity.java
scamell.michael.amulet.ResumeTaskDialogFragment.java
scamell.michael.amulet.RetrieveHTTPDataAsync.java
scamell.michael.amulet.RetrieveHTTPData.java
scamell.michael.amulet.RetrieveTaskDataFromServer.java
scamell.michael.amulet.SaveDrinkDiaryUtility.java
scamell.michael.amulet.SendDrinkDiaryEntriesToServer.java
scamell.michael.amulet.SendDrinkDiaryEntryToServer.java
scamell.michael.amulet.SendTaskEntriesToServer.java
scamell.michael.amulet.SendTaskEntryToServer.java
scamell.michael.amulet.SequenceTaskActivity.java
scamell.michael.amulet.SequenceTaskInstruction1Fragment.java
scamell.michael.amulet.SequenceTaskInstruction2Fragment.java
scamell.michael.amulet.SequenceTaskInstruction3Fragment.java
scamell.michael.amulet.SharedPreferencesWrapper.java
scamell.michael.amulet.Sound.java
scamell.michael.amulet.TaskEntries.java
scamell.michael.amulet.TaskEntry.java
scamell.michael.amulet.TaskFinishFragment.java
scamell.michael.amulet.TaskInstructionsActivity.java
scamell.michael.amulet.TaskStartCountdownFragment.java
scamell.michael.amulet.TasksFirstStartWelcomeFragment.java
scamell.michael.amulet.TasksMenuFragment.java
scamell.michael.amulet.UnitCalculatorFavouriteDrinksDialogFragment.java
scamell.michael.amulet.UnitCalculatorFragment.java
scamell.michael.amulet.UnitCalculator.java