If you think the Android project Amphitheatre listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2014 Jerrell Mardis//www.java2s.com
*
* 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.jerrellmardis.amphitheatre.util;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import com.jerrellmardis.amphitheatre.R;
import com.squareup.picasso.Picasso;
import java.io.IOException;
publicclass RecommendationBuilder {
privatestaticint CARD_WIDTH = 117;
privatestaticint CARD_HEIGHT = 176;
publicstaticfinal String EXTRA_BACKGROUND_IMAGE_URL = "background_image_url";
private Context mContext;
private NotificationManager mNotificationManager;
privateint mId;
privateint mPriority;
privateint mSmallIcon;
private String mTitle;
private String mDescription;
private String mImageUri;
private String mBackgroundUri;
private PendingIntent mIntent;
public RecommendationBuilder() { }
public RecommendationBuilder setContext(Context context) {
mContext = context;
returnthis;
}
public RecommendationBuilder setId(int id) {
mId = id;
returnthis;
}
public RecommendationBuilder setPriority(int priority) {
mPriority = priority;
returnthis;
}
public RecommendationBuilder setTitle(String title) {
mTitle = title;
returnthis;
}
public RecommendationBuilder setDescription(String description) {
mDescription = description;
returnthis;
}
public RecommendationBuilder setImage(String uri) {
mImageUri = uri;
returnthis;
}
public RecommendationBuilder setBackground(String uri) {
mBackgroundUri = uri;
returnthis;
}
public RecommendationBuilder setIntent(PendingIntent intent) {
mIntent = intent;
returnthis;
}
public RecommendationBuilder setSmallIcon(int resourceId) {
mSmallIcon = resourceId;
returnthis;
}
public Notification build() throws IOException {
if (mNotificationManager == null) {
mNotificationManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
}
Bundle extras = new Bundle();
if (mBackgroundUri != null) {
extras.putString(EXTRA_BACKGROUND_IMAGE_URL, mBackgroundUri);
}
Bitmap image = Picasso.with(mContext)
.load(mImageUri)
.resize(Utils.dpToPx(CARD_WIDTH, mContext), Utils.dpToPx(CARD_HEIGHT, mContext))
.get();
Notification notification = new NotificationCompat.BigPictureStyle(
new NotificationCompat.Builder(mContext)
.setContentTitle(mTitle)
.setContentText(mDescription)
.setPriority(mPriority)
.setLocalOnly(true)
.setOngoing(true)
.setColor(mContext.getResources().getColor(R.color.fastlane_background))
.setCategory(Notification.CATEGORY_RECOMMENDATION)
.setLargeIcon(image)
.setSmallIcon(mSmallIcon)
.setContentIntent(mIntent)
.setExtras(extras))
.build();
mNotificationManager.notify(mId, notification);
mNotificationManager = null;
return notification;
}
}