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.github.fountaingeyser.typefacecompat.TypefaceCompat.java

public static Typeface create(Context ctx, String familyName, int style) {
    if (isSupported(familyName)) {
        boolean styleAfterwards = false;
        String fileName = FONT_FAMILY_FILE_PREFIX.get(familyName);
        if (fileName.endsWith("-")) {
            // All styles are supported.
            fileName += STYLE_SUFFIX[style];
        } else {/*from w ww.j a  v a  2 s  . c  om*/
            switch (style) {
            case Typeface.NORMAL:
                break;
            case Typeface.BOLD:
            case Typeface.BOLD_ITALIC:
                // These styles are not supported by default. Therefore force style after retrieving normal font.
                styleAfterwards = true;
                break;
            case Typeface.ITALIC:
                fileName += STYLE_SUFFIX[style];
                break;
            }
        }
        fileName += TTF_SUFFIX;
        // Retrieve Typeface from cache.
        Typeface tf = TYPEFACE_CACHE.get(fileName);
        if (tf == null) {
            // Create Typeface and cache it for later.
            String fontPath = "fonts/" + fileName;
            tf = Typeface.createFromAsset(ctx.getAssets(), fontPath);
            if (tf != null) {
                TYPEFACE_CACHE.put(fileName, tf);
            }
        }
        if (tf != null) {
            return styleAfterwards ? Typeface.create(tf, style) : tf;
        }
    }
    // Let the default implementation of Typeface try.
    return Typeface.create(familyName, style);
}

From source file:foam.mongoose.StarwispActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from   w ww  .j a v  a  2 s.  co m

    String arg = "none";
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        arg = extras.getString("arg");
    }

    String json = m_Scheme.eval("(activity-callback 'on-create \"" + m_Name + "\" (list \"" + arg + "\"))");
    View root = findViewById(R.id.main);

    //m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/Pfennig.ttf");
    //m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/grstylus.ttf");
    m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/RobotoCondensed-Regular.ttf");

    try {
        m_Builder.Build(this, m_Name, new JSONArray(json), (ViewGroup) root);
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + json + "] " + e.toString());
    }
}

From source file:applicationVo.UserProfileDataAsync.java

public Typeface getFountType() {
    return founttype = Typeface.createFromAsset(context.getAssets(), "fonts/calibri.ttf");
}

From source file:com.db.williamchartdemo.ChartsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View layout = inflater.inflate(R.layout.charts, container, false);

    ((AppCompatActivity) getActivity()).setSupportActionBar((Toolbar) layout.findViewById(R.id.toolbar));
    ((TextView) layout.findViewById(R.id.title))
            .setTypeface(Typeface.createFromAsset(getContext().getAssets(), "Ponsi-Regular.otf"));

    (new LineCardOne((CardView) layout.findViewById(R.id.card1), getContext())).init();
    (new LineCardThree((CardView) layout.findViewById(R.id.card2), getContext())).init();
    (new BarCardOne((CardView) layout.findViewById(R.id.card3), getContext())).init();
    (new StackedCardThree((CardView) layout.findViewById(R.id.card4), getContext())).init();
    (new StackedCardOne((CardView) layout.findViewById(R.id.card5))).init();
    (new BarCardThree((CardView) layout.findViewById(R.id.card6), getContext())).init();
    (new BarCardTwo((CardView) layout.findViewById(R.id.card7), getContext())).init();
    (new StackedCardTwo((CardView) layout.findViewById(R.id.card8))).init();
    (new LineCardTwo((CardView) layout.findViewById(R.id.card9))).init();

    return layout;
}

From source file:foam.jellyfish.StarwispActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from w  ww  .  ja va 2s  . c om
    OuyaController.init(this);

    String arg = "none";
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        arg = extras.getString("arg");
    }

    String json = m_Scheme.eval("(activity-callback 'on-create \"" + m_Name + "\" (list \"" + arg + "\"))");
    View root = findViewById(R.id.main);

    m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/Pfennig.ttf");
    //m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/grstylus.ttf");

    try {
        m_Builder.Build(this, m_Name, new JSONArray(json), (ViewGroup) root);
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + json + "] " + e.toString());
    }
}

