Example usage for android.support.v4.content LocalBroadcastManager sendBroadcast

List of usage examples for android.support.v4.content LocalBroadcastManager sendBroadcast

Introduction

In this page you can find the example usage for android.support.v4.content LocalBroadcastManager sendBroadcast.

Prototype

public boolean sendBroadcast(Intent intent) 

Source Link

Document

Broadcast the given intent to all interested BroadcastReceivers.

Usage

From source file:org.scribacrm.scriba.SerializationBroadcast.java

public static void sendSerializationBroadcast(Context context) {
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
    Intent intent = new Intent(ACTION_SERIALIZATION_COMPLETED);
    manager.sendBroadcast(intent);
}

From source file:org.scribacrm.scriba.SerializationBroadcast.java

public static void sendDeserializationBroadcast(Context context) {
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
    Intent intent = new Intent(ACTION_DESERIALIZATION_COMPLETED);
    manager.sendBroadcast(intent);
}

From source file:com.javadog.bluetoothproximitylock.SignalReaderService.java

/**
 * Sends the specified int using the LocalBroadcastManager interface.
 * Retrieve the message using intent.getIntExtra("message").
 *
 * @param context The application context.
 * @param action The action to specify with the Intent.
 * @param message The message to send.//from  www.  j a  v  a2s .c om
 */
protected static void sendLocalBroadcast(Context context, String action, int message) {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(context);
    Intent i = new Intent(action);
    i.putExtra("message", message);
    broadcastManager.sendBroadcast(i);

    Log.d(MainActivity.DEBUG_TAG, "Sent local broadcast with action: " + action);
}

From source file:org.isoron.uhabits.HabitBroadcastReceiver.java

public static void sendRefreshBroadcast(Context context) {
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
    Intent refreshIntent = new Intent(MainActivity.ACTION_REFRESH);
    manager.sendBroadcast(refreshIntent);

    MainActivity.updateWidgets(context);
}

From source file:com.google.ytdl.ResumableUpload.java

/**
 * Uploads user selected video in the project folder to the user's YouTube account using OAuth2
 * for authentication.//  w w w .  j  a va 2s .co  m
 *
 * @param args command line args (not used).
 */

public static String upload(YouTube youtube, final InputStream fileInputStream, final long fileSize,
        Context context) {
    final NotificationManager mNotifyManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setContentTitle(context.getString(R.string.youtube_upload))
            .setContentText(context.getString(R.string.youtube_direct_lite_upload_started))
            .setSmallIcon(R.drawable.icon);
    String videoId = null;
    try {
        // Add extra information to the video before uploading.
        Video videoObjectDefiningMetadata = new Video();

        /*
         * Set the video to public, so it is available to everyone (what most people want). This is
         * actually the default, but I wanted you to see what it looked like in case you need to set
         * it to "unlisted" or "private" via API.
         */
        VideoStatus status = new VideoStatus();
        status.setPrivacyStatus("public");
        videoObjectDefiningMetadata.setStatus(status);

        // We set a majority of the metadata with the VideoSnippet object.
        VideoSnippet snippet = new VideoSnippet();

        /*
         * The Calendar instance is used to create a unique name and description for test purposes, so
         * you can see multiple files being uploaded. You will want to remove this from your project
         * and use your own standard names.
         */
        Calendar cal = Calendar.getInstance();
        snippet.setTitle("Test Upload via Java on " + cal.getTime());
        snippet.setDescription(
                "Video uploaded via YouTube Data API V3 using the Java library " + "on " + cal.getTime());

        // Set your keywords.
        List<String> tags = new ArrayList<String>();
        tags.add(Constants.DEFAULT_KEYWORD);
        tags.add(Upload.generateKeywordFromPlaylistId(Constants.UPLOAD_PLAYLIST));
        snippet.setTags(tags);

        // Set completed snippet to the video object.
        videoObjectDefiningMetadata.setSnippet(snippet);

        InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT,
                new BufferedInputStream(fileInputStream));
        mediaContent.setLength(fileSize);

        /*
         * The upload command includes: 1. Information we want returned after file is successfully
         * uploaded. 2. Metadata we want associated with the uploaded video. 3. Video file itself.
         */
        YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status",
                videoObjectDefiningMetadata, mediaContent);

        // Set the upload type and add event listener.
        MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();

        /*
         * Sets whether direct media upload is enabled or disabled. True = whole media content is
         * uploaded in a single request. False (default) = resumable media upload protocol to upload
         * in data chunks.
         */
        uploader.setDirectUploadEnabled(false);

        MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
            public void progressChanged(MediaHttpUploader uploader) throws IOException {
                switch (uploader.getUploadState()) {
                case INITIATION_STARTED:
                    mBuilder.setContentText("Initiation Started").setProgress((int) fileSize,
                            (int) uploader.getNumBytesUploaded(), false);
                    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
                    break;
                case INITIATION_COMPLETE:
                    mBuilder.setContentText("Initiation Completed").setProgress((int) fileSize,
                            (int) uploader.getNumBytesUploaded(), false);
                    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
                    break;
                case MEDIA_IN_PROGRESS:
                    mBuilder.setContentTitle("YouTube Upload " + (int) (uploader.getProgress() * 100) + "%")
                            .setContentText("Direct Lite upload in progress")
                            .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false);
                    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
                    break;
                case MEDIA_COMPLETE:
                    mBuilder.setContentTitle("YouTube Upload Completed").setContentText("Upload complete")
                            // Removes the progress bar
                            .setProgress(0, 0, false);
                    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
                case NOT_STARTED:
                    Log.d(this.getClass().getSimpleName(), "Upload Not Started!");
                    break;
                }
            }
        };
        uploader.setProgressListener(progressListener);

        // Execute upload.
        Video returnedVideo = videoInsert.execute();
        videoId = returnedVideo.getId();

    } catch (final GoogleJsonResponseException e) {
        if (401 == e.getDetails().getCode()) {
            Log.e(ResumableUpload.class.getSimpleName(), e.getMessage());
            LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
            manager.sendBroadcast(new Intent(MainActivity.INVALIDATE_TOKEN_INTENT));
        }
    } catch (IOException e) {
        Log.e("IOException", e.getMessage());
    } catch (Throwable t) {
        Log.e("Throwable", t.getMessage());
    }
    return videoId;
}

