Example #1
0
  // Alert dialog block
  public void onButtonClick(View v) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    if (spnService.getSelectedItem().toString().equalsIgnoreCase("cafe")) {
      builder.setTitle("Cafe List");
      servList = cafeList;
    } else if (spnService.getSelectedItem().toString().equalsIgnoreCase("pho")) {
      builder.setTitle("Pho List");
      servList = cafeList;
    } else if (spnService.getSelectedItem().toString().equalsIgnoreCase("ATM")) {
      builder.setTitle("ATM List");
      servList = ATMList;
    } else if (spnService.getSelectedItem().toString().equalsIgnoreCase("Fuel")) {
      builder.setTitle("Fuel List");
      servList = fuelList;
    }

    builder.setSingleChoiceItems(
        servList,
        -1,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            checkedItem = which;
            selectedPlace = servList[which].toString();
            dialog.cancel();
            if (selectedPlace.equalsIgnoreCase("cafe1")) {
              if (curLocation == null) {
                Log.d("Veng", "GPS not found");
                AlertDialog.Builder warn = new AlertDialog.Builder(QTPlaceActivity.this);
                warn.setTitle("GPS Error!")
                    .setMessage("Your GPS is not enabled")
                    .setPositiveButton(
                        "OK",
                        new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                          }
                        });
                warn.show();

              } else {
                OverlayItem overlayItem = new OverlayItem(curLocation, "Hello", "You're here!");
                itemizeOverlay.AddOverlay(overlayItem);
                mapOverlays.add(itemizeOverlay);
                mapController.animateTo(curLocation);
                Route route =
                    directions(
                        curLocation,
                        new GeoPoint((int) (37.422006 * 1E6), (int) (-122.074095 * 1E6)));
                RouteOverlay routeOverlay = new RouteOverlay(route, Color.RED);
                mapView.getOverlays().add(routeOverlay);
                Log.d("VenG", "distance");
                txtDistance.setText(Integer.toString(route.getDistance()));
              }
            }
          }
        });
    AlertDialog alert_dialog = builder.create();
    alert_dialog.show();
    alert_dialog.getListView().setItemChecked(checkedItem, true);
  }
