Example usage for android.content BroadcastReceiver BroadcastReceiver

List of usage examples for android.content BroadcastReceiver BroadcastReceiver

Introduction

In this page you can find the example usage for android.content BroadcastReceiver BroadcastReceiver.

Prototype

public BroadcastReceiver() 

Source Link

Usage

From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java

/**
 * USB???/*from  ww  w  .jav a 2 s  .co  m*/
 */
private void listenUsbDevice(CallbackContext callbackContext) {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    this.usbCallbackContext = callbackContext;
    if (this.mUsbReceiver == null) {
        this.mUsbReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String handlerName = null;
                String action = intent.getAction();
                if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
                    // plugin result of USB attached
                    handlerName = HANDLER_PREFIX + "." + "attached";
                }
                if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
                    // plugin result of USB detached
                    handlerName = HANDLER_PREFIX + "." + "detached";
                }
                try {
                    String json = "{\"handlerName\":" + handlerName + " }";
                    JSONObject parameter = new JSONObject(json);
                    PluginResult dataResult = new PluginResult(PluginResult.Status.OK, parameter);
                    dataResult.setKeepCallback(true);
                    usbCallbackContext.sendPluginResult(dataResult);
                } catch (JSONException e) {
                    Log.e(POCKETDUINO, "Exception: " + e.getMessage());
                    usbCallbackContext.error(e.toString());
                }
            }
        };
        webView.getContext().registerReceiver(this.mUsbReceiver, intentFilter);
    }
}

From source file:org.mycard.net.network.RequestQueue.java

/***
 * Enables data state and proxy tracking
 *//*from  w  ww. j a va  2s  .  co  m*/
public synchronized void enablePlatformNotifications() {
    //if (HttpLog.LOGV) HttpLog.v("RequestQueue.enablePlatformNotifications() network");

    if (mProxyChangeReceiver == null) {
        mProxyChangeReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context ctx, Intent intent) {
                setProxyConfig();
            }
        };
        mContext.registerReceiver(mProxyChangeReceiver, new IntentFilter(Proxy.PROXY_CHANGE_ACTION));
    }
    // we need to resample the current proxy setup
    setProxyConfig();
}

From source file:com.nadmm.airports.ActivityBase.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDbManager = DatabaseManager.instance(this);
    mInflater = getLayoutInflater();//from   w  w  w  .j  a v  a 2s .co m
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    mHandler = new Handler();

    mFilter = new IntentFilter();
    mFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    mFilter.addAction(Intent.ACTION_MEDIA_SHARED);
    mFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    mFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
    mFilter.addDataScheme("file");

    mExternalStorageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            externalStorageStatusChanged();
        }
    };

    if (Application.sDonationDone == null) {
        DonateDatabase db = new DonateDatabase(this);
        Cursor c = db.queryAllDonations();
        Application.sDonationDone = c.moveToFirst();
        db.close();
    }

    // Enable Google Analytics
    ((Application) getApplication()).getAnalyticsTracker();
}

