Home | History | Annotate | Download | only in settings
      1 /*
      2  * Copyright (C) 2008 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.settings;
     18 
     19 import android.content.Context;
     20 import android.preference.Preference;
     21 import android.util.AttributeSet;
     22 import android.view.View;
     23 
     24 public class ProgressCategory extends ProgressCategoryBase {
     25 
     26     private final int mEmptyTextRes;
     27     private boolean mProgress = false;
     28     private Preference mNoDeviceFoundPreference;
     29     private boolean mNoDeviceFoundAdded;
     30 
     31     public ProgressCategory(Context context, AttributeSet attrs,
     32             int emptyTextRes) {
     33         super(context, attrs);
     34         setLayoutResource(R.layout.preference_progress_category);
     35         mEmptyTextRes = emptyTextRes;
     36     }
     37 
     38     @Override
     39     public void onBindView(View view) {
     40         super.onBindView(view);
     41         final View progressBar = view.findViewById(R.id.scanning_progress);
     42 
     43         boolean noDeviceFound = (getPreferenceCount() == 0 ||
     44                 (getPreferenceCount() == 1 && getPreference(0) == mNoDeviceFoundPreference));
     45         progressBar.setVisibility(mProgress ? View.VISIBLE : View.GONE);
     46 
     47         if (mProgress || !noDeviceFound) {
     48             if (mNoDeviceFoundAdded) {
     49                 removePreference(mNoDeviceFoundPreference);
     50                 mNoDeviceFoundAdded = false;
     51             }
     52         } else {
     53             if (!mNoDeviceFoundAdded) {
     54                 if (mNoDeviceFoundPreference == null) {
     55                     mNoDeviceFoundPreference = new Preference(getContext());
     56                     mNoDeviceFoundPreference.setLayoutResource(R.layout.preference_empty_list);
     57                     mNoDeviceFoundPreference.setTitle(mEmptyTextRes);
     58                     mNoDeviceFoundPreference.setSelectable(false);
     59                 }
     60                 addPreference(mNoDeviceFoundPreference);
     61                 mNoDeviceFoundAdded = true;
     62             }
     63         }
     64     }
     65 
     66     @Override
     67     public void setProgress(boolean progressOn) {
     68         mProgress = progressOn;
     69         notifyChanged();
     70     }
     71 }
     72