Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c0cc114 authored by Daria Evdokimova's avatar Daria Evdokimova Committed by Android Git Automerger
Browse files

am 97149ea8: Enabling VoiceInteractor

* commit '97149ea8':
  Enabling VoiceInteractor
parents ac53ec55 97149ea8
Loading
Loading
Loading
Loading
+18 −22
Original line number Diff line number Diff line
@@ -918,14 +918,14 @@
    First %d represents hour, second %d represents minutes,
    [CHAR LIMIT=NONE]
    -->
    <string name="invalid_time">Invalid time <xliff:g id="invalid_hour" example="25">%d</xliff:g>:<xliff:g id="invalid_minutes" example="63">%d</xliff:g></string>
    <string name="invalid_time">Invalid time <xliff:g id="invalid_hour" example="25">%d</xliff:g>:<xliff:g id="invalid_minutes" example="63">%d</xliff:g> <xliff:g id="invalid_pmam" example="PM">%s</xliff:g></string>

    <!-- String that represents that no alarm has been specified for a requested hour:minutes.
    This happens when a user sends a voice command 'dismiss my alarm at 3:00pm' but they have no
    alarms specified for that time. %s represents the time of the alarm.
    [CHAR LIMIT=NONE]
    -->
    <string name="no_alarm_at">No alarm at <xliff:g id="alarm_time" example="14:20">%s</xliff:g></string>
    <string name="no_alarm_at">No alarm at <xliff:g id="alarm_time_hour" example="14">%d</xliff:g>:<xliff:g id="alarm_time_minutes" example="23">%d</xliff:g></string>

    <!-- String that represents that the user doesn't have any alarms scheduled. This happens when
    a user sends a voice command 'dismiss next alarm' or 'dismiss all of my alarms' but they have
