Ejemplo n.º 1
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;
  }