Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2012 [iPs]TeaM
- * Bruno da Silva (email@brunodasilva.com)
- * Código fonte do aplicativo BRS Mobile TV
- *
- * www.brunodasilva.com
- * www.ips-team.forumeiros.com
- */
- import javax.microedition.media.*;
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- import javax.microedition.io.*;
- import java.util.*;
- import java.io.*;
- public class HelloMIDlet extends MIDlet implements CommandListener
- {
- private StringItem messageItem;
- private StringItem errorItem;
- private Command playCommand;
- private Command exitCommand ;
- private Display display;
- private Player player;
- private List form;
- private Timer timer;
- private TestTimerTask task;
- private Form mainForm;
- private Image telaInicial;
- // Função para dar split na string e extrair informações
- private String[] split(String splitStr, String delimiter) {
- StringBuffer token = new StringBuffer();
- Vector tokens = new Vector();
- // split
- char[] chars = splitStr.toCharArray();
- for (int i=0; i < chars.length; i++) {
- if (delimiter.indexOf(chars[i]) != -1) {
- // we bumbed into a delimiter
- if (token.length() > 0) {
- tokens.addElement(token.toString());
- token.setLength(0);
- }
- } else {
- token.append(chars[i]);
- }
- }
- // don't forget the "tail"...
- if (token.length() > 0) {
- tokens.addElement(token.toString());
- }
- // convert the vector into an array
- String[] splitArray = new String[tokens.size()];
- for (int i=0; i < splitArray.length; i++) {
- splitArray[i] = (String)tokens.elementAt(i);
- }
- return splitArray;
- }
- // Criar novas variáveis e strings para conexão
- StringBuffer inhalt = new StringBuffer();
- boolean carregado = false;
- HttpConnection c = null;
- InputStream is = null;
- StringBuffer sb = new StringBuffer();
- String[] options = new String[100];
- String[] canaisLink = new String[100];
- // Públicas nativas de qualquer aplicativo
- public void pauseApp() {
- }
- public void destroyApp(boolean unconditional) {
- notifyDestroyed();
- }
- public void startApp() {
- display.setCurrent(mainForm);
- }
- // Efetuar conexão e listar canais ao iniciar java
- public HelloMIDlet() {
- display = Display.getDisplay(this);
- mainForm = new Form("[BRS] Mobile TV");
- form = new List("Listagem", Choice.IMPLICIT);
- try {
- telaInicial = Image.createImage("/tela.png");
- }
- catch(Exception e){
- }
- Item mItem = new ImageItem(null, telaInicial, 0, null);
- mainForm.append(telaInicial);
- display.setCurrent(mainForm);
- playCommand = new Command("Carregar Canais", Command.ITEM, 1);
- exitCommand = new Command("Sair", Command.EXIT, 1);
- mainForm.addCommand(playCommand);
- mainForm.addCommand(exitCommand);
- mainForm.setCommandListener(this);
- }
- public void commandAction(Command comm, Displayable disp) {
- if (comm == List.SELECT_COMMAND) {
- try {
- platformRequest(canaisLink[form.getSelectedIndex()]);
- }
- catch (Exception ex) {}
- }
- if (comm == playCommand) {
- Canvas canvas = new LineCanvas();
- display.setCurrent(canvas);
- timer = new Timer();
- task = new TestTimerTask();
- timer.schedule(task, 100);
- }
- if (comm == exitCommand) {
- destroyApp(true);
- notifyDestroyed();
- }
- }
- private class TestTimerTask extends TimerTask {
- public final void run() {
- if(carregado == true) {
- try {
- platformRequest(canaisLink[form.getSelectedIndex()]);
- }
- catch (Exception ex) {}
- }
- else {
- int canais = 0;
- int chr = 0;
- options[0] = "";
- try {
- carregado = true;
- c = (HttpConnection)Connector.open("http://pastebin.com/raw.php?i=LB9j8cTY");
- is = c.openInputStream();
- while((chr = is.read()) != -1) {
- if((char)chr == '\n') {
- String[] str = split(options[canais],"|");
- form.insert(canais, str[0], Image.createImage("/ff.png"));
- canaisLink[canais] = str[1];
- canais++;
- options[canais] = "";
- }
- else {
- options[canais] += ((char)chr);
- }
- }
- }
- catch (IOException x) {
- x.printStackTrace();
- }
- finally {
- try {
- playCommand = new Command("Assistir", Command.ITEM, 1);
- form.addCommand(playCommand);
- form.addCommand(exitCommand);
- form.setCommandListener(HelloMIDlet.this);
- is.close();
- c.close();
- display.setCurrent(form);
- }
- catch (IOException x) {
- x.printStackTrace();
- }
- }
- }
- }
- }
- private class LineCanvas extends Canvas {
- public void paint(Graphics g) {
- int width = getWidth();
- int height = getHeight();
- try {
- Image image = Image.createImage("/carreg.gif");
- g.drawImage(image, width/2, height/2, Graphics.VCENTER | Graphics.HCENTER);
- }
- catch (IOException ex) {
- g.setColor(0xffffff);
- g.drawString("ERRO Inesperado ao carregar. Tentando corrigir", 0, 0, Graphics.TOP | Graphics.LEFT);
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement