private Vector getAayaList(int surahNumber, int surahpart) {
    final Vector vector = new Vector();
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser;
    DefaultHandler handler;
    InputStream inputStream;
    try {

      saxParser = factory.newSAXParser();

      handler =
          new DefaultHandler() {

            boolean surah = false;
            String text;

            public void startElement(
                String uri, String localName, String qName, Attributes attributes)
                throws SAXException {

              if (qName.equalsIgnoreCase("a")) {
                text = attributes.getValue("n") + ". ";
                surah = true;
              }
            }

            public void characters(char ch[], int start, int length) throws SAXException {

              if (surah) {
                vector.addElement(text + new String(ch, start, length));
                surah = false;
                text = null;
              }
            }
          };

      inputStream =
          getClass().getResourceAsStream("/res/quran/" + surahNumber + "_" + surahpart + ".xml");
      //            Reader reader = new InputStreamReader(inputStream, "UTF-8");
      //
      //            InputSource is = new InputSource(reader);
      //            is.setEncoding("UTF-8");
      if (inputStream == null) {
        Dialog.show(null, "inputStream null", "OK", null);
      }

      saxParser.parse(inputStream, handler);
    } catch (Exception e) {
      e.printStackTrace();
      Dialog.show(null, "getAayaList Exception", "OK", null);
    } finally {
      factory = null;
      saxParser = null;
      handler = null;
      inputStream = null;
    }
    return vector;
  }
  protected void onSurah_ListSurahAction(Component c, ActionEvent event) {
    // If the resource file changes the names of components this call will break notifying you that
    // you should fix the code
    super.onSurah_ListSurahAction(c, event);
    try {
      List l = (List) c;
      String name = (String) l.getSelectedItem();
      selectedSurahNumber = Integer.parseInt(name.substring(0, name.indexOf(".")));

      if (selectSurah != null) {
        selectSurah.released();
      } else {
        Dialog.show(null, "selectSurah null", "OK", null);
      }
      name = null;
    } catch (Exception e) {
      Dialog.show(null, "onSurah_ListSurahAction excepption", "OK", null);
    }
  }
 protected void beforeSurah(Form f) {
   // If the resource file changes the names of components this call will break notifying you that
   // you should fix the code
   super.beforeSurah(f);
   try {
     selectSurah = findSurahSelect(f);
     selectSurah.setVisible(false);
   } catch (Exception e) {
     Dialog.show(null, "beforeSurah excepption", "OK", null);
   }
 }
 private Vector parseWallpaperThumbnailJSON(String response, List cmp) {
   Vector resultVector = new Vector();
   Image blank = Image.createImage(50, 50);
   try {
     JSONObject jSONObject = new JSONObject(response);
     System.out.println(jSONObject);
     Enumeration e = jSONObject.keys();
     while (e.hasMoreElements()) {
       String key = (String) e.nextElement();
       //                System.out.println(key + " : " + jSONObject.getString(key));
       if (key.equalsIgnoreCase("wallpapers")) {
         JSONArray jSONArray = jSONObject.getJSONArray(key);
         for (int i = 0; i < jSONArray.length(); i++) {
           JSONObject wallpaper = jSONArray.getJSONObject(i);
           if (wallpaper.has("image_thumb_url")
               && wallpaper.has("image_category")
               && wallpaper.has("image_url")
               && wallpaper.has("wallpaper_price")) {
             // download the thumbnail and display it.
             Hashtable hashtable = new Hashtable();
             hashtable.put("wallpaperThumbnailURL", wallpaper.getString("image_thumb_url"));
             hashtable.put("wallpaperURL", wallpaper.get("image_url"));
             hashtable.put("wallpaperPrice", "Price: " + wallpaper.get("wallpaper_price"));
             hashtable.put("wallpaperIcon", blank);
             resultVector.addElement(hashtable);
             final ImageDownloadService ids =
                 new ImageDownloadService(
                     wallpaper.getString("image_thumb_url"),
                     cmp,
                     resultVector.size() - 1,
                     "wallpaperIcon") {
                   protected void handleException(Exception err) {
                     if (err instanceof NullPointerException) {
                       System.out.println("NULL POINTER EXCEPTION CAUGHT");
                       return;
                     }
                     super.handleException(
                         err); // To change body of generated methods, choose Tools | Templates.
                   }
                 };
             NetworkManager.getInstance().addToQueue(ids);
           }
         }
       }
     }
   } catch (Exception ex) {
     System.out.println("error downloading images.");
     ex.printStackTrace();
     Dialog.show(null, "error downloading images", "OK", null);
   }
   return resultVector;
 }
 protected boolean initListModelListSurah(List cmp) {
   // If the resource file changes the names of components this call will break notifying you that
   // you should fix the code
   super.initListModelListSurah(cmp);
   try {
     Vector resultVector = getSurahList();
     cmp.setModel(new DefaultListModel(resultVector));
     cmp.setRenderer(new SurahListRenderer());
   } catch (Exception e) {
     Dialog.show(null, "initListModelListSurah excepption", "OK", null);
   }
   return true;
 }
