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