Example usage for android.os CountDownTimer CountDownTimer

List of usage examples for android.os CountDownTimer CountDownTimer

Introduction

In this page you can find the example usage for android.os CountDownTimer CountDownTimer.

Prototype

public CountDownTimer(long millisInFuture, long countDownInterval) 

Source Link

Usage

From source file:com.monkey.entonado.MainActivity.java

/**
 * OnResume//from w w w  .  ja  va  2 s. co m
 * register the broadcast receiver with the intent values to be matched
 */
@Override
protected void onResume() {
    super.onResume();
    registerReceiver(mReceiver, mIntentFilter);
    CountDownTimer t = new CountDownTimer(1000, 500) {

        public void onTick(long millisUntilFinished) {

        }

        public void onFinish() {
            if (intentoConectar) {
                mostrarMensaje(mensajeConexion);
                intentoConectar = false;
            } else if (intentoEnviarLista) {
                String mensaje = "";
                boolean entro = false;
                if (mensajeConexion == null) {
                    mensaje = "Estas desconectado";

                } else if (mensajeConexion.equals("desconectado")) {
                    mensaje = "Estas desconectado";

                } else if (mensajeConexion.equals("Estas conectado!")) {
                    mensaje = "La lista ha sido enviada";
                    Intent in = new Intent(MainActivity.this, AlarmReciever.class);
                    PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, in,
                            PendingIntent.FLAG_ONE_SHOT);
                    entro = true;
                    System.out.println("puso alarma");

                    AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE);
                    am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60, pi);
                } else {
                    mensaje = mensajeConexion;
                }
                if (!entro)
                    mostrarMensaje(mensaje);
                intentoEnviarLista = false;
            }
        }
    }.start();
}

From source file:org.y20k.trackbook.TrackerService.java

private void startTracking(Intent intent) {
    LogHelper.v(LOG_TAG, "Service received command: START");

    // create a new track
    mTrack = new Track();

    // get last location
    if (intent.hasExtra(EXTRA_LAST_LOCATION)) {
        mCurrentBestLocation = intent.getParcelableExtra(EXTRA_LAST_LOCATION);
    }//from   www. j  av a2  s. c om
    //  get last location - fallback
    if (mCurrentBestLocation == null) {
        mCurrentBestLocation = LocationHelper.determineLastKnownLocation(mLocationManager);
    }

    // add last location as WayPoint to track
    addWayPointToTrack();

    // set timer to retrieve new locations and to prevent endless tracking
    mTimer = new CountDownTimer(EIGHT_HOURS_IN_MILLISECONDS, FIFTEEN_SECONDS_IN_MILLISECONDS) {
        @Override
        public void onTick(long millisUntilFinished) {
            // update track duration
            long duration = EIGHT_HOURS_IN_MILLISECONDS - millisUntilFinished;
            mTrack.setDuration(duration);
            // try to add WayPoint to Track
            addWayPointToTrack();
            // update notification
            NotificationHelper.update(mTrack, true);
        }

        @Override
        public void onFinish() {
            // remove listeners
            stopFindingLocation();
        }
    };
    mTimer.start();

    // initialize step counter
    mStepCountOffset = 0;
    Sensor stepCounter = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    if (stepCounter != null) {
        mSensorManager.registerListener(this, stepCounter, SensorManager.SENSOR_DELAY_UI);
    } else {
        LogHelper.v(LOG_TAG, "Pedometer Sensor not available");
        mTrack.setStepCount(-1);
    }

    // put up notification
    NotificationHelper.show(this, mTrack);

    // create gps and network location listeners
    startFindingLocation();

    // register content observer for changes in System Settings
    this.getContentResolver().registerContentObserver(android.provider.Settings.Secure.CONTENT_URI, true,
            mSettingsContentObserver);
}

From source file:org.lastmilehealth.collect.android.tasks.BluetoothService.java

