Fixing “Base SDK Missing”

By Automater on January 6th, 2011
0

Load your project
From the menu, select Project > Edit Project Settings…
Under Architecture > Base SDK, choose one of the available device options: iPhone 3.2 or iPhone 4.0. If you are iPhone-only, 4.0 is the way to go.
Close that window.
From the menu, select Project > Edit Active Target “YourTarget”
Under Architecture > Base SDK, choose one of the available device or simulator options: iPhone 3.2 or iPhone 4.0.
If you want to target previous iOS versions, then in that same window, under Deployment > iPhone OS Deployment Target, select the lowest version you want to support. Note that support for 2.x versions through the app store is deprecated. See the “Readiness Checklist” quote above.

Posted in

How To Uninstall Xcode Completely

By Automater on January 6th, 2011
0

To uninstall developer tools/Xcode type in the following command in the terminal

sudo /Developer/Library/uninstall-devtools –mode=all

But beware, this completely removes Xcode and once it is gone, it’s gone. Of-course you can always reinstall it. So be sure of what you are doing.

Posted in

Using Invoke APIs in your BlackBerry widget

By Automater on December 13th, 2010
0

One feature of Super Apps is that they integrate with the native applications on BlackBerry® smartphones. So, how do you go about doing this? For BlackBerry® Widgets, it’s actually pretty simple. The BlackBerry® Widget API provides the Invoke object, which allows you to design your application to seamlessly work with the other applications on the BlackBerry smartphone. This results in a richer BlackBerry smartphone user experience.

By leveraging the Invoke API, you can invoke virtually any other application on the BlackBerry smartphone through a simple API call, where you’ll set a parameter for the app you want to invoke and then pass in any parameters that application is expecting. Right out of the box, the BlackBerry API contains these APIs to invoke:

• Address Book


• BlackBerry Browser


• Calendar


• Camera


• Maps


• MemoPad


• Email


• Phone


• Search


• Tasks


• Any other Java application on the device


By leveraging these APIs, you can come up with a compelling user story or use case to design your application as a one-stop shop for anyone looking to organize their daily tasks through your app. Open an email, save a meeting invite, set GPS to locate the meeting room, associate tasks with that meeting – these are just a few of the countless ways you can easily leverage the Invoke APIs, taking your BlackBerry Widget to the next level and embracing the Super App concept!

Posted in

Black Berry Splash Screens (By RIM)

By Automater on October 11th, 2010
0

Splash Screen code that I shamelessly copied from Rim website (with a few modifications)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import java.util.*;

public class SplashScreen extends MainScreen {
   private MainScreen next;
   private UiApplication application;
   private Timer timer = new Timer();
   private static final Bitmap _bitmap = Bitmap.getBitmapResource("wm_splash_screen.jpeg");
   public SplashScreen(UiApplication ui, MainScreen next) {
      super(Field.USE_ALL_HEIGHT | Field.FIELD_LEFT);

      this.application = ui;
      this.next = next;
      this.add(new BitmapField(_bitmap,Field.FIELD_HCENTER | Field.FIELD_VCENTER));
      SplashScreenListener listener = new SplashScreenListener(this);
      this.addKeyListener(listener);
      timer.schedule(new CountDown(), 5000);
      application.pushScreen(this);
   }
   public void dismiss() {
      timer.cancel();
      application.popScreen(this);
      application.pushScreen(next);
   }
   private class CountDown extends TimerTask {
      public void run() {
         DismissThread dThread = new DismissThread();
         application.invokeLater(dThread);
      }
   }
   private class DismissThread implements Runnable {
      public void run() {
         dismiss();
      }
   }
   protected boolean navigationClick(int status, int time) {
      dismiss();
      return true;
   }
   protected boolean navigationUnclick(int status, int time) {
      return false;
   }
   protected boolean navigationMovement(int dx, int dy, int status, int time) {
      return false;
   }
   public static class SplashScreenListener implements
      KeyListener {
      private SplashScreen screen;
      public boolean keyChar(char key, int status, int time) {
         //intercept the ESC and MENU key - exit the splash screen

         boolean retval = false;
         switch (key) {
            case Characters.CONTROL_MENU:
            case Characters.ESCAPE:
            screen.dismiss();
            retval = true;
            break;
         }
         return retval;
      }
      public boolean keyDown(int keycode, int time) {
         return false;
      }
      public boolean keyRepeat(int keycode, int time) {
         return false;
      }
      public boolean keyStatus(int keycode, int time) {
         return false;
      }
      public boolean keyUp(int keycode, int time) {
         return false;
      }
      public SplashScreenListener(SplashScreen splash) {
         screen = splash;
      }
   }
}

