Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Spiral / Rotation Menu Control ?

Yes, I have a few apps that I use or used it in.
New Contributor
Posts: 7
Registered: ‎02-20-2011
My Device: 9800

Re: Spiral / Rotation Menu Control ?

Hi CMY, can you give me some app with the code that you give?

 

i try to use that but nothing happen, i use paint in a class that extend field

Regular Contributor
Posts: 65
Registered: ‎06-13-2011
My Device: mini curve

Re: Spiral / Rotation Menu Control ?

man where is the all code its not rotating when i move left or right 

can u help me please 

Contributor
Posts: 18
Registered: ‎11-16-2011
My Device: 9900

Re: Spiral / Rotation Menu Control ?

Please chare the complete class or code for the same.

I shall be very grateful to you.

 

Thanks in Advance

Rahul

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Spiral / Rotation Menu Control ?

Here is the complete class....be mindful that I have a completely custom UI Library which is why I only posted the relevant parts before.

 

//#preprocess

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CM.api.ui.blackberry.component;

import CM.api.ui.blackberry.MyField;
import CM.api.ui.blackberry.ToolTip;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.math.Fixed32;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.TouchEvent;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.UiApplication;

import java.util.Vector;
import java.util.Timer;

/**
 *
 * @author HU77
 */
public class CustomCarouselField extends Field implements MyField {
   //private String label;
   private int width,height,xPos,yPos;
   private int itemSize;
   private int selectedChoice = 0;
   private int backgroundColor = 0x000000;
   private int backgroundGradient = 0x000000;
   private int focusColor = 0x002299;
   private int focusGradient = 0x002299;
   private int fontColor = 0xFFFFFF;
   private boolean useGradient = true;
   private boolean useOutline = true;
   private boolean hasFocus = false;
   private Vector choices;
   private Font defaultFont = null;
   private int fontSize = 14;
   private int bgAlpha = 255;
   private int fgAlpha = 255;
   private int prevx;
   private int offset = 0;
   //private int fWidth, choiceWidth, fp1, fp2;
   //int xOffset, yOffset;
   ToolTip tip;
   static Timer timer = null;
   boolean touchEnabled = false;
   boolean alwaysShowLabel = false;
   boolean changeOnScroll = false;
   boolean selectedChanged = false;
   boolean showText = true;
   boolean hideBorder = false;

   //===============================================================================================//

   public CustomCarouselField(int sz, int x, int y, int w, int h){
      //label = lbl;
      choices = new Vector();
      //choices.ensureCapacity(nChoices);
      //maxItems = nChoices;
      xPos = x;
      yPos = y;
      width = w;
      height = h;
      itemSize = sz;
   }

   public void addChoice(String bitmap, String desc, Runnable action){
      choices.addElement( new CarouselItem(desc,bitmap,choices.size(),action) );
   }

   public void addChoice(String name, String bitmap, String desc, Runnable action){
      choices.addElement( new CarouselItem(name,desc,bitmap,choices.size(),action) );
   }

   public void defaultChoice(int index){
      selectedChoice = index;
   }
   
   public int getCurrentSelection(){
      return selectedChoice;
   }

   public String getCurrentTitle(){
      return ((CarouselItem)choices.elementAt(selectedChoice)).name;
   }

   public Runnable getCurrentAction(){
      return ((CarouselItem)choices.elementAt(selectedChoice)).action;
   }
   
   public void runCurrentAction(){
      UiApplication.getUiApplication().invokeLater( getCurrentAction() );
   }

   public void replaceAction(int i, Runnable r){
      ((CarouselItem)choices.elementAt(i)).action = r;
   }
   
   public int getNumberOfChoices(){
      return choices.size();
   }

   public void removeChoice(int index){
      if( index < choices.size() ){
         for(int i=index; i<choices.size(); ++i){
            ((CarouselItem)choices.elementAt(i)).element--;
         }
         choices.removeElementAt(index);
      }
      if( selectedChoice == index ) selectedChoice = 0;
   }

   protected void layout(int width, int height){
      setExtent(myWidth(),myHeight());
   }

   /**
    * Changes the color of the button back to the default color when it loses focus
    * and forces the button to redraw.
    */
   protected void onUnfocus(){
      hasFocus = false;
      if( this.getFocusListener() != null ) getFocusListener().focusChanged(this, FOCUS_LOST);
   }

