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:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

private void notifyActivityCancelled() {
    Intent cancelIntent = new Intent(ACTION_PROVISIONING_CANCELLED);
    LocalBroadcastManager.getInstance(this).sendBroadcast(cancelIntent);
}

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

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

    checkPreferences();//from w w w .  j  a v  a  2s .  co  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_camera);

    /*
     * 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 CameraActivity in landscape because it is the natural 
     * orientation of the camera sensor
     */
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    mLandscapeOrientation = getDeviceLandscapeOrientation();

    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        if (BuildConfig.DEBUG)
            Log.e(TAG, "onCreate: error create CameraActivity, wrong parameter");
        finish();
        return;
    }

    /*
     *  make sure we have camera
     */
    if (!checkCameraHardware(this)) {
        if (BuildConfig.DEBUG)
            Log.e(TAG, "onCreate: error create CameraActivity, cannot find camera!!!");
        finish();
        return;
    }

    mIsLeft = extras.getBoolean(MainConsts.EXTRA_ISLEFT);

    mView3DButton = (ImageButton) findViewById(R.id.view3D_button);
    mExitButton = (ImageButton) findViewById(R.id.exit_button);
    mCaptureButton = (ImageButton) findViewById(R.id.capture_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);
    mModeButton = (ImageButton) findViewById(R.id.mode_button);

    if (mIsLeft) {
        mCaptureButton.setImageResource(R.drawable.ic_photo_camera_black_24dp);
    } else {
        mCaptureButton.setVisibility(View.INVISIBLE);

        mPvButton.setVisibility(View.INVISIBLE);
        mFbButton.setVisibility(View.INVISIBLE);
    }

    mView3DButton.setOnClickListener(oclView3D);
    mExitButton.setOnClickListener(oclExit);
    mPvButton.setOnClickListener(oclPV);
    mFbButton.setOnClickListener(oclFB);
    mCaptureButton.setOnClickListener(oclCapture);

    /*
     * we could get here in two ways: 1) directly after MainActivity ->
     * AimfireService sync with remote device. 2) we could get here 
     * because of a switch from video to photo mode. 
     * 
     * mSyncTimeUs is determined by AudioContext. each device 
     * calculates it, and they correspond to the same absolute moment 
     * in time
     */
    mSyncTimeUs = extras.getLong(MainConsts.EXTRA_SYNCTIME, -1);

    /*
     * start camera client object in a dedicated thread
     */
    mCameraClient = new CameraClient(Camera.CameraInfo.CAMERA_FACING_BACK, PHOTO_DIMENSION[0],
            PHOTO_DIMENSION[1]);

    /*
     * create our SurfaceView for preview 
     */
    mPreview = new CameraPreview(this);
    mPreviewLayout = (AspectFrameLayout) findViewById(R.id.cameraPreview_frame);
    mPreviewLayout.addView(mPreview);
    mPreviewLayout.setOnTouchListener(otl);
    if (BuildConfig.DEBUG)
        Log.d(TAG, "add camera preview view");

    mShutterSoundPlayer = MediaPlayer.create(this, Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));

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

    /*
     * load the latest thumbnail to the view3D button
     */
    loadCurrThumbnail();

    /*
     * initializes AimfireService, and bind to it
     */
    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();

    if (ADD_LOGO) {
        /*
         * init our logo that will be embedded in processed photos
         */
        AssetManager assetManager = getAssets();
        p.getInstance().a(assetManager, MainConsts.MEDIA_3D_RAW_PATH, "logo.png");
    }

    /*
     * 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(mPhotoProcessorMsgReceiver,
            new IntentFilter(MainConsts.PHOTO_PROCESSOR_MESSAGE));
}

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

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

    /*/*from w w w  . j a  v a 2 s  .  com*/
    * 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 
     * Camcorder mode, we have already stopped camera.
     */
    if (!mSwitchPhotoVideo) {
        stopCamera();

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

    /*
     * de-register for intents sent by the Aimfire service
     */
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mAimfireServiceMsgReceiver);

    mSwitchPhotoVideo = false;
    mLocalCameraPaused = true;
}

From source file:ch.bfh.evoting.alljoyn.BusHandler.java

/**
 * Signal Handler for the Ping signal//  www  .j ava 2s.c  o m
 * This method receives the message from the other peers
 * @param str content of the message
 */
