Java Code Examples for org.telegram.ui.ActionBar.AlertDialog#Builder

The following examples show how to use org.telegram.ui.ActionBar.AlertDialog#Builder . 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: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void leaveChatPressed()
{
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    if (ChatObject.isChannel(chat_id, currentAccount) && !currentChat.megagroup)
    {
        builder.setMessage(ChatObject.isChannel(chat_id, currentAccount) ? LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert) : LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
    }
    else
    {
        builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
    }
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> kickUser(0));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    showDialog(builder.create());
}
 
Example 2
Source File: ChannelCreateActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void showErrorAlert(String error) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    switch (error) {
        case "USERNAME_INVALID":
            builder.setMessage(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
            break;
        case "USERNAME_OCCUPIED":
            builder.setMessage(LocaleController.getString("LinkInUse", R.string.LinkInUse));
            break;
        default:
            builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
            break;
    }
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example 3
Source File: ContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert) {
    Activity activity = getParentActivity();
    if (activity == null || !UserConfig.getInstance(currentAccount).syncContacts || activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return;
    }
    if (alert && askAboutContacts) {
        AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, new MessagesStorage.IntCallback() {
            @Override
            public void run(int param) {
                askAboutContacts = param != 0;
                MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).commit();
                askForPermissons(false);
            }
        });
        showDialog(builder.create());
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    permissons.add(Manifest.permission.READ_CONTACTS);
    permissons.add(Manifest.permission.WRITE_CONTACTS);
    permissons.add(Manifest.permission.GET_ACCOUNTS);
    String[] items = permissons.toArray(new String[permissons.size()]);
    activity.requestPermissions(items, 1);
}
 
Example 4
Source File: ChannelCreateActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void showErrorAlert(String error) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    switch (error) {
        case "USERNAME_INVALID":
            builder.setMessage(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
            break;
        case "USERNAME_OCCUPIED":
            builder.setMessage(LocaleController.getString("LinkInUse", R.string.LinkInUse));
            break;
        default:
            builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
            break;
    }
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example 5
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 6
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static AlertDialog showUpdateAppAlert(final Context context, final String text, boolean updateApp)
{
    if (context == null || text == null)
    {
        return null;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(text);
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    if (updateApp)
    {
        builder.setNegativeButton(LocaleController.getString("UpdateApp", R.string.UpdateApp), (dialog, which) -> Browser.openUrl(context, BuildVars.PLAYSTORE_APP_URL));
    }
    return builder.show();
}
 
Example 7
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 8
Source File: ChatAttachAlertPollLayout.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkDiscard() {
    boolean allowDiscard = TextUtils.isEmpty(getFixedString(questionString));
    if (allowDiscard) {
        for (int a = 0; a < answersCount; a++) {
            allowDiscard = TextUtils.isEmpty(getFixedString(answers[a]));
            if (!allowDiscard) {
                break;
            }
        }
    }
    if (!allowDiscard) {
        AlertDialog.Builder builder = new AlertDialog.Builder(parentAlert.baseFragment.getParentActivity());
        builder.setTitle(LocaleController.getString("CancelPollAlertTitle", R.string.CancelPollAlertTitle));
        builder.setMessage(LocaleController.getString("CancelPollAlertText", R.string.CancelPollAlertText));
        builder.setPositiveButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), (dialogInterface, i) -> parentAlert.dismiss());
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.show();
    }
    return allowDiscard;
}
 
Example 9
Source File: ThemePreviewActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkDiscard() {
    if (screenType == SCREEN_TYPE_ACCENT_COLOR && (
            accent.accentColor != backupAccentColor ||
            accent.myMessagesAccentColor != backupMyMessagesAccentColor ||
            accent.myMessagesGradientAccentColor != backupMyMessagesGradientAccentColor ||
            accent.backgroundOverrideColor != backupBackgroundOverrideColor ||
            accent.backgroundGradientOverrideColor != backupBackgroundGradientOverrideColor ||
            accent.backgroundRotation != backupBackgroundRotation ||
            !accent.patternSlug.equals(selectedPattern != null ? selectedPattern.slug : "") ||
            selectedPattern != null && accent.patternMotion != isMotion ||
            selectedPattern != null && accent.patternIntensity != currentIntensity
    )) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("SaveChangesAlertTitle", R.string.SaveChangesAlertTitle));
        builder.setMessage(LocaleController.getString("SaveChangesAlertText", R.string.SaveChangesAlertText));
        builder.setPositiveButton(LocaleController.getString("Save", R.string.Save), (dialogInterface, i) -> actionBar2.getActionBarMenuOnItemClick().onItemClick(4));
        builder.setNegativeButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), (dialog, which) -> cancelThemeApply(false));
        showDialog(builder.create());
        return false;
    }
    return true;
}
 