   /**
    * Changes the color of the button if a focus color has been set  and forces the
    * button to redraw.
    *
    * @param direction not used
    */
   protected void onFocus(int direction){
      hasFocus = true;
      if( this.getFocusListener() != null ) getFocusListener().focusChanged(this, FOCUS_GAINED);
   }

   public void setFocus() {
      hasFocus = true;
      super.setFocus();
   }

   /**
   * Sets whether a gradient is used to color the button. Default is true;
   *
   * @param b
   */
   public void useGradient(boolean b){
      useGradient = b;
   }

   /**
    * Sets whether to outline the button in white. Default is true;
    *
    * @param b
    */
   public void useOutline(boolean b){
      useOutline = b;
   }

   /**
   * Sets whether a back drop is drawn behind individual icons. Default is true;
   *
   * @param b
   */
   public void useBackground(boolean b){
      hideBorder = !b;
   }

   public void setAlwaysShowText(boolean b){ alwaysShowLabel = b; }

   public void setShowText(boolean b){ showText = b; }

   public void setChangeOnScroll(boolean b){ changeOnScroll = b; }

   /**
    * Redraws the button when it has gained focus.
    *
    * @param g the graphics object/context to draw on the button with
    * @param on not used
    */
   public void drawFocus(Graphics g, boolean on){
      paint(g);

      if( showText || alwaysShowLabel ){
         //now draw the text for the selected item
         if( defaultFont != null ){
            g.setFont( defaultFont );
         }
         if( fontSize > 0 ){
            g.setFont( getFont().derive(Font.PLAIN, fontSize, Ui.UNITS_px) );
         }

         int w = myWidth();
         int h = myHeight()-fontSize-2;
         int hh = fontSize>>>1;
         byte ep = Graphics.CURVEDPATH_END_POINT;
         byte cp = Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT;
         int [] xpt = { 0,0,8,w-8,w,w,w,w,w-8,8,0,0 };
         int [] ypt = { h+hh,h,h,h,h,h+hh,h+fontSize-hh,h+fontSize,h+fontSize,h+fontSize,h+fontSize,h+fontSize-hh };
         byte [] typ = { ep,cp,ep,ep,cp,ep,ep,cp,ep,ep,cp,ep };
         g.setGlobalAlpha( 128 );
         g.setColor( backgroundGradient );
         g.drawFilledPath(xpt, ypt, typ, null);
         g.setGlobalAlpha( fgAlpha );
         g.setColor(fontColor);
         CarouselItem item = (CarouselItem)choices.elementAt(selectedChoice);
         g.pushRegion(4, (myHeight()-fontSize)-2, myWidth()-8, fontSize+2, 0, 0);
         //g.drawText(item.description, 4, (myHeight()-fontSize)-2, DrawStyle.HCENTER, myWidth()-8);
         g.drawText(item.description, 0, 1, DrawStyle.HCENTER, myWidth()-8);
         g.popContext();
         g.setGlobalAlpha(255);
      }
   }

