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:net.yoching.android.MainActivity.java

/**
 * Called when the activity is first created.
 *///from w w  w.  j a  v  a 2s  . c om
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    throwButton = (Button) findViewById(R.id.throw_button);
    throwButton.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Exo-ExtraBold.otf"));
    initCoinToss();
    addDrawerItems();

    WrexagramListAdapter adapter = new WrexagramListAdapter(MainActivity.this, wrexagramTitles,
            wrexagramSubTitles, wrexagramImageIds);

    mDrawerList = (ListView) findViewById(R.id.navList);

    mDrawerList.setAdapter(adapter);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mActivityTitle = getTitle().toString();

    setupDrawer();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    //getSupportActionBar().setLogo(R.drawable.ic_launcher);
    getSupportActionBar().setHomeButtonEnabled(true);

    TextView toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
    toolbarTitle.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Exo-ExtraBold.otf"));

    int width = getResources().getDisplayMetrics().widthPixels;
    DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerList
            .getLayoutParams();
    params.width = width;
    mDrawerList.setLayoutParams(params);

    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //Toast.makeText(MainActivity.this, position+" - clicked", Toast.LENGTH_SHORT).show();
            mDrawerLayout.closeDrawers();
            Intent intent = new Intent(MainActivity.this, ViewWrexagramActivity.class);
            //intent.putExtra("string",Yourlist.get(pos).sms);
            intent.putExtra("wrexagram", position + 1 + "");

            PendingIntent pendingIntent = TaskStackBuilder.create(MainActivity.this)
                    // add all of DetailsActivity's parents to the stack,
                    // followed by DetailsActivity itself
                    .addNextIntentWithParentStack(intent)
                    .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this);
            builder.setContentIntent(pendingIntent);

            startActivity(intent);
            finish();
        }
    });
}

From source file:com.yan.stamped.SlidingTabsBasicFragment.java

/**
 * Inflates the {@link android.view.View} which will be displayed by this {@link Fragment}, from the app's
 * resources./*  ww  w  . j av  a 2  s . c om*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    imageadapt = new ImageAdapter(getActivity());
    rewardAdapter = new RewardAdapter(getActivity());
    db = new DatabaseHandler(getActivity());
    userFunctions = new UserFunctions();
    availableRewards = new ArrayList<String>();
    availableRewards = db.getAvailableRewards();
    availableRewardsExtra = db.getRewards();
    font = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(),
            "fontawesome-webfont.ttf");
    //arrayAdapter = new ArrayAdapter<String>(getActivity());
    return inflater.inflate(R.layout.home_fragment, container, false);
}

From source file:android.support.text.emoji.MetadataRepo.java

/**
 * Construct MetadataRepo from an asset.
 *
 * @param assetManager AssetManager instance
 * @param assetPath asset manager path of the file that the Typeface and metadata will be
 *                  created from//from   ww w  . java 2s  .  com
 */
public static MetadataRepo create(@NonNull final AssetManager assetManager, final String assetPath)
        throws IOException {
    final Typeface typeface = Typeface.createFromAsset(assetManager, assetPath);
    return new MetadataRepo(typeface, MetadataListReader.read(assetManager, assetPath));
}

