/*
  * (non-Javadoc)
  * @see android.app.DialogFragment#onCreateDialog(android.os.Bundle)
  */
 @Override
 public Dialog onCreateDialog(Bundle savedInstanceState) {
   View header = View.inflate(getActivity(), R.layout.context_menu_header, null);
   TextView title = (TextView) header.findViewById(R.id.context_menu_title);
   title.setText(getString(R.string.place_correction_choose_method));
   AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
   builder
       .setCustomTitle(header)
       .setItems(
           R.array.place_correction_choice_array,
           new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
               // The 'which' argument contains the index position
               // of the selected item
               Log.d(TAG, "onClick(): which: " + which);
               String[] optionsArray =
                   getActivity()
                       .getResources()
                       .getStringArray(R.array.place_correction_choice_array);
               String whichOption = optionsArray[which];
               if (whichOption.equals(
                   getActivity().getString(R.string.place_correction_option_manual))) {
                 activity.onManualCorrectionSelected();
               } else if (whichOption.equals(
                   getActivity().getString(R.string.place_correction_option_candidates))) {
                 activity.onCandidatesListCorrectionSelected();
               }
             }
           });
   return builder.create();
 }
示例#2
0
  private AlertDialog buildInfoDialog(String title, List<String> messages) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    LayoutInflater inflater = getLayoutInflater();
    TextView titleDialogView =
        (TextView) inflater.inflate(R.layout.dialog_generic_title, null, false);
    titleDialogView.setText(title);

    TextView bodyDialogView =
        (TextView) inflater.inflate(R.layout.dialog_generic_body, null, false);
    String dialogMessage = "Errors: \n\n";

    for (String message : messages) {
      dialogMessage += message + "\n\n";
    }

    bodyDialogView.setText(dialogMessage);

    builder.setCustomTitle(titleDialogView);
    builder.setView(bodyDialogView);

    builder.setPositiveButton(
        "OK",
        new Dialog.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
          }
        });

    return builder.create();
  }
 public void show(IBinder ibinder) {
   Object obj = mMenu;
   android.app.AlertDialog.Builder builder =
       new android.app.AlertDialog.Builder(((MenuBuilder) (obj)).getContext());
   mPresenter =
       new ListMenuPresenter(
           android.support.v7.appcompat.R.layout.abc_list_menu_item_layout,
           android.support.v7.appcompat.R.style.Theme_AppCompat_CompactMenu_Dialog);
   mPresenter.setCallback(this);
   mMenu.addMenuPresenter(mPresenter);
   builder.setAdapter(mPresenter.getAdapter(), this);
   View view = ((MenuBuilder) (obj)).getHeaderView();
   if (view != null) {
     builder.setCustomTitle(view);
   } else {
     builder
         .setIcon(((MenuBuilder) (obj)).getHeaderIcon())
         .setTitle(((MenuBuilder) (obj)).getHeaderTitle());
   }
   builder.setOnKeyListener(this);
   mDialog = builder.create();
   mDialog.setOnDismissListener(this);
   obj = mDialog.getWindow().getAttributes();
   obj.type = 1003;
   if (ibinder != null) {
     obj.token = ibinder;
   }
   obj.flags = ((android.view.WindowManager.LayoutParams) (obj)).flags | 0x20000;
   mDialog.show();
 }
  private void showChangeAccountConfirmAlertDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

    View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
    TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
    titleTextView.setText(
        getString(R.string.preferences_dialog_change_account_title, getSyncAccountName(this)));
    TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
    subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
    dialogBuilder.setCustomTitle(titleView);

    CharSequence[] menuItemArray =
        new CharSequence[] {
          getString(R.string.preferences_menu_change_account),
          getString(R.string.preferences_menu_remove_account),
          getString(R.string.preferences_menu_cancel)
        };
    dialogBuilder.setItems(
        menuItemArray,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
              showSelectAccountAlertDialog();
            } else if (which == 1) {
              removeSyncAccount();
              refreshUI();
            }
          }
        });
    dialogBuilder.show();
  }
  private void showSelectAccountAlertDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

    View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
    TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
    titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
    TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
    subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));

    dialogBuilder.setCustomTitle(titleView);
    dialogBuilder.setPositiveButton(null, null);

    Account[] accounts = getGoogleAccounts();
    String defAccount = getSyncAccountName(this);

    mOriAccounts = accounts;
    mHasAddedAccount = false;

    if (accounts.length > 0) {
      CharSequence[] items = new CharSequence[accounts.length];
      final CharSequence[] itemMapping = items;
      int checkedItem = -1;
      int index = 0;
      for (Account account : accounts) {
        if (TextUtils.equals(account.name, defAccount)) {
          checkedItem = index;
        }
        items[index++] = account.name;
      }
      dialogBuilder.setSingleChoiceItems(
          items,
          checkedItem,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              setSyncAccount(itemMapping[which].toString());
              dialog.dismiss();
              refreshUI();
            }
          });
    }

    View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
    dialogBuilder.setView(addAccountView);

    final AlertDialog dialog = dialogBuilder.show();
    addAccountView.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            mHasAddedAccount = true;
            Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
            intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {"gmail-ls"});
            startActivityForResult(intent, -1);
            dialog.dismiss();
          }
        });
  }
  protected void builderDialog(int resId) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View view = LayoutInflater.from(this).inflate(R.layout.layout_dialog_setting, null);
    TextView title = (TextView) view.findViewById(R.id.txt_dialog_title);
    title.setText(resId);

    ((TextView) view.findViewById(R.id.item_txt_01))
        .setText(GlobalSetting.CONTENT_MAP.get(Constants.Music.ITEM_01));
    ((TextView) view.findViewById(R.id.item_txt_02))
        .setText(GlobalSetting.CONTENT_MAP.get(Constants.Music.ITEM_02));
    ((TextView) view.findViewById(R.id.item_txt_03))
        .setText(GlobalSetting.CONTENT_MAP.get(Constants.Music.ITEM_03));
    ((TextView) view.findViewById(R.id.item_txt_04))
        .setText(GlobalSetting.CONTENT_MAP.get(Constants.Music.ITEM_04));

    view.findViewById(R.id.ly_01).setOnClickListener(mDialogListener);
    view.findViewById(R.id.ly_02).setOnClickListener(mDialogListener);
    view.findViewById(R.id.ly_03).setOnClickListener(mDialogListener);
    view.findViewById(R.id.ly_04).setOnClickListener(mDialogListener);

    mBtnItem01 = (RawMusicContrlLayer) view.findViewById(R.id.item_contrl_01);
    mBtnItem02 = (RawMusicContrlLayer) view.findViewById(R.id.item_contrl_02);
    mBtnItem03 = (RawMusicContrlLayer) view.findViewById(R.id.item_contrl_03);
    mBtnItem04 = (RawMusicContrlLayer) view.findViewById(R.id.item_contrl_04);

    mBtnItem01.setPath(GlobalSetting.MUSIC_MAP.get(Constants.Music.ITEM_01));
    mBtnItem02.setPath(GlobalSetting.MUSIC_MAP.get(Constants.Music.ITEM_02));
    mBtnItem03.setPath(GlobalSetting.MUSIC_MAP.get(Constants.Music.ITEM_03));
    mBtnItem04.setPath(GlobalSetting.MUSIC_MAP.get(Constants.Music.ITEM_04));

    mBtnItem01.setOnClickListener(mPickerListener);
    mBtnItem02.setOnClickListener(mPickerListener);
    mBtnItem03.setOnClickListener(mPickerListener);
    mBtnItem04.setOnClickListener(mPickerListener);

    builder.setCustomTitle(view);
    mDialog = builder.create();
    mDialog.show();
  }
