commit 594b336d469fab36413ccd34a2c6887bd3974ff1 Author: Victor Date: Wed Nov 14 22:44:45 2018 +0200 Initial diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..b24c7d6 --- /dev/null +++ b/build.xml @@ -0,0 +1,83 @@ + + + + + + Builds, tests, and runs the project . + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..6bbf666 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Classpath to J2ME Ant extension library (libs.j2me_ant_ext.classpath property) is not set. For example: location of mobility/modules/org-netbeans-mobility-antext.jar file in the IDE installation directory. + Platform home (platform.home property) is not set. Value of this property should be ${platform.active.description} emulator home directory location. + Platform boot classpath (platform.bootclasspath property) is not set. Value of this property should be ${platform.active.description} emulator boot classpath containing all J2ME classes provided by emulator. + Must set src.dir + Must set build.dir + Must set dist.dir + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preprocessed.dir + + + + + + + + + + + + + + + + + + Must set build.classes.dir + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must set obfuscated.classes.dir + + + + Must set obfuscated.classes.dir + Must set obfuscator.srcjar + Must set obfuscator.destjar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preverify.classes.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroEdition-Configuration: ${platform.configuration} + + MicroEdition-Configuration: ${platform.configuration} + + + + MicroEdition-Profile: ${platform.profile} + + MicroEdition-Profile: ${platform.profile} + + + + Must set dist.jad + + + + + + + + + + + + + + + + + + + + + + + + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.jad} + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.manifest} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Must set dist.javadoc.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${all.configurations} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property deployment.${deployment.method}.scriptfile not set. The property should point to an Ant script providing ${deployment.method} deployment. + + + + + + + + Classpath to Ant Contrib library (libs.ant-contrib.classpath property) is not set. + + + + + + + + + Active project configuration: @{cfg} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property build.root.dir is not set. By default its value should be \"build\". + Property dist.root.dir is not set. By default its value should be \"dist\". + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..24a33dc --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +build.xml.data.CRC32=83c2feaf +build.xml.script.CRC32=5f3bfc00 +build.xml.stylesheet.CRC32=9c6a911d +nbproject/build-impl.xml.data.CRC32=83c2feaf +nbproject/build-impl.xml.script.CRC32=fbedd971 +nbproject/build-impl.xml.stylesheet.CRC32=e46c2d22 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..4d2670f --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,7 @@ +#Mon, 30 Apr 2012 02:28:02 +0300 +app-version.autoincrement=true +config.active= +deployment.counter=7 +deployment.number=0.0.6 +javadoc.preview=true +netbeans.user=C\:\\Users\\aNNiMON\\.netbeans\\7.1 diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..879f882 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,106 @@ +abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,NOKIAUI=1.0,JSR226=1.0,capuchin=1.0,MIDP=2.1,JSR229=1.1.0,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,eSWT=1.1,J2MEWS=1.0,VSCL=2.1,WMA=2.0,JSR172=1.0,JSR256=1.1,SEMC_EXT_JP8=1.0,ColorScreen,NokiaUI=1.0,OBEX=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,MascotV3=1.0,JSR75=1.0,IAPInfo=1.0,SATSAPKI=1.0,JSR184=1.1,ScreenHeight=321,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0, +all.configurations=\ +application.args= +application.description= +application.description.detail= +application.name= +application.vendor=Vendor +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 +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=TimeSpeaker.jad +dist.jar=TimeSpeaker.jar +dist.javadoc.dir=${dist.dir}/doc +dist.root.dir=dist +extra.classpath= +file.reference.TimeSpeaker-res=res +filter.exclude.tests=false +filter.excludes= +filter.more.excludes=**/overview.html,**/package.html +filter.use.standard=true +jar.compress=true +javac.debug=true +javac.deprecation=false +javac.encoding=UTF-8 +javac.optimize=false +javac.source=1.3 +javac.target=1.3 +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +libs.classpath=${file.reference.TimeSpeaker-res} +main.class= +main.class.class=applet +manifest.apipermissions= +manifest.file=manifest.mf +manifest.is.liblet=false +manifest.jad= +manifest.manifest= +manifest.midlets=MIDlet-1: TimeSpeaker, , Main\n +manifest.others=MIDlet-Vendor: Vendor\nMIDlet-Name: TimeSpeaker\nMIDlet-Version: 1.0\n +manifest.pushregistry= +name=TimeSpeaker +no.dependencies=false +nokiaS80.application.icon= +obfuscated.classes.dir=${build.dir}/obfuscated +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_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=WMA-2.0,JSR211-1.0,JSR82-1.1,JSR177-1.0,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,IAPInfo-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,eSWT-1.1,JSR75-1.0,JSR184-1.1,JSR179-1.0.1 +platform.bootclasspath=${platform.home}/lib/eswt.jar:${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/iapinfo.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/cldcapi10.jar:${platform.home}/lib/midpapi20.jar +platform.configuration=CLDC-1.0 +platform.device=SonyEricsson_JP8_240x320_Emu +platform.fat.jar=true +platform.profile=MIDP-2.0 +platform.trigger=CLDC +platform.type=UEI-1.0.1 +preprocessed.dir=${build.dir}/preprocessed +preverify.classes.dir=${build.dir}/preverified +preverify.sources.dir=${build.dir}/preverifysrc +resources.dir=resources +run.cmd.options= +run.jvmargs= +run.method=STANDARD +run.security.domain=trusted +run.use.security.domain=false +savaje.application.icon= +savaje.application.icon.focused= +savaje.application.icon.small= +savaje.application.uid=TBD +savaje.bundle.base= +savaje.bundle.debug=false +savaje.bundle.debug.port= +semc.application.caps= +semc.application.icon= +semc.application.icon.count= +semc.application.icon.splash= +semc.application.icon.splash.installonly=false +semc.application.uid=E7748318 +semc.certificate.path= +semc.private.key.password= +semc.private.key.path= +sign.alias= +sign.enabled=false +sign.keystore= +src.dir=src +use.emptyapis=true +use.preprocessor=true diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..a44e9dd --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,10 @@ + + + org.netbeans.modules.kjava.j2meproject + + + TimeSpeaker + 1.6 + + + diff --git a/res/font.ppf b/res/font.ppf new file mode 100644 index 0000000..0f76c1b Binary files /dev/null and b/res/font.ppf differ diff --git a/res/icon.png b/res/icon.png new file mode 100644 index 0000000..c4c3db3 Binary files /dev/null and b/res/icon.png differ diff --git a/res/res/1.mp3 b/res/res/1.mp3 new file mode 100644 index 0000000..d20f5c3 Binary files /dev/null and b/res/res/1.mp3 differ diff --git a/res/res/10.mp3 b/res/res/10.mp3 new file mode 100644 index 0000000..044a483 Binary files /dev/null and b/res/res/10.mp3 differ diff --git a/res/res/11.mp3 b/res/res/11.mp3 new file mode 100644 index 0000000..99c115e Binary files /dev/null and b/res/res/11.mp3 differ diff --git a/res/res/12.mp3 b/res/res/12.mp3 new file mode 100644 index 0000000..44b37d5 Binary files /dev/null and b/res/res/12.mp3 differ diff --git a/res/res/13.mp3 b/res/res/13.mp3 new file mode 100644 index 0000000..4f99884 Binary files /dev/null and b/res/res/13.mp3 differ diff --git a/res/res/14.mp3 b/res/res/14.mp3 new file mode 100644 index 0000000..bb30c6b Binary files /dev/null and b/res/res/14.mp3 differ diff --git a/res/res/15.mp3 b/res/res/15.mp3 new file mode 100644 index 0000000..0d89bb0 Binary files /dev/null and b/res/res/15.mp3 differ diff --git a/res/res/16.mp3 b/res/res/16.mp3 new file mode 100644 index 0000000..2243d5e Binary files /dev/null and b/res/res/16.mp3 differ diff --git a/res/res/17.mp3 b/res/res/17.mp3 new file mode 100644 index 0000000..2ebdb7f Binary files /dev/null and b/res/res/17.mp3 differ diff --git a/res/res/18.mp3 b/res/res/18.mp3 new file mode 100644 index 0000000..4105a79 Binary files /dev/null and b/res/res/18.mp3 differ diff --git a/res/res/19.mp3 b/res/res/19.mp3 new file mode 100644 index 0000000..b4d2c93 Binary files /dev/null and b/res/res/19.mp3 differ diff --git a/res/res/1a.mp3 b/res/res/1a.mp3 new file mode 100644 index 0000000..16de7b0 Binary files /dev/null and b/res/res/1a.mp3 differ diff --git a/res/res/2.mp3 b/res/res/2.mp3 new file mode 100644 index 0000000..12fd7ed Binary files /dev/null and b/res/res/2.mp3 differ diff --git a/res/res/20.mp3 b/res/res/20.mp3 new file mode 100644 index 0000000..c41172c Binary files /dev/null and b/res/res/20.mp3 differ diff --git a/res/res/2a.mp3 b/res/res/2a.mp3 new file mode 100644 index 0000000..b6605fc Binary files /dev/null and b/res/res/2a.mp3 differ diff --git a/res/res/3.mp3 b/res/res/3.mp3 new file mode 100644 index 0000000..30a1e20 Binary files /dev/null and b/res/res/3.mp3 differ diff --git a/res/res/30.mp3 b/res/res/30.mp3 new file mode 100644 index 0000000..ffe5f2a Binary files /dev/null and b/res/res/30.mp3 differ diff --git a/res/res/4.mp3 b/res/res/4.mp3 new file mode 100644 index 0000000..358e4cc Binary files /dev/null and b/res/res/4.mp3 differ diff --git a/res/res/40.mp3 b/res/res/40.mp3 new file mode 100644 index 0000000..b9c36de Binary files /dev/null and b/res/res/40.mp3 differ diff --git a/res/res/5.mp3 b/res/res/5.mp3 new file mode 100644 index 0000000..4450c6e Binary files /dev/null and b/res/res/5.mp3 differ diff --git a/res/res/50.mp3 b/res/res/50.mp3 new file mode 100644 index 0000000..a450047 Binary files /dev/null and b/res/res/50.mp3 differ diff --git a/res/res/6.mp3 b/res/res/6.mp3 new file mode 100644 index 0000000..adbd15a Binary files /dev/null and b/res/res/6.mp3 differ diff --git a/res/res/7.mp3 b/res/res/7.mp3 new file mode 100644 index 0000000..4558420 Binary files /dev/null and b/res/res/7.mp3 differ diff --git a/res/res/8.mp3 b/res/res/8.mp3 new file mode 100644 index 0000000..15db9c6 Binary files /dev/null and b/res/res/8.mp3 differ diff --git a/res/res/9.mp3 b/res/res/9.mp3 new file mode 100644 index 0000000..3ac5db7 Binary files /dev/null and b/res/res/9.mp3 differ diff --git a/res/res/hour1.mp3 b/res/res/hour1.mp3 new file mode 100644 index 0000000..85cf6df Binary files /dev/null and b/res/res/hour1.mp3 differ diff --git a/res/res/hour2.mp3 b/res/res/hour2.mp3 new file mode 100644 index 0000000..b3ccf22 Binary files /dev/null and b/res/res/hour2.mp3 differ diff --git a/res/res/hour3.mp3 b/res/res/hour3.mp3 new file mode 100644 index 0000000..8c5d5c0 Binary files /dev/null and b/res/res/hour3.mp3 differ diff --git a/res/res/minute1.mp3 b/res/res/minute1.mp3 new file mode 100644 index 0000000..9fbce3f Binary files /dev/null and b/res/res/minute1.mp3 differ diff --git a/res/res/minute2.mp3 b/res/res/minute2.mp3 new file mode 100644 index 0000000..b35aa90 Binary files /dev/null and b/res/res/minute2.mp3 differ diff --git a/res/res/minute3.mp3 b/res/res/minute3.mp3 new file mode 100644 index 0000000..b21645a Binary files /dev/null and b/res/res/minute3.mp3 differ diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..bff0ed0 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,33 @@ +/* + * aNNiMON 2012 + * For more info visit http://annimon.com/ + */ + +import javax.microedition.lcdui.Display; +import javax.microedition.midlet.MIDlet; + +/** + * @author aNNiMON + */ +public class Main extends MIDlet { + + public Display dsp; + public static Main midlet; + private TimeCanvas canv; + + public Main() { + midlet = Main.this; + dsp = Display.getDisplay(Main.this); + canv = new TimeCanvas(); + } + + public void startApp() { + dsp.setCurrent(canv); + } + + public void pauseApp() {} + + public void destroyApp(boolean ex) { + notifyDestroyed(); + } +} diff --git a/src/Sound.java b/src/Sound.java new file mode 100644 index 0000000..c7b5176 --- /dev/null +++ b/src/Sound.java @@ -0,0 +1,52 @@ +import java.io.InputStream; +import javax.microedition.media.Manager; +import javax.microedition.media.Player; +import javax.microedition.media.PlayerListener; + +/* + * aNNiMON 2012 + * For more info visit http://annimon.com/ + */ + +/** + * + * @author aNNiMON + */ +public class Sound implements PlayerListener { + + private Player plr; + private String[] soundsToPlay; + private int current; + + public Sound(String[] soundsToPlay) { + this.soundsToPlay = soundsToPlay; + current = 0; + plr = null; + } + + public void speak() { + if (plr != null) { + plr.close(); + } + try { + System.out.println(soundsToPlay[current]); + InputStream is = getClass().getResourceAsStream("/res/"+soundsToPlay[current]+".mp3"); + plr = Manager.createPlayer(is, "audio/mpeg"); + plr.realize(); + plr.prefetch(); + plr.addPlayerListener(this); + plr.start(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void playerUpdate(Player player, String event, Object eventData) { + if (event.equals(PlayerListener.END_OF_MEDIA)) { + current++; + if (current < soundsToPlay.length) speak(); + else Main.midlet.destroyApp(true); + } + } + +} diff --git a/src/TimeCanvas.java b/src/TimeCanvas.java new file mode 100644 index 0000000..487bc81 --- /dev/null +++ b/src/TimeCanvas.java @@ -0,0 +1,43 @@ +/* + * aNNiMON 2012 + * For more info visit http://annimon.com/ + */ + +import com.annimon.ppf.PPFont; +import javax.microedition.lcdui.Canvas; +import javax.microedition.lcdui.Font; +import javax.microedition.lcdui.Graphics; + +/** + * @author aNNiMON + */ +public class TimeCanvas extends Canvas { + + private int w, h; + private int fontWidth, fontHeight; + private PPFont font; + private Sound sound; + private String time; + + public TimeCanvas() { + setFullScreenMode(true); + w = getWidth(); + h = getHeight(); + + time = TimeUtil.getTime(); + + font = new PPFont("/font.ppf"); + fontWidth = font.getTextWidth(time); + fontHeight = font.getFontHeight(true); + + String[] names = TimeUtil.getStringsToSpeak(); + sound = new Sound(names); + sound.speak(); + } + + public void paint(Graphics g) { + g.setColor(0xFFFFFF); + g.fillRect(0, 0, w, h); + font.drawText(g, w/2-fontWidth/2, h/2-fontHeight/2, time); + } +} \ No newline at end of file diff --git a/src/TimeUtil.java b/src/TimeUtil.java new file mode 100644 index 0000000..2d595f8 --- /dev/null +++ b/src/TimeUtil.java @@ -0,0 +1,110 @@ + +import java.util.Calendar; +import java.util.Vector; + +/* + * aNNiMON 2012 + * For more info visit http://annimon.com/ + */ + +/** + * + * @author aNNiMON + */ +public class TimeUtil { + + private static final int[] NORMAL_1_TO_20 = { + 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 + }; + + private static final int[] NAMES_TEN = { + 10, 20, 30, 40, 50 + }; + + private static final String[] NAMES_1_2 = { + "1a", "2a" + }; + + private static final String[] NAMES_HOUR = { + "hour1", "hour2", "hour3" + }; + + private static final String[] NAMES_MINUTE = { + "minute1", "minute2", "minute3" + }; + + /** + * Получить время + * @return строка с временем вида: HH:MM + */ + public static String getTime() { + StringBuffer sb = new StringBuffer(); + Calendar cal = Calendar.getInstance(); + // Час + int 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 String[] getStringsToSpeak() { + Vector audioNames = new Vector(); + Calendar cal = Calendar.getInstance(); + // Час + int hour = cal.get(Calendar.HOUR_OF_DAY); + appendHourString(audioNames, hour); + // Минута + int minute = cal.get(Calendar.MINUTE); + appendMinuteString(audioNames, minute); + + String[] out = new String[audioNames.size()]; + audioNames.copyInto(out); + return out; + } + + private static void appendHourString(Vector audioNames, int hour) { + int minHour = Math.min(hour, 20); + audioNames.addElement(String.valueOf(NORMAL_1_TO_20[minHour])); // 0..20 + if (hour > 20) audioNames.addElement(String.valueOf(NORMAL_1_TO_20[hour % 20])); //21..23 + // Час + if ( (hour == 1) || (hour == 21) ) audioNames.addElement(NAMES_HOUR[0]); + else if ( ((1 < hour) && (hour <= 4)) || ((21 < hour) && (hour <= 23)) ) audioNames.addElement(NAMES_HOUR[1]); + else audioNames.addElement(NAMES_HOUR[2]); + } + + private static void appendMinuteString(Vector audioNames, int minute) { + // Ноль минут нет + if (minute == 0) return; + + // От пяти до двадцати одинаково + if ((5 <= minute) && (minute <= 20) ) { + audioNames.addElement(String.valueOf(NORMAL_1_TO_20[minute])); + audioNames.addElement(NAMES_MINUTE[0]); + return; + } + + // Десятки минут + int tenMinute = minute / 10; + if (tenMinute != 0) audioNames.addElement(String.valueOf(NAMES_TEN[tenMinute - 1])); + + int modMinute = minute % 10; + // Одна минута / две минуты + if ( (modMinute == 1) || (modMinute == 2)) { + audioNames.addElement(NAMES_1_2[modMinute - 1]); + audioNames.addElement(NAMES_MINUTE[modMinute]); + return; + } + // без десятков + if (modMinute != 0) audioNames.addElement(String.valueOf(NORMAL_1_TO_20[modMinute])); + + // x2, x3, x4 минуты + if ( (2 <= modMinute) && (modMinute <= 4) ) audioNames.addElement(NAMES_MINUTE[2]); + else audioNames.addElement(NAMES_MINUTE[0]); // минут + } +} diff --git a/src/com/annimon/ppf/Char.java b/src/com/annimon/ppf/Char.java new file mode 100644 index 0000000..f7202c0 --- /dev/null +++ b/src/com/annimon/ppf/Char.java @@ -0,0 +1,18 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package com.annimon.ppf; + +import javax.microedition.lcdui.Image; + +/** + * + * @author aNNiMON + */ +public class Char { + + public Image charImage; + short x, y, xx; +} diff --git a/src/com/annimon/ppf/PPFont.java b/src/com/annimon/ppf/PPFont.java new file mode 100644 index 0000000..33241fb --- /dev/null +++ b/src/com/annimon/ppf/PPFont.java @@ -0,0 +1,155 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package com.annimon.ppf; + +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Hashtable; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * + * @author aNNiMON + */ +public class PPFont { + + public Hashtable ht; + public boolean isModificated; + private String fontName; + private short fontHeight; + private short startIndex, endIndex; + private char[] charTable; + private int textcolor; + + /** + * Конструктор класса + * @param path - путь к ppf-шрифту + */ + public PPFont(String path) { + try { + InputStream is = getClass().getResourceAsStream(path); + DataInputStream dis = new DataInputStream(is); + //Проверка сигнатуры + if (dis.readInt() != 0x50504600) return; + fontName = dis.readUTF();//Название шрифта + fontHeight = dis.readShort();//размер шрифта + startIndex = dis.readShort();//начальный символ + endIndex = dis.readShort();//конечный символ + charTable = new char[endIndex-startIndex+1]; + ht = new Hashtable(charTable.length); + for (int i = startIndex; i <= endIndex; i++) { + //Создаем объект для хранения данных + Char co = new Char(); + //Читаем символ + char t = charTable[i-startIndex] = dis.readChar(); + Character ch = new Character(t); + //Размеры символа и позиции + short width = dis.readShort(); + short height = dis.readShort(); + short x = dis.readShort(); + short y = dis.readShort(); + short xx = dis.readShort();//m.getAdvanceX() + int[] rgb = new int[width*height]; + for (int j = 0; j < rgb.length; j++) { + rgb[j] = dis.readBoolean() ? 0xFF000000 : 0;//если true - цвет чёрный + } + //Записываем переменные в объект + co.charImage = Image.createRGBImage(rgb, width, height, true); + co.x = x; + co.y = y; + co.xx = xx; + ht.put(ch, co); + } + dis.close(); + textcolor = 0xFF000000; + isModificated = false; + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + /** + * Изменить цвет шрифта + * @param newcolor - новый цвет + */ + public void setColor(int newcolor) { + if(newcolor==textcolor || isModificated) return;//предотвращение повторной установки цвета + if(newcolor==0) newcolor=0x10;//предотвращение установки цвета фона + for (int i = startIndex; i <= endIndex; i++) { + Character o = new Character(charTable[i-startIndex]); + //Получаем объект Char + Char co = (Char) ht.get(o); + Image charImage = co.charImage; + + int width = charImage.getWidth(); + int height = charImage.getHeight(); + + int length = width * height; + int[] rgb = new int[length]; + charImage.getRGB(rgb, 0, width, 0, 0, width, height); + for (int pos = 0; pos < length; pos++) { + if (rgb[pos] != 0) { + rgb[pos] = newcolor; + } + } + //Записываем переменные в объект + co.charImage = Image.createRGBImage(rgb, width, height, true); + + ht.put(o, co); + } + textcolor = newcolor; + } + + /** + * Отрисовка текста + * @param g - Graphics + * @param x - x-координата левого верхнего угла + * @param y - y-координата левого верхнего угла + * @param s - текст + * @return - ширина строки + */ + public int drawText(Graphics g, int x, int y, String s) { + int wdh = 0; + int length = s.length(); + int temp = (fontHeight*3)/4; + for (int i = 0; i < length; i++) { + Char co = (Char) ht.get(new Character(s.charAt(i))); + if (co != null && co.charImage != null) { + if(g!=null) g.drawImage(co.charImage, x + co.x + wdh, y + co.y + temp, 20); + wdh += co.xx; + } + } + return wdh; + } + + /** + * Ширина строки + * @param s - текст + * @return - ширина строки s + */ + public int getTextWidth(String s) { + return drawText(null, 0, 0, s); + } + + /** + * Высота шрифта + * @param absolute - true - высота шрифта, false - высота букв + * @return высота шрифта/букв + */ + public short getFontHeight(boolean absolute) { + return (short) (absolute ? fontHeight : (fontHeight * 3) / 4); + } + + /** + * Получение названия шрифта + * @return - имя шрифта + */ + public String getFontName() { + return fontName; + } +} \ No newline at end of file