quinta-feira, 2 de fevereiro de 2012

Having trouble with rails sunspot and tomcat solr using utf-8 searches?

If after setting tomcat Connector using URIEncoding="UTF-8" didn't work, try this in rails application:

create a file like this name:
config/initializers/monkey_patch_sunspot_solr.rb

Put this code:
module Sunspot
module Search
class AbstractSearch
# Fix utf-8 trouble in search with solr, tomcat and sunspot_solr by Klaus Magalhaes
def execute
reset
params = @query.to_params
save_ferris = {:data => params, :headers => {'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'}}
@solr_result = @connection.post "#{request_handler}", save_ferris
self
end
end
end
end

restart the rails application and cross your fingers...

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());
Log.i("measured",measured);
String padding = Integer.toString(getPaddingLeft())+
"x"+Integer.toString(getPaddingTop())+
"x"+Integer.toString(getPaddingRight())+
"x"+Integer.toString(getPaddingBottom());
Log.i("padding", padding);
getDrawingRect(clipBounds);
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);
Log.i("finished","here");
}

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"

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.

Methods

setIconType(int value)

Valid values are:

StarsViewKMB.ICON_TYPE_STAR
StarsViewKMB.ICON_TYPE_DOLLAR
StarsViewKMB.ICON_TYPE_LEAF

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"
android:layout_height="wrap_content"
android:visibility="visible"
android:paddingTop="5px"
android:paddingBottom="5px"
doubleSize="true"
allowCancel="false"
editable="false"
iconType="0"
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) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout mainLayout = (LinearLayout)findViewById(R.id.main_layout);

StarsViewKMB starsViewKmb1 = new StarsViewKMB(this);
starsViewKmb1.setIsDoubleSize(false);
starsViewKmb1.setStars(3);
starsViewKmb1.setIconType(StarsViewKMB.ICON_TYPE_STAR);
starsViewKmb1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

StarsViewKMB starsViewKmb2 = new StarsViewKMB(this);
starsViewKmb2.setIsDoubleSize(false);
starsViewKmb2.setStars(2);
starsViewKmb2.setIconType(StarsViewKMB.ICON_TYPE_DOLLAR);
starsViewKmb2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

StarsViewKMB starsViewKmb3 = new StarsViewKMB(this);
starsViewKmb3.setIsDoubleSize(false);
starsViewKmb3.setStars(1);
starsViewKmb3.setIconType(StarsViewKMB.ICON_TYPE_LEAF);
starsViewKmb3.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

mainLayout.addView(starsViewKmb1);
mainLayout.addView(starsViewKmb2);
mainLayout.addView(starsViewKmb3);
}

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.

Java

Android

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.

MIDP

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.

Desktop

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...

QBasic

Minefield programa, single proccess thread, so dificult.

Ruby On Rails

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

ActionScript

Dinamic flash animation.

Flash

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