Package com.mitac.api.libs
Class DateTime
- java.lang.Object
-
- com.mitac.api.libs.ApiBindBase
-
- com.mitac.api.libs.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 serviceboolean
isServiceReady()
Check if service is ready.boolean
set24Hour(boolean is24Hour)
Set device time format 12 or 24boolean
setAutoTime(boolean enable)
Set device auto timeboolean
setAutoTimeZone(boolean enable)
Set device auto time zoneboolean
setDate(int year, int month, int day)
Set device dateboolean
setTime(int hourOfDay, int minute)
Set device timevoid
unbindService()
unbind service
-
-
-
Constructor Detail
-
DateTime
public DateTime(android.content.Context context)
This constructor will not bind the service automatically. Please callbindService()
at least once before using APIs.- Parameters:
context
- better to useContext.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 useContext.getApplicationContext()
to prevent memory leakscallback
- used to get the notification when service is ready.- Throws:
java.lang.IllegalArgumentException
- if context or callback is null.- See Also:
ServiceStatusCallback
-
-
Method Detail
-
bindService
public void bindService()
Description copied from class:ApiBindBase
bind service- Specified by:
bindService
in classApiBindBase
-
unbindService
public void unbindService()
Description copied from class:ApiBindBase
unbind service- Specified by:
unbindService
in classApiBindBase
-
setDate
public boolean setDate(int year, int month, int day)
Set device date- Parameters:
year
- Date of year from 2007 ~ 2037month
- Date of month value from 1 ~ 12day
- 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 ~ 23minute
- 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.
-
-