Ejemplo n.º 1
0
 protected Dialog onCreateDialog(int id) {
   switch (id) {
     case DialogId.DIALOG_ALERT_FREQUENCY:
     case DialogId.DIALOG_ALERT_FREQUENCY_NULL:
     case DialogId.DIALOG_ALERT_SYMBOL:
     case DialogId.DIALOG_ALERT_SYMBOL_NULL:
     case DialogId.DIALOG_ALERT_SYMBOL_OUT:
       AlertDialog alert =
           new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK).create();
       alert.setTitle(getResources().getString(R.string.alert));
       alert.setOnKeyListener(
           new OnKeyListener() {
             public boolean onKey(DialogInterface arg0, int arg1, KeyEvent event) {
               // 任意按键都能让提示对话框消失
               if (event.getAction() == KeyEvent.ACTION_DOWN) {
                 arg0.dismiss();
               }
               return true;
             }
           });
       // 这个是用来在组装对话框时必须的,用来显示消息内容
       // 可以在onPrepareDialog中改变的,如果这里没有那么
       // 对话框就没这个组件了
       alert.setMessage("");
       return alert;
   }
   return super.onCreateDialog(id);
 }
Ejemplo n.º 2
0
  @Override
  protected void showDialog(Bundle state) {
    super.showDialog(state);
    AlertDialog alertDialog = (AlertDialog) getDialog();
    if (alertDialog == null) {
      return;
    }

    if (getContext().getPackageManager().hasSystemFeature("android.hardware.touchscreen")) {
      /* Disable focus for buttons to prevent them being highlighted when keys are pressed */
      alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setFocusable(false);
      alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setFocusable(false);
    }
    alertDialog.setOnKeyListener(this);
    setPositiveButtonText(R.string.save);
    setNegativeButtonText(android.R.string.cancel);
    setDialogIcon(null);
  }
  protected void showDeviceDialog(BluetoothDevice device, final DialogListener listener) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String message = "Device " + device.getName() + " has address: " + device.getAddress() + ".\n";
    boolean isBonded = false;
    if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
      isBonded = true;
      message += "You are Bonded to this device.\n";
    } else if (device.getBondState() == BluetoothDevice.BOND_BONDING) {
      message += "You are currently bonding to this device.\n";
    } else {
      message += "You are not bonded to this device.\n";
    }

    builder.setMessage(message).setCancelable(true);

    if (!isBonded) {
      builder.setPositiveButton(
          "Pair to this device",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              listener.pairDevice();
            }
          });
    } else {
      builder.setNegativeButton(
          "Un-Pair from this device",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              listener.unpairDevices();
              dialog.cancel();
            }
          });
    }

    AlertDialog deviceDialog = builder.create();
    deviceDialog.setOnKeyListener(
        new OnKeyListener() {
          public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            return DroidToothActivity.this.onKeyDown(keyCode, event);
          }
        });
    deviceDialog.show();
  }
Ejemplo n.º 4
0
  static void shutdownInner(final Context context, boolean confirm) {
    // ensure that only one thread is trying to power down.
    // any additional calls are just returned
    synchronized (sIsStartedGuard) {
      if (sIsStarted) {
        Log.d(TAG, "Request to shutdown already running, returning.");
        return;
      }
    }

    final int titleResourceId;
    final int resourceId;

    Log.d(TAG, "Notifying thread to start shutdown");

    if (mRebootSafeMode) {
      titleResourceId = com.android.internal.R.string.reboot_safemode_title;
      resourceId = com.android.internal.R.string.reboot_safemode_confirm;
    } else if (mReboot) {
      titleResourceId = com.android.internal.R.string.reboot_system;
      resourceId = com.android.internal.R.string.reboot_confirm;
    } else {

      final int longPressBehavior =
          context
              .getResources()
              .getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior);

      titleResourceId = com.android.internal.R.string.power_off;
      if (longPressBehavior == 2) {
        resourceId = com.android.internal.R.string.shutdown_confirm_question;
      } else {
        resourceId = com.android.internal.R.string.shutdown_confirm;
      }

      Log.d(TAG, "longPressBehavior=" + longPressBehavior);
    }

    if (confirm) {
      final CloseDialogReceiver closer = new CloseDialogReceiver(context);
      if (sConfirmDialog != null) {
        sConfirmDialog.dismiss();
        sConfirmDialog = null;
      }
      if (mReboot && !mRebootSafeMode) {
        // Determine if primary user is logged in
        boolean isPrimary = UserHandle.getCallingUserId() == UserHandle.USER_OWNER;

        // See if the advanced reboot menu is enabled (only if primary user) and check the keyguard
        // state
        boolean advancedReboot = isPrimary ? advancedRebootEnabled(context) : false;
        KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        boolean locked = km.inKeyguardRestrictedInputMode();

        if (advancedReboot && !locked) {
          // Include options in power menu for rebooting into recovery or bootloader
          sConfirmDialog =
              new AlertDialog.Builder(context)
                  .setTitle(titleResourceId)
                  .setSingleChoiceItems(
                      com.android.internal.R.array.shutdown_reboot_options,
                      0,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                          if (which < 0) return;

                          String actions[] =
                              context
                                  .getResources()
                                  .getStringArray(
                                      com.android.internal.R.array.shutdown_reboot_actions);

                          if (actions != null && which < actions.length)
                            mRebootReason = actions[which];
                        }
                      })
                  .setPositiveButton(
                      com.android.internal.R.string.yes,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                          mReboot = true;
                          beginShutdownSequence(context);
                        }
                      })
                  .setNegativeButton(
                      com.android.internal.R.string.no,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                          mReboot = false;
                          dialog.cancel();
                        }
                      })
                  .create();
          sConfirmDialog.setOnKeyListener(
              new DialogInterface.OnKeyListener() {
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                  if (keyCode == KeyEvent.KEYCODE_BACK) {
                    mReboot = false;
                    dialog.cancel();
                  }
                  return true;
                }
              });
        }
      }

      if (sConfirmDialog == null) {
        sConfirmDialog =
            new AlertDialog.Builder(context)
                .setTitle(titleResourceId)
                .setMessage(resourceId)
                .setPositiveButton(
                    com.android.internal.R.string.yes,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                        beginShutdownSequence(context);
                      }
                    })
                .setNegativeButton(com.android.internal.R.string.no, null)
                .create();
      }

      closer.dialog = sConfirmDialog;
      sConfirmDialog.setOnDismissListener(closer);
      sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
      sConfirmDialog.show();

    } else {
      beginShutdownSequence(context);
    }
  }