   public void paint(Graphics g){
      // Need to start drawing from middle of vector and move out to each end
      double itemAngle = 360 / choices.size();
      int startItem = choices.size()>>>1;
      int wRadius = (myWidth()-itemSize)>>>1;
      int hRadius = (myHeight()-(itemSize+fontSize+4))>>>1;
      int xstart = myWidth()>>>1;
      int ystart = hRadius;
      int xoff;
      int yoff;
      int angleOff = ((int)itemAngle)>>>1;
      if( angleOff == 0 ) angleOff = 1;
      int xleft = (int)(wRadius * Math.cos( Math.toRadians(90+(angleOff)) ));
      int xright = (int)(wRadius * Math.cos( Math.toRadians(90-(angleOff)) ));
      int xs;
      int iw = itemSize>>>1;
      int yadj = 0;
      CarouselItem item = null;
      selectedChanged = false;

//#ifdef DEBUG_APP
      System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
//#endif

      //Figure out selectedItem before drawing instead of while drawing
      for( int i=0; i<choices.size(); ++i ){
         xoff = (int)(wRadius * Math.cos( Math.toRadians((itemAngle * i) + 90 + offset) ));
         yoff = (int)(hRadius * Math.sin( Math.toRadians((itemAngle * i) + 90 + offset) ));
         xs = (xstart+xoff);

         if( ((xs) > (xstart+xleft)) && ((xs) < (xstart+xright)) && ((ystart+yoff) > ystart) ){
            if( i != selectedChoice ) selectedChanged = true;
            selectedChoice = i;
//#ifdef DEBUG_APP
            System.out.println("SELECTED CHOICE NOW: "+i+ " ********");
            System.out.println();
//#endif
            if( changeOnScroll && selectedChanged ){
               if( this.getChangeListener() != null ) this.getChangeListener().fieldChanged(this, -1);
            }
         }
      }

      Vector temp = new Vector();
      System.out.println();
      
      int half = choices.size()>>>1;
      if( (choices.size()%2) == 1) half++;
      for( int i=0; i<choices.size(); ++i ){
         temp.addElement( choices.elementAt((selectedChoice+i)%choices.size()) );
         System.out.println("Adding Item "+((selectedChoice+i)%choices.size()));
      }
                        
      iw = itemSize>>>1;
      double pcnt = 160 / (hRadius*2);
      double alpha = 1;
            
      for( int i=(half-1); i>=0; --i ){

         if( i != 0 ){

            item = (CarouselItem)temp.elementAt(i);

            //Left (i)
            xoff = (int)(wRadius * Math.cos( Math.toRadians((itemAngle * item.element) + 90 + offset) ));
            yoff = (int)(hRadius * Math.sin( Math.toRadians((itemAngle * item.element) + 90 + offset) ));

            xs = (xstart+xoff);
            
            int [] xpt2 = { xs-iw, xs-iw, xs-iw+8, xs+iw-8, xs+iw, xs+iw,
                            xs+iw, xs+iw, xs+iw-8, xs-iw+8, xs-iw, xs-iw };
            int [] ypt2 = { ystart+yoff+8, ystart+yoff, ystart+yoff, ystart+yoff, ystart+yoff, ystart+yoff+8,
                            ystart+yoff+itemSize-8, ystart+yoff+itemSize, ystart+yoff+itemSize,
                            ystart+yoff+itemSize, ystart+yoff+itemSize, ystart+yoff+itemSize-8 };
            byte [] typ2 = { Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                             Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                             Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                             Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT };

            alpha = 255 - (((hRadius*2)-(ystart+yoff)) * pcnt);
            g.setGlobalAlpha( (int)alpha - 64 );

            if( !hideBorder && (bgAlpha > 0) ){
               if( useGradient ){
                  int [] col2 = { backgroundColor, backgroundColor, backgroundColor, backgroundColor, backgroundColor, backgroundColor,
                                  backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient };
                  g.drawShadedFilledPath(xpt2, ypt2, typ2, col2, null);
               } else {
                  g.setColor( backgroundColor );
                  g.drawFilledPath(xpt2, ypt2, typ2, null);
               }

               g.setColor(fontColor);
               
               if( useOutline )
//#ifdef OS_ABOVE_5_0
                  g.drawOutlinedPath(xpt2,ypt2,typ2,null,true);
//#else
                  g.drawPathOutline(xpt2,ypt2,typ2,null,true);
//#endif
               g.setGlobalAlpha(255);
            }

            if( item.image.getHeight() < itemSize ) yadj = (itemSize-item.image.getHeight())>>>1;
            else yadj = 0;
            g.drawBitmap((xstart+xoff)-(item.image.getWidth()>>>1), (ystart+yoff+yadj),
                         item.image.getWidth(), item.image.getHeight(), item.image, 0, 0);
         }

         //Right (startItem+(startItem-i))
         if( (temp.size()-i) < temp.size() ){

            int n = temp.size()-i;

            
               item = (CarouselItem)temp.elementAt(n);

               xoff = (int)(wRadius * Math.cos( Math.toRadians((itemAngle * item.element) + 90 + offset) ));
               yoff = (int)(hRadius * Math.sin( Math.toRadians((itemAngle * item.element) + 90 + offset) ));

               xs = (xstart+xoff);
               
               int [] xpt3 = { xs-iw, xs-iw, xs-iw+8, xs+iw-8, xs+iw, xs+iw,
                               xs+iw, xs+iw, xs+iw-8, xs-iw+8, xs-iw, xs-iw };
               int [] ypt3 = { ystart+yoff+8, ystart+yoff, ystart+yoff, ystart+yoff, ystart+yoff, ystart+yoff+8,
                               ystart+yoff+itemSize-8, ystart+yoff+itemSize, ystart+yoff+itemSize,
                               ystart+yoff+itemSize, ystart+yoff+itemSize, ystart+yoff+itemSize-8 };
               byte [] typ3 = { Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                                Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                                Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                                Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT };

               alpha = 255 - (((hRadius*2)-(ystart+yoff)) * pcnt);
               g.setGlobalAlpha( (int)alpha - 64 );

               if( !hideBorder && (bgAlpha > 0) ){
                  if( useGradient ){
                     int [] col3 = { backgroundColor, backgroundColor, backgroundColor, backgroundColor, backgroundColor, backgroundColor,
                                     backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient };
                     g.drawShadedFilledPath(xpt3, ypt3, typ3, col3, null);
                  } else {
                     g.setColor( backgroundColor );
                     g.drawFilledPath(xpt3, ypt3, typ3, null);
                  }

                  g.setColor(fontColor);
                  
                  if( useOutline )
//#ifdef OS_ABOVE_5_0
                     g.drawOutlinedPath(xpt3,ypt3,typ3,null,true);
//#else
                     g.drawPathOutline(xpt3,ypt3,typ3,null,true);
//#endif
                  g.setGlobalAlpha(255);
               }

               if( item.image.getHeight() < itemSize ) yadj = (itemSize-item.image.getHeight())>>>1;
               else yadj = 0;
               g.drawBitmap((xstart+xoff)-(item.image.getWidth()>>>1), (ystart+yoff+yadj),
                            item.image.getWidth(), item.image.getHeight(), item.image, 0, 0);           
         }
      }

      g.setGlobalAlpha(255);

      //Draw startItem
      item = (CarouselItem)temp.elementAt(0);
      xoff = (int)(wRadius * Math.cos( Math.toRadians((itemAngle * item.element) + 90 + offset) ));
      yoff = (int)(hRadius * Math.sin( Math.toRadians((itemAngle * item.element) + 90 + offset) ));

      xs = (xstart+xoff);
      
      int [] xpt2 = { xs-iw, xs-iw, xs-iw+8, xs+iw-8, xs+iw, xs+iw,
                      xs+iw, xs+iw, xs+iw-8, xs-iw+8, xs-iw, xs-iw };
      int [] ypt2 = { ystart+yoff+8, ystart+yoff, ystart+yoff, ystart+yoff, ystart+yoff, ystart+yoff+8,
                      ystart+yoff+itemSize-8, ystart+yoff+itemSize, ystart+yoff+itemSize,
                      ystart+yoff+itemSize, ystart+yoff+itemSize, ystart+yoff+itemSize-8 };
      byte [] typ2 = { Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                       Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                       Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT,
                       Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT, Graphics.CURVEDPATH_END_POINT };
      if( useGradient ){
         if( hasFocus ){
            int [] col2 = { focusColor, focusColor, focusColor, focusColor, focusColor, focusColor,
                            focusGradient, focusGradient, focusGradient, focusGradient, focusGradient, focusGradient };
            g.drawShadedFilledPath(xpt2, ypt2, typ2, col2, null);
         } else {
            int [] col2 = { backgroundColor, backgroundColor, backgroundColor, backgroundColor, backgroundColor, backgroundColor,
                            backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient, backgroundGradient };
            g.drawShadedFilledPath(xpt2, ypt2, typ2, col2, null);
         }
      } else {
         if( hasFocus ){
            g.setColor( focusColor );
            g.drawFilledPath(xpt2, ypt2, typ2, null);
         } else {
            g.setColor( backgroundColor );
            g.drawFilledPath(xpt2, ypt2, typ2, null);
         }
      }

      g.setColor(fontColor);
      
      if( useOutline )
//#ifdef OS_ABOVE_5_0
         g.drawOutlinedPath(xpt2,ypt2,typ2,null,true);
//#else
         g.drawPathOutline(xpt2,ypt2,typ2,null,true);
//#endif

      if( item.image.getHeight() < itemSize ) yadj = (itemSize-item.image.getHeight())>>>1;
      else yadj = 0;
      g.drawBitmap((xstart+xoff)-(item.image.getWidth()>>>1), (ystart+yoff+yadj),
                   item.image.getWidth(), item.image.getHeight(), item.image, 0, 0);
   }

