Example usage for android.graphics Typeface createFromAsset

List of usage examples for android.graphics Typeface createFromAsset

Introduction

In this page you can find the example usage for android.graphics Typeface createFromAsset.

Prototype

public static Typeface createFromAsset(AssetManager mgr, String path) 

Source Link

Document

Create a new typeface from the specified font data.

Usage

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final Typeface getTypeFaceFromAsset(String assetName) {
    try {/*from w w  w.j  a  va  2s. c  om*/
        return Typeface.createFromAsset(this.getResources().getAssets(), assetName);
    } catch (Throwable e) {
    }

    return null;
}

From source file:com.tengio.FloatingSearchView.java

/**
 * Sets the font in the search text field
 *
 * @param fontPath font path in the assets folder
 */// w ww  .j  a v  a 2 s  .  com
public void setFont(String fontPath) {
    if (TextUtils.isEmpty(fontPath)) {
        return;
    }
    Typeface tf = Typeface.createFromAsset(getContext().getAssets(), fontPath);
    if (tf == null) {
        return;
    }
    mSearchInput.setTypeface(tf, Typeface.BOLD);
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Typeface/*from   w ww  .  ja  v a2s.co m*/
 * @param customFont
 * @return
 */
public static Typeface getTypeface(Context context, String customFont) {
    Typeface tf = fontCache.get(customFont);
    if (tf == null) {
        try {
            tf = Typeface.createFromAsset(context.getAssets(), customFont);
        } catch (Exception e) {
            return null;
        }
        fontCache.put(customFont, tf);
    }
    return tf;
}

From source file:com.juce.JuceAppActivity.java

public final Typeface getTypeFaceFromAsset (String assetName)
{
    try//ww w.  j  ava  2s  . co  m
    {
        return Typeface.createFromAsset (this.getResources().getAssets(), assetName);
    }
    catch (Throwable e) {}

    return null;
}

From source file:com.free.searcher.MainFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Log.d("onViewCreated.savedInstanceState", savedInstanceState + " vvv9");
    tf = Typeface.createFromAsset(activity.getAssets(), "fonts/DejaVuSerifCondensed.ttf");
    initFind();/* w w  w .ja  v  a2s  . co m*/
}

From source file:com.example.search.car.pools.welcome.java

public void dialog(String name, final String[] arr, final TextView tv) {

    final Dialog dialog = new Dialog(welcome.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.setContentView(R.layout.dialog);
    final ListView list = (ListView) dialog.findViewById(R.id.list_cities);
    DialogAdapter adapter = new DialogAdapter(welcome.this, arr);
    list.setAdapter(adapter);//from w  w w . j  a  v a2 s.co m
    final TextView t = (TextView) dialog.findViewById(R.id.tv_1_send_msg);
    t.setText("Select " + name);
    Typeface tf = Typeface.createFromAsset(welcome.this.getAssets(), "AvenirLTStd_Book.otf");
    t.setTypeface(tf);
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            tv.setText(arr[position]);
            dialog.dismiss();
        }
    });
    final RelativeLayout l_close = (RelativeLayout) dialog.findViewById(R.id.l_close);
    l_close.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * Finds all the views we need and configure them properly.
 *//*from   ww w  .j a va 2s  . c o m*/
