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:Main.java

/**
 * Sets a determined font on a text view element
 *
 * @param context Context in which the TextView can be found
 * @param font    Font to be set in the text view see available fonts as static attributes of this class
 * @param group   Root layout in which TextView and Buttons will be searched to apply the font
 *//*from   w w w  .j  a  v a2s.  co  m*/
public static void setTypeface(Context context, String font, ViewGroup group) {
    Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
    int count = group.getChildCount();
    View v;
    for (int i = 0; i < count; i++) {
        v = group.getChildAt(i);
        if (v instanceof TextView)
            ((TextView) v).setTypeface(tf);
        else if (v instanceof ViewGroup)
            setTypeface(context, font, (ViewGroup) v);
    }
}

From source file:tech.salroid.filmy.activities.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    nightMode = sp.getBoolean("dark", false);
    if (nightMode)
        setTheme(R.style.AppTheme_Base_Dark);
    else//from   ww  w .  j  a v a2 s . c  o  m
        setTheme(R.style.AppTheme_Base);

    setContentView(R.layout.activity_login);

    ButterKnife.bind(this);

    setSupportActionBar(toolbar);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(" ");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/canaro_extra_bold.otf");
    logo.setTypeface(typeface);

    if (nightMode)
        allThemeLogic();

    loginNow();

}

From source file:com.module.candychat.net.wouclass.CaseInsensitiveAssetFontLoader.java

@Override
public Typeface getTypeFace(String typefaceName) {
    String lowerTypefaceName = typefaceName.toLowerCase();
    Typeface typeface = sTypefaceCache.get(lowerTypefaceName);

    if (typeface == null) {
        String fontFile = mTypefacenameMapping.get(lowerTypefaceName);

        try {//from w  ww  .  ja  va  2  s  . co m
            typeface = Typeface.createFromAsset(mAssetManager, fontFile);
            sTypefaceCache.put(lowerTypefaceName, typeface);
            sTypefaceCache555.put(typeface, typefaceName);
        } catch (java.lang.RuntimeException e) {
            return android.graphics.Typeface.DEFAULT;
        }

    }
    return typeface;
}

From source file:info.degois.damien.android.CustomFontHtml.CaseInsensitiveAssetFontLoader.java

@Override
public Typeface getTypeFace(String typefaceName) {
    String lowerTypefaceName = typefaceName.toLowerCase();
    Typeface typeface = sTypefaceCache.get(lowerTypefaceName);

    if (typeface == null) {
        String fontFile = mTypefacenameMapping.get(lowerTypefaceName);

        try {/*from   w  ww.  java  2 s .  com*/
            typeface = Typeface.createFromAsset(mAssetManager, fontFile);
            sTypefaceCache.put(lowerTypefaceName, typeface);
        } catch (java.lang.RuntimeException e) {
            return android.graphics.Typeface.DEFAULT;
        }
    }
    return typeface;
}

From source file:com.ieeecsvit.riviera17android.activity.MainActivity.java

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override//from  w w  w  .  j  av a  2  s.  c  o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setBackgroundColor(Color.parseColor("#302236"));
    getSupportActionBar().setTitle("");

    if (Preferences.getPrefs(Consts.SHOW_WISHLIST_PREF, this).equals(Consts.TRUE)
            || Preferences.getPrefs(Consts.SHOW_WISHLIST_PREF, this).equals(Consts.NOT_FOUND)) {
        CustomDialogClass cdd = new CustomDialogClass(this);
        cdd.show();
    }

    pre = (TextView) findViewById(R.id.pretext);
    work = (TextView) findViewById(R.id.workshoptext);
    formal = (TextView) findViewById(R.id.formaltext);
    informal = (TextView) findViewById(R.id.informaltext);
    cyber = (TextView) findViewById(R.id.sportstext);
    premium = (TextView) findViewById(R.id.premiumtext);

    bell = (ImageView) toolbar.findViewById(R.id.iv_bell);

    bell.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MainActivity.this, NotificationsActivity.class);
            startActivity(intent);
        }
    });

    if (Preferences.getPrefs(Consts.ROLE_PREF, this).equals("admin")) {
        bell.setVisibility(View.VISIBLE);
    }

    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Regular.ttf");

    premium.setTypeface(typeface);
    pre.setTypeface(typeface);
    work.setTypeface(typeface);
    formal.setTypeface(typeface);
    informal.setTypeface(typeface);
    cyber.setTypeface(typeface);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (Preferences.getPrefs(Consts.LOGGED_IN_PREF, MainActivity.this).equals("0")) {
        hideItem();
    }
}

