Java Code Examples for android.content.res.Resources
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/.
Source file: MenuPopupHelper.java

public MenuPopupHelper(Context context,MenuBuilder menu,View anchorView,boolean overflowOnly){ mContext=context; mInflater=LayoutInflater.from(context); mMenu=menu; mOverflowOnly=overflowOnly; final Resources res=context.getResources(); mPopupMaxWidth=Math.max(res.getDisplayMetrics().widthPixels / 2,res.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth)); mAnchorView=anchorView; menu.addMenuPresenter(this); }
Example 2
From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.
Source file: MenuPopupHelper.java

public MenuPopupHelper(Context context,MenuBuilder menu,View anchorView,boolean overflowOnly){ mContext=context; mInflater=LayoutInflater.from(context); mMenu=menu; mOverflowOnly=overflowOnly; final Resources res=context.getResources(); mPopupMaxWidth=Math.max(res.getDisplayMetrics().widthPixels / 2,res.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth)); mAnchorView=anchorView; menu.addMenuPresenter(this); }
Example 3
From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/view/menu/.
Source file: MenuPopupHelper.java

public MenuPopupHelper(Context context,MenuBuilder menu,View anchorView,boolean overflowOnly){ mContext=context; mInflater=LayoutInflater.from(context); mMenu=menu; mOverflowOnly=overflowOnly; final Resources res=context.getResources(); mPopupMaxWidth=Math.max(res.getDisplayMetrics().widthPixels / 2,res.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth)); mAnchorView=anchorView; menu.addMenuPresenter(this); }
Example 4
From project adg-android, under directory /src/com/analysedesgeeks/android/.
Source file: ActivityController.java

public static void onContactEmailClicked(final Context context){ final Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND); final Resources res=context.getResources(); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{Const.ADG_CONTACT_EMAIL}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,res.getString(R.string.contactEmailSubject)); context.startActivity(Intent.createChooser(emailIntent,res.getString(R.string.sendEmail))); }
Example 5
From project agit, under directory /agit/src/main/java/com/madgag/android/.
Source file: ActionBarUtil.java

public static void fixImageTilingOn(ActionBar actionBar){ if (Build.VERSION.SDK_INT < ICE_CREAM_SANDWICH) { Resources resources=actionBar.getThemedContext().getResources(); BitmapDrawable bg=(BitmapDrawable)resources.getDrawable(R.drawable.actionbar_background); bg.setTileModeXY(REPEAT,REPEAT); actionBar.setBackgroundDrawable(bg); } }
Example 6
public void startRefreshAnimation(){ if (mRefreshItem != null) { Resources res=getResources(); AnimationDrawable d=(AnimationDrawable)res.getDrawable(R.drawable.ic_popup_sync); mRefreshItem.setIcon(d); d.start(); } }
Example 7
From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/internal/view/menu/.
Source file: MenuPopupHelper.java

public MenuPopupHelper(Context context,MenuBuilder menu,View anchorView,boolean overflowOnly){ mContext=context; mInflater=LayoutInflater.from(context); mMenu=menu; mOverflowOnly=overflowOnly; final Resources res=context.getResources(); mPopupMaxWidth=Math.max(res.getDisplayMetrics().widthPixels / 2,res.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth)); mAnchorView=anchorView; menu.addMenuPresenter(this); }
Example 8
From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/util/.
Source file: StyleableSpannableStringBuilder.java

public StyleableSpannableStringBuilder appendOrange(CharSequence text){ final Resources resources=context.getResources(); if (resources != null) { final ForegroundColorSpan c=new ForegroundColorSpan(resources.getColor(R.color.orange)); return appendWithStyle(c,text); } return appendWithStyle(new ForegroundColorSpan(0),text); }
Example 9
From project and-bible, under directory /AndBible/src/net/bible/service/readingplan/.
Source file: ReadingPlanDao.java

