User Code List
All my code
---Android
------Sending SMS using Intents
------Send email attachment
------read file from sdcard
------get size of screen
------Accelerometer in Android OS 2.x and deprecated API
------Getting Animation Drawables to actually Animate
------hide the status bar and title bar
------Email, send intent
------wifi scanner
---------New Snippet
------scrollable tabhost
------bluring windows when dialog shows up
------Animated activity transition, diagonal slide
------simple way to scale image
------monitor outgoing phone call
------add directory in sdcard
------EditTextPreference only numbers
------MapView, LongPress, GestureDetector, OnTouchListener
------Preference Screen with custom views
------write and read data from file
------background without stretching
------System setting, change and write_settings
------Creating Persistent AlertDialog for on Orientation Change
------print from Android application
------Screen in landscape mode
------add contact photo to your list
------Distance calculation between 2 Geopoint by Haversine formula
---Iphone
------get iphone orientation
------generate pdf from iphone
------new thread autorelease pool
------determine firmware version
------turn page animation
------load resource file to webview
------call javascript in Objective-C code
------call objective-C code from Javascript
------Disable Webview selection flash
------Disable the action popup
------Disable webview zoom effect
---Utilities
------recursive remove .svn directory
New Snippet
 
 
print from Android application
 

The "Send 2 Printer" application hooks into existing applications to

enable printing but you can also send the following data formats to

Send 2 Printer for printing from your own applications:

- HTML content

- Text

- Image

- Canvas draw commands (via serialized Picture)

- Canvas draw commands rendered to a Bitmap

For example:

Java:

void printCanvasExample()

{

// create canvas to render on

Picture picture = new Picture();

Canvas c = picture.beginRecording( 240, 240 );

// fill background with WHITE

c.drawRGB( 0xFF, 0xFF, 0xFF );

// draw text

Paint p = new Paint();

Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);

p.setTextSize( 18 );

p.setTypeface( font );

p.setAntiAlias(true);

Rect textBounds = new Rect();

p.getTextBounds( HELLO_WORLD, 0, HELLO_WORLD.length(), textBounds );

int x = (c.getWidth() - (textBounds.right-textBounds.left)) / 2;

int y = (c.getHeight() - (textBounds.bottom-textBounds.top)) / 2;

c.drawText( HELLO_WORLD, x, y, p );

// draw icon

Bitmap icon = BitmapFactory.decodeResource( getResources(), R.drawable.icon );

c.drawBitmap( icon, 0, 0, null );

// stop drawing

picture.endRecording();

// queue canvas for printing

File f = PrintUtils.saveCanvasPictureToTempFile( picture );

if( f != null )

{

PrintUtils.queuePictureStreamForPrinting( this, f );

}

}

The following post contains sample code to print the above formats and

include a sample "Test Print" eclipse project:

http://hit-mob.com/forums/viewtopic.php?f=13&t=66

More information about the "Send 2 Printer" application:

http://hit-mob.com/forums/viewtopic.php?f=13&t=58

 
Sub-Article List