Example 10
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onLongPress() {
    if (baseFragment == null || currentUser == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(LocaleController.formatString("ChatHintsDelete", R.string.ChatHintsDelete, ContactsController.formatName(currentUser.first_name, currentUser.last_name)));
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> DataQuery.getInstance(currentAccount).removeInline(currentUser.id));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.show();
}
 
Example 11
Source File: VoIPHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void startCall(TLRPC.User user, final Activity activity, TLRPC.TL_userFull userFull){
	if(userFull!=null && userFull.phone_calls_private){
		new AlertDialog.Builder(activity)
				.setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed))
				.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("CallNotAvailable", R.string.CallNotAvailable,
						ContactsController.formatName(user.first_name, user.last_name))))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
				.show();
		return;
	}
	if (ConnectionsManager.getInstance(UserConfig.selectedAccount).getConnectionState() != ConnectionsManager.ConnectionStateConnected) {
		boolean isAirplaneMode = Settings.System.getInt(activity.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
		AlertDialog.Builder bldr = new AlertDialog.Builder(activity)
				.setTitle(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplaneTitle", R.string.VoipOfflineAirplaneTitle) : LocaleController.getString("VoipOfflineTitle", R.string.VoipOfflineTitle))
				.setMessage(isAirplaneMode ? LocaleController.getString("VoipOfflineAirplane", R.string.VoipOfflineAirplane) : LocaleController.getString("VoipOffline", R.string.VoipOffline))
				.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
		if (isAirplaneMode) {
			final Intent settingsIntent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
			if (settingsIntent.resolveActivity(activity.getPackageManager()) != null) {
				bldr.setNeutralButton(LocaleController.getString("VoipOfflineOpenSettings", R.string.VoipOfflineOpenSettings), new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						activity.startActivity(settingsIntent);
					}
				});
			}
		}
		bldr.show();
		return;
	}
	if (Build.VERSION.SDK_INT >= 23 && activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
		activity.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 101);
	} else {
		initiateCall(user, activity);
	}
}
 
Example 12
Source File: ChatUsersActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean createMenuForParticipant(final TLRPC.ChatParticipant participant, boolean resultOnly) {
    if (participant == null) {
        return false;
    }
    int currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
    if (participant.user_id == currentUserId) {
        return false;
    }
    boolean allowKick = false;
    if (currentChat.creator) {
        allowKick = true;
    } else if (participant instanceof TLRPC.TL_chatParticipant) {
        if (currentChat.admin && currentChat.admins_enabled || participant.inviter_id == currentUserId) {
            allowKick = true;
        }
    }
    if (!allowKick) {
        return false;
    }
    if (resultOnly) {
        return true;
    }
    ArrayList<String> items = new ArrayList<>();
    final ArrayList<Integer> actions = new ArrayList<>();
    items.add(LocaleController.getString("KickFromGroup", R.string.KickFromGroup));
    actions.add(0);
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setItems(items.toArray(new CharSequence[actions.size()]), (dialogInterface, i) -> {
        if (actions.get(i) == 0) {
            MessagesController.getInstance(currentAccount).deleteUserFromChat(chatId, MessagesController.getInstance(currentAccount).getUser(participant.user_id), info);
        }
    });
    showDialog(builder.create());
    return true;
}
 
Example 13
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog showUpdateAppAlert(final Context context, final String text, boolean updateApp) {
    if (context == null || text == null) {
        return null;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    builder.setMessage(text);
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    if (updateApp) {
        builder.setNegativeButton(LocaleController.getString("UpdateApp", R.string.UpdateApp), (dialog, which) -> Browser.openUrl(context, BuildVars.PLAYSTORE_APP_URL));
    }
    return builder.show();
}
 
Example 14
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog.Builder createContactsPermissionDialog(final Activity parentActivity, final MessagesStorage.IntCallback callback)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    builder.setTopImage(R.drawable.permissions_contacts, Theme.getColor(Theme.key_dialogTopBackground));
    builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("ContactsPermissionAlert", R.string.ContactsPermissionAlert)));
    builder.setPositiveButton(LocaleController.getString("ContactsPermissionAlertContinue", R.string.ContactsPermissionAlertContinue), (dialog, which) -> callback.run(1));
    builder.setNegativeButton(LocaleController.getString("ContactsPermissionAlertNotNow", R.string.ContactsPermissionAlertNotNow), (dialog, which) -> callback.run(0));
    return builder;
}
 