/** * look in assets/readingplan and sdcard/jsword/readingplan for reading plans and return a list of all codes */ private List<String> getAllReadingPlanCodes() throws IOException { Resources resources=BibleApplication.getApplication().getResources(); AssetManager assetManager=resources.getAssets(); List<String> allCodes=new ArrayList<String>(); String[] internalPlans=assetManager.list(READING_PLAN_FOLDER); allCodes.addAll(getReadingPlanCodes(internalPlans)); String[] userPlans=USER_READING_PLAN_FOLDER.list(); allCodes.addAll(getReadingPlanCodes(userPlans)); return allCodes; }
Example 10
From project andlytics, under directory /actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.
Source file: MenuPopupHelper.java

public MenuPopupHelper(Context context,MenuBuilder menu,View anchorView,boolean overflowOnly){ mContext=context; mInflater=LayoutInflater.from(context); mMenu=menu; mOverflowOnly=overflowOnly; final Resources res=context.getResources(); mPopupMaxWidth=Math.max(res.getDisplayMetrics().widthPixels / 2,res.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth)); mAnchorView=anchorView; menu.addMenuPresenter(this); }
Example 11
From project Android, under directory /app/src/main/java/com/github/mobile/ui/commit/.
Source file: CommitFileListAdapter.java

/** * @param inflater * @param diffStyler * @param avatars * @param imageGetter */ public CommitFileListAdapter(final LayoutInflater inflater,final DiffStyler diffStyler,final AvatarLoader avatars,final HttpImageGetter imageGetter){ super(inflater); this.diffStyler=diffStyler; this.avatars=avatars; this.imageGetter=imageGetter; Resources resources=inflater.getContext().getResources(); addTextColor=resources.getColor(color.diff_add_text); removeTextColor=resources.getColor(color.diff_remove_text); }
Example 12
From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/language/.
Source file: LanguageCodeHelper.java

/** * Map the given ISO 639-3 language code to a name of a language, for example, "Spanish" * @param context interface to calling application environment. Needed to access values from strings.xml. * @param languageCode ISO 639-3 language code * @return language name */ public static String getOcrLanguageName(Context context,String languageCode){ Resources res=context.getResources(); String[] language6393=res.getStringArray(R.array.iso6393); String[] languageNames=res.getStringArray(R.array.languagenames); int len; for (len=0; len < language6393.length; len++) { if (language6393[len].equals(languageCode)) { Log.d(TAG,"getOcrLanguageName: " + languageCode + "->"+ languageNames[len]); return languageNames[len]; } } Log.d(TAG,"languageCode: Could not find language name for ISO 693-3: " + languageCode); return languageCode; }
Example 13
From project Android-Terminal-Emulator, under directory /src/jackpal/androidterm/.
Source file: Term.java

private void doDocumentKeys(){ AlertDialog.Builder dialog=new AlertDialog.Builder(this); Resources r=getResources(); dialog.setTitle(r.getString(R.string.control_key_dialog_title)); dialog.setMessage(formatMessage(mSettings.getControlKeyId(),TermSettings.CONTROL_KEY_ID_NONE,r,R.array.control_keys_short_names,R.string.control_key_dialog_control_text,R.string.control_key_dialog_control_disabled_text,"CTRLKEY") + "\n\n" + formatMessage(mSettings.getFnKeyId(),TermSettings.FN_KEY_ID_NONE,r,R.array.fn_keys_short_names,R.string.control_key_dialog_fn_text,R.string.control_key_dialog_fn_disabled_text,"FNKEY")); dialog.show(); }
Example 14
From project android-thaiime, under directory /latinime/src/com/android/inputmethod/keyboard/internal/.
Source file: KeyboardBuilder.java

public KeyboardBuilder(Context context,KP params){ mContext=context; final Resources res=context.getResources(); mResources=res; mDisplayMetrics=res.getDisplayMetrics(); mParams=params; setTouchPositionCorrectionData(context,params); params.GRID_WIDTH=res.getInteger(R.integer.config_keyboard_grid_width); params.GRID_HEIGHT=res.getInteger(R.integer.config_keyboard_grid_height); }
Example 15
From project androidZenWriter, under directory /library/src/com/actionbarsherlock/internal/view/menu/.
Source file: MenuPopupHelper.java

