Pradeep's Blog

July 21, 2010

Finding Location (GPS)

Filed under: BlackBerry Sample Code — Pradeep @ 6:25 pm

This class will find the value only once, it will not continuously update the location value.

public class GPSDemo extends UiApplication
{ private MainScreen screen;
private static int _interval = 1;
private LocationProvider _locationProvider;

public static void main(String[] args)
{
new GPSDemo().enterEventDispatcher();
}

// Constructor
public GPSDemo() {
screen = new MainScreen();
screen.add(new LabelField(“Finding Location………”));
if ( startLocationUpdate() == false )
{
System.exit(1);
}
pushScreen(screen);
}

/**
* Call the Next Screen As soon the value is retrieved
*/
private void updateLocationScreen(final String msg)
{
invokeAndWait(new Runnable()
{
public void run()
{
//As soon the longitude and latidue is retrieved the Location Update is
//close and new screen is pushed with the value.
if (msg.length()>0) {
close();
UiApplication.getUiApplication().pushScreen(new DisplayScreen(msg));
}

}
});

}

/**
* Invokes the Location API with the default criteria.
*
*/
private boolean startLocationUpdate()
{
boolean retval = false;

try
{
_locationProvider = LocationProvider.getInstance(null);

if ( _locationProvider == null )
{
Runnable showGpsUnsupportedDialog = new Runnable()
{
public void run() {
Dialog.alert(“GPS is not supported on this platform, exiting…”);
System.exit( 1 );
}
};

invokeLater( showGpsUnsupportedDialog ); // Ask event-dispatcher thread to display dialog ASAP.
}
else
{
_locationProvider.setLocationListener(new LocationListenerImpl(), _interval, 1, 1);
retval = true;
}
}
catch (LocationException le)
{
System.err.println(“Failed to instantiate the LocationProvider object, exiting…”);
System.err.println(le);
System.exit(0);
}
return retval;
}

private class LocationListenerImpl implements LocationListener
{
public void locationUpdated(LocationProvider provider, Location location)
{
if(location.isValid())
{
double longitude = location.getQualifiedCoordinates().getLongitude();
double latitude = location.getQualifiedCoordinates().getLatitude();

StringBuffer sb = new StringBuffer();
sb.append(“Longitude: “);
sb.append(longitude);
sb.append(“\n”);
sb.append(“Latitude: “);
sb.append(latitude);
GPSDemo.this.updateLocationScreen(sb.toString());
}
}

public void providerStateChanged(LocationProvider provider, int newState)
{
// Not implemented.
}
}

public void close()
{
if ( _locationProvider != null )
{
_locationProvider.reset();
_locationProvider.setLocationListener(null, -1, -1, -1);
}
}

July 14, 2010

ButtonField with Image as a BackGround

Filed under: BlackBerry Sample Code — Pradeep @ 11:39 pm

public class CustomSmallButton extends Field {
private Bitmap offPicture;
private Bitmap onPicture ;

public CustomSmallButton(Bitmap onFocous, Bitmap offFocous, long style) {
super(style);
onPicture = onFocous;
offPicture = offFocous;
this.setPadding(5,5, 5, 5);
}

public int getPreferredHeight() {
return onPicture.getHeight();
}

public int getPreferredWidth() {
return onPicture.getWidth();
}

protected void layout(int width , int height) {
setExtent(Math.min(width, getPreferredWidth()), Math.min(height,getPreferredHeight()));
}

protected void drawFocus(Graphics graphics, boolean on) {
// Don’t draw the default focus
}

protected void paint(Graphics graphics) {
/*When button is on focus*/
if (isFocus()) {
graphics.drawBitmap(0, 0, getWidth(), getHeight(),onPicture , 0, 0);
} else {
/*When button is off focus*/
graphics.drawBitmap(0, 0, getWidth(), getHeight(),offPicture , 0, 0);
}
}

public boolean isFocusable() {
return true;
}

protected void onFocus(int direction) {
super.onFocus(direction);
invalidate();
}

protected void onUnfocus() {
super.onUnfocus();
invalidate();
}

protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}

protected boolean keyChar(char character, int status, int time) {
if (character == Keypad.KEY_ENTER) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}

January 20, 2010

V2 SOLUTION APTITUDE PAPER

Filed under: BlackBerry Sample Code — Pradeep @ 3:25 am

As far i Remember these were the following questions:

Qns 1.A length,breadth and height of a room are in the ratio 3:2:1.?if the breadth and height are halved while the length is doubled,
then the total area of the four walls of the room will be?
a.same
b.decrease by 13.64%
c.decrease by 15%
d.decrease by 18.75%
e.decrease by 30%
answer : decrease by 30% (5th option)
Ans: Let Length=3x
Breadth=2x,and
Height=x
Area of the four walls
=2(3x+2x)*x
=10x^2 units
When the breadth and height is halved and the length is doubled
The length,breadth and height of the room becomes 6x,x and x/2 respectively
Area of the four walls
=2(6x+x)*x/2
=7x^2
Therefore the area of the four walls will be reduced by 3/10 or 30%
Qns2:When you reverse the digits of the number 13, the number increases by 18. How many other two digit numbers increase by 18 when their digits are reversed?   5   6   7   8   10
a. 5
b. 6
c. 7
d. 8
e. 10
Answer: 6 (2nd option)
Feedback:
Let ‘ab’ be the two-digit number satisfying the given conditions.
ab + 18 = ba
? 10a + b + 18 = 10b + a
b – a = 2
(a, b) can be (1, 3), (2, 4), (3, 5), (4, 5) (5, 7) (6, 8) or (7, 9)
? 6 other two-digit numbers excluding 13 are possible
Qns 3.There are 6 tasks and 6 persons. Task 1 cannot be assigned either to person 1 or to person 2;
task 2 must be assigned to either person 3 or person 4. Every person is to be assigned one task. In how many ways can the assignment be done?
a. 144
b. 180
c. 192
d. 360
e. 716
Answer: 144 (first option)
Feedback:
Let T1, T2, ……., T6 denote the six tasks and P1, P2,……, P6 denote the six persons, each of whom isassigned a task.
Let us first assign T2 to P3.
As T1 cannot be assigned to P1 or P2, there are only 3 ways of assigning this task, namely P4, P5 or P6.
The rest of the tasks T3, T4, T5 and T6 can be assigned in 4! ways.
Thus, we get 3 × 4! = 72 ways.
Similarly, on assigning T2 to P4, we get 72 ways. Thus, the required number of ways is 72 + 72
= 144.
Qns4. Ques.10: The number of employees in Obelix Menhir Co. is a prime number and is less than 300.
The ratio of the number of employees who are graduates and above, to that of employees who are not, can possibly be (CAT2006)
1. 101:88 2. 87:100 3. 110:111 4.85:98 5.97:84
Answer: 97:84(5th option)
Qns 5.Arun, Barun and Kiranmala start from the same place and travel in the same direction at speeds of 30, 40 and 60 km per hour respectively. Barun starts two hours after Arun. If Barun and Kiranmala overtake Arun at the same instant, how many hours after Arun did Kiranmala start?
a. 3
b. 3.5
c. 4
d. 4.5
e. 5
Answer: 4 (3rd option)
Feedback:
Distance travelled by Arun in the first 2 hours = 60 km
Time taken by Barun to overtake Arun =
60/(40-30)= 6 hours.
Distance travelled by Barun in this time = Distance travelled by Arun up to this time = 240 km
Time taken by Kiranmala to overtake Arun =240/60
= 4
hours
? Kiranmala starts 2 hours after Barun who started 2 hours after Arun.
?Kiranmala must have started 4 hours after Arun.
Choice (3)
Qns 6.A group of 630 children is arranged in rows for a group photograph session. Each row contains three fewer children than the row in front of it
What number of rows is not possible?
A. 3
B. 6
C. 5
D. 4
Answer : 6 (2nd option)
Solution is given in aptitude  pdf
qns 7: there will be a weight question which will be having two sub question whose answer is as follows:
answer 1: 35kg
answer 2: 15kg
qns 8: there will a consecutive number questoin whose answer is as follows:
answer: 41
qns 9: there will be a  venn diagram question whose answer is
answer: 9

Blog at WordPress.com.

Create your own website, free on WordPress.com.Create your own website.
Start free