Example #1
0
  public static AlertDialog showWebAlert(
      final Context context,
      final String title,
      final String rawUrl,
      final WebViewClient client,
      final String ok,
      final String cancel,
      final DialogInterface.OnClickListener lOk,
      final DialogInterface.OnClickListener lCancel,
      final DialogInterface.OnDismissListener lDismiss) {
    final View view = View.inflate(context, R.layout.webalert, null);
    final AlertDialog alert = showAlert(context, title, view, ok, cancel, lOk, lCancel);
    alert.setOnDismissListener(
        new DialogInterface.OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {
            if (lDismiss != null) {
              lDismiss.onDismiss(dialog);
            }
          }
        });

    final WebView info = (WebView) view.findViewById(R.id.info_wv);
    info.loadUrl(rawUrl);
    if (client != null) {
      info.setWebViewClient(client);
    }
    return alert;
  }
 public void show(IBinder ibinder) {
   Object obj = mMenu;
   android.app.AlertDialog.Builder builder =
       new android.app.AlertDialog.Builder(((MenuBuilder) (obj)).getContext());
   mPresenter =
       new ListMenuPresenter(
           android.support.v7.appcompat.R.layout.abc_list_menu_item_layout,
           android.support.v7.appcompat.R.style.Theme_AppCompat_CompactMenu_Dialog);
   mPresenter.setCallback(this);
   mMenu.addMenuPresenter(mPresenter);
   builder.setAdapter(mPresenter.getAdapter(), this);
   View view = ((MenuBuilder) (obj)).getHeaderView();
   if (view != null) {
     builder.setCustomTitle(view);
   } else {
     builder
         .setIcon(((MenuBuilder) (obj)).getHeaderIcon())
         .setTitle(((MenuBuilder) (obj)).getHeaderTitle());
   }
   builder.setOnKeyListener(this);
   mDialog = builder.create();
   mDialog.setOnDismissListener(this);
   obj = mDialog.getWindow().getAttributes();
   obj.type = 1003;
   if (ibinder != null) {
     obj.token = ibinder;
   }
   obj.flags = ((android.view.WindowManager.LayoutParams) (obj)).flags | 0x20000;
   mDialog.show();
 }
  /**
   * Loads default setting for currency and performs app first-run initialization.
   *
   * <p>Also handles displaying the What's New dialog
   */
  private void init() {
    PreferenceManager.setDefaultValues(this, R.xml.fragment_transaction_preferences, false);

    Money.DEFAULT_CURRENCY_CODE = GnuCashApplication.getDefaultCurrency();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
    if (firstRun) {
      showFirstRunDialog();
      // default to using double entry and save the preference explicitly
      prefs.edit().putBoolean(getString(R.string.key_use_double_entry), true).apply();
    }

    if (hasNewFeatures()) {
      AlertDialog dialog = showWhatsNewDialog(this);
      // TODO: remove this when we upgrade to 1.7.0. Users will already know the nav drawer then
      dialog.setOnDismissListener(
          new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
              mDrawerLayout.openDrawer(mDrawerList);
            }
          });
    }
    GnuCashApplication.startScheduledActionExecutionService(this);
  }
Example #4
0
  private void showMsgDialog(final TodoType type, final String idStr, final String msg) {
    dismissSendMsgDialog();
    mSendSmsDialog =
        new AlertDialog.Builder(getActivity())
            .setTitle(R.string.dialog_title_sms_templet)
            .setMessage(msg)
            .setPositiveButton(
                R.string.dialog_btn_send_sms,
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    sendSms(type, idStr);
                  }
                })
            .create();
    mSendSmsDialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {
            releaseHandleBtnlock();
          }
        });
    if (getActivity() != null && !getActivity().isFinishing()) {
      mSendSmsDialog.show();
    }
  }
  public static void showGrantPermissionsMessage(Context context, OnDismissListener listener) {
    AlertDialog.Builder kernelExpiredDlgBuilder = new AlertDialog.Builder(context);

    kernelExpiredDlgBuilder.setMessage("Please Grant the required Permission and Then Try Again.");
    kernelExpiredDlgBuilder.setTitle("Permissions Required!!!");
    kernelExpiredDlgBuilder.setPositiveButton("OK", null);
    AlertDialog kernelExpiredDlg = kernelExpiredDlgBuilder.create();
    kernelExpiredDlg.setCanceledOnTouchOutside(false);
    kernelExpiredDlg.setOnDismissListener(listener);
    kernelExpiredDlg.show();
  }
 void buildResetDialog() {
   if (mResetDialog == null) {
     AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
     builder.setTitle(R.string.reset_app_preferences_title);
     builder.setMessage(R.string.reset_app_preferences_desc);
     builder.setPositiveButton(R.string.reset_app_preferences_button, this);
     builder.setNegativeButton(R.string.cancel, null);
     mResetDialog = builder.show();
     mResetDialog.setOnDismissListener(this);
   }
 }
  public static void showKernelExpiredMessage(Context context, OnDismissListener listener) {
    AlertDialog.Builder kernelExpiredDlgBuilder = new AlertDialog.Builder(context);

    kernelExpiredDlgBuilder.setMessage(
        "Your license file is missing, invalid or expired. LEADTOOLS will not function. Please contact LEAD Sales for information on obtaining a valid license.");
    kernelExpiredDlgBuilder.setTitle("No LEADTOOLS License");
    kernelExpiredDlgBuilder.setPositiveButton("OK", null);
    AlertDialog kernelExpiredDlg = kernelExpiredDlgBuilder.create();
    kernelExpiredDlg.setCanceledOnTouchOutside(false);
    kernelExpiredDlg.setOnDismissListener(listener);
    kernelExpiredDlg.show();
  }
