示例#1
0
  @Override
  public boolean onItemLongClick(final AdapterView<?> adapterView, View view, final int i, long l) {
    if (i == 0) {
      return false;
    }

    final ContactsSource.LocalContact contact =
        (ContactsSource.LocalContact) adapterView.getItemAtPosition(i);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(contact.displayName);

    if (contact.user != null) {
      builder.setItems(
          new CharSequence[] {
            getStringSafe(R.string.st_contacts_action_view),
            getStringSafe(R.string.st_contacts_action_share),
            getStringSafe(R.string.st_contacts_action_delete),
            getStringSafe(R.string.st_contacts_action_block),
            getStringSafe(R.string.st_contacts_action_block_and_delete)
          },
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
              if (i == 0) {
                viewInBookContact(contact);
              } else if (i == 1) {
                shareContact(contact);
              } else if (i == 2) {
                deleteContact(contact);
              } else if (i == 3) {
                blockContact(contact);
              } else if (i == 4) {
                blockDeleteContact(contact);
              }
            }
          });
    } else {
      builder.setItems(
          new CharSequence[] {
            getStringSafe(R.string.st_contacts_action_view),
            getStringSafe(R.string.st_contacts_action_delete),
          },
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
              if (i == 0) {
                viewInBookContact(contact);
              } else if (i == 1) {
                deleteContact(contact);
              }
            }
          });
    }
    AlertDialog contextMenu = builder.create();
    contextMenu.setCanceledOnTouchOutside(true);
    contextMenu.show();

    return true;
  }
  public void dialogAcciones(final int idComprobante) {

    // NO SE PODRÁ ANULAR, POR EL MOMENTO.
    // final String[] items = {"Imprimir", "Anular"};
    final String[] items = {"Imprimir"};
    AlertDialog.Builder dialogo = new AlertDialog.Builder(this);
    dialogo.setTitle("Seleccionar una acción");
    dialogo.setItems(
        items,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {

            switch (item) {
              case 0:
                Intent intent = new Intent(contexto, VMovil_BluetoothImprimir.class);
                intent.putExtra("idComprobante", idComprobante);
                finish();
                startActivity(intent);
                break;
              case 1:
                anularComprobante(VMovil_Venta_Comprob.this).show();

                break;
              default:
                //
                break;
            }
          }
        });
    dialogo.create();
    dialogo.show();
  }