示例#7
0
  protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
      case PROMPT_OAUTH:
        builder
            .setMessage(R.string.commentneedsinaoauth)
            .setCancelable(false)
            .setPositiveButton(
                R.string.ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                    FlipdroidApplications application = (FlipdroidApplications) getApplication();
                    OAuth oauth = new OAuth();
                    application.setOauth(oauth);
                    //// System.out.println("OAuthHolder.oauth" + application + oauth);
                    oauth.RequestAccessToken(PageActivity.this, "flipdroid://SinaAccountSaver");
                  }
                })
            .setNegativeButton(
                R.string.cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {}
                });
        this.dialog = builder.create();
        break;
      case NAVIGATION:
        LayoutInflater li = LayoutInflater.from(this);
        View v = li.inflate(R.layout.dialog_nav_title_view, null);

        // builder.setView(v);
        builder.setCustomTitle(v);

        builder.setAdapter(
            sourceAdapter,
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(PageActivity.this, PageActivity.class);
                SourceItem cursor = sourceAdapter.getItem(i);
                intent.putExtra("type", cursor.getSourceType());
                intent.putExtra("sourceId", cursor.getSourceId());
                intent.putExtra("sourceImage", cursor.getSourceImage());
                intent.putExtra("sourceName", cursor.getSourceName());
                intent.putExtra("contentUrl", cursor.getSourceURL());
                if (dialog != null) dialog.dismiss();
                startActivity(intent);
                finishActivity();
              }
            });

        this.dialog = builder.create();
        Button btn_addshortcut = (Button) v.findViewById(R.id.btnaddshortcut);
        btn_addshortcut.setText("add shortcut");

        btn_addshortcut.setOnClickListener(
            new Button.OnClickListener() {
              public void onClick(View v) {
                addShortcut();
                dialog.cancel();
              }
            });

        dialog.setOnKeyListener(
            new DialogInterface.OnKeyListener() {
              public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_MENU) {
                  if (dialog != null) {
                    dialog.dismiss();
                    return true;
                  }
                }

                return false;
              }
            });
        break;
      default:
        this.dialog = null;
    }
    if (dialog != null) {
      dialog.setOnDismissListener(
          new DialogInterface.OnDismissListener() {
            public void onDismiss(DialogInterface dialogInterface) {
              dialog = null;
            }
          });
    }
    return this.dialog;
  }