   //===============================================================================================//

   public boolean myNavigationMovement(int dx, int dy, int status, int time){
      return this.navigationMovement(dx, dy, status, time);
   }
   
   protected boolean navigationMovement(int dx, int dy, int status, int time) {
      int itemAngle = 360 / choices.size();
      if( dx > 0 ){
         offset += itemAngle>>>1;
      } else if( dx < 0 ){
         offset -= itemAngle>>>1;
      }
      return true;
   }

   protected boolean navigationClick(int status, int time) {
      if( this.getChangeListener() != null ) this.getChangeListener().fieldChanged(this, selectedChoice);
      return true;
   }
   
//#ifdef OS_ABOVE_4_7
   public boolean myTouchEvent(TouchEvent t){
      return touchEvent(t);
   }

   protected synchronized boolean touchEvent(TouchEvent t){
      int x = t.getX(1);
      int event = t.getEvent();
      switch( event ){
         case TouchEvent.DOWN:
              prevx = x;
              break;
         case TouchEvent.MOVE:
              if( Math.abs(x-prevx) > 10 ){
                 if( (x-prevx) > 0 ) offset -= 10;
                 else offset += 10;
              } else {
                 offset -= (x - prevx);
              }
              prevx = x;
              break;
         case TouchEvent.CLICK:
              if( this.getChangeListener() != null ) this.getChangeListener().fieldChanged(this, selectedChoice);
              return true;
         default:
              break;
      }
      return super.touchEvent(t);
   }
//#endif
   
