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
17package com.android.settings.applications;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.View;
22import android.widget.TextView;
23
24import com.android.settings.R;
25import com.android.settings.accessibility.ListDialogPreference;
26
27public class AppDomainsPreference extends ListDialogPreference {
28    private int mNumEntries;
29
30    public AppDomainsPreference(Context context, AttributeSet attrs) {
31        super(context, attrs);
32
33        setDialogLayoutResource(R.layout.app_domains_dialog);
34        setListItemLayoutResource(R.layout.app_domains_item);
35    }
36
37    @Override
38    public void setTitles(CharSequence[] titles) {
39        mNumEntries = (titles != null) ? titles.length : 0;
40        super.setTitles(titles);
41    }
42
43    @Override
44    public CharSequence getSummary() {
45        final Context context = getContext();
46        if (mNumEntries == 0) {
47            return context.getString(R.string.domain_urls_summary_none);
48        }
49
50        // The superclass summary is the text of the first entry in the list
51        final CharSequence summary = super.getSummary();
52        final int whichVersion = (mNumEntries == 1)
53                ? R.string.domain_urls_summary_one
54                : R.string.domain_urls_summary_some;
55        return context.getString(whichVersion, summary);
56    }
57
58    @Override
59    protected void onBindListItem(View view, int index) {
60        final CharSequence title = getTitleAt(index);
61        if (title != null) {
62            final TextView domainName = (TextView) view.findViewById(R.id.domain_name);
63            domainName.setText(title);
64        }
65    }
66}
67