diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index ef3127b..d69ab84 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -96,6 +96,15 @@ + + + + + + + + + @@ -164,47 +173,13 @@ - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -285,6 +260,13 @@ + + + + + + + @@ -312,22 +294,10 @@ - - - - - - - - - - - - - + @@ -559,9 +529,10 @@ - + + - + @@ -640,14 +611,6 @@ - - - - - - - - @@ -660,78 +623,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -766,7 +659,7 @@ - + @@ -888,19 +781,6 @@ - - - - - - - - - - - - - @@ -951,6 +831,15 @@ + + + + + + + + + @@ -962,17 +851,14 @@ - - - - - - - - + + + + + @@ -1001,8 +887,8 @@ - - + + @@ -1013,28 +899,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -1085,6 +949,21 @@ + + + + + + + + + + + + + + + @@ -1099,8 +978,10 @@ - - + + + + @@ -1123,19 +1004,15 @@ - - - - - + - + @@ -1152,6 +1029,11 @@ + + + + + Starting emulator with port number ${active.debug.port} @@ -1216,12 +1098,6 @@ - - - - - - @@ -1245,6 +1121,9 @@ + + + @@ -1297,7 +1176,7 @@ - + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 48224f5..ca0c69f 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -2,7 +2,7 @@ # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. build.xml.data.CRC32=d5ed72e0 build.xml.script.CRC32=4c4ce240 -build.xml.stylesheet.CRC32=03eab09b +build.xml.stylesheet.CRC32=9c6a911d nbproject/build-impl.xml.data.CRC32=d5ed72e0 -nbproject/build-impl.xml.script.CRC32=c6fa47a7 -nbproject/build-impl.xml.stylesheet.CRC32=a4fc63f1 +nbproject/build-impl.xml.script.CRC32=cdca5f14 +nbproject/build-impl.xml.stylesheet.CRC32=e46c2d22 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 286945a..125cffe 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1,7 +1,8 @@ -#Wed May 05 19:16:46 EEST 2010 -netbeans.user=C:\\Users\\aNNiMON\\.netbeans\\6.9m1 -javadoc.preview=true -config.active= -deployment.counter=160 +#Mon, 25 Apr 2011 16:20:49 +0300 app-version.autoincrement=true -deployment.number=0.1.59 +config.active= +deployment.counter=37 +deployment.number=0.0.36 +file.reference.MultimediaServices_API.jar=E\:\\MOBILE\\Programming\\Java\\Libraries_n_API\\API\\MultimediaServices_API.jar +javadoc.preview=true +netbeans.user=C:\\Users\\aNNiMON\\.netbeans\\7.1 diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index c1f155a..8505fc1 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -1,4 +1,5 @@ + diff --git a/nbproject/project.properties b/nbproject/project.properties index 3cdfc48..33f7035 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,5 +1,5 @@ abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,NOKIAUI=1.0,JSR226=1.0,MIDP=2.1,JSR229=1.1.0,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,J2MEWS=1.0,VSCL=2.1,WMA=2.0,JSR172=1.0,SEMC_EXT_JP8=1.0,ColorScreen,OBEX=1.0,NokiaUI=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,lib/semc_ext_jp8.jar=1.0,MascotV3=1.0,JSR75=1.0,JSR184=1.1,SATSAPKI=1.0,ScreenHeight=321,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0, -all.configurations=\ +all.configurations=\ ,EmulatorTest application.args= application.description= application.description.detail= @@ -9,21 +9,30 @@ build.classes.dir=${build.dir}/compiled build.classes.excludes=**/*.java,**/*.form,**/*.class,**/.nbintdb,**/*.mvd,**/*.wsclient,**/*.vmd build.dir=build/${config.active} build.root.dir=build +configs.EmulatorTest.extra.classpath= +configs.EmulatorTest.filter.exclude.tests=false +configs.EmulatorTest.filter.excludes=newfile +configs.EmulatorTest.filter.more.excludes=**/overview.html,**/package.html +configs.EmulatorTest.filter.use.standard=true +configs.EmulatorTest.libs.classpath=${file.reference.MultimediaServices_API.jar} +configs.EmulatorTest.manifest.midlets=MIDlet-2: TestScrobbler,/res/icon.png,seps.TestScrobbler\nMIDlet-1: SEPlayerService, /res/icon.png,seps.Main\n +configs.EmulatorTest.obfuscation.custom= +configs.EmulatorTest.obfuscation.level=0 debug.level=debug +debugger.timeout= deployment.copy.target=deploy deployment.instance=default deployment.jarurl=${dist.jar} deployment.method=NONE deployment.override.jarurl=false dist.dir=dist/${config.active} -dist.jad=SEPlayerService.jad -dist.jar=SEPlayerService.jar +dist.jad=SEPlayerService_v7.0.jad +dist.jar=SEPlayerService_v7.0.jar dist.javadoc.dir=${dist.dir}/doc dist.root.dir=dist extra.classpath=${file.reference.MultimediaServices_API.jar} -file.reference.MultimediaServices_API.jar=../../NetBeans Libraries/MultimediaServices_API.jar filter.exclude.tests=false -filter.excludes=newfile +filter.excludes=seps/TestScrobbler.java filter.more.excludes=**/overview.html,**/package.html filter.use.standard=true jar.compress=true @@ -48,10 +57,11 @@ main.class= main.class.class=applet manifest.apipermissions= manifest.file=manifest.mf +manifest.is.liblet=false manifest.jad= manifest.manifest= -manifest.midlets=MIDlet-1: SEPS,/icon.png,SEPS\n -manifest.others=MIDlet-Vendor: aNNiMON\nMIDlet-Name: SEPlayerService\nMIDlet-Version: 5.3\n +manifest.midlets=MIDlet-1: SEPlayerService, /res/icon.png,seps.Main\n +manifest.others=MIDlet-Vendor: aNNiMON\nMIDlet-Name: SEPlayerService\nMIDlet-Version: 7.0\n manifest.pushregistry= name=SEPlayerService no.dependencies=false @@ -62,13 +72,13 @@ nsicom.application.runverbose= nsicom.remoteapp.location=\\My Documents\\NetBeans Applications nsicom.remotevm.location=\\Windows\\creme\\bin\\CrEme.exe obfuscated.classes.dir=${build.dir}/obfuscated -obfuscation.custom= -obfuscation.level=9 +obfuscation.custom=@E:\\SETUPS\\Disk\\Programming\\Java\\annimon.pro +obfuscation.level=1 obfuscator.destjar=${build.dir}/obfuscated.jar obfuscator.srcjar=${build.dir}/before-obfuscation.jar -platform.active=Sony_Ericsson_SDK_2_5_0_4_for_the_Java_TM__ME_Platform_Emulator_ -platform.active.description=Sony Ericsson SDK 2.5.0.4 for the Java(TM) ME Platform(Emulator) -platform.apis=JSR234-1.0,SATSA-APDU-1.0,capuchin-1.0,JSR211-1.0,JSR75-1.0,J2ME-WS-1.0,J2ME-XMLRPC-1.0,JSR82-1.1,SATSA-JCRMI-1.0,SATSA-CRYPTO-1.0,JSR239-1.0,JSR179-1.0.1,MascotV3-1.0,JSR184-1.1,JSR238-1.0,MMAPI-1.1,JSR256-1.1,NokiaUI-1.0,JSR229-1.1.0,SATSA-PKI-1.0,JSR180-1.0.1,JSR226-1.0,JSR177-1.0,SEMC_EXT_JP8-1.0,VSCL-2.0,VSCL-2.1,WMA-2.0 +platform.active=Sony_Ericsson_SDK_2_5_0_6_for_the_Java_TM__ME_Platform_Emulator_ +platform.active.description=Sony Ericsson SDK 2.5.0.6 for the Java(TM) ME Platform(Emulator) +platform.apis=JSR234-1.0,SATSA-APDU-1.0,capuchin-1.0,J2ME-WS-1.0,J2ME-XMLRPC-1.0,SATSA-JCRMI-1.0,SATSA-CRYPTO-1.0,JSR239-1.0,MascotV3-1.0,JSR238-1.0,MMAPI-1.1,JSR256-1.1,NokiaUI-1.0,JSR229-1.1.0,SATSA-PKI-1.0,JSR180-1.0.1,JSR226-1.0,SEMC_EXT_JP8-1.0,VSCL-2.0,VSCL-2.1,JSR75-1.0,JSR184-1.1,WMA-2.0,JSR211-1.0,JSR82-1.1,JSR177-1.0,JSR179-1.0.1 platform.bootclasspath=${platform.home}/lib/mascotv3.jar:${platform.home}/lib/jsr226.jar:${platform.home}/lib/jsr256.jar:${platform.home}/lib/satsa-crypto.jar:${platform.home}/lib/jsr229.jar:${platform.home}/lib/jsr238.jar:${platform.home}/lib/j2me-xmlrpc.jar:${platform.home}/lib/jsr211.jar:${platform.home}/lib/vscl21.jar:${platform.home}/lib/satsa-jcrmi.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/satsa-apdu.jar:${platform.home}/lib/jsr184.jar:${platform.home}/lib/nokiaext.jar:${platform.home}/lib/capuchin.jar:${platform.home}/lib/jsr239.jar:${platform.home}/lib/jsr75.jar:${platform.home}/lib/satsa-pki.jar:${platform.home}/lib/jsr179.jar:${platform.home}/lib/jsr180.jar:${platform.home}/lib/vscl.jar:${platform.home}/lib/mmapi.jar:${platform.home}/lib/j2me-ws.jar:${platform.home}/lib/wma20.jar:${platform.home}/lib/jsr234.jar:${platform.home}/lib/semc_ext_jp8.jar:${platform.home}/lib/cldcapi11.jar:${platform.home}/lib/midpapi20.jar platform.configuration=CLDC-1.1 platform.device=SonyEricsson_JP8_240x320_Emu diff --git a/src/1.swf b/src/1.swf deleted file mode 100644 index 053818c..0000000 Binary files a/src/1.swf and /dev/null differ diff --git a/src/Canv.java b/src/Canv.java deleted file mode 100644 index db8f84d..0000000 --- a/src/Canv.java +++ /dev/null @@ -1,1039 +0,0 @@ -import com.nokia.mid.ui.DeviceControl; -import com.sonyericsson.multimedia.*; -import com.sonyericsson.multimedia.control.*; -import java.io.IOException; -import java.util.*; -import javax.microedition.io.Connector; -import javax.microedition.lcdui.*; -import javax.microedition.sensor.*; -import mobscrob.scrobbler.AudioScrobbler; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class Canv extends Canvas implements Runnable, MediaControlListener { - - public static int softUp1, softUp2, softDn1, softDn2, background, line, text, valuet, inf; - private boolean rspressed; - - //Меню - private String[] m = new String[] {SEPS.midlet.lang.sleepmode, - SEPS.midlet.lang.findtext, SEPS.midlet.lang.visual, SEPS.midlet.lang.skin, SEPS.midlet.lang.options, SEPS.midlet.lang.about, - SEPS.midlet.lang.minimise, SEPS.midlet.lang.exit}; - private int menuwidth, menuheight, mcur, menuy, menuup; - private boolean menu, skin, vis; - private int volumeplus, volumeminus; //визуализация изменения громкости - private boolean fastF, fastR; //быстрая перемотка - private int cx, cy, thisskin;//выбор скина - private int chngx, chngmode;//переключение mode (all, visual) - private int accelPrevDelta = 0; - - //Скролллинг текста (исп, трек, альб, текст) - private int[] scrollPos = {0,0,0,0}; - private int[] sleepPos = {0,0,0,0}; - private boolean[] scrolldirection = {false, false, false, false}; - private int textWidth, lyricWidth; - - private Image old; - - private int w,h; - private int mode; - - private Lyrics lrc; - public RateImpl ri; - private Engine1 e1, tmpe1; - private Engine2 e2, tmpe2; - private Object tmpswf; - private Images im; - private FWCashe mfwc; - - private byte repeat;//функция повтора - private int a,b; - - public Object swf; - - private boolean updateAlbum; - private Image I, album; - private Graphics G; - private Thread thr; - private final Font medFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM); - private final Font smallFont_b = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL); - - private MultimediaService service = null; - private MediaControl mediaControl = null; - public Media media = null; - - private int[] channels = new int[3]; - private String[] channelNames = new String[3]; - private SensorConnection sensor; - private String URL; - - public Canv(Images im) { - setFullScreenMode(true); - w = getWidth(); - volumeminus = h = getHeight(); - I = Image.createImage(w, h); - G = I.getGraphics(); - this.im = im; - thr = new Thread(this); - thr.start(); - lyricWidth = w/(smallFont_b.charWidth('a')+1); - textWidth = lyricWidth - 3; - mfwc = FWCashe.getCache(medFont); - menuwidth = mfwc.stringWidth(m[0]); - menuheight = m.length * (medFont.getHeight()+2); - for(int i=1; imenuwidth) menuwidth = mfwc.stringWidth(m[i]); - } - menuwidth+=6; - menuy = 2*im.statusBarHeight-menuheight; - updateAlbum = menu = rspressed = false; - volumeplus = menuup = mcur = chngx = repeat = 0; - mode = 0; //Режим плейера - getInfo(); - service = MultimediaServiceManager.getMultimediaService("MediaPlayer"); - mediaControl = (MediaControl)service.getControl("MediaControl"); - mediaControl.addMediaControlListener(this); - cx = w/2; - cy = 4*im.statusBarHeight+im.pal.getHeight()/2; - if(Rms.visid>=6) Rms.visid = 1; - if(Rms.visid>1) swf = new Capuchin(Rms.visid); - if(Rms.stat) { - ri = new RateImpl(); - ri.open(); - } - if(Rms.startPlayer) playTrack(); - } - - protected void sizeChanged(int w, int h) { - w = getWidth(); - h = getHeight(); - volumeminus = h = getHeight(); - I = Image.createImage(w, h); - G = I.getGraphics(); - lyricWidth = w/(smallFont_b.charWidth('a')+1); - textWidth = lyricWidth - 3; - cx = w/2; - super.sizeChanged(w, h); - } - - protected void paint(Graphics g) { - setFullScreenMode(true); - //Выбор визуализации - if(vis) {choiceVisual(g, Rms.visid); return;} - if(skin) {choiceSkin(g, cx, cy); return;} - //Переключение режимов (all, visual) - if(chngx>0) { - if(old==null) { - old = Image.createImage(I.getWidth(), I.getHeight()); - old.getGraphics().drawImage(I, 0, 0, 20); - if(mode==0) drawPlayerCanvas(G); - else if(mode==1) drawVisual(G); - if(chngmode<3) chngx = h; - else chngx = w; - } - switch(chngmode) { - case 0: - g.drawImage(I, 0, -chngx, 20); - g.drawImage(old, 0, h-chngx, 20); - break; - case 1: - g.drawImage(I, 0, chngx, 20); - g.drawImage(old, 0, chngx-h, 20); - break; - case 2: - g.drawImage(old, 0, 0, 20); - g.drawRegion(I, 0, 0, w, h/2, 0, 0, -chngx/2, 20); - g.drawRegion(I, 0, h/2, w, h/2, 0, 0, h/2+chngx/2, 20); - break; - case 3: - g.drawImage(I, 0, 0, 20); - g.drawRegion(old, 0, 0, w, h/2, 0, 0, chngx/2-h/2, 20); - g.drawRegion(old, 0, h/2, w, h/2, 0, 0, -chngx/2+h, 20); - break; - case 4: - g.drawImage(I, -chngx, 0, 20); - g.drawImage(old, w-chngx, 0, 20); - break; - case 5: - g.drawImage(I, chngx, 0, 20); - g.drawImage(old, chngx-w, 0, 20); - break; - case 6: - g.drawImage(old, 0, 0, 20); - g.drawRegion(I, 0, 0, w/2, h, 0, -chngx/2, 0, 20); - g.drawRegion(I, w/2, 0, w/2, h, 0, w/2+chngx/2, 0, 20); - break; - default: - g.drawImage(I, 0, 0, 20); - g.drawRegion(old, 0, 0, w/2, h, 0, chngx/2-w/2, 0, 20); - g.drawRegion(old, w/2, 0, w/2, h, 0, -chngx/2+w, 0, 20); - break; - } - chngx-=4; - repaint(); - }else{ - if(mode==0) drawPlayerCanvas(G); - else if(mode==1) drawVisual(G); - g.drawImage(I, 0, 0, 20); - //Меню - if(menuup!=0) { - if(menuup>0) { - menuy-=25; - if(menuy<=2*im.statusBarHeight-menuheight) {menu = false; menuup=0;} - } else { - menuy+=25; - if(menuy>=2*im.statusBarHeight) {menu = true; menuup=0;} - } - drawMenu(g, mcur, menuy); - }else if(menu) drawMenu(g, mcur, menuy); - //Визуализации изменения громкости - if(volumeplus>0) { - drawRect(g, 0x33000000, 0xAA000000, 0, volumeplus-20, w, 20); - drawRect(g, 0xAA000000, 0x33000000, 0, volumeplus, w, 20); - volumeplus-=10; - } - if(volumeminusih) album = Effects.Resize(album, ih*album.getWidth()/album.getHeight(), ih); - g.drawImage(album, w/2, h/2, 3); - }else if(Rms.vis){ - if(Rms.visid==0) { - if(e2==null) { - e2 = new Engine2(w, ih); - e2.setRun(true); - } - g.drawImage(e2.MainCanvas(), w/2, h/2, 3); - } else if(Rms.visid==1) { - if(e1==null) { - e1 = new Engine1(w, ih); - e1.setRun(true); - } - g.drawImage(e1.MainCanvas(), w/2, h/2, 3); - } else{ - ((Capuchin) swf).drawFlash(g, 3, h/2-(ih/2), w-6, ih); - } - } - if(Rms.isLyric && lrc!=null) { - try { - drawCenter(g, lrc.get5Lines(media.getMediaTime())); - } catch (Exception e) {} - } - } - } - drawSoft(g); - } - - private String getValue(MetaData metaData, String md) { - String data = metaData.getValue(md); - StringBuffer sb = new StringBuffer(); - for(int i=0; iih) album = Effects.Resize(album, ih*album.getWidth()/album.getHeight(), ih); - g.drawImage(album, w/2, py+15, 17); - }else if(Rms.vis){ - int ih = h-fh-2-py-20; - if(Rms.visid==0) { - if(e2==null) { - e2 = new Engine2(ih, ih); - e2.setRun(true); - } - g.drawImage(e2.MainCanvas(), w/2, py+15, 17); - } else if(Rms.visid==1) { - if(e1==null) { - e1 = new Engine1(ih, ih); - e1.setRun(true); - } - g.drawImage(e1.MainCanvas(), w/2, py+15, 17); - }else{ - ((Capuchin) swf).drawFlash(g, w/2-ih/2, py+15, ih, ih); - } - } - g.setColor(inf); - if(Rms.slpmode) g.drawString("S", 2, py+15+3*(smallFont_b.getHeight()+2), 20); - drawSoft(g); - } - - public void keyPressed(int key) { - if(key==-6 && !menu) { - menuup = menu?1:-1; - } - if((menuup!=0 || menu) && !vis && !skin) { - if(key==-6) { - menuup = menu?1:-1; - } - int ga=getGameAction(key); - switch (ga) { - case UP: - mcur--; - if(mcur<0) mcur=m.length-1; - break; - case DOWN: - mcur++; - if(mcur>=m.length) mcur=0; - break; - case FIRE: - menuAction(mcur); - break; - } - }else if(vis) { - int ga=getGameAction(key); - switch (ga) { - case UP: - case LEFT: - Rms.visid--; - if(Rms.visid<0) Rms.visid=5; - tmpswf=null; - break; - case DOWN: - case RIGHT: - Rms.visid++; - if(Rms.visid>=6) Rms.visid=0; - tmpswf=null; - break; - } - if(ga==FIRE || key==-6) { - tmpe2=null; tmpe1=null; tmpswf=null; - if(Rms.visid>1) swf = new Capuchin(Rms.visid); - vis = false; - } - }else if(skin) { - int ga=getGameAction(key); - if(ga==UP) {cy--;if(cy<4*im.statusBarHeight) cy=4*im.statusBarHeight+im.pal.getHeight()-1;} - else if(ga==DOWN) {cy++;if(cy>=4*im.statusBarHeight+im.pal.getHeight()) cy=4*im.statusBarHeight+1;} - else if(ga==LEFT) {cx--;if(cx=w/2+im.pal.getWidth()/2) cx=w/2-im.pal.getWidth()/2;} - else if(ga==FIRE || key==-6) { - Rms.skinid = thisskin; - new Skin(Rms.skinid); - skin = false; - } - }else{ - if(key==-7) rspressed = true; - else if(key==KEY_POUND) Rms.accel=!Rms.accel; - else if(key==KEY_STAR) Rms.vis=!Rms.vis; - else if(key==KEY_NUM0) Rms.isLyric=!Rms.isLyric; - else if(key== -36) volumeplus = h;//vol+; - else if(key== -37) volumeminus = 0;//vol-; - } - repaint(); - } - - public void keyReleased(int key) { - if(menuup!=0 || menu) return; - int ga=getGameAction(key); - if(key==-7) { - rspressed = false; - if(Rms.closePlayer) pauseTrack(); - SEPS.midlet.destroyApp(true); - }else if(key==KEY_NUM9) new SetSleepMode(); - if(key==KEY_NUM4) rewind(); - else if(key==KEY_NUM6) fastForward(); - if(ga==LEFT && key!=KEY_NUM4) prevTrack(); - else if(ga==RIGHT && key!=KEY_NUM6) nextTrack(); - if(key==KEY_NUM3) ABRepeat(); - else if(key==KEY_NUM1) { - String art="",tit=""; - try{ - MetaData metaData = SEPS.midlet.cnv.media.getMetaData(); - tit = getValue(metaData, MetaData.TITLE_KEY); - art = getValue(metaData, MetaData.ARTIST_KEY); - }catch(Exception ex){} - FindLyrics fl = new FindLyrics(); - fl.find(art, tit);//SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - } - switch(ga) { - case UP: - upMode(); - break; - case DOWN: - upMode(); - break; - case FIRE: - try { - if (mediaControl.getState() == mediaControl.STATE_PLAY) pauseTrack(); - else playTrack(); - } catch (Exception e) { - } - break; - } - repaint(); - } - - public void keyRepeated(int key) { - if(key==KEY_NUM4) { - try { - if(!fastR) { - mediaControl.rewind(); - fastR = true; - } - } catch (ControlException ex) { - ex.printStackTrace(); - } - }else if(key==KEY_NUM6) { - try { - if(!fastF) { - mediaControl.fastForward(); - fastF = true; - } - } catch (ControlException ex) { - ex.printStackTrace(); - } - - }else keyPressed(key); - } - - public int getDelta(int channel, int threshold) { - int delta = 0; - try { - Data[] data = sensor.getData(1, -1, false, false, false); - int drx = 0; - - for (int i = 0; i < data.length; i++) { - if (data[i].getChannelInfo().getName().equals(channelNames[channel])) { - drx = data[i].getIntValues()[0]; - } - } - - delta = channels[channel] - drx; - channels[channel] = drx; - - if (Math.abs(delta) < threshold) { - delta = 0; - } - } catch (Throwable t) { - } - - return delta; - } - - public void run() { - while (true) { - try { - if(Rms.light) DeviceControl.setLights(0, 100); - final int delta = getDelta(0, Rms.sensetivity); - if (delta != 0) { - if (accelPrevDelta != 0 && (delta * accelPrevDelta) < 0) { - accelPrevDelta = 0; - } else { - accelPrevDelta = delta; - - Runnable runnable = new Runnable() { - - public void run() { - if (delta > 0 && Rms.accel) { - nextTrack(); - } else if (delta < 0 && Rms.accel) { - if(Rms.listfw) nextTrack(); - else prevTrack(); - } - } - }; - (new Thread(runnable)).start(); - } - } - if(!Rms.vis) Thread.sleep(100); - if(Rms.slpmode) { - if(checkTime()) { - pauseTrack(); - SEPS.midlet.destroyApp(true); - } - } - if(repeat==2) { - try { - int mgt = media.getMediaTime(); - int sk = Math.abs(b-a); - if(mgt>=b) mediaControl.skip(-sk); - } catch (ControlException ex) { - ex.printStackTrace(); - } - } - if((Rms.stat || Rms.urlstat || Rms.actmenu) && media!=null) { - MetaData metaData = media.getMetaData(); - Object data = getValue(metaData, MetaData.ARTIST_KEY); - String thisSong = (String) data; - data = getValue(metaData, MetaData.TITLE_KEY); - thisSong = thisSong+" - "+ (String) data; - if(!thisSong.equalsIgnoreCase(Rms.lastSong)) { - int thisTime = media.getMediaTime(); - int allTime = media.getDuration()*50/*% проиграно*//100; - if(thisTime>allTime) { - int cn = 1; - - try { - //GetPass - String username = "aNMCore"; //[0] - String password = "abcdcba"; //[1] - String md5pass = ""; //[2] - if (md5pass.equals("")) { - md5pass = AudioScrobbler.GetPasswordMD5(password); - } - //if (audioscrobbler == null) - AudioScrobbler audioscrobbler = new AudioScrobbler("tst", "1.0", username, md5pass); - audioscrobbler.connect(); - Thread.sleep(3000); - audioscrobbler.Submit( - (String) getValue(metaData, MetaData.ARTIST_KEY), - (String) getValue(metaData, MetaData.TITLE_KEY), - (String) getValue(metaData, MetaData.ALBUM_KEY), - "1", media.getDuration() - ); - - /*MobScrobblerImpl ms = new MobScrobblerImpl(); - ms.scrobble( - (String) getValue(metaData, MetaData.ARTIST_KEY), - (String) getValue(metaData, MetaData.TITLE_KEY), - (String) getValue(metaData, MetaData.ALBUM_KEY), - media.getDuration(), - thisTime - );*/ - }catch(Exception ex) { - SEPS.midlet.dsp.setCurrent(new Alert("Ahtung", ex.getMessage(), null, AlertType.INFO)); - } - - if(Rms.stat) { - Rms.lastSong = thisSong; - cn = ri.update(thisSong); - } - if(Rms.urlstat) { - FindLyrics fl = new FindLyrics(); - fl.scrob(thisSong); - Rms.lastSong = thisSong; - } - if(Rms.actmenu) { - try { - Image icon = Image.createImage("/icon.png"); - StringBuffer sb = new StringBuffer();//String desc = ""; - if(Rms.stat) { sb.append(cn); sb.append(" |");} - allTime = media.getDuration(); - int hh = 0, m=0, s = 0; - if(allTime<60) s=allTime; - else { - if(allTime<3600) { - m = allTime/60; - s = allTime - m*60; - }else{ - m = allTime/60; - hh = m/60; m=m-hh*60; - } - } - if(hh>0) {sb.append(hh); sb.append(" :");} - if(m>0) {if(m>10) sb.append(0); sb.append(m); sb.append(" :");} - if(s>10) sb.append(0); - sb.append(s); - com.sonyericsson.ui.UIActivityMenu.getInstance(SEPS.midlet).addEvent(thisSong, sb.toString(), icon, null); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - } - } - if (service != null) { - repaint(); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - /** - * Переключение трека - */ - private void newTrack() { - a=b=0; repeat = 0; - SEPS.midlet.dsp.vibrate(Rms.vibrlen); - if (Rms.flash) { - DeviceControl.setLights(0, 0); - DeviceControl.setLights(0, 100); - } - } - - private void getInfo() { - SensorInfo[] info = SensorManager.findSensors("acceleration", null); - for (int i = 0; i < info.length; i++) { - SensorInfo s = info[i]; - URL = s.getUrl(); - ChannelInfo[] ci = s.getChannelInfos(); - for (int r = 0; r < ci.length; r++) { - ChannelInfo c = ci[r]; - channelNames[r] = c.getName(); - } - } - try { - sensor = (SensorConnection) Connector.open(URL); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - private void initLyric(Media med) { - if (med == null) {return;} - lrc = null; - String at = ""; - String fl = ""; - MetaData metaData = med.getMetaData(); - if (metaData != null) { - Object data = getValue(metaData, MetaData.ARTIST_KEY); - if (data != null) at=at +(String)(data) + " - "; - - data = getValue(metaData, MetaData.TITLE_KEY); - if (data != null) at+=(String) data; - - data = getValue(metaData, MetaData.FILE_URI_KEY); - if (data != null) {fl=(String) data;fl=fl.substring(fl.lastIndexOf('/')+1, fl.lastIndexOf('.'));} - - if(Lyrics.isExists(at)) lrc = new Lyrics(at); - else if(Lyrics.isExists(fl)) lrc = new Lyrics(fl); - } - } - - private void nextTrack() { - try { - newTrack(); - mediaControl.next(); - } catch (ControlException ex) { - ex.printStackTrace(); - } - } - - private void prevTrack() { - try { - newTrack(); - mediaControl.prev(); - } catch (ControlException ex) { - ex.printStackTrace(); - } - } - - public void pauseTrack() { - try { - mediaControl.pause(); - } catch (ControlException ex) { - ex.printStackTrace(); - } - } - - private void playTrack() { - try { - mediaControl.play(); - } catch (ControlException ex) { - ex.printStackTrace(); - } - } - - private void fastForward() { - try { - if(fastF) { - fastF = false; - mediaControl.play(); - } - else mediaControl.skip(10); - } catch (ControlException ex) { - ex.printStackTrace(); - } - } - - private void rewind() { - try { - if(fastR) { - fastR = false; - mediaControl.play(); - } - else mediaControl.skip(-10); - } catch (ControlException ex) { - ex.printStackTrace(); - } - } - - public void mediaControlUpdate(int eventId, ControlEvent event) { - try { - switch (eventId) { - case MediaControlListener.PLAY: - case MediaControlListener.PAUSE: - case MediaControlListener.STOP: - case MediaControlListener.ENDPLAY: - case MediaControlListener.FASTFORWARD: - case MediaControlListener.REWIND: - this.media = (Media) event.getData(); - break; - case MediaControlListener.ERROR: - //errorString = (String) event.getData(); - //canvas.removeCommand(pauseCommand); - //canvas.addCommand(playCommand); - break; - default: - break; - } - MetaData data = this.media.getMetaData(); - if (data != null) { - byte[] alb = data.getAlbumArt(); - if (alb != null) album = Image.createImage(alb, 0, alb.length); - else album = null; - } - a = b = 0; repeat = 0; - if(Rms.isLyric) initLyric(this.media); - } catch (Throwable t) { - t.printStackTrace(); - } - - } - - private void upMode() { - old = null; - chngmode = random(0,8); - chngx = 2; - mode = 1-mode; - e2=null; - e1=null; - if(album!=null) updateAlbum = true; - } - - private void menuAction(int i) { - if(m[i].equals(SEPS.midlet.lang.sleepmode)) SEPS.midlet.dsp.setCurrent(new SetSleepMode()); - else if(m[i].equals(SEPS.midlet.lang.findtext)) { - MetaData metaData = this.media.getMetaData(); - String all = getValue(metaData, MetaData.ARTIST_KEY) + " - " + getValue(metaData, MetaData.TITLE_KEY); - SEPS.midlet.dsp.setCurrent(new FindText(all)); - } - else if(m[i].equals(SEPS.midlet.lang.options)) SEPS.midlet.dsp.setCurrent(new Options()); - else if(m[i].equals(SEPS.midlet.lang.about)) SEPS.midlet.dsp.setCurrent(new Info()); - else if(m[i].equals(SEPS.midlet.lang.minimise)) SEPS.midlet.dsp.setCurrent(null); - else if(m[i].equals(SEPS.midlet.lang.exit)) SEPS.midlet.destroyApp(true); - else if(m[i].equals(SEPS.midlet.lang.skin)) skin = true; - else if(m[i].equals(SEPS.midlet.lang.visual)) vis = true; - } - - //GUI - GRAPHICAL USER INTERFACE - - private int drawText(Graphics g, String value, int y, int id) { - g.setColor(line); - g.drawLine(3, y-1, w-3, y-1); - g.setColor(valuet); - g.setFont(smallFont_b); - g.drawString(value, (id!=3?im.track.getWidth()+4:w/2), y, (id!=3?20:17)); - return y+(smallFont_b.getHeight()+2); - } - - private void drawMenu(Graphics g, int cur, int y) { - ACLS(g,180,0x00); - int fh = medFont.getHeight()+2; - int x = w/2-menuwidth/2; - for(int i=0; i(h-2*im.statusBarHeight)) ww = h-2*im.statusBarHeight; - if(cur==0) { - if(tmpe2==null) tmpe2 = new Engine2(ww, ww); - kdr = tmpe2.MainCanvas(); - }else if(cur==1) { - if(tmpe1==null) tmpe1 = new Engine1(ww, ww); - kdr = tmpe1.MainCanvas(); - }else { - if(tmpswf==null) tmpswf = new Capuchin(Rms.visid); - kdr = ((Capuchin)tmpswf).getImage(ww, ww); - } - g.drawImage(Effects.reflection(kdr, 0.5D), w/2, 2*im.statusBarHeight, 17); - drawTitle(g, getTime()); - } - - private void choiceSkin(Graphics g, int cx, int cy) { - g.setColor(0); - int x = w/2-im.pal.getWidth()/2; - g.fillRect(0, 0, w, h); - g.drawImage(im.pal, x, 4*im.statusBarHeight, 20); - //cursor - g.setColor(0x00); - int dcur = 4; - g.drawLine(cx + 1, cy, cx + dcur, cy); - g.drawLine(cx - dcur, cy, cx - 1, cy); - g.drawLine(cx, cy - dcur, cx, cy - 1); - g.drawLine(cx, cy + 1, cx, cy + dcur); - // - thisskin=Effects.get(im.pal, cx-x, cy-4*im.statusBarHeight); - drawTitle(g, Integer.toHexString(thisskin)); - } - - private void drawSoft(Graphics g) { - int fh = medFont.getHeight()+2; - int wsoft = 26; - int msoft = (w-wsoft*2)/3; - g.setFont(medFont); - //Линия - g.setColor(0); - g.drawLine(0, h-fh-1, w, h-fh-1); - //Меню - drawRect(g, (menuup!=0 || menu)?softUp1:softDn1, (menuup!=0 || menu)?softUp2:softDn2, 0, h-fh, wsoft, fh); - g.setColor(valuet); - g.fillTriangle(wsoft/2, h-5, 3, h-fh+7, wsoft-3, h-fh+7); - //Выход - drawRect(g, rspressed?softUp1:softDn1, rspressed?softUp2:softDn2, w-wsoft, h-fh, wsoft, fh); - g.drawImage(im.exit, w-2, h-fh, 24); - //* - Визуализация - drawRect(g, Rms.vis?softUp1:softDn1, Rms.vis?softUp2:softDn2, wsoft, h-fh, msoft, fh); - g.drawChar('*', wsoft+msoft/6, h-fh+2, 20); - g.drawImage(im.star, wsoft+msoft-msoft/6, h-fh+fh/2, 10); - //0 - Тексты Песен - drawRect(g, Rms.isLyric?softUp1:softDn1, Rms.isLyric?softUp2:softDn2, wsoft+msoft, h-fh, w-2*(wsoft+msoft), fh); - g.drawChar('0', w/2-msoft/4, h-fh+2, 17); - g.drawImage(im.zero, w/2+msoft/4, h-fh+fh/2, 3); - // - Акселерометр - drawRect(g, Rms.accel?softUp1:softDn1, Rms.accel?softUp2:softDn2, w-wsoft-msoft, h-fh, msoft, fh); - g.drawChar('#', w-wsoft-msoft+msoft/6, h-fh+2, 20); - g.drawImage(im.pound, w-wsoft-msoft/6, h-fh+fh/2, 10); - } - - private void drawTitle(Graphics g, String text) { - g.setColor(valuet); - g.setFont(medFont); - int k = im.titleleft.getWidth(); - for(int i=k; i> 24) & 0xff; - int r1 = (color1 >> 16) & 0xff; - int g1 = (color1 >> 8) & 0xff; - int b1 = color1 & 0xff; - int a2 = (color2 >> 24) & 0xff; - int r2 = (color2 >> 16) & 0xff; - int g2 = (color2 >> 8) & 0xff; - int b2 = color2 & 0xff; - int beforecolor = g.getColor(); - int crd1, crd2; - int count = h/3; - if (count < 0) count = -count; - if (count < 8) count = 8; - boolean lite = false; - if(a1==0xff && a2==0xff) lite = true; - for (int i=count-1; i>=0; i--) { - crd1 = i*h/count+y1; - crd2 = (i+1)*h/count+y1; - if (crd1 == crd2) continue; - if(lite) { - g.setColor(i * (r2 - r1) / (count - 1) + r1, i * (g2 - g1) / (count - 1) + g1, i * (b2 - b1) / (count - 1) + b1); - g.fillRect(x1, crd1, w, crd2 - crd1); - }else{ - int[] pixelArray = new int[w * (crd2 - crd1)]; - for(int zi = 0; zi < pixelArray.length; zi++) - pixelArray[zi] = (int) ((i * (a2 - a1) / (count - 1) + a1) << 24) | - ((i * (r2 - r1) / (count - 1) + r1) << 16) | - ((i * (g2 - g1) / (count - 1) + g1) << 8) | (i * (b2 - b1) / (count - 1) + b1); - g.drawRGB(pixelArray, 0, w, x1, crd1, w, crd2 - crd1, true); - } - } - g.setColor(beforecolor); - } - - private void ACLS(Graphics g, int a1, int color) { - int[] pixelArray = new int[g.getClipWidth() * g.getClipHeight()]; - for(int i = 0; i < pixelArray.length; i++) - pixelArray[i] = (int) (a1 << 24| color & 0x00ffffff); - g.drawRGB(pixelArray, 0, g.getClipWidth(), 0, 0, g.getClipWidth(), g.getClipHeight(), true); - } - - //Methods - - private boolean checkTime() { - Calendar cal = Calendar.getInstance (); - int ch = cal.get(Calendar.HOUR_OF_DAY); - int cm = cal.get(Calendar.MINUTE); - if(ch!=Rms.dh) return false; - else return (cm>=Rms.dm); - } - - private String getTime() { - StringBuffer sb = new StringBuffer(); - Calendar cal = Calendar.getInstance(); - int tmp; - tmp = cal.get(Calendar.HOUR_OF_DAY); - if(tmp<=9) sb.append('0'); sb.append(tmp); - sb.append(':'); - //Минута - tmp = cal.get(Calendar.MINUTE); - if(tmp<=9) sb.append('0'); sb.append(tmp); - return sb.toString(); - } - - private int random(int min, int max) { - return min + ((new Random().nextInt() >>> 1)%(max-min)); - } - - private void ABRepeat() { - try { - repeat++; - switch (repeat) { - case 1: // ставим A - a = media.getMediaTime(); - break; - case 2: // ставим B - b = media.getMediaTime(); - if(a>b) { - int t = b; b=a; a=t; - } - break; - case 3: // конец повтора - a = b = 0; - repeat = 0; - break; - } - } catch (Exception e) { - } - } - - private String scrollText(String text, int id) { - int count; - if(id==3) count = lyricWidth; - else count = textWidth; - String tmp = text; - int lent = text.length(); - int scr = lent - count; - try { - if (lent > count) { - tmp = text.substring(scrollPos[id], scrollPos[id] + count); - if(sleepPos[id] scr) { - scrollPos[id]--; - scrolldirection[id] = !scrolldirection[id]; - } else if (scrollPos[id] < 0) { - scrollPos[id] = 0; - scrolldirection[id] = !scrolldirection[id]; - } - sleepPos[id] = 0; - } - } - }catch(Exception ex) {tmp = text;} - return tmp; - } -} \ No newline at end of file diff --git a/src/Capuchin.java b/src/Capuchin.java deleted file mode 100644 index 007c457..0000000 --- a/src/Capuchin.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -import com.sonyericsson.capuchin.*; -import javax.microedition.lcdui.*; - -/** - * @author aNNiMON - */ -public class Capuchin { - - public FlashImage flashImage; - - public Capuchin(int i) { - flashImage = null; - try - { - flashImage = FlashImage.createImage(getClass().getResourceAsStream("/"+String.valueOf(i-1)+".swf"), null); - } - catch(Exception ex) {} - } - - public void drawFlash(Graphics g, int x, int y, int w, int h) { - if(flashImage!=null) flashImage.render(g, x, y, w, h); - } - - public Image getImage(int w, int h) { - Image img = Image.createImage(w, h); - Graphics g = img.getGraphics(); - if(flashImage!=null) flashImage.render(g, 0, 0, w, h); - return img; - } -} \ No newline at end of file diff --git a/src/Engine1.java b/src/Engine1.java deleted file mode 100644 index 6a401d3..0000000 --- a/src/Engine1.java +++ /dev/null @@ -1,195 +0,0 @@ -import java.util.Random; -import javax.microedition.lcdui.*; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class Engine1 implements Runnable{ - - public Image db; - private Graphics G; - private int w,h; - private int K,i,mode; - private int max, spd, cf; - private int[] starx,stary,starz; - private long time, dt; - private boolean up,dn; - private Random rnd; - private Thread thr; - public boolean run; - - public Engine1(int w, int h) { - this.w=w; - this.h=h; - db = Image.createImage(w, h); - G=db.getGraphics(); - rnd = new Random(); - max = 300; spd = 200; K=60; - mode = (rnd.nextInt() >>> 1) % 4; - init(max); - time = System.currentTimeMillis(); - thr = new Thread(this); - thr.start(); - } - - public void run() { - while (run) { - if(up) { - while(cf!=0) { - spd++; cf--; - try { Thread.sleep(25L);} catch (InterruptedException ex) {ex.printStackTrace();} - } - up=false; - } - if(dn) { - while(cf!=0) { - spd--; cf--; - try { Thread.sleep(25L);} catch (InterruptedException ex) {ex.printStackTrace();} - } - dn=false; - } - int r = (rnd.nextInt() >>> 1) % 20; - switch(r) { - case 5: up=true; cf=100; break; - case 15: up=true; cf=400; break; - case 8: dn=true; cf=100; break; - case 18: dn=true; cf=400; break; - case 3: if(max>11) max-=10; break; - case 13: if(max<1000) init(max+=100); break; - case 4: if(K<84) K+=15; break; - case 14: if(K>16) K-=15; break; - case 6: mode = (rnd.nextInt() >>> 1) % 4; break; - } - try { - if(spd<25 && spd>-25) Thread.sleep(500L); - else Thread.sleep(2000L); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - } - } - - public void setRun(boolean run) { - this.run=run; - } - - public Image MainCanvas() { - dt = System.currentTimeMillis() - time; - time = System.currentTimeMillis(); - if(K>=3) ACLS(G); - else CLS(G); - for (i = 1; i0) { - if (starz[i] <= -200) { - starx[i] = (rnd.nextInt()>>>1)%(w * 4) - w * 2; - stary[i] = (rnd.nextInt()>>>1)%(h * 4) - h * 2; - starz[i] = (rnd.nextInt()>>>1)%1900; - } - SetPix((255 - 255 * (starz[i] + 200) / 2100)); - }else{ - if (starz[i] > 2000) { - starx[i] = (rnd.nextInt()>>>1)%(w * 4) - w * 2; - stary[i] = (rnd.nextInt()>>>1)%(h * 4) - h * 2; - starz[i] = (rnd.nextInt()>>>1)%1900; - } - SetPix((255-255 * (starz[i]%2100) / 2100)); - } - } - return db; - } - - private void CLS(Graphics g) { - g.setColor(0); - g.fillRect(0, 0, w, h); - } - - private void ACLS(Graphics g) { - int[] pixelArray = new int[w * h]; - for (int io = 0; io < pixelArray.length; io++) { - pixelArray[io] = (int) ((100-K) << 24) | 0; - } - g.drawRGB(pixelArray, 0, w, 0, 0, w, h, true); - } - - private void SetPix(int c) { - int sx, sy, sx1 = 0, sy1 = 0; - sx = (w / 2 + starx[i] * 200 / (starz[i] + 200)); - sy = (h / 2 - stary[i] * 200 / (starz[i] + 200)); - if(c>255) c=255; if(c<0) c=0; - switch(mode) { - case 0: - G.setColor(c, c, c); - if(i!=22) G.drawLine(sx, sy, sx, sy); - else try{G.fillRoundRect(sx, sy, starz[i]/(255-c), starz[i]/(255-c), i, i);}catch(Exception ex) {}; - break; - case 1: - G.setColor(c, c, c); - int u=starz[i]==0?1:starz[i]; - G.fillArc(sx, sy, c/u, c/u, 0, 360); - break; - case 2: - u=(rnd.nextInt()>>>1)%6; - switch(u) { - case 0: G.setColor(255-c, c, c); break; - case 1: G.setColor(c, 255-c, c); break; - case 2: G.setColor(c, c, 255-c); break; - case 3: G.setColor(255-c, 255-c, c); break; - case 4: G.setColor(255-c, c, 255-c); break; - case 5: G.setColor(c, 255-c, 255-c); break; - case 6: G.setColor(255-c, 255-c, 255-c); break; - } - if(i!=22) G.drawLine(sx, sy, sx, sy); - else try{G.fillRoundRect(sx, sy, starz[i]/(255-c), starz[i]/(255-c), i, i);}catch(Exception ex) {}; break; - case 3: - u=rnd.nextInt()%6; - switch(u) { - case 0: G.setColor(255-c, c, c); break; - case 1: G.setColor(c, 255-c, c); break; - case 2: G.setColor(c, c, 255-c); break; - case 3: G.setColor(255-c, 255-c, c); break; - case 4: G.setColor(255-c, c, 255-c); break; - case 5: G.setColor(c, 255-c, 255-c); break; - case 6: G.setColor(255-c, 255-c, 255-c); break; - } - u=starz[i]==0?1:starz[i]; - G.fillArc(sx, sy, c/u, c/u, 0, 360); - break; - case 4: - u=rnd.nextInt()%6; - switch(u) { - case 0: G.setColor(255-c, c, c); break; - case 1: G.setColor(c, 255-c, c); break; - case 2: G.setColor(c, c, 255-c); break; - case 3: G.setColor(255-c, 255-c, c); break; - case 4: G.setColor(255-c, c, 255-c); break; - case 5: G.setColor(c, 255-c, 255-c); break; - case 6: G.setColor(255-c, 255-c, 255-c); break; - } - if(i>1) { - sx1 = (w / 2 + starx[i-1] * 200 / (starz[i-1] + 200)); - sy1 = (h / 2 - stary[i-1] * 200 / (starz[i-1] + 200)); - } - G.drawLine(sx1, sy1, sx, sy); break; - } - - } - - - - private void init(int max) { - starx = new int[max];stary = new int[max];starz = new int[max]; - for (i = 0; i>>1)%(w * 4) - w * 2; - stary[i] = (rnd.nextInt()>>>1)%(h * 4) - h * 2; - starz[i] = (rnd.nextInt()>>>1)%1900; - } - CLS(G); - } -} diff --git a/src/FindLyrics.java b/src/FindLyrics.java deleted file mode 100644 index 8c824c3..0000000 --- a/src/FindLyrics.java +++ /dev/null @@ -1,142 +0,0 @@ - -import java.io.*; -import javax.microedition.io.*; -import javax.microedition.io.file.FileConnection; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class FindLyrics { - - String MSG; - - public FindLyrics() { - - } - public boolean find(String artist, String title) { - MSG = ""; - String url = "http://www.lyricsplugin.com/winamp03/plugin/?artist="+urlName(artist)+"&title="+urlName(title); - try { - byte[] res = send(url); - int lr1 = MSG.indexOf("
"); - int lr2 = MSG.indexOf("
", lr1); - if((lr2-lr1)>30) { - FileConnection fc; - fc = (FileConnection) Connector.open("file:///" + Rms.lrcpath+artist+" - "+title+".html"); - if(fc.exists()) fc.delete(); - fc.create(); - OutputStream os = fc.openOutputStream(); - os.write(res); - os.flush(); - os.close(); - fc.close(); - return true; - } - } catch (Exception e) { - } - return false; - } - - public void scrob(String song) { - String artist = song.substring(0, song.lastIndexOf('-')).trim(); - String title = song.substring(song.lastIndexOf('-')+1).trim(); - MSG = ""; - String url = "http://annimon.com/seps/seps.php?id="+Rms.id+"&a="+urlName(artist)+"&t="+urlName(title); - try { - send(url); - } catch (Exception e) { - } - } - - private byte[] send(String url) throws Exception { - HttpConnection hc = null; - InputStream is = null; - byte[] res = null; - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - try { - hc = (HttpConnection) Connector.open(url); - int ch; - is = hc.openInputStream(); - StringBuffer sb = new StringBuffer(); - while ((ch = is.read()) != -1) { - sb.append(StringEncoder.decodeCharCP1251((byte)ch)); - bos.write(ch); - } - MSG = sb.toString(); - res = bos.toByteArray(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (bos != null) bos.close(); - if (is != null) is.close(); - if (hc != null) hc.close(); - } catch (Exception e2) { - e2.printStackTrace(); - } - } - return res; - } - - private String urlName(String url) { - if (url == null) return null; - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < url.length(); i++) { - char ch = url.charAt(i); - switch (ch) { - default: - if (ch < '\200') { - sb.append(ch); - break; - } - if (ch > '\177' && ch < '\u0800') { - sb.append('%'); - sb.append(Integer.toHexString((ch >> 6 | 0xc0) + 256).substring(1)); - sb.append('%'); - sb.append(Integer.toHexString((ch & 0x3f | 0x80) + 256).substring(1)); - break; - } - if (ch > '\u07FF' && ch < '\0') { - sb.append('%'); - sb.append(Integer.toHexString((ch >> 12 | 0xe0) + 256).substring(1)); - sb.append('%'); - sb.append(Integer.toHexString((ch >> 6 & 0x3f | 0x80) + 256).substring(1)); - sb.append('%'); - sb.append(Integer.toHexString((ch & 0x3f | 0x80) + 256).substring(1)); - } - break; - case 0: //'\0' - case 32: sb.append("%20"); break;// ' ' - case 61: sb.append("%3d"); break;// '=' - case 43: sb.append("%2b"); break;// '+' - case 39: sb.append("%27"); break;// '\'' - case 46: sb.append("%2E"); break;// '.' - case 60: sb.append("%3c"); break;// '<' - case 62: sb.append("%3e"); break;// '>' - case 35: sb.append("%23"); break;// '#' - case 37: sb.append("%25"); break;// '%' - case 38: sb.append("%26"); break;// '&' - case 123:sb.append("%7b"); break;// '{' - case 125:sb.append("%7d"); break;// '}' - case 92: sb.append("%5c"); break;// '\\' - case 94: sb.append("%5e"); break;// '^' - case 126:sb.append("%73"); break;// '~' - case 91: sb.append("%5b"); break;// '[' - case 93: sb.append("%5d"); break;// ']' - case 58: sb.append("%3A"); break;// ':' - case 47: sb.append("%2F"); break;// '/' - case 63: sb.append("%3F"); break;// '?' - case 45: sb.append("%2D"); break;// '-' - case 33: sb.append("%21"); break;// '!' - case 59: sb.append("%3B"); break;// ';' - } - } - return sb.toString(); - } -} diff --git a/src/FindText.java b/src/FindText.java deleted file mode 100644 index 0105e55..0000000 --- a/src/FindText.java +++ /dev/null @@ -1,41 +0,0 @@ -import javax.microedition.lcdui.*; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -/** - * - * @author aNNiMON - */ -public class FindText extends Form implements CommandListener { - - private Command back, ok; - public TextField all_tb; - - public FindText(String all) { - super(SEPS.midlet.lang.findtext); - back = new Command(SEPS.midlet.lang.back, Command.BACK, 2); - ok = new Command(SEPS.midlet.lang.ok, Command.OK, 1); - all_tb = new TextField(SEPS.midlet.lang.artist, all, 512, TextField.ANY); - append(all_tb); - addCommand(ok); - addCommand(back); - setCommandListener(this); - SEPS.midlet.dsp.setCurrent(this); - } - - public void commandAction(Command c, Displayable d) { - if (c == back) SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - - if (c == ok) { - try { - FindLyrics fl = new FindLyrics(); - int id = all_tb.getString().indexOf(" - "); - boolean check = fl.find(all_tb.getString().substring(0, id), all_tb.getString().substring(id+3)); - if(check) append(SEPS.midlet.lang.textsaving); - else append(SEPS.midlet.lang.nofound); - }catch(Exception ex){} - } - } -} diff --git a/src/Info.java b/src/Info.java deleted file mode 100644 index 0bf29e2..0000000 --- a/src/Info.java +++ /dev/null @@ -1,68 +0,0 @@ -import java.io.DataInputStream; -import javax.microedition.io.ConnectionNotFoundException; -import javax.microedition.lcdui.*; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class Info extends Form implements CommandListener { - private Command back = new Command(SEPS.midlet.lang.back, Command.BACK, 1); - private StringItem Text; - private Command site = new Command(SEPS.midlet.lang.site, Command.HELP, 2); - private Command scrob = new Command(SEPS.midlet.lang.scrobdb, Command.HELP, 3); - - - public Info() { - super(SEPS.midlet.lang.about); - String str = getText("/about"); - Text = new StringItem(null, str); - append(Text); - addCommand(site); - addCommand(back); - if(Rms.urlstat) { - addCommand(scrob); - append("ID="+Rms.id); - } - setCommandListener(this); - } - - public void commandAction(Command c, Displayable d) { - if(c==back) SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - if(c==site) { - try { - String url = "http://annimon.com/"; - if(url.length()!=19) return; - SEPS.midlet.platformRequest(url); - } catch (ConnectionNotFoundException ex) { - SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - } - } - if(c==scrob) { - try { - String url = "http://annimon.com/seps/seps.php?id="+String.valueOf(Rms.id); - SEPS.midlet.platformRequest(url); - } catch (ConnectionNotFoundException ex) { - SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - } - } - } - - private String getText(String path) { - DataInputStream dis = new DataInputStream(getClass().getResourceAsStream(path)); - StringBuffer strBuff = new StringBuffer(); - int ch = 0; - try { - while ((ch = dis.read()) != -1) { - strBuff.append(StringEncoder.decodeCharCP1251((byte)ch)); - } - dis.close(); - } catch (Exception e) {e.printStackTrace();} - return strBuff.toString(); - } -} diff --git a/src/Lang.java b/src/Lang.java deleted file mode 100644 index 5669a1a..0000000 --- a/src/Lang.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class Lang { - - String menu, back, exit, ok, findtext, artist, textsaving, nofound; - String site, scrobdb, about, sreturn, sleepmode, options, minimise; - String sensetivity, textfolder, vibro, skin, visual, elements, - light, start, stop, flashlight, tooff, - statlocal, scrobbling, uiactivity, listforward; - - public Lang(int id) { - if(id==0) { - menu = "Menu"; - back = "Back"; - exit = "Exit"; - ok = "Ok"; - findtext = "Text Search"; - artist = "Artist - Title"; - textsaving = "Text saved\n"; - nofound = "Not found\n"; - site = "Site"; - scrobdb = "Scrobbling info"; - about = "About"; - sreturn = "Return"; - sleepmode = "Sleep Mode"; - options = "Options"; - minimise = "Minimise"; - sensetivity = "Sensetivity to switch:"; - textfolder = "Folder with the text:"; - vibro = "Vibration switch (in ms):"; - skin = "Skin"; - visual = "Visualization"; - light = "Backlight"; - start = "Launch player when program start"; - stop = "Close player when program exit"; - flashlight = "Flash backlight"; - statlocal = "Statistics (need to restart app)"; - scrobbling = "Scrobbling (annimon.com)"; - elements = "Elements: "; - tooff = "Time to turn off (in minutes):"; - uiactivity = "Sync. with ActivityMenu"; - listforward = "List Forward"; - }else{ - menu = "Меню"; - back = "Назад"; - exit = "Выход"; - ok = "Ok"; - findtext = "Поиск текстов"; - artist = "Исполнитель - Заголовок"; - textsaving = "Текст сохранен\n"; - nofound = "Не найдено\n"; - site = "На сайт"; - scrobdb = "Данные скробблинга"; - about = "О программе"; - sreturn = "Вернуться"; - sleepmode = "Спящий режим"; - options = "Настройки"; - minimise = "Свернуть"; - sensetivity = "Чувствительность к переключению:"; - textfolder = "Папка с текстами:"; - vibro = "Вибрация при переключении (в мс):"; - skin = "Скин"; - visual = "Визуализации"; - light = "Постоянная подсветка"; - start = "Запускать плейер при старте программы"; - stop = "Закрывать плейер при выходе из программы"; - flashlight = "Мигание подсветкой"; - statlocal = "Вести статистику (необходим перезапуск)"; - scrobbling = "Скробблинг"; - elements = "Всего элементов: "; - tooff = "Врямя до выключения (в минутах):"; - uiactivity = "Синхр. с Меню Событий"; - listforward = "Листать вперед"; - } - } - - -} diff --git a/src/Options.java b/src/Options.java deleted file mode 100644 index f901dd9..0000000 --- a/src/Options.java +++ /dev/null @@ -1,102 +0,0 @@ -import java.util.Random; -import javax.microedition.lcdui.*; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class Options extends Form implements CommandListener { - - private Command back,ok; - private TextField zw, az, un; - private ChoiceGroup cRC, lang; - - - public Options() { - super(SEPS.midlet.lang.options); - back = new Command(SEPS.midlet.lang.back, Command.BACK, 3); - ok = new Command(SEPS.midlet.lang.ok, Command.OK, 1); - zw = new TextField(SEPS.midlet.lang.sensetivity, String.valueOf(Rms.sensetivity), 4, TextField.NUMERIC); - az = new TextField(SEPS.midlet.lang.textfolder, Rms.lrcpath, 256, TextField.ANY); - un = new TextField(SEPS.midlet.lang.vibro, String.valueOf(Rms.vibrlen), 4, TextField.NUMERIC); -// cc = new TextField(L.str[L.cch]+":", "000000", 6, TextField.ANY); -// hp = new TextField(L.str[L.ach], String.valueOf(P.heap), 2, TextField.ANY); - lang = new ChoiceGroup ("Language / Язык", ChoiceGroup.EXCLUSIVE); - cRC = new ChoiceGroup ("", ChoiceGroup.MULTIPLE); - appendSkin(); - StrokeStyle(); - } - - public void commandAction(Command c, Displayable d) { - if (c==back) SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - - if ((c==ok || c==List.SELECT_COMMAND)) { - SEPS.midlet.lang = new Lang(Rms.lngid = lang.getSelectedIndex()); - Rms.sensetivity=Integer.parseInt(zw.getString()); - Rms.vibrlen=Integer.parseInt(un.getString()); - Rms.lrcpath=az.getString(); -// P.az=Integer.parseInt(az.getString()); -// P.curcolor = getHexValue(cc.getString()); -// P.heap = Integer.parseInt(hp.getString()); - Rms.light = cRC.isSelected(0); - Rms.startPlayer = cRC.isSelected(1); - Rms.closePlayer = cRC.isSelected(2); - Rms.flash = cRC.isSelected(3); - Rms.statGo = cRC.isSelected(4); if(!Rms.statGo) Rms.stat=Rms.statGo; - Rms.urlstat = cRC.isSelected(5); - Rms.actmenu = cRC.isSelected(6); - Rms.listfw = cRC.isSelected(7); - if(Rms.urlstat && Rms.id==0) { - Random rnd = new Random(); - Rms.id = (rnd.nextInt() >>> 1) % 10000000; - } -// P.undo=Integer.parseInt(un.getString()); -// Editor.isteps = new Image[P.undo]; -// Editor.ist=0; - SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - } - } - - private void StrokeStyle() { - append(lang); - append(zw); - append(az); - append(un); -// append(hp); - append(cRC); - addCommand(ok); - addCommand(back); - setCommandListener(this); - SEPS.midlet.dsp.setCurrent(this); - } - - private void appendSkin() { - lang.append("English", null); - lang.append("Русский", null); - lang.setSelectedIndex(Rms.lngid, true); - - cRC.append(SEPS.midlet.lang.light, null); - cRC.append(SEPS.midlet.lang.start, null); - cRC.append(SEPS.midlet.lang.stop, null); - cRC.append(SEPS.midlet.lang.flashlight, null); - cRC.append(SEPS.midlet.lang.statlocal, null); - cRC.append(SEPS.midlet.lang.scrobbling, null); - cRC.append(SEPS.midlet.lang.uiactivity, null); - cRC.append(SEPS.midlet.lang.listforward, null); -// cRC.append(L.str[120], null); -// cRC.append(L.str[123], null); - cRC.setSelectedIndex(0, Rms.light); - cRC.setSelectedIndex(1, Rms.startPlayer); - cRC.setSelectedIndex(2, Rms.closePlayer); - cRC.setSelectedIndex(3, Rms.flash); - cRC.setSelectedIndex(4, Rms.stat); - cRC.setSelectedIndex(5, Rms.urlstat); - cRC.setSelectedIndex(6, Rms.actmenu); - cRC.setSelectedIndex(7, Rms.listfw); - } -} diff --git a/src/Rate.java b/src/Rate.java deleted file mode 100644 index 71ffbef..0000000 --- a/src/Rate.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class Rate { - - String song; - int rate; -} diff --git a/src/RateImpl.java b/src/RateImpl.java deleted file mode 100644 index d66d9d6..0000000 --- a/src/RateImpl.java +++ /dev/null @@ -1,149 +0,0 @@ -import java.io.*; -import java.util.Vector; -import javax.microedition.io.*; -import javax.microedition.io.file.FileConnection; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class RateImpl { - - public int numRates; //кол-во - public Vector rates; - private String[] path = {"c:/other", "e:/other", "c:/usb/other", "c:/music"}; - - public int update(String song) { - int s = rates.size(); - if(s!=0) - for(int i=0; i 0) - { - try { - Rate r = new Rate(); - r.rate = Integer.parseInt(s2.substring(0, s2.lastIndexOf('|')).trim()); - r.song = s2.substring(s2.lastIndexOf('|') + 1).trim(); - rates.addElement(r); - } catch (Exception ex) { - } - s2 = ""; - } - }else s2 = s2 + String.valueOf((char)i); - } - if(s2.length() > 0) { - try { - Rate r = new Rate(); - r.rate = Integer.parseInt(s2.substring(0, s2.lastIndexOf('|')).trim()); - r.song = s2.substring(s2.lastIndexOf('|') + 1).trim(); - rates.addElement(r); - } catch (Exception exc) { - } - } - } - - public void save() { - FileConnection fc; - int i; - try { - for(i=0; i>> 1) % 10000000; - } - new Skin(Rms.skinid); - cnv = new Canv(im); - dsp = Display.getDisplay(this); - dsp.setCurrent(cnv); - } - - public void pauseApp() { - } - - public void destroyApp(boolean unco) { - if(Rms.firstStart) Rms.firstStart=false; - if(Rms.stat) cnv.ri.save(); - if(Rms.statGo) Rms.stat=true; - Rms.saveOptions(); - if(Rms.closePlayer) cnv.pauseTrack(); - notifyDestroyed(); - } -} diff --git a/src/Skin.java b/src/Skin.java deleted file mode 100644 index 8cfdcab..0000000 --- a/src/Skin.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author aNNiMON - */ -public class Skin { - - public Skin(int skin) { - if(skin==1) skin = Rms.skinid = 0xFF3477d5; - else if(skin==2) skin = Rms.skinid = 0xFF181818; - else if(skin==3) skin = Rms.skinid = 0xFFCE6BA6; - else if(skin==4) skin = Rms.skinid = 0; - else if(skin==5) skin = Rms.skinid = 0xFFFFFF99; - Canv.background = 0xFF2F8400; - Canv.valuet = 0xFFFFFFFF; - if(skin!=0) { - Canv.softUp1 = Effects.changeHSV(Canv.background, 2, 0.4352941f); - Canv.softUp2 = Effects.changeHSV(Canv.background, 2, 0.19215685f); - Canv.softDn1 = Effects.changeHSV(Canv.background, 2, -0.007843137f); - Canv.softDn2 = Effects.changeHSV(Canv.background, 2, -0.16862747f); - Canv.line = Effects.changeHSV(Canv.background, 0, 22); - Canv.line = Effects.changeHSV(Canv.line, 2, 0.21568626f); - Canv.text = Effects.changeHSV(Canv.background, 0, 22); - Canv.text = Effects.changeHSV(Canv.text, 2, 0.082352936f); - Canv.inf = Effects.changeHSV(Canv.background, 2, -0.16078433f); - for(int i=0; i<=2; i++) { - float delta = Effects.getHSV(skin, i) - Effects.getHSV(Canv.background, i); - if(delta>-0.05 && delta<0.05) continue; - Canv.softUp1 = Effects.changeHSV(Canv.softUp1, i, delta); - Canv.softUp2 = Effects.changeHSV(Canv.softUp2, i, delta); - Canv.softDn1 = Effects.changeHSV(Canv.softDn1, i, delta); - Canv.softDn2 = Effects.changeHSV(Canv.softDn2, i, delta); - Canv.line = Effects.changeHSV(Canv.line, i, delta); - Canv.text = Effects.changeHSV(Canv.text, i, delta); - Canv.inf = Effects.changeHSV(Canv.inf, i, delta); - } - Canv.background = skin; - }else{ - Canv.softUp1 = 0xFF57f300; - Canv.softUp2 = 0xFF41b500; - Canv.softDn1 = 0xFF2e8200; - Canv.softDn2 = 0xFF205900; - Canv.line = 0x00BB00; - Canv.text = 0x009900; - Canv.inf = 0x215B00; - } - - } -} diff --git a/src/accel/AccelData.java b/src/accel/AccelData.java new file mode 100644 index 0000000..641a09e --- /dev/null +++ b/src/accel/AccelData.java @@ -0,0 +1,126 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ +package accel; + +import java.io.IOException; +import javax.microedition.io.Connector; +import javax.microedition.sensor.ChannelInfo; +import javax.microedition.sensor.Data; +import javax.microedition.sensor.MeasurementRange; +import javax.microedition.sensor.SensorConnection; +import javax.microedition.sensor.SensorInfo; +import javax.microedition.sensor.SensorManager; + +/** + * Подключение сенсора. Измерение отклонения. + * @author aNNiMON + */ +public class AccelData implements SensorData { + + private int[] channels; + private String[] channelNames; + private SensorConnection sensor; + private String URL; //URL для коннекта + private int numChannels; //количество каналов + private int dataType; //тип приёма данных + private double + minValue, //минимальное значение + maxValue; //максимальное значение + + /** + * Конструктор + */ + public AccelData() { + getInfo(); + } + + public int getDelta(int channel, int sensetivity) { + int delta = 0; + try { + Data[] data = sensor.getData(1, -1, false, false, false); + int drx = 0; + + for (int i = 0; i < data.length; i++) { + if (data[i].getChannelInfo().getName().equals(channelNames[channel])) { + drx = getValue(data[i]); + } + } + + delta = channels[channel] - drx; + channels[channel] = drx; + + if (Math.abs(delta) < sensetivity) { + delta = 0; + } + } catch (Throwable t) { + } + + return delta; + } + + /** + * Подключение к акселерометру + */ + private void getInfo() { + //Получаем список ВСЕХ сенсоров + SensorInfo[] info = SensorManager.findSensors(null, null); + if (info == null || info.length == 0) { + return; //ничего не нашли, выходим + } //Сканируем найденные сенсоры + for (int i = 0; i < info.length; i++) { + //Узнаём тип устройства + String quantity = info[i].getQuantity().toLowerCase(); + //Нам нужен acceleration + if (quantity.startsWith("accel")) { + //Нашли девайс + SensorInfo s = info[i]; + //Получаем URL для коннекта с ним + URL = s.getUrl(); + //Получаем каналы приёма данных + ChannelInfo[] ci = s.getChannelInfos(); + //Получаем количество каналов + numChannels = ci.length; + //Инициализируем переменные + channels = new int[numChannels]; + channelNames = new String[numChannels]; + //Получаем тип приёма данных (TYPE_DOUBLE = 1, TYPE_INT = 2, TYPE_OBJECT = 4) + dataType = ci[0].getDataType(); + MeasurementRange mr = ci[0].getMeasurementRanges()[0]; + //Получаем минимальное значение + minValue = mr.getSmallestValue(); + //Получаем максимальное значение + maxValue = mr.getLargestValue(); + //Получаем названия каналов (axis_x, axis_y, axis_z) + for (int j = 0; j < numChannels; j++) { + channelNames[j] = ci[j].getName(); + } + } + } + //Для того, чтобы подключить DataListener, нужно соединение + try { + //Открываем соединение, по раннее полученному URL + sensor = (SensorConnection) Connector.open(URL); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + /** + * Преобразование в int [-1024...+1024] + */ + private int getValue(Object o) { + int value = 0; + double doublevalue = 0; + if(dataType == ChannelInfo.TYPE_INT) { + doublevalue = ((Data) o).getIntValues()[0]; + }else if(dataType == ChannelInfo.TYPE_DOUBLE) { + doublevalue = ((Data) o).getDoubleValues()[0]; + } + if(doublevalue>=0) value = (int) (doublevalue * 1024 / maxValue); + else value = (int) (doublevalue * (-1024) / minValue); + + return value; + } +} diff --git a/src/accel/NoData.java b/src/accel/NoData.java new file mode 100644 index 0000000..0e8bcc2 --- /dev/null +++ b/src/accel/NoData.java @@ -0,0 +1,24 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package accel; + +/** + * Не подключен к сенсору - нет данных. + * @author aNNiMON + */ +public class NoData implements SensorData { + + /** + * Получение отклонения + * @param channel - канал X, Y, Z + * @param sensetivity - чувствительность + * @return int нулевое отклонение + */ + public int getDelta(int channel, int sensetivity) { + return 0; + } + +} diff --git a/src/accel/SensorData.java b/src/accel/SensorData.java new file mode 100644 index 0000000..ea45236 --- /dev/null +++ b/src/accel/SensorData.java @@ -0,0 +1,22 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package accel; + +/** + * Интерфейс получения данных от сенсоров. + * @author aNNiMON + */ +public interface SensorData { + + /** + * Получение отклонения + * @param channel - канал X, Y, Z + * @param sensetivity - чувствительность + * @return int отклонение + */ + public abstract int getDelta(int channel, int sensetivity); + +} diff --git a/src/com/annimon/GraphicsUtil.java b/src/com/annimon/GraphicsUtil.java new file mode 100644 index 0000000..70925b8 --- /dev/null +++ b/src/com/annimon/GraphicsUtil.java @@ -0,0 +1,201 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package com.annimon; + +import javax.microedition.lcdui.Font; +import javax.microedition.lcdui.Graphics; +import seps.Images; +import seps.Skin; + +/** + * Класс графических функций + * @author aNNiMON + */ +public class GraphicsUtil { + + //Поля константы + private static final Font smallPlainFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); + private static final Font smallBoldFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL); + private static final Font mediumBoldFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM); + + public static final byte + SMALL_PLAIN_FONT = 0, + SMALL_BOLD_FONT = 1, + MEDIUM_BOLD_FONT = 2; + + private static final int IMAGE_TRACK_WIDTH = 19; + + + /** + * Очистка экрана чёрным + * @param g Graphics + */ + public static void CLS(Graphics g) { + g.setColor(0); + g.fillRect(0, 0, g.getClipWidth(), g.getClipHeight()); + } + + /** + * Плавная очистка экрана + * @param g Graphics + * @param opacity int прозрачность + */ + public static void ACLS(Graphics g, int opacity) { + ACLS(g, opacity, 0); + } + + /** + * Плавная очистка экрана выбранным цветом + * @param g Graphics + * @param alpha int прозрачность + * @param color int цвет + */ + public static void ACLS(Graphics g, int alpha, int color) { + int w = g.getClipWidth(); + int h = g.getClipHeight(); + int[] pixelArray = new int[w * h]; + for(int i = 0; i < pixelArray.length; i++) + pixelArray[i] = (alpha << 24) | (color & 0x00ffffff); + g.drawRGB(pixelArray, 0, w, 0, 0, w, h, true); + } + + /** + * Отрисовка градиента + * @param g Graphics + * @param color1 первый цвет градиента + * @param color2 второй цвет градиента + * @param x1 начальная координата x + * @param y1 начальная координата y + * @param w ширина + * @param h высота + */ + public static void drawRect(Graphics g, int color1, int color2, int x1, int y1, int w, int h) { + int a1 = (color1 >> 24) & 0xff; + int r1 = (color1 >> 16) & 0xff; + int g1 = (color1 >> 8) & 0xff; + int b1 = color1 & 0xff; + int a2 = (color2 >> 24) & 0xff; + int r2 = (color2 >> 16) & 0xff; + int g2 = (color2 >> 8) & 0xff; + int b2 = color2 & 0xff; + int beforecolor = g.getColor(); + int crd1, crd2; + int count = h/3; + if (count < 0) count = -count; + if (count < 8) count = 8; + boolean lite = false; + if(a1==0xff && a2==0xff) lite = true; + for (int i=count-1; i>=0; i--) { + crd1 = i*h/count+y1; + crd2 = (i+1)*h/count+y1; + if (crd1 == crd2) continue; + if(lite) { + g.setColor(i * (r2 - r1) / (count - 1) + r1, i * (g2 - g1) / (count - 1) + g1, i * (b2 - b1) / (count - 1) + b1); + g.fillRect(x1, crd1, w, crd2 - crd1); + }else{ + int[] pixelArray = new int[w * (crd2 - crd1)]; + for(int zi = 0; zi < pixelArray.length; zi++) + pixelArray[zi] = (int) ((i * (a2 - a1) / (count - 1) + a1) << 24) | + ((i * (r2 - r1) / (count - 1) + r1) << 16) | + ((i * (g2 - g1) / (count - 1) + g1) << 8) | (i * (b2 - b1) / (count - 1) + b1); + g.drawRGB(pixelArray, 0, w, x1, crd1, w, crd2 - crd1, true); + } + } + g.setColor(beforecolor); + } + + /** + * Отрисовка текстов песен по центру + * @param g Graphics + * @param lines String[] строки текста + */ + public static void drawCenter(Graphics g, String[] lines) { + if(lines==null) return; + int fh = smallPlainFont.getHeight()+2; + int w = g.getClipWidth(); + int h = g.getClipHeight(); + g.setFont(smallPlainFont); + String v; + drawRect(g, ((160<<24)| Skin.background & 0x00ffffff),((160<<24)| Skin.background & 0x00ffffff), 0, h/2-fh*2, w, fh*5); + for(int i=0; i 0 && ch < 128) - return (byte) ch; - else if (ch == 0x401) - return -88; // Ё - else if (ch == 0x404) - return -86; // Є - else if (ch == 0x407) - return -81; // Ї - else if (ch == 0x451) - return -72; // ё - else if (ch == 0x454) - return -70; // є - else if (ch == 0x457) - return -65; // ї - return (byte)((byte)(ch) + 176); - } public static char checkCP1251 (char ch) { diff --git a/src/com/annimon/Util.java b/src/com/annimon/Util.java new file mode 100644 index 0000000..0520131 --- /dev/null +++ b/src/com/annimon/Util.java @@ -0,0 +1,63 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ +package com.annimon; + +import java.util.Calendar; +import java.util.Random; +import java.util.Vector; +import seps.Rms; + +/** + * + * @author aNNiMON + */ +public class Util { + + private static final Random rnd = new Random(); + + public static boolean checkTime() { + Calendar cal = Calendar.getInstance(); + int ch = cal.get(Calendar.HOUR_OF_DAY); + int cm = cal.get(Calendar.MINUTE); + if(ch!=Rms.dh) return false; + else return (cm>=Rms.dm); + } + + public static String getTime() { + StringBuffer sb = new StringBuffer(); + Calendar cal = Calendar.getInstance(); + int tmp; + tmp = cal.get(Calendar.HOUR_OF_DAY); + if(tmp<=9) sb.append('0'); sb.append(tmp); + sb.append(':'); + //Минута + tmp = cal.get(Calendar.MINUTE); + if(tmp<=9) sb.append('0'); sb.append(tmp); + return sb.toString(); + } + + public static int random(int min, int max) { + return min + rnd.nextInt(max+1-min); + } + + public static String[] splitString(String str, String delim) { + if (str.equals("") || delim == null || delim.length() == 0) return new String[]{str}; + String[] s; + Vector v = new Vector(); + int pos = 0; + int newpos = str.indexOf(delim, 0); + + while (newpos != -1) { + v.addElement(str.substring(pos, newpos)); + pos = newpos + delim.length(); + newpos = str.indexOf(delim, pos); + } + v.addElement(str.substring(pos)); + + s = new String[v.size()]; + v.copyInto(s); + return s; + } +} diff --git a/src/fx/AnimatedImage.java b/src/fx/AnimatedImage.java new file mode 100644 index 0000000..fb12d67 --- /dev/null +++ b/src/fx/AnimatedImage.java @@ -0,0 +1,51 @@ +package fx; + +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public class AnimatedImage { + + ImageFx fx; + Image image; + int imageWidth; + int imageHeight; + + public AnimatedImage(Image image) { + fx = null; + this.image = null; + imageWidth = 0; + imageHeight = 0; + this.image = image; + imageWidth = image.getWidth(); + imageHeight = image.getHeight(); + } + + public void setFx(ImageFx fx) { + this.fx = fx; + } + + public void start(long duration) { + fx.start(duration); + } + + public boolean isEnded() { + return fx.isEnded(); + } + + public void paint(Graphics g, int x, int y, int constraints) { + if (fx == null) { + g.drawImage(image, x, y, constraints); + } else { + int cx = g.getClipX(); + int cy = g.getClipY(); + int cw = g.getClipWidth(); + int ch = g.getClipHeight(); + int translateX = (constraints & 8) <= 0 ? (constraints & 1) <= 0 ? x : x - imageWidth / 2 : x - imageWidth; + int translateY = (constraints & 0x20) <= 0 ? (constraints & 2) <= 0 ? y : y - imageHeight / 2 : y - imageHeight; + g.translate(translateX, translateY); + fx.paint(g, image); + g.translate(-translateX, -translateY); + g.setClip(cx, cy, cw, ch); + } + } +} \ No newline at end of file diff --git a/src/fx/BlindsFx.java b/src/fx/BlindsFx.java new file mode 100644 index 0000000..b74b647 --- /dev/null +++ b/src/fx/BlindsFx.java @@ -0,0 +1,36 @@ +package fx; + +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public class BlindsFx extends ImageFx { + + int blinds; + + public BlindsFx(int blinds, int type, int orientation) { + this.blinds = blinds; + setOrientation(orientation); + setFxType(type); + assertNotOrientation(0); + assertNotFxType(0); + } + + protected void paintFx(Graphics g, Image image, long timeDiff) { + int perc = getPercentage(timeDiff); + int orientation = getOrientation(); + int imageSize = orientation != 2 ? image.getWidth() : image.getHeight(); + int pieceSize = imageSize / blinds; + int delta = imageSize - pieceSize * blinds; + int coord = 0; + for (int i = 0; i < blinds; i++) { + int size = ((pieceSize + (i >= delta ? 0 : 1)) * (100 - perc)) / 100; + if (orientation == 2) { + g.setClip(0, coord, image.getWidth(), size); + } else { + g.setClip(coord, 0, size, image.getHeight()); + } + g.drawImage(image, 0, 0, 20); + coord += pieceSize + (i >= delta ? 0 : 1); + } + } +} diff --git a/src/fx/ImageFx.java b/src/fx/ImageFx.java new file mode 100644 index 0000000..285021a --- /dev/null +++ b/src/fx/ImageFx.java @@ -0,0 +1,119 @@ +package fx; + +//~--- JDK imports ------------------------------------------------------------ +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public abstract class ImageFx { + + public static final int ORIENTATION_NONE = 0; + public static final int ORIENTATION_VERTICAL = 1; + public static final int ORIENTATION_HORIZONTAL = 2; + public static final int TYPE_NONE = 0; + public static final int TYPE_IN = 1; + public static final int TYPE_OUT = 2; + private int direction; + private long duration; + private boolean ended; + private int fxType; + private boolean looping; + private int orientation; + private boolean running; + private long startTime; + + public ImageFx() { + fxType = TYPE_NONE; + orientation = ORIENTATION_NONE; + direction = 2; + looping = false; + running = false; + ended = false; + duration = 0L; + startTime = 0L; + } + + public void start(long millisecs) { + duration = millisecs; + startTime = System.currentTimeMillis(); + ended = false; + running = true; + } + + public void setOrientation(int orientation) { + if ((orientation == ORIENTATION_HORIZONTAL) || (orientation == ORIENTATION_VERTICAL) + || (orientation == ORIENTATION_NONE)) { + this.orientation = orientation; + } + } + + public void setFxType(int fxType) { + if ((fxType == TYPE_IN) || (fxType == TYPE_OUT) || (fxType == TYPE_NONE)) { + this.fxType = fxType; + } + } + + public void setDirection(int direction) { + if ((direction == 1) || (direction == 5) || (direction == 6) || (direction == 2)) { + this.direction = direction; + } + } + + protected void assertNotFxType(int value) { + if (fxType != value) { + return; + } + } + + protected void assertNotOrientation(int value) { + if (orientation != value) { + return; + } + } + + public int getOrientation() { + return orientation; + } + + public int getDirection() { + return direction; + } + + public void paint(Graphics g, Image image) { + if (!running) { + + // if(mustNotPaint()) + // return; + // if(mustFullyPaint()) + g.drawImage(image, 0, 0, 20); + } else { + long timeDiff = System.currentTimeMillis() - startTime; + + if (timeDiff > duration) { + if (looping) { + timeDiff -= duration; + startTime += duration; + } else { + timeDiff = duration; + ended = true; + running = false; + } + } + + if (fxType == TYPE_IN) { + timeDiff = duration - timeDiff; + } + + paintFx(g, image, timeDiff); + } + } + + protected int getPercentage(long timeDiff) { + return (int) ((100L * timeDiff) / duration); + } + + public boolean isEnded() { + return ended; + } + + protected abstract void paintFx(Graphics g, Image image, long l); +} diff --git a/src/fx/PuzzleFx.java b/src/fx/PuzzleFx.java new file mode 100644 index 0000000..e58de69 --- /dev/null +++ b/src/fx/PuzzleFx.java @@ -0,0 +1,71 @@ +package fx; + +import java.util.Random; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public class PuzzleFx extends ImageFx { + + int vPieces; + int hPieces; + int[] pieceOrder; + long pieceDelay; + long pieceDuration; + + public PuzzleFx(int hPieces, int vPieces, int type) { + this.vPieces = 4; + this.hPieces = 8; + pieceOrder = null; + pieceDelay = 0L; + pieceDuration = 0L; + int normalizedType = type != 1 ? type != 2 ? type : 1 : 2; + setFxType(normalizedType); + assertNotFxType(0); + this.hPieces = hPieces; + this.vPieces = vPieces; + Random rand = new Random(); + pieceOrder = new int[hPieces * vPieces]; + for (int i = 0; i < pieceOrder.length; i++) { + pieceOrder[i] = -1; + } + + for (int i = 0; i < pieceOrder.length; i++) { + int next; + for (next = rand.nextInt(pieceOrder.length); pieceOrder[next] != -1; next = (next + 1) % pieceOrder.length); + pieceOrder[next] = i; + } + + } + + public void start(long millisecs) { + super.start(millisecs); + pieceDuration = millisecs / 8L; + pieceDelay = (millisecs - pieceDuration) / (long) (hPieces * vPieces); + } + + protected void paintFx(Graphics g, Image image, long timeDiff) { + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + int pieceWidth = imageWidth / hPieces; + int pieceHeight = imageHeight / vPieces; + for (int i = 0; i < hPieces; i++) { + for (int j = 0; j < vPieces; j++) { + int index = i * vPieces + j; + int w = pieceWidth; + int h = pieceHeight; + long delta = timeDiff - (long) pieceOrder[index] * pieceDelay; + if (delta >= 0L) { + if (delta - pieceDuration < 0L) { + int perc = (int) ((delta * 100L) / pieceDuration); + w = (pieceWidth * perc) / 100; + h = (pieceHeight * perc) / 100; + } + g.setClip(i * pieceWidth + (pieceWidth - w) / 2, j * pieceHeight + (pieceHeight - h) / 2, w, h); + g.drawImage(image, 0, 0, 20); + } + } + + } + + } +} diff --git a/src/fx/Slide2Fx.java b/src/fx/Slide2Fx.java new file mode 100644 index 0000000..a5eca65 --- /dev/null +++ b/src/fx/Slide2Fx.java @@ -0,0 +1,43 @@ +package fx; + +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public class Slide2Fx extends ImageFx { + + public Slide2Fx(int direction, int fxType) { + setDirection(direction); + setFxType(fxType); + assertNotFxType(0); + } + + protected void paintFx(Graphics g, Image image, long timeDiff) { + int perc = getPercentage(timeDiff); + int x = 0; + int y = 0; + int w = image.getWidth(); + int h = image.getHeight(); + switch (getDirection()) { + case 1: // '\001' + h = (h * (100 - perc)) / 100; + y = image.getHeight() - h; + break; + + case 6: // '\006' + h = (h * (100 - perc)) / 100; + y = h - image.getHeight(); + break; + + case 5: // '\005' + w = (w * (100 - perc)) / 100; + x = image.getWidth() - w; + break; + + case 2: // '\002' + w = (w * (100 - perc)) / 100; + x = w - image.getWidth(); + break; + } + g.drawImage(image, x, y, 20); + } +} diff --git a/src/fx/SlideFx.java b/src/fx/SlideFx.java new file mode 100644 index 0000000..db4888f --- /dev/null +++ b/src/fx/SlideFx.java @@ -0,0 +1,67 @@ +package fx; + +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public class SlideFx extends ImageFx { + + int pieces; + long singleSlideDuration; + + public SlideFx(int pieces, int slideType, int direction) { + this.pieces = 4; + singleSlideDuration = 0L; + setDirection(direction); + setFxType(slideType); + assertNotFxType(0); + this.pieces = pieces; + } + + public void start(long millisecs) { + super.start(millisecs); + singleSlideDuration = millisecs / (long) pieces; + } + + protected void paintFx(Graphics g, Image image, long timeDiff) { + int cx = g.getClipX(); + int cy = g.getClipY(); + int cw = g.getClipWidth(); + int ch = g.getClipHeight(); + int imageHeight = image.getHeight(); + int imageWidth = image.getWidth(); + int direction = getDirection(); + int pieceEnd = 0; + int pieceCoord = 0; + int pieceSize = direction != 2 && direction != 5 ? imageWidth / pieces : imageHeight / pieces; + switch (direction) { + case 2: // '\002' + pieceEnd = cx - imageWidth; + break; + + case 5: // '\005' + pieceEnd = cx + cw; + break; + + case 1: // '\001' + pieceEnd = cy - imageHeight; + break; + + case 6: // '\006' + pieceEnd = cy + ch; + break; + } + for (int i = 0; i < pieces; i++) { + if (timeDiff <= (long) (i + 1) * singleSlideDuration) { + pieceCoord = (int) (timeDiff >= (long) i * singleSlideDuration ? ((long) pieceEnd * (timeDiff - (long) i * singleSlideDuration)) / singleSlideDuration : 0L); + if (direction == 2 || direction == 5) { + g.setClip(pieceCoord, i * pieceSize, imageWidth, pieceSize); + g.drawImage(image, pieceCoord, 0, 20); + } else { + g.setClip(i * pieceSize, pieceCoord, pieceSize, imageHeight); + g.drawImage(image, 0, pieceCoord, 20); + } + } + } + + } +} diff --git a/src/fx/WaveFx.java b/src/fx/WaveFx.java new file mode 100644 index 0000000..cb2da8c --- /dev/null +++ b/src/fx/WaveFx.java @@ -0,0 +1,60 @@ +package fx; + +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public class WaveFx extends ImageFx +{ + int pieces; + int maxShift; + long pieceDuration; + long pieceDelay; + + public WaveFx(int pieces, int maxShift, int orientation) + { + this.pieces = 0; + this.maxShift = 0; + pieceDuration = 0L; + pieceDelay = 0L; + setOrientation(orientation); + this.pieces = pieces; + this.maxShift = maxShift; + } + + public void start(long millisecs) + { + super.start(millisecs); + pieceDuration = millisecs / 2L; + pieceDelay = (millisecs - pieceDuration) / (long)pieces; + } + + protected void paintFx(Graphics g, Image image, long timeDiff) + { + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + int pieceSize = (getOrientation() != 2 ? image.getWidth() : image.getHeight()) / pieces; + int shift = 0; + for(int i = 0; i < pieces; i++) + { + long delta = (long)i * pieceDelay - timeDiff; + if(delta > 0L || delta + pieceDuration <= 0L) + { + shift = 0; + } else + { + long perc = (delta * 100L) / pieceDuration; + shift = (int)((double)maxShift * Math.sin(((double)(perc * 2L) * 3.1415926535897931D) / 100D)); + } + if(getOrientation() == 2) + { + g.setClip(0 + shift, i * pieceSize, imageWidth, pieceSize); + g.drawImage(image, 0 + shift, 0, 20); + } else + { + g.setClip(i * pieceSize, 0 + shift, pieceSize, imageHeight); + g.drawImage(image, 0, 0 + shift, 20); + } + } + + } +} diff --git a/src/fx/WipeFx.java b/src/fx/WipeFx.java new file mode 100644 index 0000000..8470f3d --- /dev/null +++ b/src/fx/WipeFx.java @@ -0,0 +1,46 @@ +package fx; + +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +public class WipeFx extends ImageFx +{ + + public WipeFx(int direction, int fxType) + { + setDirection(direction); + setFxType(fxType); + assertNotFxType(0); + } + + protected void paintFx(Graphics g, Image image, long timeDiff) + { + int perc = getPercentage(timeDiff); + int x = 0; + int y = 0; + int w = image.getWidth(); + int h = image.getHeight(); + switch(getDirection()) + { + case 1: // '\001' + h = (h * (100 - perc)) / 100; + y = image.getHeight() - h; + break; + + case 6: // '\006' + h = (h * (100 - perc)) / 100; + break; + + case 5: // '\005' + w = (w * (100 - perc)) / 100; + x = image.getWidth() - w; + break; + + case 2: // '\002' + w = (w * (100 - perc)) / 100; + break; + } + g.setClip(x, y, w, h); + g.drawImage(image, 0, 0, 20); + } +} diff --git a/src/icon.png b/src/icon.png deleted file mode 100644 index b0e1f4c..0000000 Binary files a/src/icon.png and /dev/null differ diff --git a/src/lastfm/HTTPUtil.java b/src/lastfm/HTTPUtil.java new file mode 100644 index 0000000..bc9eef2 --- /dev/null +++ b/src/lastfm/HTTPUtil.java @@ -0,0 +1,264 @@ +/** + * HTTPUtil.java + * + * This program is distributed under the terms of the GNU General Public + * License + * Copyright 2008 NJ Pearman + * + * This file is part of MobScrob. + * + * MobScrob is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MobScrob is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MobScrob. If not, see . + */ +package lastfm; + +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.Vector; + +import javax.microedition.io.Connector; +import javax.microedition.io.HttpConnection; + +/** + * @author Neill + * + */ +public class HTTPUtil { + + private static final String ENC_UTF8 = "UTF-8"; + + /** + * Returns a Vector of Strings representing the lines present in the byte + * array, separated by '\n' return feed. + * + * @param bytes + * @return + */ + public static Vector readLines(byte[] bytes) { + Vector lines = new Vector(); + if (bytes == null || bytes.length == 0) { + return lines; + } + StringBuffer line = new StringBuffer(); + for (int i = 0; i < bytes.length; i++) { + if (bytes[i] == '\n') { + lines.addElement(line.toString()); + line = new StringBuffer(); + } else { + // add to current line + line.append((char) bytes[i]); + } + } + + return lines; + } + + /** + * Encodes a parameter, also ensuring that it is UTF-8 + * + * @param s + * @return + * @throws UnsupportedEncodingException + */ + public static String encodeParam(String s) { + if (s == null) return null; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + switch (ch) { + default: + if (ch < '\200') { + sb.append(ch); + break; + } + if (ch > '\177' && ch < '\u0800') { + sb.append('%'); + sb.append(Integer.toHexString((ch >> 6 | 0xc0) + 256).substring(1)); + sb.append('%'); + sb.append(Integer.toHexString((ch & 0x3f | 0x80) + 256).substring(1)); + break; + } + if (ch > '\u07FF' && ch < '\0') { + sb.append('%'); + sb.append(Integer.toHexString((ch >> 12 | 0xe0) + 256).substring(1)); + sb.append('%'); + sb.append(Integer.toHexString((ch >> 6 & 0x3f | 0x80) + 256).substring(1)); + sb.append('%'); + sb.append(Integer.toHexString((ch & 0x3f | 0x80) + 256).substring(1)); + } + break; + case 0: //'\0' + case 32: sb.append("%20"); break;// ' ' + case 61: sb.append("%3d"); break;// '=' + case 43: sb.append("%2b"); break;// '+' + case 39: sb.append("%27"); break;// '\'' + case 46: sb.append("%2E"); break;// '.' + case 60: sb.append("%3c"); break;// '<' + case 62: sb.append("%3e"); break;// '>' + case 35: sb.append("%23"); break;// '#' + case 37: sb.append("%25"); break;// '%' + case 38: sb.append("%26"); break;// '&' + case 123:sb.append("%7b"); break;// '{' + case 125:sb.append("%7d"); break;// '}' + case 92: sb.append("%5c"); break;// '\\' + case 94: sb.append("%5e"); break;// '^' + case 126:sb.append("%73"); break;// '~' + case 91: sb.append("%5b"); break;// '[' + case 93: sb.append("%5d"); break;// ']' + case 58: sb.append("%3A"); break;// ':' + case 47: sb.append("%2F"); break;// '/' + case 63: sb.append("%3F"); break;// '?' + case 45: sb.append("%2D"); break;// '-' + case 33: sb.append("%21"); break;// '!' + case 59: sb.append("%3B"); break;// ';' + } + } + return sb.toString(); + /*if (s == null) { + return s; + } + + // encode as UTF-8 + String utf8Str; + try { + utf8Str = new String(s.getBytes(), ENC_UTF8); + } catch (UnsupportedEncodingException ex) { + utf8Str = s; + } + + StringBuffer sb = new StringBuffer(utf8Str.length() * 3); + char[] chars = utf8Str.toCharArray(); + int next; + + // encode the chars in the UTF-8 String + for (int i = 0; i < chars.length; i++) { + next = chars[i]; + + if ((next >= 0x30 && next <= 0x39) || // 0-9 + (next >= 0x41 && next <= 0x5A) || // A-Z + (next >= 0x61 && next <= 0x7A)) { // a-z + sb.append((char) next); + } else if ((next == 0xA0)) { // ' ' (whitespace) + sb.append('+'); + } else { // encode all other chars + sb.append("%"); + if (next <= 0xf) { + sb.append("0"); + } + sb.append(Integer.toHexString(next)); + } + } + return sb.toString();*/ + } + + /** + * Attempts to open a URL using the GET method over HTTP and read the + * response into a byte array. Any IOExceptions are simply thrown out of + * this method to be caught elsewhere. + * + * @param url + * @return + * @throws IOException + */ + public static byte[] getUrl(String url, String headerHostname) throws IOException { + HttpConnection conn = null; + try { + conn = (HttpConnection) Connector.open(url); + + // set the compulsory HTTP/1.1 Host: header, as GET + conn.setRequestMethod(HttpConnection.GET); + //if(!headerHostname.equals("")) + conn.setRequestProperty("Host", headerHostname); + + byte[] body = readHttpResponse(conn); + return body; + } finally { + closeHttpConnection(conn); + } + } + + /** + * Reads the response from the specified HTTP connection into a byte array. + * + * @param conn + * @return + * @throws IOException + */ + public static byte[] readHttpResponse(HttpConnection conn) throws IOException { + int rc = conn.getResponseCode(); + if (rc != HttpConnection.HTTP_OK) { + String msg = "HTTP response code not OK: " + rc; + throw new IOException(msg); + } + + // connect + int len = (int) conn.getLength(); + + InputStream is = null; + + try { + is = conn.openInputStream(); + + // read response + if (len > -1) { + byte[] body = new byte[len]; + int actual = 0; + int bytesread = 0; + + while ((bytesread != len) && (actual != -1)) { + actual = is.read(body, bytesread, len - bytesread); + bytesread += actual; + } + // do something + return body; + } else { + // read byte by byte...? + + Vector bytes = new Vector(); + Byte byteObj; + int next; + while ((next = is.read()) > -1) { + byteObj = new Byte((byte) next); + bytes.addElement(byteObj); + } + + byte[] body = new byte[bytes.size()]; + Enumeration e = bytes.elements(); + int i = 0; + while (e.hasMoreElements()) { + byteObj = (Byte) e.nextElement(); + body[i++] = byteObj.byteValue(); + } + + return body; + } + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception e) { + } + } + } + } + + public static void closeHttpConnection(HttpConnection conn) { + if (conn != null) { + try { + conn.close(); + } catch (Exception e) {} + } + } +} diff --git a/src/lastfm/LastFMScrobbler.java b/src/lastfm/LastFMScrobbler.java new file mode 100644 index 0000000..d157842 --- /dev/null +++ b/src/lastfm/LastFMScrobbler.java @@ -0,0 +1,345 @@ +/** + * LastFMScrobbler.java + * + * This program is distributed under the terms of the GNU General Public + * License + * Copyright 2008 NJ Pearman + * + * This file is part of MobScrob. + * + * MobScrob is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MobScrob is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MobScrob. If not, see . + */ +package lastfm; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Vector; + +import javax.microedition.io.Connector; +import javax.microedition.io.HttpConnection; +import msapi.Track; + +/** + * Скробблинг LastFM + * @author Neill. Modding by aNNiMON + */ +public class LastFMScrobbler { + + /** Имя пользователя */ + private String login; + /** Кодированный пароль MD5 */ + private String passwordMD5; + /** ID клиента (tst) */ + private String clientId; + /** версия клиента (1.0) */ + private String clientVersion; + + /** Класс сессии*/ + private Session session; + /** Число ошибок*/ + private int failureCount; + /** Состояния (работа, завершение) */ + private boolean processing, shutdown; + + /** + * Конфигурация клиента отправителя + * @param clientId ID клиента (tst) + * @param clientVersion версия клиента (1.0) + * @param login имя пользователя + * @param passwordMD5 кодированный пароль MD5 + */ + public LastFMScrobbler(String clientId, String clientVersion, String login, String passwordMD5) { + this.clientId = clientId; + this.clientVersion = clientVersion; + this.login = login.toLowerCase(); + this.passwordMD5 = passwordMD5; + this.failureCount = 0; + } + + /** + * Кодирование строки в MD5-хэш + * @param string строка + * @return String хэшированная строка + */ + public static String md5(String string) { + return MD5.getHashString(string); + } + + /** + * "Рукопожатие". Используется для получение сессии. + * Используется протокол 1.2.1 + * @return true процесс завершен успешно + * @throws IOException + */ + public boolean handshake() throws Exception { + //Штамп времени + long timestamp = System.currentTimeMillis() / 1000; + //создаём ссылку handshake + StringBuffer urlSB = new StringBuffer(); + + urlSB.append("http://post.audioscrobbler.com/?hs=true&p=1.2.1&c=").append(clientId) + .append("&v=").append(clientVersion).append("&u=").append(login) + .append("&t=").append(timestamp).append("&a=").append( md5(passwordMD5 + timestamp) ); + String url = urlSB.toString(); + + //подключаемся по URL и получаем ответ + byte[] answer = HTTPUtil.getUrl(url, "post.audioscrobbler.com"); + //Считываем строки + Vector lines = HTTPUtil.readLines(answer); + //Первая строка - состояние (OK, BANNED, BADAUTH, BADTIME, FAILED) + String ok = (String) lines.elementAt(0); + if(ok.equals("OK")) { + //Получаем остальные строки + //ID сессии 17E61... + String sessionID = (String) lines.elementAt(1); + //Ссылка для nowPlaying http://post.audioscrobbler.com:80/np_1.2 + String nowPlayingUrl = (String) lines.elementAt(2); + //Ссылка для скробблинга трека http://post2.audioscrobbler.com:80/protocol_1.2 + String submitUrl = (String) lines.elementAt(3); + //Инициализируем сессию + session = new Session(sessionID, nowPlayingUrl, submitUrl); + }else throw new Exception(ok); + return true; + } + + /** + * Выполнить скробблинг + * @param track трек для скробблинга + * @param startTime время начала воспроизведения + */ + public void scrobble(Track track, long startTime) throws Exception { + HttpConnection http = null; + OutputStream os = null; + + try { + if (!validSession()) throw new Exception("Невозможно выполнить handshake"); + + processing = true; + //Получение данных трека для скробблинга + byte[] param = createSubmissionParams(track, startTime); + + //Получение ссылки для выполнения скробблинга + String submitUrl = session.submitUrl; + //Вырезка из ссылки хоста (без порта и http://) + String host = submitUrl.substring(7, submitUrl.lastIndexOf(':')); + //Подключение + http = (HttpConnection) Connector.open(session.submitUrl); + //Конфигурация подключения + http.setRequestMethod(HttpConnection.POST); + http.setRequestProperty("Host", host); + //http.setRequestProperty("User-Agent", "SEPlayerService"); + http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + http.setRequestProperty("Content-Length", String.valueOf(param.length)); + http.setRequestProperty("Accept", "*/*"); + http.setRequestProperty("Accept-Language", "en"); + + //Открытие потока для записи + os = http.openOutputStream(); + + //Запись данных + for (int i = 0; i < param.length; i++) { + os.write((int) param[i]); + } + + //Получение ответа от сервера + byte[] answer = HTTPUtil.readHttpResponse(http); + String responseStatus = new String(answer); + failureCount = 0; + //Неверная сессия + if (responseStatus.indexOf("BADSESSION") >= 0) { + session.invalidate(); + } + } catch (IOException ex) { + failureCount++; + String msg = "Ошибка скробблинга: " + ex.getMessage(); + if (failureCount > 2) { + session.invalidate(); + failureCount = 0; + } + throw new Exception(msg); + } finally { + if (os != null) { + try { + os.close(); + } catch (Exception e) {} + } + HTTPUtil.closeHttpConnection(http); + processing = false; + } + } + + /** + * Завершение работы скробблера + */ + public void shutdown() { + shutdown = true; + try { + while (processing) { + //Если выполняется скробблинг - ждём его завершения + Thread.sleep(5000); + } + } catch (InterruptedException e) {} + } + + /** + * Получение данных трека для скроббблинга + * @param track трек для скробблинга + * @param startTime время начала воспроизведения + * @return массив байт запроса + */ + private byte[] createSubmissionParams(Track track, long startTime) { + StringBuffer param = new StringBuffer(); + //ID сессии + param.append("s=").append(HTTPUtil.encodeParam(session.sessionID)).append('&'); + //Исполнитель + param.append("a%5b0%5d=").append(HTTPUtil.encodeParam(track.getArtist())).append('&'); + //Название трека + param.append("t%5b0%5d=").append(HTTPUtil.encodeParam(track.getTitle())).append('&'); + //Времени начала воспроизведения + param.append("i%5b0%5d=").append(startTime).append('&'); + //Ключ рекомендации + param.append("o%5b0%5d=P&"); + //Рейтинг + param.append("r%5b0%5d=&"); + //Длина трека в секундах + param.append("l%5b0%5d=").append((int)track.getDuration()).append('&'); + //Альбом + param.append("b%5b0%5d=").append(HTTPUtil.encodeParam(track.getAlbum())).append('&'); + //Номер трека + param.append("n%5b0%5d=&");//.append(track.getNumber()).append(""); + //MusicBrainz Track ID + param.append("m%5b0%5d="); + //Кодируем URL + String params = param.toString(); + byte[] paramBytes = params.getBytes(); + + return paramBytes; + } + + /** + * Проверка правильности сессии + * @return true - сессия валидна + */ + private boolean validSession() { + if (session == null || session.invalid()) { + while ((session == null || session.invalid()) && !shutdown) { + int retryTime = (session == null) ? 0 : session.getRetryWaitTime(); + //Ожидание до следующего handshake + //Ожидание 5 секунд при неуспешности + try { + Thread.sleep(retryTime); + } catch (Exception e) {} + + try { + if (handshake()) { + session.resetWaitTime(); + break; + } + } catch (Exception ex) { + if (session == null) { + session = new Session(); + } + session.increaseWaitTime(); + } + } + + if (session == null || session.invalid()) { + //Handshake не выполнен, невозможно заскробблить + return false; + } + } + //Сессия валидна + return true; + } + + /** + * Сессия подключения + * @author Neill + */ + private static class Session { + + private static final int ONE_MINUTE = 60 * 1000; + private static final int MAX_RETRY = 120 * ONE_MINUTE; + + private final String sessionID; + private final String nowPlayingUrl; + private final String submitUrl; + private int retryWaitTime; + private boolean invalid; + + /** + * Создаёт неправильную сессию с пустыми значениями + */ + public Session() { + this(null, null, null); + invalid = true; + } + + /** + * Создаёт сессию со значениями + * @param sessionID ID сессии + * @param nowPlayingUrl ссылка для nowPlaying + * @param submitUrl ссылка для скробблинга + */ + public Session(String sessionID, String nowPlayingUrl, String submitUrl) { + this.sessionID = sessionID; + this.nowPlayingUrl = nowPlayingUrl; + this.submitUrl = submitUrl; + this.retryWaitTime = 0; + invalid = false; + } + + /** + * Проверка валидности сессии + * @return true сессия неверная + */ + public boolean invalid() { + return invalid; + } + + /** + * Изменение состояния валидности + * сессии на неверную + */ + public void invalidate() { + invalid = true; + } + + /** + * Получение времени ожидания реконнекта + * @return время в миллисекундах + */ + public int getRetryWaitTime() { + return retryWaitTime; + } + + /** + * Увеличить время ожидания + */ + public void increaseWaitTime() { + if (retryWaitTime == 0) { + retryWaitTime = ONE_MINUTE; + } else if (retryWaitTime < MAX_RETRY) { + retryWaitTime *= 2; + } + } + + /** + * Сброс времени ожидания + */ + public void resetWaitTime() { + retryWaitTime = 0; + } + } +} \ No newline at end of file diff --git a/src/mobscrob/scrobbler/MD5.java b/src/lastfm/MD5.java similarity index 76% rename from src/mobscrob/scrobbler/MD5.java rename to src/lastfm/MD5.java index 398f80c..8c9cc5b 100644 --- a/src/mobscrob/scrobbler/MD5.java +++ b/src/lastfm/MD5.java @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with MobScrob. If not, see . */ -package mobscrob.scrobbler; +package lastfm; import java.io.IOException; import java.io.InputStream; @@ -79,88 +79,6 @@ public class MD5 { return toHex(this.getHash()); } - /** - * Gets the MD5 hash of the given byte array. - * - * @param b byte array for which an MD5 hash is desired. - * @return Array of 16 bytes, the hash of all updated bytes. - * - * @since ostermillerutils 1.00.00 - */ - public static byte[] getHash(byte[] b) { - MD5 md5 = new MD5(); - md5.update(b); - return md5.getHash(); - } - - /** - * Gets the MD5 hash of the given byte array. - * - * @param b byte array for which an MD5 hash is desired. - * @return 32-character hex representation the data's MD5 hash. - * - * @since ostermillerutils 1.00.00 - */ - public static String getHashString(byte[] b) { - MD5 md5 = new MD5(); - md5.update(b); - return md5.getHashString(); - } - - /** - * Gets the MD5 hash the data on the given InputStream. - * - * @param in byte array for which an MD5 hash is desired. - * @return Array of 16 bytes, the hash of all updated bytes. - * @throws IOException if an I/O error occurs. - * - * @since ostermillerutils 1.00.00 - */ - public static byte[] getHash(InputStream in) throws IOException { - MD5 md5 = new MD5(); - byte[] buffer = new byte[1024]; - int read; - while ((read = in.read(buffer)) != -1) { - md5.update(buffer, read); - } - return md5.getHash(); - } - - /** - * Gets the MD5 hash the data on the given InputStream. - * - * @param in byte array for which an MD5 hash is desired. - * @return 32-character hex representation the data's MD5 hash. - * @throws IOException if an I/O error occurs. - * - * @since ostermillerutils 1.00.00 - */ - public static String getHashString(InputStream in) throws IOException { - MD5 md5 = new MD5(); - byte[] buffer = new byte[1024]; - int read; - while ((read = in.read(buffer)) != -1) { - md5.update(buffer, read); - } - return md5.getHashString(); - } - - /** - * Gets the MD5 hash of the given String. - * The string is converted to bytes using the current - * platform's default character encoding. - * - * @param s String for which an MD5 hash is desired. - * @return Array of 16 bytes, the hash of all updated bytes. - * - * @since ostermillerutils 1.00.00 - */ - public static byte[] getHash(String s) { - MD5 md5 = new MD5(); - md5.update(s); - return md5.getHash(); - } - /** * Gets the MD5 hash of the given String. * The string is converted to bytes using the current @@ -177,38 +95,6 @@ public class MD5 { return md5.getHashString(); } - /** - * Gets the MD5 hash of the given String. - * - * @param s String for which an MD5 hash is desired. - * @param enc The name of a supported character encoding. - * @return Array of 16 bytes, the hash of all updated bytes. - * @throws UnsupportedEncodingException If the named encoding is not supported. - * - * @since ostermillerutils 1.00.00 - */ - public static byte[] getHash(String s, String enc) throws UnsupportedEncodingException { - MD5 md5 = new MD5(); - md5.update(s, enc); - return md5.getHash(); - } - - /** - * Gets the MD5 hash of the given String. - * - * @param s String for which an MD5 hash is desired. - * @param enc The name of a supported character encoding. - * @return 32-character hex representation the data's MD5 hash. - * @throws UnsupportedEncodingException If the named encoding is not supported. - * - * @since ostermillerutils 1.00.00 - */ - public static String getHashString(String s, String enc) throws UnsupportedEncodingException { - MD5 md5 = new MD5(); - md5.update(s, enc); - return md5.getHashString(); - } - /** * Reset the MD5 sum to its initial state. * @@ -219,17 +105,6 @@ public class MD5 { finalState.valid = false; } - /** - * Returns 32-character hex representation of this hash. - * - * @return String representation of this object's hash. - * - * @since ostermillerutils 1.00.00 - */ - public String toString() { - return getHashString(); - } - /** * Update this hash with the given data. *