/**
 * Start the ConnectThread to initiate a connection to a remote device.
 *
 * @param device The BluetoothDevice to connect
 */// w  w w .  ja  va  2  s.c o m
public synchronized void connect(BluetoothDevice device, boolean isForms) {
    Log.d(TAG, "BTS connect to: " + device);
    this.isForms = isForms;

    // Cancel any thread attempting to make a connection
    if (mConnectThread != null) {
        mConnectThread.cancel();
        mConnectThread = null;
    }

    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {
        mConnectedThread.cancel();
        mConnectedThread = null;
    }

    // Start the thread to connect with the given device
    mConnectThread = new ConnectThread(device);
    mConnectThread.start();
    setState(STATE_CONNECTING);

    //time limit for connection
    cdt = new CountDownTimer(CONNECTION_LIMIT * 10000, 10000) {
        @Override
        public void onTick(long millisUntilFinished) {
        }

        @Override
        public void onFinish() {
            if (getState() == STATE_CONNECTING) {
                stop();

                Message msg = mHandler.obtainMessage(Constants.MESSAGE_CONNECTION_LIMIT);
                mHandler.sendMessage(msg);
            }
        }
    };
    cdt.start();
}

From source file:BTchat.bluetoothchat.BluetoothChatFragment.java

/**
 * Set up the UI and background operations for chat.
 *//*ww w  .j a va  2 s  . c o m*/
