Search code examples
audioblackberrytext-to-speech

disabling sound in a single application in blackberry


I just did a dictionary application in blackberry along with a speech to text conversion support .Everything is working fine. Now i wanted to disable the sound when the user needs So how can i do it programmatically .Please help me


Solution

  • Try this

    use the flag value as reference
    
    
    if flag value is true then user click on item then it will play the sound
    else sound wont play and display one dialog that Do you want enable sound with two options yes or no 
                if user click on yes then make flag value as true and item.setText("Voice Disable"); otherwise no action means no changes in flag
                 in your list item click listener write condition as following
                if(flag==true)
                {
                    write your logic to play
                }
    

    sample code is

    public class app extends UiApplication{
    
    
        public static void main(String[] args) {
            new app().enterEventDispatcher();
        }
    
        public app() {
            pushScreen(new SampleScreen()); 
        }
    }
    class SampleScreen extends MainScreen
    {
        static boolean flag=true;
        MenuItem item=null;
        public SampleScreen() {
    
    //      use the flag value as reference
    //      if flag value is true then user click on item then it will play the sound
    //      else sound wont play and display one dialog that Do you want enable sound with two options yes or no 
    //      if user click on yes then make flag value as true and item.setText("Voice Disable"); otherwise no action means no changes in flag
    //       in your list item click listner write condition as following
    //      if(flag==true)
    //      {
    //          write your logic to play
    //      }
    
    
    
            // you already implement 
    
            item=new MenuItem("Voice Disable",0,100) {
                public void run() {
                    if(flag)
                    {
                        flag=false;
                        item.setText("Voice Enable");
                        UiApplication.getUiApplication().invokeLater(new Runnable() {
                            public void run() {
                                Dialog.inform("Voice Disable succesfully");
                            }
                        });
                    }else{
                        flag=true;
                        item.setText("Voice Disable");
                        UiApplication.getUiApplication().invokeLater(new Runnable() {
                            public void run() {
                                Dialog.inform("Voice Enable succesfully");
                            }
                        });
                    }
    
                }
            };
            addMenuItem(item);
    
        }
    }