Java Code Examples for android.text.BidiFormatter

The following examples show how to use android.text.BidiFormatter. These examples are extracted from open source projects.
Example 1
Project: AndroidWallet   File: TimeUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static String getTimeZoneText(TimeZone tz, boolean includeName) {
    Date now = new Date();

    SimpleDateFormat gmtFormatter = new SimpleDateFormat("ZZZZ");
    gmtFormatter.setTimeZone(tz);
    String gmtString = gmtFormatter.format(now);
    BidiFormatter bidiFormatter = BidiFormatter.getInstance();
    Locale l = Locale.getDefault();
    boolean isRtl = TextUtils.getLayoutDirectionFromLocale(l) == View.LAYOUT_DIRECTION_RTL;
    gmtString = bidiFormatter.unicodeWrap(gmtString,
            isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);

    if (!includeName) {
        return gmtString;
    }

    return gmtString;
}
 
Example 2
Project: GeometricWeather   File: NumberAnimTextView.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressLint("SetTextI18n")
private void start() {
    if (!mIsEnableAnim) {
        // 禁止动画
        setText(mPrefixString + format(new BigDecimal(mNumEnd)) + mPostfixString);
        return;
    }
    BidiFormatter f = BidiFormatter.getInstance();

    animator = ValueAnimator.ofObject(new BigDecimalEvaluator(), new BigDecimal(mNumStart), new BigDecimal(mNumEnd));
    animator.setDuration(mDuration);
    animator.setInterpolator(new DecelerateInterpolator(3f));
    animator.addUpdateListener(valueAnimator -> {
        BigDecimal value = (BigDecimal) valueAnimator.getAnimatedValue();
        setText(mPrefixString + f.unicodeWrap(format(value)) + mPostfixString);
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            setText(mPrefixString + f.unicodeWrap(mNumEnd) + mPostfixString);
        }
    });
    animator.start();
}
 
Example 3
Project: GeometricWeather   File: Hourly.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressLint("DefaultLocale")
public String getHour(Context c) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    int hour;
    if (TimeManager.is12Hour(c)) {
        hour = calendar.get(Calendar.HOUR);
        if (hour == 0) {
            hour = 12;
        }
    } else {
        hour = calendar.get(Calendar.HOUR_OF_DAY);
    }

    if (DisplayUtils.isRtl(c)) {
        return BidiFormatter.getInstance().unicodeWrap(String.format("%d", hour))
                + c.getString(R.string.of_clock);
    } else {
        return hour + c.getString(R.string.of_clock);
    }
}
 
Example 4
Project: android_9.0.0_r45   File: Formatter.java    License: Apache License 2.0 5 votes vote down vote up
private static String bidiWrap(@NonNull Context context, String source) {
    final Locale locale = localeFromContext(context);
    if (TextUtils.getLayoutDirectionFromLocale(locale) == View.LAYOUT_DIRECTION_RTL) {
        return BidiFormatter.getInstance(true /* RTL*/).unicodeWrap(source);
    } else {
        return source;
    }
}
 
Example 5
Project: GeometricWeather   File: NumberAnimTextView.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressLint("SetTextI18n")
public void setNumberString(String numberStart, String numberEnd) {
    mNumStart = numberStart;
    mNumEnd = numberEnd;
    if (checkNumString(numberStart, numberEnd)) {
        // 数字合法 开始数字动画
        start();
    } else {
        // 数字不合法 直接调用 setText 设置最终值
        setText(mPrefixString + BidiFormatter.getInstance().unicodeWrap(numberEnd) + mPostfixString);
    }
}
 
Example 6
Project: GeometricWeather   File: TemperatureUnit.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getTemperatureText(Context context, int c) {
    if (DisplayUtils.isRtl(context)) {
        return BidiFormatter.getInstance().unicodeWrap(
                UnitUtils.formatInt(getTemperature(c))
        ) + getAbbreviation(context);
    } else {
        return getTemperature(c) + getAbbreviation(context);
    }
}
 
Example 7
Project: GeometricWeather   File: TemperatureUnit.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getLongTemperatureText(Context context, int c) {
    if (DisplayUtils.isRtl(context)) {
        return BidiFormatter.getInstance().unicodeWrap(
                UnitUtils.formatInt(getTemperature(c))
        ) + getLongAbbreviation(context);
    } else {
        return getTemperature(c) + getLongAbbreviation(context);
    }
}
 
