Android Open Source - Icinga-Mobile Noti Builder






From Project

Back to project page Icinga-Mobile.

License

The source code is released under:

GNU General Public License

If you think the Android project Icinga-Mobile 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

package mhst.dreamteam.IcingaService;
/* www  . j  a v  a 2  s . c  o  m*/
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.app.NotificationCompat;

/**
 * Builds a notification message
 *
 * @author MinhNN
 */
public class NotiBuilder {
    private String mTitle;
    private String mTicker;
    private String mContentTxt;
    private String mContentInfo;
    private Bitmap mLargeIcon;
    private int mSmallIcon;
    private int mStyle;
    private Context mContext;
    private String[] mContentInbox;
    private PendingIntent mContentIntent;
    private long mWhen;

    public static final int NOTI_STYLE_NORMAL = 0x00; // Normal view
    public static final int NOTI_STYLE_INBOX = 0x01; // Big view

    public NotiBuilder(Context context) {
        this.mTitle = "";
        this.mTicker = "";
        this.mContentTxt = "";
        this.mContentInfo = "";
        this.mLargeIcon = null;
        this.mSmallIcon = 0;
        this.mStyle = NOTI_STYLE_NORMAL;
        this.mContext = context;
        this.mContentInbox = new String[0];
        this.mContentIntent = null;
        this.mWhen = 0;
    }

    public NotiBuilder(Context context, String mTitle, String mTicker, String mContentTxt, String mContentInfo, Bitmap mLargeIcon, int mSmallIcon) {
        this.mTitle = mTitle;
        this.mTicker = mTicker;
        this.mContentTxt = mContentTxt;
        this.mContentInfo = mContentInfo;
        this.mLargeIcon = mLargeIcon;
        this.mSmallIcon = mSmallIcon;
        this.mStyle = NOTI_STYLE_NORMAL;
        this.mContext = context;
        this.mContentInbox = new String[0];
        this.mContentIntent = null;
        this.mWhen = 0;
    }

    public NotiBuilder(Context context, String mTitle, String mTicker, String mContentTxt, String mContentInfo, Bitmap mLargeIcon, int mSmallIcon, int mStyle) {
        this.mTitle = mTitle;
        this.mTicker = mTicker;
        this.mContentTxt = mContentTxt;
        this.mContentInfo = mContentInfo;
        this.mLargeIcon = mLargeIcon;
        this.mSmallIcon = mSmallIcon;
        this.mStyle = mStyle;
        this.mContext = context;
        this.mContentInbox = new String[0];
        this.mContentIntent = null;
        this.mWhen = 0;
    }

    public NotiBuilder(Context mContext, String mTitle, String mTicker, String mContentTxt, String mContentInfo, Bitmap mLargeIcon, int mSmallIcon, int mStyle, String[] mContentInbox) {
        this.mContentInbox = mContentInbox;
        this.mTitle = mTitle;
        this.mTicker = mTicker;
        this.mContentTxt = mContentTxt;
        this.mContentInfo = mContentInfo;
        this.mLargeIcon = mLargeIcon;
        this.mSmallIcon = mSmallIcon;
        this.mStyle = mStyle;
        this.mContext = mContext;
        this.mContentIntent = null;
        this.mWhen = 0;
    }

    public String getTitle() {
        return mTitle;
    }

    public NotiBuilder setTitle(String mTitle) {

        this.mTitle = mTitle;
        return this;
    }

    public String getTicker() {
        return mTicker;
    }

    public NotiBuilder setTicker(String mTicker) {
        this.mTicker = mTicker;
        return this;
    }

    public String getContentTxt() {
        return mContentTxt;
    }

    public NotiBuilder setContentTxt(String mContentTxt) {
        this.mContentTxt = mContentTxt;
        return this;
    }

    public String getContentInfo() {
        return mContentInfo;
    }

    public NotiBuilder setContentInfo(String mContentInfo) {
        this.mContentInfo = mContentInfo;
        return this;
    }

    public Bitmap getLargeIcon() {
        return mLargeIcon;
    }

    public NotiBuilder setLargeIcon(Bitmap mLargeIcon) {
        this.mLargeIcon = mLargeIcon;
        return this;
    }

    public int getSmallIcon() {
        return mSmallIcon;
    }

    public NotiBuilder setSmallIcon(int mSmallIcon) {
        this.mSmallIcon = mSmallIcon;
        return this;
    }

    public int getStyle() {
        return mStyle;
    }

    public NotiBuilder setStyle(int mStyle) {
        this.mStyle = mStyle;
        return this;
    }

    public String[] getContentInbox() {
        return mContentInbox;
    }

    public NotiBuilder setContentInbox(String[] mContentInbox) {
        this.mContentInbox = mContentInbox;
        return this;
    }

    public NotiBuilder setContentIntent(PendingIntent pendingIntent) {
        this.mContentIntent = pendingIntent;
        return this;
    }

    public long getWhen() {
        return mWhen;
    }

    public NotiBuilder setWhen(long mWhen) {
        this.mWhen = mWhen;
        return this;
    }

