package com.example.download;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;

public class ChooseFileDialogFragment extends DialogFragment {
    private FileChooserListener listener;
    private String[] itemNames = { "Android", "Apache", "Error" };
    private String[] itemValues = {
            "http://www.android.com/images/brand/droid.gif",
            "http://www.apache.org/images/feather.gif",
            "http://www.apache.org/images/feather.gifxx" };
    
   @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            listener = (FileChooserListener) activity;
        }
        catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement FileChooserListener");
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                getActivity());
        builder.setTitle(R.string.chooseFile);
        builder.setItems(itemNames,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface di, int which) {
                        String url = itemValues[which];
                        listener.onFileChosen(url);
                    }
                });
        return builder.create();
    }
}