Search in sources :

Example 16 with ColorInt

use of android.annotation.ColorInt in project platform_frameworks_base by android.

the class DataUsageDetailView method bind.

public void bind(DataUsageController.DataUsageInfo info) {
    final Resources res = mContext.getResources();
    final int titleId;
    final long bytes;
    @ColorInt int usageColor = 0;
    final String top;
    String bottom = null;
    if (info.usageLevel < info.warningLevel || info.limitLevel <= 0) {
        // under warning, or no limit
        titleId = R.string.quick_settings_cellular_detail_data_usage;
        bytes = info.usageLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_warning, formatBytes(info.warningLevel));
    } else if (info.usageLevel <= info.limitLevel) {
        // over warning, under limit
        titleId = R.string.quick_settings_cellular_detail_remaining_data;
        bytes = info.limitLevel - info.usageLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_used, formatBytes(info.usageLevel));
        bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit, formatBytes(info.limitLevel));
    } else {
        // over limit
        titleId = R.string.quick_settings_cellular_detail_over_limit;
        bytes = info.usageLevel - info.limitLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_used, formatBytes(info.usageLevel));
        bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit, formatBytes(info.limitLevel));
        usageColor = mContext.getColor(R.color.system_warning_color);
    }
    if (usageColor == 0) {
        usageColor = Utils.getColorAccent(mContext);
    }
    final TextView title = (TextView) findViewById(android.R.id.title);
    title.setText(titleId);
    final TextView usage = (TextView) findViewById(R.id.usage_text);
    usage.setText(formatBytes(bytes));
    usage.setTextColor(usageColor);
    final DataUsageGraph graph = (DataUsageGraph) findViewById(R.id.usage_graph);
    graph.setLevels(info.limitLevel, info.warningLevel, info.usageLevel);
    final TextView carrier = (TextView) findViewById(R.id.usage_carrier_text);
    carrier.setText(info.carrier);
    final TextView period = (TextView) findViewById(R.id.usage_period_text);
    period.setText(info.period);
    final TextView infoTop = (TextView) findViewById(R.id.usage_info_top_text);
    infoTop.setVisibility(top != null ? View.VISIBLE : View.GONE);
    infoTop.setText(top);
    final TextView infoBottom = (TextView) findViewById(R.id.usage_info_bottom_text);
    infoBottom.setVisibility(bottom != null ? View.VISIBLE : View.GONE);
    infoBottom.setText(bottom);
    boolean showLevel = info.warningLevel > 0 || info.limitLevel > 0;
    graph.setVisibility(showLevel ? View.VISIBLE : View.GONE);
    if (!showLevel) {
        infoTop.setVisibility(View.GONE);
    }
}
Also used : ColorInt(android.annotation.ColorInt) DataUsageGraph(com.android.systemui.qs.DataUsageGraph) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Example 17 with ColorInt

use of android.annotation.ColorInt in project android_frameworks_base by DirtyUnicorns.

the class Resources method getColor.

/**
     * Returns a themed color integer associated with a particular resource ID.
     * If the resource holds a complex {@link ColorStateList}, then the default
     * color from the set is returned.
     *
     * @param id The desired resource identifier, as generated by the aapt
     *           tool. This integer encodes the package, type, and resource
     *           entry. The value 0 is an invalid identifier.
     * @param theme The theme used to style the color attributes, may be
     *              {@code null}.
     *
     * @throws NotFoundException Throws NotFoundException if the given ID does
     *         not exist.
     *
     * @return A single color value in the form 0xAARRGGBB.
     */
@ColorInt
public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException {
    final TypedValue value = obtainTempTypedValue();
    try {
        final ResourcesImpl impl = mResourcesImpl;
        impl.getValue(id, value, true);
        if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT) {
            return value.data;
        } else if (value.type != TypedValue.TYPE_STRING) {
            throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id) + " type #0x" + Integer.toHexString(value.type) + " is not valid");
        }
        final ColorStateList csl = impl.loadColorStateList(this, value, id, theme);
        return csl.getDefaultColor();
    } finally {
        releaseTempTypedValue(value);
    }
}
Also used : TypedValue(android.util.TypedValue) ColorInt(android.annotation.ColorInt)

Example 18 with ColorInt

use of android.annotation.ColorInt in project android_frameworks_base by AOSPA.

the class DataUsageDetailView method bind.

