@Override
 protected void showDialog(Bundle state) {
   super.showDialog(state);
   final Dialog dialog = getDialog();
   if (dialog != null && mController != null) {
     dialog.setOnShowListener(mController);
   }
 }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Calendar cal;

    final Bundle args = getArguments();
    if (args == null || !args.containsKey(ARG_DATE)) cal = DateTime.nowCalendar();
    else cal = DateTime.calendarFromDate((Date) args.getSerializable(ARG_DATE));

    final int d = cal.get(Calendar.DAY_OF_MONTH);
    final int m = cal.get(Calendar.MONTH);
    final int y = cal.get(Calendar.YEAR);

    if (Version.SDK_IS_JELLYBEAN_OR_NEWER) {
      // Workaround for Android issue #34833
      final Dialog dialog = new DatePickerDialog(getActivity(), null, y, m, d);
      dialog.setOnShowListener(this);
      return dialog;
    } else return new DatePickerDialog(getActivity(), mListener, y, m, d);
  }
示例#3
0
  @Override
  public Dialog onCreateDialog(Bundle bundle) {
    final View dialogView =
        LayoutInflater.from(getActivity())
            .inflate(R.layout.dialog_formula_editor_variable_name, null);

    final Dialog dialogNewVariable =
        new AlertDialog.Builder(getActivity())
            .setView(dialogView)
            .setTitle(R.string.formula_editor_variable_dialog_title)
            .setNegativeButton(
                R.string.cancel_button,
                new OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                  }
                })
            .setPositiveButton(
                R.string.ok,
                new OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    handleOkButton(dialogView);
                  }
                })
            .create();

    dialogNewVariable.setCanceledOnTouchOutside(true);

    dialogNewVariable.setOnShowListener(
        new OnShowListener() {
          @Override
          public void onShow(DialogInterface dialog) {
            handleOnShow(dialogNewVariable);
          }
        });

    return dialogNewVariable;
  }
  public static Dialog createAboutDialog(final SDLActivity ctx) {
    final Dialog d = new Dialog(ctx);

    d.setContentView(R.layout.about);

    d.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    d.setTitle(R.string.about_dialog_header);

    Button button = (Button) d.findViewById(R.id.dismissDialogButton);
    button.setOnClickListener(
        new Button.OnClickListener() {

          @Override
          public void onClick(View arg0) {
            d.dismiss();
          }
        });

    d.setOnShowListener(
        new OnShowListener() {

          @Override
          public void onShow(DialogInterface dialog) {
            TextView aboutText = (TextView) d.findViewById(R.id.aboutTextView);
            String text;
            try {
              text = Files.readTextFromResource(ctx, R.raw.about);
            } catch (IOException e) {
              text = "";
            }
            aboutText.setText(text);
          }
        });

    return d;
  }