private void setupChat() {
    Log.d(TAG, "setupChat()");

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.message);

    mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events
    mSendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view && !Sending) {
                Sending = true;
                new CountDownTimer(120000, 1000) {
                    String time;
                    int sug = sim.normal(120);

                    public void onTick(long millisUntilFinished) {
                        itsTimeToStop();
                        if (!Sending)
                            cancel();
                        sug = sim.normal(sug);
                        time = sim.GetTime();
                        sendMessage(time + ";" + Integer.toString(sug).toString());
                        if (!Sending)
                            cancel();
                    }

                    public void onFinish() {
                        Sending = false;
                        sendMessage("done hyper!!!!");
                    }
                }.start();
            }
        }
    });

    mRand.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view && !Sending) {
                Sending = true;
                new CountDownTimer(30000, 1000) {
                    String time;
                    int sug = sim.GetSugarLevel(120);

                    public void onTick(long millisUntilFinished) {
                        itsTimeToStop();
                        if (!Sending)
                            cancel();
                        sug = sim.GetSugarLevel(sug);
                        time = sim.GetTime();
                        sendMessage(time + ";" + Integer.toString(sug).toString());
                        if (!Sending)
                            cancel();
                    }

                    public void onFinish() {
                        Sending = false;
                        sendMessage("done hyper!!!!");
                    }
                }.start();
            }
        }
    });

    mHype.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view && !Sending) {
                Sending = true;
                new CountDownTimer(30000, 1000) {
                    String time;
                    int sug = sim.giveMeHyper(120);

                    public void onTick(long millisUntilFinished) {
                        itsTimeToStop();
                        if (!Sending)
                            cancel();
                        sug = sim.giveMeHyper(sug);
                        time = sim.GetTime();
                        sendMessage(time + ";" + Integer.toString(sug).toString());
                        if (!Sending)
                            cancel();
                    }

                    public void onFinish() {
                        Sending = false;
                        sendMessage("done hyper!!!!");
                    }
                }.start();
            }
        }
    });

    mHypo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view && !Sending) {
                Sending = true;
                new CountDownTimer(30000, 1000) {
                    String time;
                    int sug = sim.giveMeHypo(120);

                    public void onTick(long millisUntilFinished) {
                        itsTimeToStop();
                        if (!Sending)
                            cancel();
                        sug = sim.giveMeHypo(sug);
                        time = sim.GetTime();
                        sendMessage(time + ";" + Integer.toString(sug).toString());

                    }

                    public void onFinish() {
                        Sending = false;
                        sendMessage("done hyper!!!!");
                    }
                }.start();
            }
        }
    });

    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(getActivity(), mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

From source file:havidarou.com.appgestosfoto.MainActivity.java

public void startTimer(View v) {
    // 3000ms=3s at intervals of 1000ms=1s so that means it lasts 3 seconds
    new CountDownTimer(3000, 1000) {

        @Override/*from   ww w  .  j a va2 s  .  c o m*/
        public void onFinish() {
            // When the timer has finished, the picture is taken
            textTimeLeft.setText("Picture Taken");
            camera.takePicture(null, null, null, jpegCallBack);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            // Every second the textView gets updated
            textTimeLeft.setTextSize(16);
            textTimeLeft.setTextColor(Color.GREEN);
            textTimeLeft.setText("Seconds Left: " + millisUntilFinished / 1000);
        }

    }.start();
}

From source file:com.ibm.mil.readyapps.physio.fragments.library.VideoFragment.java

private void showNextExerciseDialog() {
    final PhysioDialog dialog = new PhysioDialog(getActivity());

    // customize dialog widgets
    Drawable dialogIcon = getResources().getDrawable(R.drawable.form_selected);
    dialog.getIcon().setImageDrawable(dialogIcon);
    String primaryMessage = getResources().getString(R.string.exercise_completed);
    dialog.getPrimaryMessage().setText(primaryMessage);
    String secondaryMessage = getResources().getString(R.string.next_timer_label);
    dialog.getSecondaryMessage().setText(secondaryMessage);
    String buttonText = getResources().getString(R.string.start_next);
    dialog.getButton().setText(buttonText);

    // set timer to advance to the next exercise automatically
    final String timerLabel = dialog.getSecondaryMessage().getText().toString();
    timer = new CountDownTimer(13000, 1000) {
        public void onTick(long millisUntilFinished) {
            // cancel if it reaches 1 sec (prevents delay)
            if (millisUntilFinished / 1000 == 1) {
                dialog.getButton().performClick();
            }/* w w w.  jav  a  2s .c  o  m*/

            // subtract 2 secs so it finishes on 0:00
            long millis = millisUntilFinished - 2000;

            // convert millisUntilFinished into m:ss format (e.g. 0:10)
            String timerFormat = String.format("%01d:%02d", TimeUnit.MILLISECONDS.toMinutes(millis),
                    TimeUnit.MILLISECONDS.toSeconds(millis)
                            - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
            dialog.getSecondaryMessage().setText(timerLabel + " " + timerFormat);
        }

        public void onFinish() {
            // stubbed out, takes too long for onFinish() to be called
            // look in onTick() for how it's handled...
        }
    };
    timer.start();

    // add click listener to dialog button
    dialog.getButton().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // go to next exercise video (refresh fragment)
            getFragmentManager().beginTransaction().detach(thisFragment).attach(thisFragment).commit();
            dialog.cancel();
        }
    });

    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            timer.cancel();
        }
    });

    dialog.show();
}

