Android Open Source - ClinicalTrialTracker Broadcast Notifier






From Project

Back to project page ClinicalTrialTracker.

License

The source code is released under:

Apache License

If you think the Android project ClinicalTrialTracker 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) 2012 The Android Open Source Project
 *//w  w  w .  j a va  2 s.c om
 * 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.yuanwei.android;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

public class BroadcastNotifier {

    private LocalBroadcastManager mBroadcaster;

    /**
     * Creates a BroadcastNotifier containing an instance of LocalBroadcastManager.
     * LocalBroadcastManager is more efficient than BroadcastManager; because it only
     * broadcasts to components within the app, it doesn't have to do parceling and so forth.
     *
     * @param context a Context from which to get the LocalBroadcastManager
     */
    public BroadcastNotifier(Context context) {

        // Gets an instance of the support library local broadcastmanager
        mBroadcaster = LocalBroadcastManager.getInstance(context);

    }

    /**
     *
     * Uses LocalBroadcastManager to send an {@link Intent} containing {@code status}. The
     * {@link Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}.
     *
     * @param status {@link Integer} denoting a work request status
     */
    public void broadcastIntentWithState(int status) {

        Intent localIntent = new Intent();

        // The Intent contains the custom broadcast action for this app
        localIntent.setAction(Constants.BROADCAST_ACTION);

        // Puts the status into the Intent
        localIntent.putExtra(Constants.EXTENDED_DATA_STATUS, status);
        localIntent.addCategory(Intent.CATEGORY_DEFAULT);

        // Broadcasts the Intent
        mBroadcaster.sendBroadcast(localIntent);

    }

    /**
     * Uses LocalBroadcastManager to send an {@link String} containing a logcat message.
     * {@link Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}.
     *
     * @param logData a {@link String} to insert into the log.
     */
    public void notifyProgress(String logData) {

        Intent localIntent = new Intent();

        // The Intent contains the custom broadcast action for this app
        localIntent.setAction(Constants.BROADCAST_ACTION);

        localIntent.putExtra(Constants.EXTENDED_DATA_STATUS, -1);

        // Puts log data into the Intent
        localIntent.putExtra(Constants.EXTENDED_STATUS_LOG, logData);
        localIntent.addCategory(Intent.CATEGORY_DEFAULT);

        // Broadcasts the Intent
        mBroadcaster.sendBroadcast(localIntent);

    }
    public void broadcastUrl(int status,String url,String tag) {

        Intent localIntent = new Intent();

        // The Intent contains the custom broadcast action for this app
        localIntent.setAction(Constants.BROADCAST_ACTION);

        localIntent.putExtra(Constants.EXTENDED_DATA_STATUS, status);

        // Puts log data into the Intent
        localIntent.putExtra(Constants.EXTENDED_FEED_URL, url);
        localIntent.putExtra(Constants.EXTENDED_FEED_TAG, tag);
        localIntent.addCategory(Intent.CATEGORY_DEFAULT);

        // Broadcasts the Intent
        mBroadcaster.sendBroadcast(localIntent);

    }
}




Java Source Code List

com.yuanwei.android.AlarmReceiver.java
com.yuanwei.android.BootReceiver.java
com.yuanwei.android.BroadcastNotifier.java
com.yuanwei.android.ClinicalTrialsFeedBuilder.java
com.yuanwei.android.ComparatorArticle.java
com.yuanwei.android.Constants.java
com.yuanwei.android.DrawerExpandableListActivity.java
com.yuanwei.android.RssDialogManager.java
com.yuanwei.android.RssDownloadingSchedulingService.java
com.yuanwei.android.adapter.ArticleExpandableListAdapter.java
com.yuanwei.android.adapter.RssChannelListAdapter.java
com.yuanwei.android.constants.ClinicalTrialConditions.java
com.yuanwei.android.constants.ClinicalTrialDrugs.java
com.yuanwei.android.constants.ClinicalTrialSponsor.java
com.yuanwei.android.db.DbAdapter.java
com.yuanwei.android.db.FeedProvider.java
com.yuanwei.android.listview.widget.DontPressWithParentButton.java
com.yuanwei.android.listview.widget.DontPressWithParentCheckBox.java
com.yuanwei.android.rss.RssDownloadingTask.java
com.yuanwei.android.rss.RssRefreshTask.java
com.yuanwei.android.rss.domain.Article.java
com.yuanwei.android.rss.domain.FeedMessage.java
com.yuanwei.android.rss.domain.RSSFeed.java
com.yuanwei.android.rss.domain.RssChannel.java
com.yuanwei.android.rss.parser.RssHandler.java
com.yuanwei.android.util.DateConverter.java