Java Code Examples for org.telegram.ui.ActionBar.BaseFragment#showDialog()

The following examples show how to use org.telegram.ui.ActionBar.BaseFragment#showDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment)
{
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null)
    {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60)
    {
        timeString = LocaleController.formatPluralString("Seconds", time);
    }
    else
    {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 2
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment) {
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60) {
        timeString = LocaleController.formatPluralString("Seconds", time);
    } else {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 3
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment) {
    try {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        if (fragment.getParentActivity() == null) {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage(LocaleController.getString("InstallGoogleMaps", R.string.InstallGoogleMaps));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            } catch (Exception e1) {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example 4
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment)
{
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null)
    {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60)
    {
        timeString = LocaleController.formatPluralString("Seconds", time);
    }
    else
    {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 5
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void showSendMediaAlert(int result, final BaseFragment fragment)
{
    if (result == 0)
    {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (result == 1)
    {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickers", R.string.ErrorSendRestrictedStickers));
    }
    else if (result == 2)
    {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedMedia", R.string.ErrorSendRestrictedMedia));
    }
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 6
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static void showSendMediaAlert(int result, final BaseFragment fragment) {
    if (result == 0) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (result == 1) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickers", R.string.ErrorSendRestrictedStickers));
    } else if (result == 2) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedMedia", R.string.ErrorSendRestrictedMedia));
    } else if (result == 3) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedPolls", R.string.ErrorSendRestrictedPolls));
    } else if (result == 4) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedStickersAll", R.string.ErrorSendRestrictedStickersAll));
    } else if (result == 5) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedMediaAll", R.string.ErrorSendRestrictedMediaAll));
    } else if (result == 6) {
        builder.setMessage(LocaleController.getString("ErrorSendRestrictedPollsAll", R.string.ErrorSendRestrictedPollsAll));
    }

    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 7
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static void showFloodWaitAlert(String error, final BaseFragment fragment) {
    if (error == null || !error.startsWith("FLOOD_WAIT") || fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    int time = Utilities.parseInt(error);
    String timeString;
    if (time < 60) {
        timeString = LocaleController.formatPluralString("Seconds", time);
    } else {
        timeString = LocaleController.formatPluralString("Minutes", time / 60);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    fragment.showDialog(builder.create(), true, null);
}
 
Example 8
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String text)
{
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null)
    {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example 9
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
    } else {
        String urlFinal;
        if (punycode) {
            try {
                Uri uri = Uri.parse(url);
                String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
                urlFinal = uri.getScheme() + "://" + host + uri.getPath();
            } catch (Exception e) {
                FileLog.e(e);
                urlFinal = url;
            }
        } else {
            urlFinal = url;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
        String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
        int index = format.indexOf("%");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
        if (index >= 0) {
            stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setMessage(stringBuilder);
        builder.setMessageTextViewClickable(false);
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
    }
}
 
Example 10
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String title, final String text) {
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null) {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), title, text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example 11
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
    } else {
        String urlFinal;
        if (punycode) {
            try {
                Uri uri = Uri.parse(url);
                String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
                urlFinal = uri.getScheme() + "://" + host + uri.getPath();
            } catch (Exception e) {
                FileLog.e(e);
                urlFinal = url;
            }
        } else {
            urlFinal = url;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
        String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
        int index = format.indexOf("%");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
        if (index >= 0) {
            stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setMessage(stringBuilder);
        builder.setMessageTextViewClickable(false);
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
    }
}
 
Example 12
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static Dialog showSimpleAlert(BaseFragment baseFragment, final String text)
{
    if (text == null || baseFragment == null || baseFragment.getParentActivity() == null)
    {
        return null;
    }
    AlertDialog.Builder builder = createSimpleAlert(baseFragment.getParentActivity(), text);
    Dialog dialog = builder.create();
    baseFragment.showDialog(dialog);
    return dialog;
}
 
Example 13
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment)
{
    try
    {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    }
    catch (PackageManager.NameNotFoundException e)
    {
        if (fragment.getParentActivity() == null)
        {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage("Install Google Maps?");
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) ->
        {
            try
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            }
            catch (Exception e1)
            {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example 14
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGoogleMapsInstalled(final BaseFragment fragment)
{
    try
    {
        ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
        return true;
    }
    catch (PackageManager.NameNotFoundException e)
    {
        if (fragment.getParentActivity() == null)
        {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setMessage("Install Google Maps?");
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) ->
        {
            try
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
                fragment.getParentActivity().startActivityForResult(intent, 500);
            }
            catch (Exception e1)
            {
                FileLog.e(e1);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
        return false;
    }
}
 
Example 15
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    AlertDialog alertDialog = builder.create();
    fragment.showDialog(alertDialog);
    TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}
 
Example 16
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
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(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);
    });
}
 
Example 17
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void openSharing(BaseFragment fragment, String url) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    fragment.showDialog(new ShareAlert(fragment.getParentActivity(), null, url, false, url, false));
}
 
Example 18
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
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(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);
    });
}
 
Example 19
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static void openSharing(BaseFragment fragment, String url) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    fragment.showDialog(new ShareAlert(fragment.getParentActivity(), null, url, false, url, false));
}
 
Example 20
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static void createBlockDialogAlert(BaseFragment fragment, int count, boolean reportSpam, TLRPC.User user, BlockDialogCallback onProcessRunnable) {
    if (fragment == null || fragment.getParentActivity() == null || count == 1 && user == null) {
        return;
    }
    Context context = fragment.getParentActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    CheckBoxCell[] cell = new CheckBoxCell[2];

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    String actionText;
    if (count == 1) {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, name));
        actionText = LocaleController.getString("BlockUser", R.string.BlockUser);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUserMessage", R.string.BlockUserMessage, name)));
    } else {
        builder.setTitle(LocaleController.formatString("BlockUserTitle", R.string.BlockUserTitle, LocaleController.formatPluralString("UsersCountTitle", count)));
        actionText = LocaleController.getString("BlockUsers", R.string.BlockUsers);
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BlockUsersMessage", R.string.BlockUsersMessage, LocaleController.formatPluralString("UsersCount", count))));
    }

    final boolean[] checks = new boolean[]{true, true};

    for (int a = 0; a < cell.length; a++) {
        if (a == 0 && !reportSpam) {
            continue;
        }
        int num = a;
        cell[a] = new CheckBoxCell(context, 1);
        cell[a].setBackgroundDrawable(Theme.getSelectorDrawable(false));
        if (a == 0) {
            cell[a].setText(LocaleController.getString("ReportSpamTitle", R.string.ReportSpamTitle), "", true, false);
        } else {
            cell[a].setText(count == 1 ? LocaleController.getString("DeleteThisChatBothSides", R.string.DeleteThisChatBothSides) : LocaleController.getString("DeleteTheseChatsBothSides", R.string.DeleteTheseChatsBothSides), "", true, false);
        }
        cell[a].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
        linearLayout.addView(cell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
        cell[a].setOnClickListener(v -> {
            CheckBoxCell cell1 = (CheckBoxCell) v;
            checks[num] = !checks[num];
            cell1.setChecked(checks[num], true);
        });
    }

    builder.setPositiveButton(actionText, (dialogInterface, i) -> onProcessRunnable.run(checks[0], checks[1]));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    AlertDialog alertDialog = builder.create();
    fragment.showDialog(alertDialog);
    TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (button != null) {
        button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
    }
}