Skip to content
Browse files

first updates

  • Loading branch information...
1 parent 4caa4d4 commit b464404872bfd9f13968e24e0c6dd34767693862 @terrilldent terrilldent committed Feb 7, 2012
Showing with 1,934 additions and 381 deletions.
  1. +1 −0 Advanced UI/README.md
  2. +123 −0 Advanced UI/src/com/samples/toolkit/ui/component/AutoScaleImageField.java
  3. +273 −346 Advanced UI/src/com/samples/toolkit/ui/component/SliderField.java
  4. +125 −0 Advanced UI/src/com/samples/toolkit/ui/container/FieldSet.java
  5. +72 −0 Advanced UI/src/com/samples/toolkit/ui/decor/BitmapBorderBackground.java
  6. +249 −0 Advanced UI/src/com/samples/toolkit/ui/decor/BitmapMask.java
  7. BIN Advanced UI/src/com/samples/toolkit/ui/images/autoscaleimage/Thumbs.db
  8. BIN Advanced UI/src/com/samples/toolkit/ui/images/autoscaleimage/logo_new_large.png
  9. BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/Thumbs.db
  10. BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_diagonal_1.png
  11. BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_honeycomb_1.png
  12. BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_symbols_1.png
  13. BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_symbols_2.png
  14. BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_thatched_1.png
  15. BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/Thumbs.db
  16. BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_back_focus.png
  17. BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_back_normal.png
  18. BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_forward_focus.png
  19. BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_forward_normal.png
  20. BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_play_focus.png
  21. BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_play_normal.png
  22. BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/Thumbs.db
  23. BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_blue_outline.png
  24. BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_bubble_left.png
  25. BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_bubble_right.png
  26. BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_edit.png
  27. BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/login_background.png
  28. BIN Advanced UI/src/com/samples/toolkit/ui/images/carets/Thumbs.db
  29. BIN Advanced UI/src/com/samples/toolkit/ui/images/carets/chevron_right_black_15x22.png
  30. BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version1/Thumbs.db
  31. BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version1/fieldset_body_border.png
  32. BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version1/fieldset_title_border.png
  33. BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version2/Thumbs.db
  34. BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version2/fieldset2_body_border.png
  35. BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version2/fieldset2_title_border.png
  36. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/Thumbs.db
  37. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/battery_back.png
  38. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/battery_progress.png
  39. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_back_2.png
  40. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_back_3.png
  41. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_back_5.png
  42. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_progress_2.png
  43. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_progress_3.png
  44. BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_progress_5.png
  45. BIN Advanced UI/src/com/samples/toolkit/ui/images/masks/Thumbs.db
  46. BIN Advanced UI/src/com/samples/toolkit/ui/images/masks/mask.png
  47. BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/Thumbs.db
  48. BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/golf.png
  49. BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/grass.png
  50. BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/storm.png
  51. BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/summit.png
  52. BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/violin.png
  53. BIN Advanced UI/src/com/samples/toolkit/ui/images/progress/Thumbs.db
  54. BIN Advanced UI/src/com/samples/toolkit/ui/images/progress/spinner.png
  55. BIN Advanced UI/src/com/samples/toolkit/ui/images/progress/spinner2.png
  56. BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/Thumbs.db
  57. BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_dot.png
  58. BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_dot_focus.png
  59. BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_star.png
  60. BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_star_focus.png
  61. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/Thumbs.db
  62. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/Thumbs.db
  63. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_base_focused.png
  64. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_base_normal.png
  65. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_base_pressed.png
  66. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_progress_focused.png
  67. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_progress_normal.png
  68. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_progress_pressed.png
  69. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_thumb_focused.png
  70. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_thumb_normal.png
  71. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_thumb_pressed.png
  72. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/Thumbs.db
  73. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_base_focused.png
  74. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_base_normal.png
  75. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_progress_focused.png
  76. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_progress_normal.png
  77. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_thumb_focused.png
  78. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_thumb_normal.png
  79. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/Thumbs.db
  80. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_base_focused.png
  81. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_base_normal.png
  82. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_base_pressed.png
  83. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_progress_focused.png
  84. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_progress_normal.png
  85. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_progress_pressed.png
  86. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_thumb_focused.png
  87. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_thumb_normal.png
  88. BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_thumb_pressed.png
  89. BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/Thumbs.db
  90. BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_left.png
  91. BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_left_focus.png
  92. BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_right.png
  93. BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_right_focus.png
  94. +97 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleAlphaMaskingScreen.java
  95. +87 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleAutoScaleImageScreen.java
  96. +69 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleBevelBorderScreen.java
  97. +115 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleBitmapBackgroundScreen.java
  98. +67 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleBitmapBorderScreen.java
  99. +4 −5 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleBitmapButtonScreen.java
  100. +19 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleBitmapMaskScreen.java
  101. +85 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleFieldSetIndexScreen.java
  102. +89 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleFieldSetScreen.java
  103. +72 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleGradientBackgroundScreen.java
  104. +115 −3 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleIndexScreen.java
  105. +2 −2 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleNegativeMarginScreen.java
  106. +6 −7 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleProgressAnimationScreen.java
  107. +70 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleRoundedBorderScreen.java
  108. +97 −0 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleSimpleBorderScreen.java
  109. +30 −18 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleSliderScreen.java
  110. +67 −0 Advanced UI/src/com/samples/toolkit/ui/test/UiExampleSolidBackgroundScreen.java
