OSDN Git Service

e854a0038d60ed635f786eb1a8fc79f848b26e41
[android-x86/packages-apps-Settings.git] / src / com / android / settings / ProgressCategory.java
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 import android.widget.TextView;
24
25 public class ProgressCategory extends ProgressCategoryBase {
26
27     private boolean mProgress = false;
28     private Preference mNoDeviceFoundPreference;
29     private boolean mNoDeviceFoundAdded;
30
31     public ProgressCategory(Context context, AttributeSet attrs) {
32         super(context, attrs);
33         setLayoutResource(R.layout.preference_progress_category);
34     }
35
36     @Override
37     public void onBindView(View view) {
38         super.onBindView(view);
39         final TextView textView = (TextView) view.findViewById(R.id.scanning_text);
40         final View progressBar = view.findViewById(R.id.scanning_progress);
41
42         textView.setText(mProgress ? R.string.progress_scanning : R.string.progress_tap_to_pair);
43         boolean noDeviceFound = (getPreferenceCount() == 0 ||
44                 (getPreferenceCount() == 1 && getPreference(0) == mNoDeviceFoundPreference));
45         textView.setVisibility(noDeviceFound ? View.INVISIBLE : View.VISIBLE);
46         progressBar.setVisibility(mProgress ? View.VISIBLE : View.INVISIBLE);
47
48         if (mProgress || !noDeviceFound) {
49             if (mNoDeviceFoundAdded) {
50                 removePreference(mNoDeviceFoundPreference);
51                 mNoDeviceFoundAdded = false;
52             }
53         } else {
54             if (!mNoDeviceFoundAdded) {
55                 if (mNoDeviceFoundPreference == null) {
56                     mNoDeviceFoundPreference = new Preference(getContext());
57                     mNoDeviceFoundPreference.setLayoutResource(R.layout.preference_empty_list);
58                     mNoDeviceFoundPreference.setTitle(R.string.bluetooth_no_devices_found);
59                     mNoDeviceFoundPreference.setSelectable(false);
60                 }
61                 addPreference(mNoDeviceFoundPreference);
62                 mNoDeviceFoundAdded = true;
63             }
64         }
65     }
66
67     @Override
68     public void setProgress(boolean progressOn) {
69         mProgress = progressOn;
70         notifyChanged();
71     }
72 }