I was wondering if there was any way to make an ApplicationMenuItem inside the message edit screen that, when selected sends the message to the selected contacts itself, bypassing the default sending program. I am fine with the menu item and have seen how to do similar things by retrieving the 'context' argument but I'm not sure how I would get the message body and contacts that were selected.
In ApplicationMenuItem of message edit context will be an instance of net.rim.blackberry.api.mail.Message
See code:
package so.samples;
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MessageArguments;
import net.rim.blackberry.api.mail.Address;
import net.rim.blackberry.api.mail.Message;
import net.rim.blackberry.api.mail.MessagingException;
import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
public class SOComposeMsgMenuApp extends UiApplication {
public static void main(String[] args) {
(new SOComposeMsgMenuApp()).enterEventDispatcher();
}
public SOComposeMsgMenuApp() {
ApplicationMenuItem emailMenuItem = new ApplicationMenuItem(0) {
public Object run(final Object context) {
if (context instanceof Message) {
StringBuffer text = new StringBuffer("Message \nTo:\n");
Message msg = (Message) context;
Address[] to = new Address[] {};
try {
to = msg.getRecipients(Message.RecipientType.TO);
} catch (MessagingException e) {
}
for (int i = 0; i < to.length; i++) {
text.append(to[i].toString());
text.append("\n");
}
text.append("Body:\n");
text.append(msg.getBodyText());
Dialog.inform(text.toString());
}
return context;
}
public String toString() {
return "My Menu Item";
}
};
ApplicationMenuItemRepository amir = ApplicationMenuItemRepository
.getInstance();
amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_EMAIL_EDIT,
emailMenuItem);
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
new MessageArguments(MessageArguments.ARG_NEW, "", "testing",
"just trying to test menu item from compose screen"));
}
}
Related
Hi can you please tell me which is a better approach while getting data from server and displaying on a list?
package mypackage;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.io.IOUtilities;
import net.rim.device.api.ui.component.Dialog;
public class ConnectJson extends Thread {
private String url;
public String response;
private String myinterface = ";deviceside=true";
private JsonObserver observer;
public void run() {
HttpConnection conn = null;
InputStream in = null;
int code;
try {
conn = (HttpConnection) Connector.open(this.url + this.myinterface, Connector.READ);
conn.setRequestMethod(HttpConnection.GET);
code = conn.getResponseCode();
System.out.println("naveen-------------------------");
if (code == HttpConnection.HTTP_OK) {
in = conn.openInputStream();
byte[] buffer = IOUtilities.streamToBytes(in);
this.response = new String(buffer,"UTF-8");
if (observer != null) {
observer.onResponseReceived(this.response);
}
if (in != null){
in.close();
}
if (conn != null){
conn.close();
}
}
} catch (Exception e) {
Dialog.inform(e.toString());
}
}
public String jsonResult(String url){
this.url = url;
this.start();
// this.run();
return response;
}
public void setObserver(JsonObserver o) {
this.observer = o;
}
}
package mypackage;
import java.util.Vector;
import xjson.me.JSONArray;
import xjson.me.JSONException;
import xjson.me.JSONObject;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class MyScreen extends MainScreen implements JsonObserver
{
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
ConnectJson connectJson = new ConnectJson();
System.out.println("------------------");
connectJson.setObserver(this);
connectJson.jsonResult("http://musicbrainz.org/ws/2/release/59211ea4-ffd2-4ad9-9a4e-941d3148024a?inc=artist-credits+labels+discids+recordings&fmt=json");
System.out.println("---------bbbbb---------");
}
public void onResponseReceived(String response) {
System.out.println("000000000000000000000000000000000"+response);
// TODO: create or update your ListField here!!!
}
}
package mypackage;
public interface JsonObserver {
public void onResponseReceived(String response);
}
Well, first of all, this will not work:
public String jsonResult(String url){
this.url = url;
this.start();
return response;
}
Calling start() will cause run() to be called on a background thread (that's good). However, immediately after you start the background thread, you return the response member variable. That won't work, because the run() method hasn't had time to actually assign the response variable.
What you need to do is assign the response variable at the end of the run() method, and then notify the UI on the main/UI thread, to let it update the user interface. Something like this:
if (code == HttpConnection.HTTP_OK) {
in = conn.openInputStream();
byte[] buffer = IOUtilities.streamToBytes(in);
this.response = new String(buffer,"UTF-8");
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
// this code is run on the main/UI thread
if (observer != null) {
observer.onResponseReceived(this.response);
}
}
});
where you add a new observer interface
public interface JsonObserver {
public void onResponseReceived(String response);
}
and then you can let your MainScreen implement that interface:
public class MyScreen extends MainScreen implements JsonObserver {
public MyScreen()
{
connectJson.setObserver(this);
// start the json request
connectJson.jsonResult("http://musicbrainz.org/ws/2/release/59211ea4-ffd2-4ad9-9a4e-941d3148024a?inc=artist-credits+labels+d...");
}
public void onResponseReceived(String response) {
System.out.println("000000000000000000000000000000000"+response);
// TODO: create or update your ListField here!!!
}
Of course, you'll need a new member and method in the ConnectJson class, too:
private JsonObserver observer;
public void setObserver(JsonObserver o) {
observer = o;
}
Note: it also might be better, for thread safety, to change your response member variable to a simple local final variable. I can't know all the ways that you plan on using it, but if it's just a way to hold onto the JSON response, you probably don't need a member variable. Try this instead (inside of run()):
final String response = new String(buffer,"UTF-8");
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
observer.onResponseReceived(response);
I'm trying to popup a global dialog from a background thread that I started from an alternate entry point.
public static void main(String[] args) {
MyApp theApp = new MyApp();
if (args != null && args.length > 0 && args[0].equals("test")) {
new Thread(new Runnable() {
public void run() {
try {
synchronized (UiApplication.getEventLock()) {
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, "Test", Dialog.OK,
Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),
Manager.VERTICAL_SCROLL);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_MODAL);
}
} catch (Exception e) {
System.out.println(e.toString());
}
}
}).start();
} else {
theApp.enterEventDispatcher();
}
}
I tried so many variations to make it work but it's still not showing up. I tried
synchronizing Application.getEventLock(), I also tried
UiApplication.getUiApplication().invokeLater,
UiApplication.getUiApplication().invokeAndWait. I even tried synchronizing the eventlock first before calling the invokeLater (which I think is redundant, but I still tried...). I'm not sure what I'm doing wrong.
okk i am giving you a sample demo ....
First of all edit the BlackBerry_App_Descriptor.xml click on Application Tab
In ApplicationArgument write alternate and check Auto Run on start up
Click on Alternate Entry Points click on add and write in the title BackgroundApp
Make a class which will extend Application class rather than UiApplication class like this way
import net.rim.device.api.system.Alert;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiEngine;
import net.rim.device.api.ui.component.Dialog;
public class BackGroundApp extends Application {
// this class is used for the background processing .....
public void startBackgroundThread()
{
new Thread(){
public void run() {
while (true) {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (getEventLock()) {
//with this UiEngine pushGlobal dialogs
//whenever with the app in background
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, "You have updates!",
Dialog.OK, Bitmap
.getPredefinedBitmap(Bitmap.EXCLAMATION),
Manager.VERTICAL_SCROLL);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
}
}
}
}.start();
}
}
Make a class which will extend UiApplication class like this way
public class GuiTest extends UiApplication {
static Timer t;
public static void main(String[] args) {
if(args.length>0&&"alternate".equals(args[0])){
BackGroundApp app = new BackGroundApp();
app.startBackgroundThread();
app.enterEventDispatcher();
}
else{
GuiTest test = new GuiTest();
test.enterEventDispatcher();
}
}
public GuiTest(){
Myscreen screeMyscreen = new Myscreen();
pushScreen(screeMyscreen);
}
}
Now make a class MyScreen and add all your Ui in it .... and push the screen
public class Myscreen extends MainScreen {
public Myscreen(){
CreateGui();
}
public void CreateGui(){
// Your Ui goes here .......
}
}
run the sample you will see after one minute a dialog will appear on your screen no matter if you are in the application or out side of it. Thanks may be this might be help full.
I have a web service that accepts a username and password and if the login credentials are correct, it returns the user's name, status, image and last known gps coordinates.
As for now I am stuck in the "login" button where the application neither proceeds nor throws any error. Simulator produces no result and I am unable to load the app on to my handset.
package mypackage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.rmi.RemoteException;
import java.util.Hashtable;
import javacard.framework.UserException;
import javax.microedition.io.HttpConnection;
import javax.microedition.location.Location;
import javax.microedition.location.LocationProvider;
import org.kobjects.base64.Base64;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.component.pane.TitleView;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.image.Image;
public class LoginTest extends UiApplication
{
public static void main(String[] args)
{
//Create a new instance of the app
//and start the app on the event thread.
LoginTest app = new LoginTest();
app.enterEventDispatcher();
}
public LoginTest()
{
//Display a new screen.
pushScreen(new LoginTestScreen());
}
}
//Create a new screen that extends MainScreen and provides
//behaviour similar to that of other apps.
final class LoginTestScreen extends MainScreen
{
//declare variables for later use
private InfoScreen _infoScreen;
private ObjectChoiceField choiceField;
private int select;
BasicEditField username;
PasswordEditField passwd;
CheckboxField checkBox1;
ButtonField loginBtn;
Hashtable persistentHashtable;
PersistentObject persistentObject;
static final long KEY = 0x9df9f961bc6d6baL;
// private static final String URL="http://prerel.track24elms.com/Android/T24AndroidLogin.asmx";
String strResult;
public LoginTestScreen()
{
//Invoke the MainScreen constructor.
super();
//Add a screen title.
setTitle("Track24ELMS");
LabelField login = new LabelField("ELMS Login", LabelField.FIELD_HCENTER);
login.setFont(Font.getDefault().derive(Font.BOLD, 30));
login.setMargin(10, 0, 20, 0); //To leave some space from top and bottom
HorizontalFieldManager user = new HorizontalFieldManager();
user.setMargin(0, 0, 10, 0);
HorizontalFieldManager pass = new HorizontalFieldManager();
pass.setMargin(0, 0, 20, 0);
HorizontalFieldManager checkbox = new HorizontalFieldManager();
checkbox.setMargin(0, 0, 30, 0);
HorizontalFieldManager btns = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
LabelField usernameTxt = new LabelField("Username :");
LabelField passwordTxt = new LabelField("Password :");
username = new BasicEditField();
passwd = new PasswordEditField();
loginBtn = new ButtonField("Login", ButtonField.CONSUME_CLICK);
// btn.setChangeListener(new view listener);
//checkBox1 = new CheckboxField("Remember me", false,Field.FOCUSABLE);
checkBox1 = new CheckboxField("Remember me",false);
user.add(usernameTxt);
user.add(username);
pass.add(passwordTxt);
pass.add(passwd);
//checkbox.add(checkBox1);
btns.add(loginBtn);
add(login);
add(user);
add(pass);
add(checkBox1);
add(btns);
// loginBtn.setChangeListener(btnlistener);
}
public void saveChecked() {
persistentHashtable.put("", username.getText());
persistentHashtable.put("", passwd.getText());
persistentHashtable.put("BoolData", new Boolean(checkBox1.getChecked()));
persistentObject.commit();
}
FieldChangeListener btnlistener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
//Open a new screen
String uname = username.getText();
String pwd = passwd.getText();
//If there is no input
if (uname.length() == 0 || pwd.length()==0) {
Dialog.alert("One of the textfield is empty!");
} else {
final String METHOD_NAME = "ValidateCredentials";
final String NAMESPACE = "http://tempuri.org/";
final String SOAP_ACTION = NAMESPACE + METHOD_NAME;
final String URL = "http://prerel.track24elms.com/Android/T24AndroidLogin.asmx";
SoapObject resultRequestSOAP = null;
HttpConnection httpConn = null;
HttpTransport httpt;
System.out.println("The username" + uname + "password" + pwd );
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//String usernamecode = Base64.encode(username.getBytes());
//String pwdEncodeString = Base64.encode(passwd.getBytes());
request.addProperty("Username", "abc");//First parameter is tag name provided by web service
request.addProperty("Password", "xyz");
System.out.println("The request is=======" + request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(request);
System.out.println("The envelope has the value++++"+ envelope.toString());
/* URL+ Here you can add paramter so that you can run on device,simulator etc. this will work only for wifi */
httpt = new HttpTransport(URL+ ";deviceside=true;ConnectionUID=S TCP-WiFi");
httpt.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
httpt.debug = true;
try
{
System.out.println("SOAP_ACTION == " + SOAP_ACTION);
httpt.call(SOAP_ACTION, envelope);
System.out.println("the tranport" + httpt.toString());
resultRequestSOAP = (SoapObject) envelope.bodyIn;
System.out.println("result == " + resultRequestSOAP);
}
catch (IOException e) {
System.out.println("The exception is IO==" + e.getMessage());
} catch (XmlPullParserException e) {
System.out.println("The exception xml parser example==="
+ e.getMessage());
}
System.out.println( resultRequestSOAP);
UiApplication.getUiApplication().pushScreen(new InfoScreen()); //Open a new Screen
}
}
};
//To display a dialog box when a BlackBerry device user
//closes the app, override the onClose() method.
public boolean onClose()
{
if(checkBox1.equals("true"))
{
persistentObject = PersistentStore.getPersistentObject(KEY);
if (persistentObject.getContents() == null) {
persistentHashtable = new Hashtable();
persistentObject.setContents(persistentHashtable);
}
else {
persistentHashtable = (Hashtable)persistentObject.getContents();
}
if (persistentHashtable.containsKey("EditData")) {
username.setText((String)persistentHashtable.get("EditData"));
}
if (persistentHashtable.containsKey("BoolData")) {
Boolean booleanObject = (Boolean)persistentHashtable.get("BoolData");
checkBox1.setChecked(booleanObject.booleanValue());
if(booleanObject.booleanValue()==true){
saveChecked();
}
}
}
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
//Create a menu item for BlackBerry device users to click to see more
//information about the city they select.
private MenuItem _viewItem = new MenuItem("More Info", 110, 10)
{
public void run()
{
//Store the index of the city the BlackBerry device user selects
select = choiceField.getSelectedIndex();
//Display a new screen with information about the
//city the BlackBerry device user selects
_infoScreen = new InfoScreen();
UiApplication.getUiApplication().pushScreen(_infoScreen);
}
};
//Create a menu item for BlackBerry device users to click to close
//the app.
private MenuItem _closeItem = new MenuItem("Close", 200000, 10)
{
public void run()
{
onClose();
}
};
//To add menu items to the menu of the app,
//override the makeMenu method.
//Create an inner class for a new screen that displays
//information about the city a BlackBerry device user selects.
private class InfoScreen extends MainScreen
{
public InfoScreen()
{
super();
setTitle("Itinerary");
LabelField login = new LabelField("Employee Itinerary", LabelField.FIELD_HCENTER);
Bitmap bitmap = Bitmap.getBitmapResource("img1.jpg");
EditField statusMsg = new EditField("Status Message", "Update status here");
}
}
}
In the code you posted, nothing is ever setup to respond to your login button being pressed.
First of all, let's remove this anonymous class that implements FieldChangeListener:
FieldChangeListener btnlistener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
and make it like this:
private class LoginButtonListener implements FieldChangeListener {
public void fieldChanged(Field field, int context) {
// no change to the content of this method!
}
}
and in the constructor for LoginTestScreen, instantiate it, and hook it up to the login button:
loginBtn = new ButtonField("Login", ButtonField.CONSUME_CLICK);
loginBtn.setChangeListener(new LoginButtonListener());
it looks like you were close, in the commented out code. Just needed a little more. Try that, and report back!
Note: you could make it work with the anonymous button listener class you originally had. I just don't like the readability of anonymous classes when they get that big, especially since your btnListener member was declared in a totally different place than all your other ones. The real missing piece was the call to setChangeListener. I just wanted to differentiate what I'm recommending, from what's needed.
Plz give the code or function how to clear the ListField and update the ListField .
Suppose i want to display some multiple text( Project Name, Project Manager )extracted from JSON object , in a ListField.
I am able to display this strings in the ListField but one more feature i need to add ie.. above the ListField there should be a ButtonField and when the user clicks on the ButtonField the ListField should display the string in sorted manner base on Project Name. So i need to clear the ListField
Code for NetworkingMainScreen is
package src1;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import java.util.Vector;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.UiApplication;
class NetworkingMainScreen extends MainScreen
{
private EditField urlField;
private BitmapField imageOutputField;
private RichTextField textOutputField;
private ListField prjctlist_Field;
private Vector prjct_list_v = new Vector();
VerticalFieldManager vfm;
private String prjts;
public int total_prjcts;
JSONArray data_json_array;
JSONObject outer;
ListField myList;
private Vector v_prj_title;
private Vector v_prj_mgr;
private Vector send_vector;
private Vector send_vector3;
private Vector send_vector4;
private String t1,t2;
public JSONArray jsArrPrjts;
ListCallBack callback;
ButtonField sort;
NetworkingMainScreen()
{
// Screen2 s = new Screen2();
// UiApplication.getUiApplication.pushScreen(s);
setTitle("Networking");
urlField = new EditField("URL:", "http://iphone.openmetrics.com/apps/mattson/api.html?action=login&user=Nathan&password=coffee00&server=exp.lcgpence.com;deviceside=true");
textOutputField = new RichTextField();
imageOutputField = new BitmapField();
add(urlField);
add(new SeparatorField());
add(new LabelField("Text retrieved:"));
add(textOutputField);
myList = new ListField();
callback = new ListCallBack();
myList.setRowHeight(80);
myList.setCallback(callback);
add(myList);
}
protected void makeMenu(Menu menu, int instance)
{
super.makeMenu(menu, instance);
menu.add(new MenuItem("Get", 10, 10) {
public void run() {
getURL();
}
});
}
private void getURL()
{
HttpRequestDispatcher dispatcher = new HttpRequestDispatcher(urlField.getText(),"GET", this);
dispatcher.start();
}
public void requestSucceeded(byte[] result, String contentType)
{
if (contentType.startsWith("text/")) {
synchronized (UiApplication.getEventLock())
{
String strResult = new String(result);
try
{
JSONObject joPrjt = new JSONObject(strResult);
String res_code = joPrjt.optString("responseCode");
if( res_code.equals("1"))
{
data_json_array = new JSONArray();
data_json_array = joPrjt.optJSONArray("data");
int s = data_json_array.length();
v_prj_title = new Vector();
v_prj_mgr = new Vector();
outer = new JSONObject();
for(int i=0; i<s; i++)
{
//outer = new JSONObject();
outer = data_json_array.getJSONObject(i);
String job_no = outer.optString("job_number");
String contract_date = outer.optString("contract_date");
String project_title = outer.optString("project_title");
String project_manager = outer.optString("project_manager");
String created_date = outer.optString("created_date");
String project_name = outer.optString("project_name");
v_prj_title.addElement(project_title);
v_prj_mgr.addElement(project_manager);
}
UiApplication.getUiApplication().pushScreen(new Screen2(v_prj_title,v_prj_mgr,0,v_prj_title,v_prj_mgr));
}
else
{
Dialog.alert("Web page connected but not the requested page");
}
}
catch(JSONException e)
{
e.printStackTrace();
System.out.println("key not found catched " + e);
}
}
}
else
{
synchronized (UiApplication.getEventLock()) {
Dialog.alert("Unknown content type: " + contentType);
}
}
}
public void requestFailed(final String message)
{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("Request failed. Reason: " + message);
}
});
}
}
Code for Screen2 is
package src1;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import java.util.Vector;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
class Screen2 extends MainScreen implements FieldChangeListener
{
JSONArray j_array;
JSONObject j_object;
CustomButtonField bf1;
Vector v_prj_title,v_prj_mgr,v_job_no,v_created_date,v_prj_name,send_vector;
Vector main_v_prj_title,main_v_prj_mgr;
String job_no,contract_date,project_title,project_manager,created_date,project_name;
VerticalFieldManager vfm;
ListField myList;
ListCallBack callback;
int pic_status;
int b;
String t1,t2;
String temp1,temp2,f1,f2;
// ListField prjctlist_Field;
Screen2(Vector v_prj_title2,Vector v_prj_mgr2,int pic_status,Vector main_v_prj_title_o2,Vector main_v_prj_mgr_o2)
{
this.main_v_prj_title = main_v_prj_title_o2;
this.main_v_prj_mgr = main_v_prj_mgr_o2;
this.v_prj_title = v_prj_title2;
this.v_prj_mgr = v_prj_mgr2;
this.pic_status = pic_status;
bf1 = new CustomButtonField("Name",pic_status,0);
bf1.setChangeListener(this);
vfm = new VerticalFieldManager();
vfm.add(bf1);
int s = v_prj_title.size();
myList = new ListField();
callback = new ListCallBack();
myList.setRowHeight(80);
myList.setCallback(callback);
for(int i=0;i<s;i++)
{
myList.insert(i);
t1 = v_prj_title.elementAt(i).toString();
send_vector = new Vector(2);
send_vector.addElement(t1);
t2 = v_prj_mgr.elementAt(i).toString();
send_vector.addElement(t2);
callback.insert(send_vector,i);
}
vfm.add(myList);
add(vfm);
}
public void fieldChanged(Field field, int context)
{
if(field == bf1)
{
if(pic_status == 0)
{
b =1;
int s = v_prj_title.size();
for(int i=0;i<s;i++)
{
for(int t=i+1;t<s;t++)
{
temp1 = (String)v_prj_title.elementAt(i);
temp2 = (String)v_prj_title.elementAt(t);
if(temp1.compareTo(temp2)>0)
{
//System.out.println("Comparision Executed :"+temp1 + " is greater than " + temp2);
f1 = (String)v_prj_mgr.elementAt(i);
f2 = (String)v_prj_mgr.elementAt(t);
v_prj_title.setElementAt(temp1,t);
v_prj_title.setElementAt(temp2,i);
v_prj_mgr.setElementAt(f1,t);
v_prj_mgr.setElementAt(f2,i);
}
}
}
UiApplication.getUiApplication().pushScreen(new Screen2(main_v_prj_title,main_v_prj_mgr,b,main_v_prj_title,main_v_prj_mgr));
}
if(pic_status == 1)
{
b=0;
UiApplication.getUiApplication().pushScreen(new Screen2(main_v_prj_title,main_v_prj_mgr,b,main_v_prj_title,main_v_prj_mgr));
}
}
}
}
one more thing i need to clearify is that in my above code firstly i have parsed the JSON object in NetworkingMainScreen and if the JSON parsing is success i have push a new screen name Screen2 passing the stored Vector to the Screen2. The Screen2 performs ListField drawings or should i perform the ListField drawing in NetworkingMainScreen class only.
For details about the items i need to display plz look **http://iphone.openmetrics.com/apps/mattson/api.html?action=login&user=Nathan&password=coffee00&server=exp.lcgpence.com&output=data**
Implement ListFieldCallback in your screen, you can then handle the drawing of your rows however you want in drawListRow.
how to make a call from menu item appended in native book of BB('Call from ABC' option)?
Initiate call programmatically
For RIM OS 4.7 and lower use Invoke:
PhoneArguments phoneArgs = new PhoneArguments(PhoneArguments.ARG_CALL,
"555-5555");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, phoneArgs);
For RIM OS 5.0 declared we can use Phone.initiateCall method:
Phone.initiateCall(Phone.getLineIds()[0], "519-555-0100");
See Make a call from a BlackBerry device application (multi-line environment)
Add custom menu item to BlackBerry application
To add your "Call via ABC" item to address book menu we need to do following:
implement custom item as an extension to ApplicationMenuItem
add instance of custom item to menu using ApplicationMenuItemRepository
before deploying to the real device, don't forget to sign your code (may take up to 2 weeks)
Now, implementing custom menu item:
class AdressBookMenuItem extends ApplicationMenuItem {
Contact mContact;
public AdressBookMenuItem(int order) {
super(order);
}
public Object run(Object context) {
if (context instanceof Contact) {
mContact = (Contact) context;
if (0 < mContact.countValues(Contact.TEL)) {
String phone = mContact.getString(Contact.TEL, 0);
PhoneArguments args = new PhoneArguments(
PhoneArguments.ARG_CALL, phone);
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);
} else {
Dialog.alert("This contact has no phone number");
}
}
return null;
}
public String toString() {
return "Call via ABC";
}
}
Now add it to the address book:
AdressBookMenuItem menuItem = new AdressBookMenuItem(0);
ApplicationMenuItemRepository repository =
ApplicationMenuItemRepository.getInstance();
long id = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST;
repository.addMenuItem(id, menuItem);
Putting All Together
Run application
Press Call button
Select contact
Open menu
You should see
address book menu http://img9.imageshack.us/img9/8175/callviaabc.png
Tested on Bold 9000 simulator
Full code:
import javax.microedition.pim.Contact;
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.PhoneArguments;
import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class CallIntegrate extends UiApplication {
public CallIntegrate() {
pushScreen(new Scr());
}
public static void main(String[] args) {
CallIntegrate app = new CallIntegrate();
app.enterEventDispatcher();
}
}
class AdressBookMenuItem extends ApplicationMenuItem {
Contact mContact;
public AdressBookMenuItem(int order) {
super(order);
}
public AdressBookMenuItem(Object context, int order) {
super(context, order);
}
public Object run(Object context) {
if (context instanceof Contact) {
mContact = (Contact) context;
if (0 < mContact.countValues(Contact.TEL)) {
String phone = mContact.getString(Contact.TEL, 0);
PhoneArguments args = new PhoneArguments(
PhoneArguments.ARG_CALL, phone);
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);
} else {
Dialog.alert("This contact has no phone number");
}
}
return null;
}
public Contact getContact() {
return mContact;
}
public String toString() {
return "Call via ABC";
}
}
class Scr extends MainScreen {
public Scr() {
super(DEFAULT_MENU|DEFAULT_CLOSE);
String label = "Now please go to blackberry adressbook, "
+ "select contact and open menu";
add(new LabelField(label));
AdressBookMenuItem menuItem = new AdressBookMenuItem(0);
ApplicationMenuItemRepository repository =
ApplicationMenuItemRepository.getInstance();
long id = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST;
repository.addMenuItem(id, menuItem);
}
}