The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 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; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 20 | import android.util.AttributeSet; |
| 21 | import android.view.View; |
| 22 | |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 23 | import androidx.preference.Preference; |
| 24 | import androidx.preference.PreferenceViewHolder; |
| 25 | |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 26 | /** |
| 27 | * A category with a progress spinner |
| 28 | */ |
Daisuke Miyakawa | d366992 | 2010-08-27 10:04:08 -0700 | [diff] [blame] | 29 | public class ProgressCategory extends ProgressCategoryBase { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 30 | |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 31 | private int mEmptyTextRes; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 32 | private boolean mProgress = false; |
Gilles Debunne | 9416136 | 2011-06-30 15:44:05 -0700 | [diff] [blame] | 33 | private Preference mNoDeviceFoundPreference; |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 34 | private boolean mNoDeviceFoundAdded; |
thigobr | d4cebee | 2010-07-21 13:10:04 -0300 | [diff] [blame] | 35 | |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 36 | public ProgressCategory(Context context) { |
Fan Zhang | ec407ff | 2016-12-19 11:14:59 -0800 | [diff] [blame] | 37 | super(context); |
| 38 | setLayoutResource(R.layout.preference_progress_category); |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | public ProgressCategory(Context context, AttributeSet attrs) { |
Fan Zhang | ec407ff | 2016-12-19 11:14:59 -0800 | [diff] [blame] | 42 | super(context, attrs); |
| 43 | setLayoutResource(R.layout.preference_progress_category); |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 46 | public ProgressCategory(Context context, AttributeSet attrs, |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 47 | int defStyleAttr) { |
Fan Zhang | ec407ff | 2016-12-19 11:14:59 -0800 | [diff] [blame] | 48 | super(context, attrs, defStyleAttr); |
| 49 | setLayoutResource(R.layout.preference_progress_category); |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | public ProgressCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 53 | super(context, attrs, defStyleAttr, defStyleRes); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 54 | setLayoutResource(R.layout.preference_progress_category); |
Fabrice Di Meglio | ab9d698 | 2014-06-17 13:56:13 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | public void setEmptyTextRes(int emptyTextRes) { |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 58 | mEmptyTextRes = emptyTextRes; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 59 | } |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 60 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 61 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 62 | public void onBindViewHolder(PreferenceViewHolder view) { |
| 63 | super.onBindViewHolder(view); |
Daisuke Miyakawa | d366992 | 2010-08-27 10:04:08 -0700 | [diff] [blame] | 64 | final View progressBar = view.findViewById(R.id.scanning_progress); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 65 | |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 66 | boolean noDeviceFound = (getPreferenceCount() == 0 || |
| 67 | (getPreferenceCount() == 1 && getPreference(0) == mNoDeviceFoundPreference)); |
Gilles Debunne | 648f4f6 | 2011-11-21 19:46:39 +0100 | [diff] [blame] | 68 | progressBar.setVisibility(mProgress ? View.VISIBLE : View.GONE); |
Gilles Debunne | 9416136 | 2011-06-30 15:44:05 -0700 | [diff] [blame] | 69 | |
Jake Hamby | de53b46 | 2011-09-06 15:38:23 -0700 | [diff] [blame] | 70 | if (mProgress || !noDeviceFound) { |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 71 | if (mNoDeviceFoundAdded) { |
Gilles Debunne | 9416136 | 2011-06-30 15:44:05 -0700 | [diff] [blame] | 72 | removePreference(mNoDeviceFoundPreference); |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 73 | mNoDeviceFoundAdded = false; |
Gilles Debunne | 9416136 | 2011-06-30 15:44:05 -0700 | [diff] [blame] | 74 | } |
| 75 | } else { |
Jake Hamby | de53b46 | 2011-09-06 15:38:23 -0700 | [diff] [blame] | 76 | if (!mNoDeviceFoundAdded) { |
Gilles Debunne | 9416136 | 2011-06-30 15:44:05 -0700 | [diff] [blame] | 77 | if (mNoDeviceFoundPreference == null) { |
Fan Zhang | ec407ff | 2016-12-19 11:14:59 -0800 | [diff] [blame] | 78 | mNoDeviceFoundPreference = new Preference(getContext()); |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 79 | mNoDeviceFoundPreference.setLayoutResource(R.layout.preference_empty_list); |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 80 | mNoDeviceFoundPreference.setTitle(mEmptyTextRes); |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 81 | mNoDeviceFoundPreference.setSelectable(false); |
Gilles Debunne | 9416136 | 2011-06-30 15:44:05 -0700 | [diff] [blame] | 82 | } |
| 83 | addPreference(mNoDeviceFoundPreference); |
Jake Hamby | 9a4543e | 2011-08-30 15:24:35 -0700 | [diff] [blame] | 84 | mNoDeviceFoundAdded = true; |
Gilles Debunne | 9416136 | 2011-06-30 15:44:05 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 87 | } |
Daisuke Miyakawa | d366992 | 2010-08-27 10:04:08 -0700 | [diff] [blame] | 88 | |
| 89 | @Override |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 90 | public void setProgress(boolean progressOn) { |
| 91 | mProgress = progressOn; |
| 92 | notifyChanged(); |
| 93 | } |
| 94 | } |