   /**
    * Returns true to show that the button can gain focus
    *
    * @return true
    */
   public boolean isFocusable(){
      return true;
   }

   /**
    * Allows user to set the color of the background. Defaults to 0x444444.
    *
    * @param c the default background color of the button
    */
   public void setColor( int c ){
      backgroundColor = c;
      invalidate();
   }

   public void setBackgroundAlpha(int alpha){ bgAlpha = alpha; }
   public void setForegroundAlpha(int alpha){ fgAlpha = alpha; }

   public void setGradient(int c){
      backgroundGradient = c;
      useGradient = true;
   }

   /**
    * Allows user to set the focused color of the background. Defaults to 0x444444.
    *
    * @param c the color to change the background when the button has the focus
    */
   public void setFocusColor( int c ){
      focusColor = c;
   }

   public void setFocusGradient(int c){
      focusGradient = c;
      useGradient = true;
   }

   /**
    * Allows user to set the font color of the text. Defaults to 0xFFFFFF.
    *
    * @param c the color to change the font to
    */
   public void setFontColor( int c ){
      fontColor = c;
      invalidate();
   }

   public void setFont(Font f){
      defaultFont = f;
   }

   public void setFontSize(int s){
      fontSize = s;
   }

   /**
   **
   ** @return the x position of the field within its manager
   */
   public int getX(){
      int xpos = xPos;
      int index = getIndex();
      if( index > 0 ){
         MyField tmp = ((MyField)getManager().getField(index-1));

         if( xpos == MyField.POS_ALIGN_LEFT )   return tmp.getX();
         if( xpos == MyField.POS_FLOAT_LEFT )   return tmp.getX()-myWidth();
         if( xpos == MyField.POS_ALIGN_RIGHT )  return (tmp.getX()+tmp.myWidth())-myWidth();
         if( xpos == MyField.POS_FLOAT_RIGHT )  return tmp.getX()+tmp.myWidth();
      } else {
         if( xpos == MyField.POS_ALIGN_LEFT )  return 0;
         if( xpos == MyField.POS_FLOAT_LEFT )  return 0;
         if( xpos == MyField.POS_ALIGN_RIGHT ) return 0;
         if( xpos == MyField.POS_FLOAT_RIGHT ) return 0;
      }

      if( xpos == MyField.POS_ALIGN_CENTER ) return (((MyField)getManager()).myWidth()-myWidth())/2;
      if( xpos == MyField.POS_MGR_FLT_RGT )  return (((MyField)getManager()).myWidth()-myWidth());
      
      return xPos;
   }

   public void changeX(int x){ xPos = x; }

   public void moveX(int x){ xPos += x; }

   /**
   **
   ** @return the y position of field within its manager
   */
   public int getY(){
      int ypos = yPos;
      int index = getIndex();
      if( index > 0 ){
         MyField tmp = ((MyField)getManager().getField(index-1));

         if( ypos == MyField.POS_ALIGN_TOP )    return tmp.getY();
         if( ypos == MyField.POS_FLOAT_ABOVE )  return tmp.getY()-myHeight();
         if( ypos == MyField.POS_ALIGN_BOTTOM ) return (tmp.getY()+tmp.myHeight())-myHeight();
         if( ypos == MyField.POS_FLOAT_BELOW )  return tmp.getY()+tmp.myHeight();
      } else {
         if( ypos == MyField.POS_ALIGN_TOP )    return 0;
         if( ypos == MyField.POS_FLOAT_ABOVE )  return 0;
         if( ypos == MyField.POS_ALIGN_BOTTOM ) return 0;
         if( ypos == MyField.POS_FLOAT_BELOW )  return 0;
      }
      if( ypos == MyField.POS_ALIGN_CENTER ) return (((MyField)getManager()).myHeight()-myHeight())/2;
      if( ypos == MyField.POS_MGR_FLT_BTM )  return (((MyField)getManager()).myHeight()-myHeight());
      return yPos;
   }

   public void changeY(int y){ yPos = y; }

   public void moveY(int y){
      if( (yPos < 10120) || (yPos > 10123) )
         yPos += y;
   }

   /**
   **
   ** @return the width of the field
   */
   public int myWidth(){
      if( width == MyField.FULLWIDTH ) return Display.getWidth();
      if( width == MyField.HALFWIDTH ) return Display.getWidth() / 2;
      if( width == MyField.THIRDWIDTH ) return Display.getWidth() / 3;
      if( width == MyField.QUARTERWIDTH ) return Display.getWidth() / 4;
      if( width == MyField.TWOTHIRDWIDTH ) return (Display.getWidth() * 2) / 3;
      if( width == MyField.THREEQUARTERWIDTH ) return (Display.getWidth() * 3) / 4;
      if( width == MyField.FIFTHWIDTH) return (Display.getWidth() / 5);
      if( width == MyField.TWOFIFTHWIDTH) return (Display.getWidth() * 2) / 5;
      if( width == MyField.THREEFIFTHWIDTH) return (Display.getWidth() * 3) / 5;
      if( width == MyField.FOURFIFTHWIDTH) return (Display.getWidth() * 4) / 5;

      if( width == MyField.PCNT_10_WIDTH) return (Display.getWidth() / 10);
      if( width == MyField.PCNT_30_WIDTH) return (Display.getWidth() * 3) / 10;
      if( width == MyField.PCNT_70_WIDTH) return (Display.getWidth() * 7) / 10;
      if( width == MyField.PCNT_90_WIDTH) return (Display.getWidth() * 9) / 10;

      if( width == MyField.MGR_FULLWIDTH ) return ((MyField)getManager()).myWidth();
      if( width == MyField.MGR_HALFWIDTH ) return ((MyField)getManager()).myWidth() / 2;
      if( width == MyField.MGR_THIRDWIDTH ) return ((MyField)getManager()).myWidth() / 3;
      if( width == MyField.MGR_QUARTERWIDTH ) return ((MyField)getManager()).myWidth() / 4;
      if( width == MyField.MGR_TWOTHIRDWIDTH ) return (((MyField)getManager()).myWidth() * 2) / 3;
      if( width == MyField.MGR_THREEQUARTERWIDTH ) return (((MyField)getManager()).myWidth() * 3) / 4;
      if( width == MyField.MGR_FIFTHWIDTH) return (((MyField)getManager()).myWidth() / 5);
      if( width == MyField.MGR_TWOFIFTHWIDTH) return (((MyField)getManager()).myWidth() * 2) / 5;
      if( width == MyField.MGR_THREEFIFTHWIDTH) return (((MyField)getManager()).myWidth() * 3) / 5;
      if( width == MyField.MGR_FOURFIFTHWIDTH) return (((MyField)getManager()).myWidth() * 4) / 5;

      if( width == MyField.MGR_PCNT_10_WIDTH) return (((MyField)getManager()).myWidth() / 10);
      if( width == MyField.MGR_PCNT_30_WIDTH) return (((MyField)getManager()).myWidth() * 3) / 10;
      if( width == MyField.MGR_PCNT_70_WIDTH) return (((MyField)getManager()).myWidth() * 7) / 10;
      if( width == MyField.MGR_PCNT_90_WIDTH) return (((MyField)getManager()).myWidth() * 9) / 10;

      if( width == MGR_MINUS_10 ) return ((MyField)getManager()).myWidth()-10;
      if( width == MGR_MINUS_20 ) return ((MyField)getManager()).myWidth()-20;
      if( width == MGR_MINUS_30 ) return ((MyField)getManager()).myWidth()-30;
      if( width == MGR_MINUS_40 ) return ((MyField)getManager()).myWidth()-40;
      if( width == MGR_MINUS_50 ) return ((MyField)getManager()).myWidth()-50;
      if( width == MGR_MINUS_60 ) return ((MyField)getManager()).myWidth()-60;
      if( width == MGR_MINUS_70 ) return ((MyField)getManager()).myWidth()-70;
      if( width == MGR_MINUS_80 ) return ((MyField)getManager()).myWidth()-80;
      if( width == MGR_MINUS_90 ) return ((MyField)getManager()).myWidth()-90;
      if( width == MGR_MINUS_100 ) return ((MyField)getManager()).myWidth()-100;

      return width;
   }