From source file:de.unifreiburg.es.iLitIt.LighterBluetoothService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (mBluetoothChangeReceiver == null) {
        mBluetoothChangeReceiver = new BroadcastReceiver() {
            @Override//from  w w  w .j a va 2s. co  m
            public void onReceive(Context context, Intent intent) {
                final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);

                switch (state) {
                case BluetoothAdapter.STATE_ON:
                    onStartCommand(null, 0, 0);
                    break;
                case BluetoothAdapter.STATE_OFF:
                    break;
                default:
                    break;
                }
            }
        };

        IntentFilter mif = new IntentFilter();
        mif.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        registerReceiver(mBluetoothChangeReceiver, mif);
    }

    if (mSmartWatchAnnotationReceiver == null) {
        mSmartWatchAnnotationReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (mEventList == null)
                    return;

                String via = intent.getStringExtra("ess.imu_logger.libs.data_save.extra.annotationVia");
                mEventList.add(new CigaretteEvent(new Date(), via == null ? "intent" : via, null));
            }
        };

        // create watch ui intent listener
        IntentFilter filter = new IntentFilter("ess.imu_logger.libs.data_save.annotate");
        registerReceiver(mSmartWatchAnnotationReceiver, filter);
    }

    // For API level 18 and above, get a reference to BluetoothAdapter through
    // BluetoothManager.
    //if (serviceIsInitialized)
    //    return START_STICKY;

    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (mBluetoothManager == null) {
        Log.e(TAG, "Unable to initialize BluetoothManager.");
        return START_NOT_STICKY;
    }

    mBluetoothAdapter = mBluetoothManager.getAdapter();
    if (mBluetoothAdapter == null) {
        Log.e(TAG, "Unable to obtain a BluetoothAdapter.");
        return START_NOT_STICKY;
    }

    // for DEBUGGING only
    // PreferenceManager.getDefaultSharedPreferences(this).edit().clear().apply();

    /** check if we are already bound to a device, if not start scanning for one */
    mBluetoothDeviceAddress = PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_DEVICEADDR,
            null);
    mLastBatteryVoltage = PreferenceManager.getDefaultSharedPreferences(this).getFloat(KEY_BATVOLTAGE, 0.0f);
    mBatteryEmpty = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(KEY_BATEMTPY, false);

    super.onStartCommand(intent, flags, startId);

    /** load the stored events */
    if (mEventList == null) {
        mEventList = CigAnnotationWriter.readCigaretteList(this);

        mEventList.register(rCigAnnotationWriter);
        mEventList.register(rCigIntentBroadcaster);

    }

    /** set-up the location service, we need this to run here, since we need to
     *access the location whenever there is a chang to the cigarette model. */
    mLocationClient = new LocationClient(this, mLocationHandler, mLocationHandler);
    mEventList.register(new DelayedObserver(1000, mLocationHandler));

    /** start to scan for LE devices in the area */
    mHandler = new Handler(Looper.getMainLooper());
    mHandler.post(rStartLEScan);

    /** create a notification on a pending connection */
    PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT);
    mNotification = (new NotificationCompat.Builder(this)).setContentText("downloading cigarette events")
            .setContentTitle("iLitIt").setSmallIcon(R.drawable.ic_cigarette_black).setProgress(0, 0, true)
            .setAutoCancel(true).setContentIntent(i).build();

    mLowBatteryWarning = (new NotificationCompat.Builder(this)).setContentTitle("iLitIt - battery low")
            .setContentText("replace battery as soons as possible").setSmallIcon(R.drawable.ic_launcher)
            .build();

    return START_STICKY;
}

From source file:info.tongrenlu.FullScreenPlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  ww  w.  j a  v a 2  s  .  c o m*/

    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
    }

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);

    //mPauseDrawable = this.getResources().getDrawable(R.drawable.ic_pause_white_48dp);
    //mPlayDrawable = this.getResources().getDrawable(R.drawable.ic_play_arrow_white_48dp);

    mPlayPause = (ImageView) findViewById(R.id.imageView1);
    mSkipNext = (ImageView) findViewById(R.id.next);
    mSkipPrev = (ImageView) findViewById(R.id.prev);
    mStart = (TextView) findViewById(R.id.startText);
    mEnd = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mLine1 = (TextView) findViewById(R.id.line1);
    //        mLine2 = (TextView) findViewById(R.id.line2);
    mLine3 = (TextView) findViewById(R.id.line3);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);

    mSkipNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), MusicService.class);
            intent.setAction(MusicService.CMD_NEXT);
            startService(intent);
        }
    });

    mSkipPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), MusicService.class);
            intent.setAction(MusicService.CMD_PREV);
            startService(intent);
        }
    });

    mPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), MusicService.class);
            intent.setAction(MusicService.CMD_TOGGLE_PLAYBACK);
            startService(intent);
        }
    });

    mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // mStart.setText(Utils.formatMillis(progress));
            mStart.setText(toTime(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            stopProgressUpdate();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Intent intent = new Intent(getApplicationContext(), MusicService.class);
            intent.setAction(MusicService.CMD_SEEK_TO);
            intent.putExtra(MusicService.PARAM_PROGRESS, seekBar.getProgress());
            startService(intent);

            scheduleProgressUpdate();
        }
    });

    // Only update from the intent if we are not recreating from a config change:
    if (savedInstanceState == null) {
        updateFromParams(getIntent());
    }

    this.mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

    mPlaybackStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(final Context context, final Intent intent) {
            switch (intent.getAction()) {
            case MusicService.CMD_PLAYBACK_STATE:
                String receiver = intent.getStringExtra(MusicService.PARAM_RECEIVER);
                if (receiver == null || TAG.equals(receiver)) {
                    updateFromService(intent);
                    PlaybackStateCompat state = intent.getParcelableExtra(MusicService.PARAM_STATE);
                    updatePlaybackState(state);
                    updateProgress();
                }
                break;
            default:
                break;
            }
        }
    };
}