Example #2
0
  @Override
  protected void onPrepareDialog(int id, Dialog dialog) {

    AlertDialog alertDialog = (AlertDialog) dialog;
    ArrayAdapter<CharSequence> adapter;
    switch (id) {
      case DIALOG_XODIT:
      case DIALOG_XODIT_EDIT:
      case DIALOG_SORT_BY_XODIL:
        mCurentDialogList = utils.getSortXodilList();
        adapter =
            new ArrayAdapter<CharSequence>(
                this,
                android.R.layout.select_dialog_item,
                android.R.id.text1,
                utils.getString(mCurentDialogList));
        alertDialog.getListView().setAdapter(adapter);
        break;

      case DIALOG_PODTVERDIL:
        int xodit = utils.getAllList().get(0).getPlayerXodit();
        mCurentDialogList = utils.getPodtverdilList(xodit);
        adapter =
            new ArrayAdapter<CharSequence>(
                this,
                android.R.layout.select_dialog_item,
                android.R.id.text1,
                utils.getString(mCurentDialogList));
        alertDialog.getListView().setAdapter(adapter);
        break;

      case DIALOG_SORT_BY_PODTVERDIL:
        mCurentDialogList = utils.getSortPodtverdilList();
        adapter =
            new ArrayAdapter<CharSequence>(
                this,
                android.R.layout.select_dialog_item,
                android.R.id.text1,
                utils.getString(mCurentDialogList));
        alertDialog.getListView().setAdapter(adapter);
        break;
      default:
        super.onPrepareDialog(id, dialog);
    }
  }
 protected void showInternal() {
   mDialog.show();
   mDialog.setOnDismissListener(this);
   mDialog
       .getListView()
       .setOnItemClickListener(
           new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               onListItemClick(position);
             }
           });
 }
 @Override
 public Dialog onCreateDialog(final Bundle savedInstanceState) {
   mAdapter = new FilesAdapter(getActivity());
   final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
   builder.setAdapter(mAdapter, this);
   builder.setTitle(R.string.pick_file);
   if (isPickDirectory()) {
     builder.setPositiveButton(android.R.string.ok, this);
   }
   final AlertDialog dialog = builder.create();
   final ListView listView = dialog.getListView();
   listView.setOnItemClickListener(this);
   return dialog;
 }
 private void setCheckedAlllanguageItem(
     final boolean[] temp, boolean isChecked, AlertDialog languageDialog) {
   boolean alllanguage = true;
   for (int i = 1; i < temp.length; ++i) {
     if (!temp[i]) {
       alllanguage = false;
       break;
     }
   }
   MmsLog.d(LOG_TAG, "All language alllanguage " + alllanguage);
   if (alllanguage) {
     ListView items = languageDialog.getListView();
     items.setItemChecked(0, isChecked);
     temp[0] = true;
   }
 }
  @Override
  protected void showDialog(final Bundle state) {
    super.showDialog(state);
    final AlertDialog dialog = (AlertDialog) getDialog();
    final ListView listView = dialog.getListView();
    final ListAdapter adapter = listView.getAdapter();
    final WrapperListAdapterImpl wrapperAdapter = createWrapperAdapter(adapter);

    // Adjust the selection because resetting the adapter loses the selection.
    final int selectedPosition = getValueIndex();
    listView.setAdapter(wrapperAdapter);
    if (selectedPosition != -1) {
      listView.setItemChecked(selectedPosition, true);
      listView.setSelection(selectedPosition);
    }
  }
  @Override
  public void onClick(DialogInterface aDialog, int aWhich) {
    ThreadUtils.assertOnUiThread();
    JSONObject ret = new JSONObject();
    try {
      int button = -1;
      ListView list = mDialog.getListView();
      if (list != null || mSelected != null) {
        button = aWhich;
        if (mSelected != null) {
          JSONArray selected = new JSONArray();
          for (int i = 0; i < mSelected.length; i++) {
            selected.put(mSelected[i]);
          }
          ret.put("button", selected);
        } else {
          ret.put("button", button);
        }
      } else {
        switch (aWhich) {
          case DialogInterface.BUTTON_POSITIVE:
            button = 0;
            break;
          case DialogInterface.BUTTON_NEUTRAL:
            button = 1;
            break;
          case DialogInterface.BUTTON_NEGATIVE:
            button = 2;
            break;
        }
        ret.put("button", button);
      }
      if (mInputs != null) {
        for (int i = 0; i < mInputs.length; i++) {
          ret.put(mInputs[i].getId(), mInputs[i].getValue());
        }
      }
    } catch (Exception ex) {
      Log.i(LOGTAG, "Error building return: " + ex);
    }

    if (mDialog != null) {
      mDialog.dismiss();
    }

    finishDialog(ret.toString());
  }
 @Override
 protected void onPrepareDialog(int id, Dialog dialog) {
   switch (id) {
     case DIALOG_LOCATION:
       ArrayAdapter<CharSequence> adapter =
           new ArrayAdapter<CharSequence>(
               this,
               android.R.layout.select_dialog_singlechoice,
               android.R.id.text1,
               locationNames);
       AlertDialog ad = (AlertDialog) dialog;
       ad.getListView().setAdapter(adapter);
       break;
     default:
       super.onPrepareDialog(id, dialog);
   }
 }
