47 void onConnectCancel();
50 private final Activity activity;
52 private final Handler mainHandler =
new Handler(Looper.getMainLooper());
54 private final AlertDialog dlgVerifyCertificate;
55 private final AlertDialog dlgUserCredentials;
56 private final View userCredView;
58 private AlertDialog progressDialog;
60 private boolean callbackDialogResult;
64 this.activity = activity;
65 this.cancelListener = cancelListener;
67 dlgVerifyCertificate =
new AlertDialog.Builder(activity)
68 .setTitle(R.string.dlg_title_verify_certificate)
69 .setPositiveButton(android.R.string.yes,
71 callbackDialogResult = true;
77 .setNegativeButton(android.R.string.no,
79 callbackDialogResult = false;
89 userCredView = activity.getLayoutInflater().inflate(R.layout.credentials,
null,
true);
90 dlgUserCredentials =
new AlertDialog.Builder(activity)
91 .setView(userCredView)
92 .setTitle(R.string.dlg_title_credentials)
93 .setPositiveButton(android.R.string.ok,
95 callbackDialogResult = true;
101 .setNegativeButton(android.R.string.cancel,
103 callbackDialogResult = false;
105 synchronized (dialog)
110 .setCancelable(
false)
119 StringBuilder password)
121 callbackDialogResult =
false;
123 ((EditText)userCredView.findViewById(R.id.editTextUsername)).setText(username);
124 ((EditText)userCredView.findViewById(R.id.editTextDomain)).setText(domain);
125 ((EditText)userCredView.findViewById(R.id.editTextPassword)).setText(password);
127 showOnUiThread(dlgUserCredentials);
131 synchronized (dlgUserCredentials)
133 dlgUserCredentials.wait();
136 catch (InterruptedException e)
140 username.setLength(0);
142 password.setLength(0);
145 ((EditText)userCredView.findViewById(R.id.editTextUsername)).getText().toString());
147 ((EditText)userCredView.findViewById(R.id.editTextDomain)).getText().toString());
149 ((EditText)userCredView.findViewById(R.id.editTextPassword)).getText().toString());
151 return callbackDialogResult;
158 String fingerprint,
long flags)
160 String msg = activity.getResources().getString(R.string.dlg_msg_verify_certificate);
161 String type =
"RDP-Server";
162 if ((flags & LibFreeRDP.VERIFY_CERT_FLAG_GATEWAY) != 0)
163 type =
"RDP-Gateway";
164 if ((flags & LibFreeRDP.VERIFY_CERT_FLAG_REDIRECT) != 0)
165 type =
"RDP-Redirect";
166 msg +=
"\n\n" + type +
": " + host +
":" + port;
167 msg +=
"\n\nSubject: " + subject +
"\nIssuer: " + issuer;
168 if ((flags & LibFreeRDP.VERIFY_CERT_FLAG_FP_IS_PEM) != 0)
169 msg +=
"\nCertificate: " + fingerprint;
171 msg +=
"\nFingerprint: " + fingerprint;
173 return showVerifyDialog(msg);
180 String fingerprint,
long flags)
184 return verifyCertificate(host, port, subject, issuer, fingerprint, flags);
187 private int showVerifyDialog(String msg)
189 callbackDialogResult =
false;
190 dlgVerifyCertificate.setMessage(msg);
192 showOnUiThread(dlgVerifyCertificate);
196 synchronized (dlgVerifyCertificate)
198 dlgVerifyCertificate.wait();
201 catch (InterruptedException e)
205 return callbackDialogResult ? 1 : 0;
208 private void showOnUiThread(
final AlertDialog dialog)
210 mainHandler.post(dialog::show);
213 private void notifyCancel()
215 if (cancelListener !=
null)
216 cancelListener.onUserCancel();
227 int pad = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24,
228 activity.getResources().getDisplayMetrics());
229 LinearLayout content =
new LinearLayout(activity);
230 content.setOrientation(LinearLayout.HORIZONTAL);
231 content.setPadding(pad, pad, pad, pad);
232 content.setGravity(Gravity.CENTER_VERTICAL);
234 ProgressBar progressBar =
new ProgressBar(activity);
235 progressBar.setIndeterminate(
true);
236 content.addView(progressBar,
237 new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
238 ViewGroup.LayoutParams.WRAP_CONTENT));
240 TextView messageView =
new TextView(activity);
241 messageView.setText(R.string.dlg_msg_connecting);
242 LinearLayout.LayoutParams textParams =
new LinearLayout.LayoutParams(
243 ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
244 textParams.leftMargin = pad;
245 content.addView(messageView, textParams);
247 progressDialog =
new AlertDialog.Builder(activity)
250 .setNegativeButton(android.R.string.cancel,
252 if (listener != null)
253 listener.onConnectCancel();
255 .setCancelable(
false)
257 progressDialog.show();
263 if (progressDialog !=
null)
265 progressDialog.dismiss();
266 progressDialog =
null;