Now you can go into your entry point class (Class extending UIApplication) and do the following:

1
SplashScreen splashScreen = new SplashScreen(this,mainScreen);
Posted in

How to programmatically send mail in Blackberry

By Automater on October 9th, 2010
0

//Get the Store from the default mail Session.
Store store =  Session.getDefaultInstance().getStore();

//retrieve the sent  folder
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder =  folders[0];

//create a new message and store it in the sent  folder
Message msg = new Message(sentfolder);
Address recipients[] = new  Address[1];

try {
recipients[0]= new Address(“user@company.com”,  “user”);

//add the recipient list to the  message
msg.addRecipients(Message.RecipientType.TO,  recipients);

//set a subject for the  message
msg.setSubject(“Test email”);

//sets the body of the  message
msg.setContent(“This is a test email from my BlackBerry Wireless  Handheld”);

//sets  priority
msg.setPriority(Message.Priority.HIGH);

//send the  message
Transport.send(msg);
}
catch (Exception me)  {
System.err.println(me);
}
Posted in

How to implement a Splash Screen for BlackBerry

By Automater on September 27th, 2010
0

To use the class, extend SplashScreen and pass the image and the seconds to display into the super class:

import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.MainScreen;

public class SplashScreen extends MainScreen {

    Bitmap popup;
    SplashScreen screen = this;
    private Timer splashTimer = new Timer();
    private TimerTask splashTask;
    int count = 0;
    int screenWidth = Display.getWidth();
    int screenHeight = Display.getHeight();
    int yCoord;
    int xCoord;
    boolean showSplash = true;
    boolean splashDisplayed = false;

    public SplashScreen(Bitmap popup, final int seconds) {
        this.popup = popup;
        xCoord = (screenWidth - popup.getWidth()) / 2;
        yCoord = (screenHeight - popup.getHeight()) / 2;

        splashTask = new TimerTask() {

            public void run() {
                if (showSplash && !splashDisplayed) {
                    count++;
                    if (count == seconds * 10) {
                        showSplash = false;
                        splashDisplayed = true;
                        splashTimer.cancel();
                        invalidate();
                    }
                }
            }
        };

        splashTimer.scheduleAtFixedRate(splashTask, 100, 100);

    }

    protected void paint(Graphics graphics) {
        super.paint(graphics);
        if (showSplash && !splashDisplayed) {
            graphics.drawBitmap(xCoord, yCoord, popup.getWidth(), popup.getHeight(), popup, 0, 0);
            //draw border, delete if not needed:
            //graphics.setColor(0xcccccc);
            //graphics.drawRect(xCoord, yCoord, popup.getWidth(), popup.getHeight());
        }
    }

    protected void onUiEngineAttached(boolean attached) {
        showSplash = true;
        invalidate();
        super.onUiEngineAttached(attached);
    }

    //allow user to dismiss splash screen:
    protected boolean navigationMovement(int dx, int dy, int status, int time) {
    	super.navigationMovement(dx, dy, status, time);
        return DismissSplash();
    }

    protected boolean navigationClick(int status, int time) {
    	super.navigationClick(status, time);
        return DismissSplash();
    }