From source file:com.physphil.android.restaurantroulette.ui.RestaurantListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    final Restaurant restaurant = mRestaurants.get(position);

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.row_restaurant_list, parent, false);
    }/*from  w  ww  . j a v a 2  s.co m*/

    TextView tvName = (TextView) convertView.findViewById(R.id.restaurant_name);
    TextView tvGenre = (TextView) convertView.findViewById(R.id.restaurant_genre);
    RatingBar rbRating = (RatingBar) convertView.findViewById(R.id.restaurant_rating);
    ImageButton btnDelete = (ImageButton) convertView.findViewById(R.id.restaurant_delete_button);
    Typeface defaultFont = Typeface.createFromAsset(mContext.getAssets(), Constants.FONT_DEFAULT);

    tvName.setText(restaurant.getName());
    tvName.setTypeface(defaultFont);
    tvGenre.setText(restaurant.getGenre());
    tvGenre.setTypeface(defaultFont);
    rbRating.setRating(restaurant.getUserRating());

    btnDelete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //                new AlertDialog.Builder(mContext)
            new CustomFontDialogBuilder(mContext).setTitle(R.string.dialog_delete_restaurant_title)
                    .setMessage(R.string.dialog_delete_restaurant_message)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            // Send broadcast to hosting fragment to delete restaurant from database
                            Intent i = new Intent(RestaurantFragment.ACTION_DELETE_RESTAURANT);
                            i.putExtra(RestaurantFragment.EXTRA_RESTAURANT_ID, restaurant.getRestaurantId());
                            LocalBroadcastManager.getInstance(mContext).sendBroadcast(i);
                        }
                    }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    }).show();
        }
    });

    return convertView;
}

From source file:gov.wa.wsdot.android.wsdot.ui.MountainPassItemReportFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Regular.ttf");
    Typeface tfb = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Bold.ttf");

    mRootView = (ViewGroup) inflater.inflate(R.layout.mountainpass_item_details, null);

    TextView date_updated = (TextView) mRootView.findViewById(R.id.date_updated);
    date_updated.setTypeface(tf);//from ww  w.ja  v a2s  .  com
    date_updated.setText(mDateUpdated);

    TextView weather_condition_header = (TextView) mRootView.findViewById(R.id.weather_condition_title);
    weather_condition_header.setTypeface(tfb);
    weather_condition_header.setText("Weather:");

    TextView weather_condition_text = (TextView) mRootView.findViewById(R.id.weather_condition_text);
    weather_condition_text.setTypeface(tf);
    weather_condition_text.setText(mWeatherCondition);

    TextView temperature_header = (TextView) mRootView.findViewById(R.id.temperature_title);
    temperature_header.setTypeface(tfb);
    temperature_header.setText("Temperature:");

    TextView temperature_text = (TextView) mRootView.findViewById(R.id.temperature_text);
    temperature_text.setTypeface(tf);
    temperature_text.setText(mTemperatureInFahrenheit);

    TextView elevation_header = (TextView) mRootView.findViewById(R.id.elevation_title);
    elevation_header.setTypeface(tfb);
    elevation_header.setText("Elevation:");

    TextView elevation_text = (TextView) mRootView.findViewById(R.id.elevation_text);
    elevation_text.setTypeface(tf);
    elevation_text.setText(mElevationInFeet + " ft");

    TextView road_condition_header = (TextView) mRootView.findViewById(R.id.road_condition_title);
    road_condition_header.setTypeface(tfb);
    road_condition_header.setText("Conditions:");

    TextView road_condition_text = (TextView) mRootView.findViewById(R.id.road_condition_text);
    road_condition_text.setTypeface(tf);
    road_condition_text.setText(mRoadCondition);

    TextView restriction_one_header = (TextView) mRootView.findViewById(R.id.restriction_one_title);
    restriction_one_header.setTypeface(tfb);
    restriction_one_header.setText("Restrictions " + mRestrictionOneTravelDirection + ":");

    TextView restriction_one_text = (TextView) mRootView.findViewById(R.id.restriction_one_text);
    restriction_one_text.setTypeface(tf);
    restriction_one_text.setText(mRestrictionOneText);

    TextView restriction_two_header = (TextView) mRootView.findViewById(R.id.restriction_two_title);
    restriction_two_header.setTypeface(tfb);
    restriction_two_header.setText("Restrictions " + mRestrictionTwoTravelDirection + ":");

    TextView restriction_two_text = (TextView) mRootView.findViewById(R.id.restriction_two_text);
    restriction_two_text.setTypeface(tf);
    restriction_two_text.setText(mRestrictionTwoText);

    return mRootView;
}