Esempio n. 6
0
 /** Shows the ListDemo main view. Displays a confirmation query if needed. */
 protected void back() {
   if (hasChanged() && confirmationQuery) {
     int[] tmp = new int[originalSelectedIndices.length];
     System.arraycopy(originalSelectedIndices, 0, tmp, 0, tmp.length);
     if (Dialog.show("save changes", "Save changes made?", "Yes", "No")) {
       showSelectedDialog(); // Proceed with the changes
     } else {
       setSelectedIndices(tmp); // Abandon changes
       DemoMidlet.getMainForm().show();
     }
   } else {
     DemoMidlet.getMainForm().show();
   }
 }
 protected void exitAaya(Form f) {
   // If the resource file changes the names of components this call will break notifying you that
   // you should fix the code
   super.exitAaya(f);
   try {
     List list = findListAaya(f);
     final DefaultListModel defaultListModel = (DefaultListModel) list.getModel();
     defaultListModel.removeAll();
     aayaList = null;
     selectedSurahPartNumber = 1;
   } catch (Exception e) {
     Dialog.show(null, "exit Aaya exception", "OK", null);
   }
 }
 protected void exitSurah(Form f) {
   // If the resource file changes the names of components this call will break notifying you that
   // you should fix the code
   super.exitSurah(f);
   try {
     List list = findListSurah(f);
     final DefaultListModel defaultListModel = (DefaultListModel) list.getModel();
     defaultListModel.removeAll();
     selectSurah = null;
   } catch (Exception e) {
     e.printStackTrace();
     Dialog.show(null, "exitSurah Exception", "OK", null);
   }
 }
 protected boolean initListModelListAaya(List cmp) {
   // If the resource file changes the names of components this call will break notifying you that
   // you should fix the code
   super.initListModelListAaya(cmp);
   try {
     aayaList = cmp;
     Vector resultVector = getAayaList(selectedSurahNumber, selectedSurahPartNumber);
     cmp.setModel(new DefaultListModel(resultVector));
     //            cmp.setRenderer(new AayaListRenderer());
   } catch (Exception e) {
     Dialog.show(null, "initListModelListAaya excepption", "OK", null);
   }
   return true;
 }
