List of usage examples for android.os SystemClock sleep
public static void sleep(long ms)
From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java
private void playBackDefaultNotification() { // Thread th=new Thread(){ // @Override // public void run() { // Uri uri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // if (uri!=null) { //// Ringtone rt=RingtoneManager.getRingtone(mContext, uri); //// rt.play(); //// SystemClock.sleep(1000); //// rt.stop(); // MediaPlayer player = MediaPlayer.create(mContext, uri); // if (player!=null) { // int dur=player.getDuration(); // player.start(); // SystemClock.sleep(dur+10); // player.stop(); // player.reset(); // player.release(); // } // } // }/* ww w.j a va 2 s. c o m*/ // }; // th.start(); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { MediaPlayer player = MediaPlayer.create(mContext, uri); if (player != null) { int dur = player.getDuration(); player.start(); SystemClock.sleep(dur + 10); player.stop(); player.reset(); player.release(); } } }
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);/* w w w. java 2 s . com*/ 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 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 www .ja v a 2 s .c o m 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(); }