package net.honeybadgerlabs.adventurequest;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;

public class CompleteReceiver extends BroadcastReceiver {
  private static final String TAG = "CompleteReceiver";
  public static final int ID_NOTIFICATION = 0;

  @Override public void onReceive(Context context, Intent intent) {
    Notification notification;
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

    Log.d(TAG, "Got completion event with action " + intent.getAction());

    if (settings.getBoolean("notify", true)) {
      PendingIntent showActivityIntent = PendingIntent.getActivity(context, 0, new Intent(context, TitleActivity.class), 0);
      String message;
      Uri sound;

      if (intent.getAction().equals(TitleActivity.ACTION_SUCCESS)) {
        sound = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.success);
        message = context.getString(R.string.notification_success);
      } else {
        sound = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.failure);
        message = context.getString(R.string.notification_failure);
      }

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Notification.Builder builder = new Notification.Builder(context);
        builder.setSmallIcon(R.drawable.ic_notify);
        builder.setTicker(message);
        builder.setContentIntent(showActivityIntent);
        builder.setWhen(0);
        builder.setContentTitle(context.getString(R.string.app_name));
        builder.setContentText(message);
        builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
        builder.setSound(sound);
        builder.setAutoCancel(true);

        notification = builder.getNotification();
      } else {
        notification = new Notification(R.drawable.ic_notify, message, 0);
        notification.setLatestEventInfo(context, context.getString(R.string.app_name), message, showActivityIntent);
        notification.sound = sound;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
      }

      ((NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE)).notify(ID_NOTIFICATION, notification);
    }
  }
}

@@ -42,41 +42,8 @@
 t;%0A%0A
-import android.app.Notification;%0A
 impo
@@ -326,33 +326,8 @@
 ri;%0A
-import android.os.Build;%0A
 impo
@@ -359,32 +359,82 @@
 ferenceManager;%0A
+import android.support.v4.app.NotificationCompat;%0A
 import android.u
@@ -681,34 +681,78 @@
     
-Notification notification;
+Log.d(TAG, %22Got completion event with action %22 + intent.getAction());%0A
 %0A   
@@ -842,83 +842,8 @@
 );%0A%0A
-    Log.d(TAG, %22Got completion event with action %22 + intent.getAction());%0A%0A
     
@@ -1481,78 +1481,8 @@
  %7D%0A%0A
-      if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.HONEYCOMB) %7B%0A  
     
@@ -1487,32 +1487,38 @@
     Notification
+Compat
 .Builder builder
@@ -1536,16 +1536,22 @@
 fication
+Compat
 .Builder
@@ -1557,26 +1557,25 @@
 r(context);%0A
-  
+%0A
       builde
@@ -1610,34 +1610,32 @@
 _notify);%0A      
-  
 builder.setTicke
@@ -1638,34 +1638,32 @@
 icker(message);%0A
-  
       builder.se
@@ -1696,34 +1696,32 @@
 yIntent);%0A      
-  
 builder.setWhen(
@@ -1722,34 +1722,32 @@
 tWhen(0);%0A      
- 
- 
 builder.setConte
@@ -1791,34 +1791,32 @@
 p_name));%0A      
-  
 builder.setConte
@@ -1830,34 +1830,32 @@
 message);%0A      
- 
- 
 builder.setLarge
@@ -1936,34 +1936,32 @@
 uncher));%0A      
-  
 builder.setSound
@@ -1971,26 +1971,24 @@
 und);%0A      
- 
- 
 builder.setA
@@ -2009,371 +2009,8 @@
 );%0A%0A
-        notification = builder.getNotification();%0A      %7D else %7B%0A        notification = new Notification(R.drawable.ic_notify, message, 0);%0A        notification.setLatestEventInfo(context, context.getString(R.string.app_name), message, showActivityIntent);%0A        notification.sound = sound;%0A        notification.flags %7C= Notification.FLAG_AUTO_CANCEL;%0A      %7D%0A%0A
     
@@ -2114,28 +2114,31 @@
 CATION, 
-notification
+builder.build()
 );%0A    %7D

use notification compatability objects