示例#3
0
  private void showProfileDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(BaseActivity.this);
    alert.setItems(
        new String[] {
          getResources().getString(R.string.view_profile),
          getResources().getString(R.string.log_out)
        },
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
            switch (item) {
              case 0:
                showUserProfile();
                break;
              case 1:
                logOut();
                break;
            }
          }
        });

    alert.setNegativeButton(
        R.string.no,
        new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
          }
        });

    AlertDialog ad = alert.create();
    ad.show();
  }
  // Lifecycle method to handle menu option actions
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    // Allows the user to choose whether to take a new photo, or choose a photo from the Gallery
    if (id == R.id.action_camera) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      builder.setItems(
          R.array.camera_choices,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int position) {
              if (position == REQUEST_IMAGE_CAPTURE) {
                takePicture();
              } else if (position == REQUEST_IMAGE_CHOOSE) {
                Intent choosePhotoIntent = new Intent(Intent.ACTION_GET_CONTENT);
                choosePhotoIntent.addCategory(Intent.CATEGORY_OPENABLE);
                choosePhotoIntent.setType("image/*");
                startActivityForResult(choosePhotoIntent, REQUEST_IMAGE_CHOOSE);
              }
            }
          });

      AlertDialog dialog = builder.create();
      dialog.show();
    }
    // Refreshes the feed by re-loading the freed fragment (which in turn calls the API for new
    // data)
    if (id == R.id.action_refresh) {
      FragmentTransaction transaction = getFragmentManager().beginTransaction();
      transaction.replace(R.id.content_frame, new FeedFragment()).commit();
    }

    return super.onOptionsItemSelected(item);
  }
  private void showDurationDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(R.drawable.ic_mms_duration);
    String title = getResources().getString(R.string.duration_selector_title);
    builder.setTitle(title + (mPosition + 1) + "/" + mSlideshowModel.size());

    builder.setItems(
        R.array.select_dialog_items,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            if ((which >= 0) && (which < NUM_DIRECT_DURATIONS)) {
              mSlideshowEditor.changeDuration(mPosition, (which + 1) * 1000);
            } else {
              Intent intent = new Intent(SlideEditorActivity.this, EditSlideDurationActivity.class);
              intent.putExtra(EditSlideDurationActivity.SLIDE_INDEX, mPosition);
              intent.putExtra(EditSlideDurationActivity.SLIDE_TOTAL, mSlideshowModel.size());
              intent.putExtra(
                  EditSlideDurationActivity.SLIDE_DUR,
                  mSlideshowModel.get(mPosition).getDuration() / 1000); // in seconds
              startActivityForResult(intent, REQUEST_CODE_CHANGE_DURATION);
            }
            dialog.dismiss();
          }
        });

    builder.show();
  }
  /** dis:500m,1000m,2000m,5000m,默认2000 */
  void showDistanceDialog() {
    final String[] strs = {"500", "1000", "2000", "5000"};
    AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
    b.setTitle(R.string.distance_unit);
    b.setItems(
        strs,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            // TODO 根据分类进行请求
            rb_sort1.setText(strs[which]);
            mDis = strs[which];
            dialog.cancel();
          }
        });
    b.setOnCancelListener(
        new OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {
            // TODO Auto-generated method stub
            getFirstData();
          }
        });
    b.show();
  }
  // Adding photo to a contact.
  public void addPhoto() {
    // Button for the alert dialog
    final CharSequence[] items = {"Choose from Library", "Cancel"};
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // If editing the add photo will be edit photo
    if (updatingContact) {
      builder.setTitle("Edit Photo");
    } else {
      builder.setTitle("Add Photo");
    }
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int item) {
            if (items[item].equals("Choose from Library")) {
              // Open the library and filter the content only to images
              Intent intent =
                  new Intent(
                      Intent.ACTION_PICK,
                      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
              intent.setType("image/*");
              ((CreateContactActivity) context)
                  .startActivityForResult(
                      Intent.createChooser(intent, "Select File"), REQUEST_LIBRARY);
            } else if (items[item].equals("Cancel")) {
              // Dismiss the dialog when a user presses cancel.
              dialog.dismiss();
            }
          }
        });
    // Showing the alert dialog
    builder.show();
  }
  public void onButtonPayWithCreditCardClicked(View view) {
    final PayPalCard lastUsedCard = PayPalCard.getLastUsedCard(this);
    if (lastUsedCard != null && !lastUsedCard.hasVaultStorageExpired()) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      if (this.paypalEnvironment == PayPalCard.Environment.SANDBOX) {
        builder.setTitle("Payment Source (Sandbox)");
      } else {
        builder.setTitle("Payment Source");
      }

      builder.setItems(
          new String[] {"Pay with new card", "Pay with card ending " + lastUsedCard.getLastFour()},
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int itemIndex) {
              if (itemIndex == 0) {
                payWithNewCard();
              } else {
                payWithExistingCard(lastUsedCard);
              }
            }
          });
      builder.show();
    } else {
      payWithNewCard();
    }
  }
示例#9
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.shutdown_type_title);
    builder.setIcon(R.drawable.shutdown);
    builder.setItems(
        R.array.shutdown_options,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              case 0:
                // reboot
                mShutdownDialogListener.onRebootClick(dialog);
                break;
              case 1:
                // halt
                mShutdownDialogListener.onHaltClick(dialog);
              default:
                break;
            }
          }
        });
    return builder.create();
  }
示例#10
0
 public void showAuthenticateDialog() {
   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setTitle("Authorize first");
   builder.setItems(
       new String[] {"Login", "Register"},
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           switch (which) {
             case 0:
               Intent intent = new Intent(MainActivity.this, LoginActivity.class);
               startActivityForResult(intent, AUTHENTICATION_REQUEST);
               break;
             case 1:
               intent = new Intent(MainActivity.this, RegistrationActivity.class);
               startActivityForResult(intent, AUTHENTICATION_REQUEST);
               break;
           }
         }
       });
   builder.setOnCancelListener(
       new DialogInterface.OnCancelListener() {
         @Override
         public void onCancel(DialogInterface dialog) {
           showUsersFragment();
         }
       });
   builder.show();
 }
示例#11
0
 public void delayDialogSettings() {
   AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
   builder.setTitle("Choose an Option");
   builder.setItems(time_options, actionListener);
   builder.setNegativeButton("Cancel", null);
   actions = builder.create();
 }