Example 15
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog createSupportAlert(BaseFragment fragment) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return null;
    }
    final TextView message = new TextView(fragment.getParentActivity());
    Spannable spanned = new SpannableString(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo).replace("\n", "<br>")));
    URLSpan[] spans = spanned.getSpans(0, spanned.length(), URLSpan.class);
    for (int i = 0; i < spans.length; i++) {
        URLSpan span = spans[i];
        int start = spanned.getSpanStart(span);
        int end = spanned.getSpanEnd(span);
        spanned.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL()) {
            @Override
            public void onClick(View widget) {
                fragment.dismissCurrentDialig();
                super.onClick(widget);
            }
        };
        spanned.setSpan(span, start, end, 0);
    }
    message.setText(spanned);
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
    message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection));
    message.setPadding(AndroidUtilities.dp(23), 0, AndroidUtilities.dp(23), 0);
    message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));

    AlertDialog.Builder builder1 = new AlertDialog.Builder(fragment.getParentActivity());
    builder1.setView(message);
    builder1.setTitle(LocaleController.getString("AskAQuestion", R.string.AskAQuestion));
    builder1.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), (dialogInterface, i) -> performAskAQuestion(fragment));
    builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return builder1.create();
}
 
Example 16
Source File: ThemeActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void showPermissionAlert(boolean byButton) {
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
    if (byButton) {
        builder.setMessage(LocaleController.getString("PermissionNoLocationPosition", R.string.PermissionNoLocationPosition));
    } else {
        builder.setMessage(LocaleController.getString("PermissionNoLocation", R.string.PermissionNoLocation));
    }
    builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), new DialogInterface.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.GINGERBREAD)
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (getParentActivity() == null) {
                return;
            }
            try {
                Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
                getParentActivity().startActivity(intent);
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    });
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    showDialog(builder.create());
}
 
Example 17
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 18
Source File: AlertsCreator.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static Dialog createFreeSpaceDialog(final LaunchActivity parentActivity)
{
    final int selected[] = new int[1];

    SharedPreferences preferences = MessagesController.getGlobalMainSettings();
    int keepMedia = preferences.getInt("keep_media", 2);
    if (keepMedia == 2)
    {
        selected[0] = 3;
    }
    else if (keepMedia == 0)
    {
        selected[0] = 1;
    }
    else if (keepMedia == 1)
    {
        selected[0] = 2;
    }
    else if (keepMedia == 3)
    {
        selected[0] = 0;
    }

    String[] descriptions = new String[]{
            LocaleController.formatPluralString("Days", 3),
            LocaleController.formatPluralString("Weeks", 1),
            LocaleController.formatPluralString("Months", 1),
            LocaleController.getString("LowDiskSpaceNeverRemove", R.string.LowDiskSpaceNeverRemove)
    };

    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    TextView titleTextView = new TextView(parentActivity);
    titleTextView.setText(LocaleController.getString("LowDiskSpaceTitle2", R.string.LowDiskSpaceTitle2));
    titleTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    titleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    linearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 0, 24, 8));

    for (int a = 0; a < descriptions.length; a++)
    {
        RadioColorCell cell = new RadioColorCell(parentActivity);
        cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
        cell.setTag(a);
        cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
        cell.setTextAndValue(descriptions[a], selected[0] == a);
        linearLayout.addView(cell);
        cell.setOnClickListener(v ->
        {
            int num = (Integer) v.getTag();
            if (num == 0)
            {
                selected[0] = 3;
            }
            else if (num == 1)
            {
                selected[0] = 0;
            }
            else if (num == 2)
            {
                selected[0] = 1;
            }
            else if (num == 3)
            {
                selected[0] = 2;
            }
            int count = linearLayout.getChildCount();
            for (int a1 = 0; a1 < count; a1++)
            {
                View child = linearLayout.getChildAt(a1);
                if (child instanceof RadioColorCell)
                {
                    ((RadioColorCell) child).setChecked(child == v, true);
                }
            }
        });
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    builder.setTitle(LocaleController.getString("LowDiskSpaceTitle", R.string.LowDiskSpaceTitle));
    builder.setMessage(LocaleController.getString("LowDiskSpaceMessage", R.string.LowDiskSpaceMessage));
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> MessagesController.getGlobalMainSettings().edit().putInt("keep_media", selected[0]).commit());
    builder.setNeutralButton(LocaleController.getString("ClearMediaCache", R.string.ClearMediaCache), (dialog, which) -> parentActivity.presentFragment(new CacheControlActivity()));
    return builder.create();
}
 