Example #8
0
    protected void selectPOILayer(final OsmandSettings settings) {
      final PoiUIFilter[] selected = new PoiUIFilter[1];
      AlertDialog dlg = ma.getMapLayers().selectPOIFilterLayer(ma.getMapView(), selected);
      dlg.setOnDismissListener(
          new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
              ma.getDashboard().refreshContent(true);
            }
          });
    }
 protected void showInternal() {
   mDialog.show();
   mDialog.setOnDismissListener(this);
   mDialog
       .getListView()
       .setOnItemClickListener(
           new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               onListItemClick(position);
             }
           });
 }
 public static void showDialog(
     Context context, int initialColor, View parentView, OnColorPickerViewListener listener) {
   final ColorPickerView picker = new ColorPickerView(context, initialColor);
   picker.parentView = parentView;
   picker.listener = listener;
   final AlertDialog dlg =
       (new AlertDialog.Builder(context))
           .setView(picker)
           .setPositiveButton(R.string.ok, picker)
           .setNegativeButton(R.string.cancel, null)
           .create();
   dlg.setOnDismissListener(picker);
   UI.prepareDialogAndShow(dlg);
 }
 @Override
 protected Dialog onCreateDialog(int id) {
   switch (id) {
     case CPU_WARNING_DIALOG:
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
       builder.setTitle(R.string.app_name).setMessage(R.string.cpu_warning);
       AlertDialog alert = builder.create();
       alert.setOnDismissListener(
           new OnDismissListener() {
             public void onDismiss(DialogInterface dialog) {
               finish();
             }
           });
       return alert;
   }
   return null;
 }
 protected boolean onSelectionActionItemClicked(final ActionMode mode, MenuItem item) {
   ListView listView = getListView();
   switch (item.getItemId()) {
     case R.id.blob_descriptor_delete:
       int count = listView.getCheckedItemCount();
       String countStr =
           getResources().getQuantityString(getDeleteConfirmationItemCountResId(), count, count);
       String message = getString(R.string.blob_descriptor_confirm_delete, countStr);
       deleteConfirmationDialog =
           new AlertDialog.Builder(getActivity())
               .setIcon(android.R.drawable.ic_dialog_alert)
               .setTitle("")
               .setMessage(message)
               .setPositiveButton(
                   android.R.string.yes,
                   new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
                       deleteSelectedItems();
                       mode.finish();
                       deleteConfirmationDialog = null;
                     }
                   })
               .setNegativeButton(android.R.string.no, null)
               .create();
       deleteConfirmationDialog.setOnDismissListener(
           new DialogInterface.OnDismissListener() {
             @Override
             public void onDismiss(DialogInterface dialogInterface) {
               deleteConfirmationDialog = null;
             }
           });
       deleteConfirmationDialog.show();
       return true;
     case R.id.blob_descriptor_select_all:
       int itemCount = listView.getCount();
       for (int i = itemCount - 1; i > -1; --i) {
         listView.setItemChecked(i, true);
       }
       return true;
     default:
       return false;
   }
 }
  public void showUpdateDialog(String intro) {
    final AlertDialog updateDialogDlg = new AlertDialog.Builder(this).create();
    updateDialogDlg.show();
    Window win = updateDialogDlg.getWindow();
    win.setContentView(R.layout.dialog_update);
    TextView tvMsg = (TextView) win.findViewById(R.id.tvMsg);
    tvMsg.setText(intro);
    Button btOk = (Button) win.findViewById(R.id.btOk);
    ImageView closeImageView = (ImageView) win.findViewById(R.id.updateclose);
    closeImageView.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            updateDialogDlg.dismiss();
            Message msg = new Message();
            msg.what = SplashActivity.CHECKVERSION_CANCEL;
            mHandler.sendMessage(msg);
          }
        });

    btOk.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View arg0) {
            updateDialogDlg.dismiss();
            Message msg = new Message();
            msg.what = SplashActivity.CHECKVERSION_DOWN;
            mHandler.sendMessage(msg);
          }
        });

    updateDialogDlg.setOnDismissListener(
        new OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            Message msg = new Message();
            msg.what = SplashActivity.CHECKVERSION_CANCEL;
            mHandler.sendMessage(msg);
          }
        });
  }
