1 /* 2 * Copyright (C) 2017 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 package com.google.android.car.kitchensink.assistant; 17 18 import android.content.Context; 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.support.annotation.Nullable; 22 import android.support.v4.app.Fragment; 23 import android.view.HapticFeedbackConstants; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.ImageView; 28 import android.widget.Toast; 29 30 import com.google.android.car.kitchensink.R; 31 32 public class CarAssistantFragment extends Fragment { 33 34 private ImageView mMic; 35 36 @Override 37 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 38 @Nullable Bundle savedInstanceState) { 39 View v = inflater.inflate(R.layout.car_assistant, container, false); 40 mMic = (ImageView) v.findViewById(R.id.voice_button); 41 Context context = getContext(); 42 mMic.setOnClickListener(new View.OnClickListener() { 43 @Override 44 public void onClick(View v) { 45 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); 46 Intent intent = new Intent(); 47 intent.setAction( 48 getContext().getString(R.string.assistant_activity_action)); 49 if (intent.resolveActivity(context.getPackageManager()) != null) { 50 startActivity(intent); 51 } else { 52 Toast.makeText(context, 53 "Assistant app is not available.", Toast.LENGTH_SHORT).show(); 54 } 55 } 56 }); 57 return v; 58 } 59 } 60