public MenuPopupHelper(Context context,MenuBuilder menu,View anchorView,boolean overflowOnly){ mContext=context; mInflater=LayoutInflater.from(context); mMenu=menu; mOverflowOnly=overflowOnly; final Resources res=context.getResources(); mPopupMaxWidth=Math.max(res.getDisplayMetrics().widthPixels / 2,res.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth)); mAnchorView=anchorView; menu.addMenuPresenter(this); }
Example 16
From project Android_1, under directory /Livewallpaper/switch_animation/src/com/novoda/wallpaper/.
Source file: AnimSwitchWallPaper.java

OutRunEngine(){ Resources res=getResources(); for (int i=0; i < FRONT_RES; i++) { mFrontPicIds[i]=res.getIdentifier("front_day00" + (i + 1),"drawable","com.novoda.wallpaper"); } for (int i=0; i < LEFT_RES; i++) { mLeftPicIds[i]=res.getIdentifier("left_day00" + (i + 1),"drawable","com.novoda.wallpaper"); } for (int i=0; i < RIGHT_RES; i++) { mRightPicIds[i]=res.getIdentifier("right_day00" + (i + 1),"drawable","com.novoda.wallpaper"); } }
Example 17
void updateTitle(){ int dictCount=dictionaryService.getVolumes().size(); Resources r=getResources(); String dictionaries=r.getQuantityString(R.plurals.dictionaries,dictCount); String appName=r.getString(R.string.appName); String mainTitle=r.getString(R.string.titleLookupActivity,appName,String.format(dictionaries,dictCount)); setTitle(mainTitle); }
Example 18
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.
Source file: ActivityPicker.java

protected IconResizer getResizer(Context context){ if (sResizer == null) { final Resources resources=context.getResources(); int size=(int)resources.getDimension(android.R.dimen.app_icon_size); sResizer=new IconResizer(size,size,resources.getDisplayMetrics()); } return sResizer; }
Example 19
From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/led/.
Source file: PackageSettingsActivity.java

private void updateUiForCapabilities(){ PreferenceScreen screen=getPreferenceScreen(); Resources res=getResources(); if (res.getBoolean(R.bool.has_single_notification_led)) { screen.removePreference(mColorPref); } if (!res.getBoolean(R.bool.has_rgb_notification_led)) { screen.removePreference(mBlinkPref); screen.removePreference(mCustomPref); screen.removePreference(findPreference("color_notice")); } }
Example 20
From project android_packages_apps_CMSettings, under directory /src/com/cyanogenmod/settings/widgets/.
Source file: TouchInterceptor.java

public TouchInterceptor(Context context,AttributeSet attrs){ super(context,attrs); mTouchSlop=ViewConfiguration.get(context).getScaledTouchSlop(); Resources res=getResources(); mItemHeightNormal=res.getDimensionPixelSize(R.dimen.normal_height); mItemHeightHalf=mItemHeightNormal / 2; mItemHeightExpanded=res.getDimensionPixelSize(R.dimen.expanded_height); }
Example 21
From project android_packages_apps_Gallery, under directory /src/com/android/camera/.
Source file: GalleryPicker.java

private void loadDrawableIfNeeded(){ if (mFrameGalleryMask != null) return; Resources r=getResources(); mFrameGalleryMask=r.getDrawable(R.drawable.frame_gallery_preview_album_mask); mCellOutline=r.getDrawable(android.R.drawable.gallery_thumb); mVideoOverlay=r.getDrawable(R.drawable.ic_gallery_video_overlay); }
Example 22
From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/app/.
Source file: Config.java

private AlbumPage(Context context){ Resources r=context.getResources(); slotViewSpec=new SlotView.Spec(); slotViewSpec.rowsLand=r.getInteger(R.integer.album_rows_land); slotViewSpec.rowsPort=r.getInteger(R.integer.album_rows_port); slotViewSpec.slotGap=r.getDimensionPixelSize(R.dimen.album_slot_gap); }
Example 23
From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.
Source file: PopupMenu.java

