Adding key event to different parts of a pie chart

Hi, I'm working on a Blackberry app I need to create pie chart from an array of integers. Unfortunately I could not find any graphics APIs for Blackberry (is there really one?), so I've implemented using the method (graphics.fillArc).

Here's my PieChart class:

public class PieChart extends Field
{
    //declaring private variables to store data
    private int[] percentage;
    private int[] angles;
    private int totalRecords;

    //declaring colors to be used in pie chart
    private final static int[] availableColors = { 0x00CDCD, 0xFF0000, 0xFF00FF, 0xCC9900, 0x9900FF, 0x990000, 0x66FF00, 0x6600FF, 0x3300FF, 0x0000FF};
    private final static int totalAvailableColors = 10;

    //assuming 250 for chart width and height
    private int chartWidth = 250;
    private int chartHeight = 250;

    public PieChart (int[] marks)
    {
        //calculating percentages and angles covered by each record
        totalRecords = marks.length;
        int sum = 0;
        for (int i = 0; i < totalRecords; i ++)
            sum += marks[i];
        percentage = new int[totalRecords];
        angles = new int[totalRecords];
        for (int i = 0; i < totalRecords; i ++)
        {
            double percent = marks[i] * 100 / sum;
            percentage[i] = (int) percent;
            angles[i] = (int) (percent * 3.6);
        }
    }

    protected void layout(int width, int height)
    {
        //setting the field to cover the whole width of display
        setExtent (Display.getWidth(), chartHeight);
    }

    protected void paint(Graphics graphics)
    {
        //generating a random color from predefined colors
        Random random = new Random();
        int lastAngle = 0;
        int previousColorIndex = -1;
        int startColorIndex = random.nextInt(totalAvailableColors);
        int currentColorIndex = startColorIndex;

        //adding offset to create the chart at center of the screen
        int offset = (Display.getWidth() - chartWidth)/ 2;

        for (int i = 0; i < totalRecords; i ++)
        {
            //if last record, cover the remaining area of the circle
            int finishAngle = i == totalRecords - 1 ? 360 - lastAngle : angles[i];

            //drawing the arc
            graphics.setColor(availableColors[currentColorIndex]);
            graphics.fillArc(offset, 0, chartWidth, chartHeight, lastAngle, finishAngle);

            //calculating text position to print the percentage
            int txtX = (int) (125 + 75 * Math.cos(Math.PI * (lastAngle + angles[i] / 2)/180));
            int txtY = (int) (125 - 75 * Math.sin(Math.PI * (lastAngle + angles[i] / 2)/180));
            txtX -= graphics.getFont().getAdvance(String.valueOf(percentage[i] + "%")) / 2;

            //drawing the percentage over the respective section
            graphics.setColor(Color.WHITE);
            graphics.drawText(String.valueOf(percentage[i] + "%"), txtX + offset, txtY);
            previousColorIndex = currentColorIndex;

            //tracking total angle used so far
            lastAngle += angles[i];

            //checking if color generated is previous color or starting color, if it is the last of the record
            do
            {
                currentColorIndex = random.nextInt(totalAvailableColors);
            }
            while ((i == totalRecords - 1 && currentColorIndex == startColorIndex) || currentColorIndex == previousColorIndex);
        }

    }

}

Now, when the user touches a any part of the generated pie chart, I need to show him the details of this particular section, which is different for different parts of the chart (for example. Say that if brands of students is used, during the click on an article I have need to display information about the marker). From my understanding, different parts of the pie chart must be different fields to contain the touch individual events. However, it seems there is no way to create irregular fields, and I can't reach camembert if I use fields rectangular for different parts of the chart (such as it's going to tear the pie! ).

Any suggestions?

BTW I develop for BB OS 6.0 (Blackberry Torch).

The word dreaded no programmer doesn't want to hear: math. You'll just have to figure out where all of your divisions are based off of their percentages, determine where the touch and then discover what segment is in.

In fact, I don't think it's going to be too bad, just refresh you on geometry.

Tags: BlackBerry Developers