Example #14
0
 /**
  * 显示一个对话框
  *
  * @param context 上下文对象,最好给Activity,否则需要android.permission.SYSTEM_ALERT_WINDOW
  * @param title 标题
  * @param message 消息
  * @param confirmButton 确认按钮
  * @param confirmButtonClickListener 确认按钮点击监听器
  * @param centerButton 中间按钮
  * @param centerButtonClickListener 中间按钮点击监听器
  * @param cancelButton 取消按钮
  * @param cancelButtonClickListener 取消按钮点击监听器
  * @param onShowListener 显示监听器
  * @param cancelable 是否允许通过点击返回按钮或者点击对话框之外的位置关闭对话框
  * @param onCancelListener 取消监听器
  * @param onDismissListener 销毁监听器
  * @return 对话框
  */
 public static AlertDialog showAlert(
     Context context,
     String title,
     String message,
     String confirmButton,
     DialogInterface.OnClickListener confirmButtonClickListener,
     String centerButton,
     DialogInterface.OnClickListener centerButtonClickListener,
     String cancelButton,
     DialogInterface.OnClickListener cancelButtonClickListener,
     DialogInterface.OnShowListener onShowListener,
     boolean cancelable,
     DialogInterface.OnCancelListener onCancelListener,
     DialogInterface.OnDismissListener onDismissListener) {
   AlertDialog.Builder promptBuilder = new AlertDialog.Builder(context);
   if (title != null) {
     promptBuilder.setTitle(title);
   }
   if (message != null) {
     promptBuilder.setMessage(message);
   }
   if (confirmButton != null) {
     promptBuilder.setPositiveButton(confirmButton, confirmButtonClickListener);
   }
   if (centerButton != null) {
     promptBuilder.setNeutralButton(centerButton, centerButtonClickListener);
   }
   if (cancelButton != null) {
     promptBuilder.setNegativeButton(cancelButton, cancelButtonClickListener);
   }
   promptBuilder.setCancelable(true);
   if (cancelable) {
     promptBuilder.setOnCancelListener(onCancelListener);
   }
   AlertDialog alertDialog = promptBuilder.create();
   if (!(context instanceof Activity)) {
     alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
   }
   alertDialog.setOnDismissListener(onDismissListener);
   alertDialog.setOnShowListener(onShowListener);
   alertDialog.show();
   return alertDialog;
 }
Example #15
0
  void deleteItem(int position) {

    final AlertDialog alert =
        new AlertDialog.Builder(getSherlockActivity())
            .setTitle(
                getSherlockActivity()
                    .getResources()
                    .getString(R.string.dialog_delete_call_block_title))
            .setMessage(
                getSherlockActivity()
                    .getResources()
                    .getString(R.string.dialog_delete_block_message))
            .setCancelable(true)
            .setNegativeButton(
                "Cancel",
                new Dialog.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    if (DEBUG) Log.d(TAG, "Canceling delete dialog");
                  }
                })
            .setPositiveButton(
                "Delete",
                new Dialog.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    processDelete(cursorToBlockItem(mCursor));
                  }
                })
            .create();
    alert.setOnDismissListener(
        new DialogInterface.OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {
            adapter.notifyDataSetChanged();
          }
        });
    alert.show();
  }
 @Override
 protected void onPostExecute(Void result) {
   if (progressDialog != null) {
     progressDialog.cancel();
   }
   if (!error) {
     restaurant.setCompleteDataLoaded(Boolean.TRUE);
   }
   dialog = new AlertDialog.Builder(activity).create();
   dialog.setInverseBackgroundForced(true);
   View view = createAndFillDataMovementLayout(restaurant, position);
   dialog.setView(view);
   dialog.show();
   dialog.setOnDismissListener(
       new DialogInterface.OnDismissListener() {
         public void onDismiss(DialogInterface dialog) {
           dialog.cancel();
         }
       });
 }
Example #17
0
  public void showProgressDialog(boolean canclelable) {
    if ((getActivity() == null) || (getActivity().isFinishing())) return;

    if (mProgressDialog == null) {
      mProgressDialog =
          new AlertDialog.Builder(mContext, R.style.dialog_progress_transparent).create();
      mProgressDialog.setCancelable(canclelable);
      mProgressDialog.setCanceledOnTouchOutside(false);
      mProgressDialog.setOnCancelListener(
          new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
              if (ivLoading != null) ivLoading.clearAnimation();
              //                    getAnimationDrawable(mProgressImageView).stop();
            }
          });
      mProgressDialog.setOnDismissListener(
          new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
              if (ivLoading != null) ivLoading.clearAnimation();
              //                    getAnimationDrawable(mProgressImageView).stop();
            }
          });
      //            mProgressImageView = (ImageView)
      // mInflater.inflate(R.layout.layout_load_progress, null);
      llProgress = (LinearLayout) mInflater.inflate(R.layout.layout_loading, null);
      ivLoading = (ImageView) llProgress.findViewById(R.id.image_loading);
    }

    mProgressDialog.show();
    Window window = mProgressDialog.getWindow();
    window.setGravity(Gravity.CENTER);
    //        window.setAddView(mProgressImageView);
    window.setContentView(llProgress);
    int width = (int) (ScreenUtils.getScreenW(mContext) * 1 / 3f);
    window.setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT);
    ivLoading.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.rotating));
    //        getAnimationDrawable(mProgressImageView).start();
  }
