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 style   {@see Typeface}//from w w  w  .ja v a 2  s.c o m
 * @param group   Root layout in which TextView and Buttons will be searched to apply the font
 */
public static void setTypeface(Context context, String font, int style, 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, style);
        else if (v instanceof ViewGroup)
            setTypeface(context, font, style, (ViewGroup) v);
    }
}

From source file:net.networksaremadeofstring.cyllell.Search.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_main);

    //Fancy title
    ((TextView) findViewById(R.id.TitleBarText))
            .setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/codeops_serif.ttf"));

    //List view to hold search results
    list = (ListView) findViewById(R.id.SearchResultsListView);

    //Prep the handler to do all the UI updating etc
    MakeHandler();/*from  w  ww .  j  a v  a 2s. co m*/

    //This is for the crafted search (not visible if the user came in via a search intent
    ((Button) findViewById(R.id.SearchButton)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            index = ((Spinner) findViewById(R.id.IndexChoice)).getSelectedItem().toString().toLowerCase();
            query = ((TextView) findViewById(R.id.SearchStringEditText)).getText().toString();
            PerformSearch(true);
        }
    });

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        findViewById(R.id.SearchParamContainer).setVisibility(8);
        //findViewById(R.id.ShowSearchParams).setVisibility(0);
        findViewById(R.id.SearchMainRelativeLayout).invalidate();

        query = intent.getStringExtra(SearchManager.QUERY);
        index = "node";

        PerformSearch(false);
    } else if (Intent.ACTION_SEARCH_LONG_PRESS.equals(intent.getAction())) {
        //findViewById(R.id.SearchParamContainer).setVisibility(0);
        //findViewById(R.id.ShowSearchParams).setVisibility(4);
    } else {
        //findViewById(R.id.SearchParamContainer).setVisibility(0);
        //findViewById(R.id.ShowSearchParams).setVisibility(4);
    }

    /*((ImageView)findViewById(R.id.ShowSearchParams)).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)
    {
       findViewById(R.id.SearchParamContainer).setVisibility(0);
      findViewById(R.id.ShowSearchParams).setVisibility(4);
      findViewById(R.id.SearchMainRelativeLayout).invalidate();
    }
     });
            
    ((ImageView)findViewById(R.id.HideSearchParams)).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)
    {
       findViewById(R.id.SearchParamContainer).setVisibility(8);
      findViewById(R.id.ShowSearchParams).setVisibility(0);
      findViewById(R.id.SearchMainRelativeLayout).invalidate();
              
    }
     });*/
}

From source file:com.brandao.tictactoe.statistics.StatisticFragment.java

