Skip to content

Commit 4caa4d4

Browse files
author
Tim Windsor
committed
Commit of Advanced UI sample
1 parent 143638b commit 4caa4d4

53 files changed

Lines changed: 6525 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Advanced UI/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/net.rim.ejde.BlackBerryVMInstallType/BlackBerry JRE 6.0.0"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

Advanced UI/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin
2+
/deliverables

Advanced UI/.project

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Advanced UI</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>net.rim.ejde.internal.builder.BlackBerryPreprocessBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>net.rim.ejde.internal.builder.BlackBerryResourcesBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>net.rim.ejde.BlackBerryPreProcessNature</nature>
26+
<nature>net.rim.ejde.BlackBerryProjectCoreNature</nature>
27+
<nature>org.eclipse.jdt.core.javanature</nature>
28+
</natures>
29+
</projectDescription>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Thu Oct 27 17:27:21 EDT 2011
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.4
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.source=1.3
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Properties ModelVersion="1.1.2">
2+
<General Title="" Version="1.0.0" Vendor="BlackBerry Developer" Description=""/>
3+
<Application Type="BlackBerry Application" MainMIDletName="" MainArgs="" HomeScreenPosition="0" StartupTier="7" IsSystemModule="false" IsAutostartup="false"/>
4+
<Resources hasTitleResource="false" TitleResourceBundleName="" TitleResourceBundleRelativePath="" TitleResourceBundleClassName="" TitleResourceBundleKey="" DescriptionId="">
5+
<Icons/>
6+
</Resources>
7+
<Compile OutputCompilerMessages="false" ConvertImages="false" CreateWarningForNoExportedRoutine="true" CompressResources="false" AliasList="">
8+
<PreprocessorDefines/>
9+
</Compile>
10+
<Packaging OutputFileName="Advanced_UI" OutputFolder="deliverables" PreBuildStep="" PostBuildStep="" CleanStep="" GenerateALXFile="true">
11+
<AlxFiles/>
12+
</Packaging>
13+
<HiddenProperties>
14+
<ClassProtection/>
15+
<PackageProtection/>
16+
</HiddenProperties>
17+
<AlternateEntryPoints/>
18+
</Properties>

