Java Code Examples for android.support.v4.content.res.ResourcesCompat#getFont()

The following examples show how to use android.support.v4.content.res.ResourcesCompat#getFont() . 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: Util.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("inlineValue")
public static TextView setToolbarTypeface(Toolbar toolbar) {
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        View view = toolbar.getChildAt(i);
        if (view instanceof TextView) {
            TextView textView = (TextView) view;
            if (textView.getText().equals(toolbar.getTitle())) {
                Typeface typeface = ResourcesCompat
                        .getFont(toolbar.getContext(), R.font.roboto_mono_medium);
                textView.setTypeface(typeface);
                return textView;
            }
        }
    }
    return null;
}
 
Example 2
Source File: SplashActivity.java    From MagicPrint-ECommerce-App-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    session =new UserSession(SplashActivity.this);

  Typeface typeface = ResourcesCompat.getFont(this, R.font.blacklist);

  TextView appname= findViewById(R.id.appname);
  appname.setTypeface(typeface);

    YoYo.with(Techniques.Bounce)
            .duration(7000)
            .playOn(findViewById(R.id.logo));

    YoYo.with(Techniques.FadeInUp)
            .duration(5000)
            .playOn(findViewById(R.id.appname));

        new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                startActivity(new Intent(SplashActivity.this,WelcomeActivity.class));
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
 
Example 3
Source File: MainActivity.java    From MagicPrint-ECommerce-App-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Typeface typeface = ResourcesCompat.getFont(this, R.font.blacklist);
    TextView appname = findViewById(R.id.appname);
    appname.setTypeface(typeface);

    //check Internet Connection
    new CheckInternetConnection(this).checkConnection();

    //retrieve session values and display on listviews
    getValues();

    //Navigation Drawer with toolbar
    inflateNavDrawer();

    //ImageSLider
    inflateImageSlider();

    if (session.getFirstTime()) {
        //tap target view
        tapview();
        session.setFirstTime(false);
    }
}
 
Example 4
Source File: EntityWidgetProvider.java    From homeassist with Apache License 2.0 4 votes vote down vote up
public static void updateEntityWidget(Context context, Widget widget) {
    Log.d("YouQi", "Widget updateEntityWidget: " + CommonUtil.deflate(widget));
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    String iconText = widget.getMdiIcon(); //MDIFont.getIcon("mdi:weather-hail");
    int iconColor = ResourcesCompat.getColor(context.getResources(), (widget.isToggleable() && !widget.isCurrentStateActive()) ? R.color.md_grey_500 : R.color.xiaomiPrimaryTextSelected, null);

    Bitmap myBitmap = Bitmap.createBitmap(160, 160, Bitmap.Config.ARGB_8888);
    myBitmap.eraseColor(Color.TRANSPARENT);

    Typeface typeface = ResourcesCompat.getFont(context, R.font.mdi);
    Paint paint = new Paint();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setAntiAlias(true);
    paint.setTypeface(typeface);
    paint.setColor(iconColor);
    paint.setTextSize(160);
    //paint.setStrokeWidth(24); // Text Size
    //setTextSizeForWidth(paint, 48, iconText);
    //paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern

    Canvas canvas = new Canvas(myBitmap);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
    int xPos = (canvas.getWidth() - yPos) / 2;//(canvas.getWidth() / 2);
    canvas.drawText(iconText, 0, yPos, paint);

    RemoteViews remoteViews = new RemoteViews("com.axzae.homeassistant", R.layout.widget_entity);
    remoteViews.setImageViewBitmap(R.id.image_icon, myBitmap);
    remoteViews.setTextViewText(R.id.text_state, widget.getFriendlyStateRow());
    remoteViews.setTextColor(R.id.text_state, iconColor);
    remoteViews.setTextViewText(R.id.text_group, widget.getFriendlyName());

    //https://stackoverflow.com/questions/21311917/onreceive-will-always-receive-the-last-appwidgetid-even-different-instance-widg
    Intent newIntent = new Intent(context, EntityWidgetProvider.class);
    newIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    newIntent.putExtra("appWidgetId", widget.appWidgetId);
    newIntent.putExtra("widget", CommonUtil.deflate(widget));
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, widget.appWidgetId, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.item, pendingIntent);
    appWidgetManager.updateAppWidget(widget.appWidgetId, remoteViews);
    Log.d("YouQi", "appWidgetManager updating (" + widget.appWidgetId + "): " + widget.getFriendlyState());
}
 