@@ -300,21 +175,6 @@ public class MD5 { update(workingState, buffer, offset, length); } - /** - * Update this hash with the given data. - *

- * If length bytes are not available to be hashed, as many bytes as - * possible will be hashed. - * - * @param buffer Array of bytes to be hashed. - * @param length number of bytes to hash. - * - * @since ostermillerutils 1.00.00 - */ - public void update(byte buffer[], int length) { - update(buffer, 0, length); - } - /** * Update this hash with the given data. * @@ -326,19 +186,6 @@ public class MD5 { update(buffer, 0, buffer.length); } - /** - * Updates this hash with a single byte. - * - * @param b byte to be hashed. - * - * @since ostermillerutils 1.00.00 - */ - public void update(byte b) { - byte buffer[] = new byte[1]; - buffer[0] = b; - update(buffer, 1); - } - /** * Update this hash with a String. * The string is converted to bytes using the current @@ -351,19 +198,6 @@ public class MD5 { public void update(String s) { update(s.getBytes()); } - - /** - * Update this hash with a String. - * - * @param s String to be hashed. - * @param enc The name of a supported character encoding. - * @throws UnsupportedEncodingException If the named encoding is not supported. - * - * @since ostermillerutils 1.00.00 - */ - public void update(String s, String enc) throws UnsupportedEncodingException { - update(s.getBytes(enc)); - } /** * The current state from which the hash sum * can be computed or updated. @@ -399,7 +233,7 @@ public class MD5 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0,}; + 0, 0, 0, 0, 0, 0, 0, 0}; /** * Contains internal state of the MD5 class. diff --git a/src/mobscrob/scrobbler/AudioScrobbler.java b/src/mobscrob/scrobbler/AudioScrobbler.java deleted file mode 100644 index 385bd56..0000000 --- a/src/mobscrob/scrobbler/AudioScrobbler.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * aNNiMON 2011 - * For more info visit http://annimon.com/ - */ -package mobscrob.scrobbler; - -import java.io.OutputStream; -import java.util.Calendar; -import java.util.Vector; -import javax.microedition.io.Connector; -import javax.microedition.io.HttpConnection; -import javax.microedition.lcdui.Image; - -/** - * - * @author aNNiMON - */ -public class AudioScrobbler { - - private Image avatarBitmap; - private String challenge; - private String clientId; - private String clientVersion; - private boolean connected = false; - private String handshakeUrl; - private String md5Response; - private String passwordMD5; - private String submitUrl; - private String user; - private static final String DEFAULT_HOST = "";//"post.audioscrobbler.com"; - - /* - * private void SubmitTrack() - * { - * if (this.LastFM[2] == string.Empty) - * { - * this.LastFM[2] = Audioscrobbler.GetPasswordMD5(this.LastFM[1]); - * } - * if (this.audioscrobbler == null) - * { - * this.audioscrobbler = new Audioscrobbler("opa", "0.1", this.LastFM[0], this.LastFM[2]); - * this.audioscrobbler.ConnectionFailed += new EventHandler(audioscrobbler_ConnectionFailed); - * this.audioscrobbler.Submitted += new EventHandler(this.audioscrobbler_Submitted); - * this.audioscrobbler.ConnectionEstablished += new EventHandler(audioscrobbler_ConnectionEstablished); - * } - * this.audioscrobbler.Connect(); - * } - * - * ((Audioscrobbler)sender).Submit(frmMain.CurrentTrackInfo[1], frmMain.CurrentTrackInfo[3], frmMain.CurrentTrackInfo[2], - * "1", frmMain.CurrentTrackLength / 1000); - */ - - //"opa", "0.1", this.LastFM[0], this.LastFM[2] - public AudioScrobbler(String clientId, String clientVersion, String user, String passwordMD5) { - this.clientId = clientId; - this.clientVersion = clientVersion; - this.user = user; - this.passwordMD5 = passwordMD5; - this.handshakeUrl = "http://post.audioscrobbler.com/?hs=true&p=1.1&c=" + this.clientId + "&v=" + this.clientVersion + "&u=" + this.user; - } - - private void connectNow() { - try { - this.avatarBitmap = null; - - byte[] body = HTTPUtil.getUrl(this.handshakeUrl, DEFAULT_HOST); - Vector lines = ByteUtil.readLines(body); - - // check is OK - String str = (String) lines.elementAt(0); - if (str.equals("UPTODATE") || str.startsWith("UPDATE")) - { - this.challenge = (String) lines.elementAt(1); - this.submitUrl = (String) lines.elementAt(2); - String s = this.passwordMD5 + this.challenge; - this.md5Response = MD5.getHashString(s).replace('-', '\0').toLowerCase(); - this.connected = true; - //ConnectionEstablished(this, new EventArgs()); - } - } catch (Exception ex) { - //ConnectionFailed(this, new EventArgs()); - } - } - - public void connect() { - Thread thread = new Thread(new Runnable() { - - public void run() { - connectNow(); - } - }); - thread.start(); - } - - private void downloadAvatar() { - String str = MD5.getHashString(this.user).replace('-', '\0').toLowerCase(); - try { - byte[] img = HTTPUtil.getUrl("http://static.last.fm/avatar/" + str + ".jpg/", ""); - this.avatarBitmap = Image.createImage(img, 0, img.length); - } catch (Exception ex) { - } - } - - public static String GetPasswordMD5(String password) { - return MD5.getHashString(password).replace('-', '\0').toLowerCase(); - } - - public void Submit(String artist, String song, String album, String musicBrainzId, int length) { - if (this.connected) { - final Submittor submittor = new Submittor(this.submitUrl, this.user, this.md5Response, artist, song, album, musicBrainzId, length, 3); - - Thread thread = new Thread(new Runnable() { - - public void run() { - submittor.execute(); - } - }); - thread.start(); - } - } - - public Image AvatarBitmap() { - return this.avatarBitmap; - } - - private class Submittor { - - private String album; - private String artist; - private int length; - private String musicBrainzId; - private String response; - private int retry; - private String song; - private String url; - private String user; - - public Submittor(String url, String user, String response, String artist, String song, String album, String musicBrainzId, int length, int retry) { - this.url = url; - this.user = user; - this.response = response; - this.artist = (retry == 0) ? HTTPUtil.encodeParam(artist) : artist; - this.song = (retry == 0) ? HTTPUtil.encodeParam(song) : song; - this.album = (retry == 0) ? HTTPUtil.encodeParam(album) : album; - this.musicBrainzId = musicBrainzId; - this.length = length; - this.retry = retry; - } - - private String getTime() { - StringBuffer sb = new StringBuffer(); - Calendar cal = Calendar.getInstance(); - int tmp; - //Год 2009-06-15 20:45:30Z - tmp = cal.get(Calendar.YEAR); - if (tmp <= 9) { - sb.append('0'); - } - sb.append(tmp); - sb.append('-'); - //Месяц - tmp = cal.get(Calendar.MONTH) + 1; - if (tmp <= 9) { - sb.append('0'); - } - sb.append(tmp); - sb.append('-'); - //День - tmp = cal.get(Calendar.DAY_OF_MONTH); - if (tmp <= 9) { - sb.append('0'); - } - sb.append(tmp); - sb.append(' '); - //Час - tmp = cal.get(Calendar.HOUR_OF_DAY); - if (tmp <= 9) { - sb.append('0'); - } - sb.append(tmp); - sb.append(':'); - //Минута - tmp = cal.get(Calendar.MINUTE); - if (tmp <= 9) { - sb.append('0'); - } - sb.append(tmp); - sb.append(':'); - //Секунда - tmp = cal.get(Calendar.SECOND); - if (tmp <= 9) { - sb.append('0'); - } - sb.append(tmp); - return sb.toString(); - } - - public void execute() { - HttpConnection conn = null; - OutputStream os = null; - try { - StringBuffer sb = new StringBuffer(); - sb.append("u=").append(this.user); //User - sb.append("&s=").append(this.response); //Session - sb.append("&a[0]=").append(this.artist); //Artist - sb.append("&t[0]=").append(this.song); //Title - sb.append("&b[0]=").append(this.album); //Album - sb.append("&m[0]=").append(this.musicBrainzId); //MusicBrainzId - - sb.append("&l[0]=").append(this.length); //Length (Duration) - sb.append("&i[0]=").append(getTime()); //Current Time - - byte[] bytes = sb.toString().getBytes("UTF-8"); - - // set up HTTP connection - conn = (HttpConnection) Connector.open(this.url); - conn.setRequestMethod(HttpConnection.POST); - conn.setRequestProperty("User-Agent", "SEPlayerService"); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - conn.setRequestProperty("Content-Length", String.valueOf(bytes.length)); - // try opening output stream first - os = conn.openOutputStream(); - // try writing byte by byte - try { - os.write(bytes, 0, bytes.length); - } finally { - os.close(); - } - /*for (int i = 0; i < paramBytes.length; i++) { - os.write((int) paramBytes[i]); - }*/ - byte[] resp = HTTPUtil.readHttpResponse(conn); - Vector lines = ByteUtil.readLines(resp); - - try { - String str2 = (String) lines.elementAt(0); - int interval = 0; - String str3 = (String) lines.elementAt(1); - if ((str3 != null) && str3.startsWith("INTERVAL")) { - try { - interval = Integer.parseInt(str3.substring("INTERVAL ".length())); - } catch (Exception ex) { - } - } - if (str2.startsWith("FAILED")) { - this.retry(interval); - } else if (str2.startsWith("BADAUTH")) { - throw new Exception(); - } - } finally { - conn.close(); - } - } catch (Exception ex) { - } - } - - private void retry(int interval) { - if (this.retry <= 3) { - this.retry++; - try { - Thread.sleep((int) ((interval * this.retry) * 0x3e8)); - } catch (InterruptedException ex) { - } - final AudioScrobbler.Submittor submittor = new AudioScrobbler.Submittor(this.url, this.user, this.response, this.artist, this.song, this.album, this.musicBrainzId, this.length, this.retry); - - Thread thread = new Thread(new Runnable() { - - public void run() { - submittor.execute(); - } - }); - thread.start(); - } - } - } -} diff --git a/src/mobscrob/scrobbler/ByteUtil.java b/src/mobscrob/scrobbler/ByteUtil.java deleted file mode 100644 index cc5d563..0000000 --- a/src/mobscrob/scrobbler/ByteUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * ByteUtil.java - * @date 30 Sep 2008 - * - * This program is distributed under the terms of the GNU General Public - * License - * Copyright 2008 NJ Pearman - * - * This file is part of MobScrob. - * - * MobScrob is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * MobScrob is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with MobScrob. If not, see . - */ -package mobscrob.scrobbler; - -import java.util.Vector; - -/** - * - */ -/** - * @author Neill - * - */ -public class ByteUtil { - - /** - * Utility class so private constructor - */ - private ByteUtil() { - } - - /** - * Returns a Vector of Strings representing the lines present in the byte - * array, separated by '\n' return feed. - * - * @param bytes - * @return - */ - public static Vector readLines(byte[] bytes) { - //final String methodName = "1"; - Vector lines = new Vector(); - if (bytes == null || bytes.length == 0) { - return lines; - } - StringBuffer line = new StringBuffer(); - for (int i = 0; i < bytes.length; i++) { - if (bytes[i] == '\n') { - lines.addElement(line.toString()); - line = new StringBuffer(); - } else { - // add to current line - line.append((char) bytes[i]); - } - } - - return lines; - } - - public static void replaceSpaceWithPlus(byte[] bytes) { - if (bytes != null) { - for (int i = 0; i < bytes.length; i++) { - if (bytes[i] == ' ') { - bytes[i] = '+'; - } - } - } - } -} diff --git a/src/mobscrob/scrobbler/HTTPUtil.java b/src/mobscrob/scrobbler/HTTPUtil.java deleted file mode 100644 index dc6cf52..0000000 --- a/src/mobscrob/scrobbler/HTTPUtil.java +++ /dev/null @@ -1,192 +0,0 @@ -/** - * HTTPUtil.java - * - * This program is distributed under the terms of the GNU General Public - * License - * Copyright 2008 NJ Pearman - * - * This file is part of MobScrob. - * - * MobScrob is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * MobScrob is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with MobScrob. If not, see . - */ -package mobscrob.scrobbler; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.util.Enumeration; -import java.util.Vector; - -import javax.microedition.io.Connector; -import javax.microedition.io.HttpConnection; - - -/** - * @author Neill - * - */ -public class HTTPUtil { - - private static final String ENC_UTF8 = "UTF-8"; - - public static final String HEADER_HOST = "Host"; - - private HTTPUtil() {} - - /** - * Encodes a parameter, also ensuring that it is UTF-8 - * - * @param s - * @return - * @throws UnsupportedEncodingException - */ - public static String encodeParam(String s) { - if (s == null) { - return s; - } - - // encode as UTF-8 - String utf8Str; - try { - utf8Str = new String(s.getBytes(), ENC_UTF8); - } catch (UnsupportedEncodingException ex) { - utf8Str = s; - } - - StringBuffer sb = new StringBuffer(utf8Str.length() * 3); - char[] chars = utf8Str.toCharArray(); - int next; - - // encode the chars in the UTF-8 String - for (int i = 0; i < chars.length; i++) { - next = chars[i]; - - if ((next >= 0x30 && next <= 0x39) || // 0-9 - (next >= 0x41 && next <= 0x5A) || // A-Z - (next >= 0x61 && next <= 0x7A)) { // a-z - sb.append((char) next); - } else if ((next == 0xA0)) { // ' ' (whitespace) - sb.append('+'); - } else { // encode all other chars - sb.append("%"); - if (next <= 0xf) - sb.append("0"); - sb.append(Integer.toHexString(next)); - } - } - return sb.toString(); - } - - /** - * Attempts to open a URL using the GET method over HTTP and read the - * response into a byte array. Any IOExceptions are simply thrown out of - * this method to be caught elsewhere. - * - * @param url - * @return - * @throws IOException - */ - public static byte[] getUrl(String url, String headerHostname) throws IOException { - HttpConnection conn = null; - try { - conn = (HttpConnection) Connector.open(url); - - // set the compulsory HTTP/1.1 Host: header, as GET - conn.setRequestMethod(HttpConnection.GET); - //if(!headerHostname.equals("")) - // conn.setRequestProperty(HEADER_HOST, headerHostname); - - byte[] body = readHttpResponse(conn); - return body; - } finally { - closeHttpConnection(conn); - } - } - - /** - * Reads the response from the specified HTTP connection into a byte array. - * - * @param conn - * @return - * @throws IOException - */ - public static byte[] readHttpResponse(HttpConnection conn) throws IOException { - final String methodName = "6"; - int rc = conn.getResponseCode(); - if (rc != HttpConnection.HTTP_OK) { - String msg = "HTTP response code not OK: " + rc; - throw new IOException(msg); - } - - String connHeader = conn.getHeaderField("Connection"); - - // connect - int len = (int) conn.getLength(); - - InputStream is = null; - - try { - is = conn.openInputStream(); - - // read response - if (len > -1) { - byte[] body = new byte[len]; - int actual = 0; - int bytesread = 0; - - while ((bytesread != len) && (actual != -1)) { - actual = is.read(body, bytesread, len - bytesread); - bytesread += actual; - } - // do something - return body; - } else { - // read byte by byte...? - - Vector bytes = new Vector(); - Byte byteObj; - int next; - while ((next = is.read()) > -1) { - byteObj = new Byte((byte) next); - bytes.addElement(byteObj); - } - - byte[] body = new byte[bytes.size()]; - Enumeration e = bytes.elements(); - int i = 0; - while (e.hasMoreElements()) { - byteObj = (Byte) e.nextElement(); - body[i++] = byteObj.byteValue(); - } - - return body; - } - } finally { - if (is != null) { - try { - is.close(); - } catch (Exception e) { - } - } - } - } - - public static void closeHttpConnection(HttpConnection conn) { - final String methodName = "7"; - if (conn != null) { - try { conn.close(); } - catch (Exception e) { } //log.error(methodName, "Unable to close HTTP connecton: " + e.getMessage(), e); } - } - } -} diff --git a/src/msapi/J2MEPlayer.java b/src/msapi/J2MEPlayer.java new file mode 100644 index 0000000..082d129 --- /dev/null +++ b/src/msapi/J2MEPlayer.java @@ -0,0 +1,57 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package msapi; + +/** + * + * @author aNNiMON + */ +public class J2MEPlayer implements SPlayer { + + public void play() { + } + + public void pause() { + } + + public void nextTrack() { + } + + public void prevTrack() { + } + + public void fastForward() { + } + + public void rewind() { + } + + public void skip(int i) { + } + + public void seek(int i) { + } + + public void updateTrackInfo() { + } + + public long getCurrentTime() { + return 10; + } + + public void playPause() { + } + + public Track getTrack() { + Track temp = new Track(); + temp.setArtist("Unknown artist"); + temp.setAlbum("Unknown album"); + temp.setTitle("Unknown title"); + temp.setDuration(100); + return temp; + } + +} diff --git a/src/msapi/MSPlayer.java b/src/msapi/MSPlayer.java new file mode 100644 index 0000000..78f9165 --- /dev/null +++ b/src/msapi/MSPlayer.java @@ -0,0 +1,156 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package msapi; + +import com.annimon.StringEncoder; +import com.sonyericsson.multimedia.ControlEvent; +import com.sonyericsson.multimedia.ControlException; +import com.sonyericsson.multimedia.Media; +import com.sonyericsson.multimedia.MetaData; +import com.sonyericsson.multimedia.MultimediaService; +import com.sonyericsson.multimedia.MultimediaServiceManager; +import com.sonyericsson.multimedia.control.MediaControl; +import com.sonyericsson.multimedia.control.MediaControlListener; +import javax.microedition.lcdui.Image; + +/** + * Стандартный плеер Sony Ericsson. Используется Multimedia Services API. + * @author aNNiMON + */ +public class MSPlayer implements MediaControlListener, SPlayer { + + private MultimediaService service; + private MediaControl mediaControl; + private Media media; + private Track track; + + public MSPlayer() { + service = MultimediaServiceManager.getMultimediaService("MediaPlayer"); + mediaControl = (MediaControl)service.getControl("MediaControl"); + mediaControl.addMediaControlListener(MSPlayer.this); + } + + public void mediaControlUpdate(int eventId, ControlEvent event) { + try { + switch (eventId) { + case MediaControlListener.PLAY: + case MediaControlListener.PAUSE: + case MediaControlListener.STOP: + case MediaControlListener.ENDPLAY: + case MediaControlListener.FASTFORWARD: + case MediaControlListener.REWIND: + this.media = (Media) event.getData(); + updateTrackInfo(); + break; + + case MediaControlListener.ERROR: + break; + } + } catch (Throwable t) {} + } + + private String getValue(MetaData metaData, String md) { + String data = metaData.getValue(md); + StringBuffer sb = new StringBuffer(); + for(int i=0; i + public void play() { + try { + mediaControl.play(); + } catch (ControlException ex) {} + } + + public void pause() { + try { + mediaControl.pause(); + } catch (ControlException ex) {} + } + + public void nextTrack() { + try { + mediaControl.next(); + } catch (ControlException ex) {} + } + + public void prevTrack() { + try { + mediaControl.prev(); + } catch (ControlException ex) {} + } + + public void fastForward() { + try { + mediaControl.fastForward(); + } catch (ControlException ex) {} + } + + public void rewind() { + try { + mediaControl.rewind(); + } catch (ControlException ex) {} + } + + public void skip(int i) { + try { + mediaControl.skip(i); + } catch (ControlException ex) {} + } + + public void seek(int i) { + try { + mediaControl.seek(i); + } catch (ControlException ex) {} + } + + public void updateTrackInfo() { + try { + MetaData data = media.getMetaData(); + if (data != null) { + + if (track == null || !track.getTitle().equals((String) getValue(data, MetaData.TITLE_KEY))) { + if (track == null) track = new Track(); + track.setAlbum((String) getValue(data, MetaData.ALBUM_KEY)); + track.setArtist((String) getValue(data, MetaData.ARTIST_KEY)); + track.setTitle((String) getValue(data, MetaData.TITLE_KEY)); + track.setDuration(media.getDuration()); + + byte[] alb = data.getAlbumArt(); + if (alb != null) { + track.setCover(Image.createImage(alb, 0, alb.length)); + } else { + track.setCover(null); + } + } + } + } catch (Exception e) {} + } + + public Track getTrack() { + return track; + } + + public long getCurrentTime() { + return media.getMediaTime(); + } + + public void playPause() { + try { + if (mediaControl.getState() == mediaControl.STATE_PLAY) pause(); + else play(); + } catch (ControlException ex) { + play(); + } + } + // + + + +} diff --git a/src/msapi/SPlayer.java b/src/msapi/SPlayer.java new file mode 100644 index 0000000..f40f37b --- /dev/null +++ b/src/msapi/SPlayer.java @@ -0,0 +1,37 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package msapi; + +/** + * + * @author aNNiMON + */ +public interface SPlayer { + + public abstract void play(); + + public abstract void pause(); + + public abstract void nextTrack(); + + public abstract void prevTrack(); + + public abstract void fastForward(); + + public abstract void rewind(); + + public abstract void skip(int i); + + public abstract void seek(int i); + + public abstract void updateTrackInfo(); + + public abstract Track getTrack(); + + public abstract long getCurrentTime(); + + public abstract void playPause(); +} diff --git a/src/msapi/Track.java b/src/msapi/Track.java new file mode 100644 index 0000000..8d5bc78 --- /dev/null +++ b/src/msapi/Track.java @@ -0,0 +1,79 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package msapi; + +import javax.microedition.lcdui.Image; + +/** + * Трек + * @author aNNiMON + */ +public class Track { + + // + /** Название альбома */ + private String album; + + /** Исполнитель */ + private String artist; + + /** Картинка альбома */ + private Image cover; + + /** Длительность */ + private long duration; + + /** Заголовок */ + private String title; + // + + // + public String getAlbum() { + return album; + } + + public String getArtist() { + return artist; + } + + public Image getCover() { + return cover; + } + + public long getDuration() { + return duration; + } + + public String getTitle() { + return title; + } + + // + + // + public void setAlbum(String album) { + this.album = album; + } + + public void setArtist(String artist) { + this.artist = artist; + } + + public void setCover(Image cover) { + this.cover = cover; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + public void setTitle(String title) { + this.title = title; + } + + // + +} diff --git a/src/newfile b/src/newfile deleted file mode 100644 index 2212995..0000000 --- a/src/newfile +++ /dev/null @@ -1,2 +0,0 @@ -визуализация смены громкости -Быстрая перемотка \ No newline at end of file diff --git a/src/res/1.swf b/src/res/1.swf new file mode 100644 index 0000000..1e65547 Binary files /dev/null and b/src/res/1.swf differ diff --git a/src/2.swf b/src/res/2.swf similarity index 100% rename from src/2.swf rename to src/res/2.swf diff --git a/src/3.swf b/src/res/3.swf similarity index 100% rename from src/3.swf rename to src/res/3.swf diff --git a/src/4.swf b/src/res/4.swf similarity index 100% rename from src/4.swf rename to src/res/4.swf diff --git a/src/res/5.swf b/src/res/5.swf new file mode 100644 index 0000000..16ccdbd Binary files /dev/null and b/src/res/5.swf differ diff --git a/src/res/6.swf b/src/res/6.swf new file mode 100644 index 0000000..6bfc419 Binary files /dev/null and b/src/res/6.swf differ diff --git a/src/about b/src/res/about similarity index 85% rename from src/about rename to src/res/about index 1a296cf..077404b 100644 --- a/src/about +++ b/src/res/about @@ -3,14 +3,13 @@ Sony Ericsson Player Service 7.0 Автор: Виктор aNNiMON Мельник Сайт разработчика: http://annimon.com/ -Программа - управление стандартным плейером телефонов Sony Ericsson с поддержкой Multimedia Service API и акселерометром. +Программа - управление стандартным плеером телефонов Sony Ericsson с поддержкой Multimedia Service API и акселерометром. Управление: Влево/Вправо/Движение акселерометром - Переключение песен. Вверх/Вниз - переключение режимов: Всё/Визуализация. - 1 - Горячая клавиша поиска текста. 3 - установить начало/конец отрезка для повтора или отключить повтор. - 4/6 - Перемотка назад/вперед. + 4/6 - Перемотка назад/вперед. Зажатие активизирует быструю перемотку. 5/Огонь - Пауза. 9 - Спящий режим. 0 - Включение/Отключение текстов песен. @@ -19,6 +18,13 @@ Sony Ericsson Player Service 7.0 Изменения: Версия 7.0 + - Программа полностью переписана с нуля, убраны неработающие и ненужные элементы. Это даёт заметный прирост скорости работы и расширение функционала. + - Добавлены новые переходы между экранами. + - Добавлены новые визуальные эффекты. + - Убран скробблер annimon.com и добавлен скробблер LastFM. + - Экран визуализации теперь показывается на весь экран. + - Изменена логика доступа к внутренним API. + - Доступ к данным акселерометра теперь универсальный. - При выборе цвета скина, по нажатию кн.0 можно выбрать цвет текста. Версия 6.0 @@ -33,10 +39,12 @@ Sony Ericsson Player Service 7.0 - Скроллинг длинных названий песен. - Добавлена быстрая перемотка на зажатие кнопок 4 или 6. - Добавлена визуализация смены громкости. + Версия 5.2 - Добавлен пункт в настройках, при котором переключение треков будет идти только вперед, независимо от направления рывка. - Поддержка русской кодировки в именах файлов. - Другие исправления и изменения. + Версия 5.0 && 5.1 - Добавлена сортировка списка файлов по рейтингу. - Добавлен английский язык. @@ -70,9 +78,6 @@ Sony Ericsson Player Service 7.0 - Режим визуализации. Переключается клавишами Вверх/Вниз, - Добавил перемотку клавишами 1 и 3. -Скробблинг: - В версии 5.0 сделал некое подобие скробблинга, то есть информация о проигруемом файле отсылается на сайт. Потом вы можете смотреть статистику проигрывания музыки. - Поддержка lrc: Lyrics-файл (.lrc) должен быть записан в кодировке WIN-1251, иначе возможны ошибки при чтении. Имя lrc-файла должно быть либо "[Название группы] - [Название песни].lrc", либо "[Название исходного фудиофайла].ltc". @@ -87,4 +92,4 @@ Z393537409230 - - - - - - - - - - - - - - - - - - © aNNiMON (Melnik Software) -Украина, 2010 \ No newline at end of file +Украина, 2011 \ No newline at end of file diff --git a/src/res/album.png b/src/res/album.png deleted file mode 100644 index 3442b7c..0000000 Binary files a/src/res/album.png and /dev/null differ diff --git a/src/res/album.xid b/src/res/album.xid new file mode 100644 index 0000000..8d1d722 Binary files /dev/null and b/src/res/album.xid differ diff --git a/src/res/artist.png b/src/res/artist.png deleted file mode 100644 index 4188fff..0000000 Binary files a/src/res/artist.png and /dev/null differ diff --git a/src/res/artist.xid b/src/res/artist.xid new file mode 100644 index 0000000..ed60172 Binary files /dev/null and b/src/res/artist.xid differ diff --git a/src/res/exit.png b/src/res/exit.png deleted file mode 100644 index 1a2f8dc..0000000 Binary files a/src/res/exit.png and /dev/null differ diff --git a/src/res/exit.xid b/src/res/exit.xid new file mode 100644 index 0000000..b683bc6 --- /dev/null +++ b/src/res/exit.xid @@ -0,0 +1,3 @@ +$ю'90z}m}wwwz>?3%wwwcwwwbqwww1ў№Яwwvњ>36#­Тўёf­фР#хKЈЦт5Т,fурY)У№6—W–^懕6ЈFЯ+RЫЯ«…pУX a°nАц`»KёDЁђЊ‹н~s‰’„ЋфПя|hЏЁьWFЛІk№аd·EMрФ•}aІ™4·n#™bї)Iц ;”aµ?~.Є,мђпµ*k„|/ра/°8{s;Ц}ґщ8Ъ»j›Gi•@I–v#а#З5·Чс‹oЁ“¦‡І} WоNќ%№{j’0GулaЪІокz<4I™ЅЙ_4 Є.ыњЄIkЗµOI]Мiм· юМќІ–xQ§тjнL +т1ВзNjИ]Ийњў„ ђЅћуЇу8•фuЬѓ qryњ4JX_¬:‰bДќѓ%>ИsrБ€?m B‹CљbџX\j7Щъєн¤wwww>293Щ5х \ No newline at end of file diff --git a/src/res/icon.png b/src/res/icon.png new file mode 100644 index 0000000..67fbfe8 Binary files /dev/null and b/src/res/icon.png differ diff --git a/src/res/pal.png b/src/res/pal.png deleted file mode 100644 index ac347c5..0000000 Binary files a/src/res/pal.png and /dev/null differ diff --git a/src/res/pal.xid b/src/res/pal.xid new file mode 100644 index 0000000..cfda1f7 Binary files /dev/null and b/src/res/pal.xid differ diff --git a/src/res/pound.png b/src/res/pound.png deleted file mode 100644 index c06391c..0000000 Binary files a/src/res/pound.png and /dev/null differ diff --git a/src/res/pound.xid b/src/res/pound.xid new file mode 100644 index 0000000..acaf4a8 Binary files /dev/null and b/src/res/pound.xid differ diff --git a/src/res/sb.png b/src/res/sb.png deleted file mode 100644 index 195c71e..0000000 Binary files a/src/res/sb.png and /dev/null differ diff --git a/src/res/sb.xid b/src/res/sb.xid new file mode 100644 index 0000000..923439f Binary files /dev/null and b/src/res/sb.xid differ diff --git a/src/res/sbl.png b/src/res/sbl.png deleted file mode 100644 index 8e50f2b..0000000 Binary files a/src/res/sbl.png and /dev/null differ diff --git a/src/res/sbl.xid b/src/res/sbl.xid new file mode 100644 index 0000000..03ee851 Binary files /dev/null and b/src/res/sbl.xid differ diff --git a/src/res/slp.xid b/src/res/slp.xid new file mode 100644 index 0000000..9784bb6 Binary files /dev/null and b/src/res/slp.xid differ diff --git a/src/res/star.png b/src/res/star.png deleted file mode 100644 index 4269fd3..0000000 Binary files a/src/res/star.png and /dev/null differ diff --git a/src/res/star.xid b/src/res/star.xid new file mode 100644 index 0000000..9c6d828 Binary files /dev/null and b/src/res/star.xid differ diff --git a/src/res/t.png b/src/res/t.png deleted file mode 100644 index 9bf6eb1..0000000 Binary files a/src/res/t.png and /dev/null differ diff --git a/src/res/t.xid b/src/res/t.xid new file mode 100644 index 0000000..7590044 Binary files /dev/null and b/src/res/t.xid differ diff --git a/src/res/tl.png b/src/res/tl.png deleted file mode 100644 index 2568a4d..0000000 Binary files a/src/res/tl.png and /dev/null differ diff --git a/src/res/tl.xid b/src/res/tl.xid new file mode 100644 index 0000000..7f3bd1c Binary files /dev/null and b/src/res/tl.xid differ diff --git a/src/res/track.png b/src/res/track.png deleted file mode 100644 index 8d5761e..0000000 Binary files a/src/res/track.png and /dev/null differ diff --git a/src/res/track.xid b/src/res/track.xid new file mode 100644 index 0000000..26169e6 Binary files /dev/null and b/src/res/track.xid differ diff --git a/src/res/zero.png b/src/res/zero.png deleted file mode 100644 index 39bbcf2..0000000 Binary files a/src/res/zero.png and /dev/null differ diff --git a/src/res/zero.xid b/src/res/zero.xid new file mode 100644 index 0000000..2a101cb Binary files /dev/null and b/src/res/zero.xid differ diff --git a/src/seps/Canv.java b/src/seps/Canv.java new file mode 100644 index 0000000..6d4b68a --- /dev/null +++ b/src/seps/Canv.java @@ -0,0 +1,692 @@ +package seps; + +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +import accel.*; +import com.annimon.GraphicsUtil; +import com.annimon.Util; +import com.nokia.mid.ui.DeviceControl; +import fx.*; +import javax.microedition.lcdui.*; +import lastfm.LastFMScrobbler; +import msapi.*; +import visual.*; + +/** + * @author aNNiMON + */ +public class Canv extends Canvas implements Runnable { + + //Экран + private Image I; + private Graphics G; + private int w,h; + + //Модули (интерфейсы) + private SensorData sensor; //Акселерометр + private SPlayer player; //MultimediaServices API + private Visual visual; //Visualization + //Переходы + private AnimatedImage animated = null; + private ImageFx imgfx; + private Image old; + + //Прочие классы + private Images im; //Изображения + private Lang lang; //Текстовые метки + private FWCashe mfwc; //Кэш размеров шрифта + private Lyrics lrc; //Тексты песен + private Thread thr; //Поток + //Изображение альбома + private Image album; + + //Функция повтора + private byte repeat; + private int a,b; + + //Режимы и состояния + private static final byte + PLAYER_MODE = 0, + VISUAL_MODE = 1; + private static final byte MAX_VISUALS = 16; + private static final int MENU_Y_STEP = 25; + private static final int VOLUME_Y_STEP = 10; + private byte mode; + private int volumeplus, volumeminus; //визуализация изменения громкости + private boolean fastF, fastR; //быстрая перемотка + private int cx, cy, thisskin; //выбор скина + private int accelPrevDelta; //Предыдущее состояние акселерометра + private boolean rspressed; + + //Скролллинг текста (исп, трек, альб, текст) + private int char_A_width; + private int[] scrollPos = {0,0,0,0}; + private int[] sleepPos = {0,0,0,0}; + private boolean[] scrolldirection = {false, false, false, false}; + private int textWidth, lyricWidth; + + //Меню + private String[] m; + private int menuwidth, menuheight, mcur, menuy, menuup; + private boolean menu, skin, vis; + + + public Canv(Images im, Lang lang) { + setFullScreenMode(true); + w = getWidth(); + h = getHeight(); + this.im = im; + this.lang = lang; + //Инициализация API + try { + if(!Rms.api_mserv) player = new J2MEPlayer(); + else player = new MSPlayer(); + } catch (Exception e) { + player = new J2MEPlayer(); + } + if(Rms.api_accel) sensor = new AccelData(); + else sensor = new NoData(); + thr = new Thread(this); + thr.start(); + //Модули + initVisual(); + //Инициализация экрана + I = Image.createImage(w, h); + G = I.getGraphics(); + //Режимы + mode = PLAYER_MODE; + fastF = fastR = menu = skin = vis = rspressed = false; + accelPrevDelta = volumeplus = volumeminus = menuup = mcur = repeat = 0; + //Размеры + char_A_width = GraphicsUtil.getFont(GraphicsUtil.SMALL_BOLD_FONT).charWidth('a'); //размер буквы а жирного шрифта + lyricWidth = w/(char_A_width+1); + textWidth = lyricWidth - 1; + cx = w/2; + cy = 4*im.statusBarHeight+im.pal.getHeight()/2; + initMenu(lang); + menuy = 2*im.statusBarHeight-menuheight; + + if(Rms.startPlayer) getPlayer().play(); + getPlayer().updateTrackInfo(); + } + + /** + * Инициализация меню + * @param lang + */ + public final void initMenu(Lang lang) { + m = new String[] { + lang.sleepmode, + lang.visual, + lang.skin, + lang.options, + lang.about, + lang.minimise, + lang.exit + }; + mfwc = FWCashe.getCache(GraphicsUtil.getFont(GraphicsUtil.MEDIUM_BOLD_FONT)); + menuwidth = mfwc.stringWidth(m[0]); + menuheight = m.length * (GraphicsUtil.getHeightFont(GraphicsUtil.MEDIUM_BOLD_FONT)+2); + for(int i=1; imenuwidth) menuwidth = mfwc.stringWidth(m[i]); + } + menuwidth+=6; + } + + public void paint(Graphics g) { + //Выбор визуализации + if(vis) choiceVisual(g, Rms.visid); + else if(skin) choiceSkin(g, cx, cy); + //Переключение режимов (all, visual) + else if (animated != null && old != null) { + g.drawImage(old, w/2, h/2, Graphics.HCENTER | Graphics.VCENTER); + animated.paint(g, w/2, h/2, Graphics.HCENTER | Graphics.VCENTER); + if (animated.isEnded()) animated = null; + }else drawCanvas(g); + repaint(); + } + + public void drawCanvas(Graphics g) { + if(mode==PLAYER_MODE) drawPlayerCanvas(G); + else if(mode==VISUAL_MODE) drawVisual(G); + g.drawImage(I, 0, 0, 20); + //Меню + if(menuup!=0) { + if(menuup>0) { + menuy-=MENU_Y_STEP; + if(menuy<=2*im.statusBarHeight-menuheight) { + menu = false; + menuup=0; + } + } else { + menuy+=MENU_Y_STEP; + if(menuy>=2*im.statusBarHeight) { + menu = true; + menuup=0; + } + } + drawMenu(g, mcur, menuy); + }else if(menu) drawMenu(g, mcur, menuy); + //Визуализации изменения громкости + if(volumeplus>0) { + GraphicsUtil.drawRect(g, Skin.volumeUp, Skin.volumeDn, 0, volumeplus-20, w, 20); + GraphicsUtil.drawRect(g, Skin.volumeDn, Skin.volumeUp, 0, volumeplus, w, 20); + volumeplus-=VOLUME_Y_STEP; + } + if(volumeminusih) album = Effects.Resize(album, ih*album.getWidth()/album.getHeight(), ih); + g.drawImage(album, w/2, h/2, 3); + }else if(Rms.vis){ + visual.setDimension(w, ih); + g.drawImage(visual.getImage(), w/2, h/2, 3); + } + if(Rms.isLyric && lrc!=null) { + try { + GraphicsUtil.drawCenter(g, lrc.get5Lines((int) getPlayer().getCurrentTime())); + } catch (Exception e) {} + } + g.setColor(Skin.valuet); + g.drawString(current.getTitle(), 9, 2, 20); + //drawSoft(g); + } + + private void drawPlayerCanvas(Graphics g) { + g.setColor(Skin.background); + g.fillRect(0, 0, w, h); + GraphicsUtil.drawTitle(g, Util.getTime(), im, mode==PLAYER_MODE); + int fh = GraphicsUtil.getHeightFont(GraphicsUtil.SMALL_BOLD_FONT)+2; + int py = fh+fh/2; + g.setFont(GraphicsUtil.getFont(GraphicsUtil.MEDIUM_BOLD_FONT)); + //Данные о треке + Track current = getPlayer().getTrack(); + //Исполнитель + String data = current.getArtist(); + g.drawImage(im.artist, 2, py, 20); + if (data != null) py = GraphicsUtil.drawText(g, scrollText(data, 0), py, 0); + //Спящий режим + if(Rms.slpmode) g.drawImage(im.sleep, w-2, py+2, Graphics.RIGHT | Graphics.TOP);//g.drawString("S", 2, py+15+3*fh, 20); + //Заголовок + data = current.getTitle(); + g.drawImage(im.track, 1, py, 20); + if (data != null) py = GraphicsUtil.drawText(g, scrollText(data, 1), py, 1); + //Альбом + data = current.getAlbum(); + g.drawImage(im.album, 2, py, 20); + if (data != null) py = GraphicsUtil.drawText(g, scrollText(data, 2), py, 2); + + if(Rms.isLyric && lrc!=null) py = GraphicsUtil.drawText(g, scrollText(lrc.getLine((int) getPlayer().getCurrentTime()), 3), py, 3); + //Индикатор прогресса + float div = ((float)w - 10) / (float)current.getDuration(); + g.setColor(Skin.valuet); + int mgt = (int) getPlayer().getCurrentTime(); + int k = im.statusBarleftWidth+3; + GraphicsUtil.drawRect(g, Skin.softUp1, Skin.softUp2, 5, py, (int)(mgt * div), im.statusBarHeight); + for(int i=k; iih) album = Effects.Resize(album, ih*album.getWidth()/album.getHeight(), ih); + g.drawImage(album, w/2, py+15, 17); + }else if(Rms.vis){ + int ih = h-fh-2-py-20; + visual.setDimension(ih, ih); + g.drawImage(visual.getImage(), w/2, py+15, 17); + } + drawSoft(g); + } + + /** + * Отрисовка меню + * @param g + * @param cur + * @param y + */ + private void drawMenu(Graphics g, int cur, int y) { + GraphicsUtil.ACLS(g, 180, 0x00); + int fh = GraphicsUtil.getHeightFont(GraphicsUtil.MEDIUM_BOLD_FONT)+2; + int x = w/2-menuwidth/2; + for(int i=0; i=m.length) mcur=0; + break; + case FIRE: + menuAction(mcur); + break; + } + }else if(vis) { + switch (ga) { + case UP: + case LEFT: + Rms.visid--; + if(Rms.visid<0) Rms.visid=MAX_VISUALS; + initVisual(); + break; + case DOWN: + case RIGHT: + Rms.visid++; + if(Rms.visid>MAX_VISUALS) Rms.visid=0; + initVisual(); + break; + } + if(ga==FIRE || key==-6) vis = false; + }else if(skin) { + if(ga==UP) {cy--;if(cy<4*im.statusBarHeight) cy=4*im.statusBarHeight+im.pal.getHeight()-1;} + else if(ga==DOWN) {cy++;if(cy>=4*im.statusBarHeight+im.pal.getHeight()) cy=4*im.statusBarHeight+1;} + else if(ga==LEFT) {cx--;if(cx=w/2+im.pal.getWidth()/2) cx=w/2-im.pal.getWidth()/2;} + else if(key==KEY_NUM0) { + int x = w/2-im.pal.getWidth()/2; + Skin.valuet = Rms.valuet = Effects.get(im.pal, cx-x, cy-4*im.statusBarHeight); + } + else if(ga==FIRE || key==-6) { + Rms.skinid = thisskin; + Skin.initSkin(Rms.skinid); + skin = false; + } + else if(key==-7) skin = false; + }else{ + if(key==-7) rspressed = true; + else if(key==KEY_POUND) Rms.accel=!Rms.accel; + else if(key==KEY_STAR) Rms.vis=!Rms.vis; + else if(key==KEY_NUM0) Rms.isLyric=!Rms.isLyric; + else if(key== -36) volumeplus = h;//vol+; + else if(key== -37) volumeminus = 0;//vol-; + } + repaint(); + } + + protected void keyReleased(int key) { + if(menuup!=0 || menu) return; + int ga=getGameAction(key); + if(key==-7) { + rspressed = false; + if(Rms.closePlayer) getPlayer().pause(); + Main.midlet.destroyApp(true); + }else if(key==KEY_NUM9) Main.midlet.dsp.setCurrent(new SetSleepMode()); + if(key==KEY_NUM4) { + if(fastR) { + fastR = false; + getPlayer().play(); + }else getPlayer().skip(-10); + } + else if(key==KEY_NUM6) { + if(fastF) { + fastF = false; + getPlayer().play(); + }else getPlayer().skip(10); + } + if(ga==LEFT && key!=KEY_NUM4) newTrack(false); + else if(ga==RIGHT && key!=KEY_NUM6) newTrack(true); + if(key==KEY_NUM3) ABRepeat(); + switch(ga) { + case UP: + case DOWN: + upMode(); + break; + case FIRE: + getPlayer().playPause(); + break; + } + repaint(); + } + + protected void keyRepeated(int key) { + if(key==KEY_NUM4) { + if(!fastR) { + getPlayer().rewind(); + fastR = true; + } + }else if(key==KEY_NUM6) { + if(!fastF) { + getPlayer().fastForward(); + fastF = true; + } + }else keyPressed(key); + } + + public void run() { + while (true) { + try { + if(Rms.light) DeviceControl.setLights(0, 100); + final int delta = sensor.getDelta(0, Rms.sensetivity); + if (delta != 0) { + if (accelPrevDelta != 0 && (delta * accelPrevDelta) < 0) { + accelPrevDelta = 0; + } else { + accelPrevDelta = delta; + + Runnable runnable = new Runnable() { + + public void run() { + if (delta > 0 && Rms.accel) { + newTrack(true); + } else if (delta < 0 && Rms.accel) { + newTrack(Rms.listfw); + } + } + }; + (new Thread(runnable)).start(); + } + } + /*if(Rms.vis) { + try { + Thread.sleep(100); + } catch (InterruptedException ex) {} + }*/ + if(Rms.slpmode) { + if(Util.checkTime()) { + getPlayer().pause(); + Main.midlet.destroyApp(true); + } + } + if(repeat==2) { + int mgt = (int) getPlayer().getCurrentTime(); + int sk = Math.abs(b-a); + if(mgt>=b) getPlayer().skip(-sk); + } + + if(Rms.isLyric && getPlayer().getCurrentTime() < 3) { + lrc = null; + //Данные о треке + Track current = getPlayer().getTrack(); + String at = current.getArtist()+" - "+current.getTitle(); + if(Lyrics.isExists(at)) lrc = new Lyrics(at); + } + + if(Rms.lastFM) { + //Данные о треке + Track current = getPlayer().getTrack(); + String thisSong = current.getArtist()+" - "+current.getTitle(); + if(!thisSong.equalsIgnoreCase(Rms.lastSong)) { + int thisTime = (int) getPlayer().getCurrentTime(); + int allTime = (int) (current.getDuration()*50/*% проиграно*//100); + if(thisTime>allTime && (current.getDuration()>30) /*если трек больше 30 секунд*/) { + try { + if (Rms.md5pass.equals("")) { + Rms.md5pass = LastFMScrobbler.md5(Rms.password); + } + // //if (audioscrobbler == null) + // AudioScrobbler audioscrobbler = new AudioScrobbler("tst", "1.0", Rms.username, Rms.md5pass); + // audioscrobbler.connect(); + // Thread.sleep(3000); + // audioscrobbler.Submit( + // current.getArtist(), + // current.getTitle(), + // current.getAlbum(), + // "1", (int)current.getDuration() + // ); + long startTime = (System.currentTimeMillis()/1000)-thisTime; + LastFMScrobbler ms = new LastFMScrobbler("tst", "1.0", Rms.username, Rms.md5pass); + ms.handshake(); + ms.scrobble(current, startTime); + }catch(Exception ex) { + Main.midlet.dsp.setCurrent(new Alert("Ошибка", ex.getMessage(), null, AlertType.INFO)); + } + Rms.lastSong = thisSong; + } + } + } + }catch(Exception ex) { + ex.printStackTrace(); + repaint(); + } + } + } + + private void menuAction(int i) { + if(m[i].equals(lang.sleepmode)) Main.midlet.dsp.setCurrent(new SetSleepMode()); + else if(m[i].equals(Main.midlet.lang.options)) Main.midlet.dsp.setCurrent(new OptionsForm()); + else if(m[i].equals(Main.midlet.lang.about)) Main.midlet.dsp.setCurrent(new Info(im)); + else if(m[i].equals(Main.midlet.lang.minimise)) Main.midlet.dsp.setCurrent(null); + else if(m[i].equals(Main.midlet.lang.exit)) Main.midlet.destroyApp(true); + else if(m[i].equals(Main.midlet.lang.skin)) skin = true; + else if(m[i].equals(Main.midlet.lang.visual)) vis = true; + } + + public final SPlayer getPlayer() { + return player; + } + + private void upMode() { + mode = (byte) (1-mode); + initFx(); + } + + private void choiceVisual(Graphics g, int cur) { + g.setColor(0); + g.fillRect(0, 0, w, h); + Image kdr; + int ww = w-w/4; + visual.setDimension(ww, ww); + kdr = visual.getImage(); + g.drawImage(Effects.reflection(kdr, 0.5D), w/2, 2*im.statusBarHeight, 17); + GraphicsUtil.drawTitle(g, Integer.toString(cur), im, mode==PLAYER_MODE); + } + + private void choiceSkin(Graphics g, int cx, int cy) { + g.setColor(0); + int x = w/2-im.pal.getWidth()/2; + g.fillRect(0, 0, w, h); + g.drawImage(im.pal, x, 4*im.statusBarHeight, 20); + //cursor + g.setColor(0x00); + int dcur = 4; + g.drawLine(cx + 1, cy, cx + dcur, cy); + g.drawLine(cx - dcur, cy, cx - 1, cy); + g.drawLine(cx, cy - dcur, cx, cy - 1); + g.drawLine(cx, cy + 1, cx, cy + dcur); + // + thisskin=Effects.get(im.pal, cx-x, cy-4*im.statusBarHeight); + GraphicsUtil.drawTitle(g,Integer.toHexString(thisskin), im, false); + } + + /** + * Инициализация смен экранов + */ + private void initFx() { + old = Image.createImage(I.getWidth(), I.getHeight()); + old.getGraphics().drawImage(I, 0, 0, 20); + if(mode==PLAYER_MODE) drawPlayerCanvas(G); + else if(mode==VISUAL_MODE) drawVisual(G); + + int type = Util.random(0, 5); + animated = new AnimatedImage(I); + int direction = (new int[] {Canvas.UP, Canvas.DOWN, Canvas.LEFT, Canvas.RIGHT})[Util.random(0, 3)]; + switch(type) { + case 1: + imgfx = new BlindsFx(Util.random(4,15), 1, direction); + break; + case 2: + imgfx = new WaveFx(Util.random(6,30), Util.random(10,95), direction); + break; + case 3: + imgfx = new PuzzleFx(Util.random(4,20), Util.random(4,20), 1); + break; + case 4: + imgfx = new WipeFx(direction, 1); + break; + case 5: + imgfx = new Slide2Fx(direction, 1); + break; + default: + imgfx = new SlideFx(Util.random(4,15), 1, direction); + + } + animated.setFx(imgfx); + animated.start(1400); + } + + /** + * Инициализация визуализаций + */ + private void initVisual() { + if(Rms.visid<=5) visual = new Stars(w, h, Rms.visid-1); + else if(Rms.visid==6) visual = new VisualME(w, h); + else if(Rms.visid<=10) visual = new Plasma(w, h, Rms.visid-7); + else visual = new Capuchin(w, h, Rms.visid-10); + } + + private String scrollText(String text, int id) { + int count = (id==3) ? lyricWidth : textWidth; + String tmp = text; + int lent = text.length(); + int scr = lent - count; + try { + if (lent > count) { + tmp = text.substring(scrollPos[id], scrollPos[id] + count); + if(sleepPos[id] scr) { + scrollPos[id]--; + scrolldirection[id] = !scrolldirection[id]; + } else if (scrollPos[id] < 0) { + scrollPos[id] = 0; + scrolldirection[id] = !scrolldirection[id]; + } + sleepPos[id] = 0; + } + } + }catch(Exception ex) {tmp = text;} + return tmp; + } + + /** + * Переключение трека + */ + private void newTrack(boolean next) { + a=b=0; repeat = 0; + Main.midlet.dsp.vibrate(Rms.vibrlen); + if (Rms.flash) { + DeviceControl.setLights(0, 0); + DeviceControl.setLights(0, 100); + } + if(next) getPlayer().nextTrack(); + else getPlayer().prevTrack(); + } + + private void ABRepeat() { + try { + repeat++; + switch (repeat) { + case 1: // ставим A + a = (int) getPlayer().getCurrentTime(); + break; + case 2: // ставим B + b = (int) getPlayer().getCurrentTime(); + if(a>b) { + int t = b; b=a; a=t; + } + break; + case 3: // конец повтора + a = b = 0; + repeat = 0; + break; + } + } catch (Exception e) { + } + } + +} \ No newline at end of file diff --git a/src/Effects.java b/src/seps/Effects.java similarity index 92% rename from src/Effects.java rename to src/seps/Effects.java index 07ffd32..0c6b008 100644 --- a/src/Effects.java +++ b/src/seps/Effects.java @@ -1,3 +1,5 @@ +package seps; + import javax.microedition.lcdui.*; /** @@ -87,7 +89,7 @@ public class Effects { return temp2; } - public static Image HSV(Image img, float hh) { + /*public static Image HSV(Image img, float hh) { float[] hsb = new float[3]; int w = img.getWidth(); int h = img.getHeight(); @@ -101,12 +103,12 @@ public class Effects { hsb = Effects.RGBtoHSV(qr, qg, qb, hsb); hsb[0] += hh; while(hsb[0]>360) hsb[0]-=360; - /*if(c=='S' || c == 's') hsb[1] = hsb[1] + (float) (ch/256); - if(c=='B' || c == 'b') hsb[2] = hsb[2] + (float) (ch/256);*/ + //if(c=='S' || c == 's') hsb[1] = hsb[1] + (float) (ch/256); + //if(c=='B' || c == 'b') hsb[2] = hsb[2] + (float) (ch/256); pixel[io] = (qa << 24) | Effects.HSVtoRGB(hsb[0], hsb[1], hsb[2]); } return Image.createRGBImage(pixel, w, h, true); - } + }*/ public static float getHSV(int color, int c) {//0-h, 1-s, 2-v float[] hsb = new float[3]; @@ -133,7 +135,7 @@ public class Effects { return (qa << 24) | Effects.HSVtoRGB(hsb[0], hsb[1], hsb[2]); } - private static int HSVtoRGB(float h, float s, float v) { + public static int HSVtoRGB(float h, float s, float v) { float qr = 0, qg = 0, qb = 0; int r = 0, g = 0, b = 0; if(s==0.0 && h==-1.0) return ((int)v << 16) | ((int)v << 8) | (int)v; @@ -166,10 +168,12 @@ public class Effects { if (b < min) min = b; // hue if(v==min) h=0; - if(v==r && g>=b) h = 60 * ((g-b)/(v-min)); - if(v==r && g 0) { + g.drawString(strLines.elementAt(i).toString(), 1, fontHeight + 5 + y1, Graphics.LEFT | Graphics.TOP); + } + y1 = y1 + defHeight; + if (y1 > mh) { + break; + } + } + g.setClip(0, 0, w, h); + GraphicsUtil.drawTitle(g, Main.midlet.lang.about, im, false); + } + + protected void keyPressed(int key) { + int ga = getGameAction(key); + if(ga==UP) MoveUp(); + else if(ga==DOWN) MoveDown(); + else if(ga==LEFT) PageUp(); + else if(ga==RIGHT) PageDown(); + else if(ga==FIRE || key==-6 || key==-7) + Main.midlet.dsp.setCurrent(Main.midlet.cnv); + else if(key==-6) { + try { + String url = "http://annimon.com/"; + if(url.length()!=19) return; + Main.midlet.platformRequest(url); + } catch (ConnectionNotFoundException ex) { + Main.midlet.dsp.setCurrent(Main.midlet.cnv); + } + } + repaint(); + } + + protected void keyRepeated(int keyCode) { + keyPressed(keyCode); + } + + + protected void pointerPressed(int x, int y) { + int w3 = w/3; + int h3 = h/3; + if(y

w3 && x<(w-w3))) keyPressed(UP); + else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyPressed(DOWN); + + if(xh3 && y<(h-h3))) keyPressed(LEFT); + else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyPressed(RIGHT); + + else if(x(h-h3)) keyPressed(-6); + else if(x>(w-w3) && y>(h-h3)) keyPressed(-7); + else if( (x>w3 && x<(w-w3)) && (y>h3 && y<(h-h3)) ) keyPressed(FIRE); + } + + private void SetTextPar() { + //Разбиваем строку на массив строк + strLines = null; + strLines = new Vector(); + String[] arr = Util.splitString(str, "\n"); + for(int i=0; i w) {//Слово полностью не умещается в строке + space = i0; + while (jw > w) { + j = 0; + while (j < w) { + space++; + j = def.stringWidth(substr.substring(in, space)); + } + space = space - 1; + j = def.stringWidth(substr.substring(in, space)); + strLines.addElement(substr.substring(in, space)); + jw = jw - j; + i0 = space; + in = space; + } + jw = 0; + } else { + i0 = space; + } + } + } + strLines.addElement(substr.substring(in, imax)); + } + textheight = strLines.size() * defHeight; + } + + private String getText(String path) { + DataInputStream dis = new DataInputStream(getClass().getResourceAsStream(path)); + StringBuffer strBuff = new StringBuffer(); + int ch = 0; + try { + while ((ch = dis.read()) != -1) { + strBuff.append(StringEncoder.decodeCharCP1251((byte)ch)); + } + dis.close(); + } catch (Exception e) {e.printStackTrace();} + return strBuff.toString(); + } + + private void MoveDown() { + if (textheight > mh) { + y0 = y0 - dy; + if (mh - y0 > textheight) { + y0 = mh - textheight; + } + } + } + + private void MoveUp() { + if (textheight > mh) { + y0 = y0 + dy; + if (y0 > 0) { + y0 = 0; + } + } + + } + + private void PageUp() { + if (textheight > mh) { + y0 = y0 + mh; + if (y0 > 0) { + y0 = 0; + } + } + } + + private void PageDown() { + if (textheight > mh) { + y0 = y0 - mh; + if (mh - y0 > textheight) { + y0 = mh - textheight; + } + } + } +} diff --git a/src/seps/Lang.java b/src/seps/Lang.java new file mode 100644 index 0000000..3917d7e --- /dev/null +++ b/src/seps/Lang.java @@ -0,0 +1,82 @@ +package seps; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author aNNiMON + */ +public class Lang { + + String back, exit, ok, no; + String about, sleepmode, options, minimise; + String sensetivity, textfolder, vibro, skin, visual, + light, start, stop, flashlight, tooff, accel, msapi, + api, scrobbling, listforward, login, pass; + + public Lang(int id) { + // Общие + msapi = "MultimediaServices"; + api = " API"; + ok = "Ok"; + //English + if(id==0) { + back = "Back"; + no = "No"; + accel = "Accelerometer"; + //Menu + sleepmode = "Sleep Mode"; + visual = "Visualization"; + skin = "Skin"; + options = "Options"; + about = "About"; + minimise = "Minimize"; + exit = "Exit"; + //SleepMode + tooff = "Time to turn off (in minutes):"; + //Options + sensetivity = "Sensetivity to switch:"; + textfolder = "Folder with the text:"; + vibro = "Vibration switch (in ms):"; + light = "Backlight"; + start = "Launch player when program start"; + stop = "Close player when program exit"; + flashlight = "Flash backlight"; + listforward = "List Forward"; + scrobbling = "LastFM scrobbling"; + login = "Login LastFM"; + pass = "Password"; + + }else{ + back = "Назад"; + exit = "Выход"; + no = "Нет"; + + accel = "Акселерометр"; + + about = "О программе"; + sleepmode = "Спящий режим"; + options = "Настройки"; + minimise = "Свернуть"; + sensetivity = "Чувствительность к переключению:"; + textfolder = "Папка с текстами:"; + vibro = "Вибрация при переключении (в мс):"; + skin = "Скин"; + visual = "Визуализации"; + light = "Постоянная подсветка"; + start = "Запускать плеер при старте программы"; + stop = "Закрывать плеер при выходе из программы"; + flashlight = "Мигание подсветкой"; + scrobbling = "LastFM скробблинг"; + tooff = "Врямя до выключения (в минутах):"; + listforward = "Листать вперед"; + login = "Логин LastFM"; + pass = "Пароль"; + } + } + + +} diff --git a/src/Lyrics.java b/src/seps/Lyrics.java similarity index 60% rename from src/Lyrics.java rename to src/seps/Lyrics.java index f1dd213..b48545e 100644 --- a/src/Lyrics.java +++ b/src/seps/Lyrics.java @@ -1,4 +1,7 @@ +package seps; + +import com.annimon.StringEncoder; import java.io.*; import java.util.Vector; import javax.microedition.io.*; @@ -61,8 +64,8 @@ public class Lyrics { } return l5; } - - public static final boolean isExists(String lyricsname) { + + public static boolean isExists(String lyricsname) { boolean r = false; FileConnection fc; try { @@ -92,7 +95,6 @@ public class Lyrics { is.close(); fc.close(); } catch (Exception e) { - e.printStackTrace(); return null; } return sb.toString(); @@ -143,7 +145,7 @@ public class Lyrics { * @return */ private boolean isNumChar(char ch) { - return ch >= '0' && ch <= '9'; + return Character.isDigit(ch);//ch >= '0' && ch <= '9'; } /** @@ -170,65 +172,4 @@ public class Lyrics { //int ms = Integer.parseInt(in.substring(in.indexOf('.')+1, in.indexOf(']'))); return ss+(mm*60); } - - /** - * Преобразовывает все неинтернет ссылки в нормальные, например убирая пробелы или лишние символы. - * @param url - исходный адрес - * @return - правильный адрес на выходе - - private String urlName(String url) { - if (url == null) return null; - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < url.length(); i++) { - char ch = url.charAt(i); - switch (ch) { - default: - if (ch < '\200') { - sb.append(ch); - break; - } - if (ch > '\177' && ch < '\u0800') { - sb.append('%'); - sb.append(Integer.toHexString((ch >> 6 | 0xc0) + 256).substring(1)); - sb.append('%'); - sb.append(Integer.toHexString((ch & 0x3f | 0x80) + 256).substring(1)); - break; - } - if (ch > '\u07FF' && ch < '\0') { - sb.append('%'); - sb.append(Integer.toHexString((ch >> 12 | 0xe0) + 256).substring(1)); - sb.append('%'); - sb.append(Integer.toHexString((ch >> 6 & 0x3f | 0x80) + 256).substring(1)); - sb.append('%'); - sb.append(Integer.toHexString((ch & 0x3f | 0x80) + 256).substring(1)); - } - break; - case 0: //'\0' - case 32: sb.append("%20"); break;// ' ' - case 61: sb.append("%3d"); break;// '=' - case 43: sb.append("%2b"); break;// '+' - case 39: sb.append("%27"); break;// '\'' - case 46: sb.append("%2E"); break;// '.' - case 60: sb.append("%3c"); break;// '<' - case 62: sb.append("%3e"); break;// '>' - case 35: sb.append("%23"); break;// '#' - case 37: sb.append("%25"); break;// '%' - case 38: sb.append("%26"); break;// '&' - case 123:sb.append("%7b"); break;// '{' - case 125:sb.append("%7d"); break;// '}' - case 92: sb.append("%5c"); break;// '\\' - case 94: sb.append("%5e"); break;// '^' - case 126:sb.append("%73"); break;// '~' - case 91: sb.append("%5b"); break;// '[' - case 93: sb.append("%5d"); break;// ']' - case 58: sb.append("%3A"); break;// ':' - case 47: sb.append("%2F"); break;// '/' - case 63: sb.append("%3F"); break;// '?' - case 45: sb.append("%2D"); break;// '-' - case 33: sb.append("%21"); break;// '!' - case 59: sb.append("%3B"); break;// ';' - } - } - return sb.toString(); - }*/ } diff --git a/src/seps/Main.java b/src/seps/Main.java new file mode 100644 index 0000000..61f13b3 --- /dev/null +++ b/src/seps/Main.java @@ -0,0 +1,51 @@ +package seps; + +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +import javax.microedition.lcdui.*; +import javax.microedition.midlet.*; + +/** + * @author aNNiMON + */ +public class Main extends MIDlet { + + public Display dsp; + public Canv cnv; + public Lang lang; + public Images im; + public static Main midlet; + + public Main() { + midlet = Main.this; + dsp = Display.getDisplay(Main.this); + } + + public void startApp() { + Rms.restoreOptions(); + im = new Images(); + lang = new Lang(Rms.lngid); + Skin.initSkin(Rms.skinid); + Displayable object; + //При первом запуске отображаем настройки + if(Rms.firstStart) { + object = new FirstStartForm(lang); + }else{ + object = cnv = new Canv(im, lang); + } + dsp = Display.getDisplay(this); + dsp.setCurrent(object); + } + + public void pauseApp() { + } + + public void destroyApp(boolean ex) { + Rms.saveOptions(); + if(Rms.closePlayer) cnv.getPlayer().pause(); + notifyDestroyed(); + } +} diff --git a/src/seps/OptionsForm.java b/src/seps/OptionsForm.java new file mode 100644 index 0000000..1f474cd --- /dev/null +++ b/src/seps/OptionsForm.java @@ -0,0 +1,102 @@ +package seps; + +import javax.microedition.lcdui.*; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * Экран настроек + * @author aNNiMON + */ +public class OptionsForm extends Form implements CommandListener { + + private Command ok, back; + private TextField sensetivityTF, lyricFolderTF, vibroLenTF, loginTF, passTF; + private ChoiceGroup optionsCG, languageCG; + + public OptionsForm() { + super(Main.midlet.lang.options); + //Инициализция команд + ok = new Command(Main.midlet.lang.ok, Command.OK, 1); + back = new Command(Main.midlet.lang.back, Command.BACK, 2); + //Инициализация элементов + sensetivityTF = new TextField(Main.midlet.lang.sensetivity, String.valueOf(Rms.sensetivity), 4, TextField.NUMERIC); + lyricFolderTF = new TextField(Main.midlet.lang.textfolder, Rms.lrcpath, 256, TextField.ANY); + vibroLenTF = new TextField(Main.midlet.lang.vibro, String.valueOf(Rms.vibrlen), 4, TextField.NUMERIC); + loginTF = new TextField(Main.midlet.lang.login, Rms.username, 64, TextField.ANY); + passTF = new TextField(Main.midlet.lang.pass, Rms.password, 64, TextField.PASSWORD); + languageCG = new ChoiceGroup ("Language / Язык", ChoiceGroup.EXCLUSIVE); + optionsCG = new ChoiceGroup ("", ChoiceGroup.MULTIPLE); + //Инициализация ChoiceGroup + initCG(); + //Добавление всех элементов на форму + addAll(); + } + + /** + * Инициализация ChoiceGroup + */ + private void initCG() { + languageCG.append("English", null); + languageCG.append("Русский", null); + languageCG.setSelectedIndex(Rms.lngid, true); + + optionsCG.append(Main.midlet.lang.light, null); + optionsCG.append(Main.midlet.lang.start, null); + optionsCG.append(Main.midlet.lang.stop, null); + optionsCG.append(Main.midlet.lang.flashlight, null); + optionsCG.append(Main.midlet.lang.listforward, null); + optionsCG.append(Main.midlet.lang.scrobbling, null); + + optionsCG.setSelectedIndex(0, Rms.light); + optionsCG.setSelectedIndex(1, Rms.startPlayer); + optionsCG.setSelectedIndex(2, Rms.closePlayer); + optionsCG.setSelectedIndex(3, Rms.flash); + optionsCG.setSelectedIndex(4, Rms.listfw); + optionsCG.setSelectedIndex(5, Rms.lastFM); + } + + /** + * Добавление всех элементов на форму + */ + private void addAll() { + append(languageCG); + append(sensetivityTF); + append(lyricFolderTF); + append(vibroLenTF); + append(optionsCG); + append(loginTF); + append(passTF); + addCommand(ok); + addCommand(back); + setCommandListener(this); + Main.midlet.dsp.setCurrent(this); + } + + public void commandAction(Command c, Displayable d) { + if (c==back) Main.midlet.dsp.setCurrent(Main.midlet.cnv); + + if ((c==ok || c==List.SELECT_COMMAND)) { + Rms.lngid = languageCG.getSelectedIndex(); + Main.midlet.lang = new Lang(Rms.lngid); + Rms.sensetivity = Integer.parseInt(sensetivityTF.getString()); + Rms.vibrlen = Integer.parseInt(vibroLenTF.getString()); + Rms.lrcpath = lyricFolderTF.getString(); + Rms.light = optionsCG.isSelected(0); + Rms.startPlayer = optionsCG.isSelected(1); + Rms.closePlayer = optionsCG.isSelected(2); + Rms.flash = optionsCG.isSelected(3); + Rms.listfw = optionsCG.isSelected(4); + Rms.lastFM = optionsCG.isSelected(5); + Rms.username = loginTF.getString(); + Rms.password = passTF.getString(); + Rms.md5pass = ""; + Main.midlet.cnv.initMenu(Main.midlet.lang); + Main.midlet.dsp.setCurrent(Main.midlet.cnv); + } + } + +} diff --git a/src/Rms.java b/src/seps/Rms.java similarity index 52% rename from src/Rms.java rename to src/seps/Rms.java index 312bf5a..db0d98b 100644 --- a/src/Rms.java +++ b/src/seps/Rms.java @@ -1,3 +1,5 @@ +package seps; + import java.io.*; import javax.microedition.rms.*; @@ -8,33 +10,47 @@ import javax.microedition.rms.*; */ public class Rms { - private static final String rmsName = "SEPS"; + private static final String rmsName = "SEPlayerService"; private static RecordStore rmsStore; + public static boolean firstStart = true; // первый старт - public static int sensetivity = 800; - public static int skinid = 0;//x820000;//0; - public static boolean isLyric = true; - public static String lrcpath = "c:/music/Lyrics/"; - public static boolean light = false; - public static boolean startPlayer = true;//запускать плейер при старте программы - public static boolean closePlayer = true;//закрывать плейер при выходе из программы - public static int vibrlen = 200; - public static boolean flash = true;//мигание при переключении - public static int visid = 0; - public static boolean statGo = false; //переключатель статистики - public static boolean stat = false;//вести статистику - public static boolean urlstat = true; - public static boolean actmenu = false; - public static boolean listfw = false; - public static boolean vis = true; - public static boolean accel = true; - public static String lastSong = ""; - public static int id = 0; - public static int lngid = 0; - - - public static int dh,dm; - public static boolean slpmode = false; + + // -= Настройки API =- \\ + public static boolean api_accel = true; //акселерометр + public static boolean api_mserv = true; //multimedia services + + // -= Настройки запуска плеера =- \\ + public static boolean startPlayer = true;//при старте программы + public static boolean closePlayer = true;//при выходе из программы + + // -= Настройки режимов и опций =- \\ + public static boolean lastFM = false; //скробблинг Last.FM + public static String username = ""; //Логин + public static String password = ""; //Пароль + public static String md5pass = ""; //Пароль в MD5 + + public static boolean vis = true; //показ визуализации + public static boolean isLyric = true; //тексты песен + public static boolean accel = true; //акселерометр + + public static boolean flash = true; //мигание при переключении + public static boolean listfw = false; //листать вперёд + public static boolean light = false; //постоянная подсветка + + + public static int sensetivity = 800; //Чувствительность акселерометра + public static int vibrlen = 200; //Время вибрации переключения треков + public static int skinid = 0; //Скин + public static int valuet = 0xFFFFFFFF;//Цвет текста + public static int lngid = 0; //Язык + public static int visid = 0; //Тип визуализации + + public static String lrcpath = "c:/music/Lyrics/"; + public static String lastSong = ""; + + public static boolean slpmode = false; //Спящий режим + public static int dh,dm; //Время выключения при спящем режиме + /** * Сохранение настроек */ @@ -45,25 +61,33 @@ public class Rms { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeBoolean(firstStart); - dos.writeInt(sensetivity); - dos.writeInt(skinid); - dos.writeBoolean(isLyric); - dos.writeUTF(lrcpath); - dos.writeBoolean(light); + dos.writeBoolean(api_accel); + dos.writeBoolean(api_mserv); dos.writeBoolean(startPlayer); dos.writeBoolean(closePlayer); - dos.writeInt(vibrlen); - dos.writeBoolean(flash); - dos.writeInt(visid); - dos.writeBoolean(stat); - dos.writeUTF(lastSong); - dos.writeInt(id); - dos.writeBoolean(urlstat); - dos.writeInt(lngid); - dos.writeBoolean(actmenu); - dos.writeBoolean(listfw); + //LastFM + dos.writeBoolean(lastFM); + dos.writeUTF(username); + dos.writeUTF(password); + dos.writeUTF(md5pass); + //Main modes dos.writeBoolean(vis); + dos.writeBoolean(isLyric); dos.writeBoolean(accel); + //Modes + dos.writeBoolean(flash); + dos.writeBoolean(listfw); + dos.writeBoolean(light); + //Values + dos.writeInt(sensetivity); + dos.writeInt(vibrlen); + dos.writeInt(skinid); + dos.writeInt(valuet); + dos.writeInt(lngid); + dos.writeInt(visid); + //Lyrics + dos.writeUTF(lrcpath); + dos.writeUTF(lastSong); dos.flush(); options = baos.toByteArray(); dos.close(); @@ -98,28 +122,35 @@ public class Rms { try { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(rmsStore.getRecord(1))); firstStart = dis.readBoolean(); - sensetivity = dis.readInt(); - skinid = dis.readInt(); - isLyric = dis.readBoolean(); - lrcpath = dis.readUTF(); - light = dis.readBoolean(); + api_accel = dis.readBoolean(); + api_mserv = dis.readBoolean(); startPlayer = dis.readBoolean(); closePlayer = dis.readBoolean(); - vibrlen = dis.readInt(); - flash = dis.readBoolean(); - visid = dis.readInt(); - stat = dis.readBoolean(); - lastSong = dis.readUTF(); - id = dis.readInt(); - urlstat = dis.readBoolean(); - lngid = dis.readInt(); - actmenu = dis.readBoolean(); - listfw = dis.readBoolean(); + //LastFM + lastFM = dis.readBoolean(); + username = dis.readUTF(); + password = dis.readUTF(); + md5pass = dis.readUTF(); + //Main modes vis = dis.readBoolean(); + isLyric = dis.readBoolean(); accel = dis.readBoolean(); + //Modes + flash = dis.readBoolean(); + listfw = dis.readBoolean(); + light = dis.readBoolean(); + //Values + sensetivity = dis.readInt(); + vibrlen = dis.readInt(); + skinid = dis.readInt(); + valuet = dis.readInt(); + lngid = dis.readInt(); + visid = dis.readInt(); + //Lyrics + lrcpath = dis.readUTF(); + lastSong = dis.readUTF(); dis.close(); - } catch (Exception ex) { - } + } catch (Exception ex) {} } } } diff --git a/src/SetSleepMode.java b/src/seps/SetSleepMode.java similarity index 65% rename from src/SetSleepMode.java rename to src/seps/SetSleepMode.java index e2231d1..032703f 100644 --- a/src/SetSleepMode.java +++ b/src/seps/SetSleepMode.java @@ -1,3 +1,5 @@ +package seps; + import java.util.Calendar; import javax.microedition.lcdui.*; @@ -7,7 +9,7 @@ import javax.microedition.lcdui.*; * and open the template in the editor. */ /** - * + * Класс установки спящего режима * @author aNNiMON */ public class SetSleepMode extends Form implements CommandListener { @@ -16,23 +18,20 @@ public class SetSleepMode extends Form implements CommandListener { private TextField zw; public SetSleepMode() { - super(SEPS.midlet.lang.sleepmode); - back = new Command(SEPS.midlet.lang.back, Command.BACK, 2); - ok = new Command(SEPS.midlet.lang.ok, Command.OK, 1); - zw = new TextField(SEPS.midlet.lang.tooff, String.valueOf(10), 2, TextField.NUMERIC); + super(Main.midlet.lang.sleepmode); + ok = new Command(Main.midlet.lang.ok, Command.OK, 1); + back = new Command(Main.midlet.lang.back, Command.BACK, 2); + zw = new TextField(Main.midlet.lang.tooff, String.valueOf(10), 2, TextField.NUMERIC); append(zw); addCommand(ok); addCommand(back); - setCommandListener(this); - SEPS.midlet.dsp.setCurrent(this); + setCommandListener(SetSleepMode.this); + Main.midlet.dsp.setCurrent(SetSleepMode.this); } public void commandAction(Command c, Displayable d) { - if (c == back) { - SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); - } - - if (c == ok) { + if (c == back) Main.midlet.dsp.setCurrent(Main.midlet.cnv); + else if (c == ok) { int time = Integer.parseInt(zw.getString()); if(time == 0) Rms.slpmode=false; else { @@ -48,9 +47,10 @@ public class SetSleepMode extends Form implements CommandListener { } if(dh>=24) dh=dh-24; Rms.slpmode=true; - Rms.dh=dh; Rms.dm=dm; + Rms.dh=dh; + Rms.dm=dm; } - SEPS.midlet.dsp.setCurrent(SEPS.midlet.cnv); + Main.midlet.dsp.setCurrent(Main.midlet.cnv); } } } diff --git a/src/seps/Skin.java b/src/seps/Skin.java new file mode 100644 index 0000000..015b511 --- /dev/null +++ b/src/seps/Skin.java @@ -0,0 +1,60 @@ +package seps; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * Скин + * @author aNNiMON + */ +public class Skin { + + public static int softUp1, softUp2, softDn1, softDn2, background, line, text, valuet, inf, + volumeUp, volumeDn; + + public static void initSkin(int skin) { + if(skin==1) skin = Rms.skinid = 0xFF3477d5; + else if(skin==2) skin = Rms.skinid = 0xFF181818; + else if(skin==3) skin = Rms.skinid = 0xFFCE6BA6; + else if(skin==4) skin = Rms.skinid = 0; + else if(skin==5) skin = Rms.skinid = 0xFFFFFF99; + background = 0xFF2F8400; + valuet = Rms.valuet; + if(skin!=0) { + softUp1 = Effects.changeHSV(background, 2, 0.4352941f); + softUp2 = Effects.changeHSV(background, 2, 0.19215685f); + softDn1 = Effects.changeHSV(background, 2, -0.007843137f); + softDn2 = Effects.changeHSV(background, 2, -0.16862747f); + line = Effects.changeHSV(background, 0, 22); + line = Effects.changeHSV(line, 2, 0.21568626f); + text = Effects.changeHSV(background, 0, 22); + text = Effects.changeHSV(text, 2, 0.082352936f); + inf = Effects.changeHSV(background, 2, -0.16078433f); + for(int i=0; i<=2; i++) { + float delta = Effects.getHSV(skin, i) - Effects.getHSV(background, i); + if(delta>-0.05 && delta<0.05) continue; + softUp1 = Effects.changeHSV(softUp1, i, delta); + softUp2 = Effects.changeHSV(softUp2, i, delta); + softDn1 = Effects.changeHSV(softDn1, i, delta); + softDn2 = Effects.changeHSV(softDn2, i, delta); + line = Effects.changeHSV(line, i, delta); + text = Effects.changeHSV(text, i, delta); + inf = Effects.changeHSV(inf, i, delta); + } + background = skin; + }else{ + softUp1 = 0xFF57f300; + softUp2 = 0xFF41b500; + softDn1 = 0xFF2e8200; + softDn2 = 0xFF205900; + line = 0x00BB00; + text = 0x009900; + inf = 0x215B00; + } + //Цвета громкостей + volumeUp = (0x33 << 24) | (softDn2 & 0x00FFFFFF); + volumeDn = (0xAA << 24) | (softDn2 & 0x00FFFFFF); + } +} diff --git a/src/seps/TestScrobbler.java b/src/seps/TestScrobbler.java new file mode 100644 index 0000000..552c5e9 --- /dev/null +++ b/src/seps/TestScrobbler.java @@ -0,0 +1,52 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ +package seps; + +import javax.microedition.lcdui.*; +import javax.microedition.midlet.*; +import lastfm.LastFMScrobbler; +import msapi.Track; + +/** + * @author aNNiMON + */ +public class TestScrobbler extends MIDlet { + + public Display dsp; + public static TestScrobbler midlet; + + public TestScrobbler() { + midlet = TestScrobbler.this; + dsp = Display.getDisplay(TestScrobbler.this); + } + + public void startApp() { + try { + String user = "User"; + String pass = "Pass"; + String md5pass = LastFMScrobbler.md5(pass); + System.out.println(md5pass); + + Track test = new Track(); + test.setTitle("Blood Brothers"); + test.setArtist("Papa Roach"); + test.setAlbum("Infest"); + test.setDuration(274); + long startTime = (System.currentTimeMillis()/1000)-180; + LastFMScrobbler ms = new LastFMScrobbler("tst", "1.0", user, md5pass); + ms.handshake(); + ms.scrobble(test, startTime); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void pauseApp() { + } + + public void destroyApp(boolean ex) { + notifyDestroyed(); + } +} diff --git a/src/visual/Capuchin.java b/src/visual/Capuchin.java new file mode 100644 index 0000000..dc12994 --- /dev/null +++ b/src/visual/Capuchin.java @@ -0,0 +1,30 @@ +package visual; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +import com.sonyericsson.capuchin.*; +import javax.microedition.lcdui.*; + +/** + * @author aNNiMON + */ +public class Capuchin extends Visual { + + private FlashImage flashImage; + + public Capuchin(int w, int h, int mode) { + super(w, h); + flashImage = null; + try { + flashImage = FlashImage.createImage(getClass().getResourceAsStream("/res/" + String.valueOf(mode) + ".swf"), null); + } catch (Exception ex) {} + } + + protected void paint(Graphics g) { + if (flashImage != null) { + flashImage.render(g, 0, 0, w, h); + } + } +} \ No newline at end of file diff --git a/src/visual/Plasma.java b/src/visual/Plasma.java new file mode 100644 index 0000000..5949d82 --- /dev/null +++ b/src/visual/Plasma.java @@ -0,0 +1,86 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package visual; + +import seps.Effects; +import java.util.Random; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Визуализация "Плазма" + * @author aNNiMON + */ +public class Plasma extends Visual { + + private int mode; + + /** + * Инициализация плазмы + * @param w - ширина области + * @param h - высота области + */ + public Plasma(int w, int h, int mode) { + super(w, h); + this.mode = mode; + } + + protected void paint(Graphics g) { + //g.drawImage(db, 0, 0, 20); + db = Image.createRGBImage(visual(), w, h, false); + } + + private int[] visual() { + int[] pix = new int[w*h]; + int color = 0; + int paletteShift =(int) (System.currentTimeMillis() / 10); + double ddr = (2 * Math.PI / 255); + for (int x = 0; x < w; x+=5) { + for (int y = 0; y < h; y+=5) { + + switch(mode) { + case 0: + double xx = (x - w / 2D); + double yy = (y - h / 2D); + color = (int) (128 + (128 * Math.sin(Math.sqrt(xx*xx + yy*yy) / 8.0))); break; + case 1: color = (int) ((128 + (128 * Math.sin(x / 8D)) + 128 + (128 * Math.sin(y / 8D))) / 2); break; + case 2: + color = (int) (( + 128 + (128 * Math.sin(x / 16D)) + + 128 + (128 * Math.sin(y / 8D)) + + 128 + (128 * Math.sin((x + y) / 16D)) + + 128 + (128 * Math.sin(Math.sqrt((x * x + y * y)) / 8D)) + ) / 4); + break; + default: + color = (int) ( (64 * (1 + Math.sin(x * ddr))) + + 64 * (1 + Math.sin(y * ddr)) ); + break; + } + //grf.setColor((palette((color + paletteShift) % 360) )); + //grf.fillRect(x, y, 5, 5); + + try { + pix[y * w + x] = pix[y * w + x + 1] = pix[y * w + x + 2] = + pix[(y + 1) * w + x] = pix[(y + 1) * w + x + 1] = pix[(y + 1) * w + x + 2] = + pix[(y + 2) * w + x] = pix[(y + 2) * w + x + 1] = pix[(y + 2) * w + x + 2] = 0xFF000000 | (palette((color + paletteShift) % 360)); + } catch (Exception e) { + } + } + } + return pix; + } + + + private int palette(int color) { + /*return ( + (color << 16) |//((255-color) << 16) | + ((2*color) << 8) |//((((color*2) > 255) ? 255 : (color*2)) << 8) | + (255-color)//(((128+color) > 255) ? 255 : (128+color)) + );*/ + return Effects.HSVtoRGB(color, 1.0f, 1.0f); + } +} diff --git a/src/visual/Stars.java b/src/visual/Stars.java new file mode 100644 index 0000000..332675f --- /dev/null +++ b/src/visual/Stars.java @@ -0,0 +1,196 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package visual; + +import com.annimon.GraphicsUtil; +import java.util.Random; +import javax.microedition.lcdui.Graphics; + +/** + * Визуализация "Звёзды" + * @author aNNiMON + */ +public class Stars extends Visual { + + /** Массивы координат звёзд */ + private int[] starx, stary, starz; + + private int K,i,mode; + private int max, spd, cf; + private long time, dt; + private boolean up,dn, update; + + /** + * Инициализация звёзд + * @param w - ширина области + * @param h - высота области + */ + public Stars(int w, int h, int mode) { + super(w, h); + this.mode = mode; + update = (mode<0); + max = 300; + spd = 200; + K = 60; + rnd = new Random(); + init(max); + time = System.currentTimeMillis(); + } + + protected void paint(Graphics g) { + g.drawImage(db, 0, 0, 20); + paint(); + updateParams(); + } + + private void paint() { + dt = System.currentTimeMillis() - time; + time = System.currentTimeMillis(); + if(K>=3) GraphicsUtil.ACLS(G, 100-K); + else GraphicsUtil.CLS(G); + for (i = 1; i0) { + if (starz[i] <= -200) { + initStar(); + } + setPix((255 - 255 * (starz[i] + 200) / 2100)); + }else{ + if (starz[i] > 2000) { + initStar(); + } + setPix((255-255 * (starz[i]%2100) / 2100)); + } + } + } + + /** + * Инициализация текущей звезды + */ + private void initStar() { + starx[i] = rnd.nextInt(w * 4) - w * 2; + stary[i] = rnd.nextInt(h * 4) - h * 2; + starz[i] = rnd.nextInt(1900); + } + + /** + * Инициализация звёзд + * @param max максимальное количество звёзд + */ + private void init(int max) { + starx = new int[max]; + stary = new int[max]; + starz = new int[max]; + for (i = 0; i11) max-=10; break; + case 13: if(update) if(max<1000) init(max+=100); break; + case 4: if(K<84) K+=15; break; + case 14: if(K>16) K-=15; break; + case 6: if(update) mode = rnd.nextInt(4); break; + } + try { + if(spd<25 && spd>-25) Thread.sleep(10); + else Thread.sleep(40); + } catch (InterruptedException ex) {} + } + + /** + * Отрисовка точки (звезды) + * @param c - цвет + */ + private void setPix(int c) { + int sx, sy, sx1 = 0, sy1 = 0; + sx = (w / 2 + starx[i] * 200 / (starz[i] + 200)); + sy = (h / 2 - stary[i] * 200 / (starz[i] + 200)); + if(c>255) c=255; + else if(c<0) c=0; + switch(mode) { + case 1: + G.setColor(c, c, c); + int u = (starz[i]==0) ? 1 : starz[i]; + G.fillArc(sx, sy, c/u, c/u, 0, 360); + break; + case 2: + u=rnd.nextInt(6); + switch(u) { + case 0: G.setColor(255-c, c, c); break; + case 1: G.setColor(c, 255-c, c); break; + case 2: G.setColor(c, c, 255-c); break; + case 3: G.setColor(255-c, 255-c, c); break; + case 4: G.setColor(255-c, c, 255-c); break; + case 5: G.setColor(c, 255-c, 255-c); break; + case 6: G.setColor(255-c, 255-c, 255-c); break; + } + if(i!=22) G.drawLine(sx, sy, sx, sy); + else try{G.fillRoundRect(sx, sy, starz[i]/(255-c), starz[i]/(255-c), i, i);}catch(Exception ex) {}; break; + case 3: + u=rnd.nextInt(6); + switch(u) { + case 0: G.setColor(255-c, c, c); break; + case 1: G.setColor(c, 255-c, c); break; + case 2: G.setColor(c, c, 255-c); break; + case 3: G.setColor(255-c, 255-c, c); break; + case 4: G.setColor(255-c, c, 255-c); break; + case 5: G.setColor(c, 255-c, 255-c); break; + case 6: G.setColor(255-c, 255-c, 255-c); break; + } + u=starz[i]==0?1:starz[i]; + G.fillArc(sx, sy, c/u, c/u, 0, 360); + break; + case 4: + u=rnd.nextInt(6); + switch(u) { + case 0: G.setColor(255-c, c, c); break; + case 1: G.setColor(c, 255-c, c); break; + case 2: G.setColor(c, c, 255-c); break; + case 3: G.setColor(255-c, 255-c, c); break; + case 4: G.setColor(255-c, c, 255-c); break; + case 5: G.setColor(c, 255-c, 255-c); break; + case 6: G.setColor(255-c, 255-c, 255-c); break; + } + if(i>1) { + sx1 = (w / 2 + starx[i-1] * 200 / (starz[i-1] + 200)); + sy1 = (h / 2 - stary[i-1] * 200 / (starz[i-1] + 200)); + } + G.drawLine(sx1, sy1, sx, sy); + break; + default: + G.setColor(c, c, c); + if(i!=22) G.drawLine(sx, sy, sx, sy); + else try{G.fillRoundRect(sx, sy, starz[i]/(255-c), starz[i]/(255-c), i, i);}catch(Exception ex) {}; + break; + } + } + +} diff --git a/src/visual/Visual.java b/src/visual/Visual.java new file mode 100644 index 0000000..35b045e --- /dev/null +++ b/src/visual/Visual.java @@ -0,0 +1,70 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package visual; + +import java.util.Random; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * + * @author aNNiMON + */ +public abstract class Visual { + + /** Изображение хранит содержимое визуализации */ + Image db; + /** Графика изображения */ + Graphics G; + /** Размеры рисуемой области */ + int w, h; + /** Генератор псевдослучайных чисел */ + Random rnd; + + /** + * Инициализация визуализации + * @param w - ширина области + * @param h - высота области + */ + public Visual(int w, int h) { + this.w = w; + this.h = h; + db = Image.createImage(w, h); + G = db.getGraphics(); + } + + /** + * Отрисовка визуализации + * @param g Graphics + */ + protected abstract void paint(Graphics g); + + /** + * Получение изображения визуализации + * @return Image + */ + public Image getImage() { + paint(G); + return db; + } + + /** + * Изменение размера визуализации + * @param w - ширина области + * @param h - высота области + */ + public void setDimension(int w, int h) { + if(this.w != w && this.h != h) { + this.w = w; + this.h = h; + db = Image.createImage(w, h); + G = db.getGraphics(); + G.setColor(0); + G.fillRect(0, 0, w, h); + } + } + +} diff --git a/src/Engine2.java b/src/visual/VisualME.java similarity index 57% rename from src/Engine2.java rename to src/visual/VisualME.java index 0c02377..892f882 100644 --- a/src/Engine2.java +++ b/src/visual/VisualME.java @@ -1,74 +1,54 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ -//import com.nokia.mid.ui.DeviceControl; -import javax.microedition.lcdui.*; +package visual; + +import com.annimon.GraphicsUtil; import java.util.Random; +import javax.microedition.lcdui.Graphics; -public class Engine2 implements Runnable { +/** + * Визуализация "Щупальца" + * @author aNNiMON + */ +public class VisualME extends Visual { - private Graphics G; - private Image db; private int S = 15;//ветви private int N = 20;//гибкость private int K = 60; - private float L = (float) 1/1; private int T = 0; //0-4 //line,time,rect private int U = 9; - private int w,h; - + private float L = (float) 1/1; + private boolean rb, gb, bb; private float x, y, tx, ty, k, d, len; private int rc, gc, bc, rgb, fr, ar; private float[] a = new float[40]; - private Random rnd; - private Thread thr; - public boolean run; - - public Engine2(int w, int h) { - this.w=w; - this.h=h; - db = Image.createImage(w, h); - G = db.getGraphics(); + + /** + * Инициализация щупалец + * @param w - ширина области + * @param h - высота области + */ + public VisualME(int w, int h) { + super(w, h); rnd = new Random(); rc = gc = bc = 0; - ar=(rnd.nextInt() >>> 1) % 14; - fr=((rnd.nextInt()>>>1)%6)+1; + ar=rnd.nextInt(14); + fr=rnd.nextInt(6)+1; rgb = 1; - thr = new Thread(this); - thr.start(); } - - public void run() { - while (run) { - int r = (rnd.nextInt() >>> 1) % 26; - switch(r) { - case 3: ar=(rnd.nextInt() >>> 1) % 14; break;//color - case 4: if(K<84) K+=15; break; - case 5: fr=((rnd.nextInt()>>>1)%6)+1; break;//formula - case 6: T = (rnd.nextInt() >>> 1) % 3; break;//фигуры - case 7: S += 4; break; - case 8: N += 5; if(N>=40) N=40; break; - case 9: N -= 5; if(N<5) N=5; break; - case 10: L = (float) 1/((rnd.nextInt() >>> 1)%8); break; - case 11: U=(rnd.nextInt() >>> 1) % 9; break; - case 14: if(K>16) K-=15; break; - } - try { - Thread.sleep(2000L); - } catch (InterruptedException ex) {} - } - } - - public void setRun(boolean run) { - this.run=run; - } - - public Image MainCanvas() { - rgb(G); + + protected void paint(Graphics g) { + g.drawImage(db, 0, 0, 20); + rgb(); visual(G); - return db; + updateParams(); } - - private void rgb(Graphics grf) { + + private void rgb() { switch(rgb) { case 1: rc++; @@ -114,7 +94,7 @@ public class Engine2 implements Runnable { break; } } - + private void visual(Graphics grf) { len = (float) (w>h?h:w) / L / N; k = (float) (Math.abs(rnd.nextFloat() * 360) * Math.PI / 180); @@ -131,36 +111,38 @@ public class Engine2 implements Runnable { for (int j = 0; j < S; j++) { x = (float) (0.5 * w); y = (float) (0.5 * h); + float temp1 = j * d + a[1]; for (int i = 1; i < N; i++) { + float temp2 = j * d + a[i]; grf.setColor(rc, gc, bc); if (fr == 1) { - tx = (float) (x + Math.cos(j * d + a[1]) * len); - ty = (float) (y + Math.sin(j * d + a[i]) * len); - x = x + (float) (Math.cos(j * d + a[i]) * len); + tx = (float) (x + Math.cos(temp1) * len); + ty = (float) (y + Math.sin(temp2) * len); + x = x + (float) (Math.cos(temp2) * len); }else if (fr == 2) { - tx = (float) (x + Math.sin(j * d + a[i]) * len); - ty = (float) (y + Math.cos(j * d + a[i]) * len); + tx = (float) (x + Math.sin(temp2) * len); + ty = (float) (y + Math.cos(temp2) * len); }else if (fr == 3) { - tx = (float) (x + Math.tan(j * d + a[1]) * len); - ty = (float) (y + Math.cos(j * d + a[i]) * len); - y = y - (float) (Math.sin(j * d + a[i]) * len); + tx = (float) (x + Math.tan(temp1) * len); + ty = (float) (y + Math.cos(temp2) * len); + y = y - (float) (Math.sin(temp2) * len); }else if (fr == 4) { - tx = (float) (x + Math.tan(j * d + a[1]) * len); - ty = (float) (y + Math.cos(j * d + a[i]) * len); - x = y - (float) (Math.sin(j * d + a[i]) * len); + tx = (float) (x + Math.tan(temp1) * len); + ty = (float) (y + Math.cos(temp2) * len); + x = y - (float) (Math.sin(temp2) * len); }else if (fr == 5) { - tx = (float) (x + Math.tan(j * d + a[1]) * len); - ty = (float) (y + Math.cos(j * d + a[i]) * len); - x = (float) (x * ty * d + a[i] - (float) (Math.sin(j * d + a[i]) * len)); + tx = (float) (x + Math.tan(temp1) * len); + ty = (float) (y + Math.cos(temp2) * len); + x = (float) (x * ty * d + a[i] - (float) (Math.sin(temp2) * len)); }else if (fr == 6) { - tx = (float) (x + Math.cos(j * d + a[1]) * len); - ty = (float) (y + Math.sin(j * d + a[1]) * len); - x = x + (float) (Math.sin(j * d + a[i]) * len); - y = y + (float) (Math.cos(j * d + a[i]) * len); - tx = (float) (x + Math.cos(j * d + a[1]) * len); - ty = (float) (y + Math.sin(j * d + a[1]) * len); - x = x + (float) (Math.sin(j * d + a[i]) * len); - y = y + (float) (Math.cos(j * d + a[i]) * len); + tx = (float) (x + Math.cos(temp1) * len); + ty = (float) (y + Math.sin(temp1) * len); + x = x + (float) (Math.sin(temp2) * len); + y = y + (float) (Math.cos(temp2) * len); + tx = (float) (x + Math.cos(temp1) * len); + ty = (float) (y + Math.sin(temp1) * len); + x = x + (float) (Math.sin(temp2) * len); + y = y + (float) (Math.cos(temp2) * len); } if (ar == 2) { grf.setColor(255, (255 - 255 * i / N), 0); @@ -196,20 +178,33 @@ public class Engine2 implements Runnable { y = ty; } } - if(K>=3) ACLS(grf); - else CLS(grf); + if(K>=3) GraphicsUtil.ACLS(grf, 100-K); + else GraphicsUtil.CLS(grf); } - private void CLS(Graphics g) { - g.setColor(Canv.background); - g.fillRect(0, 0, w, h); - } - - private void ACLS(Graphics g) { - int[] pixelArray = new int[w * h]; - for (int io = 0; io < pixelArray.length; io++) { - pixelArray[io] = (int)(100-K << 24) | Canv.background & 0x00ffffff; + + /** + * Обновление параметров + */ + private void updateParams() { + int r = rnd.nextInt(26); + switch(r) { + case 3: ar = rnd.nextInt(14); break;//color + case 4: if(K<84) K+=15; break; + case 5: fr = rnd.nextInt(6)+1; break;//formula + case 6: T = rnd.nextInt(3); break;//фигуры + case 7: S += 4; break; + case 8: N += 5; if(N>=40) N=40; break; + case 9: N -= 5; if(N<5) N=5; break; + case 10: L = (float) 1/rnd.nextInt(8); break; + case 11: U=rnd.nextInt(9); break; + case 14: if(K>16) K-=15; break; } - g.drawRGB(pixelArray, 0, w, 0, 0, w, h, true); + try { + Thread.sleep(25); + } catch (InterruptedException ex) {} } + + + }