From source file:at.jclehner.rxdroid.SplashScreenActivity.java

public static void setStatusMessage(int msgResId) {
    final Context context = RxDroid.getContext();
    final Intent intent = new Intent(context, DatabaseStatusReceiver.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.putExtra(DatabaseStatusReceiver.EXTRA_MESSAGE, msgResId);

    LocalBroadcastManager bm = RxDroid.getLocalBroadcastManager();
    bm.sendBroadcast(intent);
}

From source file:com.airbop.library.simple.CommonUtilities.java

static void sendLocalBroadcast(Context context, Intent intent) {
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    if ((lbm != null) && (intent != null)) {
        lbm.sendBroadcast(intent);
    }/*from w w  w  . ja  va2  s  .  c om*/
}

From source file:org.adaway.ui.BaseActivity.java

/**
 * Static helper method to send broadcasts to the BaseActivity and enable or disable buttons
 *
 * @param context//from ww w .j  ava2 s .co m
 * @param buttonsDisabled to enable buttons apply and revert
 */
public static void setButtonsDisabledBroadcast(Context context, boolean buttonsDisabled) {
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);

    Intent intent = new Intent(ACTION_BUTTONS);
    intent.putExtra(EXTRA_BUTTONS_DISABLED, buttonsDisabled);
    localBroadcastManager.sendBroadcast(intent);
}

From source file:ca.farrelltonsolar.classic.MonitorApplication.java

public static void monitorChargeController(int device) {
    if (device < 0 || device >= chargeControllers.count()) {
        return;/*from   w w w  .j  a v  a  2 s  . co m*/
    }
    if (chargeControllers.setCurrent(device)) {
        LocalBroadcastManager broadcaster = LocalBroadcastManager.getInstance(context);
        Intent pkg = new Intent(Constants.CA_FARRELLTONSOLAR_CLASSIC_MONITOR_CHARGE_CONTROLLER);
        pkg.putExtra("DifferentController", true);
        broadcaster.sendBroadcast(pkg); //notify activity
    }
}

From source file:com.google.android.apps.forscience.whistlepunk.metadata.CropHelper.java

private static void sendStatsUpdatedBroadcast(Context context, String sensorId, String runId) {
    if (context == null) {
        return;//w  w  w  .java 2 s.co  m
    }
    // Use a LocalBroadcastManager, because we do not need this broadcast outside the app.
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    Intent intent = new Intent();
    intent.setAction(ACTION_CROP_STATS_RECALCULATED);
    intent.putExtra(EXTRA_SENSOR_ID, sensorId);
    intent.putExtra(EXTRA_RUN_ID, runId);
    lbm.sendBroadcast(intent);
}