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.ferdi2005.secondgram.AndroidUtilities.java

public static Typeface getTypeface(String assetPath) {
    synchronized (typefaceCache) {
        if (!typefaceCache.containsKey(assetPath)) {
            try {
                Typeface t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(),
                        assetPath);/*w w w  .jav  a2s  .co  m*/
                typefaceCache.put(assetPath, t);
            } catch (Exception e) {
                FileLog.e("Could not get typeface '" + assetPath + "' because " + e.getMessage());
                return null;
            }
        }
        return typefaceCache.get(assetPath);
    }
}

From source file:edu.mit.viral.shen.DroidFish.java

/** Called when the activity is first created. */
@Override//w w w .  j  a  va  2 s.co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    game_number = getIntent().getExtras().getInt("game_id", 0);

    // sendGame();
    Pair<String, String> pair = getPgnOrFenIntent();
    String intentPgnOrFen = pair.first;
    String intentFilename = pair.second;

    createDirectories();

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    settings = PreferenceManager.getDefaultSharedPreferences(this);
    settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            handlePrefsChange();
        }
    });

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    setWakeLock(false);
    wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "droidfish");
    wakeLock.setReferenceCounted(false);

    custom1ButtonActions = new ButtonActions("custom1", CUSTOM1_BUTTON_DIALOG, R.string.select_action);
    custom2ButtonActions = new ButtonActions("custom2", CUSTOM2_BUTTON_DIALOG, R.string.select_action);
    custom3ButtonActions = new ButtonActions("custom3", CUSTOM3_BUTTON_DIALOG, R.string.select_action);

    figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf");
    setPieceNames(PGNOptions.PT_LOCAL);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    initUI();

    gameTextListener = new PgnScreenText(pgnOptions);
    if (ctrl != null)
        ctrl.shutdownEngine();
    ctrl = new DroidChessController(this, gameTextListener, pgnOptions);
    egtbForceReload = true;
    readPrefs();
    TimeControlData tcData = new TimeControlData();
    mDatabase = new SudokuDatabase(getApplicationContext());
    game_id = Long.valueOf(game_number);
    ctrl = mDatabase.getSudoku(ctrl, game_id);
    startPosition = ctrl.getData();

    tcData.setTimeControl(timeControl, movesPerSession, timeIncrement);
    int version = 1;
    version = settings.getInt("gameStateVersion", version);
    // System.out.println("this is the version" + version);
    ctrl.newGame(gameMode, tcData);

    if (game_number >= 37 && (startPosition.equals("8/8/8/8/8/8/8/8 w - - 0 1")
            | startPosition.equals("8/8/8/8/8/8/8/8 w KQkq - 0 1"))) {
        // System.out.println("greater than 37");
        startEditBoard("8/8/8/8/8/8/8/8 w KQkq - 0 1");
    }

    if (ctrl.getState() == DroidChessController.GAME_STATE_NOT_STARTED) {

        ctrl.start();
        System.out.println("GAME_STATE_NOT_STARTED");
    } else if (ctrl.getState() == DroidChessController.GAME_STATE_PLAYING) {

        System.out.println("GAME_STATE_PLAYING");
        String dataStr = ctrl.getNote();
        // System.out.println(ctrl.getNote());

        byte[] data = strToByteArr(dataStr);
        // ctrl.newGame(gameMode, tcData, "8/8/8/8/8/8/8/8 w KQkq - 0 1");

        ctrl.fromByteArray(data, 3);
    }

    ctrl.setGuiPaused(true);
    ctrl.setGuiPaused(false);
    ctrl.startGame();

    if (intentPgnOrFen != null) {
        try {
            ctrl.setFENOrPGN(intentPgnOrFen);
            setBoardFlip(true);
        } catch (ChessParseError e) {
            // If FEN corresponds to illegal chess position, go into edit board mode.
            try {
                TextIO.readFEN(intentPgnOrFen);
            } catch (ChessParseError e2) {
                if (e2.pos != null)
                    startEditBoard(intentPgnOrFen);
            }
        }
    } else if (intentFilename != null) {
        if (intentFilename.toLowerCase(Locale.US).endsWith(".fen")
                || intentFilename.toLowerCase(Locale.US).endsWith(".epd"))
            loadFENFromFile(intentFilename);
        else
            loadPGNFromFile(intentFilename);
    }
    // commented out 04/12/15
    // sendDataone(startPosition, 1);
    utils = new Utils(getApplicationContext());
    client = new WebSocketClient(URI.create(Const.URL_WEBSOCKET + URLEncoder.encode(name)),
            new WebSocketClient.Listener() {
                @Override
                public void onConnect() {

                }

                /**
                 * On receiving the message from web socket server
                 * */
                @Override
                public void onMessage(String message) {
                    Log.d(TAG, String.format("Got string message! %s", message));
                    parseMessage(message);
                }

                @Override
                public void onMessage(byte[] data) {
                    Log.d(TAG, String.format("Got binary message! %s", bytesToHex(data)));
                    parseMessage(bytesToHex(data));
                    // Message will be in JSON format
                }

                /**
                 * Called when the connection is terminated
                 * */
                @Override
                public void onDisconnect(int code, String reason) {

                    String message = String.format(Locale.US, "Disconnected! Code: %d Reason: %s", code,
                            reason);
                    //                showToast(message);

                    // clear the session id from shared preferences
                    utils.storeSessionId(null);
                }

                @Override
                public void onError(Exception error) {
                    Log.e(TAG, "Error! : " + error);

                }
            }, null);
    client.connect();
}