From source file:gr.sepals.eshop.info.gui.SyncSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_info_sync, container, false);
    if (getResources().getBoolean(R.bool.isTablet)) {
        title = (TextView) rootView.findViewById(R.id.info_sync_title_textview);
        Typeface titleFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Pyrsos.otf");
        title.setTypeface(titleFont, Typeface.BOLD);
    }/*from  w w  w  .jav  a2  s  . c om*/
    desc = (TextView) rootView.findViewById(R.id.info_sync_description_textview);
    Typeface descFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Goschen-Italic.otf");
    desc.setTypeface(descFont);

    memoryOption = (RadioGroup) rootView.findViewById(R.id.memory_radioGroup);
    internal = (RadioButton) rootView.findViewById(R.id.internal_memory_radiobutton);
    internal.setTypeface(descFont);
    internal.setOnClickListener(this);
    embedded = (RadioButton) rootView.findViewById(R.id.embedded_memory_radiobutton);
    embedded.setTypeface(descFont);
    embedded.setOnClickListener(this);
    removable = (RadioButton) rootView.findViewById(R.id.removable_memory_radiobutton);
    //check if there is sdcard port at device
    if (DeviceOptionsHandler.checkAvailableExternalMemory(getActivity()) == -1) {
        memoryOption.removeView(removable);
    } else {
        removable.setTypeface(descFont);
        removable.setOnClickListener(this);
    }

    sync = (Button) rootView.findViewById(R.id.sync_button);
    sync.setOnClickListener(this);
    exit = (Button) rootView.findViewById(R.id.exit_button);
    exit.setOnClickListener(this);

    // update the fragment content
    String selectedStorage = Settings.getString(getActivity(), InternalDatabaseKeys.PRODUCTS_DB_STORAGE_OPTION,
            InternalDatabasePredefinedValues.PRODUCTS_DB_NONE_STORAGE);
    if (selectedStorage.equals(InternalDatabasePredefinedValues.PRODUCTS_DB_INTERNAL_STORAGE)) {
        memoryOption.check(R.id.internal_memory_radiobutton);
        sync.setEnabled(true);
    } else if (selectedStorage.equals(InternalDatabasePredefinedValues.PRODUCTS_DB_EMBEDDED_STORAGE)) {
        memoryOption.check(R.id.embedded_memory_radiobutton);
        sync.setEnabled(true);
    } else if (selectedStorage.equals(InternalDatabasePredefinedValues.PRODUCTS_DB_REMOVABLE_STORAGE)) {
        memoryOption.check(R.id.removable_memory_radiobutton);
        sync.setEnabled(true);
    } else {
        sync.setEnabled(false);
    }
    return rootView;
}

From source file:io.github.tonyguyot.acronym.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   w  ww.java 2 s .c  om*/

    // set custom font for the app title
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    }
    TextView title = (TextView) toolbar.findViewById(R.id.toolbar_title);
    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Lobster-Regular.ttf");
    title.setTypeface(tf);

    // set the tabs and view pager
    final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    TabLayout tabLayout = (TabLayout) toolbar.findViewById(R.id.toolbar_tabs);
    tabLayout.setupWithViewPager(viewPager);

    // set the callback for the FAB
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // select the first tab
            viewPager.setCurrentItem(0);

            // set focus on edit text, clear it and display keyboard
            EditText ed = (EditText) viewPager.findViewById(R.id.query_entry);
            ed.requestFocus();
            ed.setText("");
            Utils.showKeyboard(MainActivity.this);
        }
    });
}

From source file:com.doodle.android.chips.sample.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContacts = (RecyclerView) findViewById(R.id.rv_contacts);
    mContacts.setLayoutManager(new LinearLayoutManager(MainActivity.this));
    mAdapter = new ContactsAdapter();
    mContacts.setAdapter(mAdapter);// w  w  w.  j a  v a2s .com

    mChipsView = (ChipsView) findViewById(R.id.cv_contacts);

    mChipsView.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/FiraSans-Medium.ttf"));
    // mChipsView.useInitials(14, Typeface.createFromAsset(this.getAssets(), "fonts/FiraSans-Medium.ttf"), Color.RED);

    // change EditText config
    mChipsView.getEditText().setCursorVisible(true);

    mChipsView.setChipsValidator(new ChipsView.ChipValidator() {
        @Override
        public boolean isValid(Contact contact) {
            if (contact.getDisplayName().equals("asd@qwe.de")) {
                return false;
            }
            return true;
        }
    });

    mChipsView.setChipsListener(new ChipsView.ChipsListener() {
        @Override
        public void onChipAdded(ChipsView.Chip chip) {
            for (ChipsView.Chip chipItem : mChipsView.getChips()) {
                Log.d("ChipList", "chip: " + chipItem.toString());
            }
        }

        @Override
        public void onChipDeleted(ChipsView.Chip chip) {

        }

        @Override
        public void onTextChanged(CharSequence text) {
            mAdapter.filterItems(text);
        }

        @Override
        public boolean onInputNotRecognized(String text) {

            try {
                FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();

                Bundle bundle = new Bundle();
                bundle.putString(ChipsEmailDialogFragment.EXTRA_STRING_TEXT, text);
                bundle.putString(ChipsEmailDialogFragment.EXTRA_STRING_TITLE, "Title");
                bundle.putString(ChipsEmailDialogFragment.EXTRA_STRING_PLACEHOLDER, "ChipsDialogPlaceholder");
                bundle.putString(ChipsEmailDialogFragment.EXTRA_STRING_CONFIRM, "ChipsDialogConfirm");
                bundle.putString(ChipsEmailDialogFragment.EXTRA_STRING_CANCEL, "ChipsDialogCancel");
                bundle.putString(ChipsEmailDialogFragment.EXTRA_STRING_ERROR_MSG, "ChipsDialogErrorMsg");

                ChipsEmailDialogFragment chipsEmailDialogFragment = new ChipsEmailDialogFragment();
                chipsEmailDialogFragment.setArguments(bundle);
                chipsEmailDialogFragment.setEmailListener(new ChipsEmailDialogFragment.EmailListener() {
                    @Override
                    public void onDialogEmailEntered(String text, String displayName) {
                        mChipsView.addChip(displayName, null, new Contact(null, null, displayName, text, null),
                                false);
                        mChipsView.clearText();
                    }
                });
                chipsEmailDialogFragment.show(fragmentManager, ChipsEmailDialogFragment.class.getSimpleName());
            } catch (ClassCastException e) {
                Log.e("CHIPS", "Error ClassCast", e);
            }
            return false;
        }
    });
}