From source file:ack.me.truconnectandroiddemo.MainActivity.java

private void initBroadcastReceiver() {
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override/*from w  ww.  j  av a  2s.  c  om*/
        public void onReceive(Context context, Intent intent) {
            // Get extra data included in the Intent
            String action = intent.getAction();

            switch (action) {
            case TruconnectService.ACTION_SCAN_RESULT:
                addDeviceToList(TruconnectService.getData(intent));
                break;

            case TruconnectService.ACTION_CONNECTED:
                String deviceName = TruconnectService.getData(intent);

                mConnected = true;
                dismissConnectDialog();
                showToast("Connected to " + deviceName, Toast.LENGTH_SHORT);
                Log.d(TAG, "Connected to " + deviceName);

                mTruconnectManager.setMode(TruconnectManager.MODE_COMMAND_REMOTE);
                mTruconnectManager.setSystemCommandMode(TruconnectCommandMode.MACHINE);
                startDeviceInfoActivity();
                break;

            case TruconnectService.ACTION_DISCONNECTED:
                break;

            case TruconnectService.ACTION_MODE_WRITE:
                break;

            case TruconnectService.ACTION_MODE_READ:
                break;

            case TruconnectService.ACTION_DATA_WRITE:
                break;

            case TruconnectService.ACTION_DATA_READ:
                break;

            case TruconnectService.ACTION_COMMAND_SENT:
                String command = TruconnectService.getCommand(intent).toString();
                Log.d(TAG, "Command " + command + " sent");
                break;

            case TruconnectService.ACTION_COMMAND_RESULT:
                break;

            case TruconnectService.ACTION_ERROR:
                TruconnectErrorCode errorCode = TruconnectService.getErrorCode(intent);
                //handle errors
                break;
            }
        }
    };
}

From source file:cn.hbm.superwechat.DemoHXSDKHelper.java

/**
 * ?//from   w w  w  .  j  ava  2  s.c  o  m
 * ?UI???UI???????
 * activityList.size() <= 0 ????????Activity Stack
 */
