sábado, 18 de setembro de 2010

Drawing In an Android View

When I was drawing in a view using onDraw method, I noted that if you are drawing a line, the y scale starts at 1px but if you are drawing a text, the scale starts at height of text, i.e. The text have 10px height, you have to specify 10px at y position to display text at top of view. I think the android are drawing the text above the pixel scale. If you specify to draw the text at 1px, it will be drawed starting at -10px. Drawing a bitmap works fine, the top left of the image is x: 0px y: 0px

You can test a lot of scales by putting the above code at onDraw event of a view:

private void printScales(Canvas canvas){
Rect clipBounds = canvas.getClipBounds();
String clip_bounds = Integer.toString(clipBounds.right)+"x"+Integer.toString(clipBounds.bottom)+
" - "+Integer.toString(clipBounds.left) + "x" + Integer.toString(clipBounds.top);
Log.i("clip bounds", clip_bounds);
String canvas_string = Integer.toString(canvas.getWidth())+"x"+Integer.toString(canvas.getHeight());
Log.i("canvas", canvas_string);
String this_string = Integer.toString(getWidth())+"x"+Integer.toString(getHeight())+
" - "+Integer.toString(getLeft()) + "x" + Integer.toString(getTop());
Log.i("this", this_string);
String measured = Integer.toString(getMeasuredWidth())+"x"+Integer.toString(getMeasuredHeight());
String padding = Integer.toString(getPaddingLeft())+
Log.i("padding", padding);
String drawing_rect = Integer.toString(clipBounds.right)+"x"+Integer.toString(clipBounds.bottom)+
" - "+Integer.toString(clipBounds.left) + Integer.toString(clipBounds.top);
Log.i("drawing rect", drawing_rect);

quinta-feira, 9 de setembro de 2010

Android ScrollView Problems

I had some kind of problem when using android:gravity="center" in a TextView inside LinearLayout inside ScrollView and using RelativeLayout too, I just find another way to display contents without using RelativeLayout and TextView with android:gravity="center". The problem was aborting program when layout started, I think in "measure" or "draw" internal methods.
The layout was working fine without the ScrollView, but when I put it outside the main LinearLayout, I had this problems that was so difficult to find and fix.

quarta-feira, 8 de setembro de 2010

My Custom Android View "StarsViewKMB"


This view created by me, allows to set and display stars rates as showing below:

You can enable or disable trackball/touch changes, you can change star type to (leaf, dollar, star), you can allow to cancel (the red icon), you can get and set stars values between 0 and 10, -1 value it's in the cancel case.
Currently do not have the option to resize the pictures, has only two sizes of images. Big (to edit with trackball or touch) and small to display the star value.


setIconType(int value)

Valid values are:


setStars(int value)

Valid values are:

A number between 0 and 10 that allows to change selected stars, -1 it's a special value when cancel is allowed.

setIsDoubleSize(boolean value)

True for big icons, false to small icons.

setAllowCancel(boolean value)

True if allow cancel option, it displays a red icon before stars. False to disable cancel option.

setIsEditable(boolean value)

True if allows the user to change stars value using trackball or touch events. False to not allow user to change stars value.

int getIconType()
boolean isAllowingCancel()
boolean isDoubleSize()
boolean isEditable()
int getStars()

XML Layout Code

You can easily implement the view in your layout using xml code as below:

<kmb.StarsViewKMB android:layout_width="wrap_content"
value="6" />

Creating StarsViewKMB by Code

  • Set the content view.
  • Get the main LinearLayout where you want to put the StarsViewKMB
  • Create the StarsViewKMB object.
  • Configure the view using the custom methods.
  • Add the StarsViewKMB to the main LinearLayout

public void onCreate(Bundle savedInstanceState) {
LinearLayout mainLayout = (LinearLayout)findViewById(R.id.main_layout);

StarsViewKMB starsViewKmb1 = new StarsViewKMB(this);
starsViewKmb1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

StarsViewKMB starsViewKmb2 = new StarsViewKMB(this);
starsViewKmb2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

StarsViewKMB starsViewKmb3 = new StarsViewKMB(this);
starsViewKmb3.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));


About Me

I'm a developer in: Visual Basic, Java, Php, MySQL, MS Access, Excel, Asp, Visual C, QBasic, Ruby On Rails, ActionScript, Flash, CSS, HTML, Javascript. Webmaster, not web designer.



Application that use GPS, Internet Connection, Web format JSON, MVC (Model, View, Controller) in ruby on rails. Image handling, advanced android layouts using images, tabs, images, google maps, custom Views.


Minefield game using high logical programming, Dinamic Array/Draw, handling time, storage data records, sound, images, all game using a customized drawing.
Translator, using simple text file data.


Background running program utility for windows/linux. Using HTTP images, http communications, http text parser, xml file parser. File/Folder handling.

Visual Basic 6

In this language, I have done the most applications in various areas such as:
Internet communications with socket by HTTP Requests, Ftp, SMTP and custom communications IP to IP
Image Editor
Full text macros, automation.
Audio Player, Video Player.
Browser Handling (Internet Explorer)
Custom Objects, DLL, OCX
Fiscal printers communications by COM port
TEF (transferência eletrônica de fundos)
File Handling
MySQL script client
MySQL user administrator client.
A lot of things...


Minefield programa, single proccess thread, so dificult.

Ruby On Rails

Full site development, including e-mail, image features.


Dinamic flash animation.


Simple animations of text, dinamic content, images, sounds.