Similar Questions

  • Why don't the mpg2 files allow to move to different parts of the clip in XP? Vista lets me.

    Hello.

    Why don't the mpg2 files allow to move to different parts of the clip in XP? Vista lets me.

    Desktop: Windows XP 32-bit Home Edition. Laptop: Windows Vista Home Premium 64-bit.

    I have a DVD I paid for and used a software to copy video clips (unprotected) to mpeg2 files. There are 4 of them. It was a DVD recorded in 2004 at a dance event. It is not a commercial version.

    XP: The 1st clip allows me to open it in Windows Media Player 11 and I can drag autour in various places to look at different times of the clip. The clip of 2nd, 3rd and 4th are locked and won't let me pick different times to watch. They will play through.

    In Vista: I can't the cursor around anywhere, then select any time to look into all parts of clips with THE 4 clips.

    I took the clips, put them on a USB stick, moved in both sense between each system. I tried two more than once.

    I used the software to rip the clips on XP and Vista. It's the same result. The fault seems to lie with XP.

    Perhaps some of this DVD had some kind of protection against copying for XP but not Vista (and other OS of potentially). Or it's the encoder?

    My account has been locked or something, I couldn't answer.

    It is therefore probably encriptación with Windows Media player. I can read files with RealPlayer on Windows XP and Vista in Windows Media Player.

    Tried to use my software for video editing, re - export files in mpeg2. But each of them had sound problems. So, this is how the DVD is probably protected.

    I have something on Vista operating systems and a workaround with XP using RealPlayer for the original files. I'll keep looking. It's mine to archive all I want at this stage.

  • No key event is generated from mac book pro trackpad

    I'm developing an application in javafx multiltouch on mac, but no key event was taken by the Manager using the trackpad. Event handlers are added to the scene.

    I use JDK1.7.0_07.

    Someone has an idea.

    Thank you.

    I don't think it will work. The javadocs for the TouchEvent explicitly state

    "Touch event indicates a touchscreen action."

    The trackpad isn't a touch screen.

    The trackpad will generate GestureEvents. Once again, since the javadocs:

    "Actions are usually caused by direct (touch screen) or indirect (track pad) touch events."

    If you can handle things like ScrollEvent, RotateEvent and ZoomEvent. I think that the mapping between the physical gestures on the trackpad and semantic events is managed by the operating system (if the behaviour could change if the user changes the settings for trackpad in system preferences, for example). It doesn't look like it will answer to your needs, but maybe...

    I don't know if there is another way to interact with the trackpad (someone else surely will).

    Here is a simple way to see which events are generated (it will generate a lot of output).

    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.input.InputEvent;
    import javafx.scene.layout.AnchorPane;
    import javafx.stage.Stage;
    
    public class TouchTest extends Application {
    
      @Override
      public void start(Stage primaryStage) throws Exception {
        Scene scene = new Scene(new AnchorPane(), 400,400);
        scene.addEventHandler(InputEvent.ANY, new EventHandler() {
          @Override
          public void handle(InputEvent event) {
            System.out.println(event.getEventType().getName());
          }
        });
        primaryStage.setScene(scene);
        primaryStage.sizeToScene();
        primaryStage.show();
      }
    
      public static void main(String[] args) {
        launch(args);
      }
    
    }
    
  • Best way to add words to the different parts of the frame?

    There are sometimes opportunities when I want to put the text on different parts of the screen, possibly with different fonts sizes and colors etc.

    On this occasion, I'm going to fill in the spaces in the jury of the Clap below.

    Is there a quick way to do it using a single title I can position each word (or groups of words) exactly where I want to?

    Or do I just add writing in Photoshop? This would limit still edit in FCP X.

    To add the likelihood that I will use fonts like marker felt, slate etc.

    Change the fonts and sizes is normally done in any title - just select the text and apply the changes. No need for a special title for this.

    To move the text independently:

    It is very easy to create a title in movement with more than one piece of text - this is a title with two layers of separate text:

    By posting the Position for each text, you can place and move independently.

    This will appear in the tab title of the Inspector instead of the video tab.

    In a quick test, I could not change the name of the parameter, but it works very well

    :

  • In the visualization of my photos display problem: I have red spots in different parts of the pictures. Someone knows how to fix this?  I rebooted my MacBook Pro, but it does not solve the problem.

    In the visualization of my photos display problem: I have red spots in different parts of the pictures. Someone knows how to fix this?  I rebooted my MacBook Pro, but it does not solve the problem.

    Details please

    What version of Aperture? Is OS X 10.7.5 as you say correct for your OS? You shoot JPEG or RAW? If RAW device? Wharton has changed since this worked?

    LN

  • Pages - selection of different parts of the text at the same time

    The old version of Pages used to have a really useful feature that allowed you to select the different parts of a text at the same time by pressing the command at the same time you did drag the cursor over the text you want to select.

    This feature doesn't seem to be available on the new version, which is a shame because it was really, really useful.

    Is there another way to select different parts of a text at the same time?

    I would be really grateful if someone could find a solution!

    Any rejection of Pages v5 supports non-contiguous text selection. No tricks to work around this design limitation. You may always continue to use Pages ' 09 v4.3 If you wanted these "professional" features of return.

  • Satellite A205 - S4629 BIOS Update Fail - file has different part number of BIOS

    I used the download from Toshiba support page to identify my notebook A205-S4629 Satellite of model and downloaded the following BIOS update utility sa200f0v520.exe.

    After construction the IOS Installer disk and running the Phoenix Phlash16 utility I get the following message "file a different part number of BIOS.

    The utility uses the image file after MW10M520.ROM.

    Any contribution is appreciated,

    Thank you

    Hello

    As far as I know the BIOS package downloaded from the Toshiba WE page driver contains the ZIP file self-extracting WinRAR 32-bit which includes both based on Windows and disk according to the BIOS update installation options.

    Have you tried to update the BIOS using the BIOS Win-based?

    What operating system do you use?

  • Cancel key event is not sent immediately

    It is a question for the gurus of management of key events. The problem I have is this: I have two containers A and B which are side by side and are equal in size and shape. If a finger touches the first A container, a touchdown event is generated on A. As your finger moves on a container, then touch MOVE events are generated. When the finger leaves container and begins to touch the container B, touch MOVE events are generated on B. When the finger is released during a B, CANCEL button is generated A and then b. touch UP

    Is it possible to receive on A CANCEL key as soon as the finger stops to touch a container?

    Thank you!

    On further investigation, I found a better solution that uses the onTouchEnter and the onTouchExit. As soon as the press finger leaves A container, onTouchExit is issued. As the finger enters container B onTouchEnter is issued. When the finger is released during a B, only editing event is released.

  • Key events of injection, but couldn't find what corresponds to the BB button?

    I'm trying to inject a key event to simulate the user after pressing the Menu button - IE the one with the logo of BB, which is triggered by pressing Insert on the Simulator. I tried to use Keypad.KEY_APPLICATION (0x15), Keypad.KEY_MIDDLE (0 x 13), Keypad.KEY_MENU (0 x 1002) and there is no result to inject these keys at all. All the other keys I try to inject seems to work very well. There is another constant, should I use?

    Using the JDE 4.3.0.1r version and the 8120 Simulator, if that makes a difference.

    Nevermind, I got it works using a KeyCodeEvent instead of a KeyEvent...

  • Capture key events

    Is there a way to cpture key events in webworks. I wanted to remove items from my database when you press the delete key native.

    Please check the event onHardwareKey

  • How to listen to key events when App in background mode.

    My application is running at startup and I want to capture "key events", while my app running in the background.

    Only the app with focus can capture key events.

  • Key events on the fields in the custom horizontalfield Manager

    Hi all

    I created the screen with a title bar and toolbar.

    The toolbar is created with a HorizontalFieldManager.

    Toolbar contains three BitmapField and a LabelField.

    How can I manage the key events of the fields in the HorizontalFieldManager.

    Where I need to override the keyChar() method.

    I did something wrong here. I do not receive the dialog box by pressing the Enter key. It is moving to the next icon that's all.

    I can move each icon by using the arrow keys, it is also developed. But when I press the Enter key, it goes to the next icon.

    I want to show the new screen by pressing the Enter key on each icon in the HorizontalFieldManager.

    How can I solve this problem... Any help...

    Override KeyDown() in your screen. As:

        public boolean keyDown(int keycode, int time)
        {
            System.out.println("Enter key pressed!");
            if (icon1.isFocus())
                Dialog.inform("show page1");
            else if (icon2.isFocus())
                Dialog.inform("show page2");
            else
                Dialog.inform("show page3");
    
            return true;
        }
    

    Concerning

    Bika

  • How to manage send / phone key end / Power key events?

    How to follow the sending key event / Phone key (green key) and end / Power (red button) button in the Blackberry device?

    You can use this feature to manage key events in red and green button

    public boolean keyDown(int keycode, int time)
        {
         switch(keycode)
         {
             case keycode.KEY_END:
    
                 break;
            case keycode.KEY_SEND:
    
                System.exit(0);
                break;
               }
         return false;
        }
    

    If your problem has been resolved then please mark the thread as "Accepted Solution" and congratulations - your wish.

  • I want to run a SWF in several screens, is - it possible a .swf can divided into different part and meet

    I have a flash file, I want to split application in 4 different part and individually run on 4 different screens (monitors o/p). If this is then can not possible I develop 4 rows of 4 different screens, but how they can jointly associated with one application.

    I have the application developed in Adobe Flash CC but no problem to switch technology. Please suggest...

    Thank you

    Maury

    Yes, you should be able to do it with a bit of CODE.

    Apply a transformation scene (scaleX = 2, scaleY = 2) and change the x / y position corresponding to higher positions left, upper right, lower left, lower right.

    The export of 4 different sovereign such as each of them show only a quarter of the original film after processing and implementation in different points of view.

  • How to divide the screen into two parts in order to see the two different parts of the same file? [Suggestion] [Android]

    I am Brazilian and I use Adobe Acrobat Reader DC a lot. I would suggest an implementation of features present in the PC, I missed a lot of things on Android, which is 'New window' or something like that, like split the screen into two parts in order to see the two different parts of the same file.

    For smartphones, its use is restricted, but for tablets, it can be really useful, because it allows the display of two distinct points of the same file,

    I have reduced considerably the use of paper using this application, however, I need to navigate the file always pick up a few points seen earlier, which causes a lot of discomfort compared to printed documents.

    This is a suggestion, but I would like it to be considered.

    Thank you for your request. We have taken note of the same and must try to integrate it into one of our future releases.

    Thank you.

Maybe you are looking for