public PopupTexture(Context context){ super(Bitmap.Config.ARGB_8888); Resources resources=context.getResources(); Bitmap background=BitmapFactory.decodeResource(resources,Res.drawable.popup); mBackground=new NinePatch(background,background.getNinePatchChunk(),null); Bitmap highlightSelected=BitmapFactory.decodeResource(resources,Res.drawable.popup_option_selected); mHighlightSelected=new NinePatch(highlightSelected,highlightSelected.getNinePatchChunk(),null); mTriangleBottom=BitmapFactory.decodeResource(resources,Res.drawable.popup_triangle_bottom); }
Example 24
From project android_packages_apps_phone, under directory /src/com/android/phone/.
Source file: EditFdnContactScreen.java

/** * Overridden to display the import and delete commands. */ @Override public boolean onCreateOptionsMenu(Menu menu){ super.onCreateOptionsMenu(menu); Resources r=getResources(); menu.add(0,MENU_IMPORT,0,r.getString(R.string.importToFDNfromContacts)).setIcon(R.drawable.ic_menu_contact); menu.add(0,MENU_DELETE,0,r.getString(R.string.menu_delete)).setIcon(android.R.drawable.ic_menu_delete); return true; }
Example 25
From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/util/.
Source file: Util.java

public static Uri getResourceUri(Context packageContext,int res){ try { Resources resources=packageContext.getResources(); return getResourceUri(resources,packageContext.getPackageName(),res); } catch ( Resources.NotFoundException e) { Log.e(TAG,"Resource not found: " + res + " in "+ packageContext.getPackageName()); return null; } }
Example 26
From project android_packages_apps_SalvageParts, under directory /src/com/salvagemod/salvageparts/widgets/.
Source file: TouchInterceptor.java

public TouchInterceptor(Context context,AttributeSet attrs){ super(context,attrs); mTouchSlop=ViewConfiguration.get(context).getScaledTouchSlop(); Resources res=getResources(); mItemHeightNormal=res.getDimensionPixelSize(R.dimen.normal_height); mItemHeightHalf=mItemHeightNormal / 2; mItemHeightExpanded=res.getDimensionPixelSize(R.dimen.expanded_height); }
Example 27
From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/widget/.
Source file: AppListItem.java

public AppListItem(Context context,AttributeSet attrs){ super(context,attrs); mContext=context; Resources resources=context.getResources(); mPreferredHeight=resources.getDimensionPixelSize(R.dimen.list_item_perferred_height); mPaddingTop=resources.getDimensionPixelSize(R.dimen.list_item_padding_top); mPaddingBottom=resources.getDimensionPixelSize(R.dimen.list_item_padding_bottom); mPaddingLeft=resources.getDimensionPixelSize(R.dimen.list_item_padding_left); mPaddingRight=resources.getDimensionPixelSize(R.dimen.list_item_padding_right); mIconViewSize=resources.getDimensionPixelSize(R.dimen.list_item_icon_size); mGapBetweenImageAndText=resources.getDimensionPixelSize(R.dimen.list_item_gap_between_image_and_text); mHeaderPaddingLeft=resources.getDimensionPixelSize(R.dimen.list_item_header_padding_left); }
Example 28
From project android_packages_apps_TouchWiz30Launcher, under directory /src/com/sec/android/app/twlauncher/.
Source file: AddAdapter.java

public AddAdapter(Launcher launcher){ mInflater=(LayoutInflater)launcher.getSystemService("layout_inflater"); Resources resources=launcher.getResources(); mItems.add(new ListItem(resources,0x7f0a0018,0x7f020072,0)); mItems.add(new ListItem(resources,0x7f0a0014,0x7f020079,1)); mItems.add(new ListItem(resources,0x7f0a0017,0x7f020070,2)); mItems.add(new ListItem(resources,0x7f0a0019,0x7f02007a,3)); }
Example 29
From project abalone-android, under directory /src/com/bytopia/abalone/.
Source file: BoardRenderer.java

