Example #1
0
 @Override
 public void onClick(DialogInterface dialog, int which) {
   switch (which) {
     case DialogInterface.BUTTON_POSITIVE:
       SharedPrefs.setServerName(mServerName.getText().toString());
       connect(mServerName.getText().toString(), null);
       break;
     case DialogInterface.BUTTON_NEGATIVE:
       dialog.cancel();
       break;
     default:
       super.onClick(dialog, which);
   }
 }
Example #2
0
  @Override
  protected View onCreateDialogView() {
    View dialogLayout = View.inflate(mContext, R.layout.dialog_sql_pref, null);

    // анимация поворота стрелки
    final Animation rotationAnim = AnimationUtils.loadAnimation(mContext, R.anim.rotate);
    rotationAnim.setRepeatCount(Animation.INFINITE);

    mInputServerName =
        (TextInputLayout) dialogLayout.findViewById(R.id.preference_item_sql_input_server);
    mServerName = mInputServerName.getEditText();
    mCheckServerConnect =
        (ImageView) dialogLayout.findViewById(R.id.preference_item_sql_check_connect);
    mServerStatus = (ImageView) dialogLayout.findViewById(R.id.preference_item_sql_status);

    mServerName.setText(SharedPrefs.getServerName());

    mCheckServerConnect.startAnimation(rotationAnim);

    connect(mServerName.getText().toString(), mCallback);

    mCheckServerConnect.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mInputServerName.getEditText().getText().length() == 0) {
              mInputServerName.setErrorEnabled(true);
              mInputServerName.setError(
                  App.getAppContext().getString(R.string.input_sql_server_name_error));
            } else {
              mCheckServerConnect.startAnimation(rotationAnim);
              connect(mServerName.getText().toString(), mCallback);
            }
          }
        });

    // если android по 4.4 включительно, то включаем программное ускорение
    // иначе анимация не работает
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
      mCheckServerConnect.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    return dialogLayout;
  }