@BusSignalHandler(iface = "org.alljoyn.bus.samples.simple.SimpleInterface", signal = "Ping")
public void Ping(String str) {

    if (str == null)
        return;

    //Deserialize the message
    AllJoynMessage message = (AllJoynMessage) su.deserialize(str, AllJoynMessage.class);
    if (message == null) {
        //deserialization failed, that means that this was not a message sent by our application
        Log.d(TAG, "Deserialization of message failed.");
        return;
    }
    message.setMessageAuthenticater(this.messageAuthenticater);
    message.setMessageEncrypter(this.messageEncrypter);

    if (connected) {
        String sender = mGroupManager.getSenderPeerId();
        //we ask alljoin for the sender id and compare it with the sender found in the message
        //if it is different, someone is trying to send a message on behalf of another peer
        if (!message.getSender().equals(sender)) {
            Intent intent = new Intent("attackDetected");
            intent.putExtra("type", 2);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
            Log.e(TAG, "The name of the sender of the message indicated by AllJoyn is " + sender
                    + " but the sender indicated in the message is " + message.getSender() + "!!");
            return;
        }
    }

    processMessage(message);
}

From source file:com.anjalimacwan.MainActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override// ww w.  j  a v  a  2  s .  co m
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    if (resultCode == RESULT_OK && resultData != null) {
        successful = true;

        if (requestCode == IMPORT) {
            Uri uri = resultData.getData();
            ClipData clipData = resultData.getClipData();

            if (uri != null)
                successful = importNote(uri);
            else if (clipData != null)
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    successful = importNote(clipData.getItemAt(i).getUri());
                }

            // Show toast notification
            showToast(successful
                    ? (uri == null ? R.string.notes_imported_successfully : R.string.note_imported_successfully)
                    : R.string.error_importing_notes);

            // Send broadcast to NoteListFragment to refresh list of notes
            Intent listNotesIntent = new Intent();
            listNotesIntent.setAction("com.anjalimacwan.LIST_NOTES");
            LocalBroadcastManager.getInstance(this).sendBroadcast(listNotesIntent);
        } else if (requestCode == EXPORT) {
            try {
                saveExportedNote(loadNote(filesToExport[fileBeingExported].toString()), resultData.getData());
            } catch (IOException e) {
                successful = false;
            }

            fileBeingExported++;
            if (fileBeingExported < filesToExport.length)
                reallyExportNote();
            else
                showToast(successful
                        ? (fileBeingExported == 1 ? R.string.note_exported_to : R.string.notes_exported_to)
                        : R.string.error_exporting_notes);

        } else if (requestCode == EXPORT_TREE) {
            DocumentFile tree = DocumentFile.fromTreeUri(this, resultData.getData());

            for (Object exportFilename : filesToExport) {
                try {
                    DocumentFile file = tree.createFile("text/plain",
                            generateFilename(loadNoteTitle(exportFilename.toString())));
                    saveExportedNote(loadNote(exportFilename.toString()), file.getUri());
                } catch (IOException e) {
                    successful = false;
                }
            }

            showToast(successful ? R.string.notes_exported_to : R.string.error_exporting_notes);
        }
    }
}

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

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

    /*/* w  w w.jav a 2  s .  c o  m*/
     *  keep the screen on until we turn off the flag 
     */
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    /*
     * start camera client object in a dedicated thread
     */
    mCameraClient = new CameraClient(Camera.CameraInfo.CAMERA_FACING_BACK, PHOTO_DIMENSION[0],
            PHOTO_DIMENSION[1]);

    /*
     * create our SurfaceView for preview 
     */
    mPreview = new CameraPreview(this);
    mPreviewLayout = (AspectFrameLayout) findViewById(R.id.cameraPreview_frame);
    mPreviewLayout.addView(mPreview);
    if (BuildConfig.DEBUG)
        Log.d(TAG, "add camera preview view");

    /*
     * 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 CameraActivity) 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));

    if ((mAimfireService != null) && mAimfireService.isP2pConnected()) {
        mAimfireService.restartDemo();
    } else {
        /*
         * during the time this activity is not in foreground, remote device
         * may have been disconnected, in which case we terminate.
         */
        finish();
    }

    mLocalCameraPaused = false;
}

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

@Override
public void onDestroy() {
    /*/*  ww w . ja v a2 s  .  c  om*/
    * screen can turn off now.
       */
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

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

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

    super.onDestroy();
}

From source file:com.aniruddhc.acemusic.player.NowPlayingQueueActivity.NowPlayingQueueFragment.java

@Override
public void onStart() {
    super.onStart();
    LocalBroadcastManager.getInstance(mContext).registerReceiver((receiver),
            new IntentFilter(Common.UPDATE_UI_BROADCAST));

}

From source file:com.anp.bdmt.MainActivity.java

@Override
protected void onResume() {
    // NotificationManager nm =
    // (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    // nm.cancelAll();
    setCartCount(this);

    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.REGISTRATION_READY));
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.REGISTRATION_GENERATING));
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.REGISTRATION_COMPLETE));

    super.onResume();
    // Check device for Play Services APK.
}

From source file:biz.wiz.android.wallet.service.BlockchainServiceImpl.java

private void broadcastPeerState(final int numPeers) {
    final Intent broadcast = new Intent(ACTION_PEER_STATE);
    broadcast.setPackage(getPackageName());
    broadcast.putExtra(ACTION_PEER_STATE_NUM_PEERS, numPeers);

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