From source file:com.policestrategies.calm_stop.citizen.ProfileDisplayActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profiledisplay);

    mProfileImageView = (ImageView) findViewById(R.id.profilePicture);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

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

    Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/avenir-next.ttf");

    navigView = navigationView.getHeaderView(0);
    mProfileImage = (ImageView) navigView.findViewById(R.id.imageView);
    mProfileName = (TextView) navigView.findViewById(R.id.nameDisplay);
    mProfileName.setTypeface(custom_font);

    Name = (TextView) findViewById(R.id.Nametxt);
    Email = (TextView) findViewById(R.id.Emailtxt);
    Phone = (TextView) findViewById(R.id.Phonenumtxt);
    DOB = (TextView) findViewById(R.id.DOBtxt);
    DriverLis = (TextView) findViewById(R.id.DriversListxt);
    Zipcode = (TextView) findViewById(R.id.Zipcodetxt);
    Lang = (TextView) findViewById(R.id.Langtxt);
    Gender = (TextView) findViewById(R.id.Gendertxt);
    Ethn = (TextView) findViewById(R.id.Ethnicitytxt);

    Title = (TextView) findViewById(R.id.title);
    Nametxt = (TextView) findViewById(R.id.Name);
    Emailtxt = (TextView) findViewById(R.id.Email);
    Phonetxt = (TextView) findViewById(R.id.Phonenumber);
    DOBtxt = (TextView) findViewById(R.id.DOB);
    DriverListxt = (TextView) findViewById(R.id.DriversLis);
    Zipcodetxt = (TextView) findViewById(R.id.Zipcode);
    Langtxt = (TextView) findViewById(R.id.langPref);
    Gendertxt = (TextView) findViewById(R.id.Gender);
    Ethntxt = (TextView) findViewById(R.id.ethnicity);

    findViewById(R.id.viewDocs).setOnClickListener(this);
    findViewById(R.id.EditButton).setOnClickListener(this);
    findViewById(R.id.menu_main).setOnClickListener(this);

    navigView = navigationView.getHeaderView(0);
    mProfileImage = (ImageView) navigView.findViewById(R.id.imageView);
    mProfileName = (TextView) navigView.findViewById(R.id.nameDisplay);
    mProfileName.setTypeface(custom_font);

    mProgressDialog = ProgressDialog.show(this, "", "Loading", true, false);

    mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();

    if (mCurrentUser == null) {
        FirebaseAuth.getInstance().signOut();
        Intent i = new Intent(this, LoginActivity.class);
        startActivity(i);//from  ww  w  .  j  av  a2 s.c  o  m
        finish();
    } else {
        mProfileReference = FirebaseDatabase.getInstance().getReference("citizen").child(mCurrentUser.getUid())
                .child("profile");
    }

    customizeFont(custom_font);

    mProfileReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            String zip = snapshot.child("zip_code").getValue().toString();
            String email = snapshot.child("email").getValue().toString();
            String firstName = snapshot.child("first_name").getValue().toString();
            String lastName = snapshot.child("last_name").getValue().toString();
            String license = snapshot.child("license_number").getValue().toString();
            String phoneNumber = snapshot.child("phone_number").getValue().toString();
            String dateOfBirth = snapshot.child("dob").getValue().toString();
            String gender = snapshot.child("gender").getValue().toString();
            String language = snapshot.child("language").getValue().toString();
            String ethnicity = snapshot.child("ethnicity").getValue().toString();

            String name = firstName + " " + lastName;
            Zipcode.setText(zip);
            Email.setText(email);
            Name.setText(name);
            DriverLis.setText(license);
            Phone.setText(phoneNumber);
            DOB.setText(dateOfBirth);
            Ethn.setText(ethnicity);
            Gender.setText(gender);
            Lang.setText(language);
            mProfileName.setText(name);

            //loadProfileImage();

            SharedUtil.dismissProgressDialog(mProgressDialog);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            Log.e(TAG, "Failed to read app title value.", error.toException());
        }

    });

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            int id = item.getItemId();
            switch (id) {
            case R.id.profile:
                profile();
                break;
            case R.id.previous_stops:
                previousStops();
                break;
            case R.id.about_us:
                aboutUs();
                break;
            case R.id.settings:
                settings();
                break;
            case R.id.logout:
                logout();
                break;
            /*case R.id.detect_beacon_debug:
                detectBecon();
                break; */
            }

            //DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            //drawer.closeDrawer(GravityCompat.START);
            return true;
        }
    });
}

From source file:com.roughike.swipeselector.SwipeAdapter.java

private SwipeAdapter(ViewPager viewPager, ViewGroup indicatorContainer, int indicatorSize, int indicatorMargin,
        int inActiveIndicatorColor, int activeIndicatorColor, int leftButtonResource, int rightButtonResource,
        ImageView leftButton, ImageView rightButton, String customFontPath, int titleTextAppearance,
        int descriptionTextAppearance) {
    mContext = viewPager.getContext();/*from   w  w  w. j  ava 2s  .c  o  m*/

    mViewPager = viewPager;
    mViewPager.addOnPageChangeListener(this);

    mIndicatorContainer = indicatorContainer;
    mCircleParams = new LinearLayout.LayoutParams(indicatorSize, indicatorSize);
    mCircleParams.leftMargin = indicatorMargin;

    mInActiveCircleDrawable = Indicator.newOne(indicatorSize, inActiveIndicatorColor);
    mActiveCircleDrawable = Indicator.newOne(indicatorSize, activeIndicatorColor);

    if (customFontPath != null && !customFontPath.isEmpty()) {
        mCustomTypeFace = Typeface.createFromAsset(mContext.getAssets(), customFontPath);
    }

    mTitleTextAppearance = titleTextAppearance;
    mDescriptionTextAppearance = descriptionTextAppearance;

    mLeftButton = leftButton;
    mLeftButton.setImageResource(leftButtonResource);

    mRightButton = rightButton;
    mRightButton.setImageResource(rightButtonResource);

    // Calculate paddings for the content so the left and right buttons
    // don't overlap.
    mSweetSixteen = (int) PixelUtils.dpToPixel(mContext, 16);
    mContentLeftPadding = ContextCompat.getDrawable(mContext, leftButtonResource).getIntrinsicWidth()
            + mSweetSixteen;
    mContentRightPadding = ContextCompat.getDrawable(mContext, rightButtonResource).getIntrinsicWidth()
            + mSweetSixteen;

    mLeftButton.setOnClickListener(this);
    mRightButton.setOnClickListener(this);

    mLeftButton.setTag(TAG_HIDDEN);
    mLeftButton.setClickable(false);
    mLeftButton.setAlpha(0.0f);
}