    /**
     * Builds a notification message template <br />
     * Requires style (normal or inbox), content title, content text, content info are not null or empty;
     * otherwise, this function will return null.
     * @return Notification Builder
     */
    public NotificationCompat.Builder build() {
        if (mStyle == NOTI_STYLE_NORMAL || mStyle == NOTI_STYLE_INBOX) {
            if (!(isNullOrEmpty(mTitle) || isNullOrEmpty(mContentTxt) || isNullOrEmpty(mContentInfo))) {
                NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

                builder.setContentTitle(mTitle)
                        .setContentText(mContentTxt)
                        .setContentInfo(mContentInfo);

                if (!isNullOrEmpty(mTicker)) {
                    builder.setTicker(mTicker);
                }

                if (mLargeIcon != null) {
                    builder.setLargeIcon(mLargeIcon);
                }

                if (mSmallIcon != 0) {
                    builder.setSmallIcon(mSmallIcon);
                }

                if (mStyle == NOTI_STYLE_INBOX) {
                    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                    inboxStyle.setBigContentTitle(mTitle);
                    for (String line : mContentInbox) {
                        inboxStyle.addLine(line);
                    }
                    builder.setStyle(inboxStyle);
                }

                if (mWhen != 0) {
                    builder.setWhen(mWhen);
                }

                if (mContentIntent != null) {
                    builder.setContentIntent(mContentIntent);
                }

                return builder;
            }
        }
        return null;
    }

    private boolean isNullOrEmpty(String str) {
        return (str == null || str.isEmpty());
    }
}




Java Source Code List

mhst.dreamteam.ApplicationContext.java
mhst.dreamteam.ApplicationTest.java
mhst.dreamteam.ApplicationTest.java
mhst.dreamteam.MainActivity.java
mhst.dreamteam.IcingaClient.GlobalConfig.java
mhst.dreamteam.IcingaClient.GlobalConst.java
mhst.dreamteam.IcingaClient.Controller.NetControllerTest.java
mhst.dreamteam.IcingaClient.Controller.NetController.java
mhst.dreamteam.IcingaClient.Icinga.IcingaApiConst.java
mhst.dreamteam.IcingaClient.Icinga.IcingaApi.java
mhst.dreamteam.IcingaClient.Icinga.IcingaConst.java
mhst.dreamteam.IcingaClient.Icinga.IcingaExecutor.java
mhst.dreamteam.IcingaClient.Icinga.IcingaParam.java
mhst.dreamteam.IcingaClient.Icinga.IcingaUdt.java
mhst.dreamteam.IcingaClient.Icinga.package-info.java
mhst.dreamteam.IcingaClient.Interface.OnCompleteListener.java
mhst.dreamteam.IcingaClient.Interface.OnPieChartClickListener.java
mhst.dreamteam.IcingaClient.Json.JsonHelperTest.java
mhst.dreamteam.IcingaClient.Json.JsonHelper.java
mhst.dreamteam.IcingaClient.Misc.CookieMng.java
mhst.dreamteam.IcingaClient.Misc.CookieTest.java
mhst.dreamteam.IcingaClient.SessionMng.LogInTest.java
mhst.dreamteam.IcingaClient.SessionMng.Login.java
mhst.dreamteam.IcingaClient.SessionMng.Logout.java
mhst.dreamteam.IcingaClient.SessionMng.Session.java
mhst.dreamteam.IcingaService.ApplicationContext.java
mhst.dreamteam.IcingaService.DataUpdater.java
mhst.dreamteam.IcingaService.MessageReveicer.java
mhst.dreamteam.IcingaService.NotiBuilder.java
mhst.dreamteam.IcingaService.SQLHelper.java
mhst.dreamteam.IcingaService.SessionProvider.java
mhst.dreamteam.UI.Color.java
mhst.dreamteam.UI.GradientLine.java
mhst.dreamteam.UI.HostDetailsFragment.java
mhst.dreamteam.UI.HostlistAdapter.java
mhst.dreamteam.UI.HostlistFragment.java
mhst.dreamteam.UI.LoginActivity.java
mhst.dreamteam.UI.OverviewFragment.java
mhst.dreamteam.UI.PieGraph.java
mhst.dreamteam.UI.ProgressDialog.java
mhst.dreamteam.UI.ServiceDetailsFragment.java
mhst.dreamteam.UI.ServicelistAdapter.java
mhst.dreamteam.UI.ServicelistFragment.java
org.json.CDL.java
org.json.CookieList.java
org.json.Cookie.java
org.json.HTTPTokener.java
org.json.HTTP.java
org.json.JSONArray.java
org.json.JSONException.java
org.json.JSONML.java
org.json.JSONObject.java
org.json.JSONString.java
org.json.JSONStringer.java
org.json.JSONTokener.java
org.json.JSONWriter.java
org.json.Kim.java
org.json.Property.java
org.json.XMLTokener.java
org.json.XML.java
org.json.zip.BitInputStream.java
org.json.zip.BitOutputStream.java
org.json.zip.BitReader.java
org.json.zip.BitWriter.java
org.json.zip.Huff.java
org.json.zip.JSONzip.java
org.json.zip.Keep.java
org.json.zip.None.java
org.json.zip.PostMortem.java
org.json.zip.Unzipper.java
org.json.zip.Zipper.java