Friday, October 4, 2013

Handling long string not visible in one entry of list field in Blackberry (show ...@ end)

This code returns string which can be shown in a field having width=width, 5 pixel margin on left and 5 pixel on right.
    private String getTextShown( String completeString, int width ) {
        if ( completeString == null )
            return null;
        width = width - 10;
        Font font = listfield.getFont( );
        if ( font.getAdvance( completeString ) < width )
            return completeString;
        for ( int i = completeString.length( ) - 1; i > 0; i-- ) {
            completeString = completeString.substring( 0, i );
            StringBuffer tempBuffer = new StringBuffer( completeString );
            tempBuffer.append( "..." );
            String temp = tempBuffer.toString( );
            if ( font.getAdvance( temp ) < width ) {
                return temp;
            }
        }
        return completeString;
    }
This can be called from

     protected void paint( Graphics graphics ) {
         String stringToDraw = getTextShown( "This is very long text. this will not fit in one line on the blackberry device", w );
         graphics.drawText( stringToDraw, x, y );
     }

Android aar deployment in Maven - 2022

Introduction If you are working on android library project, you might be wondering how to publish it on Maven like this . Earl...