@Override
public void onViewCreated(final View v, @Nullable Bundle savedInstanceState) {
    Typeface titleFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/DroidSans-Bold.ttf");

    if (((TextView) v.findViewById(R.id.tic)) != null) {
        ((TextView) v.findViewById(R.id.tic)).setTypeface(titleFont);
        ((TextView) v.findViewById(R.id.tac)).setTypeface(titleFont);
        ((TextView) v.findViewById(R.id.toe)).setTypeface(titleFont);
    }/*from   w ww .  ja v  a  2 s  .c  o  m*/

    ((TextView) v.findViewById(R.id.easy_title)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.medium_title)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.hard_title)).setTypeface(titleFont);

    ((TextView) v.findViewById(R.id.games_won_title_easy)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_lost_title_easy)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_tied_title_easy)).setTypeface(titleFont);

    ((TextView) v.findViewById(R.id.games_won_num_easy)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_lost_num_easy)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_tied_num_easy)).setTypeface(titleFont);

    ((ImageView) v.findViewById(R.id.games_won_image_easy))
            .setBackgroundResource(R.drawable.ic_green_x_android);
    ((ImageView) v.findViewById(R.id.games_lost_image_easy)).setBackgroundResource(R.drawable.ic_red_o_android);
    ((ImageView) v.findViewById(R.id.games_tied_image_easy))
            .setBackgroundResource(R.drawable.ic_red_green_android);

    ((TextView) v.findViewById(R.id.games_won_title_med)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_lost_title_med)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_tied_title_med)).setTypeface(titleFont);

    ((TextView) v.findViewById(R.id.games_won_num_med)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_lost_num_med)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_tied_num_med)).setTypeface(titleFont);

    ((ImageView) v.findViewById(R.id.games_won_image_med)).setBackgroundResource(R.drawable.ic_green_x_android);
    ((ImageView) v.findViewById(R.id.games_lost_image_med)).setBackgroundResource(R.drawable.ic_red_o_android);
    ((ImageView) v.findViewById(R.id.games_tied_image_med))
            .setBackgroundResource(R.drawable.ic_red_green_android);

    ((TextView) v.findViewById(R.id.games_won_title_hard)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_lost_title_hard)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_tied_title_hard)).setTypeface(titleFont);

    ((TextView) v.findViewById(R.id.games_won_num_hard)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_lost_num_hard)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.games_tied_num_hard)).setTypeface(titleFont);

    ((ImageView) v.findViewById(R.id.games_won_image_hard))
            .setBackgroundResource(R.drawable.ic_green_x_android);
    ((ImageView) v.findViewById(R.id.games_lost_image_hard)).setBackgroundResource(R.drawable.ic_red_o_android);
    ((ImageView) v.findViewById(R.id.games_tied_image_hard))
            .setBackgroundResource(R.drawable.ic_red_green_android);

    v.findViewById(R.id.reset).setOnClickListener(new android.view.View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            SkytraitUtils
                    .promptDialog(getActivity(), getString(R.string.statistics_dialog_message_reset),
                            getString(R.string.statistics_dialog_title_reset))
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            StatisticsDatabase.clearStatistics(getActivity());

                            setValuesFromDatabase(v);

                            Feedback.feedback(getActivity(), R.raw.game_over_sound);

                            Snackbar.make(((StatisticActivity) getActivity()).getCoordinatorLayout(),
                                    R.string.statistics_cleared, Snackbar.LENGTH_SHORT).show();
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).show();
        }
    });

    v.findViewById(R.id.back_button).setOnClickListener(new android.view.View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Feedback.feedback(getActivity(), R.raw.game_over_sound);

            NavUtils.navigateUpFromSameTask(getActivity());
        }
    });

    ((TextView) v.findViewById(R.id.reset)).setTypeface(titleFont);
    ((TextView) v.findViewById(R.id.back_button)).setTypeface(titleFont);

    setValuesFromDatabase(v);
}

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

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

    if (cars == null) {
        cars = new ArrayList<>();
    }/*from   w  ww.  j a  v  a  2s .c  o  m*/

    Button addNewCarButton = (Button) view.findViewById(R.id.newCarButton);
    TextView title = (TextView) view.findViewById(R.id.logoTextManageMyCars);
    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("")) {
        addNewCarButton.setTypeface(hebrew);
        title.setTypeface(hebrew);
    } else {
        addNewCarButton.setTypeface(english);
        title.setTypeface(english);
    }

    progressBar = (ProgressBar) view.findViewById(R.id.mainProgressBar);
    progressBar.setVisibility(View.VISIBLE);

    carCompanyInput = (EditText) view.findViewById(R.id.carCompanyInput);
    carColorInput = (EditText) view.findViewById(R.id.carColorInput);
    carLicenseInput = (EditText) view.findViewById(R.id.carLicenseInput);
    carModelInput = (EditText) view.findViewById(R.id.carModelInput);
    addNewCarButton.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 (carCompanyInput.getText().toString().matches("")
                    || carColorInput.getText().toString().matches("")
                    || carLicenseInput.getText().toString().matches("")
                    || carModelInput.getText().toString().matches("")) {
                Toast.makeText(MyApplication.getAppActivity(),
                        "You must fill all the information about the new car", Toast.LENGTH_SHORT).show();
            } else {
                Car newCar = new Car(carLicenseInput.getText().toString(), carColorInput.getText().toString(),
                        carModelInput.getText().toString(), carCompanyInput.getText().toString(),
                        Model.getInstance().getCurrentUser().getEmail());
                Model.getInstance().addCarToDB(newCar, new Model.SyncListener() {
                    @Override
                    public void isSuccessful(boolean success) {
                        if (success) {
                            Toast.makeText(MyApplication.getAppActivity(), "New Car Added!", Toast.LENGTH_SHORT)
                                    .show();
                            fragmentCommunicator.passString("HomeScreenFragment");
                        }
                    }

                    @Override
                    public void failed(String message) {
                        Toast.makeText(MyApplication.getAppActivity(), message, Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void passData(Object data) {

                    }
                });
            }
        }
    });

    carsList = (ListView) view.findViewById(R.id.carsListView);
    Model.getInstance().getOwnedCars(Model.getInstance().getCurrentUser().getEmail(), new Model.SyncListener() {
        @Override
        public void passData(Object allCars) {
            cars = (ArrayList) allCars;
            progressBar.setVisibility(View.GONE);
            adapter.notifyDataSetChanged();
        }

        @Override
        public void isSuccessful(boolean s) {
        }

        @Override
        public void failed(String s) {
        }

    });

    adapter = new MyCarsAdapter();
    carsList.setAdapter(adapter);
    carsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Object[] data = new Object[] { cars.get(position) };
            fragmentCommunicator.passData(data, "CarScreenFragment");
        }
    });

    return view;
}

