1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.deskclock.events; 18 19 import android.annotation.TargetApi; 20 import android.content.Context; 21 import android.content.pm.ShortcutManager; 22 import android.os.Build; 23 import android.support.annotation.StringRes; 24 import android.util.ArraySet; 25 26 import com.android.deskclock.R; 27 import com.android.deskclock.uidata.UiDataModel; 28 29 import java.util.Set; 30 31 @TargetApi(Build.VERSION_CODES.N_MR1) 32 public final class ShortcutEventTracker implements EventTracker { 33 34 private final ShortcutManager mShortcutManager; 35 private final Set<String> shortcuts = new ArraySet<>(5); 36 37 public ShortcutEventTracker(Context context) { 38 mShortcutManager = context.getSystemService(ShortcutManager.class); 39 final UiDataModel uidm = UiDataModel.getUiDataModel(); 40 shortcuts.add(uidm.getShortcutId(R.string.category_alarm, R.string.action_create)); 41 shortcuts.add(uidm.getShortcutId(R.string.category_timer, R.string.action_create)); 42 shortcuts.add(uidm.getShortcutId(R.string.category_stopwatch, R.string.action_pause)); 43 shortcuts.add(uidm.getShortcutId(R.string.category_stopwatch, R.string.action_start)); 44 shortcuts.add(uidm.getShortcutId(R.string.category_screensaver, R.string.action_show)); 45 } 46 47 @Override 48 public void sendEvent(@StringRes int category, @StringRes int action, @StringRes int label) { 49 final String shortcutId = UiDataModel.getUiDataModel().getShortcutId(category, action); 50 if (shortcuts.contains(shortcutId)) { 51 mShortcutManager.reportShortcutUsed(shortcutId); 52 } 53 } 54 }