-
-
Save anta40/20aa2b9d84e7fbdd2b41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.durianapp.kertasdanlakban; | |
import net.rim.device.api.ui.UiApplication; | |
public class Lakban extends UiApplication { | |
public Lakban() { | |
pushScreen(new LakbanScreen()); | |
} | |
public static void main(String[] args) { | |
new Lakban().enterEventDispatcher(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.durianapp.kertasdanlakban; | |
import net.rim.device.api.system.Bitmap; | |
import net.rim.device.api.ui.Field; | |
import net.rim.device.api.ui.Graphics; | |
import net.rim.device.api.ui.XYEdges; | |
import net.rim.device.api.ui.component.TextField; | |
import net.rim.device.api.ui.container.MainScreen; | |
import net.rim.device.api.ui.container.VerticalFieldManager; | |
import net.rim.device.api.ui.decor.Background; | |
import net.rim.device.api.ui.decor.BackgroundFactory; | |
import net.rim.device.api.ui.decor.Border; | |
import net.rim.device.api.ui.decor.BorderFactory; | |
/** | |
* This is just a simple example of how to make a good user experince using | |
* native Java for Blackberry devices. In this snippet, I use a wooden background | |
* image, a small tape image and a piece of paper image to make an application | |
* feels like we put notes on a piece of paper, then we attached them to a table | |
* using small tape. | |
* @author amri.shodiq | |
* | |
*/ | |
public class LakbanScreen extends MainScreen { | |
public LakbanScreen() { | |
super(NO_VERTICAL_SCROLL); | |
add(getMain()); | |
getMain().add(createQuoteField("Janganlah memboroskan hidup untuk " + | |
"membuktikan bahwa komentar miring orang lain itu salah.")); | |
getMain().add(createQuoteField("Letakkan sandal Anda di bawah tanda berikut.")); | |
} | |
/** | |
* Create a main container for all fields on top of this screen. | |
*/ | |
private VerticalFieldManager mainManager; | |
private VerticalFieldManager getMain() { | |
if (mainManager == null) { | |
mainManager = new VerticalFieldManager(VERTICAL_SCROLL | USE_ALL_WIDTH | | |
USE_ALL_HEIGHT); | |
mainManager.setBackground(getScreenBackground()); | |
} | |
return mainManager; | |
} | |
/** | |
* Make a background with wooden texture | |
*/ | |
private Background screenBg; | |
private Background getScreenBackground() { | |
if (screenBg == null) { | |
screenBg = BackgroundFactory.createBitmapBackground( | |
Bitmap.getBitmapResource("img/app-bg.jpg")); | |
} | |
return screenBg; | |
} | |
/** | |
* Note a quote on a piece of paper with a tape on top of it. | |
* @param quote | |
* @return | |
*/ | |
private Field createQuoteField(String quote) { | |
VerticalFieldManager v2 = new VerticalFieldManager() { | |
public void paint(Graphics g) { | |
super.paint(g); | |
// this is where we put the tape | |
g.drawBitmap( | |
(getWidth() - getTape().getWidth())/2, | |
4, getTape().getWidth(), getTape().getHeight(), getTape(), | |
0, 0); | |
} | |
}; | |
VerticalFieldManager v = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH); | |
v.setBorder(getQuoteBorder()); | |
// make a small margin to make the paper looks smaller than the table | |
v.setMargin(8, 8, 8, 8); | |
// make a small padding to make a little distance between the letter and | |
// paper side. | |
v.setPadding(8, 8, 8, 8); | |
// We use TextField to make this screen scrollable on a non touch device | |
TextField text = new TextField(TextField.NO_EDIT_MODE_INPUT|TextField.READONLY) { | |
// override this method to hide blue pointer | |
public void drawFocus(Graphics g, boolean on) { | |
} | |
}; | |
text.setText(quote); | |
v.add(text); | |
v2.add(v); | |
return v2; | |
} | |
/** | |
* Simply a bitmap instance of an image of tape. | |
*/ | |
private Bitmap tape; | |
private Bitmap getTape() { | |
if (tape == null) { | |
tape = Bitmap.getBitmapResource("img/tape.png"); | |
} | |
return tape; | |
} | |
/** | |
* Border which represent a used paper. | |
*/ | |
private Border quoteBorder; | |
private Border getQuoteBorder() { | |
if (quoteBorder == null) { | |
quoteBorder = BorderFactory.createBitmapBorder( | |
new XYEdges(26, 16, 12, 16), | |
Bitmap.getBitmapResource("img/note.png")); | |
} | |
return quoteBorder; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment