1/*
2 * Copyright (C) 2012 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.example.android.support.appnavigation.app;
18
19import com.example.android.support.appnavigation.R;
20
21import android.app.Activity;
22import android.app.NotificationManager;
23import android.app.PendingIntent;
24import android.content.Intent;
25import android.os.Bundle;
26import android.support.v4.app.NavUtils;
27import android.support.v4.app.NotificationCompat;
28import android.support.v4.app.TaskStackBuilder;
29import android.view.MenuItem;
30import android.view.View;
31
32public class NotificationsActivity extends Activity {
33    @Override
34    protected void onCreate(Bundle savedInstanceState) {
35        super.onCreate(savedInstanceState);
36        setContentView(R.layout.notifications);
37
38        ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);
39    }
40
41    @Override
42    public boolean onOptionsItemSelected(MenuItem item) {
43        if (item.getItemId() == android.R.id.home) {
44            NavUtils.navigateUpFromSameTask(this);
45            return true;
46        }
47        return super.onOptionsItemSelected(item);
48    }
49
50    public void onPostDirect(View v) {
51        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
52                .setTicker("Direct Notification")
53                .setSmallIcon(android.R.drawable.stat_notify_chat)
54                .setContentTitle("Direct Notification")
55                .setContentText("This will open the content viewer")
56                .setAutoCancel(true)
57                .setContentIntent(TaskStackBuilder.from(this)
58                        .addParentStack(ContentViewActivity.class)
59                        .addNextIntent(new Intent(this, ContentViewActivity.class)
60                                .putExtra(ContentViewActivity.EXTRA_TEXT, "From Notification"))
61                        .getPendingIntent(0, 0));
62        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
63        nm.notify("direct_tag", R.id.direct_notification, builder.getNotification());
64    }
65
66    public void onPostInterstitial(View v) {
67        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
68                .setTicker("Interstitial Notification")
69                .setSmallIcon(android.R.drawable.stat_notify_chat)
70                .setContentTitle("Interstitial Notification")
71                .setContentText("This will show a detail page")
72                .setAutoCancel(true)
73                .setContentIntent(PendingIntent.getActivity(this, 0,
74                        new Intent(this, InterstitialMessageActivity.class)
75                                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
76                                        Intent.FLAG_ACTIVITY_CLEAR_TASK), 0));
77        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
78        nm.notify("interstitial_tag", R.id.interstitial_notification, builder.getNotification());
79    }
80}
81