public void bind(DataUsageController.DataUsageInfo info) {
    final Resources res = mContext.getResources();
    final int titleId;
    final long bytes;
    @ColorInt int usageColor = 0;
    final String top;
    String bottom = null;
    if (info.usageLevel < info.warningLevel || info.limitLevel <= 0) {
        // under warning, or no limit
        titleId = R.string.quick_settings_cellular_detail_data_usage;
        bytes = info.usageLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_warning, formatBytes(info.warningLevel));
    } else if (info.usageLevel <= info.limitLevel) {
        // over warning, under limit
        titleId = R.string.quick_settings_cellular_detail_remaining_data;
        bytes = info.limitLevel - info.usageLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_used, formatBytes(info.usageLevel));
        bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit, formatBytes(info.limitLevel));
    } else {
        // over limit
        titleId = R.string.quick_settings_cellular_detail_over_limit;
        bytes = info.usageLevel - info.limitLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_used, formatBytes(info.usageLevel));
        bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit, formatBytes(info.limitLevel));
        usageColor = mContext.getColor(R.color.system_warning_color);
    }
    if (usageColor == 0) {
        usageColor = Utils.getColorAccent(mContext);
    }
    final TextView title = (TextView) findViewById(android.R.id.title);
    title.setText(titleId);
    final TextView usage = (TextView) findViewById(R.id.usage_text);
    usage.setText(formatBytes(bytes));
    usage.setTextColor(usageColor);
    final DataUsageGraph graph = (DataUsageGraph) findViewById(R.id.usage_graph);
    graph.setLevels(info.limitLevel, info.warningLevel, info.usageLevel);
    final TextView carrier = (TextView) findViewById(R.id.usage_carrier_text);
    carrier.setText(info.carrier);
    final TextView period = (TextView) findViewById(R.id.usage_period_text);
    period.setText(info.period);
    final TextView infoTop = (TextView) findViewById(R.id.usage_info_top_text);
    infoTop.setVisibility(top != null ? View.VISIBLE : View.GONE);
    infoTop.setText(top);
    final TextView infoBottom = (TextView) findViewById(R.id.usage_info_bottom_text);
    infoBottom.setVisibility(bottom != null ? View.VISIBLE : View.GONE);
    infoBottom.setText(bottom);
    boolean showLevel = info.warningLevel > 0 || info.limitLevel > 0;
    graph.setVisibility(showLevel ? View.VISIBLE : View.GONE);
    if (!showLevel) {
        infoTop.setVisibility(View.GONE);
    }
}
Also used : ColorInt(android.annotation.ColorInt) DataUsageGraph(com.android.systemui.qs.DataUsageGraph) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Example 19 with ColorInt

use of android.annotation.ColorInt in project android_frameworks_base by ResurrectionRemix.

the class Utils method getColorAccent.

@ColorInt
public static int getColorAccent(Context context) {
    TypedArray ta = context.obtainStyledAttributes(new int[] { android.R.attr.colorAccent });
    @ColorInt int colorAccent = ta.getColor(0, 0);
    ta.recycle();
    return colorAccent;
}
Also used : ColorInt(android.annotation.ColorInt) TypedArray(android.content.res.TypedArray) ColorInt(android.annotation.ColorInt)

Example 20 with ColorInt

use of android.annotation.ColorInt in project android_frameworks_base by DirtyUnicorns.

the class DataUsageDetailView method bind.

public void bind(DataUsageController.DataUsageInfo info) {
    final Resources res = mContext.getResources();
    final int titleId;
    final long bytes;
    @ColorInt int usageColor = 0;
    final String top;
    String bottom = null;
    if (info.usageLevel < info.warningLevel || info.limitLevel <= 0) {
        // under warning, or no limit
        titleId = R.string.quick_settings_cellular_detail_data_usage;
        bytes = info.usageLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_warning, formatBytes(info.warningLevel));
    } else if (info.usageLevel <= info.limitLevel) {
        // over warning, under limit
        titleId = R.string.quick_settings_cellular_detail_remaining_data;
        bytes = info.limitLevel - info.usageLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_used, formatBytes(info.usageLevel));
        bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit, formatBytes(info.limitLevel));
    } else {
        // over limit
        titleId = R.string.quick_settings_cellular_detail_over_limit;
        bytes = info.usageLevel - info.limitLevel;
        top = res.getString(R.string.quick_settings_cellular_detail_data_used, formatBytes(info.usageLevel));
        bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit, formatBytes(info.limitLevel));
        usageColor = mContext.getColor(R.color.system_warning_color);
    }
    if (usageColor == 0) {
        usageColor = Utils.getColorAccent(mContext);
    }
    final TextView title = (TextView) findViewById(android.R.id.title);
    title.setText(titleId);
    final TextView usage = (TextView) findViewById(R.id.usage_text);
    usage.setText(formatBytes(bytes));
    usage.setTextColor(usageColor);
    final DataUsageGraph graph = (DataUsageGraph) findViewById(R.id.usage_graph);
    graph.setLevels(info.limitLevel, info.warningLevel, info.usageLevel);
    final TextView carrier = (TextView) findViewById(R.id.usage_carrier_text);
    carrier.setText(info.carrier);
    final TextView period = (TextView) findViewById(R.id.usage_period_text);
    period.setText(info.period);
    final TextView infoTop = (TextView) findViewById(R.id.usage_info_top_text);
    infoTop.setVisibility(top != null ? View.VISIBLE : View.GONE);
    infoTop.setText(top);
    final TextView infoBottom = (TextView) findViewById(R.id.usage_info_bottom_text);
    infoBottom.setVisibility(bottom != null ? View.VISIBLE : View.GONE);
    infoBottom.setText(bottom);
    boolean showLevel = info.warningLevel > 0 || info.limitLevel > 0;
    graph.setVisibility(showLevel ? View.VISIBLE : View.GONE);
    if (!showLevel) {
        infoTop.setVisibility(View.GONE);
    }
}
Also used : ColorInt(android.annotation.ColorInt) DataUsageGraph(com.android.systemui.qs.DataUsageGraph) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Aggregations

ColorInt (android.annotation.ColorInt)20 TypedValue (android.util.TypedValue)10 Resources (android.content.res.Resources)5 TypedArray (android.content.res.TypedArray)5 TextView (android.widget.TextView)5 DataUsageGraph (com.android.systemui.qs.DataUsageGraph)5