/** * Constructor that initializes brushes and images from resources. * @param view parent view to render the board onto */ public BoardRenderer(View view){ this.view=view; Resources r=view.getResources(); blackBallPicture=r.getDrawable(R.drawable.black_ball); whiteBallPicture=r.getDrawable(R.drawable.white_ball); emptyBallPicture=r.getDrawable(R.drawable.hole); defaultPaint=new Paint(Paint.ANTI_ALIAS_FLAG); defaultPaint.setColor(r.getColor(R.color.defaultColor)); blackP=new Paint(Paint.ANTI_ALIAS_FLAG); blackP.setColor(Color.BLACK); whiteP=new Paint(Paint.ANTI_ALIAS_FLAG); whiteP.setColor(Color.WHITE); emptyP=new Paint(Paint.ANTI_ALIAS_FLAG); emptyP.setColor(Color.GRAY); highlightedP=new Paint(Paint.ANTI_ALIAS_FLAG); highlightedP.setColor(Color.RED); highlightedP.setAlpha(100); selectedP=new Paint(Paint.ANTI_ALIAS_FLAG); selectedP.setColor(Color.GREEN); selectedP.setAlpha(100); boardP=new Paint(Paint.ANTI_ALIAS_FLAG); boardP.setColor(r.getColor(R.color.board)); dst=new Rect(); }
Example 30
From project alljoyn_java, under directory /samples/android/chat/src/org/alljoyn/bus/sample/chat/.
Source file: TabWidget.java

public void onCreate(Bundle savedInstanceState){ Log.i(TAG,"onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res=getResources(); TabHost tabHost=getTabHost(); TabHost.TabSpec spec; Intent intent; intent=new Intent().setClass(this,UseActivity.class); spec=tabHost.newTabSpec("use").setIndicator("",res.getDrawable(R.drawable.ic_tab_use)).setContent(intent); tabHost.addTab(spec); intent=new Intent().setClass(this,HostActivity.class); spec=tabHost.newTabSpec("host").setIndicator("",res.getDrawable(R.drawable.ic_tab_host)).setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); }
Example 31
From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/editor/activity/.
Source file: TaskEditorActivity.java

static boolean addReminder(Activity activity,View.OnClickListener listener,ArrayList<LinearLayout> items,ArrayList<Integer> values,ArrayList<String> labels,int minutes){ if (items.size() >= MAX_REMINDERS) { return false; } LayoutInflater inflater=activity.getLayoutInflater(); LinearLayout parent=(LinearLayout)activity.findViewById(R.id.reminder_items_container); LinearLayout reminderItem=(LinearLayout)inflater.inflate(R.layout.edit_reminder_item,null); parent.addView(reminderItem); Spinner spinner=(Spinner)reminderItem.findViewById(R.id.reminder_value); Resources res=activity.getResources(); spinner.setPrompt(res.getString(R.string.reminders_title)); int resource=android.R.layout.simple_spinner_item; ArrayAdapter<String> adapter=new ArrayAdapter<String>(activity,resource,labels); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); ImageButton reminderRemoveButton; reminderRemoveButton=(ImageButton)reminderItem.findViewById(R.id.reminder_remove); reminderRemoveButton.setOnClickListener(listener); int index=findMinutesInReminderList(values,minutes); spinner.setSelection(index); items.add(reminderItem); return true; }
Example 32
From project android-xbmcremote, under directory /src/org/xbmc/android/widget/.
Source file: FastScrollView.java

private void init(Context context){ final Resources res=context.getResources(); useThumbDrawable(res.getDrawable(R.drawable.scrollbar_handle)); mOverlayDrawable=res.getDrawable(R.drawable.dialog_full_dark); mScrollCompleted=true; setWillNotDraw(false); setOnHierarchyChangeListener(this); mOverlayPos=new RectF(); mScrollFade=new ScrollFade(); mPaint=new Paint(); mPaint.setAntiAlias(true); mPaint.setTextAlign(Paint.Align.CENTER); mPaint.setTextSize(mOverlaySize / 2); mPaint.setColor(0xFFFFFFFF); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); }
Example 33
From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/provider/.
Source file: BooksProvider.java