protected void initEventListener() {
    eventListener = new EMEventListener() {
        private BroadcastReceiver broadCastReceiver = null;

        @Override
        public void onEvent(EMNotifierEvent event) {
            EMMessage message = null;
            if (event.getData() instanceof EMMessage) {
                message = (EMMessage) event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
            }

            switch (event.getEvent()) {
            case EventNewMessage:
                //????UI,????
                if (activityList.size() <= 0) {
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }
                break;
            case EventOfflineMessage:
                if (activityList.size() <= 0) {
                    EMLog.d(TAG, "received offline messages");
                    List<EMMessage> messages = (List<EMMessage>) event.getData();
                    HXSDKHelper.getInstance().getNotifier().onNewMesg(messages);
                }
                break;
            // below is just giving a example to show a cmd toast, the app should not follow this
            // so be careful of this
            case EventNewCMDMessage: {

                EMLog.d(TAG, "??");
                //??body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;//?action

                //? ?
                //message.getStringAttribute("");
                EMLog.d(TAG, String.format("??action:%s,message:%s", action, message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);

                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);

                if (broadCastReceiver == null) {
                    broadCastReceiver = new BroadcastReceiver() {

                        @Override
                        public void onReceive(Context context, Intent intent) {
                            // TODO Auto-generated method stub
                            Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };

                    //
                    appContext.registerReceiver(broadCastReceiver, cmdFilter);
                }

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str + action);
                appContext.sendBroadcast(broadcastIntent, null);

                break;
            }
            case EventDeliveryAck:
                message.setDelivered(true);
                break;
            case EventReadAck:
                message.setAcked(true);
                break;
            // add other events in case you are interested in
            default:
                break;
            }

        }
    };

    EMChatManager.getInstance().registerEventListener(eventListener);

    EMChatManager.getInstance().addChatRoomChangeListener(new EMChatRoomChangeListener() {
        private final static String ROOM_CHANGE_BROADCAST = "easemob.demo.chatroom.changeevent.toast";
        private final IntentFilter filter = new IntentFilter(ROOM_CHANGE_BROADCAST);
        private boolean registered = false;

        private void showToast(String value) {
            if (!registered) {
                //
                appContext.registerReceiver(new BroadcastReceiver() {

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Toast.makeText(appContext, intent.getStringExtra("value"), Toast.LENGTH_SHORT).show();
                    }

                }, filter);

                registered = true;
            }

            Intent broadcastIntent = new Intent(ROOM_CHANGE_BROADCAST);
            broadcastIntent.putExtra("value", value);
            appContext.sendBroadcast(broadcastIntent, null);
        }

        @Override
        public void onChatRoomDestroyed(String roomId, String roomName) {
            showToast(" room : " + roomId + " with room name : " + roomName + " was destroyed");
            Log.i("info", "onChatRoomDestroyed=" + roomName);
        }

        @Override
        public void onMemberJoined(String roomId, String participant) {
            showToast("member : " + participant + " join the room : " + roomId);
            Log.i("info", "onmemberjoined=" + participant);

        }

        @Override
        public void onMemberExited(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " leave the room : " + roomId + " room name : " + roomName);
            Log.i("info", "onMemberExited=" + participant);

        }

        @Override
        public void onMemberKicked(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " was kicked from the room : " + roomId + " room name : "
                    + roomName);
            Log.i("info", "onMemberKicked=" + participant);

        }

    });
}

From source file:com.shengtao.chat.chatUI.DemoHXSDKHelper.java

/**
 * ?/*from   w w  w.  j a  v a  2s.  co m*/
 * ?UI???UI???????
 * activityList.size() <= 0 ????????Activity Stack
 */
protected void initEventListener() {
    eventListener = new EMEventListener() {
        private BroadcastReceiver broadCastReceiver = null;

        @Override
        public void onEvent(EMNotifierEvent event) {
            EMMessage message = null;
            if (event.getData() instanceof EMMessage) {
                message = (EMMessage) event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
            }

            switch (event.getEvent()) {
            case EventNewMessage:
                //????UI,????
                if (activityList.size() <= 0) {
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }
                break;
            case EventOfflineMessage:
                if (activityList.size() <= 0) {
                    EMLog.d(TAG, "received offline messages");
                    List<EMMessage> messages = (List<EMMessage>) event.getData();
                    HXSDKHelper.getInstance().getNotifier().onNewMesg(messages);
                }
                break;
            // below is just giving a example to show a cmd toast, the app should not follow this
            // so be careful of this
            case EventNewCMDMessage: {

                EMLog.d(TAG, "??");
                //??body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;//?action

                //? ?
                //message.getStringAttribute("");
                EMLog.d(TAG, String.format("??action:%s,message:%s", action, message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);

                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);

                if (broadCastReceiver == null) {
                    broadCastReceiver = new BroadcastReceiver() {

                        @Override
                        public void onReceive(Context context, Intent intent) {
                            Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };

                    //
                    appContext.registerReceiver(broadCastReceiver, cmdFilter);
                }

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str + action);
                appContext.sendBroadcast(broadcastIntent, null);

                break;
            }
            case EventDeliveryAck:
                message.setDelivered(true);
                break;
            case EventReadAck:
                message.setAcked(true);
                break;
            // add other events in case you are interested in
            default:
                break;
            }

        }
    };

    EMChatManager.getInstance().registerEventListener(eventListener);

    EMChatManager.getInstance().addChatRoomChangeListener(new EMChatRoomChangeListener() {
        private final static String ROOM_CHANGE_BROADCAST = "easemob.demo.chatroom.changeevent.toast";
        private final IntentFilter filter = new IntentFilter(ROOM_CHANGE_BROADCAST);
        private boolean registered = false;

        private void showToast(String value) {
            if (!registered) {
                //
                appContext.registerReceiver(new BroadcastReceiver() {

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Toast.makeText(appContext, intent.getStringExtra("value"), Toast.LENGTH_SHORT).show();
                    }

                }, filter);

                registered = true;
            }

            Intent broadcastIntent = new Intent(ROOM_CHANGE_BROADCAST);
            broadcastIntent.putExtra("value", value);
            appContext.sendBroadcast(broadcastIntent, null);
        }

        @Override
        public void onChatRoomDestroyed(String roomId, String roomName) {
            showToast(" room : " + roomId + " with room name : " + roomName + " was destroyed");
            Log.i("info", "onChatRoomDestroyed=" + roomName);
        }

        @Override
        public void onMemberJoined(String roomId, String participant) {
            showToast("member : " + participant + " join the room : " + roomId);
            Log.i("info", "onmemberjoined=" + participant);

        }

        @Override
        public void onMemberExited(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " leave the room : " + roomId + " room name : " + roomName);
            Log.i("info", "onMemberExited=" + participant);

        }

        @Override
        public void onMemberKicked(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " was kicked from the room : " + roomId + " room name : "
                    + roomName);
            Log.i("info", "onMemberKicked=" + participant);

        }

    });
}