Example 8
Project: GeometricWeather   File: TemperatureUnit.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getShortTemperatureText(Context context, int c) {
    if (DisplayUtils.isRtl(context)) {
        return BidiFormatter.getInstance().unicodeWrap(
                UnitUtils.formatInt(getTemperature(c))
        ) + getShortAbbreviation(context);
    } else {
        return getTemperature(c) + getShortAbbreviation(context);
    }
}
 
Example 9
Project: android_9.0.0_r45   File: AppErrorDialog.java    License: Apache License 2.0 4 votes vote down vote up
public AppErrorDialog(Context context, ActivityManagerService service, Data data) {
    super(context);
    Resources res = context.getResources();

    mService = service;
    mProc = data.proc;
    mResult = data.result;
    mIsRestartable = (data.task != null || data.isRestartableForService)
            && Settings.Global.getInt(context.getContentResolver(),
            Settings.Global.SHOW_RESTART_IN_CRASH_DIALOG, 0) != 0;
    BidiFormatter bidi = BidiFormatter.getInstance();

    CharSequence name;
    if ((mProc.pkgList.size() == 1) &&
            (name = context.getPackageManager().getApplicationLabel(mProc.info)) != null) {
        setTitle(res.getString(
                data.repeating ? com.android.internal.R.string.aerr_application_repeated
                        : com.android.internal.R.string.aerr_application,
                bidi.unicodeWrap(name.toString()),
                bidi.unicodeWrap(mProc.info.processName)));
    } else {
        name = mProc.processName;
        setTitle(res.getString(
                data.repeating ? com.android.internal.R.string.aerr_process_repeated
                        : com.android.internal.R.string.aerr_process,
                bidi.unicodeWrap(name.toString())));
    }

    setCancelable(true);
    setCancelMessage(mHandler.obtainMessage(CANCEL));

    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.setTitle("Application Error: " + mProc.info.processName);
    attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR
            | WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
    getWindow().setAttributes(attrs);
    if (mProc.persistent) {
        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
    }

    // After the timeout, pretend the user clicked the quit button
    mHandler.sendMessageDelayed(
            mHandler.obtainMessage(TIMEOUT),
            DISMISS_TIMEOUT);
}
 
Example 10
Project: android_9.0.0_r45   File: AppNotRespondingDialog.java    License: Apache License 2.0 4 votes vote down vote up
public AppNotRespondingDialog(ActivityManagerService service, Context context, Data data) {
    super(context);

    mService = service;
    mProc = data.proc;
    Resources res = context.getResources();

    setCancelable(false);

    int resid;
    CharSequence name1 = data.activity != null
            ? data.activity.info.loadLabel(context.getPackageManager())
            : null;
    CharSequence name2 = null;
    if ((mProc.pkgList.size() == 1) &&
            (name2=context.getPackageManager().getApplicationLabel(mProc.info)) != null) {
        if (name1 != null) {
            resid = com.android.internal.R.string.anr_activity_application;
        } else {
            name1 = name2;
            name2 = mProc.processName;
            resid = com.android.internal.R.string.anr_application_process;
        }
    } else {
        if (name1 != null) {
            name2 = mProc.processName;
            resid = com.android.internal.R.string.anr_activity_process;
        } else {
            name1 = mProc.processName;
            resid = com.android.internal.R.string.anr_process;
        }
    }

    BidiFormatter bidi = BidiFormatter.getInstance();

    setTitle(name2 != null
            ? res.getString(resid, bidi.unicodeWrap(name1.toString()), bidi.unicodeWrap(name2.toString()))
            : res.getString(resid, bidi.unicodeWrap(name1.toString())));

    if (data.aboveSystem) {
        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
    }
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.setTitle("Application Not Responding: " + mProc.info.processName);
    attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR |
            WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
    getWindow().setAttributes(attrs);
}
 
Example 11
Project: assertj-android   File: BidiFormatterAssert.java    License: Apache License 2.0 4 votes vote down vote up
public BidiFormatterAssert(BidiFormatter actual) {
  super(actual, BidiFormatterAssert.class);
}