Android Open Source - websms My Time Picker Dialog






From Project

Back to project page websms.

License

The source code is released under:

GNU General Public License

If you think the Android project websms listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.ub0r.android.websms;
//  w  w  w.  j  a  va2s .  c o  m
import android.app.TimePickerDialog;
import android.content.Context;
import android.widget.TimePicker;

/**
 * TimePickerDialog checking time set by user. o2 allows only 00/15/30/45
 * minutes.
 * 
 * @author flx
 */
public class MyTimePickerDialog extends TimePickerDialog {
  /** Last set minutes. */
  private int lastMinutes;
  /** Allow only quaters. */
  private static boolean onlyQuaters;

  /**
   * Default Constructor.
   * 
   * @param context
   *            Context
   * @param callBack
   *            call back method
   * @param hourOfDay
   *            hour of day
   * @param minute
   *            minute
   * @param is24HourView
   *            24h / day or am/pm?
   */
  public MyTimePickerDialog(final Context context,
      final TimePickerDialog.OnTimeSetListener callBack,
      final int hourOfDay, final int minute, final boolean is24HourView) {
    super(context, callBack, hourOfDay, minute, is24HourView);
    this.lastMinutes = minute;
  }

  /**
   * Set true if only full quaters are allowed.
   * 
   * @param allowOnlyQuaters
   *            allow only 00/15/30/45 as minutes
   */
  public static final void setOnlyQuaters(final boolean allowOnlyQuaters) {
    onlyQuaters = allowOnlyQuaters;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public final void onTimeChanged(final TimePicker view, final int hourOfDay,
      final int minute) {
    if (MyTimePickerDialog.onlyQuaters && minute % 15 != 0) {
      // check input, only 00/15/30/45 allowed
      int newMinute = minute;
      if (this.lastMinutes == 0 && minute == 59) {
        newMinute = 45;
      } else if (this.lastMinutes % 15 != 0) {
        newMinute = ((minute / 15)) * 15;
      } else if (minute >= this.lastMinutes) {
        newMinute = ((minute / 15) + 1) * 15;
      } else {
        newMinute = ((minute / 15)) * 15;
      }
      newMinute = newMinute % 60;
      view.setCurrentMinute(newMinute);
      this.lastMinutes = newMinute;
    } else {
      this.lastMinutes = minute;
    }
  }
}




Java Source Code List

de.ub0r.android.websms.AboutActivity.java
de.ub0r.android.websms.Ads.java
de.ub0r.android.websms.CaptchaActivity.java
de.ub0r.android.websms.DefaultSMSLengthCalculator.java
de.ub0r.android.websms.HeaderPreferenceFragment.java
de.ub0r.android.websms.HelpActivity.java
de.ub0r.android.websms.MobilePhoneAdapter.java
de.ub0r.android.websms.MyTimePickerDialog.java
de.ub0r.android.websms.Preferences11Activity.java
de.ub0r.android.websms.PreferencesActivity.java
de.ub0r.android.websms.PreferencesAppearanceActivity.java
de.ub0r.android.websms.PreferencesBehaviorActivity.java
de.ub0r.android.websms.WebSMSApp.java
de.ub0r.android.websms.WebSMSReceiver.java
de.ub0r.android.websms.WebSMS.java
de.ub0r.android.websms.connector.sms.ConnectorSMS.java