@@ -952,31 +952,12 @@
    -->
    <string name="stopwatch_mode_changed">Stopwatch mode changed</string>

    <!-- String that represents that the user mentioned a specific alarm in a voice command,
    e.g. 'dismiss my alarm for 2pm' but for some reason there were two alarm instances scheduled for
    this alarm id (shouldn't normally happen) so the command wasn't executed.
    [CHAR LIMIT=NONE]
    -->
    <string name="more_than_one_instance_for_this_alarm_id">There is more than one alarm scheduled for this time</string>

    <!-- String that represents that the user has sent a voice command 'dismiss my alarm at 3pm' when
    there was no alarm scheduled for that time (they might have had an alarm for 3pm on the list
    but it was disabled).
    [CHAR LIMIT=NONE]
    -->
    <string name="no_alarm_instances_for_this_id">No alarm scheduled for this time</string>

    <!-- String that represents that the user has canceled an alarm through a voice action.
    %s represents alarm time, e.g. 14:20
    [CHAR LIMIT=NONE]
    -->
    <string name="alarm_is_canceled"><xliff:g id="alarm_time" example="14:20">%s</xliff:g> alarm canceled</string>

    <!-- String that represents that the user has deleted an alarm through a voice action.
    %s represents alarm time, e.g. 14:20
    [CHAR LIMIT=NONE]
    -->
    <string name="alarm_is_deleted"><xliff:g id="alarm_time" example="14:20">%s</xliff:g> alarm deleted</string>
    <string name="no_alarm_scheduled_for_this_time">No alarm scheduled for this time</string>

    <!-- String that represents that the user has dismissed an alarm through a voice action.
    %s represents alarm time, e.g. 14:20
@@ -1001,6 +982,14 @@
    -->
    <string name="timer_already_running">Timer already running</string>

    <!-- String that represents that the user has attempted to start or reset a timer when
     there were more than 1 timer of desired state in which case it's ambiguous
     which timer the user meant.
    [CHAR LIMIT=NONE]
     -->
    <string name="multiple_timers_available">Unable to complete your request, multiple timers available</string>


    <!-- String that represents that the user has successfully started a timer through a voice action.
    [CHAR LIMIT=NONE]
    -->
@@ -1070,6 +1059,13 @@
   -->
    <string name="dismiss_alarm">Dismiss alarm</string>

    <!-- String that represents that further action is needed from the user in case their
    voice command was ambiguous or there are more than 1 alarms that match their request.
    The user needs to choose an alarm they want to dismiss through the UI
   [CHAR LIMIT=NONE]
   -->
    <string name="pick_alarm_to_dismiss">Pick which alarm to dismiss</string>

    <!-- String that represents that the user doesn't have any alarms firing at the moment.
    [CHAR LIMIT=NONE]
    -->
+7 −4
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.deskclock;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
@@ -39,7 +40,7 @@ public class AlarmSelectionActivity extends ListActivity {
    public static final String EXTRA_ALARMS = "com.android.deskclock.EXTRA_ALARMS";

    private final List<AlarmSelection> mSelections = new ArrayList<>();
    private final Map<Long, Alarm> mAlarmsMap = new ArrayMap<>();;
    private final Map<Long, Alarm> mAlarmsMap = new ArrayMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -87,7 +88,7 @@ public class AlarmSelectionActivity extends ListActivity {
        final AlarmSelection selection = mSelections.get((int) id);
        final Alarm alarm = selection.getAlarm();
        if (alarm != null) {
            new ProcessAlarmActionAsync(this, alarm).execute();
            new ProcessAlarmActionAsync(this, alarm, this).execute();
        }
        finish();
    }
@@ -96,15 +97,17 @@ public class AlarmSelectionActivity extends ListActivity {

        private final Context mContext;
        private final Alarm mAlarm;
        private final Activity mActivity;

        public ProcessAlarmActionAsync(Context context, Alarm alarm) {
        public ProcessAlarmActionAsync(Context context, Alarm alarm, Activity activity) {
            mContext = context;
            mAlarm = alarm;
            mActivity = activity;
        }

        @Override
        protected Void doInBackground(Void... parameters) {
            HandleApiCalls.dismissAlarm(mAlarm, mContext);
            HandleApiCalls.dismissAlarm(mAlarm, mContext, mActivity);
            return null;
        }
    }
+17 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.deskclock;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -42,12 +43,15 @@ class FetchMatchingAlarmsAction implements Runnable {
    private final List<Alarm> mAlarms;
    private final Intent mIntent;
    private final List<Alarm> mMatchingAlarms = new ArrayList<>();
    private final Activity mActivity;

    public FetchMatchingAlarmsAction(Context context, List<Alarm> alarms, Intent intent) {
    public FetchMatchingAlarmsAction(Context context, List<Alarm> alarms, Intent intent,
                                     Activity activity) {
        mContext = context;
        // only enabled alarms are passed
        mAlarms = alarms;
        mIntent = intent;
        mActivity = activity;
    }

    @Override
@@ -78,7 +82,9 @@ class FetchMatchingAlarmsAction implements Runnable {

                if (badInput) {
                    final String amPm = isPm == null ? "null" : (isPm ? "pm" : "am");
                    LogUtils.e("Invalid time specified: %d:%d %s", hour, minutes, amPm);
                    final String reason = mContext.getString(R.string.invalid_time, hour, minutes,
                            amPm);
                    notifyFailureAndLog(reason, mActivity);
                    return;
                }

@@ -91,7 +97,8 @@ class FetchMatchingAlarmsAction implements Runnable {
                    }
                }
                if (selectedAlarms.isEmpty()) {
                    LogUtils.i("No alarm at %d:%d", hour24, minutes);
                    final String reason = mContext.getString(R.string.no_alarm_at, hour24, minutes);
                    notifyFailureAndLog(reason, mActivity);
                    return;
                }
                // there might me multiple alarms at the same time
@@ -100,7 +107,8 @@ class FetchMatchingAlarmsAction implements Runnable {
            case AlarmClock.ALARM_SEARCH_MODE_NEXT:
                final AlarmInstance nextAlarm = AlarmStateManager.getNextFiringAlarm(mContext);
                if (nextAlarm == null) {
                    LogUtils.i("No alarms are scheduled.");
                    final String reason = mContext.getString(R.string.no_scheduled_alarms);
                    notifyFailureAndLog(reason, mActivity);
                    return;
                }

@@ -128,4 +136,9 @@ class FetchMatchingAlarmsAction implements Runnable {
    public List<Alarm> getMatchingAlarms() {
        return mMatchingAlarms;
    }

    private void notifyFailureAndLog(String reason, Activity activity) {
        LogUtils.e(reason);
        Voice.notifyFailure(activity, reason);
    }
}
 No newline at end of file
+34 −16
Original line number Diff line number Diff line
@@ -93,10 +93,10 @@ public class HandleApiCalls extends Activity {

        final Intent intent = getIntent();

        new DismissAlarmAsync(mAppContext, intent).execute();
        new DismissAlarmAsync(mAppContext, intent, this).execute();
    }

    public static void dismissAlarm(Alarm alarm, Context context) {
    public static void dismissAlarm(Alarm alarm, Context context, Activity activity) {
        // only allow on background thread
        if (Looper.myLooper() == Looper.getMainLooper()) {
            throw new IllegalStateException("dismissAlarm must be called on a " +
@@ -106,16 +106,23 @@ public class HandleApiCalls extends Activity {
        final AlarmInstance alarmInstance = AlarmInstance.getNextUpcomingInstanceByAlarmId(
                context.getContentResolver(), alarm.id);
        if (alarmInstance == null) {
            LogUtils.i("There are no alarm instances for this alarm id");
            final String reason = context.getString(R.string.no_alarm_scheduled_for_this_time);
            Voice.notifyFailure(activity, reason);
            LogUtils.i(reason);
            return;
        }

        if (Utils.isAlarmWithin24Hours(alarmInstance)) {
            AlarmStateManager.setPreDismissState(context, alarmInstance);
            LogUtils.i("Dismiss %d:%d", alarm.hour, alarm.minutes);
            final String reason = context.getString(R.string.alarm_is_dismissed, alarm);
            LogUtils.i(reason);
            Voice.notifySuccess(activity, reason);
            Events.sendAlarmEvent(R.string.action_dismiss, R.string.label_intent);
        } else {
            LogUtils.i("%s wasn't dismissed, still more than 24 hours away.", alarm);
            final String reason = context.getString(
                    R.string.alarm_cant_be_dismissed_still_more_than_24_hours_away, alarm);
            Voice.notifyFailure(activity, reason);
            LogUtils.i(reason);
        }
    }

@@ -123,17 +130,21 @@ public class HandleApiCalls extends Activity {

        private final Context mContext;
        private final Intent mIntent;
        private final Activity mActivity;

        public DismissAlarmAsync(Context context, Intent intent) {
        public DismissAlarmAsync(Context context, Intent intent, Activity activity) {
            mContext = context;
            mIntent = intent;
            mActivity = activity;
        }

        @Override
        protected Void doInBackground(Void... parameters) {
            final List<Alarm> alarms = getEnabledAlarms(mContext);
            if (alarms.isEmpty()) {
                LogUtils.i("No alarms are scheduled.");
                final String reason = mContext.getString(R.string.no_scheduled_alarms);
                LogUtils.i(reason);
                Voice.notifyFailure(mActivity, reason);
                return null;
            }

@@ -161,7 +172,7 @@ public class HandleApiCalls extends Activity {

            // fetch the alarms that are specified by the intent
            final FetchMatchingAlarmsAction fmaa =
                    new FetchMatchingAlarmsAction(mContext, alarms, mIntent);
                    new FetchMatchingAlarmsAction(mContext, alarms, mIntent, mActivity);
            fmaa.run();
            final List<Alarm> matchingAlarms = fmaa.getMatchingAlarms();

@@ -173,12 +184,14 @@ public class HandleApiCalls extends Activity {
                        .putExtra(AlarmSelectionActivity.EXTRA_ALARMS,
                                matchingAlarms.toArray(new Parcelable[matchingAlarms.size()]));
                mContext.startActivity(pickSelectionIntent);
                final String reason = mContext.getString(R.string.pick_alarm_to_dismiss);
                Voice.notifySuccess(mActivity, reason);
                return null;
            }

            // Apply the action to the matching alarms
            for (Alarm alarm : matchingAlarms) {
                dismissAlarm(alarm, mContext);
                dismissAlarm(alarm, mContext, mActivity);
                LogUtils.i("Alarm %s is dismissed", alarm);
            }
            return null;
@@ -192,15 +205,17 @@ public class HandleApiCalls extends Activity {
    }

    private void handleSnoozeAlarm() {
        new SnoozeAlarmAsync(mAppContext).execute();
        new SnoozeAlarmAsync(mAppContext, this).execute();
    }

    private static class SnoozeAlarmAsync extends AsyncTask<Void, Void, Void> {

        private final Context mContext;
        private final Activity mActivity;

        public SnoozeAlarmAsync(Context context) {
        public SnoozeAlarmAsync(Context context, Activity activity) {
            mContext = context;
            mActivity = activity;
        }

        @Override
@@ -208,25 +223,28 @@ public class HandleApiCalls extends Activity {
            final List<AlarmInstance> alarmInstances = AlarmInstance.getInstancesByState(
                    mContext.getContentResolver(), AlarmInstance.FIRED_STATE);
            if (alarmInstances.isEmpty()) {
                LogUtils.i("No alarms are firing.");
                final String reason = mContext.getString(R.string.no_firing_alarms);
                LogUtils.i(reason);
                Voice.notifyFailure(mActivity, reason);
                return null;
            }

            for (AlarmInstance firingAlarmInstance : alarmInstances) {
                snoozeAlarm(firingAlarmInstance, mContext);
                LogUtils.i("Alarm %s is snoozed", firingAlarmInstance);
                snoozeAlarm(firingAlarmInstance, mContext, mActivity);
            }
            return null;
        }
    }

    static void snoozeAlarm(AlarmInstance alarmInstance, Context context) {
    static void snoozeAlarm(AlarmInstance alarmInstance, Context context, Activity activity) {
        // only allow on background thread
        if (Looper.myLooper() == Looper.getMainLooper()) {
            throw new IllegalStateException("snoozeAlarm must be called on a " +
                    "background thread");
        }

        final String reason = context.getString(R.string.alarm_is_snoozed, alarmInstance);
        LogUtils.i(reason);
        Voice.notifySuccess(activity, reason);
        AlarmStateManager.setSnoozeState(context, alarmInstance, true);
        LogUtils.i("Snooze %d:%d", alarmInstance.mHour, alarmInstance.mMinute);
        Events.sendAlarmEvent(R.string.action_snooze, R.string.label_intent);
+73 −15

File changed.

Preview size limit exceeded, changes collapsed.

Loading