    protected boolean keyChar(char c, int status, int time) {

    	super.keyChar(c, status, time);
        return DismissSplash();
    }

    private boolean DismissSplash() {
        if (showSplash) {
            showSplash = false;
            splashDisplayed = true;
            invalidate();
            return true;
        }else{
            return false;
        }
    }
}

The use of two booleans might seem unnecessary at first but they’re in place to make sure the introduction popup only displays the first time the screen is pushed onto the display stack and not when subsequent screens are popped.

Posted in

How to show a PDF/file in a module as a friendly URL

By Automater on September 13th, 2010
2

I needed a way to show a friendly URL for a PDF buried deep into a module.
The following is courtesy of my friend Deciphered:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$items['module/userguide.pdf'] = array(
    'page callback' => '_module_userguide_link',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

function _module_userguide_link() {
  header('Content-Type: application/pdf');
  header('Cache-Control: public');
  readfile('sites/all/modules/modulename/pdf/userguide.pdf');
}

Thank you Deciphered

Posted in

Handling Drupal forms submission is dead simple. You basically write a three functions: a form generator, a form validator and a form submitter.

The form generator is called everytime the form needs to be built and it can be used to populate fields default values or the values previously entered by the user.

In the form generator you can specify the functions that should be called to validate the form and to submit it (to actually do something with the form values, like adding a new row to a table for instance):

$form['#validate'][] = ‘car_edit_validate’;
$form['#submit'][] = ‘car_edit_submit’;

Where car_edit_validate is the name of the function that will be called to do the validation and car_edit_submit is the function that will be called after the form validates.

Every time you submit the form the validate function is called first and if the validation does not encounter any errors the submit function is called.

The problem I had is that I wanted to return an error and keep the form values if an error occurred in my submit function. By default, after the submit function is called an empty form will be rendered and user entered values will be lost even if you add an error to the form with form_set_error. The error is displayed but this does not prevent the form values from being lost. If you want to keep the form values you must also add this line:

1
$form_state['redirect'] = FALSE;

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function car_edit_submit($form, &$form_state) {
  global $user;
  $car = (object)$form_state['values'];
  $car->uid = $user->uid;
  if(car_save($car)) {
    drupal_set_message(t('car successfully saved')));
    drupal_goto('car/'.$car->cid);
  } else {
    form_set_error('form', t('The car could not be saved, please try again'));
    $form_state['redirect'] = FALSE; //To prevent Drupal from cleaning the form

  }
}
Posted in

Blackberry JDE API – User Interface Field Reference

By Automater on September 9th, 2010
2

When I first dug into programming with the RIM APIs installed with the Blackberry JDE I ran into quite a few roadblocks that took a while to circumvent. Most stemmed from my unfamiliarity with Java and the standard Java UI toolkits (Swing and AWT). After figuring out how to create and display each of the most interesting fields I figured I might as well document them, provide screenshots, and sample application code to help others like myself.

First off for those out there only interested in the download-able code example — here you go. Simply open the FieldExample.jdw workspace in the JDE editor and click Debug -> Go.

The following field objects are found in the net.rim.device.api.ui.component package. These objects are built-in time savers for building GUIs for Blackberry applications. One of the key benefits is that it provides your application with a consistent interface experience which guarantees users will feel right at home. Custom widgets are great and can make your application unique but each has a learning curve which could frustrate users. We’ll start with the easiest and move to the more complex.

Note: The API version pointed to by this article is currently v4.5.0 so all API URLs point there. Please utilize the documentation for the version installed with the development kit. It should be available in the start menu alongside the editor.

NullField

I don’t actually have one of these in the code example since to me they seem completely pointless. I’m sure some programmers rely on them for various weird hacks but for the most part I would avoid them. They are invisible but can have focus.

NullField API reference

SeparatorField

