List of usage examples for android.graphics Typeface createFromAsset
public static Typeface createFromAsset(AssetManager mgr, String path)
From source file:com.prey.activities.CheckPasswordActivity.java
@Override protected void onResume() { super.onResume(); bindPasswordControls();//from w w w. ja v a 2s.c om TextView device_ready_h2_text = (TextView) findViewById(R.id.device_ready_h2_text); final TextView textForgotPassword = (TextView) findViewById(R.id.link_forgot_password); Button password_btn_login = (Button) findViewById(R.id.password_btn_login); EditText password_pass_txt = (EditText) findViewById(R.id.password_pass_txt); TextView textView1 = (TextView) findViewById(R.id.textView1); TextView textView2 = (TextView) findViewById(R.id.textView2); Typeface titilliumWebRegular = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Regular.ttf"); Typeface titilliumWebBold = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Bold.ttf"); Typeface magdacleanmonoRegular = Typeface.createFromAsset(getAssets(), "fonts/MagdaClean/magdacleanmono-regular.ttf"); textView1.setTypeface(magdacleanmonoRegular); textView2.setTypeface(magdacleanmonoRegular); device_ready_h2_text.setTypeface(titilliumWebRegular); textForgotPassword.setTypeface(titilliumWebBold); password_btn_login.setTypeface(titilliumWebBold); password_pass_txt.setTypeface(magdacleanmonoRegular); try { textForgotPassword.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); } catch (Exception e) { } } }); } catch (Exception e) { } TextView textView5_1 = (TextView) findViewById(R.id.textView5_1); TextView textView5_2 = (TextView) findViewById(R.id.textView5_2); textView5_1.setTypeface(magdacleanmonoRegular); textView5_2.setTypeface(titilliumWebBold); TextView textViewUninstall = (TextView) findViewById(R.id.textViewUninstall); LinearLayout linearLayoutTour = (LinearLayout) findViewById(R.id.linearLayoutTour); textViewUninstall.setTypeface(titilliumWebBold); if (PreyConfig.getPreyConfig(getApplication()).getProtectTour()) { linearLayoutTour.setVisibility(View.GONE); textViewUninstall.setVisibility(View.VISIBLE); textViewUninstall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url = PreyConfig.getPreyConfig(getApplication()).getPreyUninstallUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); finish(); } }); } else { linearLayoutTour.setVisibility(View.VISIBLE); textViewUninstall.setVisibility(View.GONE); try { linearLayoutTour.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplication(), TourActivity1.class); Bundle b = new Bundle(); b.putInt("id", 1); intent.putExtras(b); startActivity(intent); finish(); } }); } catch (Exception e) { } } boolean showLocation = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { boolean canAccessFineLocation = PreyPermission.canAccessFineLocation(this); boolean canAccessCoarseLocation = PreyPermission.canAccessCoarseLocation(this); boolean canAccessCamera = PreyPermission.canAccessCamera(this); boolean canAccessReadPhoneState = PreyPermission.canAccessReadPhoneState(this); boolean canAccessReadExternalStorage = PreyPermission.canAccessReadExternalStorage(this); if (!canAccessFineLocation || !canAccessCoarseLocation || !canAccessCamera || !canAccessReadPhoneState || !canAccessReadExternalStorage) { AlertDialog.Builder builder = new AlertDialog.Builder(this); final FrameLayout frameView = new FrameLayout(this); builder.setView(frameView); final AlertDialog alertDialog = builder.create(); LayoutInflater inflater = alertDialog.getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.warning, frameView); TextView warning_title = (TextView) dialoglayout.findViewById(R.id.warning_title); TextView warning_body = (TextView) dialoglayout.findViewById(R.id.warning_body); warning_title.setTypeface(magdacleanmonoRegular); warning_body.setTypeface(titilliumWebBold); Button button_ok = (Button) dialoglayout.findViewById(R.id.button_ok); Button button_close = (Button) dialoglayout.findViewById(R.id.button_close); button_ok.setTypeface(titilliumWebBold); button_close.setTypeface(titilliumWebBold); final Activity thisActivity = this; button_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("askForPermission"); askForPermission(); alertDialog.dismiss(); } }); button_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("close ask"); alertDialog.dismiss(); } }); alertDialog.show(); showLocation = false; } else { showLocation = true; } } else { showLocation = true; } if (showLocation) { LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (isGpsEnabled || isNetworkEnabled) { PreyLogger.d("isGpsEnabled || isNetworkEnabled"); } else { PreyLogger.d("no gps ni red"); AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog alertDialog = builder.create(); TextView textview = new TextView(this); textview.setText(getString(R.string.location_settings)); textview.setMaxLines(10); textview.setTextSize(18F); textview.setPadding(20, 0, 20, 20); textview.setTextColor(Color.BLACK); builder.setView(textview); builder.setPositiveButton(getString(R.string.go_to_settings), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); return; } }); builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }); builder.create().show(); } } }
From source file:com.techno.jay.codingcontests.Home.java
private void applyFontToMenuItem(MenuItem mi) { Typeface font = Typeface.createFromAsset(getAssets(), "ProductSans-Regular.ttf"); SpannableString mNewTitle = new SpannableString(mi.getTitle()); mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); mi.setTitle(mNewTitle);/*from ww w .j a va 2s . co m*/ }
From source file:io.github.tonyguyot.acronym.ui.QueryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ArrayList<Acronym> savedValues = null; if (savedInstanceState != null) { // the application has been reloaded savedValues = savedInstanceState.getParcelableArrayList(KEY_ACRONYMS); }//from ww w.ja v a 2 s . c o m // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_query, container, false); // retrieve the different UI items we need to interact with mTvQuery = (TextView) view.findViewById(R.id.query_entry); mTvResultStatus = (TextView) view.findViewById(R.id.query_result); mProgress = (ProgressBar) view.findViewById(R.id.query_progress); // init graphical elements TextView intro = (TextView) view.findViewById(R.id.query_info); Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Lobster-Regular.ttf"); intro.setTypeface(tf); // initialize the recycler view for the list of results RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.query_list); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST); recyclerView.addItemDecoration(itemDecoration); if (savedValues == null) { mAdapter = new QueryAdapter(); } else { mAdapter = new QueryAdapter(savedValues); } recyclerView.setAdapter(mAdapter); // define the callback for the button Button submitButton = (Button) view.findViewById(R.id.query_submit); submitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSubmitButtonClick(); } }); Log.d(TAG, "view has been created"); return view; }
From source file:com.gaadikey.gaadikey.gaadikey.Fragment_Home.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_home, container, false); ImageView thumbnail = (ImageView) view.findViewById(R.id.thumbnail); TextView gaadiname_field = (TextView) view.findViewById(R.id.GaadiName); TextView gaadimsg_field = (TextView) view.findViewById(R.id.GaadiMsg); TextView numberplate_textview = (TextView) view.findViewById(R.id.numberplate); numberplate_textview.setOnClickListener(new View.OnClickListener() { @Override//from w ww .j ava2 s .c om public void onClick(View view) { ((LaunchActivity_NavDrawer) getActivity()).displayView(6); // This opens up numberplate view! } }); thumbnail.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Open up the settings view when clicked from here! ((LaunchActivity_NavDrawer) getActivity()).displayView(8); // The 7th option is settings! } }); // Download the Image dynamically, Pinging the Image URL // Get the image path URL by rading the persistant storage SharedPreferences sharedPref = getActivity().getSharedPreferences("android_shared", Context.MODE_PRIVATE); IMAGE_PATH = sharedPref.getString(getString(R.string.KEY_GaadiImage), "default"); // IMAGE_PATH = "http://gaadikey.com/images/GaadiKey_bikes/bajaj/bajaj-discover-100m.jpg"; // hARD CODING THE IMAGE url TO CHECK IF 37KB IMAGE LOADING IS THE ISSUE GAADI_MSG = sharedPref.getString(getString(R.string.KEY_GaadiMsg), "Set status"); GAADI_NAME = sharedPref.getString(getString(R.string.KEY_GaadiName), "Your Vehicle Name here"); gaadimsg_field.setText(GAADI_MSG); gaadiname_field.setText(GAADI_NAME); Log.e("Retrieved IMAGE_PATH ", IMAGE_PATH); Log.e("Retrieved GAADI_MSG ", GAADI_MSG); Log.e("Retrieved GAADI NAME ", GAADI_NAME); if (!IMAGE_PATH.equals("default")) { Picasso.with(getActivity().getBaseContext()).load(IMAGE_PATH).into(thumbnail); } TextView numberplateText = (TextView) view.findViewById(R.id.numberplate); SharedPreferences sharedPref1 = getActivity().getSharedPreferences("android_shared", Context.MODE_PRIVATE); String numberplatestring = sharedPref1.getString(getString(R.string.KEY_GaadiKey_Number_Saved), "KA50Q7896"); Log.e("The retreived number plate string is ", numberplatestring); numberplateText.setText(numberplatestring); // setting the string obtained from the KEY set by number picker change listener Typeface typface = Typeface.createFromAsset(getActivity().getAssets(), "LicensePlate.ttf"); numberplateText.setTypeface(typface); lanes.add("Public Lane"); lanes.add("Friends Lane"); lanes.add("Safety Lane"); lanes.add("Shopping Lane"); lanes.add("News"); listview = (ListView) view.findViewById(R.id.list); listview.setAdapter(new StickyHomeAdapter(getActivity(), lanes)); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { SharedPreferences sharedPref4 = getActivity().getSharedPreferences("android_shared", Context.MODE_PRIVATE); SharedPreferences.Editor editor_4 = sharedPref4.edit(); editor_4.putString(getString(R.string.KEY_HomeMenu), "" + position); // Incrementing the position by 1 editor_4.commit(); Log.e(" The Item clicked in the list is ", "" + position); ((LaunchActivity_NavDrawer) getActivity()).displayView(position + 1); } }); // Removing the edittext for now // final EditText edittext = (EditText) view.findViewById(R.id.editText_search); // // edittext.setOnEditorActionListener( // new EditText.OnEditorActionListener() { // @Override // public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // // // // if (event != null) { // // if shift key is down, then we want to insert the '\n' char in the TextView; // // otherwise, the default action is to send the message. // // if (!event.isShiftPressed()) // { // Log.e(" Enter is pressed! ", "Yes"); // //return true; // // Start the activity here // // } // return false; // } // // Log.e("here we are ", "Yes"); // // Intent i = new Intent(getActivity(), LaunchActivity_NavDrawer.class); // i.putExtra("searchString",edittext.getText().toString()); // i.putExtra("view", "normal"); // // SharedPreferences sharedPref4 = getActivity().getSharedPreferences("android_shared", Context.MODE_PRIVATE); // SharedPreferences.Editor editor_4 = sharedPref4.edit(); // editor_4.putString(getString(R.string.KEY_HomeMenu), "0" ); // Incrementing the position by 1 // editor_4.commit(); // startActivity(i); // // return true; // } // }); return view; }
From source file:de.measite.contactmerger.MergeActivity.java
public void updateList() { progressContainer = findViewById(R.id.progress_bar_container); progressBar = (ProgressBar) findViewById(R.id.analyze_progress); progressContainer.setVisibility(View.GONE); loadText = (TextView) findViewById(R.id.load_text); TextView stopScan = (TextView) findViewById(R.id.stop_scan); Typeface font = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf"); stopScan.setTypeface(font);/*from www. j av a 2 s . co m*/ stopScan.setClickable(true); stopScan.setOnClickListener(this); startScan = (Button) findViewById(R.id.start_scan); startScan.setOnClickListener(this); ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.switcher); ViewSwitcher switcher_list = (ViewSwitcher) findViewById(R.id.switcher_list); Context context = getApplicationContext(); File path = context.getDatabasePath("contactsgraph"); File modelFile = new File(path, "model.kryo.gz"); if (path.exists() && modelFile.exists()) { this.adapter.update(); while (switcher.getCurrentView().getId() != R.id.switcher_list) { switcher.showNext(); } if (adapter.getCount() == 0) { while (switcher_list.getCurrentView().getId() != R.id.all_done) { switcher_list.showNext(); } } else { while (switcher_list.getCurrentView().getId() != R.id.contact_merge_list) { switcher_list.showPrevious(); } } switcher_list.postInvalidate(); } else { if (switcher.getCurrentView().getId() == R.id.contact_merge_list) { switcher.showPrevious(); } Intent intent = new Intent(getApplicationContext(), AnalyzerService.class); intent.putExtra("forceRunning", true); startService(intent); } switcher.postInvalidate(); }
From source file:com.scigames.slidegame.MenuActivity.java
/** Called with the activity is first created. */ @Override// ww w.j a v a2 s .c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); Log.d(TAG, "super.OnCreate"); Intent i = getIntent(); Log.d(TAG, "getIntent"); //if(!debug){ firstNameIn = i.getStringExtra("fName"); lastNameIn = i.getStringExtra("lName"); ; studentIdIn = i.getStringExtra("studentId"); visitIdIn = i.getStringExtra("visitId"); rfidIn = i.getStringExtra("rfid"); photoUrl = i.getStringExtra("photo"); photoUrl = baseDbURL + "/" + photoUrl; slideLevelIn = i.getStringExtra("slideLevel"); massIn = i.getStringExtra("mass"); Log.d(TAG, "slideLevelIn: " + slideLevelIn); Log.d(TAG, "...getStringExtra"); //} // Inflate our UI from its XML layout description. setContentView(R.layout.menu_page); Log.d(TAG, "...setContentView"); ExistenceLightOtf = Typeface.createFromAsset(getAssets(), "fonts/Existence-Light.ttf"); //Typeface Museo300Regular = Typeface.createFromAsset(getAssets(),"fonts/Museo300-Regular.otf"); Museo500Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo500-Regular.otf"); Museo700Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo700-Regular.otf"); displayProfile(); }
From source file:io.vit.vitio.StartScreens.DetailFragment.java
private void setFonts() { typeface = Typeface.createFromAsset(getResources().getAssets(), "fonts/Montserrat-Regular.ttf"); desHead.setTypeface(typeface);/* ww w . j a v a 2 s . co m*/ desText.setTypeface(typeface); }
From source file:com.tdispatch.passenger.core.TDApplication.java
public Typeface getTypeface(String assetPath) { synchronized (mTypefaceCache) { Typeface typeface = null;/*from w ww . ja v a2 s . c o m*/ if (mTypefaceCache.containsKey(assetPath) == false) { try { typeface = Typeface.createFromAsset(mAppContext.getAssets(), assetPath); mTypefaceCache.put(assetPath, typeface); return typeface; } catch (Exception e) { WebnetLog.e("Could not get '" + assetPath + "': " + e.getMessage()); return null; } } else { typeface = mTypefaceCache.get(assetPath); } return typeface; } }
From source file:dev.vision.shopping.center.Splash.java
private void overrideFonts(final Context context, final View v) { try {// w w w . ja v a2 s . c om if (v instanceof ViewGroup) { ViewGroup vg = (ViewGroup) v; for (int i = 0; i < vg.getChildCount(); i++) { View child = vg.getChildAt(i); overrideFonts(context, child); } } else if (v instanceof TextView) { ((TextView) v) .setTypeface(Typeface.createFromAsset(context.getAssets(), "AvantGardeITCbyBTBook.otf")); } } catch (Exception e) { } }
From source file:com.kabootar.GlassMemeGenerator.ImageOverlay.java
/** * Draws the given string centered, as big as possible, on either the top or * bottom 20% of the image given.//w w w . j a v a 2 s. co m */ private static void drawStringCentered(Canvas g, String text, Bitmap image, boolean top, Context baseContext) throws InterruptedException { if (text == null) text = ""; int height = 0; int fontSize = MAX_FONT_SIZE; int maxCaptionHeight = image.getHeight() / 5; int maxLineWidth = image.getWidth() - SIDE_MARGIN * 2; String formattedString = ""; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Paint stkPaint = new Paint(Paint.ANTI_ALIAS_FLAG); stkPaint.setStyle(STROKE); stkPaint.setStrokeWidth(8); stkPaint.setColor(Color.BLACK); //Typeface tf = Typeface.create("Arial", Typeface.BOLD); Typeface tf = Typeface.createFromAsset(baseContext.getAssets(), "fonts/impact.ttf"); paint.setTypeface(tf); stkPaint.setTypeface(tf); do { paint.setTextSize(fontSize); // first inject newlines into the text to wrap properly StringBuilder sb = new StringBuilder(); int left = 0; int right = text.length() - 1; while (left < right) { String substring = text.substring(left, right + 1); Rect stringBounds = new Rect(); paint.getTextBounds(substring, 0, substring.length(), stringBounds); while (stringBounds.width() > maxLineWidth) { if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } // look for a space to break the line boolean spaceFound = false; for (int i = right; i > left; i--) { if (text.charAt(i) == ' ') { right = i - 1; spaceFound = true; break; } } substring = text.substring(left, right + 1); paint.getTextBounds(substring, 0, substring.length(), stringBounds); // If we're down to a single word and we are still too wide, // the font is just too big. if (!spaceFound && stringBounds.width() > maxLineWidth) { break; } } sb.append(substring).append("\n"); left = right + 2; right = text.length() - 1; } formattedString = sb.toString(); // now determine if this font size is too big for the allowed height height = 0; for (String line : formattedString.split("\n")) { Rect stringBounds = new Rect(); paint.getTextBounds(line, 0, line.length(), stringBounds); height += stringBounds.height(); } fontSize--; } while (height > maxCaptionHeight); // draw the string one line at a time int y = 0; if (top) { y = TOP_MARGIN; } else { y = image.getHeight() - height - BOTTOM_MARGIN; } for (String line : formattedString.split("\n")) { // Draw each string twice for a shadow effect Rect stringBounds = new Rect(); paint.getTextBounds(line, 0, line.length(), stringBounds); //paint.setColor(Color.BLACK); //g.drawText(line, (image.getWidth() - (int) stringBounds.width()) / 2 + 2, y + stringBounds.height() + 2, paint); paint.setColor(Color.WHITE); g.drawText(line, (image.getWidth() - (int) stringBounds.width()) / 2, y + stringBounds.height(), paint); //stroke Rect strokeBounds = new Rect(); stkPaint.setTextSize(fontSize); stkPaint.getTextBounds(line, 0, line.length(), strokeBounds); g.drawText(line, (image.getWidth() - (int) strokeBounds.width()) / 2, y + strokeBounds.height(), stkPaint); y += stringBounds.height(); } }