Example #18
0
 /**
  * 机选投注调用函数
  *
  * @param string 显示框信息
  * @return
  */
 public void alert_jixuan() {
   sensor.stopAction();
   buyImplement.touzhuNet(); // 投注类型和彩种
   setZhuShu(balls.size());
   toLogin = true;
   isGift = false;
   isJoin = false;
   isTouzhu = true;
   if (touZhuDialog == null) {
     initTouZhuDialog();
   } else {
     initAlerDialog();
   }
   touZhuDialog.setOnDismissListener(
       new OnDismissListener() {
         @Override
         public void onDismiss(DialogInterface dialog) {
           // TODO Auto-generated method stub
           sensor.startAction();
         }
       });
 }
  public Dialog create() {
    // Get resources
    View view = LayoutInflater.from(mContext).inflate(R.layout.dialog, null);

    TextView header = (TextView) view.findViewById(R.id.dialog_content);
    if (TextUtils.isEmpty(mHeaderText)) {
      header.setVisibility(View.GONE);
    } else {
      header.setVisibility(View.VISIBLE);
      header.setText(mHeaderText);
    }

    final WebView webView = (WebView) view.findViewById(R.id.dialog_webview);
    webView.loadDataWithBaseURL(null, mLicensesText, "text/html", "utf-8", null);

    final AlertDialog.Builder builder =
        new AlertDialog.Builder(mContext)
            .setTitle(mTitleText)
            .setView(view)
            .setPositiveButton(
                mCloseText,
                new Dialog.OnClickListener() {
                  public void onClick(final DialogInterface dialogInterface, final int i) {
                    dialogInterface.dismiss();
                  }
                });
    final AlertDialog dialog = builder.create();
    dialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(final DialogInterface dialog) {
            if (mOnDismissListener != null) {
              mOnDismissListener.onDismiss(dialog);
            }
          }
        });
    return dialog;
  }
  /**
   * Create menu
   *
   * @return
   */
  public Dialog createMenu(String menuItitle) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    builder.setTitle(menuItitle);
    builder.setAdapter(
        menuAdapter,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialoginterface, int i) {
            IconContextMenuItem item = (IconContextMenuItem) menuAdapter.getItem(i);

            if (clickHandler != null) {
              clickHandler.onClick(item.actionTag);
            }
          }
        });

    builder.setInverseBackgroundForced(true);

    AlertDialog dialog = builder.create();
    dialog.setOnCancelListener(this);
    dialog.setOnDismissListener(this);
    return dialog;
  }
 private void displayError(final Activity activity, String message) {
   Log.e(message);
   final AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
   alertDialog.setTitle(activity.getString(R.string.apptentive_oops));
   alertDialog.setMessage(message);
   alertDialog.setButton(
       AlertDialog.BUTTON_POSITIVE,
       activity.getString(R.string.apptentive_ok),
       new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialogInterface, int i) {
           alertDialog.dismiss();
         }
       });
   alertDialog.setOnDismissListener(
       new DialogInterface.OnDismissListener() {
         @Override
         public void onDismiss(DialogInterface dialog) {
           Log.d("Dismissing dialog and finishing Activity.");
           activity.finish();
         }
       });
   alertDialog.show();
 }
  @Override
  public void show() {
    LayoutInflater inflater =
        (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.device_dialog_abs, null);

    mProgressContainer = view.findViewById(R.id.progress_container);
    mProgressContainer.setVisibility(View.GONE);

    ViewGroup contentView = (ViewGroup) view.findViewById(R.id.device_dialog_content);
    contentView.addView(getContentView(inflater));

    mDialog =
        new AlertDialog.Builder(mContext)
            .setTitle(mDevice.getName())
            .setView(view)
            .setNegativeButton(R.string.esp_sss_device_dialog_exit, null)
            .show();
    mDialog.setOnDismissListener(this);
    mDialog.setCanceledOnTouchOutside(false);
    mDialog.setOnCancelListener(this);

    new StatusTask().execute();
  }
  private void createDialog(BluetoothDevice device, int state, int startId) {
    if (mDialog != null) {
      // Shouldn't normally happen
      mDialog.dismiss();
      mDialog = null;
    }
    mDevice = device;
    switch (state) {
      case Intent.EXTRA_DOCK_STATE_CAR:
      case Intent.EXTRA_DOCK_STATE_DESK:
      case Intent.EXTRA_DOCK_STATE_LE_DESK:
      case Intent.EXTRA_DOCK_STATE_HE_DESK:
        break;
      default:
        return;
    }

    startForeground(0, new Notification());

    final AlertDialog.Builder ab = new AlertDialog.Builder(this);
    View view;
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

    mAudioMediaCheckbox = null;

    if (device != null) {
      // Device in a new dock.
      boolean firstTime =
          !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress());

      CharSequence[] items = initBtSettings(device, state, firstTime);

      ab.setTitle(getString(R.string.bluetooth_dock_settings_title));

      // Profiles
      ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener);

      // Remember this settings
      view = inflater.inflate(R.layout.remember_dock_setting, null);
      CheckBox rememberCheckbox = (CheckBox) view.findViewById(R.id.remember);

      // check "Remember setting" by default if no value was saved
      boolean checked =
          firstTime
              || LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress());
      rememberCheckbox.setChecked(checked);
      rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
      if (DEBUG) {
        Log.d(
            TAG,
            "Auto connect = "
                + LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()));
      }
    } else {
      ab.setTitle(getString(R.string.bluetooth_dock_settings_title));

      view = inflater.inflate(R.layout.dock_audio_media_enable_dialog, null);
      mAudioMediaCheckbox = (CheckBox) view.findViewById(R.id.dock_audio_media_enable_cb);

      boolean checked =
          Settings.Global.getInt(getContentResolver(), Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0)
              == 1;

      mAudioMediaCheckbox.setChecked(checked);
      mAudioMediaCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
    }

    float pixelScaleFactor = getResources().getDisplayMetrics().density;
    int viewSpacingLeft = (int) (14 * pixelScaleFactor);
    int viewSpacingRight = (int) (14 * pixelScaleFactor);
    ab.setView(view, viewSpacingLeft, 0 /* top */, viewSpacingRight, 0 /* bottom */);

    // Ok Button
    ab.setPositiveButton(getString(android.R.string.ok), mClickListener);

    mStartIdAssociatedWithDialog = startId;
    mDialog = ab.create();
    mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    mDialog.setOnDismissListener(mDismissListener);
    mDialog.show();
  }
  /*
   * Create Dialog
   */
  @Override
  protected Dialog onCreateDialog(int id) {
    if (Log.DEBUG) Log.v("onCreateDialog()");

    switch (id) {
        /*
         * Delete message dialog
         */
      case DIALOG_DELETE:
        return new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(getString(R.string.pref_show_delete_button_dialog_title))
            .setMessage(getString(R.string.pref_show_delete_button_dialog_text))
            .setPositiveButton(
                android.R.string.ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    deleteMessage();
                  }
                })
            .setNegativeButton(android.R.string.cancel, null)
            .create();

        /*
         * Quick Reply Dialog
         */
      case DIALOG_QUICKREPLY:
        LayoutInflater factory = getLayoutInflater();
        final View qrLayout = factory.inflate(R.layout.message_quick_reply, null);
        qrEditText = (EditText) qrLayout.findViewById(R.id.QuickReplyEditText);
        final TextView qrCounterTextView =
            (TextView) qrLayout.findViewById(R.id.QuickReplyCounterTextView);
        final Button qrSendButton = (Button) qrLayout.findViewById(R.id.send_button);

        final ImageButton voiceRecognitionButton =
            (ImageButton) qrLayout.findViewById(R.id.SpeechRecogButton);

        voiceRecognitionButton.setOnClickListener(
            new OnClickListener() {
              public void onClick(View view) {
                final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                intent.putExtra(
                    RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

                // Check if the device has the ability to do speech recognition
                final PackageManager packageManager = SmsPopupActivity.this.getPackageManager();
                List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);

                if (list.size() > 0) {
                  // TODO: really I should allow voice input here without unlocking first (I allow
                  // quick replies without unlock anyway)
                  exitingKeyguardSecurely = true;
                  ManageKeyguard.exitKeyguardSecurely(
                      new LaunchOnKeyguardExit() {
                        public void LaunchOnKeyguardExitSuccess() {
                          SmsPopupActivity.this.startActivityForResult(
                              intent, VOICE_RECOGNITION_REQUEST_CODE);
                        }
                      });
                } else {
                  Toast.makeText(
                          SmsPopupActivity.this,
                          R.string.error_no_voice_recognition,
                          Toast.LENGTH_LONG)
                      .show();
                  view.setEnabled(false);
                }
              }
            });

        qrEditText.addTextChangedListener(new QmTextWatcher(this, qrCounterTextView, qrSendButton));
        qrEditText.setOnEditorActionListener(
            new OnEditorActionListener() {
              public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                // event != null means enter key pressed
                if (event != null) {
                  // if shift is not pressed then move focus to send button
                  if (!event.isShiftPressed()) {
                    if (v != null) {
                      View focusableView = v.focusSearch(View.FOCUS_RIGHT);
                      if (focusableView != null) {
                        focusableView.requestFocus();
                        return true;
                      }
                    }
                  }

                  // otherwise allow keypress through
                  return false;
                }

                if (actionId == EditorInfo.IME_ACTION_SEND) {
                  if (v != null) {
                    sendQuickReply(v.getText().toString());
                  }
                  return true;
                }

                // else consume
                return true;
              }
            });

        quickreplyTextView = (TextView) qrLayout.findViewById(R.id.QuickReplyTextView);
        QmTextWatcher.getQuickReplyCounterText(
            qrEditText.getText().toString(), qrCounterTextView, qrSendButton);

        qrSendButton.setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                sendQuickReply(qrEditText.getText().toString());
              }
            });

        // Construct basic AlertDialog using AlertDialog.Builder
        final AlertDialog qrAlertDialog =
            new AlertDialog.Builder(this)
                .setIcon(android.R.drawable.ic_dialog_email)
                .setTitle(R.string.quickreply_title)
                .create();

        // Set the custom layout with no spacing at the bottom
        qrAlertDialog.setView(qrLayout, 0, 5, 0, 0);

        // Preset messages button
        Button presetButton = (Button) qrLayout.findViewById(R.id.PresetMessagesButton);
        presetButton.setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                showDialog(DIALOG_PRESET_MSG);
              }
            });

        // Cancel button
        Button cancelButton = (Button) qrLayout.findViewById(R.id.CancelButton);
        cancelButton.setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                if (qrAlertDialog != null) {
                  hideSoftKeyboard();
                  qrAlertDialog.dismiss();
                }
              }
            });

        // Ensure this dialog is counted as "editable" (so soft keyboard will always show on top)
        qrAlertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

        qrAlertDialog.setOnDismissListener(
            new OnDismissListener() {
              public void onDismiss(DialogInterface dialog) {
                if (Log.DEBUG) Log.v("Quick Reply Dialog: onDissmiss()");
              }
            });

        // Update quick reply views now that they have been created
        updateQuickReplyView("");

        /*
         * TODO: due to what seems like a bug, setting selection to 0 here doesn't seem to work
         * but setting it to 1 first then back to 0 does.  I couldn't find a way around this :|
         * To reproduce, comment out the below line and set a quick reply signature, when
         * clicking Quick Reply the cursor will be positioned at the end of the EditText
         * rather than the start.
         */
        if (qrEditText.getText().toString().length() > 0) qrEditText.setSelection(1);

        qrEditText.setSelection(0);

        return qrAlertDialog;

        /*
         * Preset messages dialog
         */
      case DIALOG_PRESET_MSG:
        mDbAdapter.open(true);
        mCursor = mDbAdapter.fetchAllQuickMessages();
        startManagingCursor(mCursor);

        AlertDialog.Builder mDialogBuilder =
            new AlertDialog.Builder(this)
                .setIcon(android.R.drawable.ic_dialog_email)
                .setTitle(R.string.pref_message_presets_title)
                .setOnCancelListener(
                    new OnCancelListener() {
                      public void onCancel(DialogInterface dialog) {
                        showDialog(DIALOG_QUICKREPLY);
                      }
                    });

        // If user has some presets defined ...
        if (mCursor != null && mCursor.getCount() > 0) {

          mDialogBuilder.setCursor(
              mCursor,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                  if (Log.DEBUG) Log.v("Item clicked = " + item);
                  mCursor.moveToPosition(item);
                  if (Log.DEBUG)
                    Log.v(
                        "Item text = " + mCursor.getString(SmsPopupDbAdapter.KEY_QUICKMESSAGE_NUM));

                  quickReply(mCursor.getString(SmsPopupDbAdapter.KEY_QUICKMESSAGE_NUM));
                }
              },
              SmsPopupDbAdapter.KEY_QUICKMESSAGE);
        } else { // Otherwise display a placeholder as user has no presets
          MatrixCursor emptyCursor =
              new MatrixCursor(
                  new String[] {SmsPopupDbAdapter.KEY_ROWID, SmsPopupDbAdapter.KEY_QUICKMESSAGE});
          emptyCursor.addRow(new String[] {"0", getString(R.string.message_presets_empty_text)});
          mDialogBuilder.setCursor(
              emptyCursor,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                  // startActivity(new Intent(
                  // SmsPopupActivity.this.getApplicationContext(),
                  // net.everythingandroid.smspopup.ConfigPresetMessagesActivity.class));
                }
              },
              SmsPopupDbAdapter.KEY_QUICKMESSAGE);
        }

        return mDialogBuilder.create();

        /*
         * Loading Dialog
         */
      case DIALOG_LOADING:
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setMessage(getString(R.string.loading_message));
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setCancelable(true);
        return mProgressDialog;
    }

    return null;
  }
        @Override
        public void onClick(DialogInterface dialog, int which) {
          final String dirName = mSelectedDir.getName();
          final String dirPath = mSelectedDir.getPath();
          final String dirParent = mSelectedDir.getParent();

          switch (which) {
            case ACTION_RENAME:
              {
                final TextInputDialog dlg =
                    new TextInputDialog(mContext, android.R.string.ok, android.R.string.cancel);
                dlg.setFinishTextInputListener(
                    new TextInputDialog.FinishTextInputListener() {
                      public void onFinishTextInput(CharSequence input) {
                        String inputName = input.toString();
                        inputName = inputName.replace("\n", "").trim();
                        File file = new File(dirPath);
                        File dstFile = new File(dirParent + "/" + inputName);
                        file.renameTo(dstFile);
                        mNeedReload = true;
                      }
                    });
                dlg.setOnDismissListener(
                    new OnDismissListener() {
                      @Override
                      public void onDismiss(DialogInterface dialog) {
                        if (mNeedReload) {
                          mNeedReload = false;
                          mActivity.reload();
                        }
                      }
                    });
                dlg.show(
                    R.string.backup_manage_rename, R.string.backup_manage_rename_message, dirName);
              }
              break;
            case ACTION_DELETE:
              {
                final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
                alertDialogBuilder.setTitle(R.string.backup_manage_delete);
                alertDialogBuilder.setMessage(R.string.backup_manage_delete_confirm);
                alertDialogBuilder.setPositiveButton(
                    android.R.string.yes,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                        File file = new File(dirPath);
                        Misc.deleteDir(file);
                        mNeedReload = true;
                      }
                    });
                alertDialogBuilder.setNegativeButton(android.R.string.no, null);
                AlertDialog dlg = alertDialogBuilder.create();
                dlg.setOnDismissListener(
                    new OnDismissListener() {
                      @Override
                      public void onDismiss(DialogInterface dialog) {
                        if (mNeedReload) {
                          mNeedReload = false;
                          mActivity.reload();
                        }
                      }
                    });
                dlg.show();
              }
              break;
          }
        }
