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; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.Bundle; 22 23 import com.android.deskclock.events.Events; 24 import com.android.deskclock.stopwatch.StopwatchService; 25 import com.android.deskclock.uidata.UiDataModel; 26 27 import static com.android.deskclock.uidata.UiDataModel.Tab.STOPWATCH; 28 29 public class HandleShortcuts extends Activity { 30 31 private static final LogUtils.Logger LOGGER = new LogUtils.Logger("HandleShortcuts"); 32 33 @Override onCreate(Bundle savedInstanceState)34 protected void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 37 final Intent intent = getIntent(); 38 39 try { 40 final String action = intent.getAction(); 41 switch (action) { 42 case StopwatchService.ACTION_PAUSE_STOPWATCH: 43 Events.sendStopwatchEvent(R.string.action_pause, R.string.label_shortcut); 44 45 // Open DeskClock positioned on the stopwatch tab. 46 UiDataModel.getUiDataModel().setSelectedTab(STOPWATCH); 47 startActivity(new Intent(this, DeskClock.class) 48 .setAction(StopwatchService.ACTION_PAUSE_STOPWATCH)); 49 setResult(RESULT_OK); 50 break; 51 case StopwatchService.ACTION_START_STOPWATCH: 52 Events.sendStopwatchEvent(R.string.action_start, R.string.label_shortcut); 53 54 // Open DeskClock positioned on the stopwatch tab. 55 UiDataModel.getUiDataModel().setSelectedTab(STOPWATCH); 56 startActivity(new Intent(this, DeskClock.class) 57 .setAction(StopwatchService.ACTION_START_STOPWATCH)); 58 setResult(RESULT_OK); 59 break; 60 default: 61 throw new IllegalArgumentException("Unsupported action: " + action); 62 } 63 } catch (Exception e) { 64 LOGGER.e("Error handling intent: " + intent, e); 65 setResult(RESULT_CANCELED); 66 } finally { 67 finish(); 68 } 69 } 70 } 71