From source file:com.nextgis.maplibui.activity.AttributesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_attributes);
    setToolbar(R.id.main_toolbar);//from w w  w  .  j  a  v  a2  s.c o  m

    mTable = (TableFixHeaders) findViewById(R.id.attributes);

    mToolbar = (BottomToolbar) findViewById(R.id.bottom_toolbar);
    mToolbar.inflateMenu(R.menu.attributes_table);
    mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int i = item.getItemId();
            if (i == R.id.menu_zoom) {
                IGISApplication application = (IGISApplication) getApplication();
                MapDrawable map = (MapDrawable) application.getMap();
                if (null != map) {
                    if (mLayer.getGeometryType() == GeoConstants.GTPoint
                            || mLayer.getGeometryType() == GeoConstants.GTMultiPoint)
                        map.zoomToExtent(mLayer.getFeature(mId).getGeometry().getEnvelope(), 18);
                    else
                        map.zoomToExtent(mLayer.getFeature(mId).getGeometry().getEnvelope());

                    SharedPreferences.Editor edit = PreferenceManager
                            .getDefaultSharedPreferences(AttributesActivity.this).edit();
                    edit.putFloat(SettingsConstantsUI.KEY_PREF_ZOOM_LEVEL, map.getZoomLevel());
                    GeoPoint point = map.getMapCenter();
                    edit.putLong(SettingsConstantsUI.KEY_PREF_SCROLL_X,
                            Double.doubleToRawLongBits(point.getX()));
                    edit.putLong(SettingsConstantsUI.KEY_PREF_SCROLL_Y,
                            Double.doubleToRawLongBits(point.getY()));
                    edit.commit();
                }

                finish();
                return true;
            } else if (i == R.id.menu_delete) {
                Snackbar snackbar = Snackbar.make(findViewById(R.id.container),
                        getString(R.string.delete_item_done), Snackbar.LENGTH_LONG)
                        .setAction(R.string.undo, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                            }
                        }).setCallback(new Snackbar.Callback() {
                            @Override
                            public void onDismissed(Snackbar snackbar, int event) {
                                super.onDismissed(snackbar, event);
                                if (event == DISMISS_EVENT_MANUAL)
                                    return;
                                if (event != DISMISS_EVENT_ACTION) {
                                    mLayer.deleteAddChanges(mId);
                                }
                            }

                            @Override
                            public void onShown(Snackbar snackbar) {
                                super.onShown(snackbar);
                            }
                        });

                View view = snackbar.getView();
                TextView textView = (TextView) view.findViewById(R.id.snackbar_text);
                textView.setTextColor(
                        ContextCompat.getColor(view.getContext(), com.nextgis.maplibui.R.color.color_white));
                snackbar.show();
                mToolbar.setVisibility(View.GONE);

                return true;
            } else if (i == R.id.menu_edit) {
                ((IVectorLayerUI) mLayer).showEditForm(AttributesActivity.this, mId, null);
                return true;
            }

            return false;
        }
    });
    mToolbar.setNavigationIcon(R.drawable.ic_action_cancel_dark);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbar.setVisibility(View.GONE);
        }
    });
    mToolbar.setVisibility(View.GONE);

    mLayerId = Constants.NOT_FOUND;
    if (savedInstanceState != null)
        mLayerId = savedInstanceState.getInt(ConstantsUI.KEY_LAYER_ID);
    else
        mLayerId = getIntent().getIntExtra(ConstantsUI.KEY_LAYER_ID, mLayerId);

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mTable.setAdapter(getAdapter());
        }
    };
}