Example #26
0
  /** 联系人选择框 */
  public void LinkDialog() {
    isDialog = true;
    Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
    persons.clear();
    while (c.moveToNext()) {
      int index = c.getColumnIndex(People.NUMBER);
      int indexName = c.getColumnIndex(People.NAME);
      Person person = new Person(c.getString(indexName), c.getString(index));
      if (person.phone != null) {
        persons.add(person);
      }
    }
    startManagingCursor(c);
    checkedState = new boolean[persons.size()];

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.dialog_advice, null);
    TextView title = (TextView) v.findViewById(R.id.alert_dialog_touzhu_text_title);
    title.setText(R.string.ruyichuanqing_phonetext);

    final AlertDialog adviceDialog = new AlertDialog.Builder(this).create();

    adviceDialog.setOnDismissListener(
        new OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub;
            phoneStr = "";
            for (int i = 0; i < checkedPersons.size(); i++) {
              phoneStr += checkedPersons.get(i).phone;
              if (i != checkedPersons.size() - 1) {
                phoneStr += ",";
              }
            }

            editPhone.setText(phoneStr);
          }
        });
    avdiceList = (ListView) v.findViewById(R.id.dialog_advice_list);
    avdiceList.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            adviceDialog.cancel();
            editPhone.setText(persons.get(position).phone);
          }
        });

    // 数据源
    list = getListForLinkAdapter(persons);
    LinkAdapter adapter = new LinkAdapter(this, list);
    avdiceList.setItemsCanFocus(false);
    avdiceList.setAdapter(adapter);

    Button ok = (Button) v.findViewById(R.id.dialog_advice_img_ok);
    ok.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            //				adviceDialog.cancel();
            dialogOk();
          }
        });

    if (persons.size() == 0) {
      Toast.makeText(this, R.string.ruyichuanqing_thecontactsisnull, Toast.LENGTH_SHORT).show();
    } else {
      //			adviceDialog.show();
      //			adviceDialog.getWindow().setContentView(v);
      setContentView(v);
    }
    final EditText checkEdit = (EditText) v.findViewById(R.id.dialog_advice_edit_check);
    checkEdit.setVisibility(EditText.VISIBLE);
    checkEdit.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            Vector<Person> newPersons = new Vector<Person>(); // 所有联系人
            String nameStr = checkEdit.getText().toString();
            if (nameStr != null && !nameStr.equals("")) {
              for (int i = 0; i < persons.size(); i++) {
                if (persons.get(i).name != null && persons.get(i).name.indexOf(nameStr) != -1) {
                  persons.get(i).checkName = nameStr;
                  newPersons.add(persons.get(i));
                }
              }
              // 数据源
              list = getListForLinkAdapter(newPersons);
              LinkAdapter adapter = new LinkAdapter(GiftActivity.this, list);
              avdiceList.setItemsCanFocus(false);
              avdiceList.setAdapter(adapter);
            } else {
              for (int i = 0; i < persons.size(); i++) {
                persons.get(i).checkName = nameStr;
              }
              // 数据源
              list = getListForLinkAdapter(persons);
              LinkAdapter adapter = new LinkAdapter(GiftActivity.this, list);
              avdiceList.setItemsCanFocus(false);
              avdiceList.setAdapter(adapter);
            }
          }
        });
  }
