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

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

Introduction

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

Prototype

public static LocalBroadcastManager getInstance(Context context) 

Source Link

Usage

From source file:br.liveo.ndrawer.ui.activity.MainActivity.java

License:asdf

@Override
protected void onDestroy() {
    mTimer.cancel();/*from www  . j  a  v  a  2s. co  m*/

    super.onDestroy();
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);

}

From source file:activities.PaintActivity.java

@Override
protected void onStart() {
    super.onStart();

    LocalBroadcastManager.getInstance(this.getBaseContext()).registerReceiver(_paintColorReceiver,
            new IntentFilter(PaintUtility.COLOR_CHANGED_NOTIFICATION));

    FlurryAgent.onStartSession(this, getResources().getString(R.string.flurry_app_id));

    Log.d(TAG, "onStart");

    if (paint_fullscreen_content.isInEditMode()) {
        return;/*from ww  w  . ja  v a2s  . com*/
    }
}

From source file:com.aimfire.demo.CamcorderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "create CamcorderActivity");

    loadPrefs();/*w w  w.jav a2s .  c  o  m*/

    /*
     *  keep the screen on until we turn off the flag 
     */
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camcorder);

    /*
     * Obtain the FirebaseAnalytics instance.
     */
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    /*
     * disable nfc push
     */
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter != null)
        nfcAdapter.setNdefPushMessage(null, this);

    /*
     * get the natural orientation of this device. need to be called before
     * we fix the display orientation
     */
    mNaturalOrientation = getDeviceDefaultOrientation();

    /*
     * force CamcorderActivity in landscape because it is the natural 
     * orientation of the camera sensor
     */
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    /*
     * get the orientation for SCREEN_ORIENTATION_LANDSCAPE mode. this is the 
     * clockwise rotation of landscape mode from device natural orientation.
     * reverse landscape is 180 degrees different. call this *after* the
     * display orientation is fixed, because only then getDefaultDisplay().
     * getRotation() will consistently return the value we require.
     */
    mLandscapeOrientation = getDeviceLandscapeOrientation();

    /*
     * apply the adapter to the spinner - for filter selection.
     */
    /*
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
    R.array.cameraFilterNames, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);
    */

    mParentView = getActivity().getWindow().getDecorView();

    mCaptureButton = (ImageButton) findViewById(R.id.toggle_recording_button);
    mView3DButton = (ImageButton) findViewById(R.id.view3D_button);
    mExitButton = (ImageButton) findViewById(R.id.exit_button);
    mPvButton = (ImageButton) findViewById(R.id.switch_photo_video_button);
    mFbButton = (ImageButton) findViewById(R.id.switch_front_back_button);
    mLevelButton = (Button) findViewById(R.id.level_button);
    mTimeCounter = (LinearLayout) findViewById(R.id.time_counter);
    mScanModeButton = (ImageButton) findViewById(R.id.mode_button);

    mCaptureButton.setOnClickListener(oclToggle);
    mView3DButton.setOnClickListener(oclView3D);
    mExitButton.setOnClickListener(oclExit);
    mPvButton.setOnClickListener(oclPV);
    mFbButton.setOnClickListener(oclFB);
    mScanModeButton.setOnClickListener(oclSwitchMode);

    mShutterLayout = (FrameLayout) findViewById(R.id.shutter_layout);
    mProgView = (ImageView) findViewById(R.id.circular_progress_view);

    mProgDrawable = new com.aimfire.utilities.CircularProgressDrawable.Builder().setRingWidth(10)
            .setRingColor(getResources().getColor(R.color.orange)).create();

    mProgView.setImageDrawable(mProgDrawable);

    mScanProgView = (ImageView) findViewById(R.id.scan_circular_progress_view);
    mScanProgView.setOnClickListener(oclScan);

    int[] centerGradient = new int[] { getResources().getColor(R.color.start_button_start_color_pressed),
            getResources().getColor(R.color.start_button_end_color_pressed) };

    mScanProgDrawable = new com.aimfire.utilities.CircularProgressDrawable.Builder().setRingWidth(10)
            .setInnerCircleScale(1.0f).setOutlineColor(getResources().getColor(R.color.dark_grey))
            .setRingColor(getResources().getColor(R.color.white))
            .setArcColor(getResources().getColor(android.R.color.holo_blue_dark))
            .setCenterGradient(centerGradient).setWifiBarColor(getResources().getColor(R.color.blue))
            .setMessageSize((int) (10/*sp*/ * getResources().getDisplayMetrics().density))
            .setMessageColor(getResources().getColor(R.color.white)).create();

    mScanProgView.setImageDrawable(mScanProgDrawable);

    /*
     * showing animation for searching remote device
     */
    startScanAnim();

    String startSound = null;
    String stopSound = null;
    for (String s : CAMERA_RECORDING_START_SOUND) {
        if ((new File(s)).exists()) {
            startSound = s;
            break;
        }
    }

    if (startSound != null) {
        mCamStartSoundPlayer = MediaPlayer.create(this, Uri.fromFile(new File(startSound)));
    }

    for (String s : CAMERA_RECORDING_STOP_SOUND) {
        if ((new File(s)).exists()) {
            stopSound = s;
            break;
        }
    }

    if (stopSound != null) {
        mCamStopSoundPlayer = MediaPlayer.create(this, Uri.fromFile(new File(stopSound)));
    }

    /*
     * file name prefix for solo mode. rest of the file name (date and time stamp) are
     * added when recording starts.
     */
    mMpegPrefixSolo = MainConsts.MEDIA_3D_SAVE_PATH + "MPG_solo_";

    /*
     * place UI controls at their initial, default orientation
     */
    adjustUIControls(0);

    /*
     * load the thumbnail of the newest movie to the view3D button
     */
    loadCurrThumbnail();

    /*
     * attempt to open camera with desired dimension. the dimension may be
     * changed if camera doesn't support it, in which case the "preferred" 
     * (by the camera) dimension will be used
     */
    boolean success = openCamera(Camera.CameraInfo.CAMERA_FACING_BACK, mQualityPref);

    if (!success) {
        Toast.makeText(this, R.string.error_opening_camera, Toast.LENGTH_LONG).show();

        finish();
        return;
    }

    /*
     * define a handler that receives camera-control messages from other threads.  
     * all calls to Camera must be made on the same thread.  note we create this 
     * before the renderer thread, so we know the fully-constructed object will 
     * be visible.
     */
    mCameraHandler = new CameraHandler(this);

    /*
     * configure the GLSurfaceView.  this will start the Renderer thread, with an
     * appropriate EGL context.
     */
    mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView);
    mGLView.setEGLContextClientVersion(2); // select GLES 2.0
    mRenderer = new CameraSurfaceRenderer(mCameraHandler, mMovieEncoder);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    mGLView.setOnTouchListener(otl);

    /*
     * bind to Aimfire service
     */
    mAimfireServiceConn = new AimfireServiceConn(this);

    /*
     * binding doesn't happen until later. wait for it to happen in another 
     * thread and connect to p2p peer if necessary
     */
    (new Thread(mAimfireServiceInitTask)).start();

    /*
     * register for AimfireService message broadcast
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mAimfireServiceMsgReceiver,
            new IntentFilter(MainConsts.AIMFIRE_SERVICE_MESSAGE));

    /*
     * register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mMovieProcessorMsgReceiver,
            new IntentFilter(MainConsts.MOVIE_PROCESSOR_MESSAGE));

    /*
     * register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).registerReceiver(mMovieEncoderMsgReceiver,
            new IntentFilter(MainConsts.MOVIE_ENCODER_MESSAGE));
}

From source file:com.android.contacts.ContactSaveService.java

private void deleteGroup(Intent intent) {
    long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1);
    if (groupId == -1) {
        Log.e(TAG, "Invalid arguments for deleteGroup request");
        return;/* w  w  w .  ja  v a 2 s  .co m*/
    }
    final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId);

    final Intent callbackIntent = new Intent(BROADCAST_GROUP_DELETED);
    final Bundle undoData = mGroupsDao.captureDeletionUndoData(groupUri);
    callbackIntent.putExtra(EXTRA_UNDO_ACTION, ACTION_DELETE_GROUP);
    callbackIntent.putExtra(EXTRA_UNDO_DATA, undoData);

    mGroupsDao.delete(groupUri);

    LocalBroadcastManager.getInstance(this).sendBroadcast(callbackIntent);
}