Advanced UI/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# BlackBerry Advanced UI Samples
2+
3+
The Graphics API provides features for working with images and painting, which together can be used to create custom UI components. The sample code provides a library of various custom components, including buttons, fields, and managers.
4+
5+
For screenshots and sample images that can be used with the test application, please see this article: http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-managers/ta-p/488276. The test images have not been open sourced or included in the repository.
6+
7+
8+
The sample code for this application is Open Source under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html).
9+
10+
**Applies To**
11+
12+
* [BlackBerry Java SDK for Smartphones](http://us.blackberry.com/developers/javaappdev/)
13+
14+
15+
**Author(s)**
16+
17+
* [Tim Windsor](https://github.com/timwindsor)
18+
19+
20+
**Dependencies**
21+
22+
1. BlackBerry Java SDK 4.2.0 or higher required.
23+
24+
25+
**Known Issues**
26+
27+
1. The samples use the Preprocessor to gracefully degrade features on older software. Not all features will be exactly alike in all SDK versions.
28+
29+
30+
**To contribute code to this repository you must be [signed up as an official contributor](http://blackberry.github.com/howToContribute.html).**
31+
32+
33+
## Contributing Changes
34+
35+
Please see the [README](https://github.com/blackberry/BlackBerry-Java) of the BlackBerry-Java repository for instructions on how to add new Samples or make modifications to existing Samples.
36+
37+
38+
## Bug Reporting and Feature Requests
39+
40+
If you find a bug in a Sample, or have an enhancement request, simply file an [Issue](https://github.com/blackberry/BlackBerry-Java/issues) for the Sample and send a message (via github messages) to the Sample Author(s) to let them know that you have filed an [Issue](https://github.com/blackberry/BlackBerry-Java/issues).
41+
42+
43+
## Disclaimer
44+
45+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//#preprocess
2+
3+
/*
4+
* Copyright (c) 2011 Research In Motion Limited.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.samples.toolkit.ui;
20+
21+
import net.rim.device.api.ui.*;
22+
23+
//#ifndef VER_4.1.0 | VER_4.2.0 | VER_4.2.1 | VER_4.3.0 | VER_4.5.0
24+
import net.rim.device.api.ui.decor.*;
25+
//#endif
26+
27+
28+
public class FieldDimensionUtilities
29+
{
30+
private FieldDimensionUtilities() { }
31+
32+
public static int getBorderWidth( Field field )
33+
{
34+
int width = 0;
35+
36+
//#ifdef VER_4.1.0 | VER_4.2.0 | VER_4.2.1 | VER_4.3.0 | VER_4.5.0
37+
width = field.getWidth() - field.getContentWidth() - field.getPaddingLeft() - field.getPaddingRight();
38+
//#else
39+
Border border = field.getBorder();
40+
if( border != null ) {
41+
width = border.getLeft() + border.getRight();
42+
}
43+
//#endif
44+
return width;
45+
}
46+
47+
public static int getBorderHeight( Field field )
48+
{
49+
int height = 0;
50+
51+
//#ifdef VER_4.1.0 | VER_4.2.0 | VER_4.2.1 | VER_4.3.0 | VER_4.5.0
52+
height = field.getWidth() - field.getContentHeight() - field.getPaddingTop() - field.getPaddingBottom();
53+
//#else
54+
Border border = field.getBorder();
55+
if( border != null ) {
56+
height = border.getTop() + border.getBottom();
57+
}
58+
//#endif
59+
return height;
60+
}
61+
62+
public static int getBorderAndPaddingWidth( Field field )
63+
{
64+
int width = 0;
65+
//#ifdef VER_4.1.0 | VER_4.2.0 | VER_4.2.1 | VER_4.3.0 | VER_4.5.0
66+
width = field.getWidth() - field.getContentWidth();
67+
//#else
68+
width = field.getPaddingLeft() + field.getPaddingRight();
69+
Border border = field.getBorder();
70+
if( border != null ) {
71+
width += border.getLeft() + border.getRight();
72+
}
73+
//#endif
74+
return width;
75+
}
76+
77+
public static int getBorderAndPaddingHeight( Field field )
78+
{
79+
int height = 0;
80+
//#ifdef VER_4.1.0 | VER_4.2.0 | VER_4.2.1 | VER_4.3.0 | VER_4.5.0
81+
height = field.getHeight() - field.getContentHeight();
82+
//#else
83+
height = field.getPaddingTop() + field.getPaddingBottom();
84+
Border border = field.getBorder();
85+
if( border != null ) {
86+
height += border.getTop() + border.getBottom();
87+
}
88+
//#endif
89+
return height;
90+
}
91+
92+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2011 Research In Motion Limited.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.samples.toolkit.ui.component;
18+
19+
import net.rim.device.api.system.*;
20+
import net.rim.device.api.ui.*;
21+
22+
23+
/**
24+
* Implements all the stuff we don't want to do each time we need a new button
25+
*/
26+
public abstract class BaseButtonField extends Field
27+
{
28+
private XYRect _drawFocusTempRect = new XYRect();
29+
30+
public BaseButtonField()
31+
{
32+
this( 0 );
33+
}
34+
35+
public BaseButtonField( long style )
36+
{
37+
super( Field.FOCUSABLE | style );
38+
}
39+
40+
protected void layout( int width, int height )
41+
{
42+
setExtent( 10, 10 );
43+
}
44+
45+
protected void drawFocus( Graphics g, boolean on )
46+
{
47+
getFocusRect( _drawFocusTempRect );
48+
49+
boolean oldDrawStyleFocus = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS );
50+
boolean notEmpty = g.pushContext( _drawFocusTempRect.x, _drawFocusTempRect.y, _drawFocusTempRect.width, _drawFocusTempRect.height, 0, 0 );
51+
52+
try {
53+
if( notEmpty ) {
54+
g.setDrawingStyle( Graphics.DRAWSTYLE_FOCUS, on );
55+
paintBackground( g );
56+
paint( g );
57+
}
58+
} finally {
59+
g.popContext();
60+
g.setDrawingStyle( Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus );
61+
}
62+
}
63+
64+
protected boolean keyChar( char character, int status, int time )
65+
{
66+
if( character == Characters.ENTER ) {
67+
clickButton();
68+
return true;
69+
}
70+
return super.keyChar( character, status, time );
71+
}
72+
73+
protected boolean navigationClick( int status, int time )
74+
{
75+
clickButton();
76+
return true;
77+
}
78+
79+
protected boolean trackwheelClick( int status, int time )
80+
{
81+
clickButton();
82+
return true;
83+
}
84+
85+
protected boolean invokeAction( int action )
86+
{
87+
switch( action ) {
88+
case ACTION_INVOKE: {
89+
clickButton();
90+
return true;
91+
}
92+
}
93+
return super.invokeAction( action );
94+
}
95+
96+
public void setDirty( boolean dirty ) {
97+
// We never want to be dirty or muddy
98+
}
99+
100+
public void setMuddy( boolean muddy ) {
101+
// We never want to be dirty or muddy
102+
}
103+
104+
/**
105+
* A public way to click this button
106+
*/
107+
public void clickButton()
108+
{
109+
fieldChangeNotify( 0 );
110+
}
111+
}
112+

0 commit comments

Comments
 (0)