Search in sources :

Example 1 with ListMapModel

use of com.ushahidi.android.app.models.ListMapModel 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)

Example 2 with ListMapModel

use of com.ushahidi.android.app.models.ListMapModel in project Ushahidi_Android by ushahidi.

the class ListMapFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);
    mListMapModel = new ListMapModel();
    this.dialog = new ProgressDialog(getActivity());
    this.dialog.setCancelable(true);
    this.dialog.setIndeterminate(true);
    this.dialog.setMessage(getString(R.string.please_wait));
    if (Util.isHoneycomb()) {
        listView.setLongClickable(true);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setOnItemLongClickListener(new ActionModeHelper(this, listView));
    } else {
        registerForContextMenu(listView);
    }
    // filter map list
    if (view != null) {
        if (view.mSearchMap != null) {
            view.mSearchMap.addTextChangedListener(new TextWatcher() {

                public void afterTextChanged(Editable arg0) {
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    if (!(TextUtils.isEmpty(s.toString()))) {
                        filter = s.toString();
                        mHandler.post(filterMapList);
                    } else {
                        mHandler.post(fetchMapList);
                    }
                }
            });
        }
    }
    if (savedInstanceState != null) {
        int position = savedInstanceState.getInt(STATE_CHECKED, -1);
        if (position > -1) {
            listView.setItemChecked(position, true);
        }
    }
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ListMapModel(com.ushahidi.android.app.models.ListMapModel) ProgressDialog(android.app.ProgressDialog) ActionModeHelper(com.ushahidi.android.app.helpers.ActionModeHelper)

Aggregations

ListMapModel (com.ushahidi.android.app.models.ListMapModel)2 AlertDialog (android.app.AlertDialog)1 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 ActionModeHelper (com.ushahidi.android.app.helpers.ActionModeHelper)1 AddMapView (com.ushahidi.android.app.views.AddMapView)1 ListMapView (com.ushahidi.android.app.views.ListMapView)1