示例#8
0
  @Override
  public void onClick(final View view) {
    if (!viewSwitchLock.tryLock()) {
      return;
    }

    animatedBricks.clear();
    final int itemPosition = calculateItemPositionAndTouchPointY(view);
    final List<CharSequence> items = new ArrayList<CharSequence>();

    if (brickList.get(itemPosition) instanceof ScriptBrick) {
      int scriptIndex = getScriptIndexFromProject(itemPosition);
      ProjectManager.getInstance().setCurrentScript(sprite.getScript(scriptIndex));
    }

    if (!(brickList.get(itemPosition) instanceof DeadEndBrick)
        && !(brickList.get(itemPosition) instanceof ScriptBrick)) {
      items.add(context.getText(R.string.brick_context_dialog_move_brick));
    }
    if ((brickList.get(itemPosition) instanceof UserBrick)) {
      items.add(context.getText(R.string.brick_context_dialog_show_source));
    }
    if (brickList.get(itemPosition) instanceof NestingBrick) {
      items.add(context.getText(R.string.brick_context_dialog_animate_bricks));
    }
    if (!(brickList.get(itemPosition) instanceof ScriptBrick)) {
      items.add(context.getText(R.string.brick_context_dialog_copy_brick));
      items.add(context.getText(R.string.brick_context_dialog_delete_brick));
    } else {
      items.add(context.getText(R.string.brick_context_dialog_delete_script));
    }
    if (brickHasAFormula(brickList.get(itemPosition))) {
      items.add(context.getText(R.string.brick_context_dialog_formula_edit_brick));
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    boolean drawingCacheEnabled = view.isDrawingCacheEnabled();
    view.setDrawingCacheEnabled(true);
    view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);
    view.buildDrawingCache(true);

    if (view.getDrawingCache() != null) {
      Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
      view.setDrawingCacheEnabled(drawingCacheEnabled);

      ImageView imageView = dragAndDropListView.getGlowingBorder(bitmap);
      builder.setCustomTitle(imageView);
    }

    builder.setItems(
        items.toArray(new CharSequence[items.size()]),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            CharSequence clickedItemText = items.get(item);
            if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_move_brick))) {
              view.performLongClick();
            } else if (clickedItemText.equals(
                context.getText(R.string.brick_context_dialog_show_source))) {
              launchAddBrickAndSelectBrickAt(context, itemPosition);
            } else if (clickedItemText.equals(
                context.getText(R.string.brick_context_dialog_copy_brick))) {
              copyBrickListAndProject(itemPosition);
            } else if (clickedItemText.equals(
                    context.getText(R.string.brick_context_dialog_delete_brick))
                || clickedItemText.equals(
                    context.getText(R.string.brick_context_dialog_delete_script))) {
              showConfirmDeleteDialog(itemPosition);
            } else if (clickedItemText.equals(
                context.getText(R.string.brick_context_dialog_animate_bricks))) {
              int itemPosition = calculateItemPositionAndTouchPointY(view);
              Brick brick = brickList.get(itemPosition);
              if (brick instanceof NestingBrick) {
                List<NestingBrick> list = ((NestingBrick) brick).getAllNestingBrickParts(true);
                for (NestingBrick tempBrick : list) {
                  animatedBricks.add((Brick) tempBrick);
                }
              }
              notifyDataSetChanged();
            } else if (clickedItemText.equals(
                context.getText(R.string.brick_context_dialog_formula_edit_brick))) {
              clickedEditFormula(brickList.get(itemPosition), view);
            }
          }
        });
    alertDialog = builder.create();

    if ((selectMode == ListView.CHOICE_MODE_NONE)) {
      alertDialog.show();
    }
  }
  /**
   * Creates and shows a dialog for picking which of the active channels the user wants to show on
   * his android device. At least one is required
   */
  private void showDisplayChannels() {

    final ArrayList<String> channels = new ArrayList<String>(); // example {channel 1, channel 5}
    final ArrayList<String> sensors =
        new ArrayList<String>(); // example {blood pressure, temperature}

    // FILL THE CHANNELS AND SENSORS ARRAYS FOR THE LIST ADAPTER
    String[] activeSensors = newConfiguration.getActiveSensors();
    for (int i = 0; i < activeSensors.length; i++) {
      if (activeSensors[i].compareTo("null") != 0) {
        channels.add(getString(R.string.nc_dialog_channel) + " " + (i + 1));
        sensors.add(activeSensors[i]);
      }
    }

    final DisplayChannelsListAdapter displayChannelsListAdapter =
        new DisplayChannelsListAdapter(
            this, channels, sensors, newConfiguration.getDisplayChannels());
    AlertDialog displayChannelsDialog;

    TextView customTitleView = (TextView) inflater.inflate(R.layout.dialog_custom_title, null);
    customTitleView.setText(R.string.nc_dialog_title_channels_to_display);

    // BUILDER
    AlertDialog.Builder displayChannelsBuilder = new AlertDialog.Builder(this);
    displayChannelsBuilder
        .setCustomTitle(customTitleView)
        .setView(getLayoutInflater().inflate(R.layout.dialog_channels_listview, null))
        .setPositiveButton(
            getString(R.string.nc_dialog_positive_button),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {

                channelsSelected = displayChannelsListAdapter.getChecked();
                String[] displayChannels = new String[8];

                if (numberOfChannelsSelected(channelsSelected) == 0) {
                  displayChannelsTV.setText("");
                  displayChannelsTV.setVisibility(View.GONE);
                } else {
                  displayChannelsTV.setVisibility(View.VISIBLE);
                  displayChannelsTV.setError(null);
                  displayChannelsTV.setTextColor(getResources().getColor(R.color.blue));
                  convertBooleanToString(displayChannels, channelsSelected);
                  newConfiguration.setDisplayChannels(displayChannels);
                  displayChannelsTV.setText(newConfiguration.getDisplayChannelsWithSensors());
                }
              }

              private void convertBooleanToString(
                  String[] channelsToDisplayArray, boolean[] channelsSelected) {
                for (int i = 0; i < channelsSelected.length; i++) {
                  if (channelsSelected[i]) {
                    int in =
                        Character.getNumericValue(
                            (channels
                                    .get(i)
                                    .toString()
                                    .charAt(channels.get(i).toString().length() - 1))
                                - 1);
                    channelsToDisplayArray[in] = sensors.get(i);
                  }
                }
              }
            });
    displayChannelsBuilder.setNegativeButton(
        getString(R.string.nc_dialog_negative_button),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            // dismisses the dialog
          }
        });

    // CREATE DIALOG
    displayChannelsDialog = displayChannelsBuilder.create();
    displayChannelsDialog.show();

    // LIST VIEW CONFIGURATION
    ListView channelsToDisplayListView;
    channelsToDisplayListView =
        (ListView) displayChannelsDialog.findViewById(R.id.lv_channelsSelection);
    channelsToDisplayListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    channelsToDisplayListView.setItemsCanFocus(false);
    channelsToDisplayListView.setAdapter(displayChannelsListAdapter);
  }
