List of usage examples for android.os CountDownTimer CountDownTimer
public CountDownTimer(long millisInFuture, long countDownInterval)
From source file:com.mEmoZz.qrgen.MainActivity.java
public void mCore() { Toast.makeText(getApplicationContext(), "Generating code...", Toast.LENGTH_SHORT).show(); new CountDownTimer(3000, 1000) { public void onTick(long millisUntilFinished) { }/*from w w w . ja v a 2s. co m*/ public void onFinish() { Button yupBtn, delBtn, shareBtn; Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show(); final Dialog dialog = new Dialog(MainActivity.this); dialog.setContentView(R.layout.dialog); dialog.setTitle("Want to save?"); iv = (ImageView) dialog.findViewById(R.id.iv); iv.setImageBitmap(bm); shareBtn = (Button) dialog.findViewById(R.id.shareBtn); shareBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { shareIt(); } }); yupBtn = (Button) dialog.findViewById(R.id.btn1); yupBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mStream(); dialog.dismiss(); } }); delBtn = (Button) dialog.findViewById(R.id.btn2); delBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_SHORT).show(); } }); dialog.show(); dialog.setCancelable(false); keepDialog(dialog); } }.start(); }
From source file:org.messic.android.smartphone.activities.searchmessicservice.SearchMessicServiceActivity.java
public void onSearchServiceClick(View view) { this.buttonSearch.setEnabled(false); final CountDownTimer cdt = new CountDownTimer(15000, 1000) { @Override/*w ww .ja va 2 s. c o m*/ public void onTick(long millisUntilFinished) { buttonSearch.setText(getString(R.string.searchMessicService_countdown_searching) + " (" + (millisUntilFinished / 1000) + getString(R.string.searchMessicService_countdown_seconds) + ")"); } @Override public void onFinish() { buttonSearch.post(new Runnable() { public void run() { buttonSearch.setEnabled(true); buttonSearch.setText(R.string.searchMessicService_searchaction); } }); presenter.cancelSearch(); } }; cdt.start(); presenter.searchMessicServices(new MessicDiscovering.SearchListener() { public boolean messicServiceFound(final MDMMessicServerInstance md) { // let's see if the instance was found already if (!rvListAdapter.existInstance(md)) { SearchMessicServiceActivity.this.runOnUiThread(new Runnable() { public void run() { lempty.setVisibility(View.GONE); if (rvListAdapter.addInstance(md)) { rvListAdapter.notifyDataSetChanged(); } } }); cdt.cancel(); cdt.onFinish(); return true; } return false; } }); }
From source file:nl.hnogames.domoticz.UpdateActivity.java
private void updateServer() { // Cancel the check prerequisites dialog if (progressDialog != null) progressDialog.cancel();/*from www. j ava2s.c o m*/ final boolean showMinMax = false; final MaterialDialog dialog = new MaterialDialog.Builder(this).title(R.string.msg_please_wait) .content(getString(R.string.please_wait_while_server_updated) + UsefulBits.newLine() + getString(R.string.this_take_minutes)) .cancelable(false).progress(false, SERVER_UPDATE_TIME * 60, showMinMax).show(); CountDownTimer mCountDownTimer = new CountDownTimer(SERVER_UPDATE_TIME * 60 * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { dialog.incrementProgress(1); } @Override public void onFinish() { dialog.cancel(); showMessageUpdateSuccess(); refreshData(); } }; mCountDownTimer.start(); if (!mSharedPrefs.isDebugEnabled() || serverUtil.getActiveServer().getServerUpdateInfo(this).isUpdateAvailable()) { mDomoticz.updateDomoticzServer(null); // No feedback is provided when updating /* new UpdateDomoticzServerReceiver() { @Override public void onUpdateFinish(boolean updateSuccess) { if (!updateSuccess) showMessageUpdateFailed(); else showMessageUpdateSuccess(); } @Override public void onError(Exception error) { showMessageUpdateNotStarted(); } }); */ } }
From source file:com.villasoftgps.movil.Act_Main.java
private void mostrarMensaje(boolean isWelcome, DialogType dialogType, int icon, String message, final Ejecutar ejecutar) { try {/*from www . j a v a 2s. c o m*/ if (isWelcome) { if (villaDialog != null) { villaDialog.dismiss(); villaDialog = null; } villaDialog = new VillaDialog(Act_Main.this, VillaDialog.DialogType.MESSAGE, message, icon); villaDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); villaDialog.setCanceledOnTouchOutside(false); villaDialog.show(); CountDownTimer timer = new CountDownTimer(3000, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { } }; timer.start(); } else { if (dialogType == DialogType.PROGRESS) { if (villaDialog != null) { villaDialog.dismiss(); villaDialog = null; } villaDialog = new VillaDialog(Act_Main.this, VillaDialog.DialogType.PROGRESS, message); villaDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); villaDialog.setCanceledOnTouchOutside(true); villaDialog.show(); } else if (dialogType == DialogType.PROMPT) { if (villaDialog != null) { villaDialog.dismiss(); villaDialog = null; } villaDialog = new VillaDialog(Act_Main.this, VillaDialog.DialogType.PROMPT, message, icon); villaDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); villaDialog.setCanceledOnTouchOutside(false); villaDialog.setListener(new VillaDialog.DialogListener() { @Override public void Ok() { switch (ejecutar) { case LOGOUT: cerrarSesion(); break; } } @Override public void Cancel() { if (villaDialog != null) { villaDialog.dismiss(); villaDialog = null; } } }); villaDialog.show(); } else { if (villaDialog != null) { villaDialog.dismiss(); villaDialog = null; } villaDialog = new VillaDialog(Act_Main.this, VillaDialog.DialogType.MESSAGE, message, icon); villaDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); villaDialog.setCanceledOnTouchOutside(true); villaDialog.show(); CountDownTimer timer = new CountDownTimer(3000, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { if (villaDialog != null) { villaDialog.dismiss(); villaDialog = null; } } }; timer.start(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.marblelab.dropbox.DBRoulette.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Firebase.setAndroidContext(this); mRef = new Firebase("https://light-and-fridge.firebaseio.com/fridge/state"); /**/*from w w w . j ava2 s.c o m*/ * new codes here */ /* DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int height = displayMetrics.heightPixels; int width = displayMetrics.widthPixels; */ final ImagePopup imagePopup = new ImagePopup(this); imagePopup.setBackgroundColor(Color.BLACK); //Pad imagePopup.setWindowWidth(1500); imagePopup.setWindowHeight(1250); //S2 /*imagePopup.setWindowWidth(480); imagePopup.setWindowHeight(410);*/ imagePopup.setHideCloseIcon(true); imagePopup.setImageOnClickClose(true); if (savedInstanceState != null) { mCameraFileName = savedInstanceState.getString("mCameraFileName"); } // We create a new AuthSession so that we can use the Dropbox API. AndroidAuthSession session = buildSession(); mApi = new DropboxAPI<AndroidAuthSession>(session); // Basic Android widgets setContentView(R.layout.activity_main); checkAppKeySetup(); /** * old code */ mSubmit = (FloatingActionButton) findViewById(R.id.fbSubmit); mSubmit.setOnClickListener(new OnClickListener() { public void onClick(View v) { // This logs you out if you're logged in, or vice versa if (mLoggedIn) { logOut(); } else { // Start the remote authentication if (USE_OAUTH1) { mApi.getSession().startAuthentication(DBRoulette.this); } else { mApi.getSession().startOAuth2Authentication(DBRoulette.this); } } } }); //mDisplay = (LinearLayout)findViewById(R.id.logged_in_display); // This is where a photo is displayed mImage = (ImageView) findViewById(R.id.image_view); mImageSecond = (ImageView) findViewById(R.id.image_second); mImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { imagePopup.initiatePopup(mImage.getDrawable()); } }); mImageSecond.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { imagePopup.initiatePopup(mImageSecond.getDrawable()); } }); // This is the button to take a photo /* mPhoto = (Button)findViewById(R.id.photo_button); mPhoto.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); // Picture from camera intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); // This is not the right way to do this, but for some reason, having // it store it in // MediaStore.Images.Media.EXTERNAL_CONTENT_URI isn't working right. Date date = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss", Locale.US); String newPicFile = df.format(date) + ".jpg"; String outPath = new File(Environment.getExternalStorageDirectory(), newPicFile).getPath(); File outFile = new File(outPath); mCameraFileName = outFile.toString(); Uri outuri = Uri.fromFile(outFile); intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri); Log.i(TAG, "Importing New Picture: " + mCameraFileName); try { startActivityForResult(intent, NEW_PICTURE); } catch (ActivityNotFoundException e) { showToast("There doesn't seem to be a camera."); } } }); */ // This is the button to take a photo mRoulette = (SwipeRefreshLayout) findViewById(R.id.roulette_button); mPullText1 = (TextView) findViewById(R.id.tvPullText1); mPullText2 = (TextView) findViewById(R.id.tvPullText2); mRoulette.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mRef.setValue("send"); //TODO implements a 3-5 sec wait commands or methods new CountDownTimer(15000, 1000) { public void onTick(long millisUntilFinished) { mPullText1.setText("Waiting : " + millisUntilFinished / 1000); mPullText2.setText("Waiting: " + millisUntilFinished / 1000); } public void onFinish() { mPullText1.setText("Camera One"); mPullText2.setText("Camera Two"); DownloadRandomPicture download = new DownloadRandomPicture(DBRoulette.this, mApi, PHOTO_DIR, mImage, 2); download.execute(); DownloadRandomPicture downloadSecond = new DownloadRandomPicture(DBRoulette.this, mApi, PHOTO_DIR, mImageSecond, 1); downloadSecond.execute(); } }.start(); } }); /** * new codes here */ // Display the proper UI state if logged in or not setLoggedIn(mApi.getSession().isLinked()); }
From source file:com.rti.motorcontrolpub.MotorControlMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_motor_control_main); /* Uncomment this to turn on additional logging */ /*/*w w w. ja v a 2 s .c om*/ * Logger.get_instance().set_verbosity_by_category( * LogCategory.NDDS_CONFIG_LOG_CATEGORY_API, * LogVerbosity.NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL); */ // Log.i(TAG, "calling publisherMain"); // Starting DDS subscriber as separate threaded task... if (MotorControlPublisher.Pub_sub_create_count == 1) { ExecutorService service = Executors.newFixedThreadPool(4); service.submit(new Runnable() { @Override public void run() { String[] args = { "0" };// {"0", "0"}; MotorControlPublisher.main(args); } }); MotorControlPublisher.Pub_sub_create_count = 0; } final Button StartBtn = (Button) findViewById(R.id.btnSubmit); StartBtn.setOnClickListener(new OnClickListener() { final Spinner spinner1 = (Spinner) findViewById(R.id.spinner1); final Spinner spinner2 = (Spinner) findViewById(R.id.spinner2); final Spinner spinner3 = (Spinner) findViewById(R.id.spinner3); final Spinner spinner4 = (Spinner) findViewById(R.id.spinner4); // Do click handling here public void onClick(View view) { MotorControlPublisher.flagBtn = true; spinner1.setEnabled(true); spinner2.setEnabled(true); spinner3.setEnabled(true); spinner4.setEnabled(true); if (spinner1.getSelectedItem().toString().equals("Green")) { MotorControlMainActivity.mMotor_id = "1"; } if (spinner1.getSelectedItem().toString().equals("Yellow")) { MotorControlMainActivity.mMotor_id = "2"; } if (spinner1.getSelectedItem().toString().equals("Both")) { MotorControlMainActivity.mMotor_id = "3"; } MotorControlMainActivity.mTime_sec = Integer.valueOf(spinner2.getSelectedItem().toString()); if (spinner3.getSelectedItem().toString().equals("Clock")) { MotorControlMainActivity.mDirection = "0"; } if (spinner3.getSelectedItem().toString().equals("Anti")) { MotorControlMainActivity.mDirection = "1"; } if (spinner3.getSelectedItem().toString().equals("Invrt")) { MotorControlMainActivity.mDirection = "2"; } if (spinner3.getSelectedItem().toString().equals("Outvt")) { MotorControlMainActivity.mDirection = "3"; } if (spinner4.getSelectedItem().toString().equals("Fastest")) { MotorControlMainActivity.mSpeed = 1; } if (spinner4.getSelectedItem().toString().equals("Faster")) { MotorControlMainActivity.mSpeed = 2; } if (spinner4.getSelectedItem().toString().equals("Fast")) { MotorControlMainActivity.mSpeed = 3; } if (spinner4.getSelectedItem().toString().equals("Slow")) { MotorControlMainActivity.mSpeed = 4; } if (spinner4.getSelectedItem().toString().equals("Slower")) { MotorControlMainActivity.mSpeed = 6; } if (spinner4.getSelectedItem().toString().equals("Slowest")) { MotorControlMainActivity.mSpeed = 8; } System.out.println("MotorControlPublisher.mMotor_id " + MotorControlMainActivity.mMotor_id); System.out.println("MotorControlPublisher.mTime_sec " + MotorControlMainActivity.mTime_sec); System.out.println("MotorControlPublisher.mDirection" + MotorControlMainActivity.mDirection); System.out.println("otorControlPublisher.mSpeed" + MotorControlMainActivity.mSpeed); // code for Web DDS HTTP POST // final DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); httpClient.getParams().getParameter("http.protocol.version"); Thread t = new Thread(new Runnable() { @Override public void run() { // replace with your url StringEntity se = null; httppost = new HttpPost( "http://87.82.193.136:8080/dds/rest1/applications/LED_Demo/participants/LEDs/publishers/MyPublisher/datawriters/MyMCWriter"); try { se = new StringEntity("<MotorControl><motor_id>" + MotorControlMainActivity.mMotor_id + "</motor_id><time_sec>" + MotorControlMainActivity.mTime_sec + "</time_sec><direction>" + MotorControlMainActivity.mDirection + "</direction><speed>" + MotorControlMainActivity.mSpeed + "</speed><action>0</action></MotorControl>", "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("POST: " + se); se.setContentType("application/webdds+xml"); httppost.addHeader("Cache-Control", "no-cache"); httppost.setEntity(se); try { httpClient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); t.start(); final TextView mTextField = (TextView) findViewById(R.id.textView4); new CountDownTimer(MotorControlMainActivity.mTime_sec * 1000, 1000) { public void onTick(long millisUntilFinished) { StartBtn.setEnabled(false); spinner1.setEnabled(false); spinner2.setEnabled(false); spinner3.setEnabled(false); spinner4.setEnabled(false); mTextField.setText("Finishing in: " + millisUntilFinished / 1000 + " secs"); } public void onFinish() { // MotorControlPublisher.flagBtn = false; mTextField.setText(" "); StartBtn.setEnabled(true); spinner1.setEnabled(true); spinner2.setEnabled(true); spinner3.setEnabled(true); spinner4.setEnabled(true); if (spinner1.getSelectedItem().toString().equals("Green")) { MotorControlMainActivity.mMotor_id = "1"; } if (spinner1.getSelectedItem().toString().equals("Yellow")) { MotorControlMainActivity.mMotor_id = "2"; } if (spinner1.getSelectedItem().toString().equals("Both")) { MotorControlMainActivity.mMotor_id = "3"; } MotorControlMainActivity.mTime_sec = Integer.valueOf(spinner2.getSelectedItem().toString()); if (spinner3.getSelectedItem().toString().equals("Clock")) { MotorControlMainActivity.mDirection = "0"; } if (spinner3.getSelectedItem().toString().equals("Anti")) { MotorControlMainActivity.mDirection = "1"; } if (spinner3.getSelectedItem().toString().equals("Invrt")) { MotorControlMainActivity.mDirection = "2"; } if (spinner3.getSelectedItem().toString().equals("Outvt")) { MotorControlMainActivity.mDirection = "3"; } if (spinner4.getSelectedItem().toString().equals("Fastest")) { MotorControlMainActivity.mSpeed = 1; } if (spinner4.getSelectedItem().toString().equals("Faster")) { MotorControlMainActivity.mSpeed = 2; } if (spinner4.getSelectedItem().toString().equals("Fast")) { MotorControlMainActivity.mSpeed = 3; } if (spinner4.getSelectedItem().toString().equals("Slow")) { MotorControlMainActivity.mSpeed = 4; } if (spinner4.getSelectedItem().toString().equals("Slower")) { MotorControlMainActivity.mSpeed = 6; } if (spinner4.getSelectedItem().toString().equals("Slowest")) { MotorControlMainActivity.mSpeed = 8; } } }.start(); } }); /* Integration code for WebCam */ SharedPreferences preferences = getSharedPreferences("SAVED_VALUES", MODE_PRIVATE); width = preferences.getInt("width", width); height = preferences.getInt("height", height); ip_ad1 = preferences.getInt("ip_ad1", ip_ad1); ip_ad2 = preferences.getInt("ip_ad2", ip_ad2); ip_ad3 = preferences.getInt("ip_ad3", ip_ad3); ip_ad4 = preferences.getInt("ip_ad4", ip_ad4); ip_port = preferences.getInt("ip_port", ip_port); ip_command = preferences.getString("ip_command", ip_command); StringBuilder sb = new StringBuilder(); String s_http = "http://"; String s_dot = "."; String s_colon = ":"; String s_slash = "/"; sb.append(s_http); sb.append(ip_ad1); sb.append(s_dot); sb.append(ip_ad2); sb.append(s_dot); sb.append(ip_ad3); sb.append(s_dot); sb.append(ip_ad4); sb.append(s_colon); sb.append(ip_port); sb.append(s_slash); sb.append(ip_command); URL = new String(sb); mv = (MjpegView) findViewById(R.id.mv); if (mv != null) { mv.setResolution(width, height); } // setTitle(R.string.title_connecting); /* (e.g. x.new A() where x is an instance of MjpegActivity). */ MjpegActivity x = new MjpegActivity(); x.new DoRead().execute(URL); }
From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.alarm_preferences); pref = getSharedPreferences("AppPref", MODE_PRIVATE); email = getIntent().getStringExtra("email"); Log.d("? ???!!! ", "" + email); Bundle bundle = getIntent().getExtras(); if (bundle != null && bundle.containsKey("alarm")) { setMathAlarm((Alarm) bundle.getSerializable("alarm")); } else {// w w w . j a va2 s .c o m setMathAlarm(new Alarm()); } if (bundle != null && bundle.containsKey("adapter")) { setListAdapter((AlarmPreferenceListAdapter) bundle.getSerializable("adapter")); } else { setListAdapter(new AlarmPreferenceListAdapter(this, getMathAlarm())); } getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { final AlarmPreferenceListAdapter alarmPreferenceListAdapter = (AlarmPreferenceListAdapter) getListAdapter(); final AlarmPreference alarmPreference = (AlarmPreference) alarmPreferenceListAdapter .getItem(position); AlertDialog.Builder alert; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); switch (alarmPreference.getType()) { case BOOLEAN: CheckedTextView checkedTextView = (CheckedTextView) v; boolean checked = !checkedTextView.isChecked(); ((CheckedTextView) v).setChecked(checked); switch (alarmPreference.getKey()) { case ALARM_ACTIVE: alarm.setAlarmActive(checked); break; case ALARM_VIBRATE: alarm.setVibrate(checked); if (checked) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); } break; } alarmPreference.setValue(checked); break; case STRING: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(AlarmPreferencesActivity.this); input.setText(alarmPreference.getValue().toString()); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { alarmPreference.setValue(input.getText().toString()); if (alarmPreference.getKey() == Key.ALARM_NAME) { alarm.setAlarmName(alarmPreference.getValue().toString()); } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] items = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < items.length; i++) items[i] = alarmPreference.getOptions()[i]; alert.setItems(items, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (alarmPreference.getKey()) { case ALARM_DIFFICULTY: Alarm.Difficulty d = Alarm.Difficulty.values()[which]; alarm.setDifficulty(d); break; case ALARM_TONE: alarm.setAlarmTonePath(alarmPreferenceListAdapter.getAlarmTonePaths()[which]); if (alarm.getAlarmTonePath() != null) { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } else { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); mediaPlayer.reset(); } try { // mediaPlayer.setVolume(1.0f, 1.0f); mediaPlayer.setVolume(0.2f, 0.2f); mediaPlayer.setDataSource(AlarmPreferencesActivity.this, Uri.parse(alarm.getAlarmTonePath())); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setLooping(false); mediaPlayer.prepare(); mediaPlayer.start(); // Force the mediaPlayer to stop after 3 // seconds... if (alarmToneTimer != null) alarmToneTimer.cancel(); alarmToneTimer = new CountDownTimer(3000, 3000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e) { } } }; alarmToneTimer.start(); } catch (Exception e) { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e2) { } } } break; default: break; } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case MULTIPLE_LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] multiListItems = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < multiListItems.length; i++) multiListItems[i] = alarmPreference.getOptions()[i]; boolean[] checkedItems = new boolean[multiListItems.length]; for (Alarm.Day day : getMathAlarm().getDays()) { checkedItems[day.ordinal()] = true; } alert.setMultiChoiceItems(multiListItems, checkedItems, new OnMultiChoiceClickListener() { @Override public void onClick(final DialogInterface dialog, int which, boolean isChecked) { Alarm.Day thisDay = Alarm.Day.values()[which]; if (isChecked) { alarm.addDay(thisDay); } else { // Only remove the day if there are more than 1 // selected if (alarm.getDays().length > 1) { alarm.removeDay(thisDay); } else { // If the last day was unchecked, re-check // it ((AlertDialog) dialog).getListView().setItemChecked(which, true); } } } }); alert.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case TIME: TimePickerDialog timePickerDialog = new TimePickerDialog(AlarmPreferencesActivity.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hours, int minutes) { Calendar newAlarmTime = Calendar.getInstance(); newAlarmTime.set(Calendar.HOUR_OF_DAY, hours); newAlarmTime.set(Calendar.MINUTE, minutes); newAlarmTime.set(Calendar.SECOND, 0); alarm.setAlarmTime(newAlarmTime); alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }, alarm.getAlarmTime().get(Calendar.HOUR_OF_DAY), alarm.getAlarmTime().get(Calendar.MINUTE), true); timePickerDialog.setTitle(alarmPreference.getTitle()); timePickerDialog.show(); default: break; } } }); }
From source file:org.linphone.InCallActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; getWindow().addFlags(//from w w w. ja v a 2 s . co m WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.incall); isTransferAllowed = getApplicationContext().getResources().getBoolean(R.bool.allow_transfers); showCallListInVideo = getApplicationContext().getResources() .getBoolean(R.bool.show_current_calls_above_video); isSpeakerEnabled = LinphoneManager.getLcIfManagerNotDestroyedOrNull().isSpeakerEnabled(); if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { if (!BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { BluetoothManager.getInstance().initBluetooth(); } else { isSpeakerEnabled = false; } } isAnimationDisabled = getApplicationContext().getResources().getBoolean(R.bool.disable_animations) || !LinphonePreferences.instance().areAnimationsEnabled(); cameraNumber = AndroidCameraConfiguration.retrieveCameras().length; mListener = new LinphoneCoreListenerBase() { @Override public void callState(LinphoneCore lc, final LinphoneCall call, LinphoneCall.State state, String message) { if (LinphoneManager.getLc().getCallsNb() == 0) { finish(); return; } if (state == State.IncomingReceived) { startIncomingCallActivity(); return; } if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) { video.setEnabled(false); if (isVideoEnabled(call)) { showAudioView(); } } if (state == State.Resuming) { if (LinphonePreferences.instance().isVideoEnabled()) { status.refreshStatusItems(call, isVideoEnabled(call)); if (call.getCurrentParamsCopy().getVideoEnabled()) { showVideoView(); } } } if (state == State.StreamsRunning) { switchVideo(isVideoEnabled(call)); //Check media in progress if (LinphonePreferences.instance().isVideoEnabled() && !call.mediaInProgress()) { video.setEnabled(true); } LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled); isMicMuted = LinphoneManager.getLc().isMicMuted(); enableAndRefreshInCallActions(); if (status != null) { videoProgress.setVisibility(View.GONE); status.refreshStatusItems(call, isVideoEnabled(call)); } } refreshInCallActions(); refreshCallList(getResources()); if (state == State.CallUpdatedByRemote) { // If the correspondent proposes video while audio call boolean videoEnabled = LinphonePreferences.instance().isVideoEnabled(); if (!videoEnabled) { acceptCallUpdate(false); return; } boolean remoteVideo = call.getRemoteParams().getVideoEnabled(); boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled(); boolean autoAcceptCameraPolicy = LinphonePreferences.instance() .shouldAutomaticallyAcceptVideoRequests(); if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) { showAcceptCallUpdateDialog(); timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { if (callUpdateDialog != null) callUpdateDialog.dismiss(); acceptCallUpdate(false); } }.start(); } // else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) { // mHandler.post(new Runnable() { // @Override // public void run() { // acceptCallUpdate(true); // } // }); // } } transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null); } @Override public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted, String authenticationToken) { if (status != null) { status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled()); } } }; if (findViewById(R.id.fragmentContainer) != null) { initUI(); if (LinphoneManager.getLc().getCallsNb() > 0) { LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; if (LinphoneUtils.isCallEstablished(call)) { enableAndRefreshInCallActions(); } } if (savedInstanceState != null) { // Fragment already created, no need to create it again (else it will generate a memory leak with duplicated fragments) isSpeakerEnabled = savedInstanceState.getBoolean("Speaker"); isMicMuted = savedInstanceState.getBoolean("Mic"); isVideoCallPaused = savedInstanceState.getBoolean("VideoCallPaused"); refreshInCallActions(); return; } Fragment callFragment; if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) { callFragment = new VideoCallFragment(); videoCallFragment = (VideoCallFragment) callFragment; isSpeakerEnabled = true; if (cameraNumber > 1) { switchCamera.setVisibility(View.VISIBLE); } } else { callFragment = new AudioCallFragment(); audioCallFragment = (AudioCallFragment) callFragment; switchCamera.setVisibility(View.INVISIBLE); } if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { BluetoothManager.getInstance().routeAudioToBluetooth(); } callFragment.setArguments(getIntent().getExtras()); getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, callFragment) .commitAllowingStateLoss(); } }
From source file:com.example.anna_maria.myapplication.Camera2VideoFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture); mButtonVideo = (Button) view.findViewById(R.id.video); mButtonVideo.setOnClickListener(this); view.findViewById(R.id.info).setOnClickListener(this); final TextView mCountdownTxt = (TextView) view.findViewById(R.id.countdown); new CountDownTimer(seconds * 1000, 1000) { public void onTick(long millisUntilFinished) { long mins = (millisUntilFinished / 1000) / 60; long sec = (millisUntilFinished / 1000) - mins * 60; mCountdownTxt.setText(mins + ":" + (sec < 10 ? "0" : "") + sec); }// ww w .j a v a 2s . co m public void onFinish() { startRecording = false; stopRecordingVideo(); mCountdownTxt.setText("Your presentation time is up!"); } }.start(); }
From source file:com.sbhstimetable.sbhs_timetable_android.CountdownFragment.java
public void updateTimer() { final View f = this.getView(); if (f == null) { return;//from w ww .j a v a 2 s . c o m } if (timeLeft != null) { cancelling = true; timeLeft.cancel(); cancelling = false; } RelativeLayout extraData = (RelativeLayout) f.findViewById(R.id.countdown_extraData); TextView teacher = (TextView) extraData.findViewById(R.id.countdown_extraData_teacher); teacher.setText(""); TextView room = (TextView) extraData.findViewById(R.id.countdown_extraData_room); room.setText(""); TextView subject = (TextView) extraData.findViewById(R.id.countdown_extraData_subject); subject.setText(""); String label = "Something"; String connector = "happens in"; TodayJson.Period p = null; if (DateTimeHelper.bells != null) { BelltimesJson.Bell next = DateTimeHelper.bells.getNextBell(); if (next != null) { BelltimesJson.Bell now = DateTimeHelper.bells.getIndex(next.getIndex() - 1); if (now.isPeriod() && now.getPeriodNumber() < 5) { // in a period, it's not last period. connector = "ends in"; if (ApiAccessor.isLoggedIn() && TodayJson.getInstance() != null) { p = TodayJson.getInstance().getPeriod(now.getPeriodNumber()); label = p.name(); teacher.setText(p.teacher()); room.setText(p.room()); subject.setText(p.name()); extraData.setVisibility(View.VISIBLE); } else { label = now.getLabel(); extraData.setVisibility(View.INVISIBLE); } } else if (now.isPeriod() && now.getPeriodNumber() == 5) { // last period connector = "in"; label = "School ends"; extraData.setVisibility(View.INVISIBLE); } else if (now.getIndex() + 1 < DateTimeHelper.bells.getMaxIndex() && DateTimeHelper.bells.getIndex(now.getIndex() + 1).isPeriod()) { // in a break followed by a period - Lunch 2, Recess, Transition. connector = "starts in"; if (ApiAccessor.isLoggedIn() && TodayJson.getInstance() != null) { p = TodayJson.getInstance() .getPeriod(DateTimeHelper.bells.getIndex(now.getIndex() + 1).getPeriodNumber()); label = p.name(); teacher.setText(p.teacher()); room.setText(p.room()); subject.setText(p.name()); extraData.setVisibility(View.VISIBLE); } else { label = DateTimeHelper.bells.getIndex(now.getIndex() + 1).getLabel(); extraData.setVisibility(View.VISIBLE); } } else { // There's consecutive non-periods - i.e lunch 1 -> lunch 2 label = now.getLabel(); connector = "starts in"; } } else { // end of day label = "School starts"; connector = "in"; if (TodayJson.getInstance() != null && TodayJson.getInstance().getPeriod(1) != null) { extraData.setVisibility(View.VISIBLE); p = TodayJson.getInstance().getPeriod(1); teacher.setText(p.teacher()); room.setText(p.room()); subject.setText(p.name()); } else { extraData.setVisibility(View.INVISIBLE); } } } if (p != null) { if (p.teacherChanged()) { teacher.setTextColor(getActivity().getResources().getColor(R.color.standout)); } else { //teacher.setTextColor(getActivity().getResources().getColor(R.color.secondary_text_dark)); } if (p.roomChanged()) { room.setTextColor(getActivity().getResources().getColor(R.color.standout)); } else { //room.setTextColor(getActivity().getResources().getColor(android.R.color.secondary_text_dark)); } } final String innerLabel = label; ((TextView) f.findViewById(R.id.countdown_name)).setText(label); ((TextView) f.findViewById(R.id.countdown_in)).setText(connector); final TextView t = (TextView) f.findViewById(R.id.countdown_countdown); final CountdownFragment frag = this; CountDownTimer timer = new CountDownTimer(DateTimeHelper.milliSecondsUntilNextEvent(), 1000) { long lastTime = 10000; boolean isLast = innerLabel.equals("School ends"); @Override public void onTick(long l) { lastTime = l; t.setText(DateTimeHelper.formatToCountdown(l)); } @Override public void onFinish() { if (this.lastTime <= 1000 && !cancelling) { if (this.isLast) { ApiAccessor.getToday(frag.getActivity()); ApiAccessor.getBelltimes(frag.getActivity()); } final Handler h = new Handler(); h.postDelayed(new Runnable() { @Override public void run() { updateTimer(); } }, 1000); } } }; timer.start(); timeLeft = timer; }