示例#5
0
  /**
   * Shows a dialog with info about an event.
   *
   * @param id The id of the event
   */
  private void showDialog(int id) {

    // Create the dialog
    final Dialog dialog = new Dialog(getActivity());

    // Set window
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_around);

    // Date formatters
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);

    // Set the custom dialog components - text, image and button
    TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_around_title);
    TextView tvDescription = (TextView) dialog.findViewById(R.id.tv_dialog_around_description);
    TextView tvDate = (TextView) dialog.findViewById(R.id.tv_dialog_around_date);
    TextView tvTime = (TextView) dialog.findViewById(R.id.tv_dialog_around_time);
    TextView tvPlace = (TextView) dialog.findViewById(R.id.tv_dialog_around_place);
    TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_around_address);
    Button btClose = (Button) dialog.findViewById(R.id.bt_around_close);

    // Get info about the event
    SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
    Cursor cursor =
        db.rawQuery(
            "SELECT event.id, event.name, description, start, end, place.name, address, lat, lon FROM event, place WHERE place.id = event.place AND event.id = "
                + id
                + ";",
            null);
    if (cursor.getCount() > 0) {
      cursor.moveToNext();

      // Set title
      tvTitle.setText(cursor.getString(1));
      markerName = cursor.getString(1);

      // Set description
      tvDescription.setText(cursor.getString(2));

      // Set date
      try {
        Date day = dateFormat.parse(cursor.getString(3));
        Date date = new Date();

        // If the event is today, show "Today" instead of the date.
        if (dayFormat.format(day).equals(dayFormat.format(date))) {
          tvDate.setText(dialog.getContext().getString(R.string.today));
        } else {
          Calendar cal = Calendar.getInstance();
          cal.setTime(date);
          cal.add(Calendar.HOUR_OF_DAY, 24);

          // If the event is tomorrow, show "Tomorrow" instead of the date.
          if (dayFormat.format(cal.getTime()).equals(dayFormat.format(date))) {
            tvDate.setText(dialog.getContext().getString(R.string.tomorrow));
          }

          // Else, show the date
          else {
            SimpleDateFormat printFormat = new SimpleDateFormat("dd MMMM", Locale.US);
            tvDate.setText(printFormat.format(day));
          }
        }
      } catch (Exception ex) {
        Log.e("Error parsing around event date", ex.toString());
      }

      // Set time
      try {
        if (cursor.getString(4) == null)
          tvTime.setText(timeFormat.format(dateFormat.parse(cursor.getString(3))));
        else
          tvTime.setText(
              timeFormat.format(dateFormat.parse(cursor.getString(3)))
                  + " - "
                  + timeFormat.format(timeFormat.parse(cursor.getString(4))));
      } catch (ParseException ex) {
        Log.e("Error parsing around event time", ex.toString());
      }

      // Set place
      tvPlace.setText(cursor.getString(5));
      tvAddress.setText(cursor.getString(6));

      // Set up map
      location =
          new LatLng(
              Double.parseDouble(cursor.getString(7)), Double.parseDouble(cursor.getString(8)));
      mapView = (MapView) dialog.findViewById(R.id.mv_dialog_around_map);
      mapView.onCreate(bund);

      // Close db connection
      cursor.close();
      db.close();

      // Set close button
      btClose.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              dialog.dismiss();
            }
          });

      // Actions to take when the dialog is cancelled
      dialog.setOnCancelListener(
          new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
              if (map != null) map.setMyLocationEnabled(false);
              if (mapView != null) {
                mapView.onResume();
                mapView.onDestroy();
              }
            }
          });

      // Show the dialog
      WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
      lp.dimAmount = 0.0f;
      dialog.show();

      // Start the map
      startMap();
      mapView.onResume();
      dialog.setOnShowListener(
          new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
              // Gets to GoogleMap from the MapView and does initialization stuff
              startMap();
            }
          });
    }
  }
  @NonNull
  @Override
  public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
    final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
    final Context context = builder.getContext();
    mValidator = new TwidereValidator(context);
    final LayoutInflater inflater = LayoutInflater.from(context);
    @SuppressLint("InflateParams")
    final View view = inflater.inflate(R.layout.dialog_status_quote_retweet, null);
    final DummyStatusHolderAdapter adapter = new DummyStatusHolderAdapter(context);
    adapter.setShouldShowAccountsColor(true);
    final IStatusViewHolder holder =
        new StatusViewHolder(adapter, view.findViewById(R.id.item_content));
    final ParcelableStatus status = getStatus();

    assert status != null;

    builder.setView(view);
    builder.setTitle(R.string.retweet_quote_confirm_title);
    if (isMyRetweet(status)) {
      builder.setPositiveButton(R.string.cancel_retweet, this);
    } else if (!status.user_is_protected) {
      builder.setPositiveButton(R.string.retweet, this);
    }
    builder.setNeutralButton(R.string.quote, this);
    builder.setNegativeButton(android.R.string.cancel, null);

    holder.displayStatus(status, null, false, true);

    view.findViewById(R.id.item_menu).setVisibility(View.GONE);
    view.findViewById(R.id.action_buttons).setVisibility(View.GONE);
    view.findViewById(R.id.item_content).setFocusable(false);
    view.findViewById(R.id.comment_container)
        .setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE);
    final ComposeMaterialEditText mEditComment =
        (ComposeMaterialEditText) view.findViewById(R.id.edit_comment);
    mEditComment.setAccountId(status.account_id);

    final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
    final EditTextEnterHandler enterHandler =
        EditTextEnterHandler.attach(
            mEditComment,
            new EditTextEnterHandler.EnterListener() {
              @Override
              public boolean shouldCallListener() {
                return true;
              }

              @Override
              public boolean onHitEnter() {
                final AsyncTwitterWrapper twitter = mTwitterWrapper;
                final ParcelableStatus status = getStatus();
                if (twitter == null || status == null) return false;
                retweetOrQuote(twitter, status);
                dismiss();
                return true;
              }
            },
            sendByEnter);
    enterHandler.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateTextCount(getDialog(), s, status);
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });
    final View commentMenu = view.findViewById(R.id.comment_menu);

    mPopupMenu =
        new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
    commentMenu.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mPopupMenu.show();
          }
        });
    commentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener());
    mPopupMenu.inflate(R.menu.menu_dialog_comment);
    final Menu menu = mPopupMenu.getMenu();
    MenuUtils.setMenuItemAvailability(
        menu, R.id.quote_original_status, status.retweet_id > 0 || status.quoted_id > 0);
    mPopupMenu.setOnMenuItemClickListener(
        new PopupMenu.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            if (item.isCheckable()) {
              item.setChecked(!item.isChecked());
              return true;
            }
            return false;
          }
        });

    final Dialog dialog = builder.create();
    dialog.setOnShowListener(
        new DialogInterface.OnShowListener() {
          @Override
          public void onShow(DialogInterface dialog) {
            updateTextCount(dialog, mEditComment.getText(), status);
          }
        });
    return dialog;
  }