示例#12
0
  // 在视图中,长按用户信息条目弹出的对话框
  public static void handleContactItemLongClick(final UserEntity contact, final Context ctx) {
    if (contact == null || ctx == null) {
      return;
    }
    AlertDialog.Builder builder =
        new AlertDialog.Builder(
            new ContextThemeWrapper(ctx, android.R.style.Theme_Holo_Light_Dialog));
    builder.setTitle(contact.getMainName());
    String[] items =
        new String[] {ctx.getString(R.string.check_profile), ctx.getString(R.string.start_session)};

    final int userId = contact.getPeerId();
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              case 0:
                IMUIHelper.openUserProfileActivity(ctx, userId);
                break;
              case 1:
                IMUIHelper.openChatActivity(ctx, contact.getSessionKey());
                break;
            }
          }
        });
    AlertDialog alertDialog = builder.create();
    alertDialog.setCanceledOnTouchOutside(true);
    alertDialog.show();
  }
  private void changeVideoQuality(View anchor) {
    String ytvid = mMp.getActiveVideoYtId();
    if (null == ytvid) return;

    YTHacker hack = RTState.get().getCachedYtHacker(ytvid);
    final ArrayList<Integer> opts = new ArrayList<Integer>();
    int i = 0;
    for (Utils.PrefQuality q : Utils.PrefQuality.values()) {
      if (mVQuality != q
          && null != hack
          && null != hack.getVideo(YTPlayer.mapPrefToQScore(q), true)) opts.add(q.getText());
    }

    final CharSequence[] items = new CharSequence[opts.size()];
    for (i = 0; i < items.length; i++) items[i] = getResources().getText(opts.get(i));

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.set_video_quality);
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            doChangeVideoQuality(Utils.PrefQuality.getMatchingQuality(opts.get(item)));
          }
        });
    builder.create().show();
  }
示例#14
0
  private void uploadHeadPhoto() {
    AlertDialog.Builder builder = new Builder(this);
    builder.setTitle(R.string.dl_title_upload_photo);
    builder.setItems(
        new String[] {
          getString(R.string.dl_msg_take_photo), getString(R.string.dl_msg_local_upload)
        },
        new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            switch (which) {
              case 0:
                Toast.makeText(
                        UserProfileActivity.this,
                        getString(R.string.toast_no_support),
                        Toast.LENGTH_SHORT)
                    .show();
                break;
              case 1:
                Intent pickIntent = new Intent(Intent.ACTION_PICK, null);
                pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                startActivityForResult(pickIntent, REQUESTCODE_PICK);
                break;
              default:
                break;
            }
          }
        });
    builder.create().show();
  }
  private boolean shareComic() {

    if (PrefHelper.shareImage()) {
      shareComicImage();
      return true;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setItems(
        R.array.share_dialog,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              case 0:
                shareComicImage();
                break;
              case 1:
                shareComicUrl();
                break;
            }
          }
        });
    AlertDialog alert = builder.create();
    alert.show();
    return true;
  }
示例#16
0
  // Helper function to oncreate, get an alertdialog for showing available logs
  private AlertDialog getPrevLogsAlertDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Previous logs");
    final CharSequence[] daysavailable = availableDayLogs();
    builder.setItems(
        daysavailable,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dayLogFileNameSuffix = getFilenameFromListpos(which);

            // Update the date fields passed on to dayoverviewactivity
            String[] daylogfilenamesplit = dayLogFileNameSuffix.split("_");
            int year = Integer.valueOf(daylogfilenamesplit[0]);
            int monthOfYear = Integer.valueOf(daylogfilenamesplit[1]) - 1;
            int dayOfMonth = Integer.valueOf(daylogfilenamesplit[2]);

            Calendar c = Calendar.getInstance();
            c.set(year, monthOfYear, dayOfMonth);
            selecteddate = c.getTime();

            // Call the resume day button which handles the dayoverview activity starting
            resumeDayButton.callOnClick();
          }
        });
    return builder.create();
  }
  /** On item clicked */
  @Override
  public void onItemClick(AdapterView<?> list, View item, int position, long id) {
    final String command = adapter.getItem(position);

    String[] items = {getResources().getString(R.string.action_remove)};

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(command);
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            switch (item) {
              case 0: // Remove
                adapter.remove(command);
                commands.remove(command);
                okButton.setEnabled(true);
                break;
            }
          }
        });
    AlertDialog alert = builder.create();
    alert.show();
  }
  protected void capturePhoto() {
    final String takePhoto = getActivity().getString(R.string.take_photo),
        chooseFromLibrary = getActivity().getString(R.string.choose_from_library),
        cancel = getActivity().getString(R.string.cancel),
        selectProfilePhoto = getActivity().getString(R.string.select_profile_photo);

    final String[] items = {takePhoto, chooseFromLibrary, cancel};

    AlertDialog.Builder builder = new AlertDialog.Builder(getMainActivity());
    builder.setTitle(selectProfilePhoto);
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            String menuItemSelected = items[item];
            if (menuItemSelected.equals(takePhoto)) {

              Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(profilePhotoFile()));
              startActivityForResult(intent, REQUEST_CAMERA_CODE);
            } else if (menuItemSelected.equals(chooseFromLibrary)) {
              Intent intent = new Intent(Intent.ACTION_PICK);
              intent.setType("image/*");
              startActivityForResult(intent, REQUEST_GALLERY_CODE);
            } else if (menuItemSelected.equals(cancel)) {
              dialog.dismiss();
            }
          }
        });
    builder.show();
  }
  @Override
  public void onFilePicked(String path, String mode) {
    Log.i(TAG, "selected dir path = " + path);

    mContext = this;

    if ("restore".equals(mode)) {
      final File file = new File(path);
      final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
      alertDialogBuilder.setTitle(file.getName());
      alertDialogBuilder.setMessage(R.string.do_restore);
      alertDialogBuilder.setPositiveButton(
          android.R.string.yes,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              SystemCommand.restore_rom(file.getPath());
              SystemCommand.reboot("recovery");
            }
          });
      alertDialogBuilder.setNegativeButton(android.R.string.no, null);
      alertDialogBuilder.create().show();
    } else if ("manage".equals(mode)) {
      final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
      final CharSequence[] actions = {
        getText(R.string.backup_manage_rename), getText(R.string.backup_manage_delete)
      };

      mSelectedDir = new File(path);
      alertDialogBuilder.setTitle(mSelectedDir.getName());
      alertDialogBuilder.setItems(actions, mOnClickListener);
      alertDialogBuilder.create().show();
    }
  }
