| Forum Details |
Topics |
Posts |
| Categories |
| |
| 576 member(s) |
| 708,465 hit(s) |
| 14 categories |
| 51 topics |
| 26 messages |
| 0 online |
|
| Author |
Topics |
Replies |
Views |
Last Updated |
|
|
Audio in not Recording |
0 |
1143 |
September 20, 2011 3:45 AM |
Actually when i am recording video from mobile camera it is recording as a byte array, after thet through Http coonection i am genarating the .3gp file, but when i am palyaing the .3gp file avideo is playing fine but audio is not playing, when i chacked the descriotion it showing the the video aspect ratio,bitrate ,format,selected codec etc... , but there is no information about Audio. please help me whre i am doing wrong.
Here is the code to upload the file in server:
package com.sisatellabs.j2me.job;
import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream;
import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection;
import com.sisatellabs.j2me.VideoNote; import com.sisatellabs.j2me.prefs.SystemPreferences; import com.sisatellabs.j2me.ui.CommunicatingScreen; import com.sisatellabs.j2me.ui.LogScreen; import com.sisatellabs.j2me.ui.RecordScreen;
public class UploadJob implements Runnable { protected String name; protected ByteArrayOutputStream baos;
public UploadJob(String name, ByteArrayOutputStream baos) {
this.name = name; this.baos = baos; }
public void run() { VideoNote.instance.display.setCurrent(new CommunicatingScreen());
HttpConnection c = null; DataInputStream is = null; DataOutputStream os = null;
try { String uploadURL = VideoNote.instance.getAppProperty("http://www.sisatel.com") + "/socialad/m_input.php"; long protocolId = 1L;
String username = SystemPreferences.instance.get("account.username"); String password = SystemPreferences.instance.get("account.password");
c = (HttpConnection) Connector.open(uploadURL,Connector.READ_WRITE);
c.setRequestMethod(HttpConnection.POST); c.setRequestProperty("Connection", "keep-alive");
os = c.openDataOutputStream(); os.writeLong(protocolId);
os.writeUTF(username); os.writeUTF(password); os.writeUTF(name);
byte[] data = baos.toByteArray(); baos.reset(); baos = null;
os.writeInt(data.length); os.write(data); os.flush();
is = c.openDataInputStream(); int rc = is.readInt(); } catch (Exception e) { LogScreen.instance.log(e); } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } if (c != null) { try { c.close(); } catch (Exception e) { } } baos = null; System.gc(); }
VideoNote.instance.display.setCurrent(RecordScreen.instance); } }
Here is code of video recording:
// Java Document package com.sisatellabs.j2me.ui;
import java.io.ByteArrayOutputStream;
import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Graphics; import javax.microedition.media.Manager; import javax.microedition.media.Player; import javax.microedition.media.control.RecordControl; import javax.microedition.media.control.VideoControl;
import com.sisatellabs.j2me.job.JobRunner; import com.sisatellabs.j2me.job.UploadJob;
public class RecordScreen extends ScreenCanvas implements CommandListener, Runnable { public static final RecordScreen instance = new RecordScreen();
private Command CMD_START = new Command("Start", Command.BACK, 1); private Command CMD_STOP = new Command("Stop", Command.OK, 1); private Player p = null; private RecordControl rc = null; private VideoControl videoControl = null; private Thread thread; private long startTime = 0;
private ByteArrayOutputStream baos = new ByteArrayOutputStream(1024*500); private boolean running = false;
private RecordScreen() { this.addCommand(CMD_STOP); this.addCommand(CMD_START); this.setCommandListener(this); }
public void initialize() { }
public void commandAction(Command c, Displayable d) { if (c == CMD_START) { start(); } else if (c == CMD_STOP) { stop(); } }
protected void start() { try { if (!running) { if (thread == null) { startTime = System.currentTimeMillis(); thread = new Thread(this); thread.start();
baos.reset();
p = Manager.createPlayer("capture://video"); p.realize(); rc = (RecordControl) p.getControl("RecordControl");
videoControl = (VideoControl) (p.getControl("VideoControl")); videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this); videoControl.setVisible(true);
int x = (getWidth() - videoControl.getDisplayWidth()) >> 1; int y = (getHeight() - videoControl.getDisplayHeight()) >> 1; videoControl.setDisplayLocation(x, y);
rc.setRecordStream(baos); p.prefetch();
rc.startRecord(); p.start();
repaint();
running = true; } } } catch (Exception e) { LogScreen.instance.log(e); } }
protected void stop() { if (running) { try { thread = null;
rc.stopRecord(); rc.commit(); p.stop(); p.deallocate(); p.close();
JobRunner.instance.run(new UploadJob("sisatelmob.3gpp", baos));
p = null; rc = null; } catch (Exception e) { LogScreen.instance.log(e); } finally { running = false; } } }
public void run() { while (thread != null) {
try { Thread.sleep(1000); } catch (Exception e) { } } }
protected void paint(Graphics g) { drawHeaderAndFooter(g," Start recording >");
int w = getWidth(); int h = getHeight();
int dy = g.getFont().getHeight() + 2; int starty = (h >> 1) - (dy/2);
if ( running ) { long elapsed = (System.currentTimeMillis() - startTime)/1000; String timeString = String.valueOf(elapsed/60); long sec = elapsed % 60; timeString += ( sec 10 ) ? ":0" + sec : ":" + sec;
g.drawString(timeString, w >> 1, starty, Graphics.TOP | Graphics.HCENTER); } else { g.drawString("Record Ready", w >> 1, starty, Graphics.TOP | Graphics.HCENTER); }
} }
Here is the PHP code where file is genarting(m_input.php): $postdata = file_get_contents("php://input"); $fp = fopen(time()."-mob.3gp","a+"); // fwrite($fp, $GLOBALS['HTTP_RAW_POST_DATA']); fwrite($fp, $postdata); //fclose($fp);
Helese help me where i am doing wrong
Thank you
|
|
|
hi there..Actually i want to edit one small mobile application but i have encountered one problem when i run that application in my mobile... i.e.Unknown application. Could u give some possible solutions....thanks in advance.. |
0 |
1635 |
June 06, 2011 9:45 AM |
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version! // Decompiler options: packimports(3) // Source File Name: AgeCalc2.java
import java.io.IOException; import java.io.PrintStream; import java.util.Calendar; import java.util.Date; import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet;
public class AgeCalc2 extends MIDlet implements CommandListener {
public AgeCalc2() { display = Display.getDisplay(this); mMainForm = new Form("AgeCalc"); aboutForm = new Form("About Age Calc"); msgBox = new Alert("Warning!", "", null, AlertType.ERROR); cDate = new Date(); bDate = new Date(); cCal = Calendar.getInstance(); bCal = Calendar.getInstance(); cCal.setTime(cDate); bCal.setTime(bDate); currentDate = new DateField("Pinku", 1);// Here i have edited datafiled name as pinku but actually it was current date. birthDate = new DateField("Birth Date", 1); currentDate.setDate(cDate); birthDate.setDate(bDate); msgBox.setTimeout(-2); ageField = new StringItem("Age:", null); mMainForm.append(birthDate); mMainForm.append(currentDate); mMainForm.append(ageField); mMainForm.addCommand(new Command("Exit", 7, 0)); mMainForm.setCommandListener(this); mMainForm.addCommand(new Command("Calculate", 1, 0)); mMainForm.setCommandListener(this); mMainForm.addCommand(new Command("About", 1, 0)); mMainForm.setCommandListener(this); aboutForm.addCommand(new Command("Back", 2, 0)); aboutForm.setCommandListener(this); try { img = Image.createImage("/AgeCalc2.png"); ImageItem imageitem = new ImageItem("", img, 3, "img"); aboutForm.append(imageitem); } catch(IOException ioexception) { System.out.println("could not create image: " + ioexception); } aboutForm.append(new StringItem("Age Calculator 2.0\nCopyright (c) 2005, All rights reserved.\nBy: Abdelbaset Rabayah\nhttp://www.abdelbaset.info\nEnjoy!", null)); }
public void findAge() { int i = 0; int j = 0; int k = 0; int l = 0; int i1 = 0; int j1 = 0; cCal.setTime(currentDate.getDate()); i = cCal.get(5); j = cCal.get(2) + 1; k = cCal.get(1); bCal.setTime(birthDate.getDate()); int k1 = bCal.get(5); int l1 = bCal.get(2) + 1; int i2 = bCal.get(1); l = k - i2; if(l1 > j) { l--; i1 = 12 - Math.abs(j - l1); } else { i1 = j - l1; } if(k1 > i) { i1--; switch(j) { case 1: // '\001' case 3: // '\003' case 5: // '\005' case 7: // '\007' case 8: // '\b' case 10: // '\n' case 12: // '\f' j1 = 31 - Math.abs(i - k1); break;
case 4: // '\004' case 6: // '\006' case 9: // '\t' case 11: // '\013' j1 = 30 - Math.abs(i - k1); break;
case 2: // '\002' j1 = 28 - Math.abs(i - k1); break; } } else { j1 = i - k1; } String s = "Age: " + l + " years, " + i1 + " months, and " + j1 + " days."; if(k1 1 || k1 > 31) { msgBox.setString("Illegal value!\nPlease check day."); s = "Age:"; display.setCurrent(msgBox); } if(l1 1 || l1 > 12) { msgBox.setString("Illegal value!\nPlease check month."); s = "Age:"; display.setCurrent(msgBox); } if(i2 0 || i2 > k) { msgBox.setString("Illegal value!\nPlease check year."); s = "Age:"; display.setCurrent(msgBox); } ageField.setLabel(s); }
public void startApp() { display.setCurrent(mMainForm); }
public void pauseApp() { }
public void destroyApp(boolean flag1) { }
public void commandAction(Command command, Displayable displayable) { String s = command.getLabel(); System.out.println(s); if(s.equals("Exit")) notifyDestroyed(); else if(s.equals("Calculate")) findAge(); else if(s.equals("About")) display.setCurrent(aboutForm); else display.setCurrent(mMainForm); }
private Form mMainForm; private Form aboutForm; private DateField currentDate; private DateField birthDate; private Command exitCommand; private Command calcCommand; private Command aboutCommand; private Command backCommand; private Display display; private StringItem ageField; private Alert msgBox; private Image img; private Calendar cCal; private Calendar bCal; private Date cDate; private Date bDate; }
|
|
|
Problem ater editing |
0 |
1295 |
June 06, 2011 9:43 AM |
Hi there... Actually i want to edit one small mobile application but i have encountered one problem when i run that application in my mobile... i.e.Unknown application. Could u give some possible solutions....thanks in advance..
|
|
|
HostJ2ME.com Search Proxy |
8 |
7244 |
August 26, 2009 12:36 PM |
Provides search results for the OSM client by aggregating results from Google, Bing, Wikipedia, and Yahoo using the respective search APIs.
Example Usage:
SearchAgent agent = new SearchAgent(); Query query = new Query(); query.addHeader("user-agent","MySearchClient")); query.setTerm("volvo xc60"); query.setTypes(FileRecord.TYPE_ALL);
List providers = new ArrayList(); providers.add("yahoo"); providers.add("live"); providers.add("google"); providers.add("googlevideo"); providers.add("wikipedia");
BasicUIListable results = agent.find(query,5*1000,100,providers.toArray(new String[0]));
for ( SearchResult record : results.items(pn,ps) ) { System.out.println(record.getTitle()); }
Contact me if you need the full source code
|
|
|
Need help |
0 |
3573 |
June 14, 2009 7:57 AM |
I downloaded the application but,when opening it,I'm told 'invalid code,get key name' Please advise
|
|
|
Midlet Icon Extractor |
0 |
3122 |
January 21, 2009 12:13 PM |
HostJ2ME.com uses the code below to extract application icons from Midlet jars and display them in the HostJ2ME.com midlet directory.
package com.astrientlabs.hostj2me.util;
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile;
import com.astrientlabs.files.AstrientFile; import com.astrientlabs.util.Strings;
public class IconExtractor { private String MANIFEST = "META-INF/MANIFEST.MF"; public byte[] extract(String path) throws ZipException, IOException { return extract(new File(path)); } public byte[] extract(File jarFile) throws ZipException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ZipFile zipFile = new ZipFile(jarFile); try { /*for ( Enumeration? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) { System.out.println(e.nextElement().getName()); }*/ ZipEntry entry = zipFile.getEntry(MANIFEST);
InputStream is = zipFile.getInputStream(entry); if ( is != null ) { Properties props = new Properties(); props.load(is); String iconFile = props.getProperty("MIDlet-Icon"); if ( Strings.isNull(iconFile) ) { props.list(System.out); String midlet1 = props.getProperty("MIDlet-1"); if ( !Strings.isNull(midlet1) ) { String[] parts = midlet1.split(","); if ( parts.length > 2 ) { iconFile = parts[1].trim(); if ( iconFile.startsWith("/") ) { iconFile = iconFile.substring(1); } } } } if ( iconFile != null ) { ZipEntry iconEntry = zipFile.getEntry(iconFile); if ( iconEntry != null ) { FileOutputStream fos = new FileOutputStream("/tmp/icon.png"); InputStream zis = zipFile.getInputStream(iconEntry); int r = 0; byte[] buffer = new byte[4*1024]; while( (r = zis.read(buffer)) != -1 ) { baos.write(buffer,0,r); fos.write(buffer,0,r); } fos.close(); zis.close(); } } } } finally { zipFile.close(); } return baos.toByteArray(); } public static void main(String[] args) { File jarFile = new File("/projects/workspace/cliqmobile/builds/cliqmobile.jar"); IconExtractor extractor = new IconExtractor(); try { byte[] data = extractor.extract(jarFile); System.out.println(data.length + " " + AstrientFile.fileType(data)); } catch (ZipException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.exit(0); } }
|
|
|
Java Utility for perfrorming DNS Blacklist lookups. For more information on DNSBL see http://en.wikipedia.org/wiki/DNSBL
|
0 |
5203 |
January 16, 2009 12:43 PM |
package com.astrientlabs.net.dns;
import java.util.ArrayList; import java.util.Hashtable; import java.util.List;
import javax.naming.Context; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext;
import com.astrientlabs.prefs.Preferences;
public class DNSBL { private static String[] RECORD_TYPES = { "A", "TXT" }; private DirContext ictx; private List lookupServices = new ArrayList(); public DNSBL() throws NamingException { StringBuilder dnsServers = new StringBuilder(""); List nameservers = sun.net.dns.ResolverConfiguration.open().nameservers(); for( Object dns : nameservers ) { dnsServers.append("dns://").append(dns).append(" "); } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory"); env.put("com.sun.jndi.dns.timeout.initial", Preferences.system.get("dns.timeout","4000")); env.put("com.sun.jndi.dns.timeout.retries", Preferences.system.get("dns.retry","1")); env.put(Context.PROVIDER_URL,Preferences.system.get("dns.url",dnsServers.toString())); ictx = new InitialDirContext(env); } public void addLookupService(String service) { lookupServices.add(service); } public void check(String ip) throws DNSBLException { String[] parts = ip.split("\\."); StringBuilder buffer = new StringBuilder();
for (int i = 0; i parts.length; i++) { buffer.insert(0, '.'); buffer.insert(0, parts[i]); } ip = buffer.toString();
Attribute attribute; Attributes attributes; String lookupHost; for ( String service : lookupServices ) { lookupHost = ip + service; try { attributes = ictx.getAttributes(lookupHost, RECORD_TYPES); attribute = attributes.get("TXT"); if ( attribute != null ) { throw new DNSBLException(lookupHost + ": " + attribute.get()); } } catch (NameNotFoundException e) { //this is good //LogWriter.system.log(getClass(),e); } catch (NamingException e) { //LogWriter.system.log(getClass(),e); } } } public static void main (String[] args) { try { DNSBL dnsBL = new DNSBL(); dnsBL.addLookupService("blackholes.easynet.nl"); dnsBL.addLookupService("cbl.abuseat.org"); dnsBL.addLookupService("proxies.blackholes.wirehub.net"); dnsBL.addLookupService("bl.spamcop.net"); dnsBL.addLookupService("sbl.spamhaus.org"); dnsBL.addLookupService("dnsbl.njabl.org"); dnsBL.addLookupService("list.dsbl.org"); dnsBL.addLookupService("multihop.dsbl.org"); dnsBL.addLookupService("cbl.abuseat.org"); try { dnsBL.check("201.223.47.44"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } try { dnsBL.check("38.100.193.183"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } try { dnsBL.check("189.94.149.137"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } try { dnsBL.check("220.227.113.25"); } catch (DNSBLException se) { System.out.println(se.getMessage()); } } catch (Exception e) { e.printStackTrace(); } System.exit(0); } } class DNSBLException extends Exception {
public DNSBLException() { super(); }
public DNSBLException(String message, Throwable cause) { super(message, cause); }
public DNSBLException(String message) { super(message); }
public DNSBLException(Throwable cause) { super(cause); } }
|
|
|
Line Wrapping Utility for Drawing Strings on a Canvas |
1 |
11439 |
January 29, 2007 3:14 PM |
/* * Copyright (C) 2006 Astrient Labs, LLC Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * Astrient Labs, LLC * www.astrientlabs.com * rashid@astrientlabs.com * Rashid Mayes 2006 */ package com.astrientlabs.text;
import java.util.Enumeration; import java.util.NoSuchElementException;
import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics;
public class LineEnumeration implements Enumeration { private Font font;
private String text; private int width; private int position; private int length; private int start = 0;
public LineEnumeration(Font font, String text, int width) { this.font = font; this.text = text; this.width = width; this.length = text.length(); }
public boolean hasMoreElements() { return (position (length - 1)); }
public Object nextElement() throws NoSuchElementException { try { int next = next();
String s = text.substring(start, next); start = next;
if (text.length() - 1 > start && (text.charAt(start) == ' ' || text.charAt(start) == '\n')) { position++; start++; }
return s; } catch (IndexOutOfBoundsException e) { throw new NoSuchElementException(e.getMessage()); } catch (Exception e) { throw new NoSuchElementException(e.getMessage()); } }
private int next() { int i = position; int lastBreak = -1;
for (; i length && font.stringWidth(text.substring(position, i)) = width; i++) { if (text.charAt(i) == ' ') { lastBreak = i; } else if (text.charAt(i) == '\n') { lastBreak = i; break; } }
if (i == length) { position = i; } else if (lastBreak == position) { position++; } else if (lastBreak position) { position = i; } else { position = lastBreak; }
return position; }
public int writeTo(Graphics g, int startx, int starty, int maxY, Font font) { int fontHeight = font.getHeight() + 1;
while (hasMoreElements() && starty maxY) { g.drawString(String.valueOf(nextElement()).trim(), startx, starty, Graphics.TOP | Graphics.LEFT); starty += fontHeight; }
return starty; }
public void reset() { start = 0; position = 0; } }
|
|
|
download reporting |
1 |
3975 |
September 30, 2008 3:26 AM |
I need to know how the hostj2me server manages to log the mobile configuration, profile,and the model number of the phone which downloads a mobile application from its server....How is it possible to query the phone OTA.......
|
|
|
I need some code post on this |
2 |
3775 |
November 14, 2007 4:16 AM |
I wrote a Time Table midlet using persistence storage API for university students to save course code with time. I want the midlet to alert the user when they have that particular course or some minutes before even when the midlet is closed. I need some code post on this. Thanks
|
|
|
J2ME: Getting a list of files in a directory (inside the .jar file) |
1 |
2534 |
March 26, 2007 11:04 AM |
Hi,
I have a problem which should be quite simple, but I haven't been able to work it out. I want to create a list of files inside a directory within the .jar file, but all the instructions I've seen for listing files within a directory assume you're using the fileConnection API and listing an external directory. I don't want to require JSR75, and I've got a feeling that that can't see inside the .jar file anyway.
I can load the files themselves with no problems, and my current solution is to create a text file with a list of all the files in the directory, but this is a nuisance to keep updating. So can someone give me some pointers about how to create a String[] with a list of files inside an internal directory?
|
|
|
Need some assistance |
1 |
2515 |
November 14, 2007 4:14 AM |
I wrote a Time Table midlet using persistence storage API for university students to save course code with time. I want the midlet to alert the user when they have that particular course or some minutes before even when the midlet is closed. I need assistance on this area. Kindly help me on this. Thanks
|
|
|
Paging utility for displaying lists in web UI |
0 |
2054 |
January 02, 2008 1:29 PM |
/* * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * Astrient Labs, LLC. * www.astrientlabs.com * rashid@astrientlabs.com * Rashid Mayes 2005 */ package com.astrientlabs.webui;
import java.util.LinkedList; import java.util.List; import java.util.Random;
import com.astrientlabs.logging.LogWriter;
public class BasicUIListable extends LinkedList implements UIListable { /** * */ private static final long serialVersionUID = -7369036906003073472L; private int pageSize = 10; private int pageNumber = -1; private Random random = new Random(); public List getItems(int pageNumber) { int start = pageNumber * pageSize; int end = start + pageSize; return getItems(start,end); } public List items(int pageNumber, int pageSize) { int start = (pageNumber * pageSize); int end = start + pageSize; return getItems(start,end); } public List getItems(int start, int end) { try { if ( start > -1 && start size() ) { if ( end > size() ) { end = size(); }
return this.subList(start,end); } } catch (Exception e) { LogWriter.system.log(getClass(),e); } return this.subList(0,0);//(List)EMPTY_LIST; }
public void resetPageNumber() { pageNumber = -1; } public List next() { return getItems(++pageNumber); } public List current() { return ( pageNumber == -1 ) ? next() : getItems(pageNumber); } public List previous() { return getItems(--pageNumber); } /** * Returns the pageNumber. * @return int */ public int getPageNumber() { return pageNumber; }
/** * Returns the pageSize. * @return int */ public int getPageSize() { return pageSize; }
/** * Sets the pageNumber. * @param pageNumber The pageNumber to set */ public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; }
/** * Sets the pageSize. * @param pageSize The pageSize to set */ public void setPageSize(int pageSize) { this.pageSize = pageSize; }
public int totalPages() { int size = size(); int pageSize = getPageSize(); int total = size / pageSize; if ( (size % pageSize ) > 0 ) { total++; } return total; } public int totalPages(int pageSize) { int size = size();
int total = size / pageSize; if ( (size % pageSize ) > 0 ) { total++; } return total; } /* public synchronized void buildIndexes(Indexer indexer) { indexes.clear(); Object o; Object index; for ( Iterator iter = this.iterator(); iter.hasNext(); ) { o = iter.next(); index = indexer.index(indexes,this); } }*/ /* public static void main(String[] args) { BasicUIListable list = new BasicUIListable(); list.setPageSize(2); for(int i = 0; i 5;list.add(String.valueOf(i++))); for (String s : list) { System.out.println(s); } System.out.println("\n\n"); List l = list.getItems(2); for (String s : l) { System.out.println(s); } System.exit(0); }*/ public E random() { return this.get(random.nextInt(this.size())); } }
edited by hostj2me 1/2/08 1:31 PM
|
|
|
Detecting Soft Keys |
0 |
2461 |
November 06, 2007 3:17 PM |
Here is the pseudo code I use to determine the soft key assignments in most of my J2ME apps.
int KEY_SOFTKEY_LEFT = -6; int KEY_SOFTKEY_RIGHT = -7; if ( ...check needed ) { try { Class.forName("com.siemens.mp.game.Light"); KEY_SOFTKEY_RIGHT = -4; KEY_SOFTKEY_LEFT = -1; } catch (ClassNotFoundException ignore) { //ignore.printStackTrace(); try { Class.forName("com.mot.iden.customercare.CustomerCare"); KEY_SOFTKEY_RIGHT = -21; KEY_SOFTKEY_LEFT = -20; } catch (ClassNotFoundException ignore2) { //ignore2.printStackTrace(); try { Class.forName("com.motorola.phonebook.PhoneBookRecord"); KEY_SOFTKEY_RIGHT = -22; KEY_SOFTKEY_LEFT = -21; } catch (ClassNotFoundException ignore3) { if ( someCanvas.getKeyName(-21).equalsIgnoreCase("soft1") ) { KEY_SOFTKEY_LEFT = -21; } if ( someCanvas.getKeyName(-22).equalsIgnoreCase("soft2") ) { KEY_SOFTKEY_RIGHT = -22; } } } } }
|
|
|
MIDI Converter, Type 1 to Type 0 |
0 |
1237 |
September 14, 2007 3:46 PM |
/* * Copyright (C) 2006 Astrient Labs, LLC Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * Astrient Labs, LLC * www.astrientlabs.com * rashid@astrientlabs.com * Rashid Mayes 2005 */ package com.astrientlabs.audio;
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile;
import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiFileFormat; import javax.sound.midi.MidiSystem; import javax.sound.midi.Sequence; import javax.sound.midi.Track;
public class MidiConverter { public static boolean isType1(byte[] data) throws InvalidMidiDataException, IOException { return isType1(new ByteArrayInputStream(data)); }
public static boolean isType1(InputStream is) throws InvalidMidiDataException, IOException { MidiFileFormat format = MidiSystem.getMidiFileFormat(is); return (format.getType() == 1); }
public static byte[] convertToType(byte[] data, int maxTracks) throws InvalidMidiDataException, IOException { return convertToType0(new ByteArrayInputStream(data), maxTracks); }
public static byte[] convertToType0(InputStream is, int maxTracks) throws InvalidMidiDataException, IOException { Sequence sequence = MidiSystem.getSequence(is);
Track[] tracks = sequence.getTracks(); Track first = tracks[0]; Track track;
for (int i = 1; i tracks.length; i++) { track = tracks[i]; if (i maxTracks) for (int j = 0, stop = track.size(); j stop; first.add(track.get(j++))) ; sequence.deleteTrack(track); }
ByteArrayOutputStream os = new ByteArrayOutputStream(1024); MidiSystem.write(sequence, 0, os);
return os.toByteArray(); }
public static void main(String[] args) { try { RandomAccessFile raf = new RandomAccessFile(new File("G:/in.mid"), "r"); byte[] data = new byte[(int) raf.length()]; raf.readFully(data);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
if (isType1(bais)) { bais.reset(); data = convertToType0(bais, 8);
FileOutputStream fos = new FileOutputStream(new File("g:out.mid")); fos.write(data); fos.close(); // finally:) } } catch (Exception e) { e.printStackTrace(); } System.exit(0); } }
|
|