aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/cyanogenmod/tests/customtiles/CMStatusBarTest.java
blob: 3319f6265d949c505fe38f6cd4c89c7b644563a6 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
 * Copyright (c) 2015, The CyanogenMod 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 org.cyanogenmod.tests.customtiles;

import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;

import cyanogenmod.app.CustomTile;
import cyanogenmod.app.CMStatusBarManager;

import org.cyanogenmod.tests.R;

import org.cyanogenmod.tests.TestActivity;

import java.util.ArrayList;

public class CMStatusBarTest extends TestActivity {

    private static final int CUSTOM_TILE_ID = 1337;
    private static final int CUSTOM_TILE_SETTINGS_ID = 1336;
    private CustomTile mCustomTile;
    private CMStatusBarManager mCMStatusBarManager;

    Handler mHandler = new Handler();

    @Override
    protected String tag() {
        return null;
    }

    @Override
    protected Test[] tests() {
        mCMStatusBarManager = CMStatusBarManager.getInstance(this);
        return mTests;
    }

    private Test[] mTests = new Test[] {
            new Test("test publish tile") {
                public void run() {
                    PendingIntent intent = PendingIntent.getActivity(CMStatusBarTest.this, 0,
                            new Intent(CMStatusBarTest.this, CMStatusBarTest.class)
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
                    mCustomTile = new CustomTile.Builder(CMStatusBarTest.this)
                            .setLabel("Test From SDK")
                            .setIcon(R.drawable.ic_launcher)
                            .setOnClickIntent(intent)
                            .setContentDescription("Content description")
                            .build();
                    mCMStatusBarManager.publishTile(CUSTOM_TILE_ID, mCustomTile);
                }
            },

            new Test("test publish tile in 3 seconds") {
                public void run() {
                    mHandler.postDelayed(new Runnable() {
                        public void run() {
                            PendingIntent intent = PendingIntent.getActivity(CMStatusBarTest.this, 0,
                                    new Intent(CMStatusBarTest.this, CMStatusBarTest.class)
                                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
                            mCustomTile = new CustomTile.Builder(CMStatusBarTest.this)
                                    .setLabel("Test 3 seconds")
                                    .setIcon(R.drawable.ic_launcher)
                                    .setOnClickIntent(intent)
                                    .shouldCollapsePanel(true)
                                    .setContentDescription("Content description")
                                    .build();
                            mCMStatusBarManager.publishTile(CUSTOM_TILE_ID, mCustomTile);
                        }
                    }, 3000);
                }
            },

            new Test("test update tile") {
                public void run() {
                    if (mCustomTile != null) {
                        mCustomTile.label = "Update From SDK";
                        mCMStatusBarManager.publishTile(CUSTOM_TILE_ID, mCustomTile);
                    }
                }
            },

            new Test("test remove tile") {
                public void run() {
                    mCMStatusBarManager.removeTile(CUSTOM_TILE_ID);
                }
            },

            new Test("test remove tile in 3 seconds") {
                public void run() {
                    mHandler.postDelayed(new Runnable() {
                        public void run() {
                            mCMStatusBarManager.removeTile(CUSTOM_TILE_ID);
                        }
                    }, 3000);
                }
            },

            new Test("test publish tile with settings") {
                public void run() {
                    CustomTile customTile = new CustomTile.Builder(CMStatusBarTest.this)
                            .setLabel("Test Settings From SDK")
                            .setIcon(R.drawable.ic_launcher)
                            .setOnSettingsClickIntent(new Intent(CMStatusBarTest.this,
                                    DummySettings.class)
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
                            .setContentDescription("Content description")
                            .build();
                    CMStatusBarManager.getInstance(CMStatusBarTest.this)
                            .publishTile(CUSTOM_TILE_SETTINGS_ID, customTile);
                }
            },

            new Test("test publish tile with custom uri") {
                public void run() {
                    CustomTile customTile = new CustomTile.Builder(CMStatusBarTest.this)
                            .setIcon(R.drawable.ic_launcher)
                            .setOnClickUri(Uri.parse("http://tasker.dinglisch.net"))
                            .build();
                    CMStatusBarManager.getInstance(CMStatusBarTest.this)
                            .publishTile(CUSTOM_TILE_SETTINGS_ID, customTile);
                }
            },

            new Test("test publish tile with expanded list") {
                public void run() {
                    PendingIntent intent = PendingIntent.getActivity(CMStatusBarTest.this, 0,
                            new Intent(CMStatusBarTest.this, CMStatusBarTest.class)
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
                    ArrayList<CustomTile.ExpandedListItem> expandedListItems =
                            new ArrayList<CustomTile.ExpandedListItem>();
                    for (int i = 0; i < 100; i++) {
                        CustomTile.ExpandedListItem expandedListItem =
                                new CustomTile.ExpandedListItem();
                        expandedListItem.setExpandedListItemDrawable(R.drawable.ic_launcher);
                        expandedListItem.setExpandedListItemTitle("Test: " + i);
                        expandedListItem.setExpandedListItemSummary("Test item summary " + i);
                        expandedListItem.setExpandedListItemOnClickIntent(intent);
                        expandedListItems.add(expandedListItem);
                    }

                    CustomTile.ListExpandedStyle listExpandedStyle =
                            new CustomTile.ListExpandedStyle();
                    listExpandedStyle.setListItems(expandedListItems);
                    CustomTile customTile = new CustomTile.Builder(CMStatusBarTest.this)
                            .setLabel("Test Expanded List Style From SDK")
                            .setIcon(R.drawable.ic_launcher)
                            .setExpandedStyle(listExpandedStyle)
                            .setOnSettingsClickIntent(new Intent(CMStatusBarTest.this,
                                    DummySettings.class)
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
                            .setContentDescription("Content description")
                            .build();
                    CMStatusBarManager.getInstance(CMStatusBarTest.this)
                            .publishTile(CUSTOM_TILE_SETTINGS_ID, customTile);
                }
            },

            new Test("test publish tile with expanded grid") {
                public void run() {
                    PendingIntent intent = PendingIntent.getActivity(CMStatusBarTest.this, 0,
                            new Intent(CMStatusBarTest.this, CMStatusBarTest.class)
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
                    ArrayList<CustomTile.ExpandedGridItem> expandedGridItems =
                            new ArrayList<CustomTile.ExpandedGridItem>();
                    for (int i = 0; i < 8; i++) {
                        CustomTile.ExpandedGridItem expandedGridItem =
                                new CustomTile.ExpandedGridItem();
                        expandedGridItem.setExpandedGridItemDrawable(R.drawable.ic_launcher);
                        expandedGridItem.setExpandedGridItemTitle("Test: " + i);
                        expandedGridItem.setExpandedGridItemOnClickIntent(intent);
                        expandedGridItems.add(expandedGridItem);
                    }

                    CustomTile.GridExpandedStyle gridExpandedStyle =
                            new CustomTile.GridExpandedStyle();
                    gridExpandedStyle.setGridItems(expandedGridItems);
                    CustomTile customTile = new CustomTile.Builder(CMStatusBarTest.this)
                            .setLabel("Test Expanded Grid Style From SDK")
                            .setIcon(R.drawable.ic_launcher)
                            .setExpandedStyle(gridExpandedStyle)
                            .setOnSettingsClickIntent(new Intent(CMStatusBarTest.this,
                                    DummySettings.class)
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
                            .setContentDescription("Content description")
                            .build();
                    CMStatusBarManager.getInstance(CMStatusBarTest.this)
                            .publishTile(CUSTOM_TILE_SETTINGS_ID, customTile);
                }
            }
    };
}