From source file:org.mdc.chess.MDChess.java

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

    Pair<String, String> pair = getPgnOrFenIntent();
    String intentPgnOrFen = pair.first;
    String intentFilename = pair.second;

    createDirectories();

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    setWakeLock(false);

    figNotation = Typeface.createFromAsset(getAssets(), "fonts/KlinicSlabBold.otf");
    setPieceNames(PGNOptions.PT_LOCAL);
    initUI();

    gameTextListener = new PgnScreenText(pgnOptions);
    moveList.setOnLinkClickListener(gameTextListener);
    moveList.setBackgroundColor(Color.WHITE);
    if (ctrl != null) {
        ctrl.shutdownEngine();
    }
    ctrl = new MDChessController(this, gameTextListener, pgnOptions);
    egtbForceReload = true;
    readPrefs();
    TimeControlData tcData = new TimeControlData();
    tcData.setTimeControl(timeControl, movesPerSession, timeIncrement);
    ctrl.newGame(gameMode, tcData);
    setAutoMode(AutoMode.OFF);
    {
        byte[] data = null;
        int version = 1;
        if (savedInstanceState != null) {
            data = savedInstanceState.getByteArray("gameState");
            version = savedInstanceState.getInt("gameStateVersion", version);
        } else {
            String dataStr = settings.getString("gameState", null);
            version = settings.getInt("gameStateVersion", version);
            if (dataStr != null) {
                data = strToByteArr(dataStr);
            }
        }
        if (data != null) {
            ctrl.fromByteArray(data, version);
        }
    }
    ctrl.setGuiPaused(true);
    ctrl.setGuiPaused(false);
    ctrl.startGame();
    if (intentPgnOrFen != null) {
        try {
            ctrl.setFENOrPGN(intentPgnOrFen);
            setBoardFlip(true);
        } catch (ChessParseError e) {
            // If FEN corresponds to illegal chess position, go into edit board mode.
            try {
                TextIO.readFEN(intentPgnOrFen);
            } catch (ChessParseError e2) {
                if (e2.pos != null) {
                    startEditBoard(intentPgnOrFen);
                }
            }
        }
    } else if (intentFilename != null) {
        if (intentFilename.toLowerCase(Locale.US).endsWith(".fen")
                || intentFilename.toLowerCase(Locale.US).endsWith(".epd")) {
            loadFENFromFile(intentFilename);
        } else {
            loadPGNFromFile(intentFilename);
        }
    }

}

From source file:de.enlightened.peris.ForumSettingsFragment.java