From source file:com.example.bidisha.ace.ClueScan.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cluescan);/*  ww  w. jav  a 2  s.  c  om*/

    /**
     * @mitra00
     * receiving the values from the calling activity
     */

    Bundle b1 = getIntent().getExtras();
    if (b1 != null) {
        timeValue = b1.getLong("time");
        i = b1.getInt("question_no");

    } else {
        /**
         * @mitra00
         * the limit for the time of the event
         */
        timeValue = 7200000;
    }
    clues[0] = "Careers like rockets dont always take on time! The trick is to keep them running always.";
    clues[1] = "The place doesnt smell pleasant! A new journey starts and the Earth Feels Happy..";
    clues[2] = "I am dark and produce light and i can make something or destroy everything. Inspite of that im used everywhere.";
    clues[3] = "akivuy is a place where everyone have their eyes on!";
    clues[4] = "No one presses my first button now a days and im on top of all";
    clues[5] = "Find me in the center of the place where sounds start and turn off";
    clues[6] = "Take away standing infinity from Dhaku Mangal Singh";
    clues[7] = "Under pressure is the only way i work and by myself is the only way im hurt and mysore express inaugurated me";
    clues[8] = "Hercules has made his mark in sports";
    // clue1="This app was recently inaugurated by Mysore MLA";
    clues[10] = "Some like me hot, Some like me cold, Some like me mild,Some like me bold";
    clues[11] = "All husbands want their wives to be this";
    clues[12] = "The best solution to attract the girls";
    clues[13] = "I can tell you where we stand in the country";
    clues[14] = "I start when the VVCE fest stops";
    clues[15] = "The lead executive";
    clues[16] = "Im the lab which contains THINGS";
    clues[17] = "Railway Workshop, BEML, Silk Factory and NIE have this incommon";
    clues[18] = "Theres a place near by you will want to visit A portal place where people greet";
    clues[9] = "Im the only place whose identity remains the same even after you flip me horizontally";

    /**
     * @mitra00
     * to call the random generator only when the value of i is zero
     */
    if (i == 0)
        gen_clues();

    /**
     * @mitra00
     * updating the field of the textview
     */
    String valueS = Integer.toString(i + 1);
    currQ = (TextView) findViewById(R.id.currentQ);

    question = (TextView) findViewById(R.id.clue);
    question.setText(rando[i]);
    currQ.setText(valueS);

    Button button = (Button) findViewById(R.id.scanQR);
    scanResults = (TextView) findViewById(R.id.scanResults);
    if (savedInstanceState != null) {
        imageUri = Uri.parse(savedInstanceState.getString(SAVED_INSTANCE_URI));
        //scanResults.setText(savedInstanceState.getString(SAVED_INSTANCE_RESULT));
    }
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if (ContextCompat.checkSelfPermission(ClueScan.this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(ClueScan.this,
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_PERMISSION);

            } else {
                takePicture();
            }

        }
    });

    /* TextView question=(TextView)findViewById(R.id.clue);
     switch (q)
     {
    case 1:
        question.setText(getString(R.string.clue1));
        break;
    case 2:
        question.setText(getString(R.string.clue2));
        break;
    case 3:
        question.setText(getString(R.string.clue3));
        break;
    case 4:
        question.setText(getString(R.string.clue4));
        break;
    case 5:
        question.setText(getString(R.string.clue5));
        break;
            
     }*/

    /*This is the code for timer*/

    final TextView time_mins = (TextView) findViewById(R.id.time_mins);
    final TextView time_sec = (TextView) findViewById(R.id.time_sec);

    new CountDownTimer(timeValue, 1000) {

        public void onTick(long millisUntilFinished) {
            time_left = millisUntilFinished;
            sec = (millisUntilFinished / 1000) % 60;
            mins = millisUntilFinished / (1000 * 60);
            if (mins < 10)
                time_mins.setText("0" + millisUntilFinished / (1000 * 60));
            else
                time_mins.setText("" + millisUntilFinished / (1000 * 60));
            if (sec < 10)
                time_sec.setText(": 0" + (millisUntilFinished / 1000) % 60);
            else
                time_sec.setText(": " + (millisUntilFinished / 1000) % 60);

        }

        public void onFinish() {
            Intent i = new Intent(ClueScan.this, ScoreCal.class);
            /**
             * @mitra00
             * setting the time left to zero
             */
            ((StoreGlobal) getApplication()).setTimeToZero();
            startActivity(i);
            ClueScan.this.finish();

        }
    }.start();

    detector = new BarcodeDetector.Builder(getApplicationContext())
            .setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE | Barcode.ALL_FORMATS).build();
    if (!detector.isOperational()) {
        scanResults.setText("Could not set up the detector!");
        return;
    }
}

From source file:com.almalence.opencam.ui.AlmalenceStore.java

