Exemplo n.º 1
0
 @Override
 public void propertySet(String key, Object newValue, Object oldValue, boolean changedProperty) {
   AlertDialog dialog = (AlertDialog) dialogWrapper.getDialog();
   if (key.startsWith(TiC.PROPERTY_ACCESSIBILITY_PREFIX)) {
     if (dialog != null) {
       ListView listView = dialog.getListView();
       if (listView != null) {
         if (key.equals(TiC.PROPERTY_ACCESSIBILITY_HIDDEN)) {
           int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
           if (newValue != null && TiConvert.toBoolean(newValue)) {
             importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
           }
           ViewCompat.setImportantForAccessibility(listView, importance);
         } else {
           listView.setContentDescription(composeContentDescription());
         }
       }
     }
     return;
   }
   switch (key) {
     case TiC.PROPERTY_TITLE:
       if (dialog != null) {
         dialog.setTitle(Html.fromHtml((String) newValue));
       } else {
         getBuilder().setTitle(Html.fromHtml(TiConvert.toString(newValue)));
       }
       break;
     case TiC.PROPERTY_MESSAGE:
       if (dialog != null) {
         dialog.setMessage(Html.fromHtml((String) newValue));
       } else {
         getBuilder().setMessage(Html.fromHtml(TiConvert.toString(newValue)));
       }
       break;
     case TiC.PROPERTY_BUTTON_NAMES:
       clearDialog();
       processButtons(TiConvert.toStringArray(newValue));
       break;
     case TiC.PROPERTY_OK:
       clearDialog();
       processButtons(new String[] {TiConvert.toString(newValue)});
       break;
     case TiC.PROPERTY_CUSTOM_VIEW:
       clearDialog();
       processView(newValue);
       break;
     case TiC.PROPERTY_PERSISTENT:
       dialogWrapper.setPersistent(TiConvert.toBoolean(newValue));
       break;
     case TiC.PROPERTY_CANCEL:
       cancelIndex = TiConvert.toInt(newValue, -1);
       break;
     case TiC.PROPERTY_OPTIONS:
       {
         mProcessUpdateFlags |= TIFLAG_NEEDS_OPTIONS;
         break;
       }
     case TiC.PROPERTY_SELECTED_INDEX:
       {
         mProcessUpdateFlags |= TIFLAG_NEEDS_OPTIONS;
         break;
       }
     case TiC.PROPERTY_HIDE_ON_CLICK:
       hideOnClick = TiConvert.toBoolean(newValue);
       if (dialog != null) {
         dialog.setCancelable(hideOnClick);
       }
       break;
     case TiC.PROPERTY_TAP_OUT_DISMISS:
       tapToDismiss = TiConvert.toBoolean(newValue);
       if (dialog != null) {
         dialog.setCanceledOnTouchOutside(tapToDismiss);
       }
       break;
     default:
       super.propertySet(key, newValue, oldValue, changedProperty);
       break;
   }
 }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    mCanDeleteBrowsingHistory = PrefServiceBridge.getInstance().canDeleteBrowsingHistory();

    DialogOption[] options = getDialogOptions();
    String[] optionNames = new String[options.length];
    Resources resources = getResources();
    for (int i = 0; i < options.length; i++) {
      optionNames[i] = resources.getString(options[i].getResourceId());
    }
    mSelectedOptions = getDefaultDialogOptionsSelections();
    mAdapter = new ClearBrowsingDataAdapter(options, optionNames, getDisabledDialogOptions());
    final AlertDialog.Builder builder =
        new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setTitle(R.string.clear_browsing_data_title)
            .setPositiveButton(R.string.clear_data_delete, this)
            .setNegativeButton(R.string.cancel, this)
            .setAdapter(mAdapter, null); // OnClickListener is registered manually.

    if (ChromeSigninController.get(getActivity()).isSignedIn()) {
      final String message = getString(R.string.clear_cookies_no_sign_out_summary);
      final SpannableString messageWithLink =
          SpanApplier.applySpans(
              message,
              new SpanApplier.SpanInfo(
                  "<link>",
                  "</link>",
                  new ClickableSpan() {
                    @Override
                    public void onClick(View widget) {
                      dismiss();
                      Preferences prefActivity = (Preferences) getActivity();
                      prefActivity.startFragment(AccountManagementFragment.class.getName(), null);
                    }

                    // Change link formatting to use no underline
                    @Override
                    public void updateDrawState(TextPaint textPaint) {
                      textPaint.setColor(textPaint.linkColor);
                      textPaint.setUnderlineText(false);
                    }
                  }));

      View view =
          getActivity().getLayoutInflater().inflate(R.layout.single_line_bottom_text_dialog, null);
      TextView summaryView = (TextView) view.findViewById(R.id.summary);
      summaryView.setText(messageWithLink);
      summaryView.setMovementMethod(LinkMovementMethod.getInstance());
      builder.setView(view);
    }

    mDialog = builder.create();
    mDialog
        .getListView()
        .setOnItemClickListener(
            new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                // The present behaviour of AlertDialog is to dismiss after the onClick event.
                // Hence we are manually overriding this outside the builder.
                mAdapter.onClick(position);
              }
            });
    return mDialog;
  }