private void setupSignatureButton(final SharedPreferences appPreferences) {
    //Signature button
    final LinearLayout forumSettingTagline = (LinearLayout) getActivity()
            .findViewById(R.id.forum_setting_tagline);
    if (this.application.getSession().getServer().serverUserName.contentEquals("0")) {
        forumSettingTagline.setVisibility(View.GONE);
    } else {// w  w w.j a va2 s .c  o m
        final LinearLayout forumSettingTaglineBodyBuilder = (LinearLayout) getActivity()
                .findViewById(R.id.forum_setting_tagline_body_builder);
        final boolean useShading = appPreferences.getBoolean("use_shading", false);
        final boolean useOpenSans = appPreferences.getBoolean("use_opensans", false);
        final int fontSize = appPreferences.getInt("font_size", 16);
        final Typeface opensans = Typeface.createFromAsset(getActivity().getAssets(), "fonts/opensans.ttf");
        BBCodeParser.parseCode(getActivity(), forumSettingTaglineBodyBuilder,
                this.application.getSession().getServer().serverTagline, opensans, useOpenSans, useShading,
                null, fontSize, false, "#333333", this.application);

        forumSettingTagline.setOnClickListener(new View.OnClickListener() {
            @Override
            @SuppressWarnings("checkstyle:requirethis")
            public void onClick(final View v) {
                final Intent myIntent = new Intent(getActivity(), NewPost.class);
                final Bundle bundle = new Bundle();
                bundle.putString("postid", "0");
                bundle.putString("parent", "0");
                bundle.putString("category", "0");
                bundle.putString("subforum_id", (String) "0");
                bundle.putString("original_text", (String) "");
                bundle.putString("boxTitle", (String) "Signature Editor");
                bundle.putString("picture", (String) "0");
                bundle.putString("color", (String) application.getSession().getServer().serverColor);
                bundle.putString("subject", (String) "");
                bundle.putString("post_type", NewPost.Type.Tagline.name());
                myIntent.putExtras(bundle);

                startActivity(myIntent);
            }
        });
    }
}

From source file:com.zainsoft.ramzantimetable.QiblaActivity.java

/** Called when the activity is first created. */
@Override/*ww  w  .ja  va2 s . c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_qibla_direction);
    // registering for listeners
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    registerListeners();
    // Checking if the GPS is on or off. If it was on the default location
    // will be set and if its on, appropriate
    Context context = getApplicationContext();
    perfs = PreferenceManager.getDefaultSharedPreferences(context);
    perfs.registerOnSharedPreferenceChangeListener(this);
    String gpsPerfKey = getString(R.string.gps_pref_key);
    TextView text1 = (TextView) findViewById(R.id.location_text_line2);
    TextView text2 = (TextView) findViewById(R.id.noLocationText);
    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/kufi.ttf");
    tf = Typeface.create(tf, Typeface.BOLD);

    if ("fa".equals(Locale.getDefault().getLanguage())) {
        text1.setTypeface(tf);
        text2.setTypeface(tf);
    } else {
        text1.setTypeface(Typeface.SERIF);
        text2.setTypeface(Typeface.SERIF);
    }

    boolean isGPS = false;

    /*  if(hasPermission( LOC_PERMS[0] )) {
    checkForGPSnShowQibla();
      } else {
    requestLocationPermission();
      }
    */
    this.qiblaImageView = (ImageView) findViewById(R.id.arrowImage);
    this.compassImageView = (ImageView) findViewById(R.id.compassImage);
}

From source file:com.corporatetaxi.TaxiArrived_Acitivity.java

