Search in sources :

Example 31 with MessageFormat

use of android.icu.text.MessageFormat in project j2objc by google.

the class TestMessageFormat method TestEquals.

@Test
public void TestEquals() {
    MessageFormat x = new MessageFormat("There are {0} files on {1}");
    MessageFormat y = new MessageFormat("There are {0} files on {1}");
    if (!x.equals(y)) {
        errln("First test (operator ==): Failed!");
    }
}
Also used : MessageFormat(android.icu.text.MessageFormat) Test(org.junit.Test)

Example 32 with MessageFormat

use of android.icu.text.MessageFormat in project android_packages_apps_Settings by omnirom.

the class ZenModeBypassingAppsPreferenceController method updateAppsBypassingDndSummaryText.

@VisibleForTesting
void updateAppsBypassingDndSummaryText(List<ApplicationsState.AppEntry> apps) {
    switch(getZenMode()) {
        case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
        case Settings.Global.ZEN_MODE_ALARMS:
            // users cannot change their DND settings when an app puts the device total
            // silence or alarms only (both deprecated) modes
            mPreference.setEnabled(false);
            mSummary = mContext.getResources().getString(R.string.zen_mode_bypassing_apps_subtext_none);
            return;
        default:
            mPreference.setEnabled(true);
    }
    if (apps == null) {
        return;
    }
    Set<String> appsBypassingDnd = new ArraySet<>();
    for (ApplicationsState.AppEntry entry : apps) {
        String pkg = entry.info.packageName;
        for (NotificationChannel channel : mNotificationBackend.getNotificationChannelsBypassingDnd(pkg, entry.info.uid).getList()) {
            if (!TextUtils.isEmpty(channel.getConversationId()) && !channel.isDemoted()) {
                // conversation channels that bypass dnd will be shown on the People page
                continue;
            }
            appsBypassingDnd.add(BidiFormatter.getInstance().unicodeWrap(entry.label));
            continue;
        }
    }
    final int numAppsBypassingDnd = appsBypassingDnd.size();
    String[] appsBypassingDndArr = appsBypassingDnd.toArray(new String[numAppsBypassingDnd]);
    MessageFormat msgFormat = new MessageFormat(mContext.getString(R.string.zen_mode_bypassing_apps_subtext), Locale.getDefault());
    Map<String, Object> args = new HashMap<>();
    args.put("count", numAppsBypassingDnd);
    if (numAppsBypassingDnd >= 1) {
        args.put("app_1", appsBypassingDndArr[0]);
        if (numAppsBypassingDnd >= 2) {
            args.put("app_2", appsBypassingDndArr[1]);
            if (numAppsBypassingDnd == 3) {
                args.put("app_3", appsBypassingDndArr[2]);
            }
        }
    }
    mSummary = msgFormat.format(args);
    refreshSummary(mPreference);
}
Also used : NotificationChannel(android.app.NotificationChannel) ArraySet(android.util.ArraySet) MessageFormat(android.icu.text.MessageFormat) HashMap(java.util.HashMap) ApplicationsState(com.android.settingslib.applications.ApplicationsState) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 33 with MessageFormat

use of android.icu.text.MessageFormat in project android_packages_apps_Settings by omnirom.

the class ZenModeDurationPreferenceController method getSummary.

@Override
public CharSequence getSummary() {
    String summary;
    int zenDuration = getZenDuration();
    if (zenDuration < 0) {
        summary = mContext.getString(R.string.zen_mode_duration_summary_always_prompt);
    } else if (zenDuration == 0) {
        summary = mContext.getString(R.string.zen_mode_duration_summary_forever);
    } else {
        if (zenDuration >= 60) {
            MessageFormat msgFormat = new MessageFormat(mContext.getString(R.string.zen_mode_duration_summary_time_hours), Locale.getDefault());
            Map<String, Object> msgArgs = new HashMap<>();
            msgArgs.put("count", zenDuration / 60);
            summary = msgFormat.format(msgArgs);
        } else {
            MessageFormat msgFormat = new MessageFormat(mContext.getString(R.string.zen_mode_duration_summary_time_minutes), Locale.getDefault());
            Map<String, Object> msgArgs = new HashMap<>();
            msgArgs.put("count", zenDuration);
            summary = msgFormat.format(msgArgs);
        }
    }
    return summary;
}
Also used : MessageFormat(android.icu.text.MessageFormat) Map(java.util.Map) HashMap(java.util.HashMap)