   public void setWidth(int w){
      width = w;
   }

   /**
   **
   ** @return the height of the field
   */
   public int myHeight(){
      if( height == MyField.FULLHEIGHT ) return Display.getHeight();
      if( height == MyField.HALFHEIGHT ) return Display.getHeight() / 2;
      if( height == MyField.THIRDHEIGHT ) return Display.getHeight() / 3;
      if( height == MyField.QUARTERHEIGHT ) return Display.getHeight() / 4;
      if( height == MyField.TWOTHIRDHEIGHT ) return (Display.getHeight() * 2) / 3;
      if( height == MyField.THREEQUARTERHEIGHT ) return (Display.getHeight() * 3) / 4;
      if( height == MyField.FIFTHHEIGHT) return (Display.getHeight() / 5);
      if( height == MyField.TWOFIFTHHEIGHT) return (Display.getHeight() * 2) / 5;
      if( height == MyField.THREEFIFTHHEIGHT) return (Display.getHeight() * 3) / 5;
      if( height == MyField.FOURFIFTHHEIGHT) return (Display.getHeight() * 4) / 5;

      if( height == MyField.PCNT_10_HEIGHT) return (Display.getHeight() / 10);
      if( height == MyField.PCNT_30_HEIGHT) return (Display.getHeight() * 3) / 10;
      if( height == MyField.PCNT_70_HEIGHT) return (Display.getHeight() * 7) / 10;
      if( height == MyField.PCNT_90_HEIGHT) return (Display.getHeight() * 9) / 10;

      if( height == MyField.MGR_FULLHEIGHT ) return ((MyField)getManager()).myHeight();
      if( height == MyField.MGR_HALFHEIGHT ) return ((MyField)getManager()).myHeight() / 2;
      if( height == MyField.MGR_THIRDHEIGHT ) return ((MyField)getManager()).myHeight() / 3;
      if( height == MyField.MGR_QUARTERHEIGHT ) return ((MyField)getManager()).myHeight() / 4;
      if( height == MyField.MGR_TWOTHIRDHEIGHT ) return (((MyField)getManager()).myHeight() * 2) / 3;
      if( height == MyField.MGR_THREEQUARTERHEIGHT ) return (((MyField)getManager()).myHeight() * 3) / 4;
      if( height == MyField.MGR_FIFTHHEIGHT) return (((MyField)getManager()).myHeight() / 5);
      if( height == MyField.MGR_TWOFIFTHHEIGHT) return (((MyField)getManager()).myHeight() * 2) / 5;
      if( height == MyField.MGR_THREEFIFTHHEIGHT) return (((MyField)getManager()).myHeight() * 3) / 5;
      if( height == MyField.MGR_FOURFIFTHHEIGHT) return (((MyField)getManager()).myHeight() * 4) / 5;

      if( height == MyField.MGR_PCNT_10_HEIGHT) return (((MyField)getManager()).myHeight() / 10);
      if( height == MyField.MGR_PCNT_30_HEIGHT) return (((MyField)getManager()).myHeight() * 3) / 10;
      if( height == MyField.MGR_PCNT_70_HEIGHT) return (((MyField)getManager()).myHeight() * 7) / 10;
      if( height == MyField.MGR_PCNT_90_HEIGHT) return (((MyField)getManager()).myHeight() * 9) / 10;

      if( height == MGR_MINUS_10 ) return ((MyField)getManager()).myHeight()-10;
      if( height == MGR_MINUS_20 ) return ((MyField)getManager()).myHeight()-20;
      if( height == MGR_MINUS_30 ) return ((MyField)getManager()).myHeight()-30;
      if( height == MGR_MINUS_40 ) return ((MyField)getManager()).myHeight()-40;
      if( height == MGR_MINUS_50 ) return ((MyField)getManager()).myHeight()-50;
      if( height == MGR_MINUS_70 ) return ((MyField)getManager()).myHeight()-70;
      if( height == MGR_MINUS_80 ) return ((MyField)getManager()).myHeight()-80;
      if( height == MGR_MINUS_90 ) return ((MyField)getManager()).myHeight()-90;
      if( height == MGR_MINUS_100 ) return ((MyField)getManager()).myHeight()-100;

      return height;
   }