Example #27
0
  private void add() {

    final EditText input = new EditText(getSherlockActivity());
    input.setInputType(InputType.TYPE_CLASS_PHONE);

    final AlertDialog alert =
        new AlertDialog.Builder(getSherlockActivity())
            .setTitle(
                getSherlockActivity()
                    .getResources()
                    .getString(R.string.dialog_add_call_block_title))
            .setMessage(
                getSherlockActivity().getResources().getString(R.string.dialog_add_block_message))
            .setView(input)
            .setCancelable(true)
            .setNegativeButton(
                "Cancel",
                new Dialog.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    if (DEBUG) Log.d(TAG, "Canceling add item dialog");
                  }
                })
            .setPositiveButton(
                "Done",
                new Dialog.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    String temp = input.getText().toString();
                    String phoneNum = PhoneNumberUtils.formatNumber(temp);

                    // Create a block item in the database
                    ContentValues values = new ContentValues(2);
                    values.put(
                        BlockItemTable.COLUMN_NUMBER, PhoneNumberUtils.stripSeparators(phoneNum));
                    values.put(BlockItemTable.COLUMN_LAST_CONTACT, -1337);
                    loader.insert(BlockItemTable.CALLBLOCK_TABLE_NAME, null, values);

                    dialog.dismiss();
                  }
                })
            .create();

    alert.setOnDismissListener(
        new DialogInterface.OnDismissListener() {

          @Override
          public void onDismiss(DialogInterface dialog) {

            adapter.notifyDataSetChanged();
          }
        });

    input.addTextChangedListener(
        new TextWatcher() {

          private PhoneNumber number = null;
          private String locale =
              getSherlockActivity().getResources().getConfiguration().locale.getCountry();
          PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {

            try {
              number = phoneUtil.parse(s.toString(), locale);
            } catch (NumberParseException e) {
              // do nothing
            }
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable editable) {

            if (number != null) {
              if (!phoneUtil.isValidNumber(number)) {
                alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
              } else {
                if (DEBUG) Log.d(TAG, "Valid number: " + number.toString());
                alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
              }
            }
          }
        });
    alert.show();
    alert.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
  }
