List of usage examples for android.app NotificationManager cancelAll
public void cancelAll()
From source file:com.wondertoys.pokevalue.utils.AutoUpdateApk.java
protected void raise_notification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { setChanged();/*from w w w . j a v a 2 s .c o m*/ notifyObservers(AUTOUPDATE_HAVE_UPDATE); // raise the notification CharSequence contentTitle = appName + " update available"; CharSequence contentText = "Select to install"; Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType(Uri.parse( "file://" + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + update_file), ANDROID_PACKAGE); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); builder.setSmallIcon(appIcon); builder.setTicker(appName + " update"); builder.setContentTitle(contentTitle); builder.setContentText(contentText); builder.setContentIntent(contentIntent); builder.setWhen(System.currentTimeMillis()); builder.setAutoCancel(true); builder.setOngoing(true); nm.notify(NOTIFICATION_ID, builder.build()); } else { //nm.cancel( NOTIFICATION_ID ); // tried this, but it just doesn't do the trick =( nm.cancelAll(); } }
From source file:org.matrix.console.activity.RoomActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Intent intent = getIntent();//from www .ja va2 s. c o m if (CommonActivityUtils.shouldRestartApp()) { if (intent.hasExtra(EXTRA_START_FROM_PUSH)) { Log.e(LOG_TAG, "Room activity is started from push but the application should be restarted"); } else { Log.e(LOG_TAG, "Restart the application."); CommonActivityUtils.restartApp(this); } } super.onCreate(savedInstanceState); setContentView(R.layout.activity_room); if (!intent.hasExtra(EXTRA_ROOM_ID)) { Log.e(LOG_TAG, "No room ID extra."); finish(); return; } if (intent.hasExtra(EXTRA_START_CALL_ID)) { mCallId = intent.getStringExtra(EXTRA_START_CALL_ID); } // the user has tapped on the "View" notification button if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) { // remove any pending notifications NotificationManager notificationsManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationsManager.cancelAll(); } mPendingThumbnailUrl = null; mPendingMediaUrl = null; mPendingMimeType = null; mPendingFilename = null; if (null != savedInstanceState) { if (savedInstanceState.containsKey(PENDING_THUMBNAIL_URL)) { mPendingThumbnailUrl = savedInstanceState.getString(PENDING_THUMBNAIL_URL); Log.d(LOG_TAG, "Restore mPendingThumbnailUrl " + mPendingThumbnailUrl); } if (savedInstanceState.containsKey(PENDING_MEDIA_URL)) { mPendingMediaUrl = savedInstanceState.getString(PENDING_MEDIA_URL); Log.d(LOG_TAG, "Restore mPendingMediaUrl " + mPendingMediaUrl); } if (savedInstanceState.containsKey(PENDING_MIMETYPE)) { mPendingMimeType = savedInstanceState.getString(PENDING_MIMETYPE); Log.d(LOG_TAG, "Restore mPendingMimeType " + mPendingMimeType); } if (savedInstanceState.containsKey(PENDING_FILENAME)) { mPendingFilename = savedInstanceState.getString(PENDING_FILENAME); Log.d(LOG_TAG, "Restore mPendingFilename " + mPendingFilename); } } String roomId = intent.getStringExtra(EXTRA_ROOM_ID); Log.i(LOG_TAG, "Displaying " + roomId); mEditText = (EditText) findViewById(R.id.editText_messageBox); mSendButton = (ImageButton) findViewById(R.id.button_send); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // send the previewed image ? if (null != mPendingThumbnailUrl) { boolean sendMedia = true; // check if the media could be resized if ("image/jpeg".equals(mPendingMimeType)) { System.gc(); FileInputStream imageStream = null; try { Uri uri = Uri.parse(mPendingMediaUrl); final String filename = uri.getPath(); final int rotationAngle = ImageUtils.getRotationAngleForBitmap(RoomActivity.this, uri); imageStream = new FileInputStream(new File(filename)); int fileSize = imageStream.available(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.outWidth = -1; options.outHeight = -1; // get the full size bitmap Bitmap fullSizeBitmap = null; try { fullSizeBitmap = BitmapFactory.decodeStream(imageStream, null, options); } catch (OutOfMemoryError e) { Log.e(LOG_TAG, "Onclick BitmapFactory.decodeStream : " + e.getMessage()); } final ImageSize fullImageSize = new ImageSize(options.outWidth, options.outHeight); imageStream.close(); int maxSide = (fullImageSize.mHeight > fullImageSize.mWidth) ? fullImageSize.mHeight : fullImageSize.mWidth; // can be rescaled ? if (maxSide > SMALL_IMAGE_SIZE) { ImageSize largeImageSize = null; int divider = 2; if (maxSide > LARGE_IMAGE_SIZE) { largeImageSize = new ImageSize((fullImageSize.mWidth + (divider - 1)) / divider, (fullImageSize.mHeight + (divider - 1)) / divider); divider *= 2; } ImageSize mediumImageSize = null; if (maxSide > MEDIUM_IMAGE_SIZE) { mediumImageSize = new ImageSize( (fullImageSize.mWidth + (divider - 1)) / divider, (fullImageSize.mHeight + (divider - 1)) / divider); divider *= 2; } ImageSize smallImageSize = null; if (maxSide > SMALL_IMAGE_SIZE) { smallImageSize = new ImageSize((fullImageSize.mWidth + (divider - 1)) / divider, (fullImageSize.mHeight + (divider - 1)) / divider); } FragmentManager fm = getSupportFragmentManager(); ImageSizeSelectionDialogFragment fragment = (ImageSizeSelectionDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_IMAGE_SIZE_DIALOG); if (fragment != null) { fragment.dismissAllowingStateLoss(); } final ArrayList<ImageCompressionDescription> textsList = new ArrayList<ImageCompressionDescription>(); final ArrayList<ImageSize> sizesList = new ArrayList<ImageSize>(); ImageCompressionDescription description = new ImageCompressionDescription(); description.mCompressionText = getString(R.string.compression_opt_list_original); description.mCompressionInfoText = fullImageSize.mWidth + "x" + fullImageSize.mHeight + " (" + android.text.format.Formatter.formatFileSize(RoomActivity.this, fileSize) + ")"; textsList.add(description); sizesList.add(fullImageSize); if (null != largeImageSize) { int estFileSize = largeImageSize.mWidth * largeImageSize.mHeight * 2 / 10 / 1024 * 1024; description = new ImageCompressionDescription(); description.mCompressionText = getString(R.string.compression_opt_list_large); description.mCompressionInfoText = largeImageSize.mWidth + "x" + largeImageSize.mHeight + " (~" + android.text.format.Formatter .formatFileSize(RoomActivity.this, estFileSize) + ")"; textsList.add(description); sizesList.add(largeImageSize); } if (null != mediumImageSize) { int estFileSize = mediumImageSize.mWidth * mediumImageSize.mHeight * 2 / 10 / 1024 * 1024; description = new ImageCompressionDescription(); description.mCompressionText = getString(R.string.compression_opt_list_medium); description.mCompressionInfoText = mediumImageSize.mWidth + "x" + mediumImageSize.mHeight + " (~" + android.text.format.Formatter .formatFileSize(RoomActivity.this, estFileSize) + ")"; textsList.add(description); sizesList.add(mediumImageSize); } if (null != smallImageSize) { int estFileSize = smallImageSize.mWidth * smallImageSize.mHeight * 2 / 10 / 1024 * 1024; description = new ImageCompressionDescription(); description.mCompressionText = getString(R.string.compression_opt_list_small); description.mCompressionInfoText = smallImageSize.mWidth + "x" + smallImageSize.mHeight + " (~" + android.text.format.Formatter .formatFileSize(RoomActivity.this, estFileSize) + ")"; textsList.add(description); sizesList.add(smallImageSize); } fragment = ImageSizeSelectionDialogFragment.newInstance(textsList); fragment.setListener(new ImageSizeSelectionDialogFragment.ImageSizeListener() { @Override public void onSelected(int pos) { final int fPos = pos; RoomActivity.this.runOnUiThread(new Runnable() { @Override public void run() { try { // pos == 0 -> original if (0 != fPos) { FileInputStream imageStream = new FileInputStream( new File(filename)); ImageSize imageSize = sizesList.get(fPos); InputStream resizeBitmapStream = null; try { resizeBitmapStream = ImageUtils.resizeImage(imageStream, -1, (fullImageSize.mWidth + imageSize.mWidth - 1) / imageSize.mWidth, 75); } catch (OutOfMemoryError ex) { Log.e(LOG_TAG, "Onclick BitmapFactory.createScaledBitmap : " + ex.getMessage()); } catch (Exception e) { Log.e(LOG_TAG, "Onclick BitmapFactory.createScaledBitmap failed : " + e.getMessage()); } if (null != resizeBitmapStream) { String bitmapURL = mMediasCache.saveMedia( resizeBitmapStream, null, "image/jpeg"); if (null != bitmapURL) { mPendingMediaUrl = bitmapURL; } resizeBitmapStream.close(); // try to apply exif rotation if (0 != rotationAngle) { // rotate the image content ImageUtils.rotateImage(RoomActivity.this, mPendingMediaUrl, rotationAngle, mMediasCache); } } } } catch (Exception e) { Log.e(LOG_TAG, "Onclick " + e.getMessage()); } // mConsoleMessageListFragment.uploadImageContent(mPendingThumbnailUrl, mPendingMediaUrl, mPendingFilename, mPendingMimeType); mPendingThumbnailUrl = null; mPendingMediaUrl = null; mPendingMimeType = null; mPendingFilename = null; manageSendMoreButtons(); } }); } }); fragment.show(fm, TAG_FRAGMENT_IMAGE_SIZE_DIALOG); sendMedia = false; } } catch (Exception e) { Log.e(LOG_TAG, "Onclick " + e.getMessage()); } } if (sendMedia) { mConsoleMessageListFragment.uploadImageContent(mPendingThumbnailUrl, mPendingMediaUrl, mPendingFilename, mPendingMimeType); mPendingThumbnailUrl = null; mPendingMediaUrl = null; mPendingMimeType = null; mPendingFilename = null; manageSendMoreButtons(); } } else { String body = mEditText.getText().toString(); sendMessage(body); mEditText.setText(""); } } }); mAttachmentButton = (ImageButton) findViewById(R.id.button_more); mAttachmentButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FragmentManager fm = getSupportFragmentManager(); IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG); if (fragment != null) { fragment.dismissAllowingStateLoss(); } final Integer[] messages = new Integer[] { R.string.option_send_files, R.string.option_take_photo, R.string.option_take_video }; final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files R.drawable.ic_material_camera, // R.string.action_members R.drawable.ic_material_videocam, // R.string.action_members }; fragment = IconAndTextDialogFragment.newInstance(icons, messages); fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() { @Override public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) { Integer selectedVal = messages[position]; if (selectedVal == R.string.option_send_files) { RoomActivity.this.launchFileSelectionIntent(); } else if (selectedVal == R.string.option_take_photo) { RoomActivity.this.launchCamera(); } else if (selectedVal == R.string.option_take_video) { RoomActivity.this.launchVideo(); } } }); fragment.show(fm, TAG_FRAGMENT_INVITATION_MEMBERS_DIALOG); } }); mEditText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(android.text.Editable s) { MXLatestChatMessageCache latestChatMessageCache = RoomActivity.this.mLatestChatMessageCache; String textInPlace = latestChatMessageCache.getLatestText(RoomActivity.this, mRoom.getRoomId()); // check if there is really an update // avoid useless updates (initializations..) if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) { latestChatMessageCache.updateLatestMessage(RoomActivity.this, mRoom.getRoomId(), mEditText.getText().toString()); handleTypingNotification(mEditText.getText().length() != 0); } manageSendMoreButtons(); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mSession = getSession(intent); if (mSession == null) { Log.e(LOG_TAG, "No MXSession."); finish(); return; } mMyUserId = mSession.getCredentials().userId; CommonActivityUtils.resumeEventStream(this); mRoom = mSession.getDataHandler().getRoom(roomId); FragmentManager fm = getSupportFragmentManager(); mConsoleMessageListFragment = (ConsoleMessageListFragment) fm .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST); if (mConsoleMessageListFragment == null) { // this fragment displays messages and handles all message logic mConsoleMessageListFragment = ConsoleMessageListFragment.newInstance(mMyUserId, mRoom.getRoomId(), org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment); fm.beginTransaction().add(R.id.anchor_fragment_messages, mConsoleMessageListFragment, TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit(); } // set general room information setTitle(mRoom.getName(mMyUserId)); setTopic(mRoom.getTopic()); mImagePreviewLayout = findViewById(R.id.room_image_preview_layout); mImagePreviewView = (ImageView) findViewById(R.id.room_image_preview); mImagePreviewButton = (ImageButton) findViewById(R.id.room_image_preview_cancel_button); // the user cancels the image selection mImagePreviewButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mPendingThumbnailUrl = null; mPendingMediaUrl = null; mPendingMimeType = null; mPendingFilename = null; manageSendMoreButtons(); } }); mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache(); mMediasCache = Matrix.getInstance(this).getMediasCache(); // some medias must be sent while opening the chat if (intent.hasExtra(HomeActivity.EXTRA_ROOM_INTENT)) { final Intent mediaIntent = intent.getParcelableExtra(HomeActivity.EXTRA_ROOM_INTENT); // sanity check if (null != mediaIntent) { mEditText.postDelayed(new Runnable() { @Override public void run() { sendMediasIntent(mediaIntent); } }, 1000); } } }
From source file:im.vector.activity.VectorRoomActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vector_room); if (CommonActivityUtils.shouldRestartApp(this)) { Log.e(LOG_TAG, "onCreate : Restart the application."); CommonActivityUtils.restartApp(this); return;/* ww w. j a v a 2 s. com*/ } final Intent intent = getIntent(); if (!intent.hasExtra(EXTRA_ROOM_ID)) { Log.e(LOG_TAG, "No room ID extra."); finish(); return; } mSession = getSession(intent); if (mSession == null) { Log.e(LOG_TAG, "No MXSession."); finish(); return; } String roomId = intent.getStringExtra(EXTRA_ROOM_ID); // ensure that the preview mode is really expected if (!intent.hasExtra(EXTRA_ROOM_PREVIEW_ID)) { sRoomPreviewData = null; Matrix.getInstance(this).clearTmpStoresList(); } if (CommonActivityUtils.isGoingToSplash(this, mSession.getMyUserId(), roomId)) { Log.d(LOG_TAG, "onCreate : Going to splash screen"); return; } // bind the widgets of the room header view. The room header view is displayed by // clicking on the title of the action bar mRoomHeaderView = (RelativeLayout) findViewById(R.id.action_bar_header); mActionBarHeaderRoomTopic = (TextView) findViewById(R.id.action_bar_header_room_topic); mActionBarHeaderRoomName = (TextView) findViewById(R.id.action_bar_header_room_title); mActionBarHeaderActiveMembers = (TextView) findViewById(R.id.action_bar_header_room_members); mActionBarHeaderRoomAvatar = (ImageView) mRoomHeaderView.findViewById(R.id.avatar_img); mActionBarHeaderInviteMemberView = mRoomHeaderView.findViewById(R.id.action_bar_header_invite_members); mRoomPreviewLayout = findViewById(R.id.room_preview_info_layout); mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.room_pending_call_view); mVectorOngoingConferenceCallView = (VectorOngoingConferenceCallView) findViewById( R.id.room_ongoing_conference_call_view); // hide the header room as soon as the bottom layout (text edit zone) is touched findViewById(R.id.room_bottom_layout).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); return false; } }); // use a toolbar instead of the actionbar // to be able to display an expandable header mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.room_toolbar); this.setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // set the default custom action bar layout, // that will be displayed from the custom action bar layout setActionBarDefaultCustomLayout(); mCallId = intent.getStringExtra(EXTRA_START_CALL_ID); mEventId = intent.getStringExtra(EXTRA_EVENT_ID); mDefaultRoomName = intent.getStringExtra(EXTRA_DEFAULT_NAME); mDefaultTopic = intent.getStringExtra(EXTRA_DEFAULT_TOPIC); // the user has tapped on the "View" notification button if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) { // remove any pending notifications NotificationManager notificationsManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationsManager.cancelAll(); } Log.d(LOG_TAG, "Displaying " + roomId); mEditText = (EditText) findViewById(R.id.editText_messageBox); // hide the header room as soon as the message input text area is touched mEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); } }); // IME's DONE button is treated as a send action mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { int imeActionId = actionId & EditorInfo.IME_MASK_ACTION; if (EditorInfo.IME_ACTION_DONE == imeActionId) { sendTextMessage(); } return false; } }); mSendingMessagesLayout = findViewById(R.id.room_sending_message_layout); mSendImageView = (ImageView) findViewById(R.id.room_send_image_view); mSendButtonLayout = findViewById(R.id.room_send_layout); mSendButtonLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(mEditText.getText())) { sendTextMessage(); } else { // hide the header room enableActionBarHeader(HIDE_ACTION_BAR_HEADER); FragmentManager fm = getSupportFragmentManager(); IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG); if (fragment != null) { fragment.dismissAllowingStateLoss(); } final Integer[] messages = new Integer[] { R.string.option_send_files, R.string.option_take_photo, }; final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files R.drawable.ic_material_camera, // R.string.option_take_photo }; fragment = IconAndTextDialogFragment.newInstance(icons, messages, null, ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_text_black_color)); fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() { @Override public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) { Integer selectedVal = messages[position]; if (selectedVal == R.string.option_send_files) { VectorRoomActivity.this.launchFileSelectionIntent(); } else if (selectedVal == R.string.option_take_photo) { if (CommonActivityUtils.checkPermissions( CommonActivityUtils.REQUEST_CODE_PERMISSION_TAKE_PHOTO, VectorRoomActivity.this)) { launchCamera(); } } } }); fragment.show(fm, TAG_FRAGMENT_ATTACHMENTS_DIALOG); } } }); mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(android.text.Editable s) { if (null != mRoom) { MXLatestChatMessageCache latestChatMessageCache = VectorRoomActivity.this.mLatestChatMessageCache; String textInPlace = latestChatMessageCache.getLatestText(VectorRoomActivity.this, mRoom.getRoomId()); // check if there is really an update // avoid useless updates (initializations..) if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) { latestChatMessageCache.updateLatestMessage(VectorRoomActivity.this, mRoom.getRoomId(), mEditText.getText().toString()); handleTypingNotification(mEditText.getText().length() != 0); } manageSendMoreButtons(); refreshCallButtons(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mVectorPendingCallView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = VectorCallViewActivity.getActiveCall(); if (null != call) { final Intent intent = new Intent(VectorRoomActivity.this, VectorCallViewActivity.class); intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID, call.getSession().getCredentials().userId); intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId()); VectorRoomActivity.this.runOnUiThread(new Runnable() { @Override public void run() { VectorRoomActivity.this.startActivity(intent); } }); } else { // if the call is no more active, just remove the view mVectorPendingCallView.onCallTerminated(); } } }); mActionBarHeaderInviteMemberView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { launchRoomDetails(VectorRoomDetailsActivity.PEOPLE_TAB_INDEX); } }); // notifications area mNotificationsArea = findViewById(R.id.room_notifications_area); mNotificationIconImageView = (ImageView) mNotificationsArea.findViewById(R.id.room_notification_icon); mNotificationTextView = (TextView) mNotificationsArea.findViewById(R.id.room_notification_message); mCanNotPostTextView = findViewById(R.id.room_cannot_post_textview); mStartCallLayout = findViewById(R.id.room_start_call_layout); mStartCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isUserAllowedToStartConfCall()) { displayVideoCallIpDialog(); } else { displayConfCallNotAllowed(); } } }); mStopCallLayout = findViewById(R.id.room_end_call_layout); mStopCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = mSession.mCallsManager.getCallWithRoomId(mRoom.getRoomId()); if (null != call) { call.hangup(null); } } }); mMyUserId = mSession.getCredentials().userId; CommonActivityUtils.resumeEventStream(this); mRoom = mSession.getDataHandler().getRoom(roomId, false); FragmentManager fm = getSupportFragmentManager(); mVectorMessageListFragment = (VectorMessageListFragment) fm .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST); if (mVectorMessageListFragment == null) { Log.d(LOG_TAG, "Create VectorMessageListFragment"); // this fragment displays messages and handles all message logic mVectorMessageListFragment = VectorMessageListFragment.newInstance(mMyUserId, roomId, mEventId, (null == sRoomPreviewData) ? null : VectorMessageListFragment.PREVIEW_MODE_READ_ONLY, org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment); fm.beginTransaction().add(R.id.anchor_fragment_messages, mVectorMessageListFragment, TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit(); } else { Log.d(LOG_TAG, "Reuse VectorMessageListFragment"); } mVectorRoomMediasSender = new VectorRoomMediasSender(this, mVectorMessageListFragment, Matrix.getInstance(this).getMediasCache()); mVectorRoomMediasSender.onRestoreInstanceState(savedInstanceState); manageRoomPreview(); addRoomHeaderClickListeners(); // in timeline mode (i.e search in the forward and backward room history) // or in room preview mode // the edition items are not displayed if (!TextUtils.isEmpty(mEventId) || (null != sRoomPreviewData)) { mNotificationsArea.setVisibility(View.GONE); findViewById(R.id.bottom_separator).setVisibility(View.GONE); findViewById(R.id.room_notification_separator).setVisibility(View.GONE); findViewById(R.id.room_notifications_area).setVisibility(View.GONE); View v = findViewById(R.id.room_bottom_layout); ViewGroup.LayoutParams params = v.getLayoutParams(); params.height = 0; v.setLayoutParams(params); } mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache(); // some medias must be sent while opening the chat if (intent.hasExtra(EXTRA_ROOM_INTENT)) { final Intent mediaIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT); // sanity check if (null != mediaIntent) { mEditText.postDelayed(new Runnable() { @Override public void run() { intent.removeExtra(EXTRA_ROOM_INTENT); sendMediasIntent(mediaIntent); } }, 1000); } } mVectorOngoingConferenceCallView.initRoomInfo(mSession, mRoom); mVectorOngoingConferenceCallView .setCallClickListener(new VectorOngoingConferenceCallView.ICallClickListener() { private void startCall(boolean isVideo) { if (CommonActivityUtils.checkPermissions( isVideo ? CommonActivityUtils.REQUEST_CODE_PERMISSION_VIDEO_IP_CALL : CommonActivityUtils.REQUEST_CODE_PERMISSION_AUDIO_IP_CALL, VectorRoomActivity.this)) { startIpCall(isVideo); } } @Override public void onVoiceCallClick() { startCall(false); } @Override public void onVideoCallClick() { startCall(true); } }); View avatarLayout = findViewById(R.id.room_self_avatar); if (null != avatarLayout) { mAvatarImageView = (ImageView) avatarLayout.findViewById(R.id.avatar_img); } refreshSelfAvatar(); // in case a "Send as" dialog was in progress when the activity was destroyed (life cycle) mVectorRoomMediasSender.resumeResizeMediaAndSend(); // header visibility has launched enableActionBarHeader(intent.getBooleanExtra(EXTRA_EXPAND_ROOM_HEADER, false) ? SHOW_ACTION_BAR_HEADER : HIDE_ACTION_BAR_HEADER); // the both flags are only used once intent.removeExtra(EXTRA_EXPAND_ROOM_HEADER); Log.d(LOG_TAG, "End of create"); }
From source file:im.neon.activity.VectorRoomActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vector_room); if (CommonActivityUtils.shouldRestartApp(this)) { Log.e(LOG_TAG, "onCreate : Restart the application."); CommonActivityUtils.restartApp(this); return;/* w w w .j a va2s .co m*/ } final Intent intent = getIntent(); if (!intent.hasExtra(EXTRA_ROOM_ID)) { Log.e(LOG_TAG, "No room ID extra."); finish(); return; } mSession = MXCActionBarActivity.getSession(this, intent); if (mSession == null) { Log.e(LOG_TAG, "No MXSession."); finish(); return; } String roomId = intent.getStringExtra(EXTRA_ROOM_ID); // ensure that the preview mode is really expected if (!intent.hasExtra(EXTRA_ROOM_PREVIEW_ID)) { sRoomPreviewData = null; Matrix.getInstance(this).clearTmpStoresList(); } if (CommonActivityUtils.isGoingToSplash(this, mSession.getMyUserId(), roomId)) { Log.d(LOG_TAG, "onCreate : Going to splash screen"); return; } //setDragEdge(SwipeBackLayout.DragEdge.LEFT); // bind the widgets of the room header view. The room header view is displayed by // clicking on the title of the action bar mRoomHeaderView = (RelativeLayout) findViewById(R.id.action_bar_header); mActionBarHeaderRoomTopic = (TextView) findViewById(R.id.action_bar_header_room_topic); mActionBarHeaderRoomName = (TextView) findViewById(R.id.action_bar_header_room_title); mActionBarHeaderActiveMembers = (TextView) findViewById(R.id.action_bar_header_room_members); mActionBarHeaderRoomAvatar = (ImageView) mRoomHeaderView.findViewById(R.id.avatar_img); mActionBarHeaderInviteMemberView = mRoomHeaderView.findViewById(R.id.action_bar_header_invite_members); mRoomPreviewLayout = findViewById(R.id.room_preview_info_layout); mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.room_pending_call_view); mVectorOngoingConferenceCallView = (VectorOngoingConferenceCallView) findViewById( R.id.room_ongoing_conference_call_view); mE2eImageView = (ImageView) findViewById(R.id.room_encrypted_image_view); // hide the header room as soon as the bottom layout (text edit zone) is touched findViewById(R.id.room_bottom_layout).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); return false; } }); // use a toolbar instead of the actionbar // to be able to display an expandable header mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.room_toolbar); this.setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // set the default custom action bar layout, // that will be displayed from the custom action bar layout setActionBarDefaultCustomLayout(); mCallId = intent.getStringExtra(EXTRA_START_CALL_ID); mEventId = intent.getStringExtra(EXTRA_EVENT_ID); mDefaultRoomName = intent.getStringExtra(EXTRA_DEFAULT_NAME); mDefaultTopic = intent.getStringExtra(EXTRA_DEFAULT_TOPIC); // the user has tapped on the "View" notification button if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) { // remove any pending notifications NotificationManager notificationsManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationsManager.cancelAll(); } Log.d(LOG_TAG, "Displaying " + roomId); mEditText = (EditText) findViewById(R.id.editText_messageBox); // hide the header room as soon as the message input text area is touched mEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { enableActionBarHeader(HIDE_ACTION_BAR_HEADER); } }); // IME's DONE button is treated as a send action mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { int imeActionId = actionId & EditorInfo.IME_MASK_ACTION; if (EditorInfo.IME_ACTION_DONE == imeActionId) { sendTextMessage(); } return false; } }); mSendingMessagesLayout = findViewById(R.id.room_sending_message_layout); mSendImageView = (ImageView) findViewById(R.id.room_send_image_view); mSendButtonLayout = findViewById(R.id.room_send_layout); mSendButtonLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!TextUtils.isEmpty(mEditText.getText())) { sendTextMessage(); } else { // hide the header room enableActionBarHeader(HIDE_ACTION_BAR_HEADER); FragmentManager fm = getSupportFragmentManager(); IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG); if (fragment != null) { fragment.dismissAllowingStateLoss(); } final Integer[] messages = new Integer[] { R.string.option_send_files, R.string.option_take_photo_video, }; final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files R.drawable.ic_material_camera, // R.string.option_take_photo }; fragment = IconAndTextDialogFragment.newInstance(icons, messages, null, ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_text_black_color)); fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() { @Override public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) { Integer selectedVal = messages[position]; if (selectedVal == R.string.option_send_files) { VectorRoomActivity.this.launchFileSelectionIntent(); } else if (selectedVal == R.string.option_take_photo_video) { if (CommonActivityUtils.checkPermissions( CommonActivityUtils.REQUEST_CODE_PERMISSION_TAKE_PHOTO, VectorRoomActivity.this)) { launchCamera(); } } } }); fragment.show(fm, TAG_FRAGMENT_ATTACHMENTS_DIALOG); } } }); mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(android.text.Editable s) { if (null != mRoom) { MXLatestChatMessageCache latestChatMessageCache = VectorRoomActivity.this.mLatestChatMessageCache; String textInPlace = latestChatMessageCache.getLatestText(VectorRoomActivity.this, mRoom.getRoomId()); // check if there is really an update // avoid useless updates (initializations..) if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) { latestChatMessageCache.updateLatestMessage(VectorRoomActivity.this, mRoom.getRoomId(), mEditText.getText().toString()); handleTypingNotification(mEditText.getText().length() != 0); } manageSendMoreButtons(); refreshCallButtons(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mVectorPendingCallView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = VectorCallViewActivity.getActiveCall(); if (null != call) { final Intent intent = new Intent(VectorRoomActivity.this, VectorCallViewActivity.class); intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID, call.getSession().getCredentials().userId); intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId()); VectorRoomActivity.this.runOnUiThread(new Runnable() { @Override public void run() { VectorRoomActivity.this.startActivity(intent); } }); } else { // if the call is no more active, just remove the view mVectorPendingCallView.onCallTerminated(); } } }); mActionBarHeaderInviteMemberView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { launchRoomDetails(VectorRoomDetailsActivity.PEOPLE_TAB_INDEX); } }); // notifications area mNotificationsArea = findViewById(R.id.room_notifications_area); mNotificationIconImageView = (ImageView) mNotificationsArea.findViewById(R.id.room_notification_icon); mNotificationTextView = (TextView) mNotificationsArea.findViewById(R.id.room_notification_message); mCanNotPostTextView = findViewById(R.id.room_cannot_post_textview); // increase the clickable area to open the keyboard. // when there is no text, it is quite small and some user thought the edition was disabled. findViewById(R.id.room_sending_message_layout).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mEditText.requestFocus()) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT); } } }); mStartCallLayout = findViewById(R.id.room_start_call_layout); mStartCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if ((null != mRoom) && mRoom.isEncrypted() && (mRoom.getActiveMembers().size() > 2)) { // display the dialog with the info text AlertDialog.Builder permissionsInfoDialog = new AlertDialog.Builder(VectorRoomActivity.this); Resources resource = getResources(); permissionsInfoDialog .setMessage(resource.getString(R.string.room_no_conference_call_in_encrypted_rooms)); permissionsInfoDialog.setIcon(android.R.drawable.ic_dialog_alert); permissionsInfoDialog.setPositiveButton(resource.getString(R.string.ok), null); permissionsInfoDialog.show(); } else if (isUserAllowedToStartConfCall()) { displayVideoCallIpDialog(); } else { displayConfCallNotAllowed(); } } }); mStopCallLayout = findViewById(R.id.room_end_call_layout); mStopCallLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IMXCall call = mSession.mCallsManager.getCallWithRoomId(mRoom.getRoomId()); if (null != call) { call.hangup(null); } } }); findViewById(R.id.room_button_margin_right).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // extend the right side of right button // to avoid clicking in the void if (mStopCallLayout.getVisibility() == View.VISIBLE) { mStopCallLayout.performClick(); } else if (mStartCallLayout.getVisibility() == View.VISIBLE) { mStartCallLayout.performClick(); } else if (mSendButtonLayout.getVisibility() == View.VISIBLE) { mSendButtonLayout.performClick(); } } }); mMyUserId = mSession.getCredentials().userId; CommonActivityUtils.resumeEventStream(this); mRoom = mSession.getDataHandler().getRoom(roomId, false); FragmentManager fm = getSupportFragmentManager(); mVectorMessageListFragment = (VectorMessageListFragment) fm .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST); if (mVectorMessageListFragment == null) { Log.d(LOG_TAG, "Create VectorMessageListFragment"); // this fragment displays messages and handles all message logic mVectorMessageListFragment = VectorMessageListFragment.newInstance(mMyUserId, roomId, mEventId, (null == sRoomPreviewData) ? null : VectorMessageListFragment.PREVIEW_MODE_READ_ONLY, org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment); fm.beginTransaction().add(R.id.anchor_fragment_messages, mVectorMessageListFragment, TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit(); } else { Log.d(LOG_TAG, "Reuse VectorMessageListFragment"); } mVectorRoomMediasSender = new VectorRoomMediasSender(this, mVectorMessageListFragment, Matrix.getInstance(this).getMediasCache()); mVectorRoomMediasSender.onRestoreInstanceState(savedInstanceState); manageRoomPreview(); addRoomHeaderClickListeners(); // in timeline mode (i.e search in the forward and backward room history) // or in room preview mode // the edition items are not displayed if (!TextUtils.isEmpty(mEventId) || (null != sRoomPreviewData)) { mNotificationsArea.setVisibility(View.GONE); findViewById(R.id.bottom_separator).setVisibility(View.GONE); findViewById(R.id.room_notification_separator).setVisibility(View.GONE); findViewById(R.id.room_notifications_area).setVisibility(View.GONE); View v = findViewById(R.id.room_bottom_layout); ViewGroup.LayoutParams params = v.getLayoutParams(); params.height = 0; v.setLayoutParams(params); } mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache(); // some medias must be sent while opening the chat if (intent.hasExtra(EXTRA_ROOM_INTENT)) { final Intent mediaIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT); // sanity check if (null != mediaIntent) { mEditText.postDelayed(new Runnable() { @Override public void run() { intent.removeExtra(EXTRA_ROOM_INTENT); sendMediasIntent(mediaIntent); } }, 1000); } } mVectorOngoingConferenceCallView.initRoomInfo(mSession, mRoom); mVectorOngoingConferenceCallView .setCallClickListener(new VectorOngoingConferenceCallView.ICallClickListener() { private void startCall(boolean isVideo) { if (CommonActivityUtils.checkPermissions( isVideo ? CommonActivityUtils.REQUEST_CODE_PERMISSION_VIDEO_IP_CALL : CommonActivityUtils.REQUEST_CODE_PERMISSION_AUDIO_IP_CALL, VectorRoomActivity.this)) { startIpCall(isVideo); } } @Override public void onVoiceCallClick() { startCall(false); } @Override public void onVideoCallClick() { startCall(true); } }); View avatarLayout = findViewById(R.id.room_self_avatar); if (null != avatarLayout) { mAvatarImageView = (ImageView) avatarLayout.findViewById(R.id.avatar_img); } refreshSelfAvatar(); // in case a "Send as" dialog was in progress when the activity was destroyed (life cycle) mVectorRoomMediasSender.resumeResizeMediaAndSend(); // header visibility has launched enableActionBarHeader(intent.getBooleanExtra(EXTRA_EXPAND_ROOM_HEADER, false) ? SHOW_ACTION_BAR_HEADER : HIDE_ACTION_BAR_HEADER); // the both flags are only used once intent.removeExtra(EXTRA_EXPAND_ROOM_HEADER); Log.d(LOG_TAG, "End of create"); }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public void dismissNotification(Object o) { NotificationManager notificationManager = (NotificationManager) getContext() .getSystemService(Activity.NOTIFICATION_SERVICE); if (o != null) { Integer n = (Integer) o; notificationManager.cancel("CN1", n.intValue()); } else {/* w ww. jav a 2s. com*/ notificationManager.cancelAll(); } }