From source file:com.adityarathi.muo.ui.activities.NowPlayingActivity.java

@Override
public void onStart() {
    super.onStart();
    //Initialize the broadcast manager that will listen for track changes.
    LocalBroadcastManager.getInstance(mContext).registerReceiver((mReceiver),
            new IntentFilter(Common.UPDATE_UI_BROADCAST));

    /* Check if the service is up and running. If so, send out a broadcast message 
     * that will initialize this activity fully. This code block is what will 
     * initialize this activity fully if it is opened after the service is already 
     * up and running (the onServiceRunning() callback isn't available at this point).
     *///from  w w w  .ja  v  a  2 s  . com
    if (mApp.isServiceRunning() && mApp.getService().getCursor() != null) {
        String[] updateFlags = new String[] { Common.UPDATE_PAGER_POSTIION, Common.UPDATE_SEEKBAR_DURATION,
                Common.HIDE_STREAMING_BAR, Common.INIT_PAGER, Common.UPDATE_PLAYBACK_CONTROLS,
                Common.UPDATE_EQ_FRAGMENT };

        String[] flagValues = new String[] { "" + mApp.getService().getCurrentSongIndex(),
                "" + mApp.getService().getCurrentMediaPlayer().getDuration(), "", "", "", "" };
        mApp.broadcastUpdateUICommand(updateFlags, flagValues);
    }

}

