List of usage examples for android.content Intent getParcelableArrayListExtra
public <T extends Parcelable> ArrayList<T> getParcelableArrayListExtra(String name)
From source file:it.feio.android.omninotes.DetailFragment.java
private void handleIntents() { Intent i = mainActivity.getIntent(); if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) { noteOriginal = new Note(); note = new Note(noteOriginal); noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE); if (i.getStringArrayListExtra("merged_notes") != null) { mergedNotesIds = i.getStringArrayListExtra("merged_notes"); }//from w w w .j ava2 s . com } // Action called from home shortcut if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) { afterSavedReturnsToList = false; noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0)); // Checks if the note pointed from the shortcut has been deleted try { note = new Note(noteOriginal); noteTmp = new Note(noteOriginal); } catch (NullPointerException e) { mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG); mainActivity.finish(); } } // Check if is launched from a widget if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) { afterSavedReturnsToList = false; showKeyboard = true; // with tags to set tag if (i.hasExtra(Constants.INTENT_WIDGET)) { String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString(); if (widgetId != null) { String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, ""); String categoryId = TextHelper.checkIntentCategory(sqlCondition); if (categoryId != null) { Category category; try { category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId)); noteTmp = new Note(); noteTmp.setCategory(category); } catch (NumberFormatException e) { Log.e(Constants.TAG, "Category with not-numeric value!", e); } } } } // Sub-action is to take a photo if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) { takePhoto(); } } /** * Handles third party apps requests of sharing */ if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE, Constants.INTENT_GOOGLE_NOW) && i.getType() != null) { afterSavedReturnsToList = false; if (noteTmp == null) noteTmp = new Note(); // Text title String title = i.getStringExtra(Intent.EXTRA_SUBJECT); if (title != null) { noteTmp.setTitle(title); } // Text content String content = i.getStringExtra(Intent.EXTRA_TEXT); if (content != null) { noteTmp.setContent(content); } // Single attachment data Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM); // Due to the fact that Google Now passes intent as text but with // audio recording attached the case must be handled in specific way if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) { String name = FileHelper.getNameFromUri(mainActivity, uri); AttachmentTask task = new AttachmentTask(this, uri, name, this); task.execute(); } // Multiple attachment data ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (uris != null) { for (Uri uriSingle : uris) { String name = FileHelper.getNameFromUri(mainActivity, uriSingle); AttachmentTask task = new AttachmentTask(this, uriSingle, name, this); task.execute(); } } // i.setAction(null); } if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST)) { showKeyboard = true; } }
From source file:com.dycody.android.idealnote.DetailFragment.java
private void handleIntents() { Intent i = mainActivity.getIntent(); if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) { noteOriginal = new Note(); note = new Note(noteOriginal); noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE); if (i.getStringArrayListExtra("merged_notes") != null) { mergedNotesIds = i.getStringArrayListExtra("merged_notes"); }/*from w w w .ja v a 2 s . c o m*/ } // Action called from home shortcut if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) { afterSavedReturnsToList = false; noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0)); // Checks if the note pointed from the shortcut has been deleted try { note = new Note(noteOriginal); noteTmp = new Note(noteOriginal); } catch (NullPointerException e) { mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG); mainActivity.finish(); } } // Check if is launched from a widget if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) { afterSavedReturnsToList = false; showKeyboard = true; // with tags to set tag if (i.hasExtra(Constants.INTENT_WIDGET)) { String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString(); if (widgetId != null) { String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, ""); String categoryId = TextHelper.checkIntentCategory(sqlCondition); if (categoryId != null) { Category category; try { category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId)); noteTmp = new Note(); noteTmp.setCategory(category); } catch (NumberFormatException e) { Log.e(Constants.TAG, "Category with not-numeric value!", e); } } } } // Sub-action is to take a photo if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) { takePhoto(); } } /** * Handles third party apps requests of sharing */ if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE, Constants.INTENT_GOOGLE_NOW) && i.getType() != null) { afterSavedReturnsToList = false; if (noteTmp == null) noteTmp = new Note(); // Text title String title = i.getStringExtra(Intent.EXTRA_SUBJECT); if (title != null) { noteTmp.setTitle(title); } // Text content String content = i.getStringExtra(Intent.EXTRA_TEXT); if (content != null) { noteTmp.setContent(content); } // Single attachment data Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM); // Due to the fact that Google Now passes intent as text but with // audio recording attached the case must be handled in specific way if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) { String name = FileHelper.getNameFromUri(mainActivity, uri); new AttachmentTask(this, uri, name, this).execute(); } // Multiple attachment data ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (uris != null) { for (Uri uriSingle : uris) { String name = FileHelper.getNameFromUri(mainActivity, uriSingle); new AttachmentTask(this, uriSingle, name, this).execute(); } } } if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST, Constants.ACTION_SHORTCUT_WIDGET, Constants.ACTION_WIDGET)) { showKeyboard = true; } i.setAction(null); }
From source file:com.fa.mastodon.activity.ComposeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_compose); ButterKnife.bind(this); // Setup the toolbar. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from ww w . j a v a 2 s .co m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(null); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp); ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint); actionBar.setHomeAsUpIndicator(closeIcon); } // Setup the interface buttons. floatingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSendClicked(); } }); pickBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onMediaPick(); } }); takeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCameraApp(); } }); nsfwBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleNsfw(); } }); visibilityBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showComposeOptions(); } }); /* Initialise all the state, or restore it from a previous run, to determine a "starting" * state. */ SharedPreferences preferences = getPrivatePreferences(); String startingVisibility; boolean startingHideText; String startingContentWarning = null; ArrayList<SavedQueuedMedia> savedMediaQueued = null; if (savedInstanceState != null) { showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive"); startingVisibility = savedInstanceState.getString("statusVisibility"); statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive"); startingHideText = savedInstanceState.getBoolean("statusHideText"); // Keep these until everything needed to put them in the queue is finished initializing. savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued"); // These are for restoring an in-progress commit content operation. InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo")); int previousFlags = savedInstanceState.getInt("commitContentFlags"); if (previousInputContentInfo != null) { onCommitContentInternal(previousInputContentInfo, previousFlags); } } else { showMarkSensitive = false; startingVisibility = preferences.getString("rememberedVisibility", "public"); statusMarkSensitive = false; startingHideText = false; } /* If the composer is started up as a reply to another post, override the "starting" state * based on what the intent from the reply request passes. */ Intent intent = getIntent(); String[] mentionedUsernames = null; inReplyToId = null; if (intent != null) { inReplyToId = intent.getStringExtra("in_reply_to_id"); String replyVisibility = intent.getStringExtra("reply_visibility"); if (replyVisibility != null && startingVisibility != null) { // Lowest possible visibility setting in response if (startingVisibility.equals("private") || replyVisibility.equals("private")) { startingVisibility = "private"; } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) { startingVisibility = "unlisted"; } else { startingVisibility = replyVisibility; } } mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames"); if (inReplyToId != null) { startingHideText = !intent.getStringExtra("content_warning").equals(""); if (startingHideText) { startingContentWarning = intent.getStringExtra("content_warning"); } } } /* If the currently logged in account is locked, its posts should default to private. This * should override even the reply settings, so this must be done after those are set up. */ if (preferences.getBoolean("loggedInAccountLocked", false)) { startingVisibility = "private"; } // After the starting state is finalised, the interface can be set to reflect this state. setStatusVisibility(startingVisibility); postProgress.setVisibility(View.INVISIBLE); updateNsfwButtonColor(); // Setup the main text field. setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" } final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color); SpanUtils.highlightSpans(textEditor.getText(), mentionColour); textEditor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable editable) { SpanUtils.highlightSpans(editable, mentionColour); } }); // Add any mentions to the text field when a reply is first composed. if (mentionedUsernames != null) { StringBuilder builder = new StringBuilder(); for (String name : mentionedUsernames) { builder.append('@'); builder.append(name); builder.append(' '); } textEditor.setText(builder); textEditor.setSelection(textEditor.length()); } // Initialise the content warning editor. contentWarningEditor.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void afterTextChanged(Editable s) { } }); showContentWarning(startingHideText); if (startingContentWarning != null) { contentWarningEditor.setText(startingContentWarning); } // Initialise the empty media queue state. mediaQueued = new ArrayList<>(); waitForMediaLatch = new CountUpDownLatch(); statusAlreadyInFlight = false; // These can only be added after everything affected by the media queue is initialized. if (savedMediaQueued != null) { for (SavedQueuedMedia item : savedMediaQueued) { addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); } } else if (intent != null && savedInstanceState == null) { /* Get incoming images being sent through a share action from another app. Only do this * when savedInstanceState is null, otherwise both the images from the intent and the * instance state will be re-queued. */ String type = intent.getType(); if (type != null) { if (type.startsWith("image/")) { List<Uri> uriList = new ArrayList<>(); switch (intent.getAction()) { case Intent.ACTION_SEND: { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { uriList.add(uri); } break; } case Intent.ACTION_SEND_MULTIPLE: { ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (list != null) { for (Uri uri : list) { if (uri != null) { uriList.add(uri); } } } break; } } for (Uri uri : uriList) { long mediaSize = getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (type.equals("text/plain")) { String action = intent.getAction(); if (action != null && action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); if (text != null) { int start = Math.max(textEditor.getSelectionStart(), 0); int end = Math.max(textEditor.getSelectionEnd(), 0); int left = Math.min(start, end); int right = Math.max(start, end); textEditor.getText().replace(left, right, text, 0, text.length()); } } } } } }
From source file:net.maa123.tatuky.ComposeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_compose); ButterKnife.bind(this); // Setup the toolbar. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w ww.j a v a2 s .c o m*/ ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(null); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp); ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint); actionBar.setHomeAsUpIndicator(closeIcon); } // Setup the interface buttons. floatingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSendClicked(); } }); pickBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onMediaPick(); } }); takeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCameraApp(); } }); nsfwBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleNsfw(); } }); visibilityBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showComposeOptions(); } }); /* Initialise all the state, or restore it from a previous run, to determine a "starting" * state. */ SharedPreferences preferences = getPrivatePreferences(); String startingVisibility; boolean startingHideText; String startingContentWarning = null; ArrayList<SavedQueuedMedia> savedMediaQueued = null; if (savedInstanceState != null) { showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive"); startingVisibility = savedInstanceState.getString("statusVisibility"); statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive"); startingHideText = savedInstanceState.getBoolean("statusHideText"); // Keep these until everything needed to put them in the queue is finished initializing. savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued"); // These are for restoring an in-progress commit content operation. InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo")); int previousFlags = savedInstanceState.getInt("commitContentFlags"); if (previousInputContentInfo != null) { onCommitContentInternal(previousInputContentInfo, previousFlags); } } else { showMarkSensitive = false; startingVisibility = preferences.getString("rememberedVisibility", "public"); statusMarkSensitive = false; startingHideText = false; } /* If the composer is started up as a reply to another post, override the "starting" state * based on what the intent from the reply request passes. */ Intent intent = getIntent(); String[] mentionedUsernames = null; inReplyToId = null; if (intent != null) { inReplyToId = intent.getStringExtra("in_reply_to_id"); String replyVisibility = intent.getStringExtra("reply_visibility"); if (replyVisibility != null && startingVisibility != null) { // Lowest possible visibility setting in response if (startingVisibility.equals("direct") || replyVisibility.equals("direct")) { startingVisibility = "direct"; } else if (startingVisibility.equals("private") || replyVisibility.equals("private")) { startingVisibility = "private"; } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) { startingVisibility = "unlisted"; } else { startingVisibility = replyVisibility; } } mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames"); if (inReplyToId != null) { startingHideText = !intent.getStringExtra("content_warning").equals(""); if (startingHideText) { startingContentWarning = intent.getStringExtra("content_warning"); } } } /* If the currently logged in account is locked, its posts should default to private. This * should override even the reply settings, so this must be done after those are set up. */ if (preferences.getBoolean("loggedInAccountLocked", false)) { startingVisibility = "private"; } // After the starting state is finalised, the interface can be set to reflect this state. setStatusVisibility(startingVisibility); postProgress.setVisibility(View.INVISIBLE); updateNsfwButtonColor(); // Setup the main text field. setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" } final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color); SpanUtils.highlightSpans(textEditor.getText(), mentionColour); textEditor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable editable) { SpanUtils.highlightSpans(editable, mentionColour); } }); // Add any mentions to the text field when a reply is first composed. if (mentionedUsernames != null) { StringBuilder builder = new StringBuilder(); for (String name : mentionedUsernames) { builder.append('@'); builder.append(name); builder.append(' '); } textEditor.setText(builder); textEditor.setSelection(textEditor.length()); } // Initialise the content warning editor. contentWarningEditor.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void afterTextChanged(Editable s) { } }); showContentWarning(startingHideText); if (startingContentWarning != null) { contentWarningEditor.setText(startingContentWarning); } // Initialise the empty media queue state. mediaQueued = new ArrayList<>(); waitForMediaLatch = new CountUpDownLatch(); statusAlreadyInFlight = false; // These can only be added after everything affected by the media queue is initialized. if (savedMediaQueued != null) { for (SavedQueuedMedia item : savedMediaQueued) { addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); } } else if (intent != null && savedInstanceState == null) { /* Get incoming images being sent through a share action from another app. Only do this * when savedInstanceState is null, otherwise both the images from the intent and the * instance state will be re-queued. */ String type = intent.getType(); if (type != null) { if (type.startsWith("image/")) { List<Uri> uriList = new ArrayList<>(); switch (intent.getAction()) { case Intent.ACTION_SEND: { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { uriList.add(uri); } break; } case Intent.ACTION_SEND_MULTIPLE: { ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (list != null) { for (Uri uri : list) { if (uri != null) { uriList.add(uri); } } } break; } } for (Uri uri : uriList) { long mediaSize = getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (type.equals("text/plain")) { String action = intent.getAction(); if (action != null && action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); if (text != null) { int start = Math.max(textEditor.getSelectionStart(), 0); int end = Math.max(textEditor.getSelectionEnd(), 0); int left = Math.min(start, end); int right = Math.max(start, end); textEditor.getText().replace(left, right, text, 0, text.length()); } } } } } }
From source file:com.tct.mail.compose.ComposeActivity.java
private void finishCreate() { final Bundle savedState = mInnerSavedState; findViews();/*from w ww . j a va 2s . c om*/ // TS: junwei-xu 2015-09-01 EMAIL BUGFIX-526192 ADD_S updateFromRowByAccounts(); // TS: junwei-xu 2015-09-01 EMAIL BUGFIX-526192 ADD_E final Intent intent = getIntent(); final Message message; final ArrayList<AttachmentPreview> previews; mShowQuotedText = false; final CharSequence quotedText; int action; // Check for any of the possibly supplied accounts.; final Account account; if (hadSavedInstanceStateMessage(savedState)) { action = savedState.getInt(EXTRA_ACTION, COMPOSE); account = savedState.getParcelable(Utils.EXTRA_ACCOUNT); message = savedState.getParcelable(EXTRA_MESSAGE); previews = savedState.getParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS); mRefMessage = savedState.getParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE); quotedText = savedState.getCharSequence(EXTRA_QUOTED_TEXT); mExtraValues = savedState.getParcelable(EXTRA_VALUES); } else { account = obtainAccount(intent); action = intent.getIntExtra(EXTRA_ACTION, COMPOSE); // Initialize the message from the message in the intent message = intent.getParcelableExtra(ORIGINAL_DRAFT_MESSAGE); previews = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENT_PREVIEWS); mRefMessage = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE); //TS: wenggangjin 2015-01-06 EMAIL BUGFIX_882161 MOD_S if (mRefMessage != null && "".equals(mRefMessage.bodyHtml)) { String htmlbody = Body.restoreBodyHtmlWithMessageId(this, mRefMessage.getId()); mRefMessage.bodyHtml = htmlbody; //TS: xujian 2015-06-23 EMAIL BUGFIX_1015657 MOD_S } else if (message != null) { if ("".equals(message.bodyHtml)) { String htmlbody = Body.restoreBodyHtmlWithMessageId(this, message.getId()); message.bodyHtml = htmlbody; } if ("".equals(message.bodyText)) { String body = Body.restoreBodyTextWithMessageId(this, message.getId()); message.bodyText = body; } //TS: xujian 2015-06-23 EMAIL BUGFIX_1015657 MOD_S } //TS: wenggangjin 2015-01-06 EMAIL BUGFIX_882161 MOD_E mRefMessageUri = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE_URI); quotedText = null; if (Analytics.isLoggable()) { if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) { Analytics.getInstance().sendEvent("notification_action", "compose", getActionString(action), 0); } } } //TS: Gantao 2015-08-27 EMAIL FEATURE_ID DEL_S // mAttachmentsView.setAttachmentPreviews(previews); //TS: Gantao 2015-08-27 EMAIL FEATURE_ID DEL_E // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_S if (action == EDIT_DRAFT) { //mIsClickIcon = true;//[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,05/06/2016,2013535 mEditDraft = true; } // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_E setAccount(account); if (mAccount == null) { return; } // TS: chenyanhua 2015-01-12 EMAIL BUGFIX-890424 MOD_S // initRecipients(); // TS: chenyanhua 2015-01-12 EMAIL BUGFIX-890424 MOD_S // Clear the notification and mark the conversation as seen, if necessary final Folder notificationFolder = intent.getParcelableExtra(EXTRA_NOTIFICATION_FOLDER); if (notificationFolder != null) { final Uri conversationUri = intent.getParcelableExtra(EXTRA_NOTIFICATION_CONVERSATION); Intent actionIntent; if (conversationUri != null) { actionIntent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS_WEAR); actionIntent.putExtra(Utils.EXTRA_CONVERSATION, conversationUri); } else { actionIntent = new Intent(MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS); actionIntent.setData(Utils.appendVersionQueryParameter(this, notificationFolder.folderUri.fullUri)); } actionIntent.setPackage(getPackageName()); actionIntent.putExtra(Utils.EXTRA_ACCOUNT, account); actionIntent.putExtra(Utils.EXTRA_FOLDER, notificationFolder); startService(actionIntent); } if (intent.getBooleanExtra(EXTRA_FROM_EMAIL_TASK, false)) { mLaunchedFromEmail = true; } else if (Intent.ACTION_SEND.equals(intent.getAction())) { final Uri dataUri = intent.getData(); if (dataUri != null) { final String dataScheme = intent.getData().getScheme(); final String accountScheme = mAccount.composeIntentUri.getScheme(); mLaunchedFromEmail = TextUtils.equals(dataScheme, accountScheme); } } if (mRefMessageUri != null) { mShowQuotedText = true; mComposeMode = action; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); String wearReply = null; if (remoteInput != null) { LogUtils.d(LOG_TAG, "Got remote input from new api"); CharSequence input = remoteInput.getCharSequence(NotificationActionUtils.WEAR_REPLY_INPUT); if (input != null) { wearReply = input.toString(); } } else { // TODO: remove after legacy code has been removed. LogUtils.d(LOG_TAG, "No remote input from new api, falling back to compatibility mode"); ClipData clipData = intent.getClipData(); if (clipData != null && LEGACY_WEAR_EXTRA.equals(clipData.getDescription().getLabel())) { Bundle extras = clipData.getItemAt(0).getIntent().getExtras(); if (extras != null) { wearReply = extras.getString(NotificationActionUtils.WEAR_REPLY_INPUT); } } } if (!TextUtils.isEmpty(wearReply)) { createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, mComposeMode, wearReply).execute(); finish(); return; } else { LogUtils.w(LOG_TAG, "remote input string is null"); } } getLoaderManager().initLoader(INIT_DRAFT_USING_REFERENCE_MESSAGE, null, this); return; } else if (message != null && action != EDIT_DRAFT) { initFromDraftMessage(message); initQuotedTextFromRefMessage(mRefMessage, action); mShowQuotedText = message.appendRefMessageContent; // if we should be showing quoted text but mRefMessage is null // and we have some quotedText, display that if (mShowQuotedText && mRefMessage == null) { if (quotedText != null) { initQuotedText(quotedText, false /* shouldQuoteText */); } else if (mExtraValues != null) { initExtraValues(mExtraValues); return; } } } else if (action == EDIT_DRAFT) { if (message == null) { throw new IllegalStateException("Message must not be null to edit draft"); } initFromDraftMessage(message); // Update the action to the draft type of the previous draft switch (message.draftType) { case UIProvider.DraftType.REPLY: action = REPLY; break; case UIProvider.DraftType.REPLY_ALL: action = REPLY_ALL; break; case UIProvider.DraftType.FORWARD: action = FORWARD; break; case UIProvider.DraftType.COMPOSE: default: action = COMPOSE; break; } LogUtils.d(LOG_TAG, "Previous draft had action type: %d", action); mShowQuotedText = message.appendRefMessageContent; //TS: Gantao 2015-07-28 EMAIL BUGFIX_1053829 MOD_S //Terrible original design,refMessageUri did not save to db,the value is always 0 here. //but the body's sourceKey is saved ,it points to the refMessage's id,so we can get //the refMessage from the body's sourceKey. long sourceKey = Body.restoreBodySourceKey(this, message.id); if (sourceKey != 0) { // If we're editing an existing draft that was in reference to an existing message, // still need to load that original message since we might need to refer to the // original sender and recipients if user switches "reply <-> reply-all". mRefMessageUri = Uri.parse("content://" + EmailContent.AUTHORITY + "/uimessage/" + sourceKey); //TS: Gantao 2015-07-28 EMAIL BUGFIX_1053829 MOD_E mComposeMode = action; getLoaderManager().initLoader(REFERENCE_MESSAGE_LOADER, null, this); return; } } else if ((action == REPLY || action == REPLY_ALL || action == FORWARD)) { if (mRefMessage != null) { initFromRefMessage(action); mShowQuotedText = true; } } else { if (initFromExtras(intent)) { return; } } mComposeMode = action; finishSetup(action, intent, savedState); }
From source file:org.kontalk.ui.AbstractComposeFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // image from storage/picture from camera // since there are like up to 3 different ways of doing this... if (requestCode == SELECT_ATTACHMENT_OPENABLE || requestCode == SELECT_ATTACHMENT_PHOTO) { if (resultCode == Activity.RESULT_OK) { Uri[] uris = null;/*from ww w . j a v a2s .c o m*/ String[] mimes = null; // returning from camera if (requestCode == SELECT_ATTACHMENT_PHOTO) { if (mCurrentPhoto != null) { Uri uri = Uri.fromFile(mCurrentPhoto); // notify media scanner Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(uri); getActivity().sendBroadcast(mediaScanIntent); mCurrentPhoto = null; uris = new Uri[] { uri }; } } else { if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && data.getClipData() != null) { ClipData cdata = data.getClipData(); uris = new Uri[cdata.getItemCount()]; for (int i = 0; i < uris.length; i++) { ClipData.Item item = cdata.getItemAt(i); uris[i] = item.getUri(); } } else { uris = new Uri[] { data.getData() }; mimes = new String[] { data.getType() }; } // SAF available, request persistable permissions if (MediaStorage.isStorageAccessFrameworkAvailable()) { for (Uri uri : uris) { if (uri != null && !"file".equals(uri.getScheme())) { MediaStorage.requestPersistablePermissions(getActivity(), uri); } } } } for (int i = 0; uris != null && i < uris.length; i++) { Uri uri = uris[i]; if (uri == null) continue; String mime = (mimes != null && mimes.length >= uris.length) ? mimes[i] : null; if (mime == null || mime.startsWith("*/") || mime.endsWith("/*")) { mime = MediaStorage.getType(getActivity(), uri); Log.v(TAG, "using detected mime type " + mime); } if (ImageComponent.supportsMimeType(mime)) sendBinaryMessage(uri, mime, true, ImageComponent.class); else if (VCardComponent.supportsMimeType(mime)) sendBinaryMessage(uri, VCardComponent.MIME_TYPE, false, VCardComponent.class); else Toast.makeText(getActivity(), R.string.send_mime_not_supported, Toast.LENGTH_LONG).show(); } } // operation aborted else { // delete photo :) if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } } } // contact card (vCard) else if (requestCode == SELECT_ATTACHMENT_CONTACT) { if (resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); if (uri != null) { Uri vcardUri = null; // get lookup key final Cursor c = getContext().getContentResolver().query(uri, new String[] { Contacts.LOOKUP_KEY }, null, null, null); if (c != null) { try { if (c.moveToFirst()) { String lookupKey = c.getString(0); vcardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); } } catch (Exception e) { Log.w(TAG, "unable to lookup selected contact. Did you grant me the permission?", e); ReportingManager.logException(e); } finally { c.close(); } } if (vcardUri != null) { sendBinaryMessage(vcardUri, VCardComponent.MIME_TYPE, false, VCardComponent.class); } else { Toast.makeText(getContext(), R.string.err_no_contact, Toast.LENGTH_LONG).show(); } } } } // invite user else if (requestCode == REQUEST_INVITE_USERS) { if (resultCode == Activity.RESULT_OK) { ArrayList<Uri> uris; Uri threadUri = data.getData(); if (threadUri != null) { String userId = threadUri.getLastPathSegment(); addUsers(new String[] { userId }); } else if ((uris = data.getParcelableArrayListExtra("org.kontalk.contacts")) != null) { String[] users = new String[uris.size()]; for (int i = 0; i < users.length; i++) users[i] = uris.get(i).getLastPathSegment(); addUsers(users); } } } }
From source file:org.telegram.ui.LaunchActivity.java
private void handleIntent(Intent intent, boolean isNew, boolean restore) { boolean pushOpened = false; Integer push_user_id = 0;/*www . ja va 2 s. c o m*/ Integer push_chat_id = 0; Integer push_enc_id = 0; Integer open_settings = 0; photoPath = null; videoPath = null; sendingText = null; documentPath = null; imagesPathArray = null; documentsPathArray = null; if (intent != null && intent.getAction() != null && !restore) { if (Intent.ACTION_SEND.equals(intent.getAction())) { boolean error = false; String type = intent.getType(); if (type != null && type.equals("text/plain")) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); if (text != null && text.length() != 0) { if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null && subject.length() != 0) { text = subject + "\n" + text; } sendingText = text; } else { error = true; } } else if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) { try { Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM); if (uri != null) { ContentResolver cr = getContentResolver(); InputStream stream = cr.openInputStream(uri); String name = null; String nameEncoding = null; String nameCharset = null; ArrayList<String> phones = new ArrayList<String>(); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(stream, "UTF-8")); String line = null; while ((line = bufferedReader.readLine()) != null) { String[] args = line.split(":"); if (args.length != 2) { continue; } if (args[0].startsWith("FN")) { String[] params = args[0].split(";"); for (String param : params) { String[] args2 = param.split("="); if (args2.length != 2) { continue; } if (args2[0].equals("CHARSET")) { nameCharset = args2[1]; } else if (args2[0].equals("ENCODING")) { nameEncoding = args2[1]; } } name = args[1]; if (nameEncoding != null && nameEncoding.equalsIgnoreCase("QUOTED-PRINTABLE")) { while (name.endsWith("=") && nameEncoding != null) { name = name.substring(0, name.length() - 1); line = bufferedReader.readLine(); if (line == null) { break; } name += line; } byte[] bytes = Utilities.decodeQuotedPrintable(name.getBytes()); if (bytes != null && bytes.length != 0) { String decodedName = new String(bytes, nameCharset); if (decodedName != null) { name = decodedName; } } } } else if (args[0].startsWith("TEL")) { String phone = PhoneFormat.stripExceptNumbers(args[1], true); if (phone.length() > 0) { phones.add(phone); } } } if (name != null && !phones.isEmpty()) { contactsToSend = new ArrayList<TLRPC.User>(); for (String phone : phones) { TLRPC.User user = new TLRPC.TL_userContact(); user.phone = phone; user.first_name = name; user.last_name = ""; user.id = 0; contactsToSend.add(user); } } } else { error = true; } } catch (Exception e) { FileLog.e("tmessages", e); error = true; } } else { Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (parcelable == null) { return; } String path = null; if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } if (parcelable != null && type != null && type.startsWith("image/")) { photoPath = (Uri) parcelable; } else { path = Utilities.getPath((Uri) parcelable); if (path != null) { if (path.startsWith("file:")) { path = path.replace("file://", ""); } if (type != null && type.startsWith("video/")) { videoPath = path; } else { documentPath = path; } } else { error = true; } } if (error) { Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); } } } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { boolean error = false; try { ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); String type = intent.getType(); if (uris != null) { if (type != null && type.startsWith("image/")) { Uri[] uris2 = new Uri[uris.size()]; for (int i = 0; i < uris2.length; i++) { Parcelable parcelable = uris.get(i); if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } uris2[i] = (Uri) parcelable; } imagesPathArray = uris2; } else { String[] uris2 = new String[uris.size()]; for (int i = 0; i < uris2.length; i++) { Parcelable parcelable = uris.get(i); if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } String path = Utilities.getPath((Uri) parcelable); if (path != null) { if (path.startsWith("file:")) { path = path.replace("file://", ""); } uris2[i] = path; } } documentsPathArray = uris2; } } else { error = true; } } catch (Exception e) { FileLog.e("tmessages", e); error = true; } if (error) { Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); } } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { try { Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { int userId = cursor.getInt(cursor.getColumnIndex("DATA4")); NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); push_user_id = userId; } cursor.close(); } } catch (Exception e) { FileLog.e("tmessages", e); } } else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) { open_settings = 1; } } if (getIntent().getAction() != null && getIntent().getAction().startsWith("com.tmessages.openchat") && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0 && !restore) { int chatId = getIntent().getIntExtra("chatId", 0); int userId = getIntent().getIntExtra("userId", 0); int encId = getIntent().getIntExtra("encId", 0); if (chatId != 0) { TLRPC.Chat chat = MessagesController.getInstance().chats.get(chatId); if (chat != null) { NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); push_chat_id = chatId; } } else if (userId != 0) { TLRPC.User user = MessagesController.getInstance().users.get(userId); if (user != null) { NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); push_user_id = userId; } } else if (encId != 0) { TLRPC.EncryptedChat chat = MessagesController.getInstance().encryptedChats.get(encId); if (chat != null) { NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats); push_enc_id = encId; } } } if (push_user_id != 0) { if (push_user_id == UserConfig.clientUserId) { open_settings = 1; } else { ChatActivity fragment = new ChatActivity(); Bundle bundle = new Bundle(); bundle.putInt("user_id", push_user_id); fragment.setArguments(bundle); if (fragment.onFragmentCreate()) { pushOpened = true; ApplicationLoader.fragmentsStack.add(fragment); getSupportFragmentManager().beginTransaction() .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); } } } else if (push_chat_id != 0) { ChatActivity fragment = new ChatActivity(); Bundle bundle = new Bundle(); bundle.putInt("chat_id", push_chat_id); fragment.setArguments(bundle); if (fragment.onFragmentCreate()) { pushOpened = true; ApplicationLoader.fragmentsStack.add(fragment); getSupportFragmentManager().beginTransaction() .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); } } else if (push_enc_id != 0) { ChatActivity fragment = new ChatActivity(); Bundle bundle = new Bundle(); bundle.putInt("enc_id", push_enc_id); fragment.setArguments(bundle); if (fragment.onFragmentCreate()) { pushOpened = true; ApplicationLoader.fragmentsStack.add(fragment); getSupportFragmentManager().beginTransaction() .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); } } if (videoPath != null || photoPath != null || sendingText != null || documentPath != null || documentsPathArray != null || imagesPathArray != null || contactsToSend != null) { MessagesActivity fragment = new MessagesActivity(); fragment.selectAlertString = R.string.ForwardMessagesTo; fragment.selectAlertStringDesc = "ForwardMessagesTo"; fragment.animationType = 1; Bundle args = new Bundle(); args.putBoolean("onlySelect", true); fragment.setArguments(args); fragment.delegate = this; ApplicationLoader.fragmentsStack.add(fragment); fragment.onFragmentCreate(); getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()) .commitAllowingStateLoss(); pushOpened = true; } if (open_settings != 0) { SettingsActivity fragment = new SettingsActivity(); ApplicationLoader.fragmentsStack.add(fragment); fragment.onFragmentCreate(); getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings") .commitAllowingStateLoss(); pushOpened = true; } if (!pushOpened && !isNew) { BaseFragment fragment = ApplicationLoader.fragmentsStack .get(ApplicationLoader.fragmentsStack.size() - 1); getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()) .commitAllowingStateLoss(); } getIntent().setAction(null); }
From source file:com.keylesspalace.tusky.ComposeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT); if (theme.equals("black")) { setTheme(R.style.TuskyDialogActivityBlackTheme); }/*from ww w .j a va2s.co m*/ setContentView(R.layout.activity_compose); replyTextView = findViewById(R.id.composeReplyView); replyContentTextView = findViewById(R.id.composeReplyContentView); textEditor = findViewById(R.id.composeEditField); mediaPreviewBar = findViewById(R.id.compose_media_preview_bar); contentWarningBar = findViewById(R.id.composeContentWarningBar); contentWarningEditor = findViewById(R.id.composeContentWarningField); charactersLeft = findViewById(R.id.composeCharactersLeftView); tootButton = findViewById(R.id.composeTootButton); pickButton = findViewById(R.id.composeAddMediaButton); visibilityButton = findViewById(R.id.composeToggleVisibilityButton); contentWarningButton = findViewById(R.id.composeContentWarningButton); emojiButton = findViewById(R.id.composeEmojiButton); hideMediaToggle = findViewById(R.id.composeHideMediaButton); emojiView = findViewById(R.id.emojiView); emojiList = Collections.emptyList(); saveTootHelper = new SaveTootHelper(database.tootDao(), this); // Setup the toolbar. Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(null); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp); ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint); actionBar.setHomeAsUpIndicator(closeIcon); } // setup the account image final AccountEntity activeAccount = accountManager.getActiveAccount(); if (activeAccount != null) { ImageView composeAvatar = findViewById(R.id.composeAvatar); if (TextUtils.isEmpty(activeAccount.getProfilePictureUrl())) { composeAvatar.setImageResource(R.drawable.avatar_default); } else { Picasso.with(this).load(activeAccount.getProfilePictureUrl()).error(R.drawable.avatar_default) .placeholder(R.drawable.avatar_default).into(composeAvatar); } composeAvatar.setContentDescription( getString(R.string.compose_active_account_description, activeAccount.getFullName())); mastodonApi.getInstance().enqueue(new Callback<Instance>() { @Override public void onResponse(@NonNull Call<Instance> call, @NonNull Response<Instance> response) { if (response.isSuccessful() && response.body().getMaxTootChars() != null) { maximumTootCharacters = response.body().getMaxTootChars(); updateVisibleCharactersLeft(); cacheInstanceMetadata(activeAccount); } } @Override public void onFailure(@NonNull Call<Instance> call, @NonNull Throwable t) { Log.w(TAG, "error loading instance data", t); loadCachedInstanceMetadata(activeAccount); } }); mastodonApi.getCustomEmojis().enqueue(new Callback<List<Emoji>>() { @Override public void onResponse(@NonNull Call<List<Emoji>> call, @NonNull Response<List<Emoji>> response) { emojiList = response.body(); setEmojiList(emojiList); cacheInstanceMetadata(activeAccount); } @Override public void onFailure(@NonNull Call<List<Emoji>> call, @NonNull Throwable t) { Log.w(TAG, "error loading custom emojis", t); loadCachedInstanceMetadata(activeAccount); } }); } else { // do not do anything when not logged in, activity will be finished in super.onCreate() anyway return; } composeOptionsView = findViewById(R.id.composeOptionsBottomSheet); composeOptionsView.setListener(this); composeOptionsBehavior = BottomSheetBehavior.from(composeOptionsView); composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); addMediaBehavior = BottomSheetBehavior.from(findViewById(R.id.addMediaBottomSheet)); emojiBehavior = BottomSheetBehavior.from(emojiView); emojiView.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false)); enableButton(emojiButton, false, false); // Setup the interface buttons. tootButton.setOnClickListener(v -> onSendClicked()); pickButton.setOnClickListener(v -> openPickDialog()); visibilityButton.setOnClickListener(v -> showComposeOptions()); contentWarningButton.setOnClickListener(v -> onContentWarningChanged()); emojiButton.setOnClickListener(v -> showEmojis()); hideMediaToggle.setOnClickListener(v -> toggleHideMedia()); TextView actionPhotoTake = findViewById(R.id.action_photo_take); TextView actionPhotoPick = findViewById(R.id.action_photo_pick); int textColor = ThemeUtils.getColor(this, android.R.attr.textColorTertiary); Drawable cameraIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_camera_alt).color(textColor) .sizeDp(18); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(actionPhotoTake, cameraIcon, null, null, null); Drawable imageIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_image).color(textColor).sizeDp(18); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(actionPhotoPick, imageIcon, null, null, null); actionPhotoTake.setOnClickListener(v -> initiateCameraApp()); actionPhotoPick.setOnClickListener(v -> onMediaPick()); thumbnailViewSize = getResources().getDimensionPixelSize(R.dimen.compose_media_preview_size); /* Initialise all the state, or restore it from a previous run, to determine a "starting" * state. */ Status.Visibility startingVisibility = Status.Visibility.UNKNOWN; boolean startingHideText; ArrayList<SavedQueuedMedia> savedMediaQueued = null; if (savedInstanceState != null) { startingVisibility = Status.Visibility .byNum(savedInstanceState.getInt("statusVisibility", Status.Visibility.PUBLIC.getNum())); statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive"); startingHideText = savedInstanceState.getBoolean("statusHideText"); // Keep these until everything needed to put them in the queue is finished initializing. savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued"); // These are for restoring an in-progress commit content operation. InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo")); int previousFlags = savedInstanceState.getInt("commitContentFlags"); if (previousInputContentInfo != null) { onCommitContentInternal(previousInputContentInfo, previousFlags); } photoUploadUri = savedInstanceState.getParcelable("photoUploadUri"); } else { statusMarkSensitive = false; startingHideText = false; photoUploadUri = null; } /* If the composer is started up as a reply to another post, override the "starting" state * based on what the intent from the reply request passes. */ Intent intent = getIntent(); String[] mentionedUsernames = null; ArrayList<String> loadedDraftMediaUris = null; inReplyToId = null; if (intent != null) { if (startingVisibility == Status.Visibility.UNKNOWN) { Status.Visibility preferredVisibility = Status.Visibility.byString( preferences.getString("defaultPostPrivacy", Status.Visibility.PUBLIC.serverString())); Status.Visibility replyVisibility = Status.Visibility .byNum(intent.getIntExtra(REPLY_VISIBILITY_EXTRA, Status.Visibility.UNKNOWN.getNum())); startingVisibility = Status.Visibility .byNum(Math.max(preferredVisibility.getNum(), replyVisibility.getNum())); } inReplyToId = intent.getStringExtra(IN_REPLY_TO_ID_EXTRA); mentionedUsernames = intent.getStringArrayExtra(MENTIONED_USERNAMES_EXTRA); String contentWarning = intent.getStringExtra(CONTENT_WARNING_EXTRA); if (contentWarning != null) { startingHideText = !contentWarning.isEmpty(); if (startingHideText) { startingContentWarning = contentWarning; } } // If come from SavedTootActivity String savedTootText = intent.getStringExtra(SAVED_TOOT_TEXT_EXTRA); if (!TextUtils.isEmpty(savedTootText)) { startingText = savedTootText; textEditor.setText(savedTootText); } String savedJsonUrls = intent.getStringExtra(SAVED_JSON_URLS_EXTRA); if (!TextUtils.isEmpty(savedJsonUrls)) { // try to redo a list of media loadedDraftMediaUris = new Gson().fromJson(savedJsonUrls, new TypeToken<ArrayList<String>>() { }.getType()); } int savedTootUid = intent.getIntExtra(SAVED_TOOT_UID_EXTRA, 0); if (savedTootUid != 0) { this.savedTootUid = savedTootUid; } if (intent.hasExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA)) { replyTextView.setVisibility(View.VISIBLE); String username = intent.getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA); replyTextView.setText(getString(R.string.replying_to, username)); Drawable arrowDownIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_down) .sizeDp(12); ThemeUtils.setDrawableTint(this, arrowDownIcon, android.R.attr.textColorTertiary); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowDownIcon, null); replyTextView.setOnClickListener(v -> { TransitionManager.beginDelayedTransition((ViewGroup) replyContentTextView.getParent()); if (replyContentTextView.getVisibility() != View.VISIBLE) { replyContentTextView.setVisibility(View.VISIBLE); Drawable arrowUpIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_up) .sizeDp(12); ThemeUtils.setDrawableTint(this, arrowUpIcon, android.R.attr.textColorTertiary); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowUpIcon, null); } else { replyContentTextView.setVisibility(View.GONE); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowDownIcon, null); } }); } if (intent.hasExtra(REPLYING_STATUS_CONTENT_EXTRA)) { replyContentTextView.setText(intent.getStringExtra(REPLYING_STATUS_CONTENT_EXTRA)); } } // After the starting state is finalised, the interface can be set to reflect this state. setStatusVisibility(startingVisibility); updateHideMediaToggle(); updateVisibleCharactersLeft(); // Setup the main text field. textEditor.setOnCommitContentListener(this); final int mentionColour = textEditor.getLinkTextColors().getDefaultColor(); SpanUtilsKt.highlightSpans(textEditor.getText(), mentionColour); textEditor.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable editable) { SpanUtilsKt.highlightSpans(editable, mentionColour); updateVisibleCharactersLeft(); } }); textEditor.setAdapter(new MentionAutoCompleteAdapter(this, R.layout.item_autocomplete, this)); textEditor.setTokenizer(new MentionTokenizer()); // Add any mentions to the text field when a reply is first composed. if (mentionedUsernames != null) { StringBuilder builder = new StringBuilder(); for (String name : mentionedUsernames) { builder.append('@'); builder.append(name); builder.append(' '); } startingText = builder.toString(); textEditor.setText(startingText); textEditor.setSelection(textEditor.length()); } // work around Android platform bug -> https://issuetracker.google.com/issues/67102093 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O || Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1) { textEditor.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // Initialise the content warning editor. contentWarningEditor.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateVisibleCharactersLeft(); } @Override public void afterTextChanged(Editable s) { } }); showContentWarning(startingHideText); if (startingContentWarning != null) { contentWarningEditor.setText(startingContentWarning); } // Initialise the empty media queue state. waitForMediaLatch = new CountUpDownLatch(); // These can only be added after everything affected by the media queue is initialized. if (!ListUtils.isEmpty(loadedDraftMediaUris)) { for (String uriString : loadedDraftMediaUris) { Uri uri = Uri.parse(uriString); long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (savedMediaQueued != null) { for (SavedQueuedMedia item : savedMediaQueued) { Bitmap preview = MediaUtils.getImageThumbnail(getContentResolver(), item.uri, thumbnailViewSize); addMediaToQueue(item.id, item.type, preview, item.uri, item.mediaSize, item.readyStage, item.description); } } else if (intent != null && savedInstanceState == null) { /* Get incoming images being sent through a share action from another app. Only do this * when savedInstanceState is null, otherwise both the images from the intent and the * instance state will be re-queued. */ String type = intent.getType(); if (type != null) { if (type.startsWith("image/")) { List<Uri> uriList = new ArrayList<>(); if (intent.getAction() != null) { switch (intent.getAction()) { case Intent.ACTION_SEND: { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { uriList.add(uri); } break; } case Intent.ACTION_SEND_MULTIPLE: { ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (list != null) { for (Uri uri : list) { if (uri != null) { uriList.add(uri); } } } break; } } } for (Uri uri : uriList) { long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); } } else if (type.equals("text/plain")) { String action = intent.getAction(); if (action != null && action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); if (text != null) { int start = Math.max(textEditor.getSelectionStart(), 0); int end = Math.max(textEditor.getSelectionEnd(), 0); int left = Math.min(start, end); int right = Math.max(start, end); textEditor.getText().replace(left, right, text, 0, text.length()); } } } } } textEditor.requestFocus(); }
From source file:org.cafemember.ui.LaunchActivity.java
private boolean handleIntent(Intent intent, boolean isNew, boolean restore, boolean fromPassword) { int flags = intent.getFlags(); if (!fromPassword && (AndroidUtilities.needShowPasscode(true) || UserConfig.isWaitingForPasscodeEnter)) { showPasscodeActivity();/*from w w w . jav a2s .c o m*/ passcodeSaveIntent = intent; passcodeSaveIntentIsNew = isNew; passcodeSaveIntentIsRestore = restore; UserConfig.saveConfig(false); } else { boolean pushOpened = false; Integer push_user_id = 0; Integer push_chat_id = 0; Integer push_enc_id = 0; Integer open_settings = 0; long dialogId = intent != null && intent.getExtras() != null ? intent.getExtras().getLong("dialogId", 0) : 0; boolean showDialogsList = false; boolean showPlayer = false; photoPathsArray = null; videoPath = null; sendingText = null; documentsPathsArray = null; documentsOriginalPathsArray = null; documentsMimeType = null; documentsUrisArray = null; contactsToSend = null; if (UserConfig.isClientActivated() && (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { if (intent != null && intent.getAction() != null && !restore) { if (Intent.ACTION_SEND.equals(intent.getAction())) { boolean error = false; String type = intent.getType(); if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) { try { Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM); if (uri != null) { ContentResolver cr = getContentResolver(); InputStream stream = cr.openInputStream(uri); String name = null; String nameEncoding = null; String nameCharset = null; ArrayList<String> phones = new ArrayList<>(); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(stream, "UTF-8")); String line; while ((line = bufferedReader.readLine()) != null) { String[] args = line.split(":"); if (args.length != 2) { continue; } if (args[0].startsWith("FN")) { String[] params = args[0].split(";"); for (String param : params) { String[] args2 = param.split("="); if (args2.length != 2) { continue; } if (args2[0].equals("CHARSET")) { nameCharset = args2[1]; } else if (args2[0].equals("ENCODING")) { nameEncoding = args2[1]; } } name = args[1]; if (nameEncoding != null && nameEncoding.equalsIgnoreCase("QUOTED-PRINTABLE")) { while (name.endsWith("=") && nameEncoding != null) { name = name.substring(0, name.length() - 1); line = bufferedReader.readLine(); if (line == null) { break; } name += line; } byte[] bytes = AndroidUtilities .decodeQuotedPrintable(name.getBytes()); if (bytes != null && bytes.length != 0) { String decodedName = new String(bytes, nameCharset); if (decodedName != null) { name = decodedName; } } } } else if (args[0].startsWith("TEL")) { String phone = PhoneFormat.stripExceptNumbers(args[1], true); if (phone.length() > 0) { phones.add(phone); } } } try { bufferedReader.close(); stream.close(); } catch (Exception e) { FileLog.e("tmessages", e); } if (name != null && !phones.isEmpty()) { contactsToSend = new ArrayList<>(); for (String phone : phones) { TLRPC.User user = new TLRPC.TL_userContact_old2(); user.phone = phone; user.first_name = name; user.last_name = ""; user.id = 0; contactsToSend.add(user); } } } else { error = true; } } catch (Exception e) { FileLog.e("tmessages", e); error = true; } } else { String text = intent.getStringExtra(Intent.EXTRA_TEXT); if (text == null) { CharSequence textSequence = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); if (textSequence != null) { text = textSequence.toString(); } } String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); if (text != null && text.length() != 0) { if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null && subject.length() != 0) { text = subject + "\n" + text; } sendingText = text; } else if (subject != null && subject.length() > 0) { sendingText = subject; } Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (parcelable != null) { String path; if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } Uri uri = (Uri) parcelable; if (uri != null) { if (isInternalUri(uri)) { error = true; } } if (!error) { if (uri != null && (type != null && type.startsWith("image/") || uri.toString().toLowerCase().endsWith(".jpg"))) { if (photoPathsArray == null) { photoPathsArray = new ArrayList<>(); } photoPathsArray.add(uri); } else { path = AndroidUtilities.getPath(uri); if (path != null) { if (path.startsWith("file:")) { path = path.replace("file://", ""); } if (type != null && type.startsWith("video/")) { videoPath = path; } else { if (documentsPathsArray == null) { documentsPathsArray = new ArrayList<>(); documentsOriginalPathsArray = new ArrayList<>(); } documentsPathsArray.add(path); documentsOriginalPathsArray.add(uri.toString()); } } else { if (documentsUrisArray == null) { documentsUrisArray = new ArrayList<>(); } documentsUrisArray.add(uri); documentsMimeType = type; } } if (sendingText != null) { if (sendingText.contains("WhatsApp")) { //remove unnecessary caption 'sent from WhatsApp' from photos forwarded from WhatsApp sendingText = null; } } } } else if (sendingText == null) { error = true; } } if (error) { Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); } } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { boolean error = false; try { ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); String type = intent.getType(); if (uris != null) { for (int a = 0; a < uris.size(); a++) { Parcelable parcelable = uris.get(a); if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } Uri uri = (Uri) parcelable; if (uri != null) { if (isInternalUri(uri)) { uris.remove(a); a--; } } } if (uris.isEmpty()) { uris = null; } } if (uris != null) { if (type != null && type.startsWith("image/")) { for (int a = 0; a < uris.size(); a++) { Parcelable parcelable = uris.get(a); if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } Uri uri = (Uri) parcelable; if (photoPathsArray == null) { photoPathsArray = new ArrayList<>(); } photoPathsArray.add(uri); } } else { for (int a = 0; a < uris.size(); a++) { Parcelable parcelable = uris.get(a); if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } String path = AndroidUtilities.getPath((Uri) parcelable); String originalPath = parcelable.toString(); if (originalPath == null) { originalPath = path; } if (path != null) { if (path.startsWith("file:")) { path = path.replace("file://", ""); } if (documentsPathsArray == null) { documentsPathsArray = new ArrayList<>(); documentsOriginalPathsArray = new ArrayList<>(); } documentsPathsArray.add(path); documentsOriginalPathsArray.add(originalPath); } } } } else { error = true; } } catch (Exception e) { FileLog.e("tmessages", e); error = true; } if (error) { Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); } } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri data = intent.getData(); if (data != null) { String username = null; String group = null; String sticker = null; String botUser = null; String botChat = null; String message = null; Integer messageId = null; boolean hasUrl = false; String scheme = data.getScheme(); if (scheme != null) { if ((scheme.equals("http") || scheme.equals("https"))) { String host = data.getHost().toLowerCase(); if (host.equals("telegram.me") || host.equals("telegram.dog")) { String path = data.getPath(); if (path != null && path.length() > 1) { path = path.substring(1); if (path.startsWith("joinchat/")) { group = path.replace("joinchat/", ""); } else if (path.startsWith("addstickers/")) { sticker = path.replace("addstickers/", ""); } else if (path.startsWith("msg/") || path.startsWith("share/")) { message = data.getQueryParameter("url"); if (message == null) { message = ""; } if (data.getQueryParameter("text") != null) { if (message.length() > 0) { hasUrl = true; message += "\n"; } message += data.getQueryParameter("text"); } } else if (path.length() >= 1) { List<String> segments = data.getPathSegments(); if (segments.size() > 0) { username = segments.get(0); if (segments.size() > 1) { messageId = Utilities.parseInt(segments.get(1)); if (messageId == 0) { messageId = null; } } } botUser = data.getQueryParameter("start"); botChat = data.getQueryParameter("startgroup"); } } } } else if (scheme.equals("tg")) { String url = data.toString(); if (url.startsWith("tg:resolve") || url.startsWith("tg://resolve")) { url = url.replace("tg:resolve", "tg://telegram.org").replace("tg://resolve", "tg://telegram.org"); data = Uri.parse(url); username = data.getQueryParameter("domain"); botUser = data.getQueryParameter("start"); botChat = data.getQueryParameter("startgroup"); } else if (url.startsWith("tg:join") || url.startsWith("tg://join")) { url = url.replace("tg:join", "tg://telegram.org").replace("tg://join", "tg://telegram.org"); data = Uri.parse(url); group = data.getQueryParameter("invite"); } else if (url.startsWith("tg:addstickers") || url.startsWith("tg://addstickers")) { url = url.replace("tg:addstickers", "tg://telegram.org") .replace("tg://addstickers", "tg://telegram.org"); data = Uri.parse(url); sticker = data.getQueryParameter("set"); } else if (url.startsWith("tg:msg") || url.startsWith("tg://msg") || url.startsWith("tg://share") || url.startsWith("tg:share")) { url = url.replace("tg:msg", "tg://telegram.org") .replace("tg://msg", "tg://telegram.org") .replace("tg://share", "tg://telegram.org") .replace("tg:share", "tg://telegram.org"); data = Uri.parse(url); message = data.getQueryParameter("url"); if (message == null) { message = ""; } if (data.getQueryParameter("text") != null) { if (message.length() > 0) { hasUrl = true; message += "\n"; } message += data.getQueryParameter("text"); } } } } if (username != null || group != null || sticker != null || message != null) { runLinkRequest(username, group, sticker, botUser, botChat, message, hasUrl, messageId, 0); } else { try { Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { int userId = cursor.getInt(cursor.getColumnIndex("DATA4")); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.closeChats); push_user_id = userId; } cursor.close(); } } catch (Exception e) { FileLog.e("tmessages", e); } } } } else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) { open_settings = 1; } else if (intent.getAction().startsWith("com.tmessages.openchat")) { int chatId = intent.getIntExtra("chatId", 0); int userId = intent.getIntExtra("userId", 0); int encId = intent.getIntExtra("encId", 0); if (chatId != 0) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); push_chat_id = chatId; } else if (userId != 0) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); push_user_id = userId; } else if (encId != 0) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); push_enc_id = encId; } else { showDialogsList = true; } } else if (intent.getAction().equals("com.tmessages.openplayer")) { showPlayer = true; } } } if (push_user_id != 0) { Bundle args = new Bundle(); args.putInt("user_id", push_user_id); if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) { ChatActivity fragment = new ChatActivity(args); if (actionBarLayout.presentFragment(fragment, false, true, true)) { pushOpened = true; } } } else if (push_chat_id != 0) { Bundle args = new Bundle(); args.putInt("chat_id", push_chat_id); if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) { ChatActivity fragment = new ChatActivity(args); if (actionBarLayout.presentFragment(fragment, false, true, true)) { pushOpened = true; } } } else if (push_enc_id != 0) { Bundle args = new Bundle(); args.putInt("enc_id", push_enc_id); ChatActivity fragment = new ChatActivity(args); if (actionBarLayout.presentFragment(fragment, false, true, true)) { pushOpened = true; } } else if (showDialogsList) { if (!AndroidUtilities.isTablet()) { actionBarLayout.removeAllFragments(); } else { if (!layersActionBarLayout.fragmentsStack.isEmpty()) { for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) { layersActionBarLayout .removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0)); a--; } layersActionBarLayout.closeLastFragment(false); } } pushOpened = false; isNew = false; } else if (showPlayer) { if (AndroidUtilities.isTablet()) { for (int a = 0; a < layersActionBarLayout.fragmentsStack.size(); a++) { BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(a); if (fragment instanceof AudioPlayerActivity) { layersActionBarLayout.removeFragmentFromStack(fragment); break; } } actionBarLayout.showLastFragment(); rightActionBarLayout.showLastFragment(); drawerLayoutContainer.setAllowOpenDrawer(false, false); } else { for (int a = 0; a < actionBarLayout.fragmentsStack.size(); a++) { BaseFragment fragment = actionBarLayout.fragmentsStack.get(a); if (fragment instanceof AudioPlayerActivity) { actionBarLayout.removeFragmentFromStack(fragment); break; } } drawerLayoutContainer.setAllowOpenDrawer(true, false); } actionBarLayout.presentFragment(new AudioPlayerActivity(), false, true, true); pushOpened = true; } else if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) { if (!AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); } if (dialogId == 0) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); if (contactsToSend != null) { args.putString("selectAlertString", LocaleController.getString("SendContactTo", R.string.SendMessagesTo)); args.putString("selectAlertStringGroup", LocaleController.getString("SendContactToGroup", R.string.SendContactToGroup)); } else { args.putString("selectAlertString", LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo)); args.putString("selectAlertStringGroup", LocaleController.getString("SendMessagesToGroup", R.string.SendMessagesToGroup)); } DialogsActivity fragment = new DialogsActivity(args); dialogsFragment = fragment; fragment.setDelegate(this); boolean removeLast; if (AndroidUtilities.isTablet()) { removeLast = layersActionBarLayout.fragmentsStack.size() > 0 && layersActionBarLayout.fragmentsStack.get( layersActionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity; } else { removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack .get(actionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity; } actionBarLayout.presentFragment(fragment, removeLast, true, true); pushOpened = true; if (PhotoViewer.getInstance().isVisible()) { PhotoViewer.getInstance().closePhoto(false, true); } drawerLayoutContainer.setAllowOpenDrawer(false, false); if (AndroidUtilities.isTablet()) { actionBarLayout.showLastFragment(); rightActionBarLayout.showLastFragment(); } else { drawerLayoutContainer.setAllowOpenDrawer(true, false); } } else { didSelectDialog(null, dialogId, false); } } else if (open_settings != 0) { actionBarLayout.presentFragment(new SettingsActivity(), false, true, true); if (AndroidUtilities.isTablet()) { actionBarLayout.showLastFragment(); rightActionBarLayout.showLastFragment(); drawerLayoutContainer.setAllowOpenDrawer(false, false); } else { drawerLayoutContainer.setAllowOpenDrawer(true, false); } pushOpened = true; } if (!pushOpened && !isNew) { if (AndroidUtilities.isTablet()) { if (!UserConfig.isClientActivated()) { if (layersActionBarLayout.fragmentsStack.isEmpty()) { layersActionBarLayout.addFragmentToStack(new LoginActivity()); drawerLayoutContainer.setAllowOpenDrawer(false, false); } } else { if (actionBarLayout.fragmentsStack.isEmpty()) { actionBarLayout.addFragmentToStack(new DialogsActivity(null)); drawerLayoutContainer.setAllowOpenDrawer(true, false); } } } else { if (actionBarLayout.fragmentsStack.isEmpty()) { if (!UserConfig.isClientActivated()) { actionBarLayout.addFragmentToStack(new LoginActivity()); drawerLayoutContainer.setAllowOpenDrawer(false, false); } else { actionBarLayout.addFragmentToStack(new DialogsActivity(null)); drawerLayoutContainer.setAllowOpenDrawer(true, false); } } } actionBarLayout.showLastFragment(); if (AndroidUtilities.isTablet()) { layersActionBarLayout.showLastFragment(); rightActionBarLayout.showLastFragment(); } } intent.setAction(null); return pushOpened; } return false; }