Example 19
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void fillNumber()
{
    try
    {
        TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE)
        {
            boolean allowCall = true;
            boolean allowSms = true;
            if (Build.VERSION.SDK_INT >= 23)
            {
                allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
                allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
                if (checkShowPermissions && !allowCall && !allowSms)
                {
                    permissionsShowItems.clear();
                    if (!allowCall)
                    {
                        permissionsShowItems.add(Manifest.permission.READ_PHONE_STATE);
                    }
                    if (!allowSms)
                    {
                        permissionsShowItems.add(Manifest.permission.RECEIVE_SMS);
                        if (Build.VERSION.SDK_INT >= 23)
                        {
                            permissionsShowItems.add(Manifest.permission.READ_SMS);
                        }
                    }
                    if (!permissionsShowItems.isEmpty())
                    {
                        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                        if (preferences.getBoolean("firstloginshow", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS))
                        {
                            preferences.edit().putBoolean("firstloginshow", false).commit();
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                            builder.setMessage(LocaleController.getString("AllowFillNumber", R.string.AllowFillNumber));
                            permissionsShowDialog = showDialog(builder.create());
                        }
                        else
                        {
                            getParentActivity().requestPermissions(permissionsShowItems.toArray(new String[permissionsShowItems.size()]), 7);
                        }
                    }
                    return;
                }
            }
            if (!newAccount && (allowCall || allowSms))
            {
                String number = PhoneFormat.stripExceptNumbers(tm.getLine1Number());
                String textToSet = null;
                boolean ok = false;
                if (!TextUtils.isEmpty(number))
                {
                    if (number.length() > 4)
                    {
                        for (int a = 4; a >= 1; a--)
                        {
                            String sub = number.substring(0, a);
                            String country = codesMap.get(sub);
                            if (country != null)
                            {
                                ok = true;
                                textToSet = number.substring(a, number.length());
                                codeField.setText(sub);
                                break;
                            }
                        }
                        if (!ok)
                        {
                            textToSet = number.substring(1, number.length());
                            codeField.setText(number.substring(0, 1));
                        }
                    }
                    if (textToSet != null)
                    {
                        phoneField.requestFocus();
                        phoneField.setText(textToSet);
                        phoneField.setSelection(phoneField.length());
                    }
                }
            }
        }
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
}
 
Example 20
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void showTermsOfService(boolean needAccept)
{
    if (currentTermsOfService == null)
    {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("TermsOfService", R.string.TermsOfService));

    if (needAccept)
    {
        builder.setPositiveButton(LocaleController.getString("Accept", R.string.Accept), (dialog, which) ->
        {
            currentTermsOfService.popup = false;
            onNextPressed();
        });
        builder.setNegativeButton(LocaleController.getString("Decline", R.string.Decline), (dialog, which) ->
        {
            AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity());
            builder1.setTitle(LocaleController.getString("TermsOfService", R.string.TermsOfService));
            builder1.setMessage(LocaleController.getString("TosDecline", R.string.TosDecline));
            builder1.setPositiveButton(LocaleController.getString("SignUp", R.string.SignUp), (dialog1, which1) ->
            {
                currentTermsOfService.popup = false;
                onNextPressed();
            });
            builder1.setNegativeButton(LocaleController.getString("Decline", R.string.Decline), (dialog12, which12) -> wrongNumber.callOnClick());
            showDialog(builder1.create());
        });
    }
    else
    {
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
    }

    SpannableStringBuilder text = new SpannableStringBuilder(currentTermsOfService.text);
    MessageObject.addEntitiesToText(text, currentTermsOfService.entities, false, 0, false, false, false);
    builder.setMessage(text);

    showDialog(builder.create());
}