private String keyFor(String name){ if (name == null) name=""; name=name.trim().toLowerCase(); if (mKeyPrefixes == null) { final Resources resources=getContext().getResources(); final String[] keyPrefixes=resources.getStringArray(R.array.prefixes); final int count=keyPrefixes.length; mKeyPrefixes=new Pattern[count]; for (int i=0; i < count; i++) { mKeyPrefixes[i]=Pattern.compile("^" + keyPrefixes[i] + "\\s+"); } } if (mKeySuffixes == null) { final Resources resources=getContext().getResources(); final String[] keySuffixes=resources.getStringArray(R.array.suffixes); final int count=keySuffixes.length; mKeySuffixes=new Pattern[count]; for (int i=0; i < count; i++) { mKeySuffixes[i]=Pattern.compile("\\s*" + keySuffixes[i] + "$"); } } final Pattern[] prefixes=mKeyPrefixes; for ( Pattern prefix : prefixes) { final Matcher matcher=prefix.matcher(name); if (matcher.find()) { name=name.substring(matcher.end()); break; } } final Pattern[] suffixes=mKeySuffixes; for ( Pattern suffix : suffixes) { final Matcher matcher=suffix.matcher(name); if (matcher.find()) { name=name.substring(0,matcher.start()); break; } } return name; }
Example 34
From project android_7, under directory /src/org/immopoly/android/widget/.
Source file: ImmoscoutPlacesOverlay.java

public ImmoscoutPlacesOverlay(Fragment fragment,MapView mapView,LayoutInflater inflator,boolean isPortfolio){ super(boundCenter(fragment.getResources().getDrawable(R.drawable.map_marker_icon))); mMapView=mapView; this.isPortfolio=isPortfolio; mMapFragment=fragment; Resources resources=fragment.getResources(); mapMarkerIcon=boundCenter(resources.getDrawable(R.drawable.map_marker_icon)); mapMarkerIcon_new=boundCenter(resources.getDrawable(R.drawable.map_marker_icon_new)); mapMarkerIcon_old=boundCenter(resources.getDrawable(R.drawable.map_marker_icon_old)); mapMarkerIcon_owned=boundCenter(resources.getDrawable(R.drawable.map_marker_property_icon)); mapMarkerIcon_cluster=boundCenter(resources.getDrawable(R.drawable.map_marker_icon_cluster)); markerBounds=mapMarkerIcon.getBounds(); MIN_INTERSECTION_AREA=(int)(markerBounds.width() * markerBounds.height() * MIN_INTERSECTION_AMOUNT); ClusterMarker.init(resources.getDisplayMetrics(),mapMarkerIcon.getIntrinsicHeight()); gestureDetector=new GestureDetector(new GestureDetector.SimpleOnGestureListener(){ public boolean onDoubleTap( MotionEvent e){ if (System.currentTimeMillis() - itemTapTime > 500) mMapView.getController().zoomInFixing((int)e.getX(),(int)e.getY()); return super.onDoubleTap(e); } } ); }
Example 35
From project android_packages_apps_Exchange, under directory /src/com/android/exchange/utility/.
Source file: CalendarUtilities.java