From source file:com.adampmarshall.speedo.LocationActivity.java

/**
 * This sample demonstrates how to incorporate location based services in
 * your app and process location updates. The app also shows how to convert
 * lat/long coordinates to human-readable addresses.
 *//*  ww w .ja  v  a  2 s .  c o  m*/
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Restore apps state (if exists) after rotation.
    if (savedInstanceState != null) {
        mUseFine = savedInstanceState.getBoolean(KEY_FINE);
        mUseBoth = savedInstanceState.getBoolean(KEY_BOTH);
    } else {
        mUseFine = false;
        mUseBoth = true;
    }
    mSpeed = (TextView) findViewById(R.id.speed);
    Typeface font = Typeface.createFromAsset(getAssets(), "DS-DIGI.TTF");
    mSpeed.setTypeface(font);

    // The isPresent() helper method is only available on Gingerbread or
    // above.
    mGeocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent();

    // Handler for updating text fields on the UI like the lat/long and
    // address.
    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case UPDATE_SPEED:
                mSpeed.setText((String) msg.obj);
                break;
            }
        }
    };
    // Get a reference to the LocationManager object.
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mGmeterView = (GmeterView) findViewById(R.id.gmeter);

}

From source file:com.benlinskey.greekreference.GreekTextView.java

/**
 * Class constructor.// w  w w  .j  a  va2s  .  com
 *
 * @param context
 * @param attrs
 */
@SuppressWarnings("JavaDoc")
public GreekTextView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (!isInEditMode() && !TextUtils.isEmpty(TYPEFACE_NAME)) {
        Typeface typeface = sTypefaceCache.get(TYPEFACE_NAME);

        if (typeface == null) {
            typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + TYPEFACE_NAME);

            // Cache the Typeface object
            sTypefaceCache.put(TYPEFACE_NAME, typeface);
        }
        setTypeface(typeface);

        int textColor = getResources()
                .getColor(android.support.v7.appcompat.R.color.primary_text_default_material_light);
        setTextColor(textColor);

        // Note: This flag is required for proper typeface rendering
        setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    }
}

From source file:com.physphil.android.restaurantroulette.HistoryListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_history_list, container, false);

    // Set font for text when listview is empty
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), Constants.FONT_DEFAULT);
    ((TextView) v.findViewById(android.R.id.empty)).setTypeface(tf);

    return v;/*from   w  w  w  . j  av  a  2  s.co  m*/
}