From source file:com.module.candychat.net.view.custom.SimpleAssetFontLoader.java

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

    if (typeface == null) {
        String fontFile = mFolderForPath + typefaceName + "." + mExtension;

        try {/*from  w ww .  j  a  va2s .c  o  m*/
            typeface = Typeface.createFromAsset(mAssetManager, fontFile);
            sTypefaceCache.put(typefaceName, typeface);
        } catch (RuntimeException e) {
            return Typeface.DEFAULT;
        }
    }
    return typeface;
}

From source file:foam.opensauces.StarwispActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from   ww  w .ja va  2s.  c o 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");
    //m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/DejaVuSerif.ttf");
    m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/Ginger-Regular.otf");

    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:org.gluu.super_gluu.app.fragments.SettingsFragment.SettingsList.SettingsListFragmentAdapter.java

public SettingsListFragmentAdapter(Activity activity, List<Map<String, Integer>> listContact,
        SettingsListFragment.SettingsListListener settingsListListener) {
    list = listContact;//w  w w  .  j  a  v a  2 s .c o m
    this.activity = activity;
    this.context = activity.getApplicationContext();
    mInflater = LayoutInflater.from(activity);
    mListener = settingsListListener;
    face = Typeface.createFromAsset(activity.getAssets(), "ProximaNova-Regular.otf");
    initIAPurchaseService();
}

From source file:com.bionx.res.DashMainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_new);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    initCards();/* ww  w .j a v  a  2  s .  com*/
    Appirater.appLaunched(this);

    Typeface tf = Typeface.createFromAsset(getAssets(), "SegoeWP-Semilight.ttf");

    TextView tv1 = (TextView) findViewById(R.id.textView1);
    tv1.setTypeface(tf);
    TextView tv2 = (TextView) findViewById(R.id.textView4);
    tv2.setTypeface(tf);
    TextView tv3 = (TextView) findViewById(R.id.textView5);
    tv3.setTypeface(tf);
    TextView tv4 = (TextView) findViewById(R.id.textView6);
    tv4.setTypeface(tf);
    TextView tv5 = (TextView) findViewById(R.id.textView7);
    tv5.setTypeface(tf);
    TextView tv6 = (TextView) findViewById(R.id.textView8);
    tv6.setTypeface(tf);
    TextView tv7 = (TextView) findViewById(R.id.ads);
    tv7.setTypeface(tf);

    SlidingMenu menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setMenu(R.layout.slide_menu);
}

From source file:org.exobel.routerkeygen.ui.WifiListAdapter.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public WifiListAdapter(Context context) {
    this.listNetworks = new ArrayList<>();
    try {/*from   www.j  a  v  a  2 s .  c  o m*/
        typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf");
    } catch (Exception e) {
        // Rarely some devices have a problem creating this typeface
    }

    final Resources resources = context.getResources();
    inflater = LayoutInflater.from(context);
    wifiSignal = new Drawable[4];
    wifiSignalLocked = new Drawable[4];
    final int currentApiVersion = android.os.Build.VERSION.SDK_INT;
    for (int i = 0; i < 4; ++i) {
        switch (i) {
        case 0:
            wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_1_bar_black_24dp);
            wifiSignalLocked[i] = ContextCompat.getDrawable(context,
                    R.drawable.ic_signal_wifi_1_bar_lock_black_24dp);
            break;
        case 1:
            wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_2_bar_black_24dp);
            wifiSignalLocked[i] = ContextCompat.getDrawable(context,
                    R.drawable.ic_signal_wifi_2_bar_lock_black_24dp);
            break;
        case 2:
            wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_3_bar_black_24dp);
            wifiSignalLocked[i] = ContextCompat.getDrawable(context,
                    R.drawable.ic_signal_wifi_3_bar_lock_black_24dp);
            break;
        case 3:
            wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_4_bar_black_24dp);
            wifiSignalLocked[i] = ContextCompat.getDrawable(context,
                    R.drawable.ic_signal_wifi_4_bar_lock_black_24dp);
            break;
        }
        if (currentApiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            wifiSignal[i].setTint(resources.getColor(R.color.wifi_icons));
            wifiSignalLocked[i].setTint(resources.getColor(R.color.wifi_icons));
        } else {
            wifiSignal[i].setColorFilter(resources.getColor(R.color.wifi_icons), PorterDuff.Mode.SRC_IN);
            wifiSignalLocked[i].setColorFilter(resources.getColor(R.color.wifi_icons), PorterDuff.Mode.SRC_IN);
        }

    }
}

From source file:com.manning.androidhacks.hack011.view.LedTextView.java

private void init(Context context) {
    AssetManager assets = context.getAssets();
    final Typeface font = Typeface.createFromAsset(assets, FONT_DIGITAL_7);
    setTypeface(font);
}