📄 deliverymidlet.java
字号:
// Copyright 2002 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation.
// Java and all Java-based marks are trademarks or registered trademarks of
// Sun Microsystems, Inc.
// Other product and company names mentioned herein may be trademarks or
// trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
package example.delivery;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.io.IOException;
public class DeliveryMIDlet
extends MIDlet
{
private final HttpPoster httpPoster;
private final StatusScreen statusScreen;
public DeliveryMIDlet()
{
httpPoster = new HttpPoster(getAppProperty("Servlet-URL"));
statusScreen = new StatusScreen(this, httpPoster);
Image errorImage = createImage("/error.png");
ErrorScreen.init(errorImage, Display.getDisplay(this));
}
public void startApp()
{
openRecordStores(); // re-open after pauseApp
Displayable current = Display.getDisplay(this).getCurrent();
if (current == null)
{
Alert splashScreen = new Alert(null, // no title
"Delivery MIDlet",
createImage("/splash.png"),
AlertType.INFO);
splashScreen.setTimeout(2000); // two seconds
// Show the SplashScreen the first time startApp is called.
Display.getDisplay(this).setCurrent(splashScreen, statusScreen);
}
else
{
Display.getDisplay(this).setCurrent(current);
}
}
public void pauseApp()
{
closeRecordStores();
}
public void destroyApp(boolean unconditional)
{
closeRecordStores();
httpPoster.abort(); // stop the networking thread
}
// On exit, cleanup and notify that the MIDlet has been destroyed.
private void quit()
{
destroyApp(false);
notifyDestroyed();
}
private Image createImage(String filename)
{
Image image = null;
try
{
image = Image.createImage(filename);
}
catch (IOException e)
{
// Use a 'null' image instead
}
return image;
}
private void openRecordStores()
{
try
{
Courier.openRecordStore();
DeliveryOrder.openRecordStore();
}
catch (RecordStoreException e)
{
ErrorScreen.showError("RecordStore error: " + e.getMessage());
}
}
private void closeRecordStores()
{
try
{
Courier.closeRecordStore();
DeliveryOrder.closeRecordStore();
}
catch (RecordStoreException e)
{
ErrorScreen.showError("RecordStore error: " + e.getMessage());
}
}
// StatusScreen callbacks
void statusScreenLogin()
{
// The LoginScreen stores used usernames persistently.
// By default, it does not similarly store passwords.
// The 'CanStorePassword' application property is used to indicate
// the remote service's security policy regarding whether the MIDlet
// is allowed to store passwords. (One might also wish to
// explicitly request the user's consent, although this MIDlet
// does not.)
LoginScreen loginScreen = new LoginScreen(this, httpPoster);
String str = getAppProperty("CanStorePassword");
boolean canStorePassword = (str != null && str.equals("true"));
loginScreen.setCanStorePassword(canStorePassword);
Display.getDisplay(this).setCurrent(loginScreen);
}
void statusScreenSetStatus()
{
SetStatusScreen setStatusScreen = new SetStatusScreen(this, httpPoster);
Display.getDisplay(this).setCurrent(setStatusScreen);
}
void statusScreenLogout()
{
LogoutScreen logoutScreen = new LogoutScreen(this, httpPoster);
Display.getDisplay(this).setCurrent(logoutScreen);
}
void statusScreenQuit()
{
quit();
}
// LoginScreen callbacks
void loginScreenDone()
{
statusScreen.beLoggedIn();
Display.getDisplay(this).setCurrent(statusScreen);
}
void loginScreenError(String errorMessage)
{
// Note: the transition to statusScreen occurs after
// the ErrorScreen alert is shown (see method showError).
ErrorScreen.showError(errorMessage, statusScreen);
}
void loginScreenCancel()
{
Display.getDisplay(this).setCurrent(statusScreen);
}
void loginScreenQuit()
{
quit();
}
// LogoutScreen callbacks
void logoutScreenDone()
{
statusScreen.beLoggedOut();
Display.getDisplay(this).setCurrent(statusScreen);
}
void logoutScreenError(String errorMessage)
{
// Note: the transition to statusScreen occurs after
// the ErrorScreen alert is shown (see method showError).
ErrorScreen.showError(errorMessage, statusScreen);
}
void logoutScreenCancel()
{
Display.getDisplay(this).setCurrent(statusScreen);
}
// SetStatusScreen callbacks
void setStatusScreenDone(String status)
{
if (status.equals(DeliveryOrder.OPENED))
{
status = DeliveryOrder.NOJOB;
try
{
DeliveryOrder.getInstance().init();
statusScreen.updateDeliveryOrderItems();
}
catch (RecordStoreException e)
{
ErrorScreen.showError("RecordStore error: " + e.getMessage());
}
}
else
{
statusScreen.updateStatus(status);
statusScreen.updateSetStatusCommand();
}
Display.getDisplay(this).setCurrent(statusScreen);
}
void setStatusScreenError(String errorMessage)
{
// Note: the transition to statusScreen occurs after
// the ErrorScreen alert is shown (see method showError).
ErrorScreen.showError(errorMessage, statusScreen);
}
void setStatusScreenRemoteError()
{
ErrorScreen.showError("Remote error. Use 'Get Job' to sync.",
statusScreen);
try
{
DeliveryOrder.getInstance().init();
if (statusScreen != null)
{
statusScreen.updateDeliveryOrderItems();
}
}
catch (RecordStoreException e)
{
// Note: the transition to statusScreen occurs after
// the ErrorScreen alert is shown (see method showError).
ErrorScreen.showError("RecordStore error: " + e.getMessage(),
statusScreen);
}
}
void setStatusScreenCancel()
{
Display.getDisplay(this).setCurrent(statusScreen);
}
// Callback to handle invalid or expired session for
// 'Get Job', 'Set Status' or 'Logout'...
void anyScreenInvalidSession()
{
statusScreen.beLoggedOut();
String errorMessage = "Invalid or expired session. Please login again.";
// Note: the transition to statusScreen occurs after
// the ErrorScreen alert is shown (see method showError).
ErrorScreen.showError(errorMessage, statusScreen);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -