예제 #1
0
 /** 获取消息 若有聊天窗口,则通过广播发送 否则保存到数据库 */
 private void fetchMessages() {
   try {
     List<Message> messages = MessageAPI.queryMessages();
     if (messages == null) return;
     MessageDB messageDB = MessageDB.getInstance(this);
     for (Message message : messages) {
       FriendsDB friendsDB = FriendsDB.getInstance(this);
       FriendProfile friendProfile = friendsDB.findFriend(message.getUsername());
       Session session = new Session();
       session.setUsername(friendProfile.getUsername());
       if (message.getType() == Message.VALUE_LEFT_TEXT) {
         session.setLastWord(message.getText());
       } else if (message.getType() == Message.VALUE_LEFT_IMAGE) {
         session.setLastWord("(图片)");
       }
       LogUtil.i(TAG, "收到!!!!!!!!");
       session.setTime(System.currentTimeMillis());
       SessionDB sessionDB = SessionDB.getInstance(this);
       sessionDB.saveSession(session); // 保存会话
       messageDB.saveMessage(message, "UNREAD"); // 保存消息,未读
       // 当前是主Activity,更新session
       if (MyChatUtility.getRunningActivityName(this)
           .equals("com.gl.mychatclient.activities.MainActivity")) {
         Intent intent = new Intent("com.gl.mychatclient.BROADCAST_UPDATE_SESSION");
         localBroadcastManager.sendBroadcast(intent);
       }
       if (MyChatUtility.getRunningActivityName(this)
           .equals("com.gl.mychatclient.activities.ChatActivity")) { // 当前是聊天Activity
         Intent intent = new Intent("com.gl.mychatclient.BROADCAST_RECEIVE_MESSAGE");
         localBroadcastManager.sendBroadcast(intent);
       } else { // 没开启聊天窗口,则发送通知
         if (message.getType() == Message.VALUE_LEFT_TEXT) {
           Intent intent = new Intent(this, ChatActivity.class);
           intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
           if (friendProfile.getFriendNote() != null)
             intent.putExtra("title", friendProfile.getFriendNote());
           else intent.putExtra("title", friendProfile.getNickname());
           intent.putExtra("username", message.getUsername());
           PendingIntent pendingIntent =
               PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
           int sessionId = sessionDB.findSessionId(friendProfile.getUsername());
           if (friendProfile.getFriendNote() != null) {
             MyChatUtility.sendNotification(
                 this, sessionId, friendProfile.getFriendNote(), message.getText(), pendingIntent);
           } else {
             MyChatUtility.sendNotification(
                 this, sessionId, friendProfile.getNickname(), message.getText(), pendingIntent);
           }
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #2
0
 private void sendBroadcastUpdateLovedOneAfterRemoved(CircleItem mItem) {
   if (mLocalBroadcastManager != null) {
     Intent intent = new Intent(Actions.UPDATE_MY_CIRCLE_OF_LIEF_AFTER_REMOVED);
     intent.putExtra(Extras.ITEM, mItem);
     mLocalBroadcastManager.sendBroadcast(intent);
   }
 }
예제 #3
0
 private void sendBroadcastReadChat() {
   if (mLocalBroadcastManager != null) {
     Intent intent = new Intent(Actions.UPDATE_READ_CHAT_CONVERSATION);
     intent.putExtra(Extras.ID, mItem.getMemberID());
     mLocalBroadcastManager.sendBroadcast(intent);
   }
 }
 @Override
 public void onDismiss(final DialogInterface dialog) {
   final LocalBroadcastManager localBroadcastManager =
       LocalBroadcastManager.getInstance(getActivity());
   localBroadcastManager.sendBroadcast(new Intent(RESET_CLOSE_ACTION));
   super.onDismiss(dialog);
 }
  private void showUploadCancelDialog(boolean abort) {
    final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
    final Intent pauseAction = new Intent(DfuService.BROADCAST_ACTION);
    pauseAction.putExtra(DfuService.EXTRA_ACTION, DfuService.ACTION_PAUSE);
    manager.sendBroadcast(pauseAction);

    if (abort) {

      pauseAction.putExtra(DfuService.EXTRA_ACTION, DfuService.ACTION_ABORT);
      manager.sendBroadcast(pauseAction);
      do {} while (isDfuServiceRunning());
    } else {
      final UploadCancelFragment fragment = UploadCancelFragment.getInstance();
      fragment.show(getSupportFragmentManager(), TAG);
    }
  }
예제 #6
0
  /**
   * Static helper method to send broadcasts to the BaseActivity and enable or disable buttons
   *
   * @param context
   * @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);
  }
  @Override
  public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    String senderId = data.getString("senderId");
    String senderName = data.getString("senderName");
    String caseId = data.getString("caseId");
    caseId = "testCaseId";
    String messageId = data.getString("messageId");
    int typeOfMessage = data.getInt("typeOfMessage");
    new ChatsDb(this).insertChatMessage(caseId, senderId, typeOfMessage, message);

    if (UserChatRoom.broadcastReceiverIsSet
        && UserChatRoom.getChatRoomDetailsReturnContainerCache.caseId.equals(caseId)) {
      Intent intent = new Intent(MyGcmListenerService.MESSAGE_RESULT);
      if (message != null) {
        intent.putExtra(Constants.messageString, message);
        intent.putExtra(Constants.senderNameString, senderName);
        intent.putExtra(Constants.senderIdString, senderId);
        intent.putExtra(Constants.typeOfMessageString, typeOfMessage);
        intent.putExtra(Constants.caseIdString, caseId);
      }

      broadcaster.sendBroadcast(intent);
    } else {
      new AppIdentityDb(this).InsertUpdateResource(AppIdentityDb.newChatMessage + caseId, "1");
      sendNotification(message, senderName, caseId);
    }
  }
 private void finishLogin() {
   RemoteClient remoteClient = m_app.getRemoteClientManager().getRemoteClient();
   remoteClient.finishLogin();
   if (remoteClient.finishLogin() && remoteClient.isAuthenticated()) {
     switchToTodolist();
     localBroadcastManager.sendBroadcast(new Intent(Constants.BROADCAST_START_SYNC_FROM_REMOTE));
   }
 }
  private void sendResult(String message) {
    Intent intent = new Intent(RESULT);
    if (message != null) {
      intent.putExtra(message, message);
      intent.putExtra("isAuth", false);
    }

    broadcaster.sendBroadcast(intent);
  }
예제 #10
0
  /**
   * Static helper method to send broadcasts to the BaseActivity and update status in frontend
   *
   * @param context
   * @param title
   * @param text
   * @param iconStatus Select UPDATE_AVAILABLE, ENABLED, DISABLED, DOWNLOAD_FAIL, or CHECKING from
   *     StatusCodes
   */
  public static void setStatusBroadcast(
      Context context, String title, String text, int iconStatus) {
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);

    Intent intent = new Intent(ACTION_UPDATE_STATUS);
    intent.putExtra(EXTRA_UPDATE_STATUS_ICON, iconStatus);
    intent.putExtra(EXTRA_UPDATE_STATUS_TITLE, title);
    intent.putExtra(EXTRA_UPDATE_STATUS_TEXT, text);
    localBroadcastManager.sendBroadcast(intent);
  }
예제 #11
0
  private void sendServiceBroadcast(String actionExtra, String message) {
    Intent intentSend = new Intent(BROADCAST_NAME).putExtra(Const.ACTION_EXTRA, actionExtra);
    if (message != null) {
      intentSend.putExtra(Const.MESSAGE, message);
    }

    if (broadcastManager != null) {
      broadcastManager.sendBroadcast(intentSend);
    }
  }
  @Override
  protected void onHandleIntent(Intent intent) {

    // Only for test, send a broadcast intent
    Intent mIntent = new Intent();
    mIntent.setAction(Constants.INTENT_ACTION);
    mIntent.putExtra(Constants.INTENT_EXTRA, "Additional info");
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.sendBroadcast(mIntent);
  }
예제 #13
0
  private void broadcastChange() {
    Zup.getInstance().updateSyncAction(this);

    Intent intent = new Intent(SyncAction.ACTION_SYNC_CHANGED);
    intent.putExtra("sync_action", this);

    if (ZupApplication.getContext() == null) return;

    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(ZupApplication.getContext());
    manager.sendBroadcast(intent);
  }
 private void broadcastServiceResult(int status, String message) {
   Intent localIntent = new Intent(BROADCAST_UPLOAD_RESULT);
   localIntent.putExtra("status", status);
   localIntent.putExtra("message", message);
   if (status != STATUS_TRANSACTION_COMPLETE) {
     Log.e(TAG, message);
   } else {
     Log.i(TAG, "Upload Successful");
   }
   mLocalBroadcasterMngr.sendBroadcast(localIntent);
   return;
 }
예제 #15
0
  /**
   * 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(Utility.BROADCAST_ACTION);
    localIntent.putExtra(Utility.EXTENDED_DATA_STATUS, -1);
    localIntent.addCategory(Intent.CATEGORY_DEFAULT);

    // Broadcasts the Intent
    mBroadcaster.sendBroadcast(localIntent);
  }
 /**
  * Broadcasts a new intent with the result of the login and finishes this activity.
  *
  * @param token the received login token, or null if an error happened.
  */
 private void sendBackResult(String token) {
   Intent result = new Intent(ACTION_LOGIN_RESULT);
   if (token == null || token.isEmpty()) {
     result.putExtra(EXTRA_SUCCESS, false);
   } else {
     result.putExtra(EXTRA_SUCCESS, true);
     result.putExtra(EXTRA_TOKEN, token);
   }
   LocalBroadcastManager manager = LocalBroadcastManager.getInstance(SimpleAuthActivity.this);
   manager.sendBroadcast(result);
   finish();
 }
예제 #17
0
파일: Probe.java 프로젝트: benarito/sensor
  protected void transmitData(Context context, Bundle data) {
    if (context != null) {
      UUID uuid = UUID.randomUUID();
      data.putString(Probe.PROBE_GUID, uuid.toString());

      LocalBroadcastManager localManager = LocalBroadcastManager.getInstance(context);
      Intent intent =
          new Intent(edu.northwestern.cbits.purple_robot_manager.probes.Probe.PROBE_READING);
      intent.putExtras(data);

      localManager.sendBroadcast(intent);
    }
  }
예제 #18
0
  /**
   * 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(Utility.BROADCAST_ACTION);

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

    // Broadcasts the Intent
    mBroadcaster.sendBroadcast(localIntent);
  }
예제 #19
0
        @Override
        public void onWalletChanged(Wallet wallet) {
          // Compute balances and transaction counts.
          Iterable<WalletTransaction> iwt = mKit.wallet().getWalletTransactions();
          mHDWallet.applyAllTransactions(iwt);

          // Check to make sure we have sufficient margins.
          int maxExtended = mHDWallet.ensureMargins(mKit.wallet());

          // Persist the new state.
          mHDWallet.persist(mApp);

          Intent intent = new Intent("wallet-state-changed");
          mLBM.sendBroadcast(intent);

          if (maxExtended > HDChain.maxSafeExtend()) {
            mLogger.info(String.format("%d addresses added, rescanning", maxExtended));
            rescanBlockchain(HDAddress.EPOCH);
          }
        }
예제 #20
0
  @Override
  public void onMessageReceived(String from, Bundle data) {
    if (!data.isEmpty()) {
      String message = String.valueOf(data.get(getString(R.string.key_message)));

      Intent messageIntent = new Intent(getString(R.string.intent_message));
      messageIntent.putExtra(getString(R.string.key_message), message);
      messageIntent.putExtra(
          getString(R.string.key_school_id),
          String.valueOf(data.get(getString(R.string.key_school_id))));

      if (message.equals(getString(R.string.key_add_bus))
          || message.equals(getString(R.string.key_remove_bus))) {
        messageIntent.putExtra(
            getString(R.string.key_bus_row),
            String.valueOf(data.get(getString(R.string.key_bus_row))));
        messageIntent.putExtra(
            getString(R.string.key_bus_number),
            String.valueOf(data.get(getString(R.string.key_bus_number))));

        if (message.equals(getString(R.string.key_add_bus))
            && getSharedPreferences(getString(R.string.shared_pref_user), Context.MODE_PRIVATE)
                .getStringSet(
                    String.format(
                        getString(R.string.pref_favorite_bus),
                        String.valueOf(data.get(getString(R.string.key_school_id)))),
                    new HashSet<String>())
                .contains(String.valueOf(data.get(getString(R.string.key_bus_number))))) {
          sendNotification(
              String.valueOf(data.get(getString(R.string.key_school_id))),
              String.valueOf(data.get(getString(R.string.key_bus_row_name))),
              String.valueOf(data.get(getString(R.string.key_bus_number))),
              String.valueOf(data.get(getString(R.string.key_bus_position))));
        }
      }

      mLocalBroadcastManager.sendBroadcast(messageIntent);
    }
    super.onMessageReceived(from, data);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();

    switch (item.getItemId()) {
      case 16908332:
        transaction.remove(this);
        transaction.commit();
        getActivity().setTitle("Dirección de socio de negocio");
        getFragmentManager().popBackStack();

        return true;

      case R.id.action_aceptar:
        if (arguments != null) {

          // MANDAR LOS PARÀMETROS EN LOCALBORADCAST INTENT
          Intent localBroadcastIntent = new Intent("custom-event-get-calle");
          localBroadcastIntent.putExtras(arguments);
          LocalBroadcastManager myLocalBroadcastManager =
              LocalBroadcastManager.getInstance(getActivity());
          myLocalBroadcastManager.sendBroadcast(localBroadcastIntent);

          transaction.remove(this);
          transaction.commit();
          getActivity().setTitle("Dirección de socio de negocio");
          getFragmentManager().popBackStack();

        } else {
          Toast.makeText(contexto, "Seleccione la calle", Toast.LENGTH_LONG).show();
        }

        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }
예제 #22
0
 private void sendBroadcastUpdateProfile() {
   if (mLocalBroadcastManager != null) {
     Intent intent = new Intent(Actions.UPDATE_USER_PROFILE);
     mLocalBroadcastManager.sendBroadcast(intent);
   }
 }
예제 #23
0
 private void sendStateChanged() {
   Intent intent = new Intent("wallet-state-changed");
   mLBM.sendBroadcast(intent);
 }
예제 #24
0
 private void sendReloadBroadcast() {
   final LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(mContext);
   final Intent reloadIntent = new Intent(RELOAD_BROADCAST);
   lbm.sendBroadcast(reloadIntent);
 }
예제 #25
0
 private void sendLocalBroadcast() {
   localManager.sendBroadcast(new Intent("com.lovexiaov.learnfromzero.ACTION_LOCAL_CUSTOM"));
 }
예제 #26
0
 private void enviarBroadcast() {
   Intent intentRespuesta = new Intent(REPRODUCIENDO_ACTION);
   intentRespuesta.putExtra(INDICE_CANCION, cancionActual);
   LocalBroadcastManager gestor = LocalBroadcastManager.getInstance(this);
   gestor.sendBroadcast(intentRespuesta);
 }
예제 #27
0
 private void sendBroadCastSendSmsFailedOutOfFree() {
   if (mLocalBroadcastManager != null) {
     Intent intent = new Intent(Actions.SHOW_ALERT_SEND_SMS_FAILED_OUT_OF_FREE_SMS);
     mLocalBroadcastManager.sendBroadcast(intent);
   }
 }
예제 #28
0
 private void sendBroadCastSendSmsFailedWrongNumber() {
   if (mLocalBroadcastManager != null) {
     Intent intent = new Intent(Actions.SHOW_ALERT_SEND_SMS_FAILED_WRONG_NUMBER);
     mLocalBroadcastManager.sendBroadcast(intent);
   }
 }