In the standard MainScreen layout it is usually necessary to use these. They are very simple to add and provide a single pixel grey horizontal line on the screen from one side to the other. The general purpose is to separate two sections of UI elements. It is possible to override the drawing behavior and change the color/shape of the line but that is a more advanced topic for a future post.

SeparatorField API reference

1
add(new SeparatorField());

LabelField

This element is essentially a glorified String which knows how to draw itself on the screen. As with all text based Fields you can change the drawing Font and use it as the Screen title. By default this element does not accept focus but as will all Fields you can change this by setting the Field.FOCUSABLE style.

LabelField API reference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// LabelField variations

add(new LabelField("LabelField"));

add(new LabelField("LabelField 2", 0, -1, Field.FIELD_RIGHT));

LabelField lbl = new LabelField("LabelField 3", 0, -1, Field.FIELD_HCENTER);
Font fnt = this.getFont().derive(Font.BOLD | Font.ITALIC);
lbl.setFont(fnt);
add(lbl);

TextField

This class seems to be abstract since it has no constructors listed in the APIs. You can create a TextField but I would avoid it since from everything I have seen it is not used. It is the parent class of RichTextField and BasicEditField which are the fields you should actually use for selectable and editable text respectively.

TextField API reference

RichTextField

TextFields provide the equivalent of standard TextBox from other platforms. Each letter of the text is focusable and selectable. The RichTextField is not editable by default but can made editable by setting the Field.EDITABLE style. The major benefit of using a RichTextField over other text based fields is the configurability of the text formatting. It is quite cumbersome to setup as you can see by the following code example but is handy.

RichTextField API reference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// RichTextField variations

add(new RichTextField("RichTextField"));

String str[] = new String[] {"RichTextField:", "Value"};
int off[] = new int[] {0, str[0].length(), str[0].length() + str[1].length()};
byte attr[] = new byte[] {0, 1};
FontFamily fontfam[] = FontFamily.getFontFamilies();
Font fon[] = new Font[2];
fon[0] = fontfam[0].getFont(FontFamily.SCALABLE_FONT, 16);
fon[1] = fontfam[1].getFont(FontFamily.SCALABLE_FONT, 18);
add(new RichTextField(str[0] + str[1], off, attr, fon, RichTextField.TEXT_ALIGN_HCENTER));

EditField

Pretty much the equivalent of the LabelField but is focusable, selectable and editable. There are some mechanisms included which allow configuration of how the key presses interact with the field but overall it is very simple.

EditField API reference

1
2
3
4
5
6
// EditField

EditField edit = new EditField("Username: ", "");
add(edit);

PasswordEditField

As you might expect this is exactly the same as the EditField but replaces keystrokes with asterisk’s. Both Fields are children of the BasicEditField class. On the Pearl there is a short delay where it shows the actual character before switching it to the asterisk (another benefit of using the built in Fields). Some of the standard features like cut/copy and the auto manipulators are disabled.

PasswordEditField API reference

1
2
3
4
5
6
// PasswordEditField

PasswordEditField pass = new PasswordEditField("Password: ", "");
add(pass);

BitmapField

The BitmapField allows you to add a Bitmap to your application. It can be aligned just like any other field with Field.FIELD_RIGHT or Field.FIELD_HCENTER and additionally can have border padding. I haven’t looked to far into positioning beyond the standard but I will get into more complex layouts in a future post. The Bitmap class can load PNG, GIF or JPEG images along with raw byte data. If you include an image in the project it is automatically added to the .cod file as a resource which can be loaded using getBitmapResource(). When targeting a resource the path begins at the root project level. I’ve made the image focusable just as an example, I belive you can also turn an image into a button.

BitmapField API reference

1
2
3
4
5
6
7
// BitmapField
Bitmap img = Bitmap.getBitmapResource("com/examples/img/rainbow.png");
BitmapField bf = new BitmapField(img, BitmapField.FOCUSABLE);
add(bf);