static public String buildMessageTextFromEntityValues(Context context,ContentValues entityValues,StringBuilder sb){ if (sb == null) { sb=new StringBuilder(); } Resources resources=context.getResources(); Date date=new Date(entityValues.getAsLong(Events.DTSTART)); boolean allDayEvent=false; if (entityValues.containsKey(Events.ALL_DAY)) { Integer ade=entityValues.getAsInteger(Events.ALL_DAY); allDayEvent=(ade != null) && (ade == 1); } boolean recurringEvent=!entityValues.containsKey(Events.ORIGINAL_SYNC_ID) && entityValues.containsKey(Events.RRULE); String dateTimeString; int res; if (allDayEvent) { dateTimeString=DateFormat.getDateInstance().format(date); res=recurringEvent ? R.string.meeting_allday_recurring : R.string.meeting_allday; } else { dateTimeString=DateFormat.getDateTimeInstance().format(date); res=recurringEvent ? R.string.meeting_recurring : R.string.meeting_when; } sb.append(resources.getString(res,dateTimeString)); String location=null; if (entityValues.containsKey(Events.EVENT_LOCATION)) { location=entityValues.getAsString(Events.EVENT_LOCATION); if (!TextUtils.isEmpty(location)) { sb.append("\n"); sb.append(resources.getString(R.string.meeting_where,location)); } } String desc=entityValues.getAsString(Events.DESCRIPTION); if (desc != null) { sb.append("\n--\n"); sb.append(desc); } return sb.toString(); }
Example 36
From project android_packages_apps_FileManager, under directory /src/org/openintents/distribution/.
Source file: EulaActivity.java

/** * Read license from raw resource. * @param resourceid ID of the raw resource. * @return */ String readTextFromRawResource(int resourceid,boolean preserveLineBreaks){ String license=""; Resources resources=getResources(); BufferedReader in=new BufferedReader(new InputStreamReader(resources.openRawResource(resourceid))); String line; StringBuilder sb=new StringBuilder(); try { while ((line=in.readLine()) != null) { if (TextUtils.isEmpty(line)) { sb.append("\n\n"); } else { sb.append(line); if (preserveLineBreaks) { sb.append("\n"); } else { sb.append(" "); } } } license=sb.toString(); } catch ( IOException e) { e.printStackTrace(); } return license; }
Example 37
From project android_packages_apps_Nfc, under directory /src/com/android/nfc/handover/.
Source file: ConfirmConnectActivity.java

@Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); AlertDialog.Builder builder=new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_DARK); Intent launchIntent=getIntent(); mDevice=launchIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (mDevice == null) finish(); Resources res=getResources(); String deviceName=mDevice.getName() != null ? mDevice.getName() : ""; String confirmString=String.format(res.getString(R.string.confirm_pairing),deviceName); builder.setMessage(confirmString).setCancelable(false).setPositiveButton(res.getString(R.string.pair_yes),new DialogInterface.OnClickListener(){ public void onClick( DialogInterface dialog, int id){ Intent allowIntent=new Intent(BluetoothHeadsetHandover.ACTION_ALLOW_CONNECT); allowIntent.putExtra(BluetoothDevice.EXTRA_DEVICE,mDevice); sendBroadcast(allowIntent); ConfirmConnectActivity.this.finish(); } } ).setNegativeButton(res.getString(R.string.pair_no),new DialogInterface.OnClickListener(){ public void onClick( DialogInterface dialog, int id){ Intent denyIntent=new Intent(BluetoothHeadsetHandover.ACTION_DENY_CONNECT); denyIntent.putExtra(BluetoothDevice.EXTRA_DEVICE,mDevice); sendBroadcast(denyIntent); ConfirmConnectActivity.this.finish(); } } ); AlertDialog alert=builder.create(); alert.show(); }
Example 38
From project android_packages_apps_Tag, under directory /canon/src/com/android/apps/tagcanon/.
Source file: TagCanon.java

final NdefMessage[] buildImageMessages(){ Resources res=getResources(); Drawable drawable=res.getDrawable(R.drawable.ic_launcher_nfc); Bitmap photo=((BitmapDrawable)drawable).getBitmap(); final int size=photo.getWidth() * photo.getHeight() * 4; final ByteArrayOutputStream out=new ByteArrayOutputStream(size); try { photo.compress(Bitmap.CompressFormat.PNG,100,out); out.flush(); byte[] payload=out.toByteArray(); out.close(); NdefRecord text=newTextRecord("There's an image below this text!",Locale.US,true); NdefRecord image=newMimeRecord("image/png",payload); NdefMessage[] msgs=new NdefMessage[]{new NdefMessage(new NdefRecord[]{text,image})}; return msgs; } catch ( IOException e) { throw new RuntimeException("Failed to compress image",e); } }
Example 39
From project android-animation-backport, under directory /animation-backport/src/backports/animation/.
Source file: AnimatorInflater.java

