List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java
public Take5PdfDocument(Context appContext) { can = new Canvas(); mContext = appContext;//from w w w . ja v a 2 s. c o m // FONT11 = mContext.getResources().getDimensionPixelSize(R.dimen.font_11); // FONT12 = mContext.getResources().getDimensionPixelSize(R.dimen.font_12); // FONT14 = mContext.getResources().getDimensionPixelSize(R.dimen.font_14); // FONT16 = mContext.getResources().getDimensionPixelSize(R.dimen.font_16); FONT11 = 10; FONT12 = 11; FONT14 = 13; FONT16 = 15; Take5Data d = Take5Data.get(appContext); mCheckBoxSectionOne = d.getSectionOneCheckBoxs(); mCheckBoxSectionTwo = d.getSectionTwoCheckBoxs(); mCheckBoxSectionThree = d.getSectionThreeCheckBoxs(); mEditTextValues = d.getEditTexts(); mDate = d.getDate(); mRiskElements = d.getRiskElements(); setDateTime(mDate); //Create custom font Typefaces impact = Typeface.createFromAsset(appContext.getAssets(), "impact.ttf"); roboto = Typeface.createFromAsset(appContext.getAssets(), "Roboto-LightItalic.ttf"); carlitoBold = Typeface.createFromAsset(appContext.getAssets(), "Carlito-Bold.ttf"); }
From source file:pro.jariz.reisplanner.fragments.PlannerFragment.java
void Render(NSStation[] nsStations, final View x, final Context context) { AutoCompleteTextView auto = (AutoCompleteTextView) x.findViewById(R.id.AutoCompleteTextView1); AutoCompleteTextView auto2 = (AutoCompleteTextView) x.findViewById(R.id.AutoCompleteTextView2); AutoCompleteTextView auto3 = (AutoCompleteTextView) x.findViewById(R.id.AutoCompleteTextView3); ArrayList<String> fullnames = new ArrayList<String>(); CardUI mCardView = (CardUI) x.findViewById(R.id.cardsview); mCardView.setSwipeable(true);/* w w w . j av a 2 s . c o m*/ CardStack stack = new CardStack(); stack.setTitle("Recentelijke stations"); for (Integer i = 0; i < nsStations.length; i++) { fullnames.add((nsStations[i]).Namen.Lang); if (i < 5) stack.add(new StationCard((nsStations[i]).Namen.Lang)); } mCardView.addStack(stack); //draw time auto.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, fullnames)); auto2.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, fullnames)); auto3.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, fullnames)); mCardView.refresh(); //stacktitle, do you even #HOLO? stack.setTitleTypeFace(Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-ThinItalic.ttf")); }
From source file:com.only5c.unsplash.com.astuetz.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/*w ww . j a va 2 s . c om*/ setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); courier = Typeface.createFromAsset(context.getAssets(), "courier.ttf"); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.door43.translationstudio.core.TargetTranslation.java
/** * Creates a new target translation/*from www. j av a2s . c o m*/ * @param translator * @param translationFormat * @param targetLanguage * @param projectId * @param translationType * @param resourceSlug * @param packageInfo * @param targetTranslationDir * @return * @throws Exception */ public static TargetTranslation create(Context context, NativeSpeaker translator, TranslationFormat translationFormat, TargetLanguage targetLanguage, String projectId, TranslationType translationType, String resourceSlug, PackageInfo packageInfo, File targetTranslationDir) throws Exception { targetTranslationDir.mkdirs(); Manifest manifest = Manifest.generate(targetTranslationDir); // build new manifest JSONObject projectJson = new JSONObject(); projectJson.put("id", projectId); projectJson.put("name", ""); manifest.put(FIELD_PROJECT, projectJson); JSONObject typeJson = new JSONObject(); typeJson.put("id", translationType); typeJson.put("name", translationType.getName()); manifest.put(FIELD_TRANSLATION_TYPE, typeJson); JSONObject generatorJson = new JSONObject(); generatorJson.put("name", "ts-android"); generatorJson.put("build", packageInfo.versionCode); manifest.put(FIELD_GENERATOR, generatorJson); manifest.put(FIELD_PACKAGE_VERSION, PACKAGE_VERSION); manifest.put(FIELD_TARGET_LANGUAGE, targetLanguage.toJson()); manifest.put(FIELD_FORMAT, translationFormat); JSONObject resourceJson = new JSONObject(); resourceJson.put("id", resourceSlug); manifest.put(FIELD_RESOURCE, resourceJson); File licenseFile = new File(targetTranslationDir, LICENSE_FILE); InputStream is = context.getAssets().open(LICENSE_FILE); if (is != null) { FileUtils.copyInputStreamToFile(is, licenseFile); } else { throw new FileNotFoundException("The template LICENSE.md file could not be found in the assets"); } // return the new target translation TargetTranslation targetTranslation = new TargetTranslation(targetTranslationDir); targetTranslation.addContributor(translator); return targetTranslation; }
From source file:com.gft.unity.android.AndroidIO.java
private void loadServicesConfig() { Context context = AndroidServiceLocator.getContext(); ArrayList<IOService> servicesList = new ArrayList<IOService>(); try {/*w ww .j a v a 2 s . c o m*/ XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(AndroidUtils.getInstance().getAssetInputStream(context.getAssets(), SERVICES_CONFIG_FILE), DEFAULT_ENCODING); int eventType = xpp.getEventType(); IOService service = null; String serviceName = ""; String serviceType = ""; String serviceMethod = ""; String fingerprint = ""; IOServiceEndpoint serviceEndpoint = null; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xpp.getName().toUpperCase().equals(SERVICE_NODE_ATTRIBUTE)) { service = new IOService(); serviceName = xpp.getAttributeValue(null, SERVICE_ATTRIBUTE); serviceType = xpp.getAttributeValue(null, TYPE_ATTRIBUTE); serviceMethod = xpp.getAttributeValue(null, REQ_METHOD_ATTRIBUTE); } else if (xpp.getName().toUpperCase().equals(ENDPOINT_NODE_ATTRIBUTE)) { serviceEndpoint = new IOServiceEndpoint(); serviceEndpoint.setHost(xpp.getAttributeValue(null, HOST_ATTRIBUTE)); String port = xpp.getAttributeValue(null, PORT_ATTRIBUTE); if (port != null) { serviceEndpoint.setPort(Integer.valueOf(port)); } serviceEndpoint.setPath(xpp.getAttributeValue(null, PATH_ATTRIBUTE)); serviceEndpoint.setProxyUrl(xpp.getAttributeValue(null, PROXY_ATTRIBUTE)); serviceEndpoint.setScheme(xpp.getAttributeValue(null, SCHEME_ATTRIBUTE)); fingerprint = xpp.getAttributeValue(null, FINGERPRINT_ATTRIBUTE); if (fingerprint != null) fingerprint = fingerprint.toUpperCase(); serviceEndpoint.setFingerprint(fingerprint); //LOG.LogDebug(Module.PLATFORM, "LoadConfig fingerprint [" + fingerprint + "]"); } } else if (eventType == XmlPullParser.END_TAG) { if (xpp.getName().toUpperCase().equals(SERVICE_NODE_ATTRIBUTE)) { service.setName(serviceName); if (serviceType == null) { serviceType = DEFAULT_SERVICE_TYPE; } service.setType(ServiceType.valueOf(serviceType)); if (serviceMethod == null) { serviceMethod = DEFAULT_SERVICE_METHOD; } service.setRequestMethod(RequestMethod.valueOf(serviceMethod)); service.setEndpoint(serviceEndpoint); servicesList.add(service); } } eventType = xpp.next(); } } catch (Exception ex) { LOG.LogDebug(Module.PLATFORM, "LoadConfig error [" + SERVICES_CONFIG_FILE + "]: " + ex.getMessage()); } servicesConfig.setServices(servicesList.toArray(new IOService[servicesList.size()])); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static byte[] storage_readAssetResource(Context context, String fileName) { try {//w w w . ja v a 2 s . c om InputStream asset = context.getAssets().open(fileName); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[asset.available()]; asset.read(buffer); byteArrayOutputStream.write(buffer); asset.close(); return byteArrayOutputStream.toByteArray(); } catch (Exception e) { if (LOG_ENABLE) Log.e("TollBox_ERROR", "storage_readRawResource() Error obtaining raw data: " + e.getMessage(), e); return null; } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Plays the specified sound from the application asset folder. * //from w ww . java 2 s . c o m * @param context * @param assetSoundPath Path to the sound in the assets folder. */ public static void media_soundPlayFromAssetFolder(Context context, String assetSoundPath) { try { AssetFileDescriptor afd = context.getAssets().openFd(assetSoundPath); MediaPlayer player = new MediaPlayer(); player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); player.prepare(); player.start(); } catch (Exception e) { if (LOG_ENABLE) { Log.e(TAG, "Error playing sound: '" + assetSoundPath + "' (" + e.getMessage() + ")", e); } } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Set a font to a text view./* ww w .j a va 2s .c om*/ * * @param context * @param textView * @param fontPath The path to the font resource. Must be placed in asset * folder. */ public static void font_applyTitleFont(Context context, TextView textView, String fontPath) { if (textView != null) { Typeface font = Typeface.createFromAsset(context.getAssets(), fontPath); textView.setTypeface(font); } }
From source file:com.polychrom.cordova.actionbar.ActionBarSherlock.java
private Drawable getDrawableForURI(String uri_string) { Uri uri = Uri.parse(uri_string);//from w w w . j a v a 2s . com Context ctx = ((SherlockActivity) cordova); // Special case - TrueType fonts if (uri_string.endsWith(".ttf")) { /*for(String base: bases) { String path = base + uri; // TODO: Font load / glyph rendering ("/blah/fontawesome.ttf:\f1234") }*/ } else if (uri_string.startsWith("R.drawable")) { String[] array = uri_string.split("\\."); String name = array[2]; int resourceId = ctx.getResources().getIdentifier(name, "drawable", ctx.getPackageName()); Drawable drawable = ctx.getResources().getDrawable(resourceId); return drawable; } // General bitmap else { if (uri.isAbsolute()) { if (uri.getScheme().startsWith("http")) { try { URL url = new URL(uri_string); InputStream stream = url.openConnection().getInputStream(); return new BitmapDrawable(ctx.getResources(), stream); } catch (MalformedURLException e) { return null; } catch (IOException e) { return null; } catch (Exception e) { return null; } } else { try { InputStream stream = ctx.getContentResolver().openInputStream(uri); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { return null; } } } else { for (String base : bases) { String path = base + uri; // Asset if (base.startsWith("file:///android_asset/")) { path = path.substring(22); try { InputStream stream = ctx.getAssets().open(path); return new BitmapDrawable(ctx.getResources(), stream); } catch (IOException e) { continue; } } // General URI else { try { InputStream stream = ctx.getContentResolver().openInputStream(Uri.parse(path)); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { continue; } } } } } return null; }
From source file:io.imoji.sdk.grid.ui.ResultView.java
public ResultView(Context context, @ResultViewSize int viewSize) { super(context); this.context = context; this.viewSize = viewSize; int resultWidth = getDimension(0); int resultHeight = getDimension(1); setLayoutParams(new StaggeredGridLayoutManager.LayoutParams(resultWidth, resultHeight)); placeholder = new ImageView(context); int placeholderSide = getDimension(4); RelativeLayout.LayoutParams placeholderParams = new LayoutParams(placeholderSide, placeholderSide); placeholderParams.addRule(RelativeLayout.CENTER_IN_PARENT); placeholder.setLayoutParams(placeholderParams); addView(placeholder);//from ww w . j a v a 2s . co m container = new RelativeLayout(context); addView(container, new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); final Animation pressedAnimation = AnimationUtils.loadAnimation(context, R.anim.search_result_pressed); final Animation releasedAnimation = AnimationUtils.loadAnimation(context, R.anim.search_result_released); imageView = new GifImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (searchResult != null && !searchResult.isCategory()) { imageView.startAnimation(pressedAnimation); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (searchResult != null && !searchResult.isCategory()) { imageView.startAnimation(releasedAnimation); } break; } return super.onTouchEvent(event); } }; RelativeLayout.LayoutParams imageParams = new LayoutParams(resultWidth, resultWidth); imageParams.addRule(RelativeLayout.CENTER_IN_PARENT); imageView.setLayoutParams(imageParams); container.addView(imageView); textView = new TextView(context); int titleHeight = getDimension(2); RelativeLayout.LayoutParams titleParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, titleHeight); titleParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); textView.setLayoutParams(titleParams); textView.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Montserrat-Light.otf")); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getDimension(3)); //TODO // FIXME: 5/2/16 textView.setTextColor(getResources().getColor(R.color.search_result_category_title)); textView.setGravity(Gravity.CENTER); container.addView(textView); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { listener.onTap(searchResult); } }); }