Example 34 with MessageFormat

use of android.icu.text.MessageFormat in project android_packages_apps_Settings by omnirom.

the class ZenModeBackend method getContactsNumberSummary.

String getContactsNumberSummary(Context context) {
    MessageFormat msgFormat = new MessageFormat(mContext.getString(R.string.zen_mode_contacts_count), Locale.getDefault());
    Map<String, Object> args = new HashMap<>();
    args.put("count", queryAllContactsData().getCount());
    return msgFormat.format(args);
}
Also used : MessageFormat(android.icu.text.MessageFormat) HashMap(java.util.HashMap)

Example 35 with MessageFormat

use of android.icu.text.MessageFormat in project android_packages_apps_Settings by omnirom.

the class ChooseSimActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.choose_sim_activity);
    Intent intent = getIntent();
    mHasPsim = intent.getBooleanExtra(KEY_HAS_PSIM, false);
    mNoPsimContinueToSettings = intent.getBooleanExtra(KEY_NO_PSIM_CONTINUE_TO_SETTINGS, false);
    updateSubscriptions();
    if (mEmbeddedSubscriptions.size() == 0) {
        Log.e(TAG, "Unable to find available eSIM subscriptions.");
        finish();
        return;
    }
    if (savedInstanceState != null) {
        mSelectedItemIndex = savedInstanceState.getInt(STATE_SELECTED_INDEX);
        mIsSwitching = savedInstanceState.getBoolean(STATE_IS_SWITCHING);
    }
    GlifLayout layout = findViewById(R.id.glif_layout);
    int subscriptionCount = mEmbeddedSubscriptions.size();
    if (mHasPsim) {
        // Choose a number to use
        subscriptionCount++;
    }
    layout.setHeaderText(getString(R.string.choose_sim_title));
    MessageFormat msgFormat = new MessageFormat(getString(R.string.choose_sim_text), Locale.getDefault());
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("count", subscriptionCount);
    layout.setDescriptionText(msgFormat.format(arguments));
    displaySubscriptions();
    mSwitchToRemovableSlotSidecar = SwitchToRemovableSlotSidecar.get(getFragmentManager());
    mSwitchToEuiccSubscriptionSidecar = SwitchToEuiccSubscriptionSidecar.get(getFragmentManager());
}
Also used : MessageFormat(android.icu.text.MessageFormat) HashMap(java.util.HashMap) GlifLayout(com.google.android.setupdesign.GlifLayout) Intent(android.content.Intent)

Aggregations

MessageFormat (android.icu.text.MessageFormat)61 Test (org.junit.Test)53 AttributedString (java.text.AttributedString)24 HashMap (java.util.HashMap)15 FieldPosition (java.text.FieldPosition)12 ParsePosition (java.text.ParsePosition)10 Date (java.util.Date)10 ChoiceFormat (java.text.ChoiceFormat)9 ParseException (java.text.ParseException)9 IOException (java.io.IOException)7 Map (java.util.Map)7 TreeMap (java.util.TreeMap)6 SimpleDateFormat (android.icu.text.SimpleDateFormat)5 DateFormat (android.icu.text.DateFormat)4 DecimalFormat (android.icu.text.DecimalFormat)4 NumberFormat (android.icu.text.NumberFormat)4 UFormat (android.icu.text.UFormat)3 ULocale (android.icu.util.ULocale)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3