com.samsung.android.sdk.healthdata

Enum HealthDataResolver.AggregateRequest.TimeGroupUnit

  • All Implemented Interfaces:
    Serializable, Comparable<HealthDataResolver.AggregateRequest.TimeGroupUnit>
    Enclosing interface:
    HealthDataResolver.AggregateRequest


    public static enum HealthDataResolver.AggregateRequest.TimeGroupUnit
    extends Enum<HealthDataResolver.AggregateRequest.TimeGroupUnit>
    This enumeration defines time units to group values of the aggregate result.
    You can retrieve grouped result of HealthDataResolver.agregate() with the specified time unit.

    Time Group Unit and Format

    The time unit for grouping can be set with HealthDataResolver.AggregateRequest.Builder.setTimeGroup(). Time information in the aggregate result is included as the following format for each time group unit.

      Time group unit Format
      MINUTELY yyyy-mm-dd hh:mm
      (e.g. 2015-10-09 18:17)
      HOURLY yyyy-mm-dd hh
      (e.g. 2015-10-09 18)
      DAILY yyyy-mm-dd
      (e.g. 2015-10-09)
      WEEKLY yyyy-ww
      (e.g. 2015-41)
      MONTHLY yyyy-mm
      (e.g. 2015-10)

    Getting Grouped Aggregate Result with Time Group Unit

    If you requests hourly average steps on today, you can set the time group unit for the aggregate request.

       public class HealthDataResolverExample {
      
           // The state of connection
           private HealthDataStore mStore;
      
           private void getHourlySteps(long startTime, long endTime) {
               HealthDataResolver resolver = new HealthDataResolver(mStore, null);
      
               HealthDataResolver.AggregateRequest request = new HealthDataResolver.AggregateRequest.Builder()
                   .setDataType(HealthConstants.StepCount.HEALTH_DATA_TYPE)
                   .setLocalTimeRange(HealthConstants.StepCount.START_TIME, HealthConstants.StepCount.TIME_OFFSET,
                                                                              startTime, endTime)
                   .addFunction(HealthDataResolver.AggregateRequest.AggregateFunction.AVG,
                       HealthConstants.StepCount.COUNT, "average")
                   .setTimeGroup(HealthDataResolver.AggregateRequest.TimeGroupUnit.HOURLY, 1,
                       HealthConstants.StepCount.START_TIME,
                       HealthConstants.StepCount.TIME_OFFSET, "hour")
                   .build();
      
               try {
                   resolver.aggregate(request).setResultListener(mStepAggrResult);
               } catch (Exception e) {
                   Log.d(APP_TAG, "Aggregating health data fails.");
               }
           }

    The retrieved result can be checked:

           private final HealthResultHolder.ResultListener<HealthDataResolver.AggregateResult> mStepAggrResult=
               new HealthResultHolder.ResultListener<HealthDataResolver.AggregateResult>() {
      
               @Override
               public void onResult(HealthDataResolver.AggregateResult result) {
      
                   try {
                       Iterator<HealthData> iterator = result.iterator();
      
                       if (iterator.hasNext()) {
                           HealthData data = iterator.next();
      
                           // Gets hour information as yyyy-mm-dd hh, e.g. 2015-10-09 18
                           String hour = data.getString("hour");
      
                           // Gets the average value for the current cursor
                           float avr = data.getFloat("average");
      
                           // ...
                       }
                   } finally {
                       result.close();
                   }
               }
           };
       }

    Since:
    1.0.0
    • Method Detail

      • values

        public static HealthDataResolver.AggregateRequest.TimeGroupUnit[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (HealthDataResolver.AggregateRequest.TimeGroupUnit c : HealthDataResolver.AggregateRequest.TimeGroupUnit.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static HealthDataResolver.AggregateRequest.TimeGroupUnit valueOf(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null