示例#10
0
  /** START DIALOG DEFINITION */
  private AlertDialog.Builder createDirectoryChooserDialog(
      String title, List<String> listItems, DialogInterface.OnClickListener onClickListener) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
    // Create title text showing file select type
    mTitleView1 = new TextView(mContext);
    mTitleView1.setLayoutParams(
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    switch (typeOfSelection) {
      case FILE_OPEN:
        mTitleView1.setText("Open:");
        break;
      case FILE_SAVE:
        mTitleView1.setText("Save As:");
        break;
      case FOLDER_CHOOSE:
        mTitleView1.setText("Folder Select:");
        break;
      default:
        mTitleView1.setText("?? " + typeOfSelection);
        break;
    }

    // need to make this a variable Save as, Open, Select Directory
    mTitleView1.setGravity(Gravity.CENTER_VERTICAL);
    mTitleView1.setBackgroundColor(DARK_GREY_COLOR);
    mTitleView1.setTextColor(mContext.getResources().getColor(android.R.color.white));

    // Create custom view for AlertDialog title
    LinearLayout titleLayout1 = new LinearLayout(mContext);
    titleLayout1.setOrientation(LinearLayout.VERTICAL);
    titleLayout1.addView(mTitleView1);

    if (typeOfSelection == TypeOfSelection.FOLDER_CHOOSE
        || typeOfSelection == TypeOfSelection.FILE_SAVE) {
      // Create New Folder Button
      Button newDirButton = new Button(mContext);
      newDirButton.setLayoutParams(
          new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
      newDirButton.setText("New Folder");
      newDirButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              final EditText input = new EditText(mContext);

              // Show new folder name input dialog
              new AlertDialog.Builder(mContext)
                  .setTitle("New Folder Name")
                  .setView(input)
                  .setPositiveButton(
                      "OK",
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                          Editable newDir = input.getText();
                          String newDirName = newDir.toString();
                          // Create new directory
                          if (createSubDir(mDir + "/" + newDirName)) {
                            // Navigate into the new directory
                            mDir += "/" + newDirName;
                            updateDirectory();
                          } else {
                            Toast.makeText(
                                    mContext,
                                    "Failed to create '" + newDirName + "' folder",
                                    Toast.LENGTH_SHORT)
                                .show();
                          }
                        }
                      })
                  .setNegativeButton("Cancel", null)
                  .show();
            }
          });
      titleLayout1.addView(newDirButton);
    }

    // Create View with folder path and entry text box //
    LinearLayout titleLayout = new LinearLayout(mContext);
    titleLayout.setOrientation(LinearLayout.VERTICAL);

    mTitleView = new TextView(mContext);
    mTitleView.setLayoutParams(
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    mTitleView.setBackgroundColor(DARK_GREY_COLOR);
    mTitleView.setTextColor(mContext.getResources().getColor(android.R.color.white));
    mTitleView.setGravity(Gravity.CENTER_VERTICAL);
    mTitleView.setText(title);

    titleLayout.addView(mTitleView);

    if (typeOfSelection == TypeOfSelection.FILE_OPEN
        || typeOfSelection == TypeOfSelection.FILE_SAVE) {
      mInputText = new EditText(mContext);
      mInputText.setText(mDefaultFileName);
      titleLayout.addView(mInputText);
    }

    // Set Views and Finish Dialog builder
    dialogBuilder.setView(titleLayout);
    dialogBuilder.setCustomTitle(titleLayout1);
    mListAdapter = createListAdapter(listItems);
    dialogBuilder.setSingleChoiceItems(mListAdapter, -1, onClickListener);
    dialogBuilder.setCancelable(false);
    return dialogBuilder;
  }