/** * Loads an {@link Animator} object from a resource * @param context Application context used to access resources * @param id The resource id of the animation to load * @return The animator object reference by the specified id * @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded */ public static Animator loadAnimator(Context context,int id) throws NotFoundException { XmlResourceParser parser=null; try { parser=context.getResources().getAnimation(id); return createAnimatorFromXml(context,parser); } catch ( XmlPullParserException ex) { Resources.NotFoundException rnf=new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } catch ( IOException ex) { Resources.NotFoundException rnf=new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } finally { if (parser != null) parser.close(); } }
Example 40
From project android-api-demos, under directory /src/com/mobeelizer/demos/utils/.
Source file: DataUtil.java

/** * Generates the title, related director of the movie and its rating. Data is then stored in {@link Movie} class. <br/>{@link android.content.res.Resources Resource} reference is required for first usage to access{@code res/values/movies.xml} file and its data. * @param res Reference to Android {@link android.content.res.Resources Resources} class. * @return Random {@link Movie} object. */ public static Movie getRandomMovie(final Resources res){ if (mTitles == null) { mTitles=res.getStringArray(R.array.movieTitles); mDirectors=res.getStringArray(R.array.movieDirectors); } int index=mRand.nextInt(mTitles.length); Movie m=new Movie(); m.title=mTitles[index]; m.director=mDirectors[index]; m.rating=mRand.nextInt(5) + 1; return m; }
Example 41
From project android-bankdroid, under directory /src/com/liato/bankdroid/liveview/.
Source file: PluginUtils.java

/** * Stores icon to phone file system * @param resources Reference to project resources * @param resource Reference to specific resource * @param fileName The icon file name */ public static String storeIconToFile(Context ctx,Resources resources,int resource,String fileName){ Log.d(PluginConstants.LOG_TAG,"Store icon to file."); if (resources == null) { return ""; } Bitmap bitmap=BitmapFactory.decodeStream(resources.openRawResource(resource)); try { FileOutputStream fos=ctx.openFileOutput(fileName,Context.MODE_WORLD_READABLE); bitmap.compress(Bitmap.CompressFormat.PNG,100,fos); fos.flush(); fos.close(); } catch ( IOException e) { Log.e(PluginConstants.LOG_TAG,"Failed to store to device",e); } File iconFile=ctx.getFileStreamPath(fileName); Log.d(PluginConstants.LOG_TAG,"Icon stored. " + iconFile.getAbsolutePath()); return iconFile.getAbsolutePath(); }
Example 42
From project android-joedayz, under directory /Proyectos/GreenDroid/src/greendroid/widget/item/.
Source file: DrawableItem.java

@Override public void inflate(Resources r,XmlPullParser parser,AttributeSet attrs) throws XmlPullParserException, IOException { super.inflate(r,parser,attrs); TypedArray a=r.obtainAttributes(attrs,R.styleable.DrawableItem); drawableId=a.getResourceId(R.styleable.DrawableItem_drawable,0); a.recycle(); }
Example 43
From project androidquery, under directory /src/com/androidquery/util/.
Source file: RatioDrawable.java

public RatioDrawable(Resources res,Bitmap bm,ImageView iv,float ratio,float anchor){ super(res,bm); this.ref=new WeakReference<ImageView>(iv); this.ratio=ratio; this.anchor=anchor; iv.setScaleType(ScaleType.MATRIX); Matrix m=new Matrix(); iv.setImageMatrix(m); adjust(iv,bm,false); }
Example 44
From project android_packages_apps_CellBroadcastReceiver, under directory /src/com/android/cellbroadcastreceiver/.
Source file: CellBroadcastAlertAudio.java

private static void setDataSourceFromResource(Resources resources,MediaPlayer player,int res) throws java.io.IOException { AssetFileDescriptor afd=resources.openRawResourceFd(res); if (afd != null) { player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); afd.close(); } }