示例#20
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
      case R.id.action_logout:
        ParseUser.logOut();
        navigateToLogin();
        break;
      case R.id.action_edit_friends:
        Intent intent = new Intent(this, EditFriendsActivity.class);
        startActivity(intent);
        break;
      case R.id.action_camera:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setItems(R.array.camera_choices, mDialogListener);
        AlertDialog dialog = builder.create();
        dialog.show();
        break;
    }

    return super.onOptionsItemSelected(item);
  }
  private void selectImage() {
    final CharSequence[] items = {"Take Photo", "Choose from Library", "Cancel"};

    AlertDialog.Builder builder = new AlertDialog.Builder(UpdateDetailsActivity.this);
    builder.setTitle("Add Photo!");
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            if (items[item].equals("Take Photo")) {
              Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              startActivityForResult(intent, REQUEST_CAMERA);
            } else if (items[item].equals("Choose from Library")) {
              Intent intent =
                  new Intent(
                      Intent.ACTION_PICK,
                      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
              intent.setType("image/*");
              startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
            } else if (items[item].equals("Cancel")) {
              dialog.dismiss();
            }
          }
        });
    builder.show();
  }
        public boolean onChildClick(
            ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
          if (groupPosition == 0) {

            final String friendHUID = children.get(0).get(childPosition).get("HUID");
            final int position = childPosition;

            AlertDialog.Builder builder = new AlertDialog.Builder(FriendListActivity.this);
            builder.setCancelable(true);
            builder.setTitle("Options");
            builder.setItems(
                R.array.req_array,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    if (which == 0) {
                      acceptFriend(prefs.getString("huid", ""), friendHUID, "Y");

                      children.get(0).remove(position);
                      fla.notifyDataSetChanged();
                    } else if (which == 1) {
                      acceptFriend(prefs.getString("huid", ""), friendHUID, "N");

                      children.get(0).remove(position);
                      fla.notifyDataSetChanged();
                    }
                  }
                });
            builder.create();
            builder.show();
          } else {

          }
          return true;
        }
示例#23
0
  private void showMenuDialog(final FileEncryption fileEncryption) {
    final CharSequence[] operations = {
      getString(R.string.file_delete),
      getString(R.string.file_recover),
      getString(R.string.file_detail)
    };
    final CharSequence[] operationsRes = {
      getString(R.string.file_deleted),
      getString(R.string.file_recovered),
      getString(R.string.file_detail_show)
    };
    final MenuOp[] menuOps = {
      new MenuDelete(this), new MenuRecover(this), new MenuDetail(this),
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setItems(
        operations,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
            boolean operate = menuOps[item].operate(fileEncryption);
            if (operate) {
              Toast.makeText(getApplicationContext(), operationsRes[item], Toast.LENGTH_SHORT)
                  .show();
              if (item < 2) {
                updateDetailFileInfo(currentSelectedDir());
              }
            }
          }
        });
    AlertDialog alert = builder.create();
    alert.show();
  }