Example #28
0
  @Override
  protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    AlertDialog dialog = null;
    switch (id) {
      case DIALOG_CREATE_MASTER_PASSWORD:
        final EditText input1 = getTextBox(R.string.masterpassword_password);
        final EditText input2 = getTextBox(R.string.masterpassword_confirm);
        linearLayout.addView(input1);
        linearLayout.addView(input2);

        builder
            .setTitle(R.string.masterpassword_create_title)
            .setView((View) linearLayout)
            .setPositiveButton(
                R.string.button_ok,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    JSONObject jsonPref = new JSONObject();
                    try {
                      jsonPref.put("name", PREFS_MP_ENABLED);
                      jsonPref.put("type", "string");
                      jsonPref.put("value", input1.getText().toString());

                      GeckoEvent event =
                          GeckoEvent.createBroadcastEvent("Preferences:Set", jsonPref.toString());
                      GeckoAppShell.sendEventToGecko(event);
                    } catch (Exception ex) {
                      Log.e(LOGTAG, "Error setting master password", ex);
                    }
                    return;
                  }
                })
            .setNegativeButton(
                R.string.button_cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    return;
                  }
                });
        dialog = builder.create();
        dialog.setOnShowListener(
            new DialogInterface.OnShowListener() {
              @Override
              public void onShow(DialogInterface dialog) {
                input1.setText("");
                input2.setText("");
                input1.requestFocus();
              }
            });

        PasswordTextWatcher watcher = new PasswordTextWatcher(input1, input2, dialog);
        input1.addTextChangedListener((TextWatcher) watcher);
        input2.addTextChangedListener((TextWatcher) watcher);

        break;
      case DIALOG_REMOVE_MASTER_PASSWORD:
        final EditText input = getTextBox(R.string.masterpassword_password);
        linearLayout.addView(input);

        builder
            .setTitle(R.string.masterpassword_remove_title)
            .setView((View) linearLayout)
            .setPositiveButton(
                R.string.button_ok,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    PrefsHelper.setPref(PREFS_MP_ENABLED, input.getText().toString());
                  }
                })
            .setNegativeButton(
                R.string.button_cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    return;
                  }
                });
        dialog = builder.create();
        dialog.setOnDismissListener(
            new DialogInterface.OnDismissListener() {
              @Override
              public void onDismiss(DialogInterface dialog) {
                input.setText("");
              }
            });
        dialog.setOnShowListener(
            new DialogInterface.OnShowListener() {
              @Override
              public void onShow(DialogInterface dialog) {
                input.setText("");
              }
            });
        input.addTextChangedListener(new EmptyTextWatcher(input, dialog));
        break;
      default:
        return null;
    }

    return dialog;
  }
