summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/contacts/tests/widget/PinnedHeaderUseCaseActivity.java
blob: 46a1f4381c362934510a5b8cbe5c259e7654c012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.tests.widget;

import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.android.contacts.tests.R;
import com.android.contacts.common.list.PinnedHeaderListView;

/**
 * An activity that demonstrates various use cases for the {@link PinnedHeaderListView}.
 */
public class PinnedHeaderUseCaseActivity extends ListActivity {

    private static final int SINGLE_SHORT_SECTION_NO_HEADERS = 0;
    private static final int TWO_SHORT_SECTIONS_WITH_HEADERS = 1;
    private static final int FIVE_SHORT_SECTIONS_WITH_HEADERS = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this, R.layout.intent_list_item,
                getResources().getStringArray(R.array.pinnedHeaderUseCases)));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        switch (position) {
            case SINGLE_SHORT_SECTION_NO_HEADERS:
                startActivity(
                        new int[]{5},
                        new String[]{"Line"},
                        new boolean[]{false},
                        new boolean[]{false},
                        new int[]{0});
                break;
            case TWO_SHORT_SECTIONS_WITH_HEADERS:
                startActivity(
                        new int[]{2, 30},
                        new String[]{"First", "Second"},
                        new boolean[]{true, true},
                        new boolean[]{false, false},
                        new int[]{0, 2000});
                break;
            case FIVE_SHORT_SECTIONS_WITH_HEADERS:
                startActivity(
                        new int[]{1, 5, 5, 5, 5},
                        new String[]{"First", "Second", "Third", "Fourth", "Fifth"},
                        new boolean[]{true, true, true, true, true},
                        new boolean[]{false, false, false, false, false},
                        new int[]{0, 2000, 3000, 4000, 5000});
                break;
        }
    }

    private void startActivity(int[] counts, String[] names, boolean[] headers,
            boolean[] showIfEmpty, int[] delays) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(
                getResources().getString(R.string.target_package_name),
                "com.android.contacts.widget.PinnedHeaderListDemoActivity"));
        intent.putExtra("counts", counts);
        intent.putExtra("names", names);
        intent.putExtra("headers", headers);
        intent.putExtra("showIfEmpty", showIfEmpty);
        intent.putExtra("delays", delays);

        startActivity(intent);
    }
}