/*
 * Copyright (C) 2015 The Nevolution 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 com.oasisfeng.nevo.decorators;

import android.app.Notification;
import android.os.RemoteException;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.oasisfeng.android.os.IBundle;
import com.oasisfeng.nevo.INotification;
import com.oasisfeng.nevo.StatusBarNotificationEvo;
import com.oasisfeng.nevo.decorator.NevoDecoratorService;

import static android.support.v4.app.NotificationCompat.EXTRA_TEXT;
import static android.support.v4.app.NotificationCompat.EXTRA_TITLE;

/** @author Oasis */
public class BigTextDecorator extends NevoDecoratorService {

	private static final int MIN_TEXT_LENGTH = 20;

	@Override public void apply(final StatusBarNotificationEvo evolved) throws RemoteException {
		final INotification n = evolved.notification();
		if (n.hasBigContentView()) return;
		final IBundle extras = n.extras();
		final CharSequence text = extras.getCharSequence(EXTRA_TEXT);
		if (text == null) return;
//		mPaint.measureText(text);							// TODO
		if (text.length() < MIN_TEXT_LENGTH) return;
		final Notification expanded = new NotificationCompat.BigTextStyle(mDummyBuilder).bigText(text)
				.setBigContentTitle(extras.getCharSequence(EXTRA_TITLE)).build();
		n.setBigContentView(expanded.bigContentView);
		Log.i(TAG, "Expanded the text");
	}

	@Override public void onCreate() {
		super.onCreate();
		mDummyBuilder = new NotificationCompat.Builder(this);
//		mPaint.setTextSize(textSize);
	}

//	private final TextPaint mPaint = new TextPaint();
	private NotificationCompat.Builder mDummyBuilder;

	private static final String TAG = "Nevo.BigText";
}

@@ -663,134 +663,26 @@
 oid.
-app.Notification;%0Aimport android.os.RemoteException;%0Aimport android.support.v4.app.NotificationCompat;%0Aimport android.util.Log
+os.RemoteException
 ;%0A%0Ai
@@ -873,16 +873,88 @@
 rvice;%0A%0A
+import static android.support.v4.app.NotificationCompat.EXTRA_BIG_TEXT;%0A
 import s
@@ -1081,16 +1081,89 @@
 A_TITLE;
+%0Aimport static android.support.v4.app.NotificationCompat.EXTRA_TITLE_BIG;
 %0A%0A/** @a
@@ -1596,25 +1596,29 @@
 ) return;%0A//
-%09
+ TODO
 %09mPaint.meas
@@ -1635,22 +1635,8 @@
 xt);
-%09%09%09%09%09%09%09// TODO
 %0A%09%09i
@@ -1683,566 +1683,249 @@
 rn;%0A
+%0A
 %09%09
-final Notification expanded = new NotificationCompat.BigTextStyle(mDummyBuilder).bigText(text)%0A%09%09%09%09.setBigContentTitle(extras.getCharSequence(EXTRA_TITLE)).build();%0A%09%09n.setBigContentView(expanded.bigContentView);%0A%09%09Log.i(TAG, %22Expanded the
+extras.putCharSequence(EXTRA_TITLE_BIG, extras.getCharSequence(EXTRA_TITLE));%0A%09%09extras.putCharSequence(EXTRA_BIG_TEXT,
  text
-%22
 );%0A%09
-%7D%0A%0A%09@Override public void onCreate() %7B%0A%09%09super.onCreate();%0A%09%09mDummyBuilder = new NotificationCompat.Builder(this);%0A//%09%09mPaint.setTextSize(textSize);%0A%09%7D%0A%0A//%09private final TextPaint mPaint = new TextPaint();%0A%09private NotificationCompat.Builder mDummyBuilder;%0A%0A%09private static final String TAG = %22Nevo.BigText%22
+%09extras.putString(EXTRA_REBUILD_STYLE, STYLE_BIG_TEXT);%0A%09%7D%0A%0A//%09private final TextPaint mPaint = new TextPaint()
 ;%0A%7D%0A

Update BigTextDecorator with new big content rebuild APIs.