1 package com.android.car.dialer.ui.activecall; 2 3 import android.os.Bundle; 4 import android.telecom.Call; 5 import android.view.LayoutInflater; 6 import android.view.View; 7 import android.view.ViewGroup; 8 9 import androidx.annotation.NonNull; 10 import androidx.annotation.Nullable; 11 import androidx.fragment.app.Fragment; 12 import androidx.lifecycle.LiveData; 13 import androidx.lifecycle.ViewModelProviders; 14 15 import com.android.car.dialer.R; 16 17 public class RingingCallControllerBarFragment extends Fragment { 18 19 private LiveData<Call> mIncomingCall; 20 21 @Nullable 22 @Override onCreateView(@onNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)23 public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 24 @Nullable Bundle savedInstanceState) { 25 View fragmentView = inflater.inflate(R.layout.ringing_call_controller_bar_fragment, 26 container, false); 27 28 fragmentView.findViewById(R.id.answer_call_button).setOnClickListener((v) -> answerCall()); 29 fragmentView.findViewById(R.id.answer_call_text).setOnClickListener((v) -> answerCall()); 30 fragmentView.findViewById(R.id.end_call_button).setOnClickListener((v) -> declineCall()); 31 fragmentView.findViewById(R.id.end_call_text).setOnClickListener((v) -> declineCall()); 32 33 return fragmentView; 34 } 35 36 @Override onStart()37 public void onStart() { 38 super.onStart(); 39 InCallViewModel inCallViewModel = ViewModelProviders.of(getActivity()).get( 40 InCallViewModel.class); 41 mIncomingCall = inCallViewModel.getIncomingCall(); 42 } 43 answerCall()44 private void answerCall() { 45 if (mIncomingCall.getValue() != null) { 46 mIncomingCall.getValue().answer(/* videoState= */0); 47 } 48 } 49 declineCall()50 private void declineCall() { 51 if (mIncomingCall.getValue() != null) { 52 mIncomingCall.getValue().reject(/* rejectWithMessage= */false, /* textMessage= */null); 53 } 54 } 55 } 56