• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.android.car.dialer;
17 
18 import android.os.Bundle;
19 import android.support.annotation.Nullable;
20 import android.support.v4.app.Fragment;
21 import android.text.TextUtils;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 
26 import com.android.car.dialer.log.L;
27 import com.android.car.dialer.telecom.UiCallManager;
28 import com.android.car.dialer.ui.DialerInfoController;
29 import com.android.car.dialer.ui.DialpadFragment;
30 
31 /**
32  * Fragment that controls the dialpad.
33  */
34 public class DialerFragment extends Fragment implements DialpadFragment.DialpadCallback {
35     private static final String TAG = "Em.DialerFragment";
36 
37     private static final String DIAL_NUMBER_KEY = "DIAL_NUMBER_KEY";
38     private static final String PLUS_DIGIT = "+";
39 
40     private DialerInfoController mDialerInfoController;
41     private L logger = L.logger(TAG);
42 
43     /**
44      * Creates a new instance of the {@link DialerFragment} and display the given number as the one
45      * to dial.
46      */
newInstance(@ullable String dialNumber)47     static DialerFragment newInstance(@Nullable String dialNumber) {
48         DialerFragment fragment = new DialerFragment();
49 
50         if (!TextUtils.isEmpty(dialNumber)) {
51             Bundle args = new Bundle();
52             args.putString(DIAL_NUMBER_KEY, dialNumber);
53             fragment.setArguments(args);
54         }
55 
56         return fragment;
57     }
58 
59     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)60     public View onCreateView(LayoutInflater inflater, ViewGroup container,
61             Bundle savedInstanceState) {
62         logger.d("onCreateView");
63         View view = inflater.inflate(R.layout.dialer_fragment, container, false);
64 
65         Fragment dialpadFragment = DialpadFragment.newInstance();
66         getChildFragmentManager().beginTransaction()
67                 .replace(R.id.dialpad_fragment_container, dialpadFragment)
68                 .commit();
69 
70         View dialerInfoContainer = view.findViewById(R.id.dialer_info_fragment_container);
71         mDialerInfoController = new DialerInfoController(getContext(), dialerInfoContainer);
72 
73         if (getArguments() != null) {
74             mDialerInfoController.appendDialedNumber(getArguments().getString(DIAL_NUMBER_KEY));
75         }
76 
77         return view;
78     }
79 
80     @Override
onDialVoiceMail()81     public void onDialVoiceMail() {
82         UiCallManager.get().callVoicemail();
83     }
84 
85     @Override
onAppendDigit(String digit)86     public void onAppendDigit(String digit) {
87         if (PLUS_DIGIT.equals(digit)) {
88             mDialerInfoController.removeLastDigit();
89         }
90         mDialerInfoController.appendDialedNumber(digit);
91     }
92 }
93