List of usage examples for android.app Dialog setOnKeyListener
public void setOnKeyListener(@Nullable OnKeyListener onKeyListener)
From source file:org.wso2.emm.agent.AuthenticationActivity.java
/** * Show the license text retrieved from the server. * * @param message Message text to be shown as the license. * @param title Title of the license.// w w w . ja va 2 s .c om */ private void showAgreement(final String message, String title) { AuthenticationActivity.this.runOnUiThread(new Runnable() { @Override public void run() { final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.custom_terms_popup); dialog.setTitle(Constants.EULA_TITLE); dialog.setCancelable(false); WebView webView = (WebView) dialog.findViewById(R.id.webview); webView.loadDataWithBaseURL(null, message, Constants.MIME_TYPE, Constants.ENCODING_METHOD, null); Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); Button cancelButton = (Button) dialog.findViewById(R.id.dialogButtonCancel); dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Preference.putBoolean(context, Constants.PreferenceFlag.IS_AGREED, true); dialog.dismiss(); //load the next intent based on ownership type checkManifestPermissions(); } }); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); CommonUtils.clearClientCredentials(context); cancelEntry(); } }); dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == Constants.DEFAILT_REPEAT_COUNT) { return true; } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == Constants.DEFAILT_REPEAT_COUNT) { return true; } return false; } }); dialog.show(); } }); }
From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java
/** * Show the license text retrieved from the server. * * @param licenseText Message text to be shown as the license. * @param title Title of the license.//w w w .java 2s . co m */ private void showAgreement(final String licenseText, final String title) { AuthenticationActivity.this.runOnUiThread(new Runnable() { @Override public void run() { final Dialog dialog = new Dialog(context, R.style.Dialog); dialog.setContentView(R.layout.dialog_license); dialog.setCancelable(false); WebView webView = (WebView) dialog.findViewById(R.id.webViewLicense); webView.loadDataWithBaseURL(null, licenseText, Constants.MIME_TYPE, Constants.ENCODING_METHOD, null); TextView textViewTitle = (TextView) dialog.findViewById(R.id.textViewDeviceNameTitle); textViewTitle.setText(title); Button btnAgree = (Button) dialog.findViewById(R.id.dialogButtonOK); Button btnCancel = (Button) dialog.findViewById(R.id.dialogButtonCancel); btnAgree.setOnClickListener(new OnClickListener() { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onClick(View v) { Preference.putBoolean(context, Constants.PreferenceFlag.IS_AGREED, true); dialog.dismiss(); //load the next intent based on ownership type startDeviceAdminPrompt(); } }); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); CommonUtils.clearClientCredentials(context); cancelEntry(); } }); dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == Constants.DEFAULT_REPEAT_COUNT) { return true; } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == Constants.DEFAULT_REPEAT_COUNT) { return true; } return false; } }); dialog.show(); } }); }
From source file:mobisocial.musubi.ui.fragments.EulaFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.setContentView(R.layout.eula); //load the tabs mTabs = (TabHost) dialog.findViewById(android.R.id.tabhost); mTabs.setup();/*from w ww . j a va 2s. co m*/ TabSpec tab_one = mTabs.newTabSpec("eula_tab"); tab_one.setContent(R.id.eula_body); tab_one.setIndicator("EULA"); mTabs.addTab(tab_one); TabSpec tab_two = mTabs.newTabSpec("privacy_tab"); tab_two.setContent(R.id.priv_body); tab_two.setIndicator("Privacy Policy"); mTabs.addTab(tab_two); //work around lack of ability to control tab height from xml completely TabWidget tab_widget = (TabWidget) dialog.findViewById(android.R.id.tabs); mTabs.getTabWidget().getChildAt(0).getLayoutParams().height = tab_widget.getLayoutParams().height; mTabs.getTabWidget().getChildAt(1).getLayoutParams().height = tab_widget.getLayoutParams().height; //load the agreements mEulaScroll = (ScrollView) dialog.findViewById(R.id.eula_scroll); mLoading = (LinearLayout) dialog.findViewById(R.id.loading); mEulaBodyView = (TextView) dialog.findViewById(R.id.eula_body); mPrivacyBodyView = (TextView) dialog.findViewById(R.id.priv_body); mAcceptedCheckbox = (CheckBox) dialog.findViewById(R.id.eula_checkbox); mAcceptButton = (Button) dialog.findViewById(R.id.eula_accept); mRejectButton = (Button) dialog.findViewById(R.id.eula_reject); mEmailButton = (Button) dialog.findViewById(R.id.eula_email); mDismissButton = (Button) dialog.findViewById(R.id.eula_dismiss); mEulaAcceptArea = (LinearLayout) dialog.findViewById(R.id.eula_accept_area); mAcceptedCheckbox.setOnCheckedChangeListener(new OnAcceptToggle()); mAcceptButton.setOnClickListener(new OnAccept()); mRejectButton.setOnClickListener(new OnReject()); mEmailButton.setOnClickListener(new OnEmail()); mDismissButton.setOnClickListener(new OnDismiss()); if (!mRequired) { mEulaAcceptArea.setVisibility(View.GONE); mAcceptButton.setVisibility(View.GONE); mRejectButton.setVisibility(View.GONE); mDismissButton.setVisibility(View.VISIBLE); } else { mEulaAcceptArea.setVisibility(View.VISIBLE); mAcceptButton.setVisibility(View.VISIBLE); mRejectButton.setVisibility(View.VISIBLE); mDismissButton.setVisibility(View.GONE); } mAcceptButton.setEnabled(mAcceptedCheckbox.isChecked()); dialog.setTitle("Musubi Usage Agreements"); dialog.setOnKeyListener(new OnKey()); new AgreementLoader().execute(); return dialog; }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
private void closeScanRemoteNetworkProgressDlg(final Dialog dialog, final NotifyEvent p_ntfy, final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final TextView tvmsg) { final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address); final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress); final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok); final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel); ll_addr.setVisibility(LinearLayout.VISIBLE); ll_prog.setVisibility(LinearLayout.GONE); btn_scan.setVisibility(Button.VISIBLE); btn_cancel.setVisibility(Button.VISIBLE); adap.setButtonEnabled(true);//from ww w .j a v a2s . c o m dialog.setOnKeyListener(null); dialog.setCancelable(true); if (p_ntfy != null) p_ntfy.notifyToListener(true, null); }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
private void scanRemoteNetwork(final Dialog dialog, final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final ArrayList<ScanAddressResultListItem> ipAddressList, final String subnet, final int begin_addr, final int end_addr, final NotifyEvent p_ntfy) { final Handler handler = new Handler(); final ThreadCtrl tc = new ThreadCtrl(); final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address); final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress); final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_progress_msg); final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok); final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel); final Button scan_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_progress_cancel); final CheckedTextView ctv_use_port_number = (CheckedTextView) dialog .findViewById(R.id.scan_remote_ntwk_ctv_use_port); final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number); tvmsg.setText(""); scan_cancel.setText(R.string.msgs_scan_progress_spin_dlg_addr_cancel); ll_addr.setVisibility(LinearLayout.GONE); ll_prog.setVisibility(LinearLayout.VISIBLE); btn_scan.setVisibility(Button.GONE); btn_cancel.setVisibility(Button.GONE); adap.setButtonEnabled(false);//from w w w. j a va 2 s. c om scan_cancel.setEnabled(true); dialog.setOnKeyListener(new DialogBackKeyListener(mContext)); dialog.setCancelable(false); // CANCEL? scan_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { scan_cancel.setText(mContext.getString(R.string.msgs_progress_dlg_canceling)); scan_cancel.setEnabled(false); util.addDebugMsg(1, "W", "IP Address list creation was cancelled"); tc.setDisabled(); } }); dialog.show(); util.addDebugMsg(1, "I", "Scan IP address ransge is " + subnet + "." + begin_addr + " - " + end_addr); final String scan_prog = mContext.getString(R.string.msgs_ip_address_scan_progress); String p_txt = String.format(scan_prog, 0); tvmsg.setText(p_txt); new Thread(new Runnable() { @Override public void run() {//non UI thread mScanCompleteCount = 0; mScanAddrCount = end_addr - begin_addr + 1; int scan_thread = 60; String scan_port = ""; if (ctv_use_port_number.isChecked()) scan_port = et_port_number.getText().toString(); for (int i = begin_addr; i <= end_addr; i += scan_thread) { if (!tc.isEnabled()) break; boolean scan_end = false; for (int j = i; j < (i + scan_thread); j++) { if (j <= end_addr) { startRemoteNetworkScanThread(handler, tc, dialog, p_ntfy, lv_ipaddr, adap, tvmsg, subnet + "." + j, ipAddressList, scan_port); } else { scan_end = true; } } if (!scan_end) { for (int wc = 0; wc < 210; wc++) { if (!tc.isEnabled()) break; SystemClock.sleep(30); } } } if (!tc.isEnabled()) { handler.post(new Runnable() {// UI thread @Override public void run() { closeScanRemoteNetworkProgressDlg(dialog, p_ntfy, lv_ipaddr, adap, tvmsg); } }); } else { handler.postDelayed(new Runnable() {// UI thread @Override public void run() { closeScanRemoteNetworkProgressDlg(dialog, p_ntfy, lv_ipaddr, adap, tvmsg); } }, 10000); } } }).start(); }
From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java
private void closeScanRemoteNetworkProgressDlg(final Dialog dialog, final NotifyEvent p_ntfy, final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final TextView tvmsg) { final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address); final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress); final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok); final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel); ll_addr.setVisibility(LinearLayout.VISIBLE); ll_prog.setVisibility(LinearLayout.GONE); btn_scan.setEnabled(true);/*from w w w . j av a 2s. c o m*/ btn_cancel.setEnabled(true); adap.setButtonEnabled(true); dialog.setOnKeyListener(null); dialog.setCancelable(true); if (p_ntfy != null) p_ntfy.notifyToListener(true, null); }
From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java
private void scanRemoteNetwork(final Dialog dialog, final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final ArrayList<ScanAddressResultListItem> ipAddressList, final String subnet, final int begin_addr, final int end_addr, final NotifyEvent p_ntfy) { final Handler handler = new Handler(); final ThreadCtrl tc = new ThreadCtrl(); final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address); final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress); final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_progress_msg); final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok); final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel); final Button scan_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_progress_cancel); final CheckBox cb_use_port_number = (CheckBox) dialog.findViewById(R.id.scan_remote_ntwk_use_port); final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number); tvmsg.setText(""); scan_cancel.setText(R.string.msgs_progress_spin_dlg_addr_cancel); ll_addr.setVisibility(LinearLayout.GONE); ll_prog.setVisibility(LinearLayout.VISIBLE); btn_scan.setEnabled(false);/*from w w w . j a va 2s. com*/ btn_cancel.setEnabled(false); adap.setButtonEnabled(false); scan_cancel.setEnabled(true); dialog.setOnKeyListener(new DialogBackKeyListener(mContext)); dialog.setCancelable(false); // CANCEL? scan_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { scan_cancel.setText(mContext.getString(R.string.msgs_progress_dlg_canceling)); scan_cancel.setEnabled(false); sendDebugLogMsg(1, "W", "IP Address list creation was cancelled"); tc.setDisabled(); } }); dialog.show(); sendDebugLogMsg(1, "I", "Scan IP address ransge is " + subnet + "." + begin_addr + " - " + end_addr); final String scan_prog = mContext.getString(R.string.msgs_ip_address_scan_progress); String p_txt = String.format(scan_prog, 0); tvmsg.setText(p_txt); new Thread(new Runnable() { @Override public void run() {//non UI thread mScanCompleteCount = 0; mScanAddrCount = end_addr - begin_addr + 1; int scan_thread = 50; String scan_port = ""; if (cb_use_port_number.isChecked()) scan_port = et_port_number.getText().toString(); for (int i = begin_addr; i <= end_addr; i += scan_thread) { if (!tc.isEnabled()) break; boolean scan_end = false; for (int j = i; j < (i + scan_thread); j++) { if (j <= end_addr) { startRemoteNetworkScanThread(handler, tc, dialog, p_ntfy, lv_ipaddr, adap, tvmsg, subnet + "." + j, ipAddressList, scan_port); } else { scan_end = true; } } if (!scan_end) { for (int wc = 0; wc < 210; wc++) { if (!tc.isEnabled()) break; SystemClock.sleep(30); } } } if (!tc.isEnabled()) { handler.post(new Runnable() {// UI thread @Override public void run() { closeScanRemoteNetworkProgressDlg(dialog, p_ntfy, lv_ipaddr, adap, tvmsg); } }); } else { handler.postDelayed(new Runnable() {// UI thread @Override public void run() { closeScanRemoteNetworkProgressDlg(dialog, p_ntfy, lv_ipaddr, adap, tvmsg); } }, 10000); } } }).start(); }