@Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    SupportMenuItem doneItem = (SupportMenuItem) menu.add(Menu.NONE, 0, Menu.NONE, null);
    doneItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS);
    doneItem.setActionView(R.layout.group_create_done_layout);

    TextView doneTextView = (TextView) doneItem.getActionView().findViewById(R.id.done_button);
    doneTextView.setText(LocaleController.getString("Done", R.string.Done));
    doneTextView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (donePressed || parentActivity == null) {
              return;
            }
            if (nameTextView.getText().length() == 0) {
              return;
            }
            donePressed = true;

            if (avatarUpdater.uploadingAvatar != null) {
              createAfterUpload = true;
            } else {
              progressDialog = new ProgressDialog(parentActivity);
              progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
              progressDialog.setCanceledOnTouchOutside(false);
              progressDialog.setCancelable(false);

              final long reqId =
                  MessagesController.getInstance()
                      .createChat(
                          nameTextView.getText().toString(), selectedContacts, uploadedAvatar);

              progressDialog.setButton(
                  DialogInterface.BUTTON_NEGATIVE,
                  LocaleController.getString("Cancel", R.string.Cancel),
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      ConnectionsManager.getInstance().cancelRpc(reqId, true);
                      donePressed = false;
                      try {
                        dialog.dismiss();
                      } catch (Exception e) {
                        FileLog.e("tmessages", e);
                      }
                    }
                  });
              progressDialog.show();
            }
          }
        });
  }
Пример #2
0
 public static void setShowAsAction(MenuItem menuitem, int i) {
   if (menuitem instanceof SupportMenuItem) {
     ((SupportMenuItem) menuitem).setShowAsAction(i);
     return;
   } else {
     IMPL.setShowAsAction(menuitem, i);
     return;
   }
 }