Example #9
0
  @Override
  protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
      case 0:
        UserList.clear();
        Cursor c = mDbHelper.getAllRows();
        startManagingCursor(c);
        c.moveToFirst();
        for (int i = 0; i < c.getCount(); i++) {
          UserList.add(c.getString(c.getColumnIndex("userfname")));
          c.moveToNext();
        }
        UserItems = UserList.toArray(new CharSequence[UserList.size()]);
        AlertDialog ad = (AlertDialog) dialog;

        ad.getListView()
            .setAdapter(
                new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, UserList));
    }
  }
  @Override
  protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
      case TIME_DIALOG_ID:
        ((TimePickerDialog) dialog)
            .updateTime(mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE));
        break;
      case DATE_DIALOG_ID:
        ((DatePickerDialog) dialog)
            .updateDate(
                mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH),
                mCalendar.get(Calendar.DAY_OF_MONTH));
        break;

      case DIALOG_MULTIPLE_CATEGORY:
        final AlertDialog alert = (AlertDialog) dialog;
        final ListView list = alert.getListView();
        // been
        // selected, then uncheck
        // selected categories
        if (mVectorCategories.size() > 0) {
          for (String s : mVectorCategories) {
            try {
              // @inoran fix
              if (list != null) {
                list.setItemChecked(mCategoryLength - Integer.parseInt(s), true);
              }
            } catch (NumberFormatException e) {
              log("NumberFormatException", e);
            }
          }
        } else {
          if (list != null) {
            list.clearChoices();
          }
        }

        break;
    }
  }
 @Override
 protected void showDialog(Bundle state) {
   super.showDialog(state);
   final AlertDialog dialog = (AlertDialog) getDialog();
   final ListView listView = dialog.getListView();
   listView.setItemsCanFocus(false);
   listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
   listView.setOnItemClickListener(
       new AdapterView.OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
           final AppViewHolder holder = (AppViewHolder) view.getTag();
           final boolean isChecked = !holder.checkBox.isChecked();
           holder.checkBox.setChecked(isChecked);
           if (isChecked) {
             mPreferenceChanged |= mNewValues.add(mEntryValues[position].toString());
           } else {
             mPreferenceChanged |= mNewValues.remove(mEntryValues[position].toString());
           }
         }
       });
 }
  @Override
  public void notifyOrientationChanged(int orientation) {
    if (mInitialOrientation == -1) mInitialOrientation = orientation;
    if (mOrientation == orientation) return;

    mOrientation = orientation;
    if (mResolutionDialog != null) {
      ((ViewGroup) mNumberPicker.getParent().getParent().getParent().getParent())
          .animate()
          .rotation(orientation - mInitialOrientation)
          .setDuration(300)
          .start();
    }

    if (mWidgetsDialog != null) {
      ((ViewGroup) mWidgetsDialog.getListView().getParent().getParent().getParent().getParent())
          .animate()
          .rotation(orientation - mInitialOrientation)
          .setDuration(300)
          .start();
    }
  }
  private void openWidgetsToggleDialog() {
    final List<WidgetBase> widgets = mCapabilities.getWidgets();
    List<String> widgetsName = new ArrayList<String>();

    // Construct a list of widgets
    for (WidgetBase widget : widgets) {
      if (widget.getClass().getName().contains("SettingsWidget")) continue;
      widgetsName.add(widget.getToggleButton().getHintText());
    }

    CharSequence[] items = widgetsName.toArray(new CharSequence[widgetsName.size()]);

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setTitle(mContext.getString(R.string.widget_settings_choose_widgets));
    builder
        .setMultiChoiceItems(
            items,
            null,
            new DialogInterface.OnMultiChoiceClickListener() {
              // indexSelected contains the index of item (of which checkbox checked)
              @Override
              public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
                widgets.get(indexSelected).setHidden(!isChecked);
              }
            })
        // Set the action buttons
        .setPositiveButton(
            "OK",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                // Store the widget visibility status in SharedPreferences, using the
                // widget class name as key
                for (WidgetBase widget : widgets) {
                  if (widget.getClass().getName().contains("SettingsWidget")) {
                    continue;
                  }

                  SettingsStorage.storeVisibilitySetting(
                      mContext, widget.getClass().getName(), !widget.isHidden());
                }
              }
            })
        .setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                // Restore visibility status from storage
                for (WidgetBase widget : widgets) {
                  if (widget.getClass().getName().contains("SettingsWidget")) {
                    continue;
                  }

                  widget.setHidden(
                      !SettingsStorage.getVisibilitySetting(mContext, widget.getClass().getName()));
                }
              }
            });

    mWidgetsDialog = builder.create();
    mWidgetsDialog.show();
    for (int i = 0; i < widgets.size(); i++) {
      mWidgetsDialog.getListView().setItemChecked(i, !widgets.get(i).isHidden());
    }
    ((ViewGroup) mWidgetsDialog.getListView().getParent().getParent().getParent())
        .animate()
        .rotation(mOrientation)
        .setDuration(300)
        .start();
  }
 @Override
 public void onClick(DialogInterface dialog, int which) {
   AlertDialog alert = (AlertDialog) dialog;
   int position = alert.getListView().getCheckedItemPosition();
   alertPositiveListener.onLayersPositiveClick(position);
 }