public void showStore() {
    LayoutInflater inflater = LayoutInflater.from(MainScreen.getInstance());
    List<RelativeLayout> pages = new ArrayList<RelativeLayout>();

    // <!-- -+-
    final boolean unlocked = false;
    //-+- -->/*from  w w w . j a  va 2s  .c  o m*/
    /* <!-- +++
    final boolean unlocked = true; 
     +++ --> */

    // page 1
    RelativeLayout page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    initStoreList();

    RelativeLayout store = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_store, null);
    final ImageView imgStoreNext = (ImageView) store.findViewById(R.id.storeWhatsNew);
    GridView gridview = (GridView) store.findViewById(R.id.storeGrid);
    gridview.setAdapter(storeAdapter);

    if (!unlocked) {
        page.addView(store);
        pages.add(page);
    }

    // page 2
    page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    RelativeLayout features = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_features, null);
    final ImageView imgFeaturesPrev = (ImageView) features.findViewById(R.id.storeWhatsNew);
    imgFeaturesPrev.setVisibility(View.INVISIBLE);
    WebView wv = (WebView) features.findViewById(R.id.text_features);
    wv.loadUrl("file:///android_asset/www/features.html");

    page.addView(features);
    pages.add(page);

    SamplePagerAdapter pagerAdapter = new SamplePagerAdapter(pages);
    final ViewPager viewPager = new ViewPager(MainScreen.getInstance());
    viewPager.setAdapter(pagerAdapter);
    if (!unlocked)
        viewPager.setCurrentItem(0);
    else
        viewPager.setCurrentItem(1);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            switch (position) {
            case 0:
                // 0
                imgStoreNext.setVisibility(View.VISIBLE);
                // 1
                imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            case 1:
                // 0
                imgStoreNext.setVisibility(View.INVISIBLE);
                // 1
                if (!unlocked)
                    imgFeaturesPrev.setVisibility(View.VISIBLE);
                else
                    imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            default:
                break;
            }
        }
    });

    imgStoreNext.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(1);
        }
    });

    imgFeaturesPrev.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(0);
        }
    });

    guiView.findViewById(R.id.buttonGallery).setEnabled(false);
    guiView.findViewById(R.id.buttonShutter).setEnabled(false);
    guiView.findViewById(R.id.buttonSelectMode).setEnabled(false);

    PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
            ApplicationInterface.MSG_CONTROL_LOCKED);

    MainScreen.getGUIManager().lockControls = true;

    // <!-- -+-
    if (MainScreen.getInstance().showPromoRedeemed) {
        Toast.makeText(MainScreen.getInstance(),
                "The promo code has been successfully redeemed. All PRO-Features are unlocked",
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemed = false;
    }
    if (MainScreen.getInstance().showPromoRedeemedJulius) {
        Toast.makeText(MainScreen.getInstance(),
                MainScreen.getInstance().getResources().getString(R.string.promoRedeemedJulius),
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemedJulius = false;
    }
    //-+- -->

    final RelativeLayout pagerLayout = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayout));
    pagerLayout.addView(viewPager);

    final RelativeLayout pagerLayoutMain = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayoutMain));
    pagerLayoutMain.setVisibility(View.VISIBLE);
    pagerLayoutMain.bringToFront();

    // We need this timer, to show store on top, after we return from google
    // play.
    // In MainScreen there is timer, which brings main buttons on top,
    // after MainScreen activity resumed.
    // So this timer "blocks" timer from MainScreen if we want to show
    // store.
    new CountDownTimer(600, 10) {
        public void onTick(long millisUntilFinished) {
            pagerLayoutMain.bringToFront();
        }

        public void onFinish() {
            pagerLayoutMain.bringToFront();
        }
    }.start();
}

From source file:com.rks.musicx.misc.utils.Sleeptimer.java