Example 5
Source File: BitmapUtils.java    From AndroidWM with Apache License 2.0 4 votes vote down vote up
/**
 * build a bitmap from a text.
 *
 * @return {@link Bitmap} the bitmap return.
 */
public static Bitmap textAsBitmap(Context context, WatermarkText watermarkText) {
    TextPaint watermarkPaint = new TextPaint();
    watermarkPaint.setColor(watermarkText.getTextColor());
    watermarkPaint.setStyle(watermarkText.getTextStyle());

    if (watermarkText.getTextAlpha() >= 0 && watermarkText.getTextAlpha() <= 255) {
        watermarkPaint.setAlpha(watermarkText.getTextAlpha());
    }

    float value = (float) watermarkText.getTextSize();
    int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            value, context.getResources().getDisplayMetrics());
    watermarkPaint.setTextSize(pixel);

    if (watermarkText.getTextShadowBlurRadius() != 0
            || watermarkText.getTextShadowXOffset() != 0
            || watermarkText.getTextShadowYOffset() != 0) {
        watermarkPaint.setShadowLayer(watermarkText.getTextShadowBlurRadius(),
                watermarkText.getTextShadowXOffset(),
                watermarkText.getTextShadowYOffset(),
                watermarkText.getTextShadowColor());
    }

    if (watermarkText.getTextFont() != 0) {
        Typeface typeface = ResourcesCompat.getFont(context, watermarkText.getTextFont());
        watermarkPaint.setTypeface(typeface);
    }

    watermarkPaint.setAntiAlias(true);
    watermarkPaint.setTextAlign(Paint.Align.LEFT);
    watermarkPaint.setStrokeWidth(5);

    float baseline = (int) (-watermarkPaint.ascent() + 1f);
    Rect bounds = new Rect();
    watermarkPaint.getTextBounds(watermarkText.getText(),
            0, watermarkText.getText().length(), bounds);

    int boundWidth = bounds.width() + 20;
    int mTextMaxWidth = (int) watermarkPaint.measureText(watermarkText.getText());
    if (boundWidth > mTextMaxWidth) {
        boundWidth = mTextMaxWidth;
    }
    StaticLayout staticLayout = new StaticLayout(watermarkText.getText(),
            0, watermarkText.getText().length(),
            watermarkPaint, mTextMaxWidth, android.text.Layout.Alignment.ALIGN_NORMAL, 2.0f,
            2.0f, false);

    int lineCount = staticLayout.getLineCount();
    int height = (int) (baseline + watermarkPaint.descent() + 3) * lineCount;
    Bitmap image = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    if (boundWidth > 0 && height > 0) {
        image = Bitmap.createBitmap(boundWidth, height, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(image);
    canvas.drawColor(watermarkText.getBackgroundColor());
    staticLayout.draw(canvas);
    return image;
}
 
Example 6
Source File: AnimatedPullToRefreshLayout.java    From AnimatedPullToRefresh-master with Apache License 2.0 4 votes vote down vote up
public AnimatedPullToRefreshLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    setWillNotDraw(false);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedPullToRefreshLayout);
    if (a != null) {
        String headerText = a.getString(R.styleable.AnimatedPullToRefreshLayout_headerText);
        int headerTextSize = a.getDimensionPixelSize(R.styleable.AnimatedPullToRefreshLayout_headerTextSize, (int) getResources().getDimension(R.dimen.headerTextSize));
        int headerTextColor = a.getColor(R.styleable.AnimatedPullToRefreshLayout_headerTextColor, getColor(android.R.color.darker_gray));
        int headerBackgroundColor = a.getColor(R.styleable.AnimatedPullToRefreshLayout_headerBackgroundColor, getColor(android.R.color.transparent));
        HeaderAnimSpeed headerAnimSpeed = HeaderAnimSpeed.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_animationSpeed, HeaderAnimSpeed.FAST.getSpeed()));
        HeaderTextAnim headerTextAnim = HeaderTextAnim.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerTextAnimation, HeaderTextAnim.ROTATE_CW.getAnimType()));
        HeaderLoopAnim headerLoopAnim = HeaderLoopAnim.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerLoopAnimation, HeaderLoopAnim.ZOOM.getAnimType()));
        int headerTextAnimIteration = a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerTextAnimIteration, HeaderTextAnim.ROTATE_CW.getAnimType());
        int headerLoopAnimIteration = a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerLoopAnimIteration, HeaderLoopAnim.ZOOM.getAnimType());
        boolean isColorAnimEnabled = a.getBoolean(R.styleable.AnimatedPullToRefreshLayout_headerTextColorAnimationEnabled, true);
        Typeface mTitleTypeface = null;
        //Font
        if (a.hasValue(R.styleable.AnimatedPullToRefreshLayout_headerTextFontFamily)) {
            int fontId = a.getResourceId(R.styleable.AnimatedPullToRefreshLayout_headerTextFontFamily, -1);
            if (fontId != -1)
                mTitleTypeface = ResourcesCompat.getFont(context, fontId);
        }

        a.recycle();

        if (isInEditMode())
            return;

        // adding header layout : important
        headerView = new CharacterAnimatorHeaderView(getContext());
        headerView.setHeaderText(headerText);
        headerView.setHeaderTextSize(headerTextSize);
        headerView.setHeaderTextColor(headerTextColor);
        headerView.setHeaderBackgroundColor(headerBackgroundColor);
        headerView.setHeaderTextAnim(headerTextAnim);
        headerView.setHeaderLoopAnim(headerLoopAnim);
        headerView.setHeaderTextAnimIteration(headerTextAnimIteration);
        headerView.setHeaderLoopAnimIteration(headerLoopAnimIteration);
        headerView.setColorAnimEnable(isColorAnimEnabled);
        headerView.setAnimationSpeed(headerAnimSpeed);
        headerView.setHeaderTextTypeface(mTitleTypeface);

        setHeaderView(headerView);
    }

}
 
