Android Open Source - amulet Unit Calculator Favourite Drinks Dialog 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  w  w .j  a v a  2 s.com
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

public class UnitCalculatorFavouriteDrinksDialogFragment extends DialogFragment {

    private final int DRINK_NAME = 0;
    private final int DRINK_TYPE = 1;
    private final int DRINK_VOLUME = 2;
    private final int DRINK_VOLUME_TYPE = 3;
    private final int DRINK_QUANTITY = 4;
    private final int DRINK_UNITS = 5;
    private final int DRINK_ABV = 6;
    private final int DRINK_VOLUME_TYPE_POS = 7;
    private final int DRINK_TYPE_POS = 8;

    private AlertDialog aD;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Favourite Drinks");
        ListView favouriteList = new ListView(getActivity());
        List<String> favouriteTitlesList = FavouriteDrinkUtility.getFavouriteDrinkTitles(getActivity());
        String[] favouriteTitlesArray = favouriteTitlesList.toArray(new String[favouriteTitlesList.size()]);
        ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, favouriteTitlesArray);
        favouriteList.setAdapter(modeAdapter);
        favouriteList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView item = (TextView) view;
                if (!item.getText().toString().equals("No Favourite Drinks")) {
                    String[] favouriteDrink = FavouriteDrinkUtility.getFavouriteDrink(getActivity(), position);
                    Intent intent = new Intent();
                    intent.putExtra("drinkName", favouriteDrink[DRINK_NAME]);
                    intent.putExtra("drinkType", favouriteDrink[DRINK_TYPE]);
                    intent.putExtra("drinkVolume", favouriteDrink[DRINK_VOLUME]);
                    intent.putExtra("drinkVolumeType", favouriteDrink[DRINK_VOLUME_TYPE]);
                    intent.putExtra("drinkQuantity", Integer.valueOf(favouriteDrink[DRINK_QUANTITY]));
                    intent.putExtra("drinkUnits", favouriteDrink[DRINK_UNITS]);
                    intent.putExtra("drinkABV", favouriteDrink[DRINK_ABV]);
                    intent.putExtra("drinkVolumeTypePos", Integer.valueOf(favouriteDrink[DRINK_VOLUME_TYPE_POS]));
                    intent.putExtra("drinkTypePos", Integer.valueOf(favouriteDrink[DRINK_TYPE_POS]));
                    getTargetFragment().onActivityResult(getTargetRequestCode(), 4444, intent);
                }
                aD.dismiss();
            }
        });
        builder.setView(favouriteList);
        aD = builder.create();
        aD.show();

        return aD;
    }
}




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