private void setupViews() {
    //CERTIFICATE
    layout = (LinearLayout) findViewById(R.id.launcher_parent_layout);

    /*   if(!PersonaMainActivity.isRovaPoliciesOn)
          layout.setBackgroundResource(R.drawable.pr_bg);*/

    mDragLayer = (PersonaDragLayer) findViewById(R.id.drag_layer);
    final PersonaDragLayer personaDragLayer = mDragLayer;

    mWorkspace = (PersonaWorkspace) personaDragLayer.findViewById(R.id.workspace);
    final PersonaWorkspace personaWorkspace = mWorkspace;
    // ADW: The app drawer is now a ViewStub and we load the resource
    // depending on custom settings
    ViewStub tmp = (ViewStub) personaDragLayer.findViewById(R.id.stub_drawer);
    int drawerStyle = PersonaAlmostNexusSettingsHelper.getDrawerStyle(this);
    tmp.setLayoutResource(mDrawerStyles[drawerStyle]);
    mAllAppsGrid = (PersonaDrawer) tmp.inflate();
    mDeleteZone = (PersonaDeleteZone) personaDragLayer.findViewById(R.id.delete_zone);

    mHandleView = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_mab);
    mHandleView.setFocusable(true);
    mHandleView.setLauncher(this);
    mHandleView.setOnClickListener(this);
    personaDragLayer.addDragListener(mHandleView);
    /*
     * mHandleView.setOnTriggerListener(new OnTriggerListener() { public
     * void onTrigger(View v, int whichHandle) { mDockBar.open(); } public
     * void onGrabbedStateChange(View v, boolean grabbedState) { } public
     * void onClick(View v) { if (allAppsOpen) { closeAllApps(true); } else
     * { showAllApps(true, null); } } });
     */
    mAllAppsGrid.setTextFilterEnabled(false);
    mAllAppsGrid.setDragger(personaDragLayer);
    mAllAppsGrid.setLauncher(this);

    personaWorkspace.setOnLongClickListener(this);
    personaWorkspace.setDragger(personaDragLayer);
    personaWorkspace.setLauncher(this);

    mDeleteZone.setLauncher(this);
    mDeleteZone.setDragController(personaDragLayer);

    personaDragLayer.setIgnoredDropTarget((View) mAllAppsGrid);
    personaDragLayer.setDragScoller(personaWorkspace);
    personaDragLayer.addDragListener(mDeleteZone);
    // ADW: Dockbar inner icon viewgroup (PersonaMiniLauncher.java)
    mMiniLauncher = (PersonaMiniLauncher) personaDragLayer.findViewById(R.id.mini_content);
    mMiniLauncher.setLauncher(this);
    mMiniLauncher.setOnLongClickListener(this);
    mMiniLauncher.setDragger(personaDragLayer);
    personaDragLayer.addDragListener(mMiniLauncher);

    // ADW: Action Buttons (LAB/RAB)
    mLAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab);
    PersonaLog.d("personalauncher", "lab rab componenets initialized");
    mLAB.setLauncher(this);
    mLAB.setSpecialIcon(R.drawable.pr_arrow_left);
    mLAB.setSpecialAction(ACTION_CATALOG_PREV);
    personaDragLayer.addDragListener(mLAB);
    mRAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab);
    mRAB.setLauncher(this);
    mRAB.setSpecialIcon(R.drawable.pr_arrow_right);
    mRAB.setSpecialAction(ACTION_CATALOG_NEXT);
    personaDragLayer.addDragListener(mRAB);
    mLAB.setOnClickListener(this);
    mRAB.setOnClickListener(this);
    // ADW: secondary aActionButtons
    mLAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab2);
    mLAB2.setLauncher(this);
    personaDragLayer.addDragListener(mLAB2);
    mRAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab2);
    mRAB2.setLauncher(this);
    personaDragLayer.addDragListener(mRAB2);
    mLAB2.setOnClickListener(this);
    mRAB2.setOnClickListener(this);
    // ADW: Dots ImageViews
    mPreviousView = (ImageView) findViewById(R.id.btn_scroll_left);
    mNextView = (ImageView) findViewById(R.id.btn_scroll_right);
    mPreviousView.setOnLongClickListener(this);
    mNextView.setOnLongClickListener(this);

    // ADW: ActionButtons swipe gestures
    mHandleView.setSwipeListener(this);
    mLAB.setSwipeListener(this);
    mLAB2.setSwipeListener(this);
    mRAB.setSwipeListener(this);
    mRAB2.setSwipeListener(this);

    // mHandleView.setDragger(dragLayer);
    // mLAB.setDragger(dragLayer);
    // mRAB.setDragger(dragLayer);
    mRAB2.setDragger(personaDragLayer);
    mLAB2.setDragger(personaDragLayer);

    // ADW linearlayout with apptray, lab and rab
    mDrawerToolbar = findViewById(R.id.drawer_toolbar);
    mHandleView.setNextFocusUpId(R.id.drag_layer);
    mHandleView.setNextFocusLeftId(R.id.drag_layer);
    mLAB.setNextFocusUpId(R.id.drag_layer);
    mLAB.setNextFocusLeftId(R.id.drag_layer);
    mRAB.setNextFocusUpId(R.id.drag_layer);
    mRAB.setNextFocusLeftId(R.id.drag_layer);
    mLAB2.setNextFocusUpId(R.id.drag_layer);
    mLAB2.setNextFocusLeftId(R.id.drag_layer);
    mRAB2.setNextFocusUpId(R.id.drag_layer);
    mRAB2.setNextFocusLeftId(R.id.drag_layer);
    // ADW add a listener to the dockbar to show/hide the app-drawer-button
    // and the dots
    mDockBar = (PersonaDockBar) findViewById(R.id.dockbar);
    mDockBar.setDockBarListener(new DockBarListener() {
        public void onOpen() {
            mDrawerToolbar.setVisibility(View.GONE);
            if (mNextView.getVisibility() == View.VISIBLE) {
                mNextView.setVisibility(View.INVISIBLE);
                mPreviousView.setVisibility(View.INVISIBLE);
            }
        }

        public void onClose() {
            if (mDockStyle != DOCK_STYLE_NONE)
                mDrawerToolbar.setVisibility(View.VISIBLE);
            if (showDots && !isAllAppsVisible()) {
                mNextView.setVisibility(View.VISIBLE);
                mPreviousView.setVisibility(View.VISIBLE);
            }

        }
    });
    if (PersonaAlmostNexusSettingsHelper.getDesktopIndicator(this)) {
        mDesktopIndicator = (PersonaDesktopIndicator) (findViewById(R.id.desktop_indicator));
    }
    // ADW: Add focusability to screen items
    mLAB.setFocusable(true);
    mRAB.setFocusable(true);
    mLAB2.setFocusable(true);
    mRAB2.setFocusable(true);
    mPreviousView.setFocusable(true);
    mNextView.setFocusable(true);

    // ADW: Load the specified theme
    String themePackage = PersonaAlmostNexusSettingsHelper.getThemePackageName(this, THEME_DEFAULT);
    PackageManager pm = getPackageManager();
    Resources themeResources = null;
    if (!themePackage.equals(THEME_DEFAULT)) {
        try {
            themeResources = pm.getResourcesForApplication(themePackage);
        } catch (NameNotFoundException e) {
            // ADW The saved theme was uninstalled so we save the default
            // one
            PersonaAlmostNexusSettingsHelper.setThemePackageName(this, PersonaLauncher.THEME_DEFAULT);
        }
    }
    if (themeResources != null) {
        // Action Buttons
        loadThemeResource(themeResources, themePackage, "lab_bg", mLAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab_bg", mRAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "lab2_bg", mLAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab2_bg", mRAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "mab_bg", mHandleView, THEME_ITEM_BACKGROUND);
        // App drawer button
        // loadThemeResource(themeResources,themePackage,"handle_icon",mHandleView,THEME_ITEM_FOREGROUND);
        // View appsBg=findViewById(R.id.appsBg);
        // loadThemeResource(themeResources,themePackage,"handle",appsBg,THEME_ITEM_BACKGROUND);
        // Deletezone
        loadThemeResource(themeResources, themePackage, "ic_delete", mDeleteZone, THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "delete_zone_selector", mDeleteZone,
                THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_left", mPreviousView,
                THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_right", mNextView, THEME_ITEM_FOREGROUND);
        // Dockbar
        loadThemeResource(themeResources, themePackage, "dockbar_bg", mMiniLauncher, THEME_ITEM_BACKGROUND);
        try {
            themeFont = Typeface.createFromAsset(themeResources.getAssets(), "themefont.ttf");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
    }
    Drawable previous = mPreviousView.getDrawable();
    Drawable next = mNextView.getDrawable();
    mWorkspace.setIndicators(previous, next);

    // ADW: EOF Themes
    updateAlmostNexusUI();
}

From source file:com.olacabs.customer.ui.TrackRideActivity.java

private Bitmap m13911a(int i, String str) {
    int i2 = 50;/*from  w  ww. ja  v a  2 s  .c  om*/
    Typeface createFromAsset = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    int i3 = (int) getResources().getDisplayMetrics().scaledDensity;
    int i4 = i3 * 60;
    int i5 = i3 * 76;
    Config config = Config.ARGB_8888;
    if (i4 <= 0) {
        i4 = 50;
    }
    if (i5 > 0) {
        i2 = i5;
    }
    Bitmap createScaledBitmap = Bitmap
            .createScaledBitmap(BitmapFactoryInstrumentation.decodeResource(getResources(), i), i4, i2, true);
    Canvas canvas = new Canvas(createScaledBitmap);
    float f = (float) (i4 / 2);
    float f2 = (float) (i4 / 2);
    Paint paint = new Paint(1);
    paint.setColor(Color.parseColor("#d4db28"));
    paint.setStyle(Style.FILL);
    paint.setTextSize((float) (i3 * 18));
    paint.setTypeface(createFromAsset);
    if (str.length() == 3) {
        canvas.drawText(str, f - ((float) (i3 * 15)), f2, paint);
    } else if (str.length() == 2) {
        canvas.drawText(str, f - ((float) (i3 * 10)), f2, paint);
    } else if (str.length() == 1) {
        canvas.drawText(str, f - ((float) (i3 * 6)), f2, paint);
    }
    paint.setTextSize((float) (i3 * 16));
    canvas.drawText(" min ", f - ((float) (i3 * 18)), f2 + ((float) (i3 * 15)), paint);
    return createScaledBitmap;
}

From source file:saphion.services.ForegroundService.java

private XYMultipleSeriesRenderer getRenderer() {
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    renderer.setAxisTitleTextSize(getDimension(10.67f));
    renderer.setChartTitleTextSize(getDimension(13.34f));
    renderer.setPointSize(0f);/*from w ww .ja  va 2s .  c o m*/
    renderer.setMargins(new int[] { (int) getDimension(20f), // 13.34
            (int) getDimension(33.34f), (int) getDimension(1f), // 10
            (int) getDimension(6.67f) });
    XYSeriesRenderer r = new XYSeriesRenderer();
    r.setColor(0xff1e8bd4);

    renderer.setBackgroundColor(0x00000000);
    // renderer.setApplyBackgroundColor(true);
    /* r.setFillBelowLine(true); */
    FillOutsideLine fol = new FillOutsideLine(XYSeriesRenderer.FillOutsideLine.Type.BOUNDS_ALL);
    fol.setColor(0xa01e8bd4);
    r.addFillOutsideLine(fol);
    renderer.setYLabelsAlign(Align.RIGHT);

    // r.setFillBelowLineColor(0xff21637c);
    r.setLineWidth(getDimension(2.67f));
    renderer.setMarginsColor(0xff111111);
    renderer.setLabelsTextSize(getDimension(10f));

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        renderer.setXLabels(5);
    } else {
        renderer.setXLabels(6);
    }

    renderer.setYLabels(11);
    renderer.addSeriesRenderer(r);
    renderer.setShowGrid(true);
    renderer.setShowLegend(false);
    renderer.setInScroll(true);

    r = new XYSeriesRenderer();
    r.setPointStyle(PointStyle.POINT);
    r.setLineWidth(4);

    if (isconnected) {
        r.setColor(0xff17699f);
        FillOutsideLine fol1 = new FillOutsideLine(XYSeriesRenderer.FillOutsideLine.Type.BOUNDS_ALL);
        fol1.setColor(0xa017699f);
        r.addFillOutsideLine(fol1);

    } else {

        r.setColor(0xffff4444);
        FillOutsideLine fol2 = new FillOutsideLine(XYSeriesRenderer.FillOutsideLine.Type.BOUNDS_ALL);
        fol2.setColor(0xa0ff4444);
        r.addFillOutsideLine(fol2);
    }

    renderer.setPanEnabled(true, false);
    renderer.setShowAxes(true);
    renderer.setAntialiasing(true);
    renderer.setZoomEnabled(true, false);
    renderer.setYAxisMax(100);
    renderer.setYAxisMin(0);
    renderer.setTextTypeface(Typeface.createFromAsset(getAssets(), Constants.FONT_ROBOTO_COND));

    renderer.addSeriesRenderer(r);

    renderer.setXAxisMax(lastentry + 1800000);

    for (int i = 0; i <= 100; i = i + 10)
        renderer.addYTextLabel(i, i + " %");

    renderer.setAxesColor(Color.WHITE);
    renderer.setLabelsColor(Color.LTGRAY);
    renderer.setInScroll(false);
    return renderer;
}

