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);
});
}
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();
}
}
}
}
}
Aggregations