List of usage examples for android.widget FrameLayout FrameLayout
public FrameLayout(@NonNull Context context)
From source file:org.telegram.ui.PassportActivity.java
private void createEmailInterface(Context context) { actionBar.setTitle(LocaleController.getString("PassportEmail", R.string.PassportEmail)); if (!TextUtils.isEmpty(currentEmail)) { TextSettingsCell settingsCell1 = new TextSettingsCell(context); settingsCell1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4)); settingsCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true)); settingsCell1.setText(LocaleController.formatString("PassportPhoneUseSame", R.string.PassportPhoneUseSame, currentEmail), false); linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); settingsCell1.setOnClickListener(v -> { useCurrentValue = true;//ww w . ja va2 s . c o m doneItem.callOnClick(); useCurrentValue = false; }); bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); bottomCell.setText(LocaleController.getString("PassportPhoneUseSameEmailInfo", R.string.PassportPhoneUseSameEmailInfo)); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } inputFields = new EditTextBoldCursor[1]; for (int a = 0; a < 1; a++) { ViewGroup container = new FrameLayout(context); linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50)); container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); inputFields[a] = new EditTextBoldCursor(context); inputFields[a].setTag(a); inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText)); inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setBackgroundDrawable(null); inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setCursorSize(AndroidUtilities.dp(20)); inputFields[a].setCursorWidth(1.5f); inputFields[a].setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); inputFields[a].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); switch (a) { case FIELD_EMAIL: inputFields[a].setHint(LocaleController.getString("PaymentShippingEmailPlaceholder", R.string.PaymentShippingEmailPlaceholder)); if (currentTypeValue != null && currentTypeValue.plain_data instanceof TLRPC.TL_securePlainEmail) { TLRPC.TL_securePlainEmail securePlainEmail = (TLRPC.TL_securePlainEmail) currentTypeValue.plain_data; if (!TextUtils.isEmpty(securePlainEmail.email)) { inputFields[a].setText(securePlainEmail.email); } } break; } inputFields[a].setSelection(inputFields[a].length()); inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6)); inputFields[a].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 12, 21, 6)); inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_DONE || i == EditorInfo.IME_ACTION_NEXT) { doneItem.callOnClick(); return true; } return false; }); } bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); bottomCell.setText(LocaleController.getString("PassportEmailUploadInfo", R.string.PassportEmailUploadInfo)); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
@SuppressLint("InlinedApi") private void openGridGallery() { final int tnSize = resources.getDimensionPixelSize(R.dimen.post_thumbnail_size); class GridGalleryAdapter extends ArrayAdapter<Triple<AttachmentModel, String, String>> implements View.OnClickListener, AbsListView.OnScrollListener { private final GridView view; private boolean selectingMode = false; private boolean[] isSelected = null; private volatile boolean isBusy = false; public GridGalleryAdapter(GridView view, List<Triple<AttachmentModel, String, String>> list) { super(activity, 0, list); this.view = view; this.isSelected = new boolean[list.size()]; }//from w w w.j ava 2 s. com @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { if (isBusy) setNonBusy(); isBusy = false; } else isBusy = true; } private void setNonBusy() { if (!downloadThumbnails()) return; for (int i = 0; i < view.getChildCount(); ++i) { View v = view.getChildAt(i); Object tnTag = v.findViewById(R.id.post_thumbnail_image).getTag(); if (tnTag == null || tnTag == Boolean.FALSE) fill(view.getPositionForView(v), v, false); } } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = new FrameLayout(activity); convertView.setLayoutParams(new AbsListView.LayoutParams(tnSize, tnSize)); ImageView tnImage = new ImageView(activity); tnImage.setLayoutParams(new FrameLayout.LayoutParams(tnSize, tnSize, Gravity.CENTER)); tnImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); tnImage.setId(R.id.post_thumbnail_image); ((FrameLayout) convertView).addView(tnImage); } convertView.setTag(getItem(position).getLeft()); safeRegisterForContextMenu(convertView); convertView.setOnClickListener(this); fill(position, convertView, isBusy); if (isSelected[position]) { /*ImageView overlay = new ImageView(activity); overlay.setImageResource(android.R.drawable.checkbox_on_background);*/ FrameLayout overlay = new FrameLayout(activity); overlay.setBackgroundColor(Color.argb(128, 0, 255, 0)); if (((FrameLayout) convertView).getChildCount() < 2) ((FrameLayout) convertView).addView(overlay); } else { if (((FrameLayout) convertView).getChildCount() > 1) ((FrameLayout) convertView).removeViewAt(1); } return convertView; } private void safeRegisterForContextMenu(View view) { try { view.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (presentationModel == null) { Fragment currentFragment = MainApplication .getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) { currentFragment.onCreateContextMenu(menu, v, menuInfo); } } else { BoardFragment.this.onCreateContextMenu(menu, v, menuInfo); } } }); } catch (Exception e) { Logger.e(TAG, e); } } @Override public void onClick(View v) { if (selectingMode) { int position = view.getPositionForView(v); isSelected[position] = !isSelected[position]; notifyDataSetChanged(); } else { BoardFragment fragment = BoardFragment.this; if (presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) fragment = (BoardFragment) currentFragment; } fragment.openAttachment((AttachmentModel) v.getTag()); } } private void fill(int position, View view, boolean isBusy) { AttachmentModel attachment = getItem(position).getLeft(); String attachmentHash = getItem(position).getMiddle(); ImageView tnImage = (ImageView) view.findViewById(R.id.post_thumbnail_image); if (attachment.thumbnail == null || attachment.thumbnail.length() == 0) { tnImage.setTag(Boolean.TRUE); tnImage.setImageResource(Attachments.getDefaultThumbnailResId(attachment.type)); return; } tnImage.setTag(Boolean.FALSE); CancellableTask imagesDownloadTask = BoardFragment.this.imagesDownloadTask; ExecutorService imagesDownloadExecutor = BoardFragment.this.imagesDownloadExecutor; if (presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) { imagesDownloadTask = ((BoardFragment) currentFragment).imagesDownloadTask; imagesDownloadExecutor = ((BoardFragment) currentFragment).imagesDownloadExecutor; } } bitmapCache.asyncGet(attachmentHash, attachment.thumbnail, tnSize, chan, localFile, imagesDownloadTask, tnImage, imagesDownloadExecutor, Async.UI_HANDLER, downloadThumbnails() && !isBusy, downloadThumbnails() ? (isBusy ? 0 : R.drawable.thumbnail_error) : Attachments.getDefaultThumbnailResId(attachment.type)); } public void setSelectingMode(boolean selectingMode) { this.selectingMode = selectingMode; if (!selectingMode) { Arrays.fill(isSelected, false); notifyDataSetChanged(); } } public void selectAll() { if (selectingMode) { Arrays.fill(isSelected, true); notifyDataSetChanged(); } } public void downloadSelected(final Runnable onFinish) { final Dialog progressDialog = ProgressDialog.show(activity, resources.getString(R.string.grid_gallery_dlg_title), resources.getString(R.string.grid_gallery_dlg_message), true, false); Async.runAsync(new Runnable() { @Override public void run() { BoardFragment fragment = BoardFragment.this; if (fragment.presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) fragment = (BoardFragment) currentFragment; } boolean flag = false; for (int i = 0; i < isSelected.length; ++i) if (isSelected[i]) if (!fragment.downloadFile(getItem(i).getLeft(), true)) flag = true; final boolean toast = flag; activity.runOnUiThread(new Runnable() { @Override public void run() { if (toast) Toast.makeText(activity, R.string.notification_download_exists_or_in_queue, Toast.LENGTH_LONG).show(); progressDialog.dismiss(); onFinish.run(); } }); } }); } } try { List<Triple<AttachmentModel, String, String>> list = presentationModel.getAttachments(); if (list == null) { Toast.makeText(activity, R.string.notifacation_updating_now, Toast.LENGTH_LONG).show(); return; } GridView grid = new GridView(activity); final GridGalleryAdapter gridAdapter = new GridGalleryAdapter(grid, list); grid.setNumColumns(GridView.AUTO_FIT); grid.setColumnWidth(tnSize); int spacing = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); grid.setVerticalSpacing(spacing); grid.setHorizontalSpacing(spacing); grid.setPadding(spacing, spacing, spacing, spacing); grid.setAdapter(gridAdapter); grid.setOnScrollListener(gridAdapter); grid.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)); final Button btnToSelecting = new Button(activity); btnToSelecting.setText(R.string.grid_gallery_select); CompatibilityUtils.setTextAppearance(btnToSelecting, android.R.style.TextAppearance_Small); btnToSelecting.setSingleLine(); btnToSelecting.setVisibility(View.VISIBLE); btnToSelecting.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutSelectingButtons = new LinearLayout(activity); layoutSelectingButtons.setOrientation(LinearLayout.HORIZONTAL); layoutSelectingButtons.setWeightSum(10f); Button btnDownload = new Button(activity); btnDownload.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.25f)); btnDownload.setText(R.string.grid_gallery_download); CompatibilityUtils.setTextAppearance(btnDownload, android.R.style.TextAppearance_Small); btnDownload.setSingleLine(); Button btnSelectAll = new Button(activity); btnSelectAll.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.75f)); btnSelectAll.setText(android.R.string.selectAll); CompatibilityUtils.setTextAppearance(btnSelectAll, android.R.style.TextAppearance_Small); btnSelectAll.setSingleLine(); Button btnCancel = new Button(activity); btnCancel.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3f)); btnCancel.setText(android.R.string.cancel); CompatibilityUtils.setTextAppearance(btnCancel, android.R.style.TextAppearance_Small); btnCancel.setSingleLine(); layoutSelectingButtons.addView(btnDownload); layoutSelectingButtons.addView(btnSelectAll); layoutSelectingButtons.addView(btnCancel); layoutSelectingButtons.setVisibility(View.GONE); layoutSelectingButtons.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); btnToSelecting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btnToSelecting.setVisibility(View.GONE); layoutSelectingButtons.setVisibility(View.VISIBLE); gridAdapter.setSelectingMode(true); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btnToSelecting.setVisibility(View.VISIBLE); layoutSelectingButtons.setVisibility(View.GONE); gridAdapter.setSelectingMode(false); } }); btnSelectAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gridAdapter.selectAll(); } }); btnDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gridAdapter.downloadSelected(new Runnable() { @Override public void run() { btnToSelecting.setVisibility(View.VISIBLE); layoutSelectingButtons.setVisibility(View.GONE); gridAdapter.setSelectingMode(false); } }); } }); LinearLayout dlgLayout = new LinearLayout(activity); dlgLayout.setOrientation(LinearLayout.VERTICAL); dlgLayout.addView(btnToSelecting); dlgLayout.addView(layoutSelectingButtons); dlgLayout.addView(grid); Dialog gridDialog = new Dialog(activity); gridDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); gridDialog.setContentView(dlgLayout); gridDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); gridDialog.show(); } catch (OutOfMemoryError oom) { MainApplication.freeMemory(); Logger.e(TAG, oom); Toast.makeText(activity, R.string.error_out_of_memory, Toast.LENGTH_LONG).show(); } }
From source file:org.telegram.ui.PassportActivity.java
private void createAddressInterface(Context context) { languageMap = new HashMap<>(); try {//from w w w. j a v a 2s.com BufferedReader reader = new BufferedReader( new InputStreamReader(context.getResources().getAssets().open("countries.txt"))); String line; while ((line = reader.readLine()) != null) { String[] args = line.split(";"); languageMap.put(args[1], args[2]); } reader.close(); } catch (Exception e) { FileLog.e(e); } topErrorCell = new TextInfoPrivacyCell(context); topErrorCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow)); topErrorCell.setPadding(0, AndroidUtilities.dp(7), 0, 0); linearLayout2.addView(topErrorCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); checkTopErrorCell(true); if (currentDocumentsType != null) { if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration)); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) { actionBar.setTitle(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration)); } headerCell = new HeaderCell(context); headerCell.setText(LocaleController.getString("PassportDocuments", R.string.PassportDocuments)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); documentsLayout = new LinearLayout(context); documentsLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(documentsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadDocumentCell = new TextSettingsCell(context); uploadDocumentCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); linearLayout2.addView(uploadDocumentCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadDocumentCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_DOCUMENTS; openAttachMenu(); }); bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); if (currentBotId != 0) { noAllDocumentsErrorText = LocaleController.getString("PassportAddAddressUploadInfo", R.string.PassportAddAddressUploadInfo); } else { if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) { noAllDocumentsErrorText = LocaleController.getString("PassportAddAgreementInfo", R.string.PassportAddAgreementInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) { noAllDocumentsErrorText = LocaleController.getString("PassportAddBillInfo", R.string.PassportAddBillInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) { noAllDocumentsErrorText = LocaleController.getString("PassportAddPassportRegistrationInfo", R.string.PassportAddPassportRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) { noAllDocumentsErrorText = LocaleController.getString("PassportAddTemporaryRegistrationInfo", R.string.PassportAddTemporaryRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) { noAllDocumentsErrorText = LocaleController.getString("PassportAddBankInfo", R.string.PassportAddBankInfo); } else { noAllDocumentsErrorText = ""; } } CharSequence text = noAllDocumentsErrorText; if (documentsErrors != null) { String errorText; if ((errorText = documentsErrors.get("files_all")) != null) { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText); stringBuilder.append("\n\n"); stringBuilder.append(noAllDocumentsErrorText); text = stringBuilder; stringBuilder.setSpan( new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); errorsValues.put("files_all", ""); } } bottomCell.setText(text); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (currentDocumentsType.translation_required) { headerCell = new HeaderCell(context); headerCell.setText(LocaleController.getString("PassportTranslation", R.string.PassportTranslation)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); translationLayout = new LinearLayout(context); translationLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(translationLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadTranslationCell = new TextSettingsCell(context); uploadTranslationCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); linearLayout2.addView(uploadTranslationCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadTranslationCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_TRANSLATION; openAttachMenu(); }); bottomCellTranslation = new TextInfoPrivacyCell(context); bottomCellTranslation.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); if (currentBotId != 0) { noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationUploadInfo", R.string.PassportAddTranslationUploadInfo); } else { if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) { noAllTranslationErrorText = LocaleController.getString( "PassportAddTranslationAgreementInfo", R.string.PassportAddTranslationAgreementInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) { noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBillInfo", R.string.PassportAddTranslationBillInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) { noAllTranslationErrorText = LocaleController.getString( "PassportAddTranslationPassportRegistrationInfo", R.string.PassportAddTranslationPassportRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) { noAllTranslationErrorText = LocaleController.getString( "PassportAddTranslationTemporaryRegistrationInfo", R.string.PassportAddTranslationTemporaryRegistrationInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) { noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBankInfo", R.string.PassportAddTranslationBankInfo); } else { noAllTranslationErrorText = ""; } } text = noAllTranslationErrorText; if (documentsErrors != null) { String errorText; if ((errorText = documentsErrors.get("translation_all")) != null) { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText); stringBuilder.append("\n\n"); stringBuilder.append(noAllTranslationErrorText); text = stringBuilder; stringBuilder.setSpan( new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); errorsValues.put("translation_all", ""); } } bottomCellTranslation.setText(text); linearLayout2.addView(bottomCellTranslation, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } } else { actionBar.setTitle(LocaleController.getString("PassportAddress", R.string.PassportAddress)); } headerCell = new HeaderCell(context); headerCell.setText(LocaleController.getString("PassportAddressHeader", R.string.PassportAddressHeader)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); inputFields = new EditTextBoldCursor[FIELD_ADDRESS_COUNT]; for (int a = 0; a < FIELD_ADDRESS_COUNT; a++) { final EditTextBoldCursor field = new EditTextBoldCursor(context); inputFields[a] = field; ViewGroup container = new FrameLayout(context) { private StaticLayout errorLayout; float offsetX; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34); errorLayout = field.getErrorLayout(width); if (errorLayout != null) { int lineCount = errorLayout.getLineCount(); if (lineCount > 1) { int height = AndroidUtilities.dp(64) + (errorLayout.getLineBottom(lineCount - 1) - errorLayout.getLineBottom(0)); heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); } if (LocaleController.isRTL) { float maxW = 0; for (int a = 0; a < lineCount; a++) { float l = errorLayout.getLineLeft(a); if (l != 0) { offsetX = 0; break; } maxW = Math.max(maxW, errorLayout.getLineWidth(a)); if (a == lineCount - 1) { offsetX = width - maxW; } } } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onDraw(Canvas canvas) { if (errorLayout != null) { canvas.save(); canvas.translate(AndroidUtilities.dp(21) + offsetX, field.getLineY() + AndroidUtilities.dp(3)); errorLayout.draw(canvas); canvas.restore(); } } }; container.setWillNotDraw(false); linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); if (a == FIELD_ADDRESS_COUNT - 1) { extraBackgroundView = new View(context); extraBackgroundView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(extraBackgroundView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 6)); } if (documentOnly && currentDocumentsType != null) { container.setVisibility(View.GONE); if (extraBackgroundView != null) { extraBackgroundView.setVisibility(View.GONE); } } inputFields[a].setTag(a); inputFields[a].setSupportRtlHint(true); inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText)); inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); inputFields[a].setTransformHintToHeader(true); inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setBackgroundDrawable(null); inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setCursorSize(AndroidUtilities.dp(20)); inputFields[a].setCursorWidth(1.5f); inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); if (a == FIELD_COUNTRY) { inputFields[a].setOnTouchListener((v, event) -> { if (getParentActivity() == null) { return false; } if (event.getAction() == MotionEvent.ACTION_UP) { CountrySelectActivity fragment = new CountrySelectActivity(false); fragment.setCountrySelectActivityDelegate((name, shortName) -> { inputFields[FIELD_COUNTRY].setText(name); currentCitizeship = shortName; }); presentFragment(fragment); } return true; }); inputFields[a].setInputType(0); inputFields[a].setFocusable(false); } else { inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI); } String value; final String key; switch (a) { case FIELD_STREET1: inputFields[a].setHintText(LocaleController.getString("PassportStreet1", R.string.PassportStreet1)); key = "street_line1"; break; case FIELD_STREET2: inputFields[a].setHintText(LocaleController.getString("PassportStreet2", R.string.PassportStreet2)); key = "street_line2"; break; case FIELD_CITY: inputFields[a].setHintText(LocaleController.getString("PassportCity", R.string.PassportCity)); key = "city"; break; case FIELD_STATE: inputFields[a].setHintText(LocaleController.getString("PassportState", R.string.PassportState)); key = "state"; break; case FIELD_COUNTRY: inputFields[a].setHintText(LocaleController.getString("PassportCountry", R.string.PassportCountry)); key = "country_code"; break; case FIELD_POSTCODE: inputFields[a] .setHintText(LocaleController.getString("PassportPostcode", R.string.PassportPostcode)); key = "post_code"; break; default: continue; } setFieldValues(currentValues, inputFields[a], key); if (a == FIELD_POSTCODE) { inputFields[a].addTextChangedListener(new TextWatcher() { private boolean ignore; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (ignore) { return; } ignore = true; boolean error = false; for (int a = 0; a < s.length(); a++) { char ch = s.charAt(a); if (!(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == '-' || ch == ' ')) { error = true; break; } } ignore = false; if (error) { field.setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly)); } else { checkFieldForError(field, key, s, false); } } }); InputFilter[] inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(10); inputFields[a].setFilters(inputFilters); } else { inputFields[a].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) { } @Override public void afterTextChanged(Editable s) { checkFieldForError(field, key, s, false); } }); } inputFields[a].setSelection(inputFields[a].length()); inputFields[a].setPadding(0, 0, 0, 0); inputFields[a] .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 64, Gravity.LEFT | Gravity.TOP, 21, 0, 21, 0)); inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_NEXT) { int num = (Integer) textView.getTag(); num++; if (num < inputFields.length) { if (inputFields[num].isFocusable()) { inputFields[num].requestFocus(); } else { inputFields[num] .dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0)); textView.clearFocus(); AndroidUtilities.hideKeyboard(textView); } } return true; } return false; }); } sectionCell = new ShadowSectionCell(context); linearLayout2.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (documentOnly && currentDocumentsType != null) { headerCell.setVisibility(View.GONE); sectionCell.setVisibility(View.GONE); } if ((currentBotId != 0 || currentDocumentsType == null) && currentTypeValue != null && !documentOnly || currentDocumentsTypeValue != null) { if (currentDocumentsTypeValue != null) { addDocumentViews(currentDocumentsTypeValue.files); addTranslationDocumentViews(currentDocumentsTypeValue.translation); } sectionCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); TextSettingsCell settingsCell1 = new TextSettingsCell(context); settingsCell1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); settingsCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true)); if (currentDocumentsType == null) { settingsCell1.setText(LocaleController.getString("PassportDeleteInfo", R.string.PassportDeleteInfo), false); } else { settingsCell1.setText( LocaleController.getString("PassportDeleteDocument", R.string.PassportDeleteDocument), false); } linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); settingsCell1.setOnClickListener(v -> createDocumentDeleteAlert()); sectionCell = new ShadowSectionCell(context); sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); linearLayout2.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } else { sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); if (documentOnly && currentDocumentsType != null) { bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); } } updateUploadText(UPLOADING_TYPE_DOCUMENTS); updateUploadText(UPLOADING_TYPE_TRANSLATION); }
From source file:org.telegram.ui.PassportActivity.java
private void createDocumentDeleteAlert() { final boolean checks[] = new boolean[] { true }; AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> { if (!documentOnly) { currentValues.clear();// www. j av a 2 s. co m } currentDocumentValues.clear(); delegate.deleteValue(currentType, currentDocumentsType, availableDocumentTypes, checks[0], null, null); finishFragment(); }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (documentOnly && currentDocumentsType == null && currentType.type instanceof TLRPC.TL_secureValueTypeAddress) { builder.setMessage( LocaleController.getString("PassportDeleteAddressAlert", R.string.PassportDeleteAddressAlert)); } else if (documentOnly && currentDocumentsType == null && currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) { builder.setMessage(LocaleController.getString("PassportDeletePersonalAlert", R.string.PassportDeletePersonalAlert)); } else { builder.setMessage(LocaleController.getString("PassportDeleteDocumentAlert", R.string.PassportDeleteDocumentAlert)); } if (!documentOnly && currentDocumentsType != null) { FrameLayout frameLayout = new FrameLayout(getParentActivity()); CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1); cell.setBackgroundDrawable(Theme.getSelectorDrawable(false)); if (currentType.type instanceof TLRPC.TL_secureValueTypeAddress) { cell.setText(LocaleController.getString("PassportDeleteDocumentAddress", R.string.PassportDeleteDocumentAddress), "", true, false); } else if (currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) { cell.setText(LocaleController.getString("PassportDeleteDocumentPersonal", R.string.PassportDeleteDocumentPersonal), "", true, false); } cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT)); cell.setOnClickListener(v -> { if (!v.isEnabled()) { return; } CheckBoxCell cell1 = (CheckBoxCell) v; checks[0] = !checks[0]; cell1.setChecked(checks[0], true); }); builder.setView(frameLayout); } showDialog(builder.create()); }
From source file:org.telegram.ui.PassportActivity.java
private void createIdentityInterface(final Context context) { languageMap = new HashMap<>(); try {/* w w w . ja v a2 s . c om*/ BufferedReader reader = new BufferedReader( new InputStreamReader(context.getResources().getAssets().open("countries.txt"))); String line; while ((line = reader.readLine()) != null) { String[] args = line.split(";"); languageMap.put(args[1], args[2]); } reader.close(); } catch (Exception e) { FileLog.e(e); } topErrorCell = new TextInfoPrivacyCell(context); topErrorCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow)); topErrorCell.setPadding(0, AndroidUtilities.dp(7), 0, 0); linearLayout2.addView(topErrorCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); checkTopErrorCell(true); if (currentDocumentsType != null) { headerCell = new HeaderCell(context); if (documentOnly) { headerCell.setText(LocaleController.getString("PassportDocuments", R.string.PassportDocuments)); } else { headerCell.setText(LocaleController.getString("PassportRequiredDocuments", R.string.PassportRequiredDocuments)); } headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); frontLayout = new LinearLayout(context); frontLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(frontLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadFrontCell = new TextDetailSettingsCell(context); uploadFrontCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); linearLayout2.addView(uploadFrontCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadFrontCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_FRONT; openAttachMenu(); }); reverseLayout = new LinearLayout(context); reverseLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(reverseLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); boolean divider = currentDocumentsType.selfie_required; uploadReverseCell = new TextDetailSettingsCell(context); uploadReverseCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); uploadReverseCell.setTextAndValue( LocaleController.getString("PassportReverseSide", R.string.PassportReverseSide), LocaleController.getString("PassportReverseSideInfo", R.string.PassportReverseSideInfo), divider); linearLayout2.addView(uploadReverseCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadReverseCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_REVERSE; openAttachMenu(); }); if (currentDocumentsType.selfie_required) { selfieLayout = new LinearLayout(context); selfieLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(selfieLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadSelfieCell = new TextDetailSettingsCell(context); uploadSelfieCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); uploadSelfieCell.setTextAndValue( LocaleController.getString("PassportSelfie", R.string.PassportSelfie), LocaleController.getString("PassportSelfieInfo", R.string.PassportSelfieInfo), currentType.translation_required); linearLayout2.addView(uploadSelfieCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadSelfieCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_SELFIE; openAttachMenu(); }); } bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); bottomCell.setText( LocaleController.getString("PassportPersonalUploadInfo", R.string.PassportPersonalUploadInfo)); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (currentDocumentsType.translation_required) { headerCell = new HeaderCell(context); headerCell.setText(LocaleController.getString("PassportTranslation", R.string.PassportTranslation)); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); translationLayout = new LinearLayout(context); translationLayout.setOrientation(LinearLayout.VERTICAL); linearLayout2.addView(translationLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadTranslationCell = new TextSettingsCell(context); uploadTranslationCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); linearLayout2.addView(uploadTranslationCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); uploadTranslationCell.setOnClickListener(v -> { uploadingFileType = UPLOADING_TYPE_TRANSLATION; openAttachMenu(); }); bottomCellTranslation = new TextInfoPrivacyCell(context); bottomCellTranslation.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); if (currentBotId != 0) { noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationUploadInfo", R.string.PassportAddTranslationUploadInfo); } else { if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassport) { noAllTranslationErrorText = LocaleController.getString("PassportAddPassportInfo", R.string.PassportAddPassportInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeInternalPassport) { noAllTranslationErrorText = LocaleController.getString("PassportAddInternalPassportInfo", R.string.PassportAddInternalPassportInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeIdentityCard) { noAllTranslationErrorText = LocaleController.getString("PassportAddIdentityCardInfo", R.string.PassportAddIdentityCardInfo); } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense) { noAllTranslationErrorText = LocaleController.getString("PassportAddDriverLicenceInfo", R.string.PassportAddDriverLicenceInfo); } else { noAllTranslationErrorText = ""; } } CharSequence text = noAllTranslationErrorText; if (documentsErrors != null) { String errorText; if ((errorText = documentsErrors.get("translation_all")) != null) { SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText); stringBuilder.append("\n\n"); stringBuilder.append(noAllTranslationErrorText); text = stringBuilder; stringBuilder.setSpan( new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); errorsValues.put("translation_all", ""); } } bottomCellTranslation.setText(text); linearLayout2.addView(bottomCellTranslation, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } } else if (Build.VERSION.SDK_INT >= 18) { scanDocumentCell = new TextSettingsCell(context); scanDocumentCell.setBackgroundDrawable(Theme.getSelectorDrawable(true)); scanDocumentCell.setText( LocaleController.getString("PassportScanPassport", R.string.PassportScanPassport), false); linearLayout2.addView(scanDocumentCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); scanDocumentCell.setOnClickListener(v -> { if (Build.VERSION.SDK_INT >= 23 && getParentActivity() .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 22); return; } MrzCameraActivity fragment = new MrzCameraActivity(); fragment.setDelegate(result -> { if (!TextUtils.isEmpty(result.firstName)) { inputFields[FIELD_NAME].setText(result.firstName); } if (!TextUtils.isEmpty(result.middleName)) { inputFields[FIELD_MIDNAME].setText(result.middleName); } if (!TextUtils.isEmpty(result.lastName)) { inputFields[FIELD_SURNAME].setText(result.lastName); } if (result.gender != MrzRecognizer.Result.GENDER_UNKNOWN) { switch (result.gender) { case MrzRecognizer.Result.GENDER_MALE: currentGender = "male"; inputFields[FIELD_GENDER] .setText(LocaleController.getString("PassportMale", R.string.PassportMale)); break; case MrzRecognizer.Result.GENDER_FEMALE: currentGender = "female"; inputFields[FIELD_GENDER] .setText(LocaleController.getString("PassportFemale", R.string.PassportFemale)); break; } } if (!TextUtils.isEmpty(result.nationality)) { currentCitizeship = result.nationality; String country = languageMap.get(currentCitizeship); if (country != null) { inputFields[FIELD_CITIZENSHIP].setText(country); } } if (!TextUtils.isEmpty(result.issuingCountry)) { currentResidence = result.issuingCountry; String country = languageMap.get(currentResidence); if (country != null) { inputFields[FIELD_RESIDENCE].setText(country); } } if (result.birthDay > 0 && result.birthMonth > 0 && result.birthYear > 0) { inputFields[FIELD_BIRTHDAY].setText(String.format(Locale.US, "%02d.%02d.%d", result.birthDay, result.birthMonth, result.birthYear)); } }); presentFragment(fragment); }); bottomCell = new TextInfoPrivacyCell(context); bottomCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); bottomCell.setText( LocaleController.getString("PassportScanPassportInfo", R.string.PassportScanPassportInfo)); linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } headerCell = new HeaderCell(context); if (documentOnly) { headerCell.setText(LocaleController.getString("PassportDocument", R.string.PassportDocument)); } else { headerCell.setText(LocaleController.getString("PassportPersonal", R.string.PassportPersonal)); } headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); int count = currentDocumentsType != null ? FIELD_IDENTITY_COUNT : FIELD_IDENTITY_NODOC_COUNT; inputFields = new EditTextBoldCursor[count]; for (int a = 0; a < count; a++) { final EditTextBoldCursor field = new EditTextBoldCursor(context); inputFields[a] = field; ViewGroup container = new FrameLayout(context) { private StaticLayout errorLayout; private float offsetX; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34); errorLayout = field.getErrorLayout(width); if (errorLayout != null) { int lineCount = errorLayout.getLineCount(); if (lineCount > 1) { int height = AndroidUtilities.dp(64) + (errorLayout.getLineBottom(lineCount - 1) - errorLayout.getLineBottom(0)); heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); } if (LocaleController.isRTL) { float maxW = 0; for (int a = 0; a < lineCount; a++) { float l = errorLayout.getLineLeft(a); if (l != 0) { offsetX = 0; break; } maxW = Math.max(maxW, errorLayout.getLineWidth(a)); if (a == lineCount - 1) { offsetX = width - maxW; } } } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onDraw(Canvas canvas) { if (errorLayout != null) { canvas.save(); canvas.translate(AndroidUtilities.dp(21) + offsetX, field.getLineY() + AndroidUtilities.dp(3)); errorLayout.draw(canvas); canvas.restore(); } } }; container.setWillNotDraw(false); linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 64)); container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); if (a == count - 1) { extraBackgroundView = new View(context); extraBackgroundView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(extraBackgroundView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 6)); } if (documentOnly && currentDocumentsType != null && a < FIELD_CARDNUMBER) { container.setVisibility(View.GONE); if (extraBackgroundView != null) { extraBackgroundView.setVisibility(View.GONE); } } inputFields[a].setTag(a); inputFields[a].setSupportRtlHint(true); inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText)); inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); inputFields[a].setTransformHintToHeader(true); inputFields[a].setBackgroundDrawable(null); inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputFields[a].setCursorSize(AndroidUtilities.dp(20)); inputFields[a].setCursorWidth(1.5f); inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); if (a == FIELD_CITIZENSHIP || a == FIELD_RESIDENCE) { inputFields[a].setOnTouchListener((v, event) -> { if (getParentActivity() == null) { return false; } if (event.getAction() == MotionEvent.ACTION_UP) { CountrySelectActivity fragment = new CountrySelectActivity(false); fragment.setCountrySelectActivityDelegate((name, shortName) -> { int field12 = (Integer) v.getTag(); final EditTextBoldCursor editText = inputFields[field12]; if (field12 == FIELD_CITIZENSHIP) { currentCitizeship = shortName; } else { currentResidence = shortName; } editText.setText(name); }); presentFragment(fragment); } return true; }); inputFields[a].setInputType(0); } else if (a == FIELD_BIRTHDAY || a == FIELD_EXPIRE) { inputFields[a].setOnTouchListener((v, event) -> { if (getParentActivity() == null) { return false; } if (event.getAction() == MotionEvent.ACTION_UP) { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int monthOfYear = calendar.get(Calendar.MONTH); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); try { final EditTextBoldCursor field1 = (EditTextBoldCursor) v; int num = (Integer) field1.getTag(); int minYear; int maxYear; int currentYearDiff; String title; if (num == FIELD_EXPIRE) { title = LocaleController.getString("PassportSelectExpiredDate", R.string.PassportSelectExpiredDate); minYear = 0; maxYear = 20; currentYearDiff = 0; } else { title = LocaleController.getString("PassportSelectBithdayDate", R.string.PassportSelectBithdayDate); minYear = -120; maxYear = 0; currentYearDiff = -18; } int selectedDay = -1; int selectedMonth = -1; int selectedYear = -1; String args[] = field1.getText().toString().split("\\."); if (args.length == 3) { selectedDay = Utilities.parseInt(args[0]); selectedMonth = Utilities.parseInt(args[1]); selectedYear = Utilities.parseInt(args[2]); } AlertDialog.Builder builder = AlertsCreator.createDatePickerDialog(context, minYear, maxYear, currentYearDiff, selectedDay, selectedMonth, selectedYear, title, num == FIELD_EXPIRE, (year1, month, dayOfMonth1) -> { if (num == FIELD_EXPIRE) { currentExpireDate[0] = year1; currentExpireDate[1] = month + 1; currentExpireDate[2] = dayOfMonth1; } field1.setText(String.format(Locale.US, "%02d.%02d.%d", dayOfMonth1, month + 1, year1)); }); if (num == FIELD_EXPIRE) { builder.setNegativeButton(LocaleController.getString("PassportSelectNotExpire", R.string.PassportSelectNotExpire), (dialog, which) -> { currentExpireDate[0] = currentExpireDate[1] = currentExpireDate[2] = 0; field1.setText(LocaleController.getString("PassportNoExpireDate", R.string.PassportNoExpireDate)); }); } showDialog(builder.create()); } catch (Exception e) { FileLog.e(e); } } return true; }); inputFields[a].setInputType(0); inputFields[a].setFocusable(false); } else if (a == FIELD_GENDER) { inputFields[a].setOnTouchListener((v, event) -> { if (getParentActivity() == null) { return false; } if (event.getAction() == MotionEvent.ACTION_UP) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("PassportSelectGender", R.string.PassportSelectGender)); builder.setItems( new CharSequence[] { LocaleController.getString("PassportMale", R.string.PassportMale), LocaleController.getString("PassportFemale", R.string.PassportFemale) }, (dialogInterface, i) -> { if (i == 0) { currentGender = "male"; inputFields[FIELD_GENDER].setText( LocaleController.getString("PassportMale", R.string.PassportMale)); } else if (i == 1) { currentGender = "female"; inputFields[FIELD_GENDER].setText(LocaleController .getString("PassportFemale", R.string.PassportFemale)); } }); builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } return true; }); inputFields[a].setInputType(0); inputFields[a].setFocusable(false); } else { inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI); } String value; final String key; HashMap<String, String> values; switch (a) { case FIELD_NAME: if (currentType.native_names) { inputFields[a].setHintText( LocaleController.getString("PassportNameLatin", R.string.PassportNameLatin)); } else { inputFields[a].setHintText(LocaleController.getString("PassportName", R.string.PassportName)); } key = "first_name"; values = currentValues; break; case FIELD_MIDNAME: if (currentType.native_names) { inputFields[a].setHintText( LocaleController.getString("PassportMidnameLatin", R.string.PassportMidnameLatin)); } else { inputFields[a] .setHintText(LocaleController.getString("PassportMidname", R.string.PassportMidname)); } key = "middle_name"; values = currentValues; break; case FIELD_SURNAME: if (currentType.native_names) { inputFields[a].setHintText( LocaleController.getString("PassportSurnameLatin", R.string.PassportSurnameLatin)); } else { inputFields[a] .setHintText(LocaleController.getString("PassportSurname", R.string.PassportSurname)); } key = "last_name"; values = currentValues; break; case FIELD_BIRTHDAY: inputFields[a] .setHintText(LocaleController.getString("PassportBirthdate", R.string.PassportBirthdate)); key = "birth_date"; values = currentValues; break; case FIELD_GENDER: inputFields[a].setHintText(LocaleController.getString("PassportGender", R.string.PassportGender)); key = "gender"; values = currentValues; break; case FIELD_CITIZENSHIP: inputFields[a].setHintText( LocaleController.getString("PassportCitizenship", R.string.PassportCitizenship)); key = "country_code"; values = currentValues; break; case FIELD_RESIDENCE: inputFields[a] .setHintText(LocaleController.getString("PassportResidence", R.string.PassportResidence)); key = "residence_country_code"; values = currentValues; break; case FIELD_CARDNUMBER: inputFields[a].setHintText( LocaleController.getString("PassportDocumentNumber", R.string.PassportDocumentNumber)); key = "document_no"; values = currentDocumentValues; break; case FIELD_EXPIRE: inputFields[a].setHintText(LocaleController.getString("PassportExpired", R.string.PassportExpired)); key = "expiry_date"; values = currentDocumentValues; break; default: continue; } setFieldValues(values, inputFields[a], key); inputFields[a].setSelection(inputFields[a].length()); if (a == FIELD_NAME || a == FIELD_SURNAME || a == FIELD_MIDNAME) { inputFields[a].addTextChangedListener(new TextWatcher() { private boolean ignore; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (ignore) { return; } int num = (Integer) field.getTag(); boolean error = false; for (int a = 0; a < s.length(); a++) { char ch = s.charAt(a); if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == ' ' || ch == '\'' || ch == ',' || ch == '.' || ch == '&' || ch == '-' || ch == '/')) { error = true; break; } } if (error && !allowNonLatinName) { field.setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly)); } else { nonLatinNames[num] = error; checkFieldForError(field, key, s, false); } } }); } else { inputFields[a].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) { } @Override public void afterTextChanged(Editable s) { checkFieldForError(field, key, s, values == currentDocumentValues); int field12 = (Integer) field.getTag(); final EditTextBoldCursor editText = inputFields[field12]; if (field12 == FIELD_RESIDENCE) { checkNativeFields(true); } } }); } inputFields[a].setPadding(0, 0, 0, 0); inputFields[a] .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 21, 0, 21, 0)); inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_NEXT) { int num = (Integer) textView.getTag(); num++; if (num < inputFields.length) { if (inputFields[num].isFocusable()) { inputFields[num].requestFocus(); } else { inputFields[num] .dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0)); textView.clearFocus(); AndroidUtilities.hideKeyboard(textView); } } return true; } return false; }); } sectionCell2 = new ShadowSectionCell(context); linearLayout2.addView(sectionCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); headerCell = new HeaderCell(context); headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); inputExtraFields = new EditTextBoldCursor[FIELD_NATIVE_COUNT]; for (int a = 0; a < FIELD_NATIVE_COUNT; a++) { final EditTextBoldCursor field = new EditTextBoldCursor(context); inputExtraFields[a] = field; ViewGroup container = new FrameLayout(context) { private StaticLayout errorLayout; private float offsetX; @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34); errorLayout = field.getErrorLayout(width); if (errorLayout != null) { int lineCount = errorLayout.getLineCount(); if (lineCount > 1) { int height = AndroidUtilities.dp(64) + (errorLayout.getLineBottom(lineCount - 1) - errorLayout.getLineBottom(0)); heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); } if (LocaleController.isRTL) { float maxW = 0; for (int a = 0; a < lineCount; a++) { float l = errorLayout.getLineLeft(a); if (l != 0) { offsetX = 0; break; } maxW = Math.max(maxW, errorLayout.getLineWidth(a)); if (a == lineCount - 1) { offsetX = width - maxW; } } } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onDraw(Canvas canvas) { if (errorLayout != null) { canvas.save(); canvas.translate(AndroidUtilities.dp(21) + offsetX, field.getLineY() + AndroidUtilities.dp(3)); errorLayout.draw(canvas); canvas.restore(); } } }; container.setWillNotDraw(false); linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 64)); container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); if (a == FIELD_NATIVE_COUNT - 1) { extraBackgroundView2 = new View(context); extraBackgroundView2.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); linearLayout2.addView(extraBackgroundView2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 6)); } inputExtraFields[a].setTag(a); inputExtraFields[a].setSupportRtlHint(true); inputExtraFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); inputExtraFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText)); inputExtraFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputExtraFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); inputExtraFields[a].setTransformHintToHeader(true); inputExtraFields[a].setBackgroundDrawable(null); inputExtraFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); inputExtraFields[a].setCursorSize(AndroidUtilities.dp(20)); inputExtraFields[a].setCursorWidth(1.5f); inputExtraFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); inputExtraFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); inputExtraFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI); String value; final String key; HashMap<String, String> values; switch (a) { case FIELD_NATIVE_NAME: key = "first_name_native"; values = currentValues; break; case FIELD_NATIVE_MIDNAME: key = "middle_name_native"; values = currentValues; break; case FIELD_NATIVE_SURNAME: key = "last_name_native"; values = currentValues; break; default: continue; } setFieldValues(values, inputExtraFields[a], key); inputExtraFields[a].setSelection(inputExtraFields[a].length()); if (a == FIELD_NATIVE_NAME || a == FIELD_NATIVE_SURNAME || a == FIELD_NATIVE_MIDNAME) { inputExtraFields[a].addTextChangedListener(new TextWatcher() { private boolean ignore; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (ignore) { return; } checkFieldForError(field, key, s, false); } }); } inputExtraFields[a].setPadding(0, 0, 0, 0); inputExtraFields[a] .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); container.addView(inputExtraFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 21, 0, 21, 0)); inputExtraFields[a].setOnEditorActionListener((textView, i, keyEvent) -> { if (i == EditorInfo.IME_ACTION_NEXT) { int num = (Integer) textView.getTag(); num++; if (num < inputExtraFields.length) { if (inputExtraFields[num].isFocusable()) { inputExtraFields[num].requestFocus(); } else { inputExtraFields[num] .dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0)); textView.clearFocus(); AndroidUtilities.hideKeyboard(textView); } } return true; } return false; }); } nativeInfoCell = new TextInfoPrivacyCell(context); linearLayout2.addView(nativeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if ((currentBotId != 0 || currentDocumentsType == null) && currentTypeValue != null && !documentOnly || currentDocumentsTypeValue != null) { if (currentDocumentsTypeValue != null) { addDocumentViews(currentDocumentsTypeValue.files); if (currentDocumentsTypeValue.front_side instanceof TLRPC.TL_secureFile) { addDocumentViewInternal((TLRPC.TL_secureFile) currentDocumentsTypeValue.front_side, UPLOADING_TYPE_FRONT); } if (currentDocumentsTypeValue.reverse_side instanceof TLRPC.TL_secureFile) { addDocumentViewInternal((TLRPC.TL_secureFile) currentDocumentsTypeValue.reverse_side, UPLOADING_TYPE_REVERSE); } if (currentDocumentsTypeValue.selfie instanceof TLRPC.TL_secureFile) { addDocumentViewInternal((TLRPC.TL_secureFile) currentDocumentsTypeValue.selfie, UPLOADING_TYPE_SELFIE); } addTranslationDocumentViews(currentDocumentsTypeValue.translation); } TextSettingsCell settingsCell1 = new TextSettingsCell(context); settingsCell1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); settingsCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true)); if (currentDocumentsType == null) { settingsCell1.setText(LocaleController.getString("PassportDeleteInfo", R.string.PassportDeleteInfo), false); } else { settingsCell1.setText( LocaleController.getString("PassportDeleteDocument", R.string.PassportDeleteDocument), false); } linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); settingsCell1.setOnClickListener(v -> createDocumentDeleteAlert()); nativeInfoCell.setBackgroundDrawable( Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); sectionCell = new ShadowSectionCell(context); sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); linearLayout2.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); } else { nativeInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); } updateInterfaceStringsForDocumentType(); checkNativeFields(false); }
From source file:net.bluehack.ui.ChatActivity.java
private void createDeleteMessagesAlert(final MessageObject finalSelectedObject) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(//w w w . j ava 2 s. c om LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("messages", finalSelectedObject != null ? 1 : selectedMessagesIds[0].size() + selectedMessagesIds[1].size()))); builder.setTitle(LocaleController.getString("Message", R.string.Message)); final boolean[] checks = new boolean[3]; TLRPC.User user = null; if (currentChat != null && currentChat.megagroup) { if (finalSelectedObject != null) { if (finalSelectedObject.messageOwner.action == null || finalSelectedObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) { user = MessagesController.getInstance().getUser(finalSelectedObject.messageOwner.from_id); } } else { int from_id = -1; for (int a = 1; a >= 0; a--) { int channelId = 0; for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a].entrySet()) { MessageObject msg = entry.getValue(); if (from_id == -1) { from_id = msg.messageOwner.from_id; } if (from_id < 0 || from_id != msg.messageOwner.from_id) { from_id = -2; break; } } if (from_id == -2) { break; } } if (from_id != -1) { user = MessagesController.getInstance().getUser(from_id); } } if (user != null && user.id != UserConfig.getClientUserId()) { FrameLayout frameLayout = new FrameLayout(getParentActivity()); if (Build.VERSION.SDK_INT >= 21) { frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0); } for (int a = 0; a < 3; a++) { CheckBoxCell cell = new CheckBoxCell(getParentActivity()); cell.setBackgroundResource(R.drawable.list_selector); cell.setTag(a); if (a == 0) { cell.setText(LocaleController.getString("DeleteBanUser", R.string.DeleteBanUser), "", false, false); } else if (a == 1) { cell.setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", false, false); } else if (a == 2) { cell.setText( LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, ContactsController.formatName(user.first_name, user.last_name)), "", false, false); } cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 48 * a, 8, 0)); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBoxCell cell = (CheckBoxCell) v; Integer num = (Integer) cell.getTag(); checks[num] = !checks[num]; cell.setChecked(checks[num], true); } }); } builder.setView(frameLayout); } else { user = null; } } final TLRPC.User userFinal = user; builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ArrayList<Integer> ids = null; if (finalSelectedObject != null) { ids = new ArrayList<>(); ids.add(finalSelectedObject.getId()); ArrayList<Long> random_ids = null; if (currentEncryptedChat != null && finalSelectedObject.messageOwner.random_id != 0 && finalSelectedObject.type != 10) { random_ids = new ArrayList<>(); random_ids.add(finalSelectedObject.messageOwner.random_id); } MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, finalSelectedObject.messageOwner.to_id.channel_id); } else { for (int a = 1; a >= 0; a--) { ids = new ArrayList<>(selectedMessagesIds[a].keySet()); ArrayList<Long> random_ids = null; int channelId = 0; if (!ids.isEmpty()) { MessageObject msg = selectedMessagesIds[a].get(ids.get(0)); if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) { channelId = msg.messageOwner.to_id.channel_id; } } if (currentEncryptedChat != null) { random_ids = new ArrayList<>(); for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a] .entrySet()) { MessageObject msg = entry.getValue(); if (msg.messageOwner.random_id != 0 && msg.type != 10) { random_ids.add(msg.messageOwner.random_id); } } } MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId); } actionBar.hideActionMode(); updatePinnedMessageView(true); } if (userFinal != null) { if (checks[0]) { MessagesController.getInstance().deleteUserFromChat(currentChat.id, userFinal, info); } if (checks[1]) { TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam(); req.channel = MessagesController.getInputChannel(currentChat); req.user_id = MessagesController.getInputUser(userFinal); req.id = ids; ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { } }); } if (checks[2]) { MessagesController.getInstance().deleteUserChannelHistory(currentChat, userFinal, 0); } } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); }
From source file:kr.wdream.ui.ChatActivity.java
private void createDeleteMessagesAlert(final MessageObject finalSelectedObject) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", kr.wdream.storyshop.R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("messages", finalSelectedObject != null ? 1 : selectedMessagesIds[0].size() + selectedMessagesIds[1].size()))); builder.setTitle(LocaleController.getString("Message", kr.wdream.storyshop.R.string.Message)); final boolean[] checks = new boolean[3]; TLRPC.User user = null;/*from w w w . j a va 2 s.com*/ if (currentChat != null && currentChat.megagroup) { if (finalSelectedObject != null) { if (finalSelectedObject.messageOwner.action == null || finalSelectedObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) { user = MessagesController.getInstance().getUser(finalSelectedObject.messageOwner.from_id); } } else { int from_id = -1; for (int a = 1; a >= 0; a--) { int channelId = 0; for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a].entrySet()) { MessageObject msg = entry.getValue(); if (from_id == -1) { from_id = msg.messageOwner.from_id; } if (from_id < 0 || from_id != msg.messageOwner.from_id) { from_id = -2; break; } } if (from_id == -2) { break; } } if (from_id != -1) { user = MessagesController.getInstance().getUser(from_id); } } if (user != null && user.id != UserConfig.getClientUserId()) { FrameLayout frameLayout = new FrameLayout(getParentActivity()); if (Build.VERSION.SDK_INT >= 21) { frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0); } for (int a = 0; a < 3; a++) { CheckBoxCell cell = new CheckBoxCell(getParentActivity()); cell.setBackgroundResource(kr.wdream.storyshop.R.drawable.list_selector); cell.setTag(a); if (a == 0) { cell.setText(LocaleController.getString("DeleteBanUser", kr.wdream.storyshop.R.string.DeleteBanUser), "", false, false); } else if (a == 1) { cell.setText(LocaleController.getString("DeleteReportSpam", kr.wdream.storyshop.R.string.DeleteReportSpam), "", false, false); } else if (a == 2) { cell.setText( LocaleController.formatString("DeleteAllFrom", kr.wdream.storyshop.R.string.DeleteAllFrom, ContactsController.formatName(user.first_name, user.last_name)), "", false, false); } cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 48 * a, 8, 0)); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBoxCell cell = (CheckBoxCell) v; Integer num = (Integer) cell.getTag(); checks[num] = !checks[num]; cell.setChecked(checks[num], true); } }); } builder.setView(frameLayout); } else { user = null; } } final TLRPC.User userFinal = user; builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ArrayList<Integer> ids = null; if (finalSelectedObject != null) { ids = new ArrayList<>(); ids.add(finalSelectedObject.getId()); ArrayList<Long> random_ids = null; if (currentEncryptedChat != null && finalSelectedObject.messageOwner.random_id != 0 && finalSelectedObject.type != 10) { random_ids = new ArrayList<>(); random_ids.add(finalSelectedObject.messageOwner.random_id); } MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, finalSelectedObject.messageOwner.to_id.channel_id); } else { for (int a = 1; a >= 0; a--) { ids = new ArrayList<>(selectedMessagesIds[a].keySet()); ArrayList<Long> random_ids = null; int channelId = 0; if (!ids.isEmpty()) { MessageObject msg = selectedMessagesIds[a].get(ids.get(0)); if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) { channelId = msg.messageOwner.to_id.channel_id; } } if (currentEncryptedChat != null) { random_ids = new ArrayList<>(); for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a] .entrySet()) { MessageObject msg = entry.getValue(); if (msg.messageOwner.random_id != 0 && msg.type != 10) { random_ids.add(msg.messageOwner.random_id); } } } MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId); } actionBar.hideActionMode(); updatePinnedMessageView(true); } if (userFinal != null) { if (checks[0]) { MessagesController.getInstance().deleteUserFromChat(currentChat.id, userFinal, info); } if (checks[1]) { TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam(); req.channel = MessagesController.getInputChannel(currentChat); req.user_id = MessagesController.getInputUser(userFinal); req.id = ids; ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { } }); } if (checks[2]) { MessagesController.getInstance().deleteUserChannelHistory(currentChat, userFinal, 0); } } } }); builder.setNegativeButton(LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); }
From source file:net.bluehack.ui.ChatActivity.java
private void processSelectedOption(int option) { if (selectedObject == null) { return;//w ww . ja v a 2s.c o m } switch (option) { case 0: { if (SendMessagesHelper.getInstance().retrySendMessage(selectedObject, false)) { moveScrollToLastMessage(); } break; } case 1: { if (getParentActivity() == null) { selectedObject = null; return; } createDeleteMessagesAlert(selectedObject); break; } case 2: { forwaringMessage = selectedObject; Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(this); presentFragment(fragment); break; } case 3: { AndroidUtilities.addToClipboard(getMessageContent(selectedObject, 0, false)); break; } case 4: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (selectedObject.type == 3 || selectedObject.type == 1) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity() .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), selectedObject.type == 3 ? 1 : 0, null, null); } break; } case 5: { File locFile = null; if (selectedObject.messageOwner.attachPath != null && selectedObject.messageOwner.attachPath.length() != 0) { File f = new File(selectedObject.messageOwner.attachPath); if (f.exists()) { locFile = f; } } if (locFile == null) { File f = FileLoader.getPathToMessage(selectedObject.messageOwner); if (f.exists()) { locFile = f; } } if (locFile != null) { if (LocaleController.getInstance().applyLanguageFile(locFile)) { presentFragment(new LanguageSelectActivity()); } else { if (getParentActivity() == null) { selectedObject = null; return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage( LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); showDialog(builder.create()); } } break; } case 6: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(selectedObject.getDocument().mime_type); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); getParentActivity().startActivityForResult( Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500); break; } case 7: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), 0, null, null); break; } case 8: { showReplyPanel(true, selectedObject, null, null, false, true); break; } case 9: { showDialog(new StickersAlert(getParentActivity(), this, selectedObject.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE ? chatActivityEnterView : null)); break; } case 10: { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } String fileName = FileLoader.getDocumentFileName(selectedObject.getDocument()); if (fileName == null || fileName.length() == 0) { fileName = selectedObject.getFileName(); } String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } MediaController.saveFile(path, getParentActivity(), selectedObject.isMusic() ? 3 : 2, fileName, selectedObject.getDocument() != null ? selectedObject.getDocument().mime_type : ""); break; } case 11: { TLRPC.Document document = selectedObject.getDocument(); MessagesController.getInstance().saveGif(document); showGifHint(); chatActivityEnterView.addRecentGif(document); break; } case 12: { if (getParentActivity() == null) { selectedObject = null; return; } if (searchItem != null && actionBar.isSearchFieldVisible()) { actionBar.closeSearchField(); chatActivityEnterView.setFieldFocused(); } mentionsAdapter.setNeedBotContext(false); chatListView.setOnItemLongClickListener(null); chatListView.setOnItemClickListener(null); chatListView.setClickable(false); chatListView.setLongClickable(false); chatActivityEnterView.setEditingMessageObject(selectedObject, !selectedObject.isMediaEmpty()); if (chatActivityEnterView.isEditingCaption()) { mentionsAdapter.setAllowNewMentions(false); } actionModeTitleContainer.setVisibility(View.VISIBLE); selectedMessagesCountTextView.setVisibility(View.GONE); checkEditTimer(); chatActivityEnterView.setAllowStickersAndGifs(false, false); final ActionBarMenu actionMode = actionBar.createActionMode(); actionMode.getItem(reply).setVisibility(View.GONE); actionMode.getItem(copy).setVisibility(View.GONE); actionMode.getItem(forward).setVisibility(View.GONE); actionMode.getItem(delete).setVisibility(View.GONE); if (editDoneItemAnimation != null) { editDoneItemAnimation.cancel(); editDoneItemAnimation = null; } editDoneItem.setVisibility(View.VISIBLE); showEditDoneProgress(true, false); actionBar.showActionMode(); updatePinnedMessageView(true); updateVisibleRows(); TLRPC.TL_messages_getMessageEditData req = new TLRPC.TL_messages_getMessageEditData(); req.peer = MessagesController.getInputPeer((int) dialog_id); req.id = selectedObject.getId(); editingMessageObjectReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { editingMessageObjectReqId = 0; if (response == null) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage( LocaleController.getString("EditMessageError", R.string.EditMessageError)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); showDialog(builder.create()); if (chatActivityEnterView != null) { chatActivityEnterView.setEditingMessageObject(null, false); } } else { showEditDoneProgress(false, true); } } }); } }); break; } case 13: { final int mid = selectedObject.getId(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("PinMessageAlert", R.string.PinMessageAlert)); final boolean[] checks = new boolean[] { true }; FrameLayout frameLayout = new FrameLayout(getParentActivity()); if (Build.VERSION.SDK_INT >= 21) { frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0); } CheckBoxCell cell = new CheckBoxCell(getParentActivity()); cell.setBackgroundResource(R.drawable.list_selector); cell.setText(LocaleController.getString("PinNotify", R.string.PinNotify), "", true, false); cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0)); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBoxCell cell = (CheckBoxCell) v; checks[0] = !checks[0]; cell.setChecked(checks[0], true); } }); builder.setView(frameLayout); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, mid, checks[0]); } }); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); break; } case 14: { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("UnpinMessageAlert", R.string.UnpinMessageAlert)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, 0, false); } }); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); break; } case 15: { Bundle args = new Bundle(); args.putInt("user_id", selectedObject.messageOwner.media.user_id); args.putString("phone", selectedObject.messageOwner.media.phone_number); args.putBoolean("addContact", true); presentFragment(new ContactAddActivity(args)); break; } case 16: { AndroidUtilities.addToClipboard(selectedObject.messageOwner.media.phone_number); break; } case 17: { try { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + selectedObject.messageOwner.media.phone_number)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getParentActivity().startActivityForResult(intent, 500); } catch (Exception e) { FileLog.e("tmessages", e); } break; } } selectedObject = null; }
From source file:kr.wdream.ui.ChatActivity.java
private void processSelectedOption(int option) { if (selectedObject == null) { return;/* w w w. j a v a 2s .co m*/ } switch (option) { case 0: { if (SendMessagesHelper.getInstance().retrySendMessage(selectedObject, false)) { moveScrollToLastMessage(); } break; } case 1: { if (getParentActivity() == null) { selectedObject = null; return; } createDeleteMessagesAlert(selectedObject); break; } case 2: { forwaringMessage = selectedObject; Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(this); presentFragment(fragment); break; } case 3: { AndroidUtilities.addToClipboard(getMessageContent(selectedObject, 0, false)); break; } case 4: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (selectedObject.type == 3 || selectedObject.type == 1) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity() .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), selectedObject.type == 3 ? 1 : 0, null, null); } break; } case 5: { File locFile = null; if (selectedObject.messageOwner.attachPath != null && selectedObject.messageOwner.attachPath.length() != 0) { File f = new File(selectedObject.messageOwner.attachPath); if (f.exists()) { locFile = f; } } if (locFile == null) { File f = FileLoader.getPathToMessage(selectedObject.messageOwner); if (f.exists()) { locFile = f; } } if (locFile != null) { if (LocaleController.getInstance().applyLanguageFile(locFile)) { presentFragment(new LanguageSelectActivity()); } else { if (getParentActivity() == null) { selectedObject = null; return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage(LocaleController.getString("IncorrectLocalization", kr.wdream.storyshop.R.string.IncorrectLocalization)); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), null); showDialog(builder.create()); } } break; } case 6: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(selectedObject.getDocument().mime_type); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", kr.wdream.storyshop.R.string.ShareFile)), 500); break; } case 7: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), 0, null, null); break; } case 8: { showReplyPanel(true, selectedObject, null, null, false, true); break; } case 9: { showDialog(new StickersAlert(getParentActivity(), this, selectedObject.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE ? chatActivityEnterView : null)); break; } case 10: { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } String fileName = FileLoader.getDocumentFileName(selectedObject.getDocument()); if (fileName == null || fileName.length() == 0) { fileName = selectedObject.getFileName(); } String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } MediaController.saveFile(path, getParentActivity(), selectedObject.isMusic() ? 3 : 2, fileName, selectedObject.getDocument() != null ? selectedObject.getDocument().mime_type : ""); break; } case 11: { TLRPC.Document document = selectedObject.getDocument(); MessagesController.getInstance().saveGif(document); showGifHint(); chatActivityEnterView.addRecentGif(document); break; } case 12: { if (getParentActivity() == null) { selectedObject = null; return; } if (searchItem != null && actionBar.isSearchFieldVisible()) { actionBar.closeSearchField(); chatActivityEnterView.setFieldFocused(); } mentionsAdapter.setNeedBotContext(false); chatListView.setOnItemLongClickListener(null); chatListView.setOnItemClickListener(null); chatListView.setClickable(false); chatListView.setLongClickable(false); chatActivityEnterView.setEditingMessageObject(selectedObject, !selectedObject.isMediaEmpty()); if (chatActivityEnterView.isEditingCaption()) { mentionsAdapter.setAllowNewMentions(false); } actionModeTitleContainer.setVisibility(View.VISIBLE); selectedMessagesCountTextView.setVisibility(View.GONE); checkEditTimer(); chatActivityEnterView.setAllowStickersAndGifs(false, false); final ActionBarMenu actionMode = actionBar.createActionMode(); actionMode.getItem(reply).setVisibility(View.GONE); actionMode.getItem(copy).setVisibility(View.GONE); actionMode.getItem(forward).setVisibility(View.GONE); actionMode.getItem(delete).setVisibility(View.GONE); if (editDoneItemAnimation != null) { editDoneItemAnimation.cancel(); editDoneItemAnimation = null; } editDoneItem.setVisibility(View.VISIBLE); showEditDoneProgress(true, false); actionBar.showActionMode(); updatePinnedMessageView(true); updateVisibleRows(); TLRPC.TL_messages_getMessageEditData req = new TLRPC.TL_messages_getMessageEditData(); req.peer = MessagesController.getInputPeer((int) dialog_id); req.id = selectedObject.getId(); editingMessageObjectReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { editingMessageObjectReqId = 0; if (response == null) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage(LocaleController.getString("EditMessageError", kr.wdream.storyshop.R.string.EditMessageError)); builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), null); showDialog(builder.create()); if (chatActivityEnterView != null) { chatActivityEnterView.setEditingMessageObject(null, false); } } else { showEditDoneProgress(false, true); } } }); } }); break; } case 13: { final int mid = selectedObject.getId(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("PinMessageAlert", kr.wdream.storyshop.R.string.PinMessageAlert)); final boolean[] checks = new boolean[] { true }; FrameLayout frameLayout = new FrameLayout(getParentActivity()); if (Build.VERSION.SDK_INT >= 21) { frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0); } CheckBoxCell cell = new CheckBoxCell(getParentActivity()); cell.setBackgroundResource(kr.wdream.storyshop.R.drawable.list_selector); cell.setText(LocaleController.getString("PinNotify", kr.wdream.storyshop.R.string.PinNotify), "", true, false); cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0)); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBoxCell cell = (CheckBoxCell) v; checks[0] = !checks[0]; cell.setChecked(checks[0], true); } }); builder.setView(frameLayout); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, mid, checks[0]); } }); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); break; } case 14: { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("UnpinMessageAlert", kr.wdream.storyshop.R.string.UnpinMessageAlert)); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, 0, false); } }); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); break; } case 15: { Bundle args = new Bundle(); args.putInt("user_id", selectedObject.messageOwner.media.user_id); args.putString("phone", selectedObject.messageOwner.media.phone_number); args.putBoolean("addContact", true); presentFragment(new ContactAddActivity(args)); break; } case 16: { AndroidUtilities.addToClipboard(selectedObject.messageOwner.media.phone_number); break; } case 17: { try { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + selectedObject.messageOwner.media.phone_number)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getParentActivity().startActivityForResult(intent, 500); } catch (Exception e) { FileLog.e("tmessages", e); } break; } } selectedObject = null; }