View
1 Advanced UI/README.md
@@ -15,6 +15,7 @@ The sample code for this application is Open Source under the [Apache 2.0 Licens
**Author(s)**
* [Tim Windsor](https://github.com/timwindsor)
+* [Terrill Dent](https://github.com/terrilldent)
**Dependencies**
View
123 Advanced UI/src/com/samples/toolkit/ui/component/AutoScaleImageField.java
@@ -0,0 +1,123 @@
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.samples.toolkit.ui.component;
+
+import net.rim.device.api.math.*;
+import net.rim.device.api.system.*;
+import net.rim.device.api.ui.*;
+
+
+public class AutoScaleImageField extends Field
+{
+ public static final long REDUCE_TO_WIDTH = 1L << 0;
+ public static final long REDUCE_TO_HEIGHT = 1L << 1;
+
+ private int _scale32;
+
+ private EncodedImage _normalImage;
+ private EncodedImage _normalScaledImage;
+
+ private EncodedImage _focusedImage;
+ private EncodedImage _focusedScaledImage;
+
+
+ public AutoScaleImageField( EncodedImage normalImage, long style )
+ {
+ this( normalImage, null, style );
+ }
+
+ public AutoScaleImageField( EncodedImage normalImage, EncodedImage focusedImage, long style )
+ {
+ super( style );
+
+ if( focusedImage == null ) {
+ focusedImage = normalImage;
+ }
+
+ if( normalImage.getWidth() != focusedImage.getWidth()
+ || normalImage.getHeight() != focusedImage.getHeight() ) {
+ throw new IllegalArgumentException();
+ }
+
+ _scale32 = Fixed32.ONE;
+
+ _normalImage = normalImage;
+ _focusedImage = focusedImage;
+ }
+
+ protected void layout( int width, int height )
+ {
+ int imageWidth = _normalImage.getWidth();
+ int widthScale32 = Fixed32.ONE;
+ if( isStyle( REDUCE_TO_WIDTH ) && imageWidth > width ) {
+ widthScale32 = Fixed32.toFP( imageWidth ) / width;
+ }
+
+ int imageHeight = _normalImage.getHeight();
+ int heightScale32 = Fixed32.ONE;
+ if( isStyle( REDUCE_TO_HEIGHT ) && imageHeight > height ) {
+ heightScale32 = Fixed32.toFP( imageHeight ) / height;
+ }
+
+ int scale32 = Math.max( widthScale32, heightScale32 );
+ if( scale32 == Fixed32.ONE ) {
+ // No scaling necessary
+ _normalScaledImage = _normalImage;
+ _focusedScaledImage = _focusedImage;
+ } else if( scale32 != _scale32 ) {
+ // We need to scale the images (and by a different factor from last time)
+ _scale32 = scale32;
+ _normalScaledImage = _normalImage.scaleImage32( scale32, scale32 );
+ if( isStyle( Field.FOCUSABLE ) ) {
+ _focusedScaledImage = _focusedImage.scaleImage32( scale32, scale32 );
+ }
+ }
+
+ setExtent( Math.min( width, _normalScaledImage.getScaledWidth() ), Math.min( height, _normalScaledImage.getScaledHeight() ) );
+ }
+
+ protected void paint( Graphics g )
+ {
+ if( g.isDrawingStyleSet( g.DRAWSTYLE_FOCUS ) ) {
+ g.drawImage( 0, 0, _focusedScaledImage.getScaledWidth(), _focusedScaledImage.getScaledHeight(), _focusedScaledImage, 0, 0, 0 );
+ } else {
+ g.drawImage( 0, 0, _normalScaledImage.getScaledWidth(), _normalScaledImage.getScaledHeight(), _normalScaledImage, 0, 0, 0 );
+ }
+ }
+
+ protected void drawFocus( Graphics g, boolean on )
+ {
+ // The DRAWSTYLE_FOCUS bit should already be set properly, so we can just call paint()
+ paint( g );
+ }
+/*
+ protected void onFocus( int direction)
+ {
+ super.onFocus( direction );
+ invalidate();
+ }
+
+ protected void onUnfocus()
+ {
+ super.onUnfocus();
+ invalidate();
+ }
+*/
+}
+
+
+
View
619 Advanced UI/src/com/samples/toolkit/ui/component/SliderField.java
@@ -22,459 +22,386 @@
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
+import net.rim.device.api.util.*;
public class SliderField extends Field
{
- Bitmap _imageThumb;
+ private final static int STATE_NORMAL = 0;
+ private final static int STATE_FOCUSED = 1;
+ private final static int STATE_PRESSED = 2;
- Bitmap _imageSlider;
- Bitmap _imageSliderLeft;
- Bitmap _imageSliderCenter;
- Bitmap _imageSliderRight;
+ private final static int NUM_STATES = 3;
- Bitmap _imageSliderFocus;
- Bitmap _imageSliderFocusLeft;
- Bitmap _imageSliderFocusCenter;
- Bitmap _imageSliderFocusRight;
- private int _numStates;
- private int _currentState;
- private boolean _selected;
+ private Bitmap[] _thumb = new Bitmap[ NUM_STATES ];
+ private Bitmap[] _progress = new Bitmap[ NUM_STATES ];
+ private Bitmap[] _base = new Bitmap[ NUM_STATES ];
+ private Bitmap[] _progressTile = new Bitmap[ NUM_STATES ];
+ private Bitmap[] _baseTile = new Bitmap[ NUM_STATES ];
- private int _xLeftBackMargin;
- private int _xRightBackMargin;
-
private int _thumbWidth;
private int _thumbHeight;
-
- private int _totalHeight;
- private int _totalWidth;
+ private int _progressWidth;
+ private int _progressHeight;
+ private int _baseWidth;
+ private int _baseHeight;
+
+ private int _leftCapWidth;
+ private int _rightCapWidth;
- private int _rop; // for tiling
- private int _backgroundColours[];
- private int _backgroundSelectedColours[];
+ private boolean _focused;
+ private boolean _pressed;
+
+ private int _numValues;
+ private int _currentValue;
+
+ private int _preferredHeight;
- private int _defaultSelectColour = 0x977DED;
- private int _defaultBackgroundColour = 0xEEEEEE;
- private int _defaultHoverColour = 0x999999;
+ // These values can be cached in layout() for use in paint()
+ private int _baseY;
+ private int _progressY;
+ private int _thumbY;
+ private int _trackWidth;
- /**
- * Bitmap thumb - The image that is used as the state indicator, it moves sideways
- * Bitmap sliderBackground - the background image is stretched to fit, only stretched horizontally
- * int numStates - the number of increments. NOTE: this DOES NOT include zero position (will be one larger than you say)
- * int initialState - NOTE: this INCLUDES ZERO POSITION.
- * int xLeftBackMargin - the amount of the background image to be used as the left side of image
- * int xRightBackMargin - the amount of background image to be used as right side of image
- * Everything between the left and right side gets tiled
- *
- * pre: NumStates must be greater or equal to initialState
- * pre: NumStates must be greater than 1
- */
- public SliderField( Bitmap thumb
- , Bitmap sliderBackground
- , int numStates
- , int initialState
- , int xLeftBackMargin
- , int xRightBackMargin )
+ // Used to tile the base and progress bitmaps
+ private int _rop;
+
+
+ public SliderField( Bitmap normalThumb, Bitmap normalProgress, Bitmap normalBase,
+ Bitmap focusedThumb, Bitmap focusedProgress, Bitmap focusedBase,
+ int numValues, int initialValue, int leftCapWidth, int rightCapWidth )
{
- this( thumb, sliderBackground, sliderBackground, numStates, initialState, xLeftBackMargin, xRightBackMargin, FOCUSABLE );
+ this( normalThumb, normalProgress, normalBase,
+ focusedThumb, focusedProgress, focusedBase,
+ null, null, null,
+ numValues, initialValue, leftCapWidth, rightCapWidth, 0 );
}
- public SliderField( Bitmap thumb
- , Bitmap sliderBackground
- , int numStates
- , int initialState
- , int xLeftBackMargin
- , int xRightBackMargin
- , long style )
- {
- this( thumb, sliderBackground, sliderBackground, numStates, initialState, xLeftBackMargin, xRightBackMargin, style );
+ public SliderField( Bitmap normalThumb, Bitmap normalProgress, Bitmap normalBase,
+ Bitmap focusedThumb, Bitmap focusedProgress, Bitmap focusedBase,
+ int numValues, int initialValue, int leftCapWidth, int rightCapWidth, long style )
+ {
+ this( normalThumb, normalProgress, normalBase,
+ focusedThumb, focusedProgress, focusedBase,
+ null, null, null,
+ numValues, initialValue, leftCapWidth, rightCapWidth, style );
}
- public SliderField( Bitmap thumb
- , Bitmap sliderBackground
- , Bitmap sliderBackgroundFocus
- , int numStates
- , int initialState
- , int xLeftBackMargin
- , int xRightBackMargin )
+ public SliderField( Bitmap normalThumb, Bitmap normalProgress, Bitmap normalBase,
+ Bitmap focusedThumb, Bitmap focusedProgress, Bitmap focusedBase,
+ Bitmap pressedThumb, Bitmap pressedProgress, Bitmap pressedBase,
+ int numValues, int initialValue, int leftCapWidth, int rightCapWidth )
{
- this( thumb, sliderBackground, sliderBackgroundFocus, numStates, initialState, xLeftBackMargin, xRightBackMargin, FOCUSABLE );
+ this( normalThumb, normalProgress, normalBase,
+ focusedThumb, focusedProgress, focusedBase,
+ pressedThumb, pressedProgress, pressedBase,
+ numValues, initialValue, leftCapWidth, rightCapWidth, 0 );
}
- public SliderField( Bitmap thumb
- , Bitmap sliderBackground
- , Bitmap sliderBackgroundFocus
- , int numStates
- , int initialState
- , int xLeftBackMargin
- , int xRightBackMargin
- , long style )
+ public SliderField( Bitmap normalThumb, Bitmap normalProgress, Bitmap normalBase,
+ Bitmap focusedThumb, Bitmap focusedProgress, Bitmap focusedBase,
+ Bitmap pressedThumb, Bitmap pressedProgress, Bitmap pressedBase,
+ int numValues, int initialValue, int leftCapWidth, int rightCapWidth, long style )
{
super( style );
- if( initialState > numStates || numStates < 2 ){
+ if( numValues < 2 || initialValue >= numValues ) {
+ throw new IllegalArgumentException( "invalid value parameters" );
}
- _imageThumb = thumb;
- _imageSlider = sliderBackground;
- _imageSliderFocus = sliderBackgroundFocus;
- _numStates = numStates;
- setState( initialState );
-
- _xLeftBackMargin = xLeftBackMargin;
- _xRightBackMargin = xRightBackMargin;
-
- _rop = _imageSlider.hasAlpha() ? Graphics.ROP_SRC_ALPHA : Graphics.ROP_SRC_COPY;
+ if( normalThumb == null || normalProgress == null || normalBase == null
+ || focusedThumb == null || focusedProgress == null || focusedBase == null ) {
+ throw new IllegalArgumentException( "thumb, normal, focused are required" );
+ }
+
+ _thumbWidth = normalThumb.getWidth();
+ _thumbHeight = normalThumb.getHeight();
+ _progressWidth = normalProgress.getWidth();
+ _progressHeight = normalProgress.getHeight();
+ _baseWidth = normalBase.getWidth();
+ _baseHeight = normalBase.getHeight();
+
+ if( focusedThumb.getWidth() != _thumbWidth || focusedThumb.getHeight() != _thumbHeight
+ || focusedProgress.getHeight() != _progressHeight || focusedBase.getHeight() != _baseHeight ) {
+ throw new IllegalArgumentException( "all base bitmaps and all progress bitmaps must be the same height" );
+ }
+ if( pressedThumb != null && pressedProgress != null && pressedBase != null ) {
+ if( pressedThumb.getWidth() != _thumbWidth || pressedThumb.getHeight() != _thumbHeight
+ || pressedProgress.getHeight() != _progressHeight || pressedBase.getHeight() != _baseHeight ) {
+ throw new IllegalArgumentException( "all base bitmaps and all progress bitmaps must be the same height" );
+ }
+ }
+
+ _leftCapWidth = leftCapWidth;
+ _rightCapWidth = rightCapWidth;
- _thumbWidth = thumb.getWidth();
- _thumbHeight = thumb.getHeight();
+ _rop = Graphics.ROP_SRC_COPY;
- initBitmaps();
+ initBitmaps( normalThumb, normalProgress, normalBase, STATE_NORMAL );
+ initBitmaps( focusedThumb, focusedProgress, focusedBase, STATE_FOCUSED );
+
+ if( pressedThumb != null && pressedProgress != null && pressedBase != null ) {
+ initBitmaps( pressedThumb, pressedProgress, pressedBase, STATE_PRESSED );
+ } else {
+ // The pressed images are optional -- if they aren't provided, just use the focused images
+ _thumb[ STATE_PRESSED ] = _thumb[ STATE_FOCUSED ];
+ _progress[ STATE_PRESSED ] = _progress[ STATE_FOCUSED ];
+ _base[ STATE_PRESSED ] = _base[ STATE_FOCUSED ];
+ _progressTile[ STATE_PRESSED ] = _progressTile[ STATE_FOCUSED ];
+ _baseTile[ STATE_PRESSED ] = _baseTile[ STATE_FOCUSED ];
+ }
+
+ _preferredHeight = Math.max( _thumbHeight, Math.max( _progressHeight, _baseHeight ) );
+
+ _numValues = numValues;
+ setValue( initialValue );
}
-
/**
- * colours - An array of colours, one for each of the states
- * selectColours - An array of colours, one for each selected state
+ * Cuts up the background image and margins you provide
+ * to make the left, center, and right bitmaps
*/
- public SliderField( Bitmap thumb
- , Bitmap sliderBackground
- , int numStates
- , int initialState
- , int xLeftBackMargin
- , int xRightBackMargin
- , int[] colours
- , int[] selectColours )
+ public void initBitmaps( Bitmap thumb, Bitmap progress, Bitmap base, int state )
{
- this(thumb, sliderBackground, sliderBackground, numStates, initialState, xLeftBackMargin, xRightBackMargin, FOCUSABLE );
-
- if( colours.length != numStates+1 ){
+ if( progress.getWidth() <= _leftCapWidth
+ || base.getWidth() <= _rightCapWidth ) {
throw new IllegalArgumentException();
}
- _backgroundColours = colours;
- _backgroundSelectedColours = selectColours;
- }
+
+ if( thumb.hasAlpha() || progress.hasAlpha() || base.hasAlpha() ) {
+ // If any one of our images has an alpha channel we need to use ROP_SRC_ALPHA instead of ROP_SRC_COPY
+ _rop = Graphics.ROP_SRC_ALPHA;
+ }
+
+ _thumb[ state ] = thumb;
+ _progress[ state ] = progress;
+ _base[ state ] = base;
- /**
- * Cuts up the background image and margins you provide
- * to make the left, center, and right bitmaps
- */
- public void initBitmaps()
- {
- int height = _imageSlider.getHeight();
+ int[] argbCopyBuffer;
- _imageSliderLeft = new Bitmap( _xLeftBackMargin, height );
- _imageSliderCenter = new Bitmap( _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height);
- _imageSliderRight = new Bitmap( _xRightBackMargin, height );
+ // Create the progress tile (i.e. to the left of the thumb)
+ int progressTileWidth = progress.getWidth() - _leftCapWidth;
+ int progressTileHeight = progress.getHeight();
- copy( _imageSlider, 0, 0, _xLeftBackMargin, height, _imageSliderLeft );
- copy( _imageSlider, _xLeftBackMargin, 0, _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height, _imageSliderCenter);
- copy( _imageSlider, _imageSlider.getWidth() - _xRightBackMargin, 0, _xRightBackMargin, height, _imageSliderRight);
-
- _imageSliderFocusLeft = new Bitmap( _xLeftBackMargin, height );
- _imageSliderFocusCenter = new Bitmap( _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height);
- _imageSliderFocusRight = new Bitmap( _xRightBackMargin, height );
-
- copy( _imageSliderFocus, 0, 0, _xLeftBackMargin, height, _imageSliderFocusLeft );
- copy( _imageSliderFocus, _xLeftBackMargin, 0, _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height, _imageSliderFocusCenter);
- copy( _imageSliderFocus, _imageSlider.getWidth() - _xRightBackMargin, 0, _xRightBackMargin, height, _imageSliderFocusRight);
- }
+ Bitmap progressTile = new Bitmap( progressTileWidth, progressTileHeight );
- private void copy(Bitmap src, int x, int y, int width, int height, Bitmap dest) {
- int[] argbData = new int[width * height];
- src.getARGB(argbData, 0, width, x, y, width, height);
- for(int tx = 0; tx < dest.getWidth(); tx += width) {
- for(int ty = 0; ty < dest.getHeight(); ty += height) {
- dest.setARGB(argbData, 0, width, tx, ty, width, height);
- }
- }
+ argbCopyBuffer = new int[ progressTileWidth * progressTileHeight ];
+ progress.getARGB( argbCopyBuffer, 0, progressTileWidth, _leftCapWidth, 0, progressTileWidth, progressTileHeight );
+ progressTile.setARGB( argbCopyBuffer, 0, progressTileWidth, 0, 0, progressTileWidth, progressTileHeight );
+
+ // Create the base tile (i.e. to the right of the thumb)
+ int baseTileWidth = base.getWidth() - _rightCapWidth;
+ int baseTileHeight = base.getHeight();
+
+ Bitmap baseTile = new Bitmap( baseTileWidth, baseTileHeight );
+
+ argbCopyBuffer = new int[ baseTileWidth * baseTileHeight ];
+ base.getARGB( argbCopyBuffer, 0, baseTileWidth, 0, 0, baseTileWidth, baseTileHeight );
+ baseTile.setARGB( argbCopyBuffer, 0, baseTileWidth, 0, 0, baseTileWidth, baseTileHeight );
+
+ _progressTile[ state ] = progressTile;
+ _baseTile[ state ] = baseTile;
}
- /**
- * Change the state of the switch. Zero is far left
- * @param on - if true, the switch will be set to on state
- */
- public void setState(int newState) {
- if( newState > _numStates ){
+ public void setValue( int newValue )
+ {
+ if( newValue < 0 || newValue >= _numValues ){
throw new IllegalArgumentException();
- } else {
- _currentState = newState;
- invalidate();
}
+ _currentValue = newValue;
+ fieldChangeNotify( FieldChangeListener.PROGRAMMATIC );
+ invalidate();
}
- /**
- * @return The current state that is selected
- * State zero is on the far left, and increase to the right
- */
- public int getState() {
- return _currentState;
+ public int getValue()
+ {
+ return _currentValue;
}
- /**
- * @return The number of states the slider has
- */
- public int getNumStates() {
- return _numStates;
- }
-
- /**
- * @return The current background colour being used
- */
- public int getColour() {
- if(_backgroundSelectedColours != null) {
- return _backgroundSelectedColours[getState()];
- }
- return 0x000000;
+ public int getNumValues()
+ {
+ return _numValues;
}
- public int getPreferredWidth() {
- return _totalWidth;
+ public int getPreferredWidth()
+ {
+ return Integer.MAX_VALUE;
}
- public int getPreferredHeight() {
- return _totalHeight;
+ public int getPreferredHeight()
+ {
+ return _preferredHeight;
}
- // Similar to TextFields layout()
- protected void layout( int width, int height ) {
- if (width < 0 || height < 0)
- throw new IllegalArgumentException();
+ protected void layout( int width, int height )
+ {
+ width = Math.min( width, getPreferredWidth() );
+ height = Math.min( height, getPreferredHeight() );
- // We'll take all we can get
- _totalWidth = width;
+ // Cache some values for paint() and input handling
+ _progressY = ( height - _progressHeight ) / 2;
+ _baseY = ( height - _baseHeight ) / 2;
+ _thumbY = ( height - _thumbHeight ) / 2;
- // The largest of the two image heights
- _totalHeight = Math.max(_imageSlider.getHeight(), _imageThumb.getHeight());
+ // The thumb should ride along the track from one end cap to the other but not cover up either one
+ _trackWidth = width - _leftCapWidth - _rightCapWidth;
- setExtent( _totalWidth, _totalHeight );
+ setExtent( width, height );
}
+
- public void paint( Graphics g )
- {
- // Calculate the slider position
- int sliderHeight = _imageSlider.getHeight();
- int sliderBackYOffset = ( _totalHeight - sliderHeight ) >> 1;
-
- // Determine a Background Color for the slider
- int backgroundColor = _defaultBackgroundColour;
- if( _backgroundSelectedColours != null || _backgroundColours != null ) {
-
- if( _selected ) {
- backgroundColor = _backgroundSelectedColours != null ? _backgroundSelectedColours[getState()] : _defaultSelectColour;
- } else if(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
- backgroundColor = _backgroundColours != null ? _backgroundColours[getState()] : _defaultHoverColour;
- } else {
- backgroundColor = _defaultBackgroundColour;
- }
- }
- g.setColor( backgroundColor );
- g.fillRect( 1, sliderBackYOffset + 1, _totalWidth - 2, sliderHeight - 2 );
+public void paint( Graphics g )
+{
+ int contentWidth = getContentWidth();
+
+ int thumbX = _leftCapWidth + ( _trackWidth - _thumbWidth ) * _currentValue / ( _numValues - 1 );
+ int transitionX = thumbX + _thumbWidth / 2;
- if(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
- paintSliderBackground( g, _imageSliderFocusLeft, _imageSliderFocusCenter, _imageSliderFocusRight );
- } else {
- paintSliderBackground( g, _imageSliderLeft, _imageSliderCenter, _imageSliderRight );
- }
-
- // Calculate the thumb position
- int thumbXOffset = ( ( _totalWidth - _thumbWidth ) * _currentState ) / _numStates;
-
- // Draw the thumb
- g.drawBitmap( thumbXOffset, ( _totalHeight - _thumbHeight ) >> 1, _thumbWidth, _thumbHeight, _imageThumb, 0, 0 );
- }
+ int currentState = _pressed ? STATE_PRESSED : ( _focused ? STATE_FOCUSED : STATE_NORMAL );
+
+ Bitmap thumb = _thumb[ currentState ];
+ Bitmap progress = _progress[ currentState ];
+ Bitmap base = _base[ currentState ];
+ Bitmap progressTile = _progressTile[ currentState ];
+ Bitmap baseTile = _baseTile[ currentState ];
+
+ // Draw the left cap, and tile the progress region
+ g.drawBitmap( 0, _progressY, _leftCapWidth, _progressHeight, progress, 0, 0 );
+ g.tileRop( _rop, _leftCapWidth, _progressY, transitionX - _leftCapWidth, _progressHeight, progressTile, 0, 0 );
+
+ // Draw the right cap, and tile the base region
+ g.drawBitmap( contentWidth - _rightCapWidth, _baseY, _rightCapWidth, _baseHeight, base, _baseWidth - _rightCapWidth, 0 );
+ g.tileRop( _rop, transitionX, _baseY, contentWidth - transitionX - _rightCapWidth, _baseHeight, baseTile, 0, 0 );
+
+ // Draw the thumb
+ g.drawBitmap( thumbX, _thumbY, _thumbWidth, _thumbHeight, thumb, 0, 0 );
+}
- private void paintSliderBackground( Graphics g, Bitmap left, Bitmap middle, Bitmap right )
+protected void drawFocus( Graphics g, boolean on )
{
- int sliderHeight = _imageSlider.getHeight();
- int sliderBackYOffset = ( _totalHeight - sliderHeight ) >> 1;
-
- // Left
- g.drawBitmap( 0, sliderBackYOffset, _xLeftBackMargin, sliderHeight, left, 0, 0 );//lefttop
- // Middle
- g.tileRop( _rop, _xRightBackMargin, sliderBackYOffset, _totalWidth - _xLeftBackMargin - _xRightBackMargin, sliderHeight, middle, 0, 0 );//top
- // Right
- g.drawBitmap( _totalWidth - _xRightBackMargin, sliderBackYOffset, _xRightBackMargin, sliderHeight, right, 0, 0 );//lefttop
+ // The paint() method looks after drawing the focus for us
}
-
- public void paintBackground( Graphics g )
+
+ protected void onFocus( int direction )
{
- // nothing
+ _focused = true;
+ invalidate();
+ super.onFocus( direction );
}
-
- protected void drawFocus( Graphics g, boolean on )
+
+ protected void onUnfocus()
{
- boolean oldDrawStyleFocus = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS );
- try {
- if( on ) {
- g.setDrawingStyle( Graphics.DRAWSTYLE_FOCUS, true );
- }
- paint( g );
- } finally {
- g.setDrawingStyle( Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus );
- }
+ _focused = false;
+ invalidate();
+ super.onUnfocus();
}
-
- /**
- * Traps touch input events.
- *
- * <p> This method handles touch input events. DOWN events cause this ButtonField
- * to enter a focused state, which is in fact handled at the Manager level. CLICK
- * events cause this ButtonField to enter an active (pressed) state. UNCLICK events
- * invoke {@link invokeAction} and {@link trackwheelUnclick} methods in sequence. The remaining
- * touch input events are consumed and/or ignored.
- *
- * @param message {@link TouchEvent} object containing various input parameters
- * including the event type and touch coordinates.
- * @return True if the event was consumed; otherwise, false.
- * @throws IllegalArgumentException If <code>message</code> is null.
- *
- */
//#ifndef VER_4.6.1 | VER_4.6.0 | VER_4.5.0 | VER_4.2.1 | VER_4.2.0
- protected boolean touchEvent(TouchEvent message)
+ protected boolean touchEvent( TouchEvent message )
{
- boolean isConsumed = false;
- boolean isOutOfBounds = false;
- int x = message.getX(1);
- int y = message.getY(1);
- // Check to ensure point is within this field
- if(x < 0 || y < 0 || x > getExtent().width || y > getExtent().height) {
- isOutOfBounds = true;
- }
- switch(message.getEvent()) {
+ int event = message.getEvent();
+ switch( event ) {
+
case TouchEvent.CLICK:
- case TouchEvent.MOVE:
- if(isOutOfBounds) return true; // consume
- _selected = true; // Pressed effect
-
- // update state
- int stateWidth = getExtent().width / _numStates;
- int numerator = x / stateWidth;
- int denominator = x % stateWidth;
- if( denominator > stateWidth / 2 ) {
- numerator++;
- }
- _currentState = numerator;
- invalidate();
-
- isConsumed = true;
- break;
- case TouchEvent.UNCLICK:
- if(isOutOfBounds) {
- _selected = false; // Reset presssed effect
- return true;
+ case TouchEvent.DOWN:
+ // If we currently have the focus, we still get told about a click in a different part of the screen
+ if( touchEventOutOfBounds( message ) ) {
+ return false;
}
+ // fall through
- // A field change notification is only sent on UNCLICK to allow for recovery
- // should the user cancel, i.e. click and move off the button
-
- _selected = false; // Reset pressed effect
+ case TouchEvent.MOVE:
+ _pressed = true;
+ setValueByTouchPosition( message.getX( 1 ) );
+ fieldChangeNotify( 0 );
+ return true;
- // Update state
- stateWidth = getExtent().width / _numStates;
- numerator = x / stateWidth;
- denominator = x % stateWidth;
- if( denominator > stateWidth / 2 ) {
- numerator++;
- }
- _currentState = numerator;
+ case TouchEvent.UNCLICK:
+ case TouchEvent.UP:
+ _pressed = false;
invalidate();
+ return true;
- fieldChangeNotify(0);
-
- isConsumed = true;
- break;
+ default:
+ return false;
}
- return isConsumed;
}
+
+ private boolean touchEventOutOfBounds( TouchEvent message )
+ {
+ int x = message.getX( 1 );
+ int y = message.getY( 1 );
+ return ( x < 0 || y < 0 || x > getWidth() || y > getHeight() );
+ }
+
+ private void setValueByTouchPosition( int x )
+ {
+ _currentValue = MathUtilities.clamp( 0, ( x - _leftCapWidth ) * _numValues / _trackWidth, _numValues - 1 );
+ invalidate();
+ }
+
+
//#endif
- protected boolean navigationMovement(int dx, int dy, int status, int time)
+ protected boolean navigationMovement( int dx, int dy, int status, int time )
{
- if( _selected )
- {
- if(dx > 0 || dy > 0) {
- incrementState();
- fieldChangeNotify( 0 );
- return true;
- } else if(dx < 0 || dy < 0) {
- decrementState();
- fieldChangeNotify( 0 );
- return true;
+ if( _pressed ) {
+ if( dx > 0 || dy > 0 ) {
+ incrementValue();
+ } else {
+ decrementValue();
}
+ fieldChangeNotify( 0 );
+ return true;
}
return super.navigationMovement( dx, dy, status, time);
}
- public void decrementState() {
- if(_currentState > 0) {
- _currentState--;
+ private void incrementValue()
+ {
+ if( _currentValue + 1 < _numValues ) {
+ _currentValue++;
invalidate();
}
}
- public void incrementState() {
- if(_currentState < _numStates) {
- _currentState++;
+ private void decrementValue()
+ {
+ if( _currentValue > 0 ) {
+ _currentValue--;
invalidate();
}
}
-
- /**
- * Invokes an action on this field. The only action that is recognized by this method is
- * {@link Field#ACTION_INVOKE}, which toggles this field from being checked and unchecked.
- */
- protected boolean invokeAction(int action) {
- switch(action) {
- case ACTION_INVOKE: {
- toggleSelected();
- return true;
- }
+ protected boolean invokeAction( int action )
+ {
+ if( action == ACTION_INVOKE ) {
+ togglePressed();
+ return true;
}
return false;
}
- /**
- * Listens for the space key to be pressed
- * When pressed, state is toggles
- */
- protected boolean keyChar( char key, int status, int time ) {
+ protected boolean keyChar( char key, int status, int time )
+ {
if( key == Characters.SPACE || key == Characters.ENTER ) {
- toggleSelected();
+ togglePressed();
return true;
}
-
return false;
}
- protected boolean trackwheelClick( int status, int time ) {
- if( isEditable() ) {
- toggleSelected();
- return true;
- }
- return super.trackwheelClick(status, time);
- }
-
- /**
- * Toggles the state of the switch
- */
- private void toggleSelected() {
- _selected = !_selected;
- invalidate();
- }
-
- public void setDirty( boolean dirty )
+ protected boolean trackwheelClick( int status, int time )
{
- // We never want to be dirty or muddy
+ togglePressed();
+ return true;
}
- public void setMuddy( boolean muddy )
+ private void togglePressed()
{
- // We never want to be dirty or muddy
+ _pressed = !_pressed;
+ invalidate();
}
}
View
125 Advanced UI/src/com/samples/toolkit/ui/container/FieldSet.java
@@ -0,0 +1,125 @@
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+package com.samples.toolkit.ui.container;
+
+import net.rim.device.api.ui.*;
+import net.rim.device.api.ui.container.*;
+import net.rim.device.api.ui.decor.*;
+
+
+public class FieldSet extends VerticalFieldManager
+{
+ private String _title;
+ private Border _titleBorder;
+ private Border _contentBorder;
+
+ public FieldSet( String title, Border titleBorder, Border contentBorder, long style )
+ {
+ super( style );
+
+ _title = title;
+ _titleBorder = titleBorder;
+ _contentBorder = contentBorder;
+ }
+
+ protected void applyFont()
+ {
+ setBorder( new FieldSetBorder( _title, getFont(), _titleBorder, _contentBorder ), true );
+ }
+
+
+ private static class FieldSetBorder extends Border
+ {
+ private String _title;
+ private Font _font;
+ private Border _titleBorder;
+ private Border _contentBorder;
+
+ private Background _titleBackground;
+
+ private int _titleAreaHeight;
+ private int _titleBorderTopAndBottom;
+ private int _titleBorderLeftAndRight;
+
+ private XYRect _paintRect = new XYRect();
+
+
+ public FieldSetBorder( String title, Font font, Border titleBorder, Border contentBorder )
+ {
+ super( getComposedBorderEdges( font, titleBorder, contentBorder ), 0 );
+
+ _title = title;
+ _font = font;
+ _titleBorder = titleBorder;
+ _contentBorder = contentBorder;
+
+ _titleBackground = titleBorder.getBackground();
+
+ _titleAreaHeight = titleBorder.getTop() + font.getHeight() + titleBorder.getBottom();
+ _titleBorderTopAndBottom = titleBorder.getTop() + titleBorder.getBottom();
+ _titleBorderLeftAndRight = titleBorder.getLeft() + titleBorder.getRight();
+ }
+
+ public static XYEdges getComposedBorderEdges( Font font, Border titleBorder, Border contentBorder )
+ {
+ if( titleBorder.getLeft() != contentBorder.getLeft()
+ || titleBorder.getRight() != contentBorder.getRight() ) {
+ throw new IllegalArgumentException( "borders must have matching left and right edges" );
+ }
+
+ return new XYEdges(
+ titleBorder.getTop() + font.getHeight() + titleBorder.getBottom() + contentBorder.getTop(),
+ contentBorder.getRight(),
+ contentBorder.getBottom(),
+ contentBorder.getLeft() );
+ }
+
+ public void paint( Graphics graphics, XYRect rect )
+ {
+ // paint() is always called from the event thread so we don't have to worry about concurrent access to _paintRect
+ _paintRect.set( rect.x, rect.y, rect.width, _titleAreaHeight );
+ _titleBorder.paint( graphics, _paintRect );
+
+ if( _titleBackground != null ) {
+ _paintRect.x += _titleBorder.getLeft();
+ _paintRect.y += _titleBorder.getTop();
+ _paintRect.width -= _titleBorderLeftAndRight;
+ _paintRect.height -= _titleBorderTopAndBottom;
+ _titleBackground.draw( graphics, _paintRect );
+ }
+
+ _paintRect.set( rect.x, rect.y + _titleAreaHeight, rect.width, rect.height - _titleAreaHeight );
+ _contentBorder.paint( graphics, _paintRect );
+
+ Font oldFont = graphics.getFont();
+ try {
+ graphics.setFont( _font );
+ graphics.drawText( _title, rect.x + _titleBorder.getLeft(), rect.y + _titleBorder.getTop(), DrawStyle.ELLIPSIS, rect.width - _titleBorderLeftAndRight );
+ } finally {
+ graphics.setFont( oldFont );
+ }
+ }
+
+ public Background getBackground()
+ {
+ return _contentBorder.getBackground();
+ }
+
+ }
+
+}
View
72 Advanced UI/src/com/samples/toolkit/ui/decor/BitmapBorderBackground.java
@@ -0,0 +1,72 @@
+//#preprocessor
+
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+//#ifndef VER_4.1.0 | VER_4.2.0 | VER_4.2.1 | VER_4.3.0 | VER_4.5.0
+
+
+package com.samples.toolkit.ui.decor;
+
+import net.rim.device.api.ui.*;
+import net.rim.device.api.ui.decor.*;
+import net.rim.device.api.ui.Graphics;
+import net.rim.device.api.ui.XYRect;
+import net.rim.device.api.system.*;
+
+public class BitmapBorderBackground extends Background
+{
+ private Bitmap _background;
+ private Border _bitmapBorder;
+ private XYEdges _edges;
+ private int _fillColor = - 1;
+
+ public BitmapBorderBackground( XYEdges edges, Bitmap background )
+ {
+ _background = background;
+ _edges = edges;
+
+ _bitmapBorder = BorderFactory.createBitmapBorder( _edges, _background );
+ }
+
+ public BitmapBorderBackground( XYEdges edges, Bitmap background, int fillColor )
+ {
+ this( edges, background );
+ _fillColor = fillColor;
+ }
+
+ public void draw( Graphics g, XYRect rect )
+ {
+ _bitmapBorder.paint( g, rect );
+
+ if( _fillColor != - 1 && rect.width > _edges.left + _edges.right && rect.height > _edges.top + _edges.bottom ) {
+ int oldColor = g.getColor();
+ try {
+ g.setColor( _fillColor );
+ g.fillRect( rect.x + _edges.left, rect.y + _edges.top, rect.width - _edges.left - _edges.right, rect.height - _edges.top - _edges.bottom );
+ } finally {
+ g.setColor( oldColor );
+ }
+ }
+ }
+
+ public boolean isTransparent()
+ {
+ return _background.hasAlpha();
+ }
+}
+//#endif
View
249 Advanced UI/src/com/samples/toolkit/ui/decor/BitmapMask.java
@@ -0,0 +1,249 @@
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.samples.toolkit.ui.decor;
+
+import net.rim.device.api.system.*;
+import net.rim.device.api.ui.*;
+
+
+/**
+ * A helper class for applying an alpha mask to a Bitmap
+ *
+ * The BitmapMask is created with a green image, and a set of edges.
+ * It is reusable (can be applied to multiple images)
+ *
+ * The green value become the alpha channel of the bitmaps passed into applyMask()
+ * Black (0x00) becomes transparent
+ * Green (0xFF) remains opaque
+ */
+public class BitmapMask
+{
+ private final int _alphaTop;
+ private final int _alphaRight;
+ private final int _alphaBottom;
+ private final int _alphaLeft;
+
+ private final int _alphaWidth;
+ private final int _alphaHeight;
+ private final int _alphaInsideWidth;
+ private final int _alphaInsideHeight;
+
+ private final int[] _alphaARGB;
+ private final int[] _cornerARGB;
+
+ /**
+ * Bitmap mask
+ * @param edges the top, right, bottom, and left edges sizes
+ * @param alpha the green bitmap which will become the mask
+ */
+ public BitmapMask( XYEdges edges, Bitmap alpha )
+ {
+ //Initialize edges
+ if( edges == null ) {
+ throw new IllegalArgumentException( "BitmapMask: XYEdges edges is null." );
+ }
+ if( edges.isEmpty() ) {
+ throw new IllegalArgumentException( "BitmapMask: XYEdges edges is empty." );
+ }
+
+ _alphaTop = edges.top;
+ _alphaRight = edges.right;
+ _alphaBottom = edges.bottom;
+ _alphaLeft = edges.left;
+
+ // Initalize bitmap properties
+ if( alpha == null ) {
+ throw new IllegalArgumentException("BitmapMask: alpha is null.");
+ }
+
+ _alphaWidth = alpha.getWidth();
+ _alphaHeight = alpha.getHeight();
+
+ _alphaInsideWidth = _alphaWidth - _alphaLeft - _alphaRight;
+ _alphaInsideHeight = _alphaHeight - _alphaBottom - _alphaTop;
+ if( ( _alphaInsideWidth < 0 ) || ( _alphaInsideHeight < 0 ) ) {
+ throw new IllegalArgumentException("BitmapMask: Invalid alpha width and height.");
+ }
+
+ _alphaARGB = new int[ _alphaWidth * _alphaHeight ];
+ alpha.getARGB( _alphaARGB, 0, _alphaWidth, 0, 0, _alphaWidth, _alphaHeight );
+
+ for( int i=_alphaARGB.length-1; i>=0; i-- ) {
+ _alphaARGB[ i ] = ( _alphaARGB[ i ] << 16 ) & 0xff000000;
+ }
+
+ _cornerARGB = new int[ Math.max( _alphaLeft, _alphaRight ) * Math.max( _alphaTop, _alphaBottom ) ];
+ }
+
+ public int getTop()
+ {
+ return _alphaTop;
+ }
+
+ public int getRight()
+ {
+ return _alphaRight;
+ }
+
+ public int getBottom()
+ {
+ return _alphaBottom;
+ }
+
+ public int getLeft()
+ {
+ return _alphaLeft;
+ }
+
+ public int getWidth()
+ {
+ return _alphaWidth;
+ }
+
+ public int getHeight()
+ {
+ return _alphaHeight;
+ }
+
+ /**
+ * Apply the mask to the given bitmap
+ *
+ * @param targetBitmap this bitmaps ARGB data will be modified with the alpha data from the mask
+ */
+ public void applyMask( Bitmap targetBitmap )
+ {
+ int targetWidth = targetBitmap.getWidth();
+ int targetHeight = targetBitmap.getHeight();
+
+ int[] bufferARGB = new int[ targetWidth ];
+
+ int targetTop = Math.min( _alphaTop, targetHeight );
+ int targetRight = Math.min( _alphaRight, targetWidth );
+ int targetBottom = Math.min( _alphaBottom, targetHeight );
+ int targetLeft = Math.min( _alphaLeft, targetWidth );
+
+ int targetInsideBottomY = targetHeight - targetBottom;
+ int targetInsideTopY = targetTop;
+
+ int targetInsideRightX = targetWidth - targetRight;
+ int targetInsideLeftX = targetLeft;
+
+ int targetInsideWidth = Math.max( targetInsideRightX - targetInsideLeftX, 0 );
+ int targetInsideHeight = Math.max( targetInsideBottomY - targetInsideTopY, 0 );
+
+
+ if( _alphaInsideWidth > 0) {
+ if( targetTop > 0 ) {
+ drawTileMask( _alphaLeft, 0, _alphaInsideWidth, _alphaTop,
+ targetLeft, 0, targetInsideWidth, targetTop, targetBitmap, bufferARGB ); // top
+ }
+ if( targetBottom > 0 ) {
+ drawTileMask( _alphaLeft, _alphaHeight - _alphaBottom, _alphaInsideWidth, _alphaBottom,
+ targetLeft, targetHeight - targetBottom, targetInsideWidth, targetBottom, targetBitmap, bufferARGB ); // bottom
+ }
+ }
+ if( _alphaInsideHeight > 0 ) {
+ if( targetLeft > 0 ) {
+ drawTileMask( 0, _alphaTop, _alphaLeft, _alphaInsideHeight,
+ 0, targetTop, targetLeft, targetInsideHeight, targetBitmap, bufferARGB ); // left
+ }
+ if( targetRight > 0 ) {
+ drawTileMask( _alphaWidth - _alphaRight, _alphaTop, _alphaRight, _alphaInsideHeight,
+ targetWidth - targetRight, targetTop, targetRight, targetInsideHeight, targetBitmap, bufferARGB ); // right
+ }
+ }
+ if( targetTop > 0 ) {
+ if( targetLeft > 0) {
+ drawCornerMask( 0, 0, _alphaLeft, _alphaTop,
+ 0, 0, targetBitmap ); // left top
+ }
+ if( targetRight > 0 ) {
+ drawCornerMask( _alphaLeft + _alphaInsideWidth, 0, _alphaRight, _alphaTop,
+ targetInsideRightX, 0, targetBitmap ); // right top
+ }
+ }
+ if( targetBottom > 0 ) {
+ if( targetLeft > 0 ) {
+ drawCornerMask( 0, _alphaHeight - _alphaBottom, _alphaLeft, _alphaBottom,
+ 0, targetHeight - targetBottom, targetBitmap ); // left bottom
+ }
+ if( targetRight > 0 ) {
+ drawCornerMask( _alphaWidth - _alphaRight, _alphaHeight - _alphaBottom, _alphaRight, _alphaBottom,
+ targetWidth - targetRight, targetHeight - targetBottom, targetBitmap ); // right bottom
+ }
+ }
+ }
+
+ /**
+ * Apply a portion of the mask to the destination area. Tile if destination area is larger than source area
+ */
+ private void drawTileMask( int sourceX, int sourceY, int sourceWidth, int sourceHeight,
+ int destX, int destY, int destWidth, int destHeight,
+ Bitmap targetBitmap, int[] bufferARGB )
+ {
+ int sourceOffsetStart = sourceY * _alphaWidth + sourceX;
+ int sourceOffsetMax = ( sourceY + sourceHeight ) + _alphaWidth;
+ int sourceOffset = sourceOffsetStart;
+
+ for( int y=0; y<destHeight; y++, destY++ ) {
+
+ targetBitmap.getARGB( bufferARGB, 0, destWidth, destX, destY, destWidth, 1 );
+
+ for( int x=0; x<destWidth; x++ ) {
+ bufferARGB[ x ] = ( bufferARGB[ x ] & 0x00ffffff ) | _alphaARGB[ sourceOffset + x % sourceWidth ];
+ }
+
+ targetBitmap.setARGB( bufferARGB, 0, destWidth, destX, destY, destWidth, 1 );
+
+ sourceOffset += _alphaWidth;
+ if( sourceOffset >= sourceOffsetMax ) {
+ sourceOffset = sourceOffsetStart;
+ }
+ }
+ }
+
+
+ /**
+ * Apply a portion of the mask to the destination area. Tile if destination area is smaller than source area
+ */
+ private void drawCornerMask( int sourceX, int sourceY, int sourceWidth, int sourceHeight,
+ int destX, int destY,
+ Bitmap targetBitmap )
+ {
+ int sourceOffset = sourceY * _alphaWidth + sourceX;
+ int destOffset = 0;
+
+ targetBitmap.getARGB( _cornerARGB, 0, sourceWidth, destX, destY, sourceWidth, sourceHeight );
+
+ for( int y=0; y<sourceHeight; y++ ) {
+
+ for( int x=0; x<sourceWidth; x++, sourceOffset++, destOffset++ ) {
+ _cornerARGB[ destOffset] = ( _cornerARGB[ destOffset ] & 0x00ffffff ) | _alphaARGB[ sourceOffset ];
+ }
+ sourceOffset += _alphaWidth - sourceWidth;
+ }
+
+ targetBitmap.setARGB( _cornerARGB, 0, sourceWidth, destX, destY, sourceWidth, sourceHeight );
+ }
+
+
+}
+
+
+
+
+
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/autoscaleimage/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/autoscaleimage/logo_new_large.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_diagonal_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_honeycomb_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_symbols_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_symbols_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/backgrounds/background_thatched_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_back_focus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_back_normal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_forward_focus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_forward_normal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_play_focus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/bitmapbutton/button_play_normal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_blue_outline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_bubble_left.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_bubble_right.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/border_edit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/borders/login_background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/carets/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/carets/chevron_right_black_15x22.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version1/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version1/fieldset_body_border.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version1/fieldset_title_border.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version2/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version2/fieldset2_body_border.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/fieldset/version2/fieldset2_title_border.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/battery_back.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/battery_progress.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_back_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_back_3.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_back_5.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_progress_2.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_progress_3.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/gauge/gauge_progress_5.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/masks/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/masks/mask.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/golf.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/grass.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/storm.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/summit.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/photos/violin.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/progress/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/progress/spinner.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/progress/spinner2.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_dot.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_dot_focus.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_star.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/rating/rating_star_focus.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_base_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_base_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_base_pressed.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_progress_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_progress_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_progress_pressed.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_thumb_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_thumb_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version1/slider_thumb_pressed.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_base_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_base_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_progress_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_progress_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_thumb_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version2/slider2_thumb_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_base_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_base_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_base_pressed.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_progress_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_progress_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_progress_pressed.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_thumb_focused.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_thumb_normal.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/sliders/version3/slider3_thumb_pressed.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/Thumbs.db
Binary file not shown.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_left.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_left_focus.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_right.png
Diff not rendered.
View
BIN Advanced UI/src/com/samples/toolkit/ui/images/switches/switch_right_focus.png
Diff not rendered.
View
97 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleAlphaMaskingScreen.java
@@ -0,0 +1,97 @@
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.samples.toolkit.ui.test;
+
+
+import com.samples.toolkit.ui.component.*;
+import com.samples.toolkit.ui.container.*;
+import com.samples.toolkit.ui.decor.*;
+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.container.*;
+
+/**
+ *
+ */
+public class UIExampleAlphaMaskingScreen extends UIExampleScreen
+{
+ private FlowFieldManager _flow1;
+ private FlowFieldManager _flow2;
+ private BitmapMask _mask;
+
+ public UIExampleAlphaMaskingScreen() {
+ super( 0 );
+ setTitle("Alpha BitmapMask Examples");
+
+ Bitmap maskImage = Bitmap.getBitmapResource( "mask.png" );
+
+ _flow1 = new FlowFieldManager();
+ _flow2 = new FlowFieldManager();
+
+ addLabel( "Image Mask" );
+
+ _mask = new BitmapMask( new XYEdges( 9, 9, 9, 9 ), maskImage );
+
+ BitmapField maskPreview = new BitmapField( maskImage );
+ maskPreview.setMargin( 15, 15, 15, 15 );
+ add( maskPreview );
+
+
+ addImage( "golf.png" );
+ addImage( "grass.png" );
+ addImage( "storm.png" );
+ addImage( "violin.png" );
+
+
+ addMaskedImage( "golf.png" );
+ addMaskedImage( "grass.png" );
+ addMaskedImage( "storm.png" );
+ addMaskedImage( "violin.png" );
+
+ _flow1.setPadding( 15, 5, 15, 5 );
+ _flow2.setPadding( 15, 5, 15, 5 );
+
+ addLabel( "Original Images" );
+ add( _flow1 );
+ addLabel( "Masked Images" );
+ add( _flow2 );
+ }
+
+ private void addLabel( String title )
+ {
+ LabelField imageField = new LabelField( title );
+ imageField.setMargin( 5, 5, 5, 5 );
+ add( imageField );
+ }
+
+ private void addImage( String filename )
+ {
+ BitmapField imageField = new BitmapField( Bitmap.getBitmapResource( filename ) );
+ imageField.setMargin( 5, 5, 5, 5 );
+ _flow1.add( imageField );
+ }
+
+ private void addMaskedImage( String filename )
+ {
+ Bitmap imageToMask = Bitmap.getBitmapResource( filename );
+ _mask.applyMask( imageToMask );
+ BitmapField imageField = new BitmapField( imageToMask );
+ imageField.setMargin( 5, 5, 5, 5 );
+ _flow2.add( imageField );
+ }
+}
View
87 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleAutoScaleImageScreen.java
@@ -0,0 +1,87 @@
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.samples.toolkit.ui.test;
+
+import com.samples.toolkit.ui.component.*;
+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.container.*;
+import net.rim.device.api.ui.decor.*;
+
+
+public class UIExampleAutoScaleImageScreen extends UIExampleScreen
+{
+ public UIExampleAutoScaleImageScreen()
+ {
+ Field field;
+ Manager manager;
+
+ EncodedImage normalImage = EncodedImage.getEncodedImageResource( "logo_new_large.png" );
+ long style = Field.FOCUSABLE | AutoScaleImageField.REDUCE_TO_WIDTH | AutoScaleImageField.REDUCE_TO_WIDTH;
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 40, 20, 10, 20 );
+ manager.setPadding( 16, 16, 16, 16 );
+ manager.setBackground(
+ BackgroundFactory.createSolidBackground( 0x79BC00 )
+ );
+
+ field = new AutoScaleImageField( normalImage, normalImage, style );
+
+ manager.add( field );
+ add( manager );
+
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 20, 40, 10, 40 );
+ manager.setPadding( 16, 16, 16, 16 );
+ manager.setBackground(
+ BackgroundFactory.createSolidBackground( 0x79BC00 )
+ );
+
+ field = new AutoScaleImageField( normalImage, normalImage, style );
+
+ manager.add( field );
+ add( manager );
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 20, 60, 10, 60 );
+ manager.setPadding( 16, 16, 16, 16 );
+ manager.setBackground(
+ BackgroundFactory.createSolidBackground( 0x79BC00 )
+ );
+
+ field = new AutoScaleImageField( normalImage, normalImage, style );
+
+ manager.add( field );
+ add( manager );
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 20, 80, 10, 80 );
+ manager.setPadding( 16, 16, 16, 16 );
+ manager.setBackground(
+ BackgroundFactory.createSolidBackground( 0x79BC00 )
+ );
+
+ field = new AutoScaleImageField( normalImage, normalImage, style );
+
+ manager.add( field );
+ add( manager );
+
+ }
+}
View
69 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleBevelBorderScreen.java
@@ -0,0 +1,69 @@
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.samples.toolkit.ui.test;
+
+import net.rim.device.api.ui.*;
+import net.rim.device.api.ui.component.*;
+import net.rim.device.api.ui.decor.*;
+
+
+public class UIExampleBevelBorderScreen extends UIExampleScreen
+{
+ public UIExampleBevelBorderScreen()
+ {
+ Field field;
+
+ field = new LabelField( "Default Gray", FIELD_HCENTER );
+ field.setMargin( 40, 0, 10, 0 );
+ field.setPadding( 10, 10, 10, 10 );
+ field.setBorder(
+ BorderFactory.createBevelBorder( new XYEdges( 8, 8, 8, 8 ) )
+ );
+
+ add( field );
+
+
+ field = new LabelField( "Warm Colors", FIELD_HCENTER );
+ field.setMargin( 10, 0, 10, 0 );
+ field.setPadding( 10, 10, 10, 10 );
+ field.setBorder(
+ BorderFactory.createBevelBorder(
+ new XYEdges( 8, 8, 8, 8 ),
+ new XYEdges( Color.RED, Color.DARKORANGE, Color.DARKRED, Color.ORANGE ),
+ new XYEdges( Color.DARKRED, Color.ORANGE, Color.RED, Color.DARKORANGE )
+ )
+ );
+
+ add( field );
+
+
+ field = new LabelField( "Cool Colors", FIELD_HCENTER );
+ field.setMargin( 10, 0, 10, 0 );
+ field.setPadding( 10, 10, 10, 10 );
+ field.setBorder(
+ BorderFactory.createBevelBorder(
+ new XYEdges( 8, 8, 8, 8 ),
+ new XYEdges( Color.CYAN, Color.DARKBLUE, Color.DARKCYAN, Color.BLUE ),
+ new XYEdges( Color.DARKCYAN, Color.BLUE, Color.CYAN, Color.DARKBLUE )
+ )
+ );
+
+ add( field );
+
+
+ }
+}
View
115 Advanced UI/src/com/samples/toolkit/ui/test/UIExampleBitmapBackgroundScreen.java
@@ -0,0 +1,115 @@
+/*
+* Copyright (c) 2011 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.samples.toolkit.ui.test;
+
+
+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.container.*;
+import net.rim.device.api.ui.decor.*;
+
+
+public class UIExampleBitmapBackgroundScreen extends UIExampleScreen
+{
+ public UIExampleBitmapBackgroundScreen()
+ {
+ Field field;
+ Manager manager;
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 40, 20, 10, 20 );
+ manager.setPadding( 48, 0, 48, 0 );
+ manager.setBackground(
+ BackgroundFactory.createBitmapBackground(
+ Bitmap.getBitmapResource( "background_symbols_1.png" ),
+ 0, 0, Background.REPEAT_BOTH
+ )
+ );
+
+ field = new LabelField( "Symbols 1", FIELD_HCENTER );
+ field.setPadding( 16, 16, 16, 16 );
+ field.setBackground(
+ BackgroundFactory.createSolidTransparentBackground( Color.WHITE, 0x80 )
+ );
+
+ manager.add( field );
+ add( manager );
+
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 10, 20, 10, 20 );
+ manager.setPadding( 48, 0, 48, 0 );
+ manager.setBackground(
+ BackgroundFactory.createBitmapBackground(
+ Bitmap.getBitmapResource( "background_symbols_2.png" ),
+ 0, 0, Background.REPEAT_BOTH
+ )
+ );
+
+ field = new LabelField( "Symbols 2", FIELD_HCENTER );
+ field.setPadding( 16, 16, 16, 16 );
+ field.setBackground(
+ BackgroundFactory.createSolidTransparentBackground( Color.WHITE, 0x80 )
+ );
+
+ manager.add( field );
+ add( manager );
+
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 10, 20, 10, 20 );
+ manager.setPadding( 48, 0, 48, 0 );
+ manager.setBackground(
+ BackgroundFactory.createBitmapBackground(
+ Bitmap.getBitmapResource( "background_honeycomb_1.png" ),
+ 0, 0, Background.REPEAT_BOTH
+ )
+ );
+
+ field = new LabelField( "Honeycomb", FIELD_HCENTER );
+ field.setPadding( 16, 16, 16, 16 );
+ field.setBackground(
+ BackgroundFactory.createSolidTransparentBackground( Color.WHITE, 0x80 )
+ );
+
+ manager.add( field );
+ add( manager );
+
+
+ manager = new VerticalFieldManager( USE_ALL_WIDTH );
+ manager.setMargin( 10, 20, 10, 20 );
+ manager.setPadding( 48, 0, 48, 0 );
+ manager.setBackground(
+ BackgroundFactory.createBitmapBackground(
+ Bitmap.getBitmapResource( "background_thatched_1.png" ),
+ 0, 0, Background.REPEAT_BOTH
+ )
+ );
+
+ field = new LabelField( "Thatched", FIELD_HCENTER );
+ field.setPadding( 16, 16, 16, 16 );
+ field.setBackground(
+ BackgroundFactory.createSolidTransparentBackground( Color.WHITE, 0x80 )
+ );
+