RadioButtonField

There are the implementation of the standard radio selection object where you put a bunch into a group and then the user can select one (and only one) of those options. If you have a fairly small set of options these can be nicer than a choice field (a.k.a. drop-down list) since a user doesn’t have to click into the list and then pick an option. You must place the RadioButtonField objects into a RadioButtonGroup or an error will occur.

RadioButtonField API reference

1
2
3
4
5
6
7
8
9
10
11
// RadioButtonField (must be part of group)
RadioButtonGroup rgrp = new RadioButtonGroup();
RadioButtonField radio = new RadioButtonField("Radio Button", rgrp, true);
RadioButtonField radio2 = new RadioButtonField("Radio 2", rgrp, false);
add(radio);
add(radio2);

CheckboxField

Again the standard implementation of a checkbox where each is individual and you can check as many as you want. It appears that you are unable to set the checkbox state to other than on or off. Other platforms generally have a third version representing half checked but it appears the user would need to extend this control to provide that functionality.

CheckboxField API reference

1
2
3
4
5
6
7
8
9
// CheckboxField
CheckboxField chk = new CheckboxField("Checkbox 1", true);
CheckboxField chk2 = new CheckboxField("Checkbox 2", false);
add(chk);
add(chk2);

ObjectChoiceField

The object choice field is essentially what most programmers would know as a drop-down box or list. You provide a list of objects that have the toString() method and it uses that to generate the list the user chooses from. Hitting the space key will roll through the options or the user can click to see all options at one is a list (as seen in the screenshot below). These fields are very handy when you have many options to present or when screen space is at a premium (as it is on most options pages).

ObjectChoiceField API reference

1
2
3
4
5
6
7
// ObjectChoiceField
String choicestrs[] = {"Opt 1", "Opt 2", "Opt 3"};
ObjectChoiceField choice = new ObjectChoiceField("Object Choice Field: ", choicestrs, 0);
add(choice);

NumericChoiceField

My only guess is that the RIM developers needed lots of choice fields that were numeric. I’m not sure why but that is the only reason to create this very limited field. It simply creates a standard choice field with numeric choices within the range given in the constructor. You can specify a start number, end number and the increment. For the most part I would recommend just using an ObjectChoiceField since it is more flexible.

NumericChoiceField

1
2
3
4
5
// NumericChoiceField
NumericChoiceField numeric = new NumericChoiceField("Numeric Choice Field: ", 1, 10, 1, 4);
add(numeric);

GaugeField

The gauge is a very handy field which allows you to show a progress bar style value selector. If the ObjectChoiceField wasn’t enough for you never to use NumericChoiceField then perhaps this field could shoulder the load. It can be a straight uneditable field or it can allow focus and edit so the user can change the value. Overall this control is great and would be handy for anybody working on game programming.

GaugeField API reference

1
2
3
4
5
// GaugeField
GaugeField gauge = new GaugeField("Gauge Field: ", 1, 100, 50, Field.EDITABLE | Field.FOCUSABLE);
add(gauge);

DateField

I’ve never actually seen one of these in the standard suite of applications on the blackberry so it took me a bit to figure out how to use it properly. First you get down to the field and click the trackball on it. The appearance of the field will change to be the same as the screenshot below and the date, if not already set, will change to be today. You can then use the trackball to choose the date part and roll through the various dates. When finished click the trackball again to complete. Of all the fields this one has the most configuration options for what I can see. You can choose from many different date input formats and representations, overall it probably needs a full post just for itself.

DateField API reference

1
2
3
4
5
// DateField
DateField dte = new DateField("Date Field: ", Long.MIN_VALUE, DateField.DATE);
add(dte);

ListField