From source file:org.openintents.notepad.NoteEditor.java

private boolean setRemoteStyle(String styleName, int size) {
    if (TextUtils.isEmpty(styleName)) {
        if (DEBUG) {
            Log.e(TAG, "Empty style name: " + styleName);
        }/* w w  w  . j  a va  2  s.com*/
        return false;
    }

    PackageManager pm = getPackageManager();

    String packageName = ThemeUtils.getPackageNameFromStyle(styleName);

    if (packageName == null) {
        Log.e(TAG, "Invalid style name: " + styleName);
        return false;
    }

    Context c = null;
    try {
        c = createPackageContext(packageName, 0);
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Package for style not found: " + packageName + ", " + styleName);
        return false;
    }

    Resources res = c.getResources();

    int themeid = res.getIdentifier(styleName, null, null);
    if (DEBUG) {
        Log.d(TAG, "Retrieving theme: " + styleName + ", " + themeid);
    }

    if (themeid == 0) {
        Log.e(TAG, "Theme name not found: " + styleName);
        return false;
    }

    try {
        ThemeAttributes ta = new ThemeAttributes(c, packageName, themeid);

        mTextTypeface = ta.getString(ThemeNotepad.TEXT_TYPEFACE);
        if (DEBUG) {
            Log.d(TAG, "textTypeface: " + mTextTypeface);
        }

        mCurrentTypeface = null;

        // Look for special cases:
        if ("monospace".equals(mTextTypeface)) {
            mCurrentTypeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL);
        } else if ("sans".equals(mTextTypeface)) {
            mCurrentTypeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
        } else if ("serif".equals(mTextTypeface)) {
            mCurrentTypeface = Typeface.create(Typeface.SERIF, Typeface.NORMAL);
        } else if (!TextUtils.isEmpty(mTextTypeface)) {

            try {
                if (DEBUG) {
                    Log.d(TAG, "Reading typeface: package: " + packageName + ", typeface: " + mTextTypeface);
                }
                Resources remoteRes = pm.getResourcesForApplication(packageName);
                mCurrentTypeface = Typeface.createFromAsset(remoteRes.getAssets(), mTextTypeface);
                if (DEBUG) {
                    Log.d(TAG, "Result: " + mCurrentTypeface);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Package not found for Typeface", e);
            }
        }

        mTextUpperCaseFont = ta.getBoolean(ThemeNotepad.TEXT_UPPER_CASE_FONT, false);

        mTextColor = ta.getColor(ThemeNotepad.TEXT_COLOR, android.R.color.white);

        if (DEBUG) {
            Log.d(TAG, "textColor: " + mTextColor);
        }

        if (size == 0) {
            mTextSize = getTextSizeTiny(ta);
        } else if (size == 1) {
            mTextSize = getTextSizeSmall(ta);
        } else if (size == 2) {
            mTextSize = getTextSizeMedium(ta);
        } else {
            mTextSize = getTextSizeLarge(ta);
        }
        if (DEBUG) {
            Log.d(TAG, "textSize: " + mTextSize);
        }

        if (mText != null) {
            mBackgroundPadding = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING, -1);
            int backgroundPaddingLeft = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_LEFT,
                    mBackgroundPadding);
            int backgroundPaddingTop = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_TOP,
                    mBackgroundPadding);
            int backgroundPaddingRight = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_RIGHT,
                    mBackgroundPadding);
            int backgroundPaddingBottom = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_BOTTOM,
                    mBackgroundPadding);

            if (DEBUG) {
                Log.d(TAG,
                        "Padding: " + mBackgroundPadding + "; " + backgroundPaddingLeft + "; "
                                + backgroundPaddingTop + "; " + backgroundPaddingRight + "; "
                                + backgroundPaddingBottom + "; ");
            }

            try {
                Resources remoteRes = pm.getResourcesForApplication(packageName);
                int resid = ta.getResourceId(ThemeNotepad.BACKGROUND, 0);
                if (resid != 0) {
                    Drawable d = remoteRes.getDrawable(resid);
                    mText.setBackgroundDrawable(d);
                } else {
                    // remove background
                    mText.setBackgroundResource(0);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Package not found for Theme background.", e);
            } catch (Resources.NotFoundException e) {
                Log.e(TAG, "Resource not found for Theme background.", e);
            }

            // Apply padding
            if (mBackgroundPadding >= 0 || backgroundPaddingLeft >= 0 || backgroundPaddingTop >= 0
                    || backgroundPaddingRight >= 0 || backgroundPaddingBottom >= 0) {
                mText.setPadding(backgroundPaddingLeft, backgroundPaddingTop, backgroundPaddingRight,
                        backgroundPaddingBottom);
            } else {
                // 9-patches do the padding automatically
                // todo clear padding
            }
        }

        mLinesMode = ta.getInteger(ThemeNotepad.LINE_MODE, 2);
        mLinesColor = ta.getColor(ThemeNotepad.LINE_COLOR, 0xFF000080);

        if (DEBUG) {
            Log.d(TAG, "line color: " + mLinesColor);
        }

        return true;

    } catch (UnsupportedOperationException e) {
        // This exception is thrown e.g. if one attempts
        // to read an integer attribute as dimension.
        Log.e(TAG, "UnsupportedOperationException", e);
        return false;
    } catch (NumberFormatException e) {
        // This exception is thrown e.g. if one attempts
        // to read a string as integer.
        Log.e(TAG, "NumberFormatException", e);
        return false;
    }
}