From source file:com.example.sam.savemeapp.StatisticsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment.
    v = inflater.inflate(R.layout.fragment_statistics, container, false);
    fontLight = Typeface.createFromAsset(getContext().getAssets(), "panton_light.otf");
    fontBlack = Typeface.createFromAsset(getContext().getAssets(), "panton_black.otf");
    //Instead of having initializeObject in this fragment.
    //We declared them here since it didn't contain many layouts.
    mLegend = (LinearLayout) v.findViewById(R.id.legends);
    LinearLayout mLegendExtra = (LinearLayout) v.findViewById(R.id.legend_extra);
    params = mLegendExtra.getLayoutParams();
    TextView mStatistics = (TextView) v.findViewById(R.id.statistics_header);
    mStatistics.setTypeface(fontLight);// www  . j  av  a2s  . c o  m
    return v;
}

From source file:com.prey.activities.InitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    this.setContentView(R.layout.home);
    PreyLogger.i("onCreate of MenuActivity");

    onboardingPagerAdapter = new OnboardingPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(onboardingPagerAdapter);

    Button buttonHome = (Button) findViewById(R.id.buttonHome);
    buttonHome.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w  w  .j  av a2s. co  m
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SignUpActivity.class);
            startActivity(intent);
            finish();

        }
    });
    TextView textView = (TextView) findViewById(R.id.linkHome);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SignInActivity.class);
            startActivity(intent);
            finish();
        }
    });

    Typeface titilliumWebBold = Typeface.createFromAsset(getAssets(),
            "fonts/Titillium_Web/TitilliumWeb-Bold.ttf");
    buttonHome.setTypeface(titilliumWebBold);

    final LinearLayout larr = (LinearLayout) findViewById(R.id.larr);
    final LinearLayout rarr = (LinearLayout) findViewById(R.id.rarr);
    larr.setVisibility(View.GONE);
    larr.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int currentItem = mViewPager.getCurrentItem();
            larr.setVisibility(View.VISIBLE);
            rarr.setVisibility(View.VISIBLE);
            if (currentItem == 0) {
                larr.setVisibility(View.GONE);
            }

            mViewPager.setCurrentItem(currentItem - 1);
        }
    });

    rarr.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int currentItem = mViewPager.getCurrentItem();
            larr.setVisibility(View.VISIBLE);
            rarr.setVisibility(View.VISIBLE);
            if (currentItem >= 5) {
                rarr.setVisibility(View.GONE);
                onboardingCompleted();
            }

            mViewPager.setCurrentItem(currentItem + 1);
        }
    });

    mViewPager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            int currentItem = mViewPager.getCurrentItem();
            larr.setVisibility(View.VISIBLE);
            rarr.setVisibility(View.VISIBLE);
            PreyLogger.i("currentItem:" + currentItem);
            if (currentItem == 0) {
                larr.setVisibility(View.GONE);
            }
            if (currentItem >= 5) {
                rarr.setVisibility(View.GONE);
                onboardingCompleted();
            }

            return false;
        }
    });

    onboardingInit();

}