   public void setHeight(int h){
      height = h;
   }

   public String getText(){ 
      CarouselItem item = (CarouselItem)choices.elementAt(selectedChoice);
      return item.description;
   }
   public void setText(String txt){ }

   public void mypaint(Graphics g){
      if( hasFocus || alwaysShowLabel ){
         drawFocus(g,true);
      } else {
         paint(g);
      }
   }

   public void forceFocus(){ }
   public void removeFocus(){ hasFocus = false; }

   public void setToolTip(ToolTip t){ tip = t; }
   public ToolTip getToolTip(){ return tip; }

   public void setTextJustify(int i){ }

   public void setTouchEnabled(boolean b){ touchEnabled = b; }
   public boolean getTouchEnabled(){ return touchEnabled; }

   public void addUiTimer(Timer t){ timer = t; }

   //****************************************************************************************************//

   private class CarouselItem {
      String name,description;
      Bitmap image;
      Runnable action;
      int element;

      CarouselItem(String n,String b,int pos,Runnable r){
         name = n;
         description = n;
         element = pos;
         action = r;

         EncodedImage enc = EncodedImage.getEncodedImageResource(b);

         int ratio2 = Fixed32.div(Fixed32.toFP(enc.getWidth()), Fixed32.toFP(itemSize));
         int ratio3 = Fixed32.div(Fixed32.toFP(enc.getHeight()), Fixed32.toFP(itemSize));
         int ratio = ratio2;
         if( ratio3 > ratio2 ) ratio = ratio3;

         image = enc.scaleImage32( ratio, ratio ).getBitmap();
      }

      CarouselItem(String n,String desc,String b,int pos,Runnable r){
         description = desc;
         name = n;
         element = pos;
         action = r;

         EncodedImage enc = EncodedImage.getEncodedImageResource(n,b);

         int ratio2 = Fixed32.div(Fixed32.toFP(enc.getWidth()), Fixed32.toFP(itemSize));
         int ratio3 = Fixed32.div(Fixed32.toFP(enc.getHeight()), Fixed32.toFP(itemSize));
         int ratio = ratio2;
         if( ratio3 > ratio2 ) ratio = ratio3;

         image = enc.scaleImage32( ratio, ratio ).getBitmap();
      }
   }

}

 

Regular Contributor
Posts: 65
Registered: ‎06-13-2011
My Device: mini curve

Re: Spiral / Rotation Menu Control ?

yes 

Contributor
Posts: 12
Registered: ‎09-01-2010
My Device: Storm 2

Re: Spiral / Rotation Menu Control ?

Hi 

 

I am not sure if you are still around working on BB, But if you are I would be grateful if you could help me use this Field.

Can you please explain to me what is the Runnable object passed for ? 

 

Thanks

Pradeep 

 

Pradeep G.
BB Developer
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Spiral / Rotation Menu Control ?

I use the runnable so that each item in the field could perform a different action. For example I use this field as a launcher for different sub-applications within a game suite I wrote. So each item in the field launches a different mini-game, and the runnable contains the instructions to launch it.