public static void reduceVolume(final int delay) {

    final short minutes = (short) (((delay / 1000) % 3600) / 60);
    final boolean tempsMinute = minutes > 10;
    int cycle;//from www.  j a  v a2  s .  c  o m
    if (tempsMinute) {
        cycle = 60000;
    } else {
        cycle = 1000;
    }
    countDownTimer = new CountDownTimer(delay, cycle) {
        @Override
        public void onTick(long mseconds) {
            long temps1 = ((mTask.getDelay(TimeUnit.MILLISECONDS) / 1000) % 3600) / 60;
            long temps2 = mTask.getDelay(TimeUnit.MILLISECONDS) / 1000;
            if (tempsMinute) {
                if (temps1 < 1) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.1f, 0.1f);
                } else if (temps1 < 2) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.2f, 0.2f);
                } else if (temps1 < 3) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.3f, 0.3f);
                } else if (temps1 < 4) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.4f, 0.4f);
                } else if (temps1 < 5) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.5f, 0.5f);
                } else if (temps1 < 6) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.6f, 0.6f);
                } else if (temps1 < 7) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.7f, 0.7f);
                } else if (temps1 < 8) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.8f, 0.8f);
                } else if (temps1 < 9) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.9f, 0.9f);
                } else if (temps1 < 10) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(1.0f, 1.0f);
                }
            } else {
                if (temps2 < 6) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.1f, 0.1f);
                } else if (temps2 < 12) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.2f, 0.2f);
                } else if (temps2 < 18) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.3f, 0.3f);
                } else if (temps2 < 24) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.4f, 0.4f);
                } else if (temps2 < 30) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.5f, 0.5f);
                } else if (temps2 < 36) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.6f, 0.6f);
                } else if (temps2 < 42) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.7f, 0.7f);
                } else if (temps2 < 48) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.8f, 0.8f);
                } else if (temps2 < 54) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(0.9f, 0.9f);
                } else if (temps2 < 60) {
                    MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(1.0f, 1.0f);
                }
            }
        }

        @Override
        public void onFinish() {
            MediaPlayerSingleton.getInstance().getMediaPlayer().setVolume(1.0f, 1.0f);
        }

    }.start();
}

From source file:nl.hnogames.domoticz.UI.SecurityPanelDialog.java

private void processRequest(final int status) {
    setFields(false);// w ww  . j  a  v  a 2 s.com
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editPinCode.getWindowToken(), 0);

    final String password = UsefulBits.getMd5String(editPinCode.getInputWidgetText().toString());

    if (validatePassword(password)) {
        if (mSettings.getSecOnDelay() <= 0 || status == DomoticzValues.Security.Status.DISARM) {
            //don't set delay
            domoticz.setSecurityPanelAction(status, password, new setCommandReceiver() {
                @Override
                public void onReceiveResult(String result) {
                    dismissListener.onDismiss();
                    md.dismiss();
                }

                @Override
                public void onError(Exception error) {
                    Log.e(TAG, domoticz.getErrorMessage(error));
                    Toast.makeText(mContext, mContext.getString(R.string.security_generic_error),
                            Toast.LENGTH_SHORT).show();
                    setFields(true);
                }
            });
        } else {
            countDownTimer = new CountDownTimer((mSettings.getSecOnDelay() * 1000), 1000) {
                public void onTick(long millisUntilFinished) {
                    txtCountDown.setText(String.valueOf((millisUntilFinished / 1000)));
                }

                public void onFinish() {
                    txtCountDown.setText("");
                    domoticz.setSecurityPanelAction(status, password, new setCommandReceiver() {
                        @Override
                        public void onReceiveResult(String result) {
                            dismissListener.onDismiss();
                            md.dismiss();
                        }

                        @Override
                        public void onError(Exception error) {
                            Toast.makeText(mContext, mContext.getString(R.string.security_generic_error),
                                    Toast.LENGTH_SHORT).show();
                            setFields(true);
                        }
                    });
                }
            }.start();
        }
    } else {
        Toast.makeText(mContext, mContext.getString(R.string.security_wrong_code), Toast.LENGTH_SHORT).show();
        setFields(true);
    }
}