Example #29
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);
    }
  }
  private void permissionsDialog(final FinishedApk viewApk, ArrayList<ApkPermission> permissions) {

    View v = LayoutInflater.from(context).inflate(R.layout.app_permission, null);
    LinearLayout layout = (LinearLayout) v.findViewById(R.id.container);

    if (permissions != null) {

      if (!permissions.isEmpty()) {
        for (int i = 0; i < permissions.size(); i++) {
          ApkPermission permission = permissions.get(i);

          View permissionView = LayoutInflater.from(context).inflate(R.layout.row_permission, null);
          if (i == 0 || !permissions.get(i - 1).getName().equals(permission.getName())) {
            ((TextView) permissionView.findViewById(R.id.permission_name))
                .setText(permission.getName());
          } else {
            permissionView.findViewById(R.id.permission_name).setVisibility(View.GONE);
          }
          ((TextView) permissionView.findViewById(R.id.permission_description))
              .setText(permission.getDescription());
          layout.addView(permissionView);
        }
      } else {
        TextView tv = new TextView(context);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(context.getString(R.string.no_permissions_required));
        layout.addView(tv);
      }
    }

    final AlertDialog dialog = new AlertDialog.Builder(context).setView(v).create();
    dialog.setTitle(context.getString(R.string.restore) + " " + viewApk.getName() + "?");
    // dialog.setIcon(BitmapDrawable.createFromPath(ImageLoader.getInstance().getDiscCache().get(path).getAbsolutePath()));

    dialog.setButton(
        DialogInterface.BUTTON_POSITIVE,
        context.getString(android.R.string.yes),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            executor.submit(
                new Runnable() {
                  @Override
                  public void run() {
                    DownloadUtils.installWithRoot(viewApk);
                  }
                });
            finish();
          }
        });

    dialog.setButton(
        DialogInterface.BUTTON_NEGATIVE,
        context.getString(android.R.string.no),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
          }
        });
    dialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(DialogInterface dialog) {
            finish();
          }
        });
    dialog.setCancelable(false);
    // dialog.show();

    String path = viewApk.getIconPath();
    GlideUtils.showDialogWithGlideLoadingIconFromCache(dialog, path, this);
  }