From source file:gov.wa.wsdot.android.wsdot.ui.ferries.departures.FerriesRouteSchedulesDayDeparturesFragment.java

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

    tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Regular.ttf");
    tfb = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Bold.ttf");

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_route_schedules_day_departures, null);

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new DepartureTimesAdapter(getActivity(), null);

    mRecyclerView.setAdapter(mAdapter);/*from w ww. j  a v a  2s. co  m*/

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    mEmptyView = root.findViewById(R.id.empty_list_view);

    schedulesViewModel = ViewModelProviders.of(getActivity()).get(FerrySchedulesViewModel.class);

    terminalViewModel = ViewModelProviders.of(getActivity()).get(FerryTerminalViewModel.class);

    terminalViewModel.getResourceStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                swipeRefreshLayout.setRefreshing(true);
                break;
            case SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                break;
            case ERROR:
                swipeRefreshLayout.setRefreshing(false);
                Toast.makeText(this.getContext(), "connection error, can't update spaces", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    terminalViewModel.getDepartureTimes().observe(this, sailingTimes -> {

        if (sailingTimes != null) {
            if (sailingTimes.size() != 0) {
                mEmptyView.setVisibility(View.GONE);
            } else {
                TextView t = (TextView) mEmptyView;
                t.setText(R.string.no_day_departures);
                mEmptyView.setVisibility(View.VISIBLE);
            }

            mAdapter.setData(new ArrayList<>(sailingTimes));

            // Scroll to the first sailing time that hasn't already passed.
            if (terminalViewModel.getShouldScrollToCurrent()) {
                terminalViewModel.setScrollToCurrent(false);
                try {
                    Date now = new Date();
                    for (int i = 0; i < sailingTimes.size(); i++) {
                        if (now.before(sailingTimes.get(i).getDepartingTime())) {
                            mRecyclerView.stopScroll();
                            ((LinearLayoutManager) mRecyclerView.getLayoutManager())
                                    .scrollToPositionWithOffset(i, 0);
                            i = sailingTimes.size();
                        }
                    }
                } catch (Exception e) {
                    MyLogger.crashlyticsLog("Ferries", "Error", "Auto scroll failed", 1);
                }
            }
        }
    });

    terminalViewModel.getDepartureTimesAnnotations().observe(this, sailingAnnotations -> {
        if (sailingAnnotations != null) {
            annotations = new ArrayList<>(sailingAnnotations);
            mAdapter.notifyDataSetChanged();
        } else {
            annotations.clear();
        }
    });

    terminalViewModel.forceRefreshVesselStatus();

    return root;
}

From source file:org.petero.droidfish.activities.EditBoard.java

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

    figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf");

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    egtbHints = settings.getBoolean("tbHintsEdit", false);
    autoScrollTitle = settings.getBoolean("autoScrollTitle", true);

    initUI();/*  w  w w  . j  a va 2  s. c o  m*/

    Util.setFullScreenMode(this, settings);

    Intent i = getIntent();
    Position pos = null;
    try {
        pos = TextIO.readFEN(i.getAction());
    } catch (ChessParseError e) {
        pos = e.pos;
    }
    if (pos != null)
        cb.setPosition(pos);
    checkValidAndUpdateMaterialDiff();
}

From source file:gov.wa.wsdot.android.wsdot.ui.amtrakcascades.AmtrakCascadesSchedulesDetailsFragment.java

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

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_recycler_with_textview_swipe_refresh, null);
    TextView schedule_title = root.findViewById(R.id.title);
    schedule_title.setTypeface(tfb);//  w w  w  . j a  v a  2  s. co m

    if ((fromLocation.equalsIgnoreCase(toLocation))) {
        schedule_title.setText(amtrakStations.get(fromLocation));
    } else {
        schedule_title.setText("Departing: " + amtrakStations.get(fromLocation) + " and Arriving: "
                + amtrakStations.get(toLocation));
    }

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new ScheduleAdapter(null);

    mRecyclerView.setAdapter(mAdapter);

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    mEmptyView = root.findViewById(R.id.empty_list_view);

    viewModel = ViewModelProviders.of(this, viewModelFactory)
            .get(AmtrakCascadesSchedulesDetailsViewModel.class);

    viewModel.getResourceStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                swipeRefreshLayout.setRefreshing(true);
                break;
            case SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                break;
            case ERROR:
                swipeRefreshLayout.setRefreshing(false);
                TextView t = (TextView) mEmptyView;
                t.setText(R.string.no_connection);
                mEmptyView.setVisibility(View.VISIBLE);
                Toast.makeText(getContext(), "connection error", Toast.LENGTH_SHORT).show();
            }
        }
    });

    viewModel.getSchedule(statusDate, fromLocation, toLocation).observe(this, serviceItems -> {
        if (serviceItems != null) {
            mEmptyView.setVisibility(View.GONE);
            if (!serviceItems.isEmpty()) {
                mAdapter.setData(new ArrayList<>(serviceItems));
            } else {
                TextView t = (TextView) mEmptyView;
                t.setText("schedule unavailable.");
                mEmptyView.setVisibility(View.VISIBLE);
            }
        }
    });

    viewModel.refresh();

    return root;
}