• 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.v4.app.Fragment;
20 import android.text.TextUtils;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.TextView;
25 
26 /**
27  * A fragment that informs the user that there is no bluetooth device attached that can make
28  * phone calls.
29  */
30 public class NoHfpFragment extends Fragment {
31     private static final String ERROR_MESSAGE_KEY = "ERROR_MESSAGE_KEY";
32 
33     private TextView mErrorMessageView;
34     private String mErrorMessage;
35 
36     /**
37      * Returns an instance of the {@link NoHfpFragment} with the given error message as the one to
38      * display.
39      */
newInstance(String errorMessage)40     static NoHfpFragment newInstance(String errorMessage) {
41         NoHfpFragment fragment = new NoHfpFragment();
42 
43         Bundle args = new Bundle();
44         args.putString(ERROR_MESSAGE_KEY, errorMessage);
45         fragment.setArguments(args);
46 
47         return fragment;
48     }
49 
onCreate(Bundle savedInstanceState)50     public void onCreate(Bundle savedInstanceState) {
51         super.onCreate(savedInstanceState);
52 
53         Bundle args = getArguments();
54         if (args != null) {
55             mErrorMessage = args.getString(ERROR_MESSAGE_KEY);
56         }
57     }
58 
59     /**
60      * Sets the given error message to be displayed.
61      */
setErrorMessage(String errorMessage)62     void setErrorMessage(String errorMessage) {
63         mErrorMessage = errorMessage;
64 
65         // If this method is called before the error message view is available, then no need to
66         // set the message. Instead, it will be set in onCreateView().
67         if (mErrorMessageView != null && !TextUtils.isEmpty(mErrorMessage)) {
68             mErrorMessageView.setText(mErrorMessage);
69         }
70     }
71 
72     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)73     public View onCreateView(LayoutInflater inflater, ViewGroup container,
74             Bundle savedInstanceState) {
75         View v = inflater.inflate(R.layout.no_hfp, container, false);
76         mErrorMessageView = v.findViewById(R.id.error_string);
77 
78         // If no error message is set, the default string from the layout will be used.
79         if (!TextUtils.isEmpty(mErrorMessage)) {
80             mErrorMessageView.setText(mErrorMessage);
81         }
82 
83         return v;
84     }
85 }
86