This element is what set me on this project in the first place. I was looking to recreate the Status screen under the Wrench icon which has a list with left and right aligned text. I wanted to make an About screen for my game that included device specs like screen size, etc and figured that would be a good way to lay it out. It certainly wasn’t easy to find out how to do it even after I discovered that ListField was the basis for it. The ListFieldCallback is more complicated than I figure is necessary but the most important part is the drawListRow method. drawText defaults to drawing left aligned text which works for the label of the field and if you add the DrawStyle.RIGHT style it will draw right aligned, voila!

ListField API reference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Listfield (must have a callback)
ListField list = new ListField();
list.setEmptyString("Nothing to see here", DrawStyle.LEFT);
list.setSize(3);
list.setCallback(new TestListCallback());
add(list);

…

final class TestListCallback implements ListFieldCallback {
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
g.drawText("Testing:", 0, y, 0, w);
g.drawText(String.valueOf(index * 111), 0, y, DrawStyle.RIGHT, w);
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return Graphics.getScreenWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return listField.indexOfList(prefix, start);
}
}

ButtonField

The API had to have a button field and here it is but I don’t feel it is very useful overall. I’ve never seen one in use in the applications on the blackberry but I haven’t dug to deeply. Most applications use a ListField for their buttons instead of actual buttons. The FieldChangeListener is used to catch the click event after it is attached to the ButtonField. You can also attach the listener to any Field since the setChangeListener function is in the parent class so you could easily make a BitmapField clickable using this technique.

ButtonField API reference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// ButtonField
ButtonField btn = new ButtonField("myButton");
btn.setChangeListener(new ButtonListener());
add(btn);

…

final class ButtonListener implements FieldChangeListener {
public void fieldChanged(Field field, int context) {
ButtonField btn = (ButtonField) field;
Status.show("Button pressed: " + btn.getLabel());
}
}

Verticle Align with CSS

By Automater on September 6th, 2010
0

Step 1 — One line vertical-align:middle

This one is quite easy. Let’s say you set up a nice graphical container for your text but when you add the text, it just sticks to the top of your container — not a very nice visual effect. To center it vertically, simply specify the line-height for your text the same height as that of the container’s.

Things get a bit more complicated when you have more than one line of text. Stick around and we’ll fix this too.

Step 2 — Multiple lines (one line) vertical-align:bottom

An absolute positioned div inside a relative positioned one can basically be placed anywhere you want inside the parent div. So we’ll just use this setup and absolute position a div with bottom:0 within a relative positioned one. The relative positioned div inherits its height from its parent.

Step 3 — Multiple lines vertical-align:middle

This must be the trickiest part of the vertical-align functionality to be achieved with CSS. If we were to just use the trick from Step2 and set the absolutely aligned div to top:50% or bottom:50%, this would align the top part of the text (or its baseline) at the middle — so its not really middle vertically aligned. We could use the actual vertical-align property but it only works for inline elements, so we should use display:table and display:table-cell for the enclosing divs.

All nice and easy but for one problem: IE — it doesn’t recognize display:table. Nevertheless that shouldn’t stop us. We’ll use this setup and achieve the desired result even though only for last-generation browsers.

So, how can we trick IE in vertically aligning the text? We’ll use its bugs against it. IE has some issues with rendering relative and absolute positioned elements. I won’t go into details on this specific bug right here as I don’t want to complicate things even more. The important thing to remember is the solution to this practical problem: positioning a relative div into an absolute one into a relative one once again. Weird, huh? Let me try and explain a bit better: we already have the relative positioned container from the last setup where we want to vertically align the text. Inside it we’ll place an absolute positioned div at top:50%, and inside this one another div relatively positioned at top:-50%. Ta da! It works even for IE.

So now, let’s combine the two solutions and create one that works on every browser. We’ll use the attributes for the modern browsers in a way that IE can’t read them (with some help from the direct child selector), and then, also add the code for IE.

That’s it. Have fun working with vertical align and CSS layouts, and always remember: there’s not been yet a layout that couldn’t be coded with CSS.

Posted in
Tags