示例#24
0
  private void showLocaleDialog() {
    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setTitle(getResources().getString(R.string.KEY_PREF_LANGUAGE_TITLE));

    Configuration config = getResources().getConfiguration();
    String defaultLangName = config.locale.getDefault().getDisplayName();
    String defaultLangCode = config.locale.getDefault().getCountry();

    String[] langs = getResources().getStringArray(R.array.languages);
    langs[0] = langs[0] + " (" + defaultLangName + ")";

    ad.setItems(
        langs,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {

            String[] locs = getResources().getStringArray(R.array.languages_values);

            if (which < locs.length) {
              ImApp.setNewLocale(WelcomeActivity.this.getBaseContext(), locs[which]);

              Intent intent = getIntent();
              finish();
              startActivity(intent);
            }
          }
        });

    ad.show();
  }
示例#25
0
 @OnClick(R.id.editGroupPhoto)
 public void editPhoto() {
   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setItems(R.array.camera_choices, mDialogInterface);
   AlertDialog dialog = builder.create();
   dialog.show();
 }
  public Dialog createDevicesDialog() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle("Select device");

    // ペアリング済みデバイスをダイアログのリストに設定する。
    Set<BluetoothDevice> pairedDevices = bluetoothClient.getPairedDevices();
    final BluetoothDevice[] devices = pairedDevices.toArray(new BluetoothDevice[0]);
    String[] items = new String[devices.length];
    for (int i = 0; i < devices.length; i++) {
      items[i] = devices[i].getName();
    }

    alertDialogBuilder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            // 選択されたデバイスを通知する。そのまま接続開始。
            bluetoothClient.doConnect(devices[which]);
          }
        });
    alertDialogBuilder.setCancelable(false);
    return alertDialogBuilder.create();
  }
示例#27
0
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
      case 0:
        UserItems = UserList.toArray(new CharSequence[UserList.size()]);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Select the user you woud like to remove");
        builder.setItems(
            UserItems,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int item) {
                mDbHelper.deleteTask(UserItems[item]);

                // refresh activity
                Intent intent = getIntent();
                finish();
                startActivity(intent);
              }
            });
        AlertDialog alert = builder.create();
        return alert;
    }
    return null;
  }
  /**
   * Allows the user to add a picture from the gallery or take a new picture and add it as an
   * annotation.
   */
  public void addImage() {
    final CharSequence[] options = {"Take Photo", "Choose from Gallery", "Cancel"};

    AlertDialog.Builder builder = new AlertDialog.Builder(FragmentViewActivity.this);
    builder.setTitle("Add Photo!");
    builder.setItems(
        options,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
              Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
              intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
              startActivityForResult(intent, 1);
            } else if (options[item].equals("Choose from Gallery")) {
              Intent intent =
                  new Intent(
                      Intent.ACTION_PICK,
                      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
              startActivityForResult(intent, 2);

            } else if (options[item].equals("Cancel")) {
              dialog.dismiss();
            }
          }
        });
    builder.show();
  }
示例#29
0
  public void doActionOnAlert(View view) {
    // Ouvre une fenêtre de dialogue pour choisir une action à effectué sur l'alerte
    Resources res = getResources();
    final CharSequence[] items = res.getStringArray(R.array.list_action_alert);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.title_list_alert_action));
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
            switch (item) {
              case OMW:
                manager.updateAlertOMW(currentAlert.getId());
                break;
              case POLICE:
                call911();
                break;
              case SAMU:
                callSamu();
                break;
              case WRONG_ALERT:
                manager.updateAlertBullshit(currentAlert.getId());
                break;
            }
          }
        });
    AlertDialog alert = builder.create();
    alert.show();
  }
  private void selectImage() {

    final CharSequence[] options = {"Tirar Foto", "Foto da Galeria", "Cancelar"};
    AlertDialog.Builder builder = new AlertDialog.Builder(EditarTarefa_Activity2.this);
    builder.setTitle("Adicionar Foto");

    builder.setItems(
        options,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int item) {

            if (options[item].equals("Tirar Foto")) {
              path =
                  Environment.getExternalStorageDirectory().getAbsolutePath()
                      + "/TEAjuda/Imagens/"
                      + System.currentTimeMillis()
                      + ".jpg";
              Intent irParaCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              Uri localFoto = Uri.fromFile(new File(path));
              irParaCamera.putExtra(MediaStore.EXTRA_OUTPUT, localFoto);
              startActivityForResult(irParaCamera, 1);
            } else if (options[item].equals("Foto da Galeria")) {
              Intent intent =
                  new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
              startActivityForResult(intent, 2);
            } else if (options[item].equals("Cancelar")) {
              dialog.dismiss();
            }
          }
        });

    builder.show();
  }