Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2007 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.example.android.apis.app;
     18 
     19 // Need the following import to get access to the app resources, since this
     20 // class is in a sub-package.
     21 import com.example.android.apis.R;
     22 
     23 import android.app.Activity;
     24 import android.app.NotificationManager;
     25 import android.content.Intent;
     26 import android.os.Bundle;
     27 import android.view.View;
     28 import android.view.WindowManager;
     29 import android.widget.ImageButton;
     30 import android.widget.RelativeLayout;
     31 
     32 /**
     33  * Activity used by StatusBarNotification to show the notification to the user.
     34  */
     35 public class NotificationDisplay extends Activity implements View.OnClickListener {
     36     /**
     37      * Initialization of the Activity after it is first created.  Must at least
     38      * call {@link android.app.Activity#setContentView setContentView()} to
     39      * describe what is to be displayed in the screen.
     40      */
     41     @Override
     42     protected void onCreate(Bundle icicle) {
     43         // Be sure to call the super class.
     44         super.onCreate(icicle);
     45 
     46         // Have the system blur any windows behind this one.
     47         getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
     48                 WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
     49 
     50         RelativeLayout container = new RelativeLayout(this);
     51 
     52         ImageButton button = new ImageButton(this);
     53         button.setImageResource(getIntent().getIntExtra("moodimg", 0));
     54         button.setOnClickListener(this);
     55 
     56         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
     57                 RelativeLayout.LayoutParams.WRAP_CONTENT,
     58                 RelativeLayout.LayoutParams.WRAP_CONTENT);
     59         lp.addRule(RelativeLayout.CENTER_IN_PARENT);
     60 
     61         container.addView(button, lp);
     62 
     63         setContentView(container);
     64     }
     65 
     66     public void onClick(View v) {
     67         // The user has confirmed this notification, so remove it.
     68         ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
     69                 .cancel(R.layout.status_bar_notifications);
     70 
     71         // Pressing on the button brings the user back to our mood ring,
     72         // as part of the api demos app.  Note the use of NEW_TASK here,
     73         // since the notification display activity is run as a separate task.
     74         Intent intent = new Intent(this, StatusBarNotifications.class);
     75         intent.setAction(Intent.ACTION_MAIN);
     76         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     77         startActivity(intent);
     78 
     79         // We're done.
     80         finish();
     81     }
     82 }
     83