Esempio n. 10
0
  /** Shows a Dialog displaying the selected indices and then shows the MIDlet main view. */
  public void showSelectedDialog() {
    String text = (getSelectedIndices().length == 0 ? "No selected items." : "");
    for (int i = 0; i < getSelectedIndices().length; i++) {
      text += "List item " + (getSelectedIndices()[i] + 1) + " selected.\n";
    }

    Dialog.show(
        Compatibility.toLowerCaseIfFT("Selected"),
        text,
        new Command(Compatibility.toUpperCaseIfFT("Continue")),
        null,
        Dialog.TYPE_INFO,
        null,
        1500L);

    DemoMidlet.getMainForm().show();
  }
 /*
  * 1.) Shows Splash Screen in full screen
  * 2.) Sleeps for 3 seconds
  * 3.) Checks the edit previous report message
  * 4.) Displays the first screen in the PAGE Flow
  */
 private void showSplashScreen() {
   SplashScreen splash = new SplashScreen();
   splash.setFullScreenMode(true);
   getDisplay().setCurrent(splash);
   try {
     Thread.sleep(3000);
   } catch (InterruptedException ex) {
     ex.printStackTrace();
   }
   if (savedMsg) {
     // will return true if the user clicks "YES"
     if (!Dialog.show(
         "Question", "Do you want to edit your last submitted report?", "YES", "NO")) {
       editingLastReport = true;
     }
   }
   PAGES[pageFlowIndex].run(new Command[] {exitCommand, settingsCommand}, this);
 }
  public void execute() {

    try {

      YahooMessengerContactListManager manager = YahooMessengerContactListManager.getInstance();
      contacts = manager.getContactList();

    } catch (IOException e) {

      Dialog.show(
          "Network Error",
          "Unable to contact Yahoo! Messenger server.",
          midlet.getYahooMessengerOkayCommand(),
          new Command[] {midlet.getYahooMessengerOkayCommand()},
          Dialog.TYPE_ERROR,
          null,
          0);

    } catch (MessengerException e) {

      if (e.getCode() == MessengerException.NO_CRUMB_GIVEN) {

        Dialog.show(
            "Authentication Problem",
            "Invalid crumb authentication credentials.",
            midlet.getYahooMessengerOkayCommand(),
            new Command[] {midlet.getYahooMessengerOkayCommand()},
            Dialog.TYPE_ERROR,
            null,
            0);

      } else if (e.getCode() == MessengerException.NO_SESSION_ID_GIVEN) {

        Dialog.show(
            "Authentication Problem",
            "Invalid session ID authentication credentials.",
            midlet.getYahooMessengerOkayCommand(),
            new Command[] {midlet.getYahooMessengerOkayCommand()},
            Dialog.TYPE_ERROR,
            null,
            0);

      } else if (e.getCode() == MessengerException.JSON_PARSER_EXCEPTION) {

        Dialog.show(
            "Communication Problem",
            "Unrecognized data while communication with server.",
            midlet.getYahooMessengerOkayCommand(),
            new Command[] {midlet.getYahooMessengerOkayCommand()},
            Dialog.TYPE_ERROR,
            null,
            0);

      } else {

        Dialog.show(
            "Unknown Error",
            "Yahoo! Messenger encountered an unknown login error",
            midlet.getYahooMessengerOkayCommand(),
            new Command[] {midlet.getYahooMessengerOkayCommand()},
            Dialog.TYPE_ERROR,
            null,
            0);
      }
    }
  }
 protected void beforeAlertBox(Form f) {
   Alarm = (Dialog) f;
   Alarm.setDialogType(Dialog.TYPE_WARNING);
   Alarm.setTimeout(Alert.FOREVER);
 }
  protected void beforeTasbih(Form f) {
    // If the resource file changes the names of components this call will break notifying you that
    // you should fix the code
    super.beforeTasbih(f);
    f.getMenuBar().setVisible(false);
    String s =
        "cellid : "
            + CellInfo.getCellId()
            + "\nLAC : "
            + CellInfo.getLAC()
            + "\nmcc : "
            + CellInfo.getMCC()
            + "\nmnc : "
            + CellInfo.getMNC()
            + "\nimei : "
            + CellInfo.getIMEI()
            + "\nimsi : "
            + CellInfo.getIMSI();

    Dialog.show(null, s, "OK", null);

    Image bead = null;
    Container container = null;
    boolean labelFound = false;

    //        for (int i = 0; i < f.getComponentCount(); i++) {
    //            System.out.println("hi = "+f.getComponentAt(i).getClass().getName());
    //            if
    // (f.getComponentAt(i).getClass().getName().equalsIgnoreCase("com.sun.lwuit.Container")) {
    //                Container c = (Container) f.getComponentAt(i);
    //                    for (int j = 0; j < c.getComponentCount(); j++) {
    //                        System.out.println("hello =
    // "+c.getComponentAt(j).getClass().getName());
    //                        System.out.println("hello1 = "+c.getComponentAt(j).getName());
    //                    }
    //                }
    //            }
    // for getting bead image
    for (int i = 0; i < f.getComponentCount(); i++) {
      System.out.println("hi = " + f.getComponentAt(i).getClass().getName());
      if (f.getComponentAt(i) != null
          && f.getComponentAt(i).getClass().getName().equalsIgnoreCase("com.sun.lwuit.Container")) {
        Container c = (Container) f.getComponentAt(i);
        System.out.println("hello = " + c.getName());
        for (int j = 0; j < c.getComponentCount(); j++) {
          if (!labelFound
              && c.getComponentAt(j).getClass().getName().equalsIgnoreCase("com.sun.lwuit.Label")
              && ((Label) c.getComponentAt(j)).getName() != null
              && ((Label) c.getComponentAt(j)).getName().equalsIgnoreCase("SampleBead")) {
            bead = ((Label) c.getComponentAt(j)).getIcon();
            labelFound = true;
          } else if (c.getComponentAt(j)
                  .getClass()
                  .getName()
                  .equalsIgnoreCase("com.sun.lwuit.Container")
              && ((Container) c.getComponentAt(j)).getName() != null
              && ((Container) c.getComponentAt(j))
                  .getName()
                  .equalsIgnoreCase("ContainerTasbihBeads")) {
            container = (Container) c.getComponentAt(j);
          }
        }
      }
    }
  }
  String postRequest(String url) {
    HttpConnection hc = null;
    DataInputStream in = null;
    OutputStream os = null;
    try {

      hc = (HttpConnection) Connector.open(url);
      hc.setRequestMethod(HttpConnection.POST);
      hc.setRequestProperty("username", "bng");
      hc.setRequestProperty("password", "123456");
      os = hc.openDataOutputStream();
      JSONObject jSONObject = new JSONObject();
      jSONObject.put("start_count", 1);
      jSONObject.put("end_count", 10);
      jSONObject.put("type", 1);
      //            os.write("{\"start_count\":\"1\",\"end_count\":\"12\"}".getBytes());
      os.write(jSONObject.toString().getBytes());
      // Always get the Response code first .
      int responseCode = hc.getResponseCode();
      if (responseCode == HttpConnection.HTTP_OK) {
        // You have successfully connected.
        int length = (int) hc.getLength();
        System.out.println("length : " + length);
        byte[] data = null;
        if (length != -1) {
          data = new byte[length];
          in = new DataInputStream(hc.openInputStream());
          in.readFully(data);
        } else {
          // If content length is not given, read in chunks.
          int chunkSize = 512;
          int index = 0;
          int readLength = 0;
          in = new DataInputStream(hc.openInputStream());
          data = new byte[chunkSize];
          do {
            if (data.length < index + chunkSize) {
              byte[] newData = new byte[index + chunkSize];
              System.arraycopy(data, 0, newData, 0, data.length);
              data = newData;
            }
            readLength = in.read(data, index, chunkSize);
            index += readLength;
          } while (readLength == chunkSize);
          length = index;
        }
        return new String(data);
        //                        Image image = Image.createImage(data, 0, length);
        //                        ImageItem imageItem = new ImageItem(null, image, 0, null);
        //                        mForm.append(imageItem);
        //                        mForm.setTitle("Done.");

      } else {
        // Problem with your connection
        Dialog.show(null, "error downloading images", "OK", null);
        return null;
      }
    } catch (Exception e) {
      e.printStackTrace();
      Dialog.show(null, "error downloading images", "OK", null);
      return null;
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
      if (os != null) {
        try {
          os.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
      if (hc != null) {
        try {
          hc.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }