• 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 
17 package com.android.tv.settings.dialog;
18 
19 import android.app.Fragment;
20 import android.graphics.drawable.Drawable;
21 import android.os.Bundle;
22 import android.text.TextUtils;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.ImageView;
27 import android.widget.ProgressBar;
28 import android.widget.TextView;
29 
30 import androidx.annotation.DrawableRes;
31 import androidx.annotation.Nullable;
32 import androidx.annotation.StringRes;
33 
34 import com.android.tv.settings.R;
35 
36 public class ProgressDialogFragment extends Fragment {
37 
38     private ImageView mIconView;
39     private TextView mTitleView;
40     private TextView mExtraTextView;
41     private TextView mSummaryView;
42     private ProgressBar mProgressBar;
43     private int mWidth = -1;
44 
45     @Override
onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)46     public @Nullable View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
47             Bundle savedInstanceState) {
48         final ViewGroup view =
49                 (ViewGroup) inflater.inflate(R.layout.progress_fragment, container, false);
50 
51         mIconView = view.findViewById(android.R.id.icon);
52         mTitleView = view.findViewById(android.R.id.title);
53         mExtraTextView = view.findViewById(R.id.extra);
54         mSummaryView = view.findViewById(android.R.id.summary);
55         mProgressBar = view.findViewById(android.R.id.progress);
56 
57         if (mWidth != -1) {
58             final ViewGroup.LayoutParams params = view.getLayoutParams();
59             params.width = mWidth;
60             view.setLayoutParams(params);
61         }
62 
63         return view;
64     }
65 
setIcon(@rawableRes int resId)66     public void setIcon(@DrawableRes int resId) {
67         mIconView.setImageResource(resId);
68         mIconView.setVisibility(View.VISIBLE);
69     }
70 
setIcon(@ullable Drawable icon)71     public void setIcon(@Nullable Drawable icon) {
72         mIconView.setImageDrawable(icon);
73         mIconView.setVisibility(icon == null ? View.GONE : View.VISIBLE);
74     }
75 
setTitle(@tringRes int resId)76     public void setTitle(@StringRes int resId) {
77         mTitleView.setText(resId);
78     }
79 
setTitle(CharSequence title)80     public void setTitle(CharSequence title) {
81         mTitleView.setText(title);
82     }
83 
setExtraText(@tringRes int resId)84     public void setExtraText(@StringRes int resId) {
85         mExtraTextView.setText(resId);
86     }
87 
setExtraText(CharSequence text)88     public void setExtraText(CharSequence text) {
89         mExtraTextView.setText(text);
90         mExtraTextView.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
91     }
92 
setSummary(@tringRes int resId)93     public void setSummary(@StringRes int resId) {
94         mSummaryView.setText(resId);
95     }
96 
setSummary(CharSequence summary)97     public void setSummary(CharSequence summary) {
98         mSummaryView.setText(summary);
99     }
100 
setIndeterminte(boolean indeterminte)101     public void setIndeterminte(boolean indeterminte) {
102         mProgressBar.setIndeterminate(indeterminte);
103     }
104 
setProgress(int progress)105     public void setProgress(int progress) {
106         mProgressBar.setProgress(progress);
107     }
108 
setProgressMax(int max)109     public void setProgressMax(int max) {
110         mProgressBar.setMax(max);
111     }
112 
setContentWidth(int width)113     public void setContentWidth(int width) {
114         mWidth = width;
115         final View root = getView();
116         if (root == null) {
117             return;
118         }
119         final ViewGroup.LayoutParams params = root.getLayoutParams();
120         params.width = width;
121         root.setLayoutParams(params);
122     }
123 }
124