Search in sources :

Example 1 with AddMapView

use of com.ushahidi.android.app.views.AddMapView in project Ushahidi_Android by ushahidi.

the class ListMapFragment method createDialog.

/**
     * Create an alert dialog
     */
public void createDialog(int d) {
    switch(d) {
        case DIALOG_SHOW_MESSAGE:
            AlertDialog.Builder messageBuilder = new AlertDialog.Builder(getActivity());
            messageBuilder.setMessage(errorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog showDialog = messageBuilder.create();
            showDialog.show();
            break;
        case DIALOG_DISTANCE:
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.select_distance);
            builder.setSingleChoiceItems(items, Preferences.selectedDistance, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    distance = items[item];
                    setDeviceLocation();
                    Preferences.selectedDistance = item;
                    // save prefrences
                    Preferences.saveSettings(getActivity());
                    dialog.cancel();
                    toastLong(R.string.finding_map);
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
            break;
        case DIALOG_CLEAR_DEPLOYMENT:
            AlertDialog.Builder clearBuilder = new AlertDialog.Builder(getActivity());
            clearBuilder.setMessage(getString(R.string.confirm_clear)).setCancelable(false).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    mHandler.post(deleteAllMaps);
                }
            }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog clearDialog = clearBuilder.create();
            clearDialog.show();
            break;
        case DIALOG_ADD_DEPLOYMENT:
            LayoutInflater factory = LayoutInflater.from(getActivity());
            final View textEntryView = factory.inflate(R.layout.add_map, null);
            final AddMapView addMapView = new AddMapView(textEntryView);
            // with existing map details
            if (edit) {
                final List<ListMapModel> listMap = mListMapModel.loadMapById(mId, mapId);
                if (listMap.size() > 0) {
                    addMapView.setMapName(listMap.get(0).getName());
                    addMapView.setMapDescription(listMap.get(0).getDesc());
                    addMapView.setMapUrl(listMap.get(0).getUrl());
                    addMapView.setMapId(listMap.get(0).getId());
                }
            }
            final AlertDialog.Builder addBuilder = new AlertDialog.Builder(getActivity());
            addBuilder.setTitle(R.string.enter_map_details).setView(textEntryView).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    // edit was selected
                    if (edit) {
                        if (!addMapView.updateMapDetails())
                            toastLong(R.string.fix_error);
                        else
                            mHandler.post(refreshMapList);
                    } else {
                        if (!addMapView.addMapDetails())
                            toastLong(R.string.fix_error);
                        else
                            mHandler.post(fetchMapList);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });
            AlertDialog deploymentDialog = addBuilder.create();
            deploymentDialog.show();
            break;
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) LayoutInflater(android.view.LayoutInflater) ListMapModel(com.ushahidi.android.app.models.ListMapModel) ListMapView(com.ushahidi.android.app.views.ListMapView) View(android.view.View) AdapterView(android.widget.AdapterView) AddMapView(com.ushahidi.android.app.views.AddMapView) ListView(android.widget.ListView) AddMapView(com.ushahidi.android.app.views.AddMapView)

Aggregations

AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 ListMapModel (com.ushahidi.android.app.models.ListMapModel)1 AddMapView (com.ushahidi.android.app.views.AddMapView)1 ListMapView (com.ushahidi.android.app.views.ListMapView)1