Example 7
Source File: FABRevealMenu.java    From FABRevealMenu-master with Apache License 2.0 4 votes vote down vote up
private void initView(Context context, AttributeSet attrs) {
    mContext = context;

    //helper initialization
    viewHelper = new ViewHelper(context);
    animationHelper = new AnimationHelper(viewHelper);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FABRevealMenu, 0, 0);

        //background
        mMenuBackground = a.getColor(R.styleable.FABRevealMenu_menuBackgroundColor, getColor(R.color.colorWhite));
        mOverlayBackground = a.getColor(R.styleable.FABRevealMenu_overlayBackground, getColor(R.color.colorOverlayDark));

        //menu
        mMenuRes = a.getResourceId(R.styleable.FABRevealMenu_menuRes, -1);

        //custom view
        int customView = a.getResourceId(R.styleable.FABRevealMenu_menuCustomView, -1);
        if (customView != -1)
            mCustomView = LayoutInflater.from(context).inflate(customView, null);

        //direction
        mDirection = Direction.fromId(a.getInt(R.styleable.FABRevealMenu_menuDirection, 0));

        //title
        mTitleTextColor = a.getColor(R.styleable.FABRevealMenu_menuTitleTextColor, getColor(android.R.color.white));
        mTitleDisabledTextColor = a.getColor(R.styleable.FABRevealMenu_menuTitleDisabledTextColor, getColor(android.R.color.darker_gray));
        mShowTitle = a.getBoolean(R.styleable.FABRevealMenu_showTitle, true);
        mShowIcon = a.getBoolean(R.styleable.FABRevealMenu_showIcon, true);
        mShowOverlay = a.getBoolean(R.styleable.FABRevealMenu_showOverlay, true);

        //size
        mMenuSize = a.getInt(R.styleable.FABRevealMenu_menuSize, FAB_MENU_SIZE_NORMAL);

        //animation
        animateItems = a.getBoolean(R.styleable.FABRevealMenu_animateItems, true);

        //Font
        if (a.hasValue(R.styleable.FABRevealMenu_menuTitleFontFamily)) {
            int fontId = a.getResourceId(R.styleable.FABRevealMenu_menuTitleFontFamily, -1);
            if (fontId != -1)
                mMenuTitleTypeface = ResourcesCompat.getFont(context, fontId);
        }

        a.recycle();

        //initialization
        if (mMenuRes != -1) {
            setMenu(mMenuRes);
        } else if (mCustomView != null) {
            setCustomView(mCustomView);
        }
    }
}