From source file:com.google.android.apps.santatracker.VillageNotificationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_takeoff);

    mVillageView = (VillageView) findViewById(R.id.villageView);
    mVillage = (Village) getSupportFragmentManager().findFragmentByTag(VILLAGE_TAG);
    if (mVillage == null) {
        mVillage = new Village();
        getSupportFragmentManager().beginTransaction().add(mVillage, VILLAGE_TAG).commit();
    }//from  w w w  .ja va2s  . c o  m
    mVillageView.setVillage(mVillage);

    //Align card to bottom if content is smaller than screen.
    CardScrollView cardScrollView = (CardScrollView) findViewById(R.id.card_scroll_view);
    cardScrollView.setCardGravity(Gravity.BOTTOM);

    mTextView = (TextView) findViewById(R.id.text);
    mTextView.setTypeface(Typeface.createFromAsset(getAssets(),
            getResources().getString(R.string.typeface_robotocondensed_light)));
    mTextView.setText(getIntent().getStringExtra(NotificationConstants.KEY_CONTENT));
}

From source file:com.example.reabar.wimc.Fragments.CarScreenFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_car_screen, container, false);

    TextView text = (TextView) view.findViewById(R.id.deleteTextView);
    Button addUserButton = (Button) view.findViewById(R.id.addUserButton);

    Typeface english = Typeface.createFromAsset(getActivity().getAssets(), "KOMIKAX_.ttf"); // create a typeface from the raw ttf
    Typeface hebrew = Typeface.createFromAsset(getActivity().getAssets(), "OpenSansHebrew-Bold.ttf"); // create a typeface from the raw ttf
    if (Locale.getDefault().getDisplayLanguage().equals("")) {
        addUserButton.setTypeface(hebrew);
        text.setTypeface(hebrew);// w  w  w  .j  a  v  a2  s . co m
    } else {
        addUserButton.setTypeface(english);
        text.setTypeface(english);
    }

    if (sharedUsersList == null) {
        sharedUsersList = new ArrayList<>();
    }

    if (sharedUsersList.isEmpty()) {
        text.setVisibility(View.GONE);
    }

    TextView licenseTextView = (TextView) view.findViewById(R.id.cars_list_row_car_license);
    licenseTextView.setText(carLicense);
    TextView modelCompanyTextView = (TextView) view.findViewById(R.id.cars_list_row_car_model_company);
    modelCompanyTextView.setText(modelCompany);

    list = (ListView) view.findViewById(R.id.listSharedUsersID);
    adapter = new MyUsersCarAdapter();
    list.setAdapter(adapter);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            car.removeCarUser(sharedUsersList.get(position));
            adapter.notifyDataSetChanged();
            Toast.makeText(MyApplication.getAppActivity(), "User removed successfully", Toast.LENGTH_SHORT)
                    .show();
        }
    });

    emailSharedInput = (EditText) view.findViewById(R.id.emailSharedinput);
    addUserButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //hide keyboard after click
            InputMethodManager inputManager = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            if (emailSharedInput.getText().toString().matches("")) {
                Toast.makeText(MyApplication.getAppActivity(), "You must enter email of the shared user",
                        Toast.LENGTH_SHORT).show();
            } else {
                //addUser user to car by email
                final String userEmail = emailSharedInput.getText().toString();
                //car.setCarUser(userEmail, true);
                //car.setNewCarUser(userEmail);
                Model.getInstance().setCarUser(car, userEmail);
                emailSharedInput.setText("");
                adapter.notifyDataSetChanged();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //sharedUsersList.add(userEmail);
                Object[] data = new Object[] { car };
                fragmentCommunicator.passData(data, "CarScreenFragment");
            }
        }
    });

    return view;
}