From source file:activities.PaintActivity.java

@Override
protected void onStop() {
    super.onStop();
    LocalBroadcastManager.getInstance(this).unregisterReceiver(_paintColorReceiver);
    FlurryAgent.onEndSession(this);
    Log.d(TAG, "onStop");

}

From source file:com.aimfire.demo.CamcorderActivity.java

@Override
protected void onRestart() {
    super.onRestart();

    if (mP2pConnected) {
        if (!mAimfireService.isP2pConnected()) {
            /*/*from ww  w . j  a  va  2  s  .  c  om*/
             * we were in 3d mode, but came back and found we are now disconnected. it must be
               * that during the time this activity is not in foreground, remote device has
               * disconnected, in which case we terminate.
               */
            finish();
            return;
        } else if (mAimfireService != null) {
            /*
             * we remain connected, tell remote device we came back
             */
            mAimfireService.restartDemo();
        }
    }

    /*
     *  keep the screen on until we turn off the flag 
     */
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    if (BuildConfig.DEBUG)
        Log.d(TAG, "onRestart -- acquiring camera");
    mGLView.onResume();

    /*
     * restart camera, keep the last camera facing. reuse EGL context
     * just as if we are doing a switch
     */
    switchCamera(mCameraFacing);

    /*
     * place UI controls at their initial, default orientation
     */
    adjustUIControls(0);

    /*
     * load the latest thumbnail to the view3D button. we need
     * to do this because we (the CamcorderActivity) has been in
     * the background, and during this time, GalleryActivity may
     * have deleted the thumb and it's associated image that was
     * showing before
     */
    loadCurrThumbnail();

    if (mOrientationEventListener != null)
        mOrientationEventListener.enable();

    LocalBroadcastManager.getInstance(this).registerReceiver(mAimfireServiceMsgReceiver,
            new IntentFilter(MainConsts.AIMFIRE_SERVICE_MESSAGE));

    mLocalCameraPaused = false;
}

From source file:com.adityarathi.muo.ui.activities.NowPlayingActivity.java

@Override
public void onStop() {
    //Unregister the broadcast receivers.
    LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mReceiver);
    super.onStop();

}

From source file:com.aimfire.demo.CamcorderActivity.java

@Override
protected void onStop() {
    super.onStop();

    /*/*from ww  w  .  j a va 2 s  . c  om*/
    * screen can turn off now. 
       */
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    /*
     * user decided to put us in background, or we are on our way to
     * be destroyed. here "stop" is in activity lifecycle's sense,
     * it doesn't mean we "end" the demo. If we are switching to 
     * Camera mode, we have already stopped camera.
     */
    if (!mSwitchPhotoVideo) {
        stopCamera();

        if (mAimfireService != null) {
            mAimfireService.stopDemo();
        }
    }

    LocalBroadcastManager.getInstance(this).unregisterReceiver(mAimfireServiceMsgReceiver);

    mSwitchPhotoVideo = false;
    mLocalCameraPaused = true;
}

From source file:com.aimfire.demo.CamcorderActivity.java

@Override
protected void onDestroy() {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onDestroy");

    /*//w ww  .  j  av  a 2 s .  c om
    * screen can turn off now.
       */
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    if (mCameraHandler != null) {
        mCameraHandler.invalidateHandler(); // paranoia
    }

    if (mAimfireServiceConn != null) {
        mAimfireServiceConn.unbind();
    }

    /*
     * de-register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMovieProcessorMsgReceiver);

    /*
     * de-register for intents sent by the media encoder service
     */
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMovieEncoderMsgReceiver);

    /*
     * unpin - no effect if screen not pinned
     */
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            stopLockTask();
        } catch (RuntimeException e) {
            if (BuildConfig.DEBUG)
                Log.e(TAG, "stopLockTask generated RuntimeException!");
        }
    }

    super.onDestroy();
}