Exemplo n.º 3
0
  public void show(KrollDict options) {
    AlertDialog dialog = (AlertDialog) dialogWrapper.getDialog();
    if (dialog == null) {
      if (dialogWrapper.getActivity() == null) {
        TiBaseActivity dialogActivity = (TiBaseActivity) getCurrentActivity();
        dialogWrapper.setActivity(new WeakReference<TiBaseActivity>(dialogActivity));
      }
      //			processProperties(proxy.getProperties());
      getBuilder()
          .setOnCancelListener(
              new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dlg) {
                  int cancelIndex =
                      (proxy.hasProperty(TiC.PROPERTY_CANCEL))
                          ? TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL))
                          : -1;
                  Log.d(
                      TAG,
                      "onCancelListener called. Sending index: "
                          + cancelIndex
                          + ", hideOnClick: "
                          + hideOnClick,
                      Log.DEBUG_MODE);
                  handleEvent(cancelIndex, false);
                  if (hideOnClick == true) hide(null);
                }
              });
      dialog = getBuilder().create();
      dialog.setOnShowListener(
          new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
              TiApplication.getInstance().cancelPauseEvent();
            }
          });
      dialog.setCancelable(hideOnClick);
      dialog.setCanceledOnTouchOutside(tapToDismiss);

      dialog.setOnKeyListener(
          new Dialog.OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
              if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (proxy.hasListeners(TiC.EVENT_ANDROID_BACK)) {
                  proxy.fireEvent(TiC.EVENT_ANDROID_BACK);
                } else if (hideOnClick) {
                  handleEvent(cancelIndex, false);
                  hide(null);
                }
              }
              return true;
            }
          });

      // Initially apply accessibility properties here, the first time
      // the dialog actually becomes available. After this, propertyChanged
      // can also be used.
      ListView listView = dialog.getListView();
      if (listView != null) {
        listView.setContentDescription(composeContentDescription());
        int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
        if (proxy != null) {
          Object propertyValue = proxy.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN);
          if (propertyValue != null && TiConvert.toBoolean(propertyValue)) {
            importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
          }
        }
        ViewCompat.setImportantForAccessibility(listView, importance);
      }

      dialogWrapper.setDialog(dialog);
      builder = null;
    }

    try {
      Activity dialogActivity = dialogWrapper.getActivity();
      if (dialogActivity != null && !dialogActivity.isFinishing()) {
        if (dialogActivity instanceof TiBaseActivity) {
          // add dialog to its activity so we can clean it up later to prevent memory leak.
          ((TiBaseActivity) dialogActivity).addDialog(dialogWrapper);
          dialog.show();
          setButtonsListeners(dialog);
          fireEvent(TiC.EVENT_OPEN, null, false);
        }
      } else {
        dialog = null;
        Log.w(
            TAG,
            "Dialog activity is destroyed, unable to show dialog with message: "
                + TiConvert.toString(proxy.getProperty(TiC.PROPERTY_MESSAGE)));
      }
    } catch (Throwable t) {
      Log.w(TAG, "Context must have gone away: " + t.getMessage(), t);
    }
  }