private void initiatePopupWindowsendmesage() {
    try {//from w ww  .  ja va 2 s .  c o m
        dialog = new Dialog(TaxiArrived_Acitivity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // before
        dialog.setContentView(R.layout.sendmesssage_popup);

        Button mbtn_sendmesssage = (Button) dialog.findViewById(R.id.btn_acceptor);
        Button mbtn_cancel = (Button) dialog.findViewById(R.id.btn_cancel);
        rd1 = (RadioButton) dialog.findViewById(R.id.radioButton1);
        rd2 = (RadioButton) dialog.findViewById(R.id.radioButton2);
        rd3 = (RadioButton) dialog.findViewById(R.id.radioButton3);
        mcross = (ImageButton) dialog.findViewById(R.id.cross);
        txt_header = (TextView) dialog.findViewById(R.id.popup_text);
        mcross.setOnClickListener(cancle_btn_click_listener);
        mbtn_cancel.setOnClickListener(cancle_btn_click_listener);
        Typeface tf = Typeface.createFromAsset(this.getAssets(), "Montserrat-Regular.ttf");
        rd1.setTypeface(tf);
        rd2.setTypeface(tf);
        rd3.setTypeface(tf);
        mbtn_sendmesssage.setTypeface(tf);
        txt_header.setTypeface(tf);
        mbtn_cancel.setTypeface(tf);
        mbtn_sendmesssage.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                if (rd1.isChecked()) {
                    sendmessage = getResources().getString(R.string.prompt_message_one);

                } else if (rd2.isChecked()) {
                    sendmessage = getResources().getString(R.string.prompt_message_two);

                } else if (rd3.isChecked()) {
                    sendmessage = getResources().getString(R.string.prompt_message_three);

                }

                Allbeans allbeans = new Allbeans();

                allbeans.setSendmessage(sendmessage);

                new SendmessageAsynch(allbeans).execute();

            }
        });
        dialog.show();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.jraf.android.piclabel.app.form.FormActivity.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);// www. j av a2 s. c o m
    paint.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/" + getSelectedFontName()));

    int textSize = canvas.getHeight() / 35;
    paint.setTextSize(textSize);
    int margin = textSize / 5;

    // Measure date/time
    String dateTime = mEdtDateTime.getText().toString();
    Rect boundsDateTime = new Rect();
    paint.getTextBounds(dateTime, 0, dateTime.length(), boundsDateTime);

    // Measure location
    String location = mEdtLocation.getText().toString();
    Rect boundsLocation = new Rect();
    paint.getTextBounds(location, 0, location.length(), boundsLocation);

    int totalWidth = boundsDateTime.width() + textSize * 2 + boundsLocation.width();
    if (totalWidth > canvas.getWidth()) {
        // Draw on 2 lines

        // Draw a rectangle
        paint.setColor(Color.argb(180, 0, 0, 0));
        canvas.drawRect(0, 0, canvas.getWidth(), -boundsDateTime.top + boundsDateTime.bottom
                + -boundsLocation.top + boundsLocation.bottom + margin * 3, paint);

        // Draw date/time
        paint.setColor(Color.WHITE);
        canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint);

        // Draw location
        canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin,
                margin + -boundsDateTime.top + boundsDateTime.bottom + margin + -boundsLocation.top, paint);

    } else {
        // Draw on 1 line

        // Draw a rectangle
        paint.setColor(Color.argb(180, 0, 0, 0));
        canvas.drawRect(0, 0, canvas.getWidth(),
                margin + Math.max(boundsDateTime.height(), boundsLocation.height()) + margin, paint);

        // Draw date/time
        paint.setColor(Color.WHITE);
        canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint);

        // Draw location
        canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin,
                margin + -boundsLocation.top, paint);
    }
}

From source file:com.corporatetaxi.TaxiOntheWay_Activity.java

private void initiatePopupWindowcanceltaxi() {
    try {//  w  w  w .  j  a va  2s. c  om
        dialog = new Dialog(TaxiOntheWay_Activity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // before
        dialog.setContentView(R.layout.canceltaxi_popup);

        cross = (ImageButton) dialog.findViewById(R.id.cross);
        cross.setOnClickListener(cancle_btn_click_listener);
        rd1 = (RadioButton) dialog.findViewById(R.id.radioButton);
        rd2 = (RadioButton) dialog.findViewById(R.id.radioButton2);
        rd3 = (RadioButton) dialog.findViewById(R.id.radioButton3);
        btn_confirm = (Button) dialog.findViewById(R.id.btn_acceptor);
        TextView txt = (TextView) dialog.findViewById(R.id.textView);
        textheader = (TextView) dialog.findViewById(R.id.popup_text);
        Typeface tf = Typeface.createFromAsset(this.getAssets(), "Montserrat-Regular.ttf");
        rd1.setTypeface(tf);
        rd2.setTypeface(tf);
        rd3.setTypeface(tf);
        btn_confirm.setTypeface(tf);
        txt.setTypeface(tf);
        textheader.setTypeface(tf);
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (rd1.isChecked()) {
                    canceltaxirequest = getResources().getString(R.string.prompt_cancel_reason_one);

                } else if (rd2.isChecked()) {
                    canceltaxirequest = getResources().getString(R.string.prompt_cancel_reason_two);

                } else if (rd3.isChecked()) {
                    canceltaxirequest = getResources().getString(R.string.prompt_cancel_reason_three);

                }

                Allbeans allbeans = new Allbeans();

                allbeans.setCanceltaxirequest(canceltaxirequest);

                new CancelTaxiAsynch(allbeans).execute();

            }
        });

        dialog.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.usertaxi.TaxiArrived_Acitivity.java

