Search in sources :

Example 1 with ThemePreviewActivity

use of org.telegram.ui.ThemePreviewActivity in project Telegram-FOSS by Telegram-FOSS-Team.

the class AlertsCreator method createThemeCreateDialog.

public static void createThemeCreateDialog(BaseFragment fragment, int type, Theme.ThemeInfo switchToTheme, Theme.ThemeAccent switchToAccent) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    final EditTextBoldCursor editText = new EditTextBoldCursor(context);
    editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("Create", R.string.Create), (dialog, which) -> {
    });
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);
    final TextView message = new TextView(context);
    if (type != 0) {
        message.setText(AndroidUtilities.replaceTags(LocaleController.getString("EnterThemeNameEdit", R.string.EnterThemeNameEdit)));
    } else {
        message.setText(LocaleController.getString("EnterThemeName", R.string.EnterThemeName));
    }
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23), AndroidUtilities.dp(6));
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    linearLayout.addView(message, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    editText.setGravity(Gravity.LEFT | Gravity.TOP);
    editText.setSingleLine(true);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorSize(AndroidUtilities.dp(20));
    editText.setCursorWidth(1.5f);
    editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
    linearLayout.addView(editText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
    editText.setOnEditorActionListener((textView, i, keyEvent) -> {
        AndroidUtilities.hideKeyboard(textView);
        return false;
    });
    editText.setText(generateThemeName(switchToAccent));
    editText.setSelection(editText.length());
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    }));
    fragment.showDialog(alertDialog);
    editText.requestFocus();
    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (fragment.getParentActivity() == null) {
            return;
        }
        if (editText.length() == 0) {
            Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator != null) {
                vibrator.vibrate(200);
            }
            AndroidUtilities.shakeView(editText, 2, 0);
            return;
        }
        if (fragment instanceof ThemePreviewActivity) {
            Theme.applyPreviousTheme();
            fragment.finishFragment();
        }
        if (switchToAccent != null) {
            switchToTheme.setCurrentAccentId(switchToAccent.id);
            Theme.refreshThemeColors();
            Utilities.searchQueue.postRunnable(() -> AndroidUtilities.runOnUIThread(() -> processCreate(editText, alertDialog, fragment)));
            return;
        }
        processCreate(editText, alertDialog, fragment);
    });
}
Also used : Context(android.content.Context) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) TextView(android.widget.TextView) Vibrator(android.os.Vibrator) ThemePreviewActivity(org.telegram.ui.ThemePreviewActivity) LinearLayout(android.widget.LinearLayout)

Example 2 with ThemePreviewActivity

use of org.telegram.ui.ThemePreviewActivity in project Telegram-FOSS by Telegram-FOSS-Team.

the class AndroidUtilities method openDocument.

public static void openDocument(MessageObject message, Activity activity, BaseFragment parentFragment) {
    if (message == null) {
        return;
    }
    TLRPC.Document document = message.getDocument();
    if (document == null) {
        return;
    }
    File f = null;
    String fileName = message.messageOwner.media != null ? FileLoader.getAttachFileName(document) : "";
    if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
        f = new File(message.messageOwner.attachPath);
    }
    if (f == null || f != null && !f.exists()) {
        f = FileLoader.getPathToMessage(message.messageOwner);
    }
    if (f != null && f.exists()) {
        if (parentFragment != null && f.getName().toLowerCase().endsWith("attheme")) {
            Theme.ThemeInfo themeInfo = Theme.applyThemeFile(f, message.getDocumentName(), null, true);
            if (themeInfo != null) {
                parentFragment.presentFragment(new ThemePreviewActivity(themeInfo));
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setMessage(LocaleController.getString("IncorrectTheme", R.string.IncorrectTheme));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                parentFragment.showDialog(builder.create());
            }
        } else {
            String realMimeType = null;
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                MimeTypeMap myMime = MimeTypeMap.getSingleton();
                int idx = fileName.lastIndexOf('.');
                if (idx != -1) {
                    String ext = fileName.substring(idx + 1);
                    realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
                    if (realMimeType == null) {
                        realMimeType = document.mime_type;
                        if (realMimeType == null || realMimeType.length() == 0) {
                            realMimeType = null;
                        }
                    }
                }
                if (Build.VERSION.SDK_INT >= 24) {
                    intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain");
                } else {
                    intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain");
                }
                if (realMimeType != null) {
                    try {
                        activity.startActivityForResult(intent, 500);
                    } catch (Exception e) {
                        if (Build.VERSION.SDK_INT >= 24) {
                            intent.setDataAndType(FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", f), "text/plain");
                        } else {
                            intent.setDataAndType(Uri.fromFile(f), "text/plain");
                        }
                        activity.startActivityForResult(intent, 500);
                    }
                } else {
                    activity.startActivityForResult(intent, 500);
                }
            } catch (Exception e) {
                if (activity == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.getDocument().mime_type));
                if (parentFragment != null) {
                    parentFragment.showDialog(builder.create());
                } else {
                    builder.show();
                }
            }
        }
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) Intent(android.content.Intent) SpannedString(android.text.SpannedString) ThemePreviewActivity(org.telegram.ui.ThemePreviewActivity) MimeTypeMap(android.webkit.MimeTypeMap) TLRPC(org.telegram.tgnet.TLRPC) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) IOException(java.io.IOException) Theme(org.telegram.ui.ActionBar.Theme) File(java.io.File)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)2 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)2 ThemePreviewActivity (org.telegram.ui.ThemePreviewActivity)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Vibrator (android.os.Vibrator)1 SpannedString (android.text.SpannedString)1 TextPaint (android.text.TextPaint)1 MimeTypeMap (android.webkit.MimeTypeMap)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 File (java.io.File)1 IOException (java.io.IOException)1 TLRPC (org.telegram.tgnet.TLRPC)1 Theme (org.telegram.ui.ActionBar.Theme)1