Class DateTime


  • public class DateTime
    extends ApiBindBase
    This class provides Date and Time related APIs.

    Sample Code:

      package com.mitac.api;
    
      import android.app.Activity;
      import android.os.Bundle;
    
      import com.mitac.api.libs.DateTime;
      import com.mitac.api.libs.ServiceStatusCallback;
    
      public class MainActivity extends Activity {
          private DateTime mDateTime;
    
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
    
              // when creating the instance the service is auto binding
              // register a callback to listen service status
              mDateTime = new DateTime(getApplicationContext(), new ServiceStatusCallback() {
                  @Override
                  public void ready() {
                      startTest();
                  }
              });
              mDateTime.bindService();
          }
    
          private void startTest() {
              if (mDateTime != null) {
                  if (!mDateTime.setAutoTimeZone(false)) { // disable time zone
                      // remote fail to do the operation
                  }
              }
          }
    
          @Override
          protected void onStop() {
              super.onStop();
    
              if (mDateTime != null) {
                  mDateTime.unbindService();
              }
          }
      }
     
    • Constructor Summary

      Constructors 
      Constructor Description
      DateTime​(android.content.Context context)
      This constructor will not bind the service automatically.
      DateTime​(android.content.Context context, ServiceStatusCallback callback)
      This constructor will bind the service automatically.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void bindService()
      bind service
      boolean isServiceReady()
      Check if service is ready.
      boolean set24Hour​(boolean is24Hour)
      Set device time format 12 or 24
      boolean setAutoTime​(boolean enable)
      Set device auto time
      boolean setAutoTimeZone​(boolean enable)
      Set device auto time zone
      boolean setDate​(int year, int month, int day)
      Set device date
      boolean setTime​(int hourOfDay, int minute)
      Set device time
      void unbindService()
      unbind service
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DateTime

        public DateTime​(android.content.Context context)
        This constructor will not bind the service automatically. Please call bindService() at least once before using APIs.
        Parameters:
        context - better to use Context.getApplicationContext() to prevent memory leaks
        Throws:
        java.lang.IllegalArgumentException - if context is null.
      • DateTime

        public DateTime​(android.content.Context context,
                        ServiceStatusCallback callback)
        This constructor will bind the service automatically.
        Parameters:
        context - better to use Context.getApplicationContext() to prevent memory leaks
        callback - used to get the notification when service is ready.
        Throws:
        java.lang.IllegalArgumentException - if context or callback is null.
        See Also:
        ServiceStatusCallback
    • Method Detail

      • setDate

        public boolean setDate​(int year,
                               int month,
                               int day)
        Set device date
        Parameters:
        year - Date of year from 2007 ~ 2037
        month - Date of month value from 1 ~ 12
        day - Date of day from 1 ~ 31
        Returns:
        false if remote fail.
        Throws:
        java.lang.IllegalArgumentException - if input value range is incorrect
      • setTime

        public boolean setTime​(int hourOfDay,
                               int minute)
        Set device time
        Parameters:
        hourOfDay - Hour of a day in 24 hour format from 0 ~ 23
        minute - Minute of an hour from 0 ~ 59
        Returns:
        false if remote fail.
      • setAutoTime

        public boolean setAutoTime​(boolean enable)
        Set device auto time
        Parameters:
        enable - True to enable auto time; false to disable.
        Returns:
        false if remote fail.
      • setAutoTimeZone

        public boolean setAutoTimeZone​(boolean enable)
        Set device auto time zone
        Parameters:
        enable - True to enable auto time zone; false to disable.
        Returns:
        false if remote fail.
      • set24Hour

        public boolean set24Hour​(boolean is24Hour)
        Set device time format 12 or 24
        Parameters:
        is24Hour - True to set as 24 hour format; false as 12 hour format.
        Returns:
        false if remote fail.
      • isServiceReady

        public boolean isServiceReady()
        Check if service is ready.
        Returns:
        true if ready; false otherwise.