private void initiatePopupWindowcanceltaxi() {
    try {//from   ww  w  .j  a  v a  2  s.  c  om
        dialog = new Dialog(TaxiArrived_Acitivity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // before
        dialog.setContentView(R.layout.canceltaxi_popup);

        cross = (ImageButton) dialog.findViewById(R.id.cross);
        cross.setOnClickListener(cancle_btn_click_listener);
        rd1 = (RadioButton) dialog.findViewById(R.id.radioButton);
        rd2 = (RadioButton) dialog.findViewById(R.id.radioButton2);
        rd3 = (RadioButton) dialog.findViewById(R.id.radioButton3);
        btn_confirm = (Button) dialog.findViewById(R.id.btn_acceptor);
        TextView txt = (TextView) dialog.findViewById(R.id.textView);
        textheader = (TextView) dialog.findViewById(R.id.popup_text);

        Typeface tf = Typeface.createFromAsset(this.getAssets(), "Montserrat-Regular.ttf");
        rd1.setTypeface(tf);
        rd2.setTypeface(tf);
        rd3.setTypeface(tf);
        btn_confirm.setTypeface(tf);
        txt.setTypeface(tf);
        textheader.setTypeface(tf);
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (rd1.isChecked()) {
                    canceltaxirequest = getResources().getString(R.string.prompt_canceltaxione);

                } else if (rd2.isChecked()) {
                    canceltaxirequest = getResources().getString(R.string.prompt_cancel_reason_two);

                } else if (rd3.isChecked()) {
                    canceltaxirequest = getResources().getString(R.string.prompt_cancel_reason_three);

                }

                Allbeans allbeans = new Allbeans();

                allbeans.setCanceltaxirequest(canceltaxirequest);

                new CancelTaxiAsynch(allbeans).execute();

            }
        });
        dialog.show();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.SR167TollRatesFragment.java

/**
 * Returns a view for the toll trip provided by the tripItem.
 * A tripItem holds information about the trip destination and toll rate
 *
 * @param tripItem//  w  w w .  j  a  va  2s. co  m
 * @param context
 * @return
 */
public static View makeTripView(TollTripEntity tripItem, TollRateSignEntity sign, Context context) {

    Typeface tfb = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf");
    LayoutInflater li = LayoutInflater.from(context);
    View cv = li.inflate(R.layout.trip_view, null);

    cv.findViewById(R.id.title).setVisibility(View.GONE);

    ((TextView) cv.findViewById(R.id.subtitle)).setText("Show on map");
    ((TextView) cv.findViewById(R.id.subtitle))
            .setTextColor(context.getResources().getColor(R.color.primary_default));
    cv.findViewById(R.id.subtitle).setOnClickListener(v -> {
        Bundle b = new Bundle();

        b.putDouble("startLat", sign.getStartLatitude());
        b.putDouble("startLong", sign.getStartLongitude());

        b.putDouble("endLat", tripItem.getEndLatitude());
        b.putDouble("endLong", tripItem.getEndLongitude());

        b.putString("title", sign.getLocationName());
        b.putString("text", String.format("Travel as far as %s.", tripItem.getEndLocationName()));

        Intent intent = new Intent(context, TollRatesRouteActivity.class);
        intent.putExtras(b);
        context.startActivity(intent);
    });

    ((TextView) cv.findViewById(R.id.content)).setText("Carpools and motorcycles free");

    // set updated label
    ((TextView) cv.findViewById(R.id.updated))
            .setText(ParserUtils.relativeTime(tripItem.getUpdated(), "MMMM d, yyyy h:mm a", false));

    // set toll
    TextView currentTimeTextView = cv.findViewById(R.id.current_value);
    currentTimeTextView.setTypeface(tfb);
    currentTimeTextView.setText(String.format(Locale.US, "$%.2f", tripItem.getTollRate() / 100));

    // set message if there is one
    if (!tripItem.getMessage().equals("null")) {
        currentTimeTextView.setText(tripItem.getMessage());
    }

    return cv;
}