/*
 * Copyright (c) 2010-2016, openHAB.org and others.
 *
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   which accompanies this distribution, and is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 */

package org.openhab.habdroid.core;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    private static final String TAG = GcmBroadcastReceiver.class.getSimpleName();
    private Context mContext;
    private NotificationManager mNotificationManager;
    private int mNotificationId = 0;

    @Override
    public void onReceive(Context context, Intent intent) {
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }

/*    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
        String messageType = gcm.getMessageType(intent);
        Log.d(TAG, "Message type = " + messageType);
        Log.d(TAG, intent.getExtras().keySet().toString());
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.d(TAG, "Send error: " + intent.getExtras().toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.d(TAG, "Deleted messages on server: " +
                    intent.getExtras().toString());
        } else {
            Log.d(TAG, "Type: " + intent.getExtras().getString("type"));
            Log.d(TAG, "From: " + intent.getExtras().getString("from"));
            Log.d(TAG, "Collapse key: " + intent.getExtras().getString("collapse_key"));
            Log.d(TAG, "Message: " + intent.getExtras().getString("message"));
            if (intent.getExtras() != null)
                if (intent.getExtras().getString("type").equals("notification")) {
                    sendNotification(intent.getExtras().getString("message"));
                }
        }
        setResultCode(Activity.RESULT_OK);
    }

    private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
                new Intent(mContext, OpenHABMainActivity.class), 0);
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mNotificationId++;
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(mContext)
                        .setSmallIcon(R.drawable.openhabicon)
                        .setContentTitle("openHAB")
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(msg))
                        .setAutoCancel(true)
                        .setSound(alarmSound)
                        .setContentText(msg);
        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(mNotificationId, mBuilder.build());
    }
*/

}

@@ -1323,2360 +1323,6 @@
  %7D%0A%0A
-/*    @Override%0A    public void onReceive(Context context, Intent intent) %7B%0A        mContext = context;%0A        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);%0A        String messageType = gcm.getMessageType(intent);%0A        Log.d(TAG, %22Message type = %22 + messageType);%0A        Log.d(TAG, intent.getExtras().keySet().toString());%0A        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) %7B%0A            Log.d(TAG, %22Send error: %22 + intent.getExtras().toString());%0A        %7D else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) %7B%0A            Log.d(TAG, %22Deleted messages on server: %22 +%0A                    intent.getExtras().toString());%0A        %7D else %7B%0A            Log.d(TAG, %22Type: %22 + intent.getExtras().getString(%22type%22));%0A            Log.d(TAG, %22From: %22 + intent.getExtras().getString(%22from%22));%0A            Log.d(TAG, %22Collapse key: %22 + intent.getExtras().getString(%22collapse_key%22));%0A            Log.d(TAG, %22Message: %22 + intent.getExtras().getString(%22message%22));%0A            if (intent.getExtras() != null)%0A                if (intent.getExtras().getString(%22type%22).equals(%22notification%22)) %7B%0A                    sendNotification(intent.getExtras().getString(%22message%22));%0A                %7D%0A        %7D%0A        setResultCode(Activity.RESULT_OK);%0A    %7D%0A%0A    private void sendNotification(String msg) %7B%0A        mNotificationManager = (NotificationManager)%0A                mContext.getSystemService(Context.NOTIFICATION_SERVICE);%0A        PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,%0A                new Intent(mContext, OpenHABMainActivity.class), 0);%0A        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);%0A        mNotificationId++;%0A        NotificationCompat.Builder mBuilder =%0A                new NotificationCompat.Builder(mContext)%0A                        .setSmallIcon(R.drawable.openhabicon)%0A                        .setContentTitle(%22openHAB%22)%0A                        .setStyle(new NotificationCompat.BigTextStyle()%0A                                .bigText(msg))%0A                        .setAutoCancel(true)%0A                        .setSound(alarmSound)%0A                        .setContentText(msg);%0A        mBuilder.setContentIntent(contentIntent);%0A        mNotificationManager.notify(mNotificationId, mBuilder.build());%0A    %7D%0A*/%0A%0A
 %7D%0A

Remove obsolete code (#666)