From source file:com.aibasis.parent.DemoHXSDKHelper.java

/**
 * ?/*from   w  w  w  .  j  ava  2s .  co  m*/
 * ?UI???UI???????
 * activityList.size() <= 0 ????????Activity Stack
 */
protected void initEventListener() {
    eventListener = new EMEventListener() {
        private BroadcastReceiver broadCastReceiver = null;

        @Override
        public void onEvent(EMNotifierEvent event) {
            EMMessage message = null;
            if (event.getData() instanceof EMMessage) {
                message = (EMMessage) event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
            }

            switch (event.getEvent()) {
            case EventNewMessage:
                //????UI,????
                if (activityList.size() <= 0) {
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }
                break;
            case EventOfflineMessage:
                if (activityList.size() <= 0) {
                    EMLog.d(TAG, "received offline messages");
                    List<EMMessage> messages = (List<EMMessage>) event.getData();
                    HXSDKHelper.getInstance().getNotifier().onNewMesg(messages);
                }
                break;
            // below is just giving a example to show a cmd toast, the app should not follow this
            // so be careful of this
            case EventNewCMDMessage: {

                EMLog.d(TAG, "??");
                //??body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;//?action

                //? ?
                //message.getStringAttribute("");
                EMLog.d(TAG, String.format("??action:%s,message:%s", action, message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);

                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);

                if (broadCastReceiver == null) {
                    broadCastReceiver = new BroadcastReceiver() {

                        @Override
                        public void onReceive(Context context, Intent intent) {
                            // TODO Auto-generated method stub
                            Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };

                    //
                    appContext.registerReceiver(broadCastReceiver, cmdFilter);
                }

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str + action);
                appContext.sendBroadcast(broadcastIntent, null);

                break;
            }
            case EventDeliveryAck:
                message.setDelivered(true);
                break;
            case EventReadAck:
                message.setAcked(true);
                break;
            // add other events in case you are interested in
            default:
                break;
            }

        }
    };

    EMChatManager.getInstance().registerEventListener(eventListener);

    EMChatManager.getInstance().addChatRoomChangeListener(new EMChatRoomChangeListener() {
        private final static String ROOM_CHANGE_BROADCAST = "easemob.demo.chatroom.changeevent.toast";
        private final IntentFilter filter = new IntentFilter(ROOM_CHANGE_BROADCAST);
        private boolean registered = false;

        private void showToast(String value) {
            if (!registered) {
                //
                appContext.registerReceiver(new BroadcastReceiver() {

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Toast.makeText(appContext, intent.getStringExtra("value"), Toast.LENGTH_SHORT).show();
                    }

                }, filter);

                registered = true;
            }

            Intent broadcastIntent = new Intent(ROOM_CHANGE_BROADCAST);
            broadcastIntent.putExtra("value", value);
            appContext.sendBroadcast(broadcastIntent, null);
        }

        @Override
        public void onChatRoomDestroyed(String roomId, String roomName) {
            showToast(" room : " + roomId + " with room name : " + roomName + " was destroyed");
            Log.i("info", "onChatRoomDestroyed=" + roomName);
        }

        @Override
        public void onMemberJoined(String roomId, String participant) {
            showToast("member : " + participant + " join the room : " + roomId);
            Log.i("info", "onmemberjoined=" + participant);
        }

        @Override
        public void onMemberExited(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " leave the room : " + roomId + " room name : " + roomName);
            Log.i("info", "onMemberExited=" + participant);

        }

        @Override
        public void onMemberKicked(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " was kicked from the room : " + roomId + " room name : "
                    + roomName);
            Log.i("info", "onMemberKicked=" + participant);

        }

    });
}