7.0
@ -96,6 +96,15 @@
|
||||
<condition property="app-version.autoincrement.trigger">
|
||||
<istrue value="${app-version.autoincrement}"/>
|
||||
</condition>
|
||||
<condition property="debug.timeout" value="30000">
|
||||
<or>
|
||||
<equals arg1="${debugger.timeout}" arg2="" trim="true"/>
|
||||
<not>
|
||||
<isset property="debugger.timeout"/>
|
||||
</not>
|
||||
</or>
|
||||
</condition>
|
||||
<property name="debug.timeout" value="${debugger.timeout}"/>
|
||||
<nb-overrideproperty name="buildsystem.baton" value="${src.dir}"/>
|
||||
</target>
|
||||
<!--cldc-init-->
|
||||
@ -164,47 +173,13 @@
|
||||
<equals arg1="${deployment.number}" arg2="" trim="true"/>
|
||||
</condition>
|
||||
<fail if="application.version.invalid" message="Property deployment.number must not be empty and must contain version in format %d.%d.%d!"/>
|
||||
</target>
|
||||
<!--ricoh-init-->
|
||||
<target name="ricoh-pre-init" if="cdc-platform.trigger">
|
||||
<condition property="ricoh-platform.trigger">
|
||||
<equals arg1="ricoh" arg2="${platform.type}" casesensitive="false"/>
|
||||
<condition property="sign.jar.trigger" value="true">
|
||||
<and>
|
||||
<isset property="cdc-platform.trigger"/>
|
||||
<istrue value="${sign.enabled}"/>
|
||||
</and>
|
||||
</condition>
|
||||
</target>
|
||||
<target name="ricoh-init" depends="ricoh-pre-init" if="ricoh-platform.trigger">
|
||||
<available property="jcifs" classname="jcifs.smb.SmbFile" classpath="${libs.RicohAntTools.classpath}"/>
|
||||
<condition property="no.vendor.name" value="true">
|
||||
<equals arg1="${application.vendor}" arg2="" trim="true"/>
|
||||
</condition>
|
||||
<condition property="ricoh.dalp.install.mode" value="auto" else="manual">
|
||||
<istrue value="${ricoh.dalp.install.mode.auto}"/>
|
||||
</condition>
|
||||
<condition property="ricoh.dalp.display-mode.type" value="COLOR" else="MONO">
|
||||
<istrue value="${ricoh.dalp.display-mode.color}"/>
|
||||
</condition>
|
||||
<property name="xml.dir" value="${build.dir}/dalp"/>
|
||||
<property name="xlet.dalp" value="${application.name}.dalp"/>
|
||||
<property name="xlet.dalp.name-only" value="${application.name}.dalp"/>
|
||||
<property name="deploy.dir" value="${dist.dir}/deploy"/>
|
||||
<property name="rideploy.zip" value="${dist.dir}/${application.name}.zip"/>
|
||||
<property name="ricoh.dalp.is-managed" value="true"/>
|
||||
<property name="ricoh.dalp.information.is-icon-used" value="true"/>
|
||||
<property name="ricoh.platform.target.version" value="2.0"/>
|
||||
<property name="ricoh.dalp.version" value="${deployment.number}"/>
|
||||
<property name="ricoh.dalp.application-desc.visible" value="true"/>
|
||||
<property name="ricoh.dalp.install.destination" value="hdd"/>
|
||||
<property name="ricoh.dalp.install.work-dir" value="hdd"/>
|
||||
<property name="ricoh.dalp.information.abbreviation" value="RICOH"/>
|
||||
<taskdef name="taskIf" classname="ricoh.ant.ConditionalTask" classpath="${libs.ricoh-ant-utils.classpath}"/>
|
||||
<taskdef name="dalp" classname="org.netbeans.modules.j2me.cdc.project.ricoh.DalpBuilder" classpath="${libs.ricoh-ant-utils.classpath}"/>
|
||||
<property name="dalp.dist" value="${build.dir}/dalp/${application.name}.dalp"/>
|
||||
<property name="deployment.dir" location="${dist.dir}"/>
|
||||
<patternset id="deployment.patternset">
|
||||
<include name="${dist.jar}"/>
|
||||
<include name="${application.name}.dalp"/>
|
||||
<include name="lib/*"/>
|
||||
</patternset>
|
||||
</target>
|
||||
<!--semc-init-->
|
||||
<target name="semc-pre-init" if="cdc-platform.trigger">
|
||||
<condition property="semc-platform.trigger">
|
||||
@ -285,6 +260,13 @@
|
||||
</condition>
|
||||
</target>
|
||||
<target name="sjmc-init" depends="sjmc-pre-init" if="sjmc-platform.trigger"/>
|
||||
<!--ojec-init-->
|
||||
<target name="ojec-pre-init" if="cdc-platform.trigger">
|
||||
<condition property="ojec-platform.trigger">
|
||||
<equals arg1="ojec" arg2="${platform.type}" casesensitive="false"/>
|
||||
</condition>
|
||||
</target>
|
||||
<target name="ojec-init" depends="ojec-pre-init" if="ojec-platform.trigger"/>
|
||||
<!--cdc-hi-init-->
|
||||
<target name="cdc-hi-pre-init" if="cdc-platform.trigger">
|
||||
<condition property="cdc-hi-platform.trigger">
|
||||
@ -312,22 +294,10 @@
|
||||
<include name="${dist.jar}"/>
|
||||
</patternset>
|
||||
</target>
|
||||
<!--nsicom-init-->
|
||||
<target name="nsicom-pre-init" if="cdc-platform.trigger">
|
||||
<condition property="nsicom-platform.trigger">
|
||||
<equals arg1="nsicom" arg2="${platform.type}" casesensitive="false"/>
|
||||
</condition>
|
||||
</target>
|
||||
<target name="nsicom-init" depends="nsicom-pre-init" if="nsicom-platform.trigger">
|
||||
<property name="deployment.dir" location="${dist.dir}"/>
|
||||
<patternset id="deployment.patternset">
|
||||
<include name="${dist.jar}"/>
|
||||
</patternset>
|
||||
</target>
|
||||
<!--init-->
|
||||
<target name="pre-init"/>
|
||||
<target name="post-init"/>
|
||||
<target name="init" depends="pre-init,load-properties,basic-init,cldc-init,cdc-init,ricoh-init,semc-init,savaje-init,sjmc-init,cdc-hi-init,nokiaS80-init,nsicom-init,post-init"/>
|
||||
<target name="init" depends="pre-init,load-properties,basic-init,cldc-init,cdc-init,semc-init,savaje-init,sjmc-init,ojec-init,cdc-hi-init,nokiaS80-init,post-init"/>
|
||||
<!--conditional clean-->
|
||||
<target name="conditional-clean-init">
|
||||
<uptodate property="no.clean.before.build" targetfile="${build.dir}/.timestamp">
|
||||
@ -559,9 +529,10 @@
|
||||
<target name="do-extra-libs" if="extra.classpath">
|
||||
<property name="dist.lib.dir" value="${dist.dir}/lib"/>
|
||||
<mkdir dir="${dist.lib.dir}"/>
|
||||
<copypath destdir="${dist.lib.dir}" path="${extra.classpath}">
|
||||
<copy todir="${dist.lib.dir}">
|
||||
<path path="${extra.classpath}"/>
|
||||
<flattenmapper/>
|
||||
</copypath>
|
||||
</copy>
|
||||
</target>
|
||||
<!--nokiaS80-manifest-->
|
||||
<target name="nokiaS80-prepare-j9" if="nokiaS80-platform.trigger">
|
||||
@ -640,14 +611,6 @@
|
||||
<fileset dir="${buildsystem.baton}"/>
|
||||
</jar>
|
||||
</target>
|
||||
<!--nsicom-create-manifest-->
|
||||
<target name="nsicom-create-manifest" if="nsicom-platform.trigger">
|
||||
<jar jarfile="${dist.dir}/${dist.jar}" compress="${jar.compress}" update="true">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
<!--do-jar-no-manifest-->
|
||||
<target name="do-jar-no-manifest" unless="manifest.available">
|
||||
<dirname file="${dist.dir}/${dist.jar}" property="dist.jar.dir"/>
|
||||
@ -660,78 +623,8 @@
|
||||
<target name="update-jad" if="cldc-platform.trigger">
|
||||
<nb-jad jadfile="${dist.dir}/${dist.jad}" jarfile="${dist.dir}/${dist.jar}" url="${dist.jar}" sign="${sign.enabled}" keystore="${sign.keystore}" keystorepassword="${sign.keystore.password}" alias="${sign.alias}" aliaspassword="${sign.alias.password}" encoding="UTF-8"/>
|
||||
</target>
|
||||
<!--ricoh-init-dalp-->
|
||||
<target name="ricoh-init-dalp" if="ricoh-platform.trigger">
|
||||
<property name="ricoh.application.telephone" value=""/>
|
||||
<property name="ricoh.application.fax" value=""/>
|
||||
<property name="ricoh.application.email" value=""/>
|
||||
<condition property="no.unmanaged.dalp">
|
||||
<and>
|
||||
<isfalse value="${ricoh.dalp.is-managed}"/>
|
||||
<not>
|
||||
<available file="./${application.name}.dalp"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<fail if="no.unmanaged.dalp" message="Dalp file ${application.name}.dalp is required in project directory when DALP management is set to off."/>
|
||||
<condition property="no.vendor.name" value="true">
|
||||
<equals arg1="${application.vendor}" arg2="" trim="true"/>
|
||||
</condition>
|
||||
<condition property="ricoh.icon.invalid" value="true">
|
||||
<or>
|
||||
<contains string="${ricoh.application.icon}" substring="$${"/>
|
||||
<equals arg1="${ricoh.application.icon}" arg2="" trim="true"/>
|
||||
</or>
|
||||
</condition>
|
||||
<mkdir dir="${dist.dir}/lib"/>
|
||||
</target>
|
||||
<!--ricoh-add-app-icon-->
|
||||
<target name="ricoh-add-app-icon" depends="ricoh-init-dalp" if="ricoh-platform.trigger" unless="ricoh.icon.invalid">
|
||||
<pathconvert property="icon.name" pathsep=" ">
|
||||
<path path="${ricoh.application.icon}"/>
|
||||
<chainedmapper>
|
||||
<flattenmapper/>
|
||||
<globmapper from="*" to="*"/>
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
<jar jarfile="${dist.jar}" compress="${jar.compress}" update="true">
|
||||
<fileset file="${ricoh.application.icon}"/>
|
||||
</jar>
|
||||
</target>
|
||||
<!--ricoh-build-dalp-with-icon-->
|
||||
<target name="ricoh-build-dalp-with-icon" depends="ricoh-add-app-icon" if="ricoh-platform.trigger" unless="ricoh.icon.invalid">
|
||||
<mkdir dir="${build.dir}/dalp/"/>
|
||||
<taskIf if="ricoh.dalp.is-managed" value="true">
|
||||
<dalp file="${dalp.dist}" iconname="${icon.name}">
|
||||
<fileset dir="${dist.dir}/lib"/>
|
||||
</dalp>
|
||||
<echo message="Managed dalp file ${dalp.dist} created w/ icon"/>
|
||||
</taskIf>
|
||||
<taskIf if="ricoh.dalp.is-managed" value="false">
|
||||
<copy tofile="${dalp.dist}">
|
||||
<fileset file="./${application.name}.dalp"/>
|
||||
</copy>
|
||||
<echo message="Non-managed dalp file ${dalp.dist} w/ icon imported"/>
|
||||
</taskIf>
|
||||
</target>
|
||||
<!--ricoh-build-dalp-without-icon-->
|
||||
<target name="ricoh-build-dalp-without-icon" if="ricoh.icon.invalid">
|
||||
<mkdir dir="${build.dir}/dalp/"/>
|
||||
<taskIf if="ricoh.dalp.is-managed" value="true">
|
||||
<dalp file="${dalp.dist}">
|
||||
<fileset dir="${dist.dir}/lib"/>
|
||||
</dalp>
|
||||
<echo message="Managed dalp file ${dalp.dist} created w/o icon"/>
|
||||
</taskIf>
|
||||
<taskIf if="ricoh.dalp.is-managed" value="false">
|
||||
<copy tofile="${dalp.dist}">
|
||||
<fileset file="./${application.name}.dalp"/>
|
||||
</copy>
|
||||
<echo message="Non-managed dalp file ${dalp.dist} w/o icon imported"/>
|
||||
</taskIf>
|
||||
</target>
|
||||
<target name="ricoh-build-dalp" depends="ricoh-build-dalp-with-icon,ricoh-build-dalp-without-icon" if="ricoh-platform.trigger">
|
||||
<copy todir="${dist.dir}" file="${dalp.dist}" overwrite="true"/>
|
||||
<target name="sign-jar" if="sign.jar.trigger">
|
||||
<signjar jar="${dist.dir}/${dist.jar}" alias="${sign.alias}" keystore="${sign.keystore}" storepass="${sign.keystore.password}" keypass="${sign.alias.password}"/>
|
||||
</target>
|
||||
<!--savaje-build-jnlp-->
|
||||
<target name="savaje-prepare-icon" if="savaje-platform.trigger" unless="savaje.icon.invalid">
|
||||
@ -766,7 +659,7 @@
|
||||
<!--jar-->
|
||||
<target name="pre-jar"/>
|
||||
<target name="post-jar"/>
|
||||
<target name="jar" depends="preverify,pre-jar,set-password,create-jad,do-extra-libs,nokiaS80-create-manifest,jad-jsr211-properties,semc-build-j9,do-jar,nsicom-create-manifest,do-jar-no-manifest,update-jad,ricoh-build-dalp,savaje-build-jnlp,post-jar" description="Build jar and application descriptor."/>
|
||||
<target name="jar" depends="preverify,pre-jar,set-password,create-jad,do-extra-libs,nokiaS80-create-manifest,jad-jsr211-properties,semc-build-j9,do-jar,do-jar-no-manifest,update-jad,sign-jar,savaje-build-jnlp,post-jar" description="Build jar and application descriptor."/>
|
||||
<!--override-jad-->
|
||||
<target name="override-jad" if="override.jarurl.trigger">
|
||||
<property name="deployment.jarurl" value="${dist.jar}"/>
|
||||
@ -888,19 +781,6 @@
|
||||
<target name="cldc-run" if="cldc-platform.trigger">
|
||||
<nb-run jadfile="${dist.dir}/${dist.jad}" jarfile="${dist.dir}/${dist.jar}" jadurl="${dist.jad.url}" device="${platform.device}" platformhome="${platform.home}" platformtype="${platform.type}" execmethod="${run.method}" securitydomain="${evaluated.run.security.domain}" commandline="${platform.runcommandline}" classpath="${platform.bootclasspath}:${dist.dir}/${dist.jar}" cmdoptions="${run.cmd.options}"/>
|
||||
</target>
|
||||
<!--ricoh-run-->
|
||||
<target name="ricoh-run" if="ricoh-platform.trigger">
|
||||
<copy todir="${platform.home}/mnt/sd3/sdk/dsdk/dist/${ricoh.application.uid}" overwrite="true">
|
||||
<fileset dir="${dist.dir}">
|
||||
<patternset refid="deployment.patternset"/>
|
||||
</fileset>
|
||||
<flattenmapper/>
|
||||
</copy>
|
||||
<ant antfile="${platform.home}/startemulator.xml" target="start_emulator" dir="${platform.home}">
|
||||
<property name="emulator.skin" value="WVGA.xml"/>
|
||||
<property name="emulator.autolaunchid" value="${ricoh.application.uid}"/>
|
||||
</ant>
|
||||
</target>
|
||||
<!--semc-run-and-debug-prepare-targets-->
|
||||
<target name="semc-icon-assembly" if="semc-platform.trigger" unless="semc.icon.invalid">
|
||||
<copy file="${semc.application.icon}" tofile="${platform.home}/epoc32/release/winscw/udeb/z/Resource/Apps/${semc.application.uid}.mbm" failonerror="false"/>
|
||||
@ -951,6 +831,15 @@
|
||||
</fileset>
|
||||
</sjmcEmulatorExec>
|
||||
</target>
|
||||
<!--ojec-run-->
|
||||
<target name="ojec-run" if="ojec-platform.trigger">
|
||||
<taskdef name="ojecEmulatorExec" classname="org.netbeans.modules.j2me.cdc.project.ojec.OJECToolkitEmulatorExecTask" classpath="${libs.ojec-ant-utils.classpath}"/>
|
||||
<ojecEmulatorExec home="${platform.home}" mainclass="${main.class}" args="${application.args}" jvmargs="${run.cmd.options}" device="${platform.device}" profile="${platform.profile}" xlet="${main.class.xlet}" applet="${main.class.applet}">
|
||||
<fileset dir="${dist.dir}">
|
||||
<exclude name="javadoc/**"/>
|
||||
</fileset>
|
||||
</ojecEmulatorExec>
|
||||
</target>
|
||||
<!--nokiaS80-run-->
|
||||
<target name="nokiaS80-run" if="nokiaS80-platform.trigger">
|
||||
<mkdir dir="${platform.home}/epoc32/wins/c/PP_Applications"/>
|
||||
@ -962,17 +851,14 @@
|
||||
</fileset>
|
||||
</nokiaexec>
|
||||
</target>
|
||||
<!--nsicom-run-->
|
||||
<target name="nsicom-run" if="nsicom-platform.trigger">
|
||||
<nsicomExecDeploy home="${platform.home}" mainclass="${main.class}" args="${application.args}" jvmargs="${run.jvmargs}" device="${platform.device}" profile="${platform.profile}" xlet="${main.class.xlet}" applet="${main.class.applet}" verbose="${nsicom.application.runverbose}" hostip="${nsicom.application.monitorhost}" runondevice="${nsicom.application.runremote}" remotevmlocation="${nsicom.remotevm.location}" remoteDataLocation="${nsicom.remoteapp.location}">
|
||||
<fileset dir="${dist.dir}">
|
||||
<exclude name="javadoc/**"/>
|
||||
</fileset>
|
||||
</nsicomExecDeploy>
|
||||
</target>
|
||||
<!--cdc-hi-run-->
|
||||
<target name="-pre-cdc-hi-run" if="cdc-hi-platform.trigger"/>
|
||||
<target name="-cdc-hi-run" if="cdc-hi-platform.trigger">
|
||||
<fail message="Main class is not set!">
|
||||
<condition>
|
||||
<equals arg1="${main.class}" arg2=""/>
|
||||
</condition>
|
||||
</fail>
|
||||
<exec executable="${platform.home}/bin/emulator">
|
||||
<arg value="-cp"/>
|
||||
<arg value="${basedir}/${dist.dir}/${dist.jar}"/>
|
||||
@ -1001,8 +887,8 @@
|
||||
</target>
|
||||
<!--run-->
|
||||
<target name="pre-run"/>
|
||||
<target name="run" depends="jar,pre-run,open-netmon,cldc-run,ricoh-run,semc-run,savaje-run,sjmc-run,nokiaS80-run,nsicom-run,cdc-hi-run,open-profiler" description="Run MIDlet suite."/>
|
||||
<target name="run-no-build" depends="init,pre-run,open-netmon,cldc-run,ricoh-run,semc-run,savaje-run,sjmc-run,nokiaS80-run,nsicom-run,cdc-hi-run,open-profiler" description="Quick Run already built MIDlet suite."/>
|
||||
<target name="run" depends="jar,pre-run,open-netmon,cldc-run,semc-run,savaje-run,sjmc-run,ojec-run,nokiaS80-run,cdc-hi-run,open-profiler" description="Run MIDlet suite."/>
|
||||
<target name="run-no-build" depends="init,pre-run,open-netmon,cldc-run,semc-run,savaje-run,sjmc-run,ojec-run,nokiaS80-run,cdc-hi-run,open-profiler" description="Quick Run already built MIDlet suite."/>
|
||||
<!--cldc-debug-->
|
||||
<target name="cldc-debug" if="cldc-platform.trigger">
|
||||
<parallel>
|
||||
@ -1013,28 +899,6 @@
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
<!--ricoh-debug-->
|
||||
<target name="ricoh-debug" if="ricoh-platform.trigger">
|
||||
<copy todir="${platform.home}/mnt/sd3/sdk/dsdk/dist/${ricoh.application.uid}" overwrite="true">
|
||||
<fileset dir="${dist.dir}">
|
||||
<patternset refid="deployment.patternset"/>
|
||||
</fileset>
|
||||
<flattenmapper/>
|
||||
</copy>
|
||||
<parallel>
|
||||
<ant antfile="${platform.home}/startemulator_debug.xml" target="debug_emulator" dir="${platform.home}">
|
||||
<property name="emulator.skin" value="WVGA.xml"/>
|
||||
<property name="emulator.autolaunchid" value="${ricoh.application.uid}"/>
|
||||
</ant>
|
||||
<sequential>
|
||||
<sleep seconds="5"/>
|
||||
<property name="jpda.port" value="8000"/>
|
||||
<property name="debug.period" value="3000"/>
|
||||
<property name="debug.timeout" value="30000"/>
|
||||
<antcall target="nbdebug" inheritall="true" inheritrefs="true"/>
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
<!--semc-debug-->
|
||||
<!--semc-build-j9-debug-->
|
||||
<target name="semc-build-j9-debug" if="semc-platform.trigger">
|
||||
@ -1085,6 +949,21 @@
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
<!--ojec-debug-->
|
||||
<target name="ojec-debug" if="ojec-platform.trigger">
|
||||
<taskdef name="ojecEmulatorExec" classname="org.netbeans.modules.j2me.cdc.project.ojec.OJECToolkitEmulatorExecTask" classpath="${libs.ojec-ant-utils.classpath}"/>
|
||||
<parallel>
|
||||
<ojecEmulatorExec home="${platform.home}" mainclass="${main.class}" args="${application.args}" jvmargs="${run.cmd.options}" device="${platform.device}" profile="${platform.profile}" xlet="${main.class.xlet}" applet="${main.class.applet}" debug="true" debuggeraddressproperty="jpda.port">
|
||||
<fileset dir="${dist.dir}">
|
||||
<exclude name="javadoc/**"/>
|
||||
</fileset>
|
||||
</ojecEmulatorExec>
|
||||
<sequential>
|
||||
<sleep seconds="1"/>
|
||||
<antcall target="nbdebug"/>
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
<!--cdc-hi-debug-->
|
||||
<target name="-pre-cdc-hi-debug" if="cdc-hi-platform.trigger"/>
|
||||
<target name="-cdc-hi-debug" if="cdc-hi-platform.trigger">
|
||||
@ -1099,8 +978,10 @@
|
||||
<arg value="-Xrunjdwp:transport=dt_socket,address=${active.debug.port},server=y,suspend=y"/>
|
||||
<arg value="-Xdebug"/>
|
||||
</exec>
|
||||
<sequential>
|
||||
<property name="debug.delay" value="500"/>
|
||||
<nb-mobility-debug address="${active.debug.port}" name="${app.codename}" delay="${debug.delay}" timeout="30000" period="2000"/>
|
||||
<nb-mobility-debug address="${active.debug.port}" name="${app.codename}" delay="${debug.delay}" timeout="${debug.timeout}" period="2000"/>
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
<target name="-post-cdc-hi-debug" if="cdc-hi-platform.trigger"/>
|
||||
@ -1123,19 +1004,15 @@
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
<!--nsicom-debug-->
|
||||
<target name="nsicom-debug" if="nsicom-platform.trigger">
|
||||
<fail message="Debugging is not supported in this NSIcom VM version. Use monitoring facility instead!"/>
|
||||
</target>
|
||||
<!--debug-->
|
||||
<target name="remove-timestamp">
|
||||
<delete file="$/.timestamp"/>
|
||||
</target>
|
||||
<target name="pre-debug"/>
|
||||
<target name="debug" description="Debug project." depends="clean,jar,remove-timestamp,pre-debug,cldc-debug,ricoh-debug,semc-debug,savaje-debug,sjmc-debug,cdc-hi-debug,nokiaS80-debug,nsicom-debug"/>
|
||||
<target name="debug" description="Debug project." depends="clean,jar,remove-timestamp,pre-debug,cldc-debug,semc-debug,savaje-debug,sjmc-debug,ojec-debug,cdc-hi-debug,nokiaS80-debug"/>
|
||||
<target name="nbdebug" description="Start NetBeans debugger" if="netbeans.home">
|
||||
<property name="debug.delay" value="5000"/>
|
||||
<nb-mobility-debug address="${jpda.port}" name="${app.codename}" delay="${debug.delay}" timeout="30000" period="2000"/>
|
||||
<nb-mobility-debug address="${jpda.port}" name="${app.codename}" delay="${debug.delay}" timeout="${debug.timeout}" period="2000"/>
|
||||
</target>
|
||||
<target name="debug-run-base" depends="cldc-debug-run,cdc-hi-debug-run"/>
|
||||
<target name="-pre-cldc-debug-run" if="cldc-platform.trigger"/>
|
||||
@ -1152,6 +1029,11 @@
|
||||
<target name="cldc-debug-run" if="cldc-platform.trigger" depends="-pre-cldc-debug-run, -cldc-debug-run, -post-cldc-debug-run"/>
|
||||
<target name="-pre-cdc-hi-debug-run" if="cdc-hi-platform.trigger"/>
|
||||
<target name="-cdc-hi-debug-run" depends="init,jar" if="cdc-hi-platform.trigger">
|
||||
<fail message="Main class is not set!">
|
||||
<condition>
|
||||
<equals arg1="${main.class}" arg2=""/>
|
||||
</condition>
|
||||
</fail>
|
||||
<echo> Starting emulator with port number ${active.debug.port} </echo>
|
||||
<exec executable="${platform.home}/bin/emulator">
|
||||
<arg value="-cp"/>
|
||||
@ -1216,12 +1098,6 @@
|
||||
<target name="clean-j9" if="j9.dist">
|
||||
<delete file="${j9.dist}"/>
|
||||
</target>
|
||||
<target name="clean-ricoh" if="ricoh-platform.trigger">
|
||||
<delete dir="${platform.home}/mnt/sd3/sdk/dsdk/dist/${ricoh.application.uid}"/>
|
||||
<delete dir="${build.dir}/dalp"/>
|
||||
<delete file="${dist.dir}/${application.name}.dalp"/>
|
||||
<delete dir="${dist.dir}/lib"/>
|
||||
</target>
|
||||
<target name="clean-semc" if="semc-platform.trigger">
|
||||
<delete dir="${dist.dir}" includes="*.sis,*.SIS"/>
|
||||
<delete dir="${platform.home}/epoc32/tools/ppro-custom-launcher/output/win32/PProLauncher${semc.application.uid}"/>
|
||||
@ -1245,6 +1121,9 @@
|
||||
<target name="clean-sjmc" if="sjmc-platform.trigger">
|
||||
<delete dir="${dist.dir}/lib"/>
|
||||
</target>
|
||||
<target name="clean-ojec" if="ojec-platform.trigger">
|
||||
<delete dir="${dist.dir}/lib"/>
|
||||
</target>
|
||||
<!--clean-->
|
||||
<target name="pre-clean"/>
|
||||
<target name="post-clean"/>
|
||||
@ -1297,7 +1176,7 @@
|
||||
<delete dir="build" quiet="true"/>
|
||||
<delete dir="dist" quiet="true"/>
|
||||
</target>
|
||||
<target name="do-clean" depends="pre-clean,clean-timestamp,clean-preprocessed,clean-classes,clean-obfuscated,clean-preverified,clean-manifest,clean-jar,clean-jad,clean-javadoc,clean-j9,clean-ricoh,clean-semc,clean-savaje,clean-sjmc,-clean-default-configuration-root,-clean-configuration-root,-clean-completely,post-clean"/>
|
||||
<target name="do-clean" depends="pre-clean,clean-timestamp,clean-preprocessed,clean-classes,clean-obfuscated,clean-preverified,clean-manifest,clean-jar,clean-jad,clean-javadoc,clean-j9,clean-semc,clean-savaje,clean-sjmc,clean-ojec,-clean-default-configuration-root,-clean-configuration-root,-clean-completely,post-clean"/>
|
||||
<target name="clean" depends="conditional-clean" if="no.clean.before.build" description="Clean build products.">
|
||||
<antcall target="do-clean" inheritall="true" inheritrefs="true"/>
|
||||
</target>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
</project-private>
|
||||
|
@ -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
|
||||
|
1039
src/Canv.java
@ -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;
|
||||
}
|
||||
}
|
195
src/Engine1.java
@ -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; i<max; i++) {
|
||||
starz[i] = (int) (starz[i] - spd * dt / 1000);
|
||||
if(spd>0) {
|
||||
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<max; i++) {
|
||||
starx[i] = (rnd.nextInt()>>>1)%(w * 4) - w * 2;
|
||||
stary[i] = (rnd.nextInt()>>>1)%(h * 4) - h * 2;
|
||||
starz[i] = (rnd.nextInt()>>>1)%1900;
|
||||
}
|
||||
CLS(G);
|
||||
}
|
||||
}
|
@ -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("<div id=\"lyrics\">");
|
||||
int lr2 = MSG.indexOf("</div>", 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();
|
||||
}
|
||||
}
|
@ -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){}
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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 = "Ëèñòàòü âïåðåä";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
102
src/Options.java
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<s; i++) {
|
||||
Rate r = (Rate) rates.elementAt(i);
|
||||
if(r.song.equals(song)) {
|
||||
r.rate++;
|
||||
rates.setElementAt(r, i);
|
||||
return r.rate;
|
||||
}
|
||||
}
|
||||
Rate r = new Rate();
|
||||
r.song = song;
|
||||
r.rate = 1;
|
||||
rates.addElement(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
rates.removeAllElements();
|
||||
}
|
||||
|
||||
public void open() {
|
||||
FileConnection fc = null;
|
||||
rates = new Vector();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
for(int i=0; i<path.length; i++) {
|
||||
fc = (FileConnection) Connector.open("file:///"+path[i]+"/SEPS_Rate.txt", Connector.READ);
|
||||
if(!fc.exists()) fc.close();
|
||||
else break;
|
||||
}
|
||||
InputStream is = fc.openInputStream();
|
||||
int ch = 0;
|
||||
while ((ch = is.read()) != -1) {
|
||||
sb.append(StringEncoder.decodeCharCP1251((byte)ch));
|
||||
}
|
||||
is.close();
|
||||
fc.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String s = sb.toString();
|
||||
char c = '\n';
|
||||
int j = s.length();
|
||||
String s2 = "";
|
||||
for(int k = 0; k < j; k++)
|
||||
{
|
||||
int i = s.charAt(k);
|
||||
if(i == c)
|
||||
{
|
||||
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 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<path.length; i++) {
|
||||
fc = (FileConnection) Connector.open("file:///"+path[i], Connector.READ);
|
||||
if(!fc.exists()) fc.close();
|
||||
else break;
|
||||
}
|
||||
fc = (FileConnection) Connector.open("file:///"+path[i]+"/SEPS_Rate.txt");
|
||||
if(fc.exists()) {fc.delete();}
|
||||
fc.create();
|
||||
DataOutputStream os = fc.openDataOutputStream();
|
||||
Rate[] s = sortRate();
|
||||
int l = s.length;
|
||||
for(i=0; i<l; i++) {
|
||||
addText(os, s[i].rate+" | "+s[i].song);
|
||||
}
|
||||
addText(os, SEPS.midlet.lang.elements+l);
|
||||
os.flush();
|
||||
os.close();
|
||||
fc.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addText(DataOutputStream dos, String s1) throws IOException {
|
||||
byte[] bt = new byte[s1.length()+1];
|
||||
int ss = bt.length-1;
|
||||
for (int i = 0; i < ss; i++) {
|
||||
char c = s1.charAt(i);
|
||||
dos.writeByte(StringEncoder.encodeCharCP1251(c));
|
||||
}
|
||||
dos.writeByte((byte) '\n');
|
||||
|
||||
}
|
||||
|
||||
private Rate[] sortRate() {
|
||||
Rate[] s = new Rate[rates.size()];
|
||||
rates.copyInto(s);
|
||||
int sl = s.length;
|
||||
for(int i=0; i<sl; i++) {
|
||||
for(int j=0; j<sl-1; j++) {
|
||||
if(s[j].rate<s[j+1].rate) {
|
||||
Rate q=s[j];
|
||||
s[j]=s[j+1];
|
||||
s[j+1]=q;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import java.util.Random;
|
||||
import javax.microedition.lcdui.Display;
|
||||
import javax.microedition.midlet.*;
|
||||
|
||||
/**
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class SEPS extends MIDlet {
|
||||
|
||||
public static SEPS midlet;
|
||||
public Display dsp;
|
||||
public Canv cnv;
|
||||
public Lang lang;
|
||||
public Images im;
|
||||
|
||||
public SEPS() {
|
||||
midlet = this;
|
||||
}
|
||||
|
||||
public void startApp() {
|
||||
Rms.restoreOptions();
|
||||
lang = new Lang(Rms.lngid);
|
||||
im = new Images();
|
||||
if(Rms.id==0) {
|
||||
Random rnd = new Random();
|
||||
Rms.id = (rnd.nextInt() >>> 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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
126
src/accel/AccelData.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
24
src/accel/NoData.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
22
src/accel/SensorData.java
Normal file
@ -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);
|
||||
|
||||
}
|
201
src/com/annimon/GraphicsUtil.java
Normal file
@ -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<lines.length; i++) {
|
||||
v=lines[i];
|
||||
if(i==2) {
|
||||
g.setColor(Skin.valuet);
|
||||
g.drawString(v, w/2, h/2+(fh*(i-2)), 17);
|
||||
g.setColor(Skin.text);
|
||||
g.drawString(v, w/2-1, h/2+(fh*(i-2))-1, 17);
|
||||
}else{
|
||||
g.setColor(Skin.text);
|
||||
g.drawString(v, w/2, h/2+(fh*(i-2)), 17);
|
||||
g.setColor(Skin.valuet);
|
||||
g.drawString(v, w/2-1, h/2+(fh*(i-2))-1, 17);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Îòðèñîâêà ëèíèè òåêñòà
|
||||
* @param g Graphics
|
||||
* @param value String òåêñòîâàÿ ñòðîêà
|
||||
* @param y int ïîçèöèÿ ðèñîâàíèÿ
|
||||
* @param id òèï îòðèñîâêè (3 = ïî öåíòðó)
|
||||
* @return int çíà÷åíèå äëÿ ñëåäóþùåé îòðèñîâêè òåêñòà
|
||||
*/
|
||||
public static int drawText(Graphics g, String value, int y, int id) {
|
||||
int w = g.getClipWidth();
|
||||
g.setColor(Skin.line);
|
||||
g.drawLine(3, y-1, w-3, y-1);
|
||||
g.setColor(Skin.valuet);
|
||||
g.setFont(smallBoldFont);
|
||||
g.drawString(value, (id!=3?IMAGE_TRACK_WIDTH+4:w/2), y, (id!=3?20:17));
|
||||
return y+(smallBoldFont.getHeight()+2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Îòðèñîâêà âåðõíåé ïàíåëè
|
||||
* @param g Graphics
|
||||
* @param text String íàäïèñü ñëåâà
|
||||
* @param im Images èçîáðàæåíèÿ ôîíà
|
||||
* @param player_mode boolean ðåæèì ïëååðà - îòðèñîâêà èìåíè ïðîãðàììû
|
||||
*/
|
||||
public static void drawTitle(Graphics g, String text, Images im, boolean player_mode) {
|
||||
int w = g.getClipWidth();
|
||||
g.setColor(Skin.valuet);
|
||||
g.setFont(GraphicsUtil.getFont(GraphicsUtil.MEDIUM_BOLD_FONT));
|
||||
int k = im.titleleft.getWidth();
|
||||
for(int i=k; i<w-k; i++) g.drawImage(im.title, i, 0, 20);
|
||||
g.drawImage(im.titleleft, 0, 0, 20);
|
||||
g.drawImage(im.titleright, w, 0, 24);
|
||||
g.drawString(text, k, 2, 20);
|
||||
if(player_mode) g.drawString("SEPlayerService", w-k, 2, 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ïîëó÷åíèå øðèôòà ïî id
|
||||
* @param fontMode id øðèôòà
|
||||
* @return Font
|
||||
*/
|
||||
public static Font getFont(byte fontMode) {
|
||||
switch(fontMode) {
|
||||
case SMALL_PLAIN_FONT:
|
||||
return smallPlainFont;
|
||||
case SMALL_BOLD_FONT:
|
||||
return smallBoldFont;
|
||||
case MEDIUM_BOLD_FONT:
|
||||
return mediumBoldFont;
|
||||
}
|
||||
return smallBoldFont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ïîëó÷åíèå âûñîòû øðèôòà ïî id
|
||||
* @param fontMode id øðèôòà
|
||||
* @return int âûñîòà øðèôòà
|
||||
*/
|
||||
public static int getHeightFont(byte fontMode) {
|
||||
return getFont(fontMode).getHeight();
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
package com.annimon;
|
||||
|
||||
|
||||
|
||||
public class StringEncoder
|
||||
@ -28,25 +30,6 @@ public class StringEncoder
|
||||
return (char)ich;
|
||||
}
|
||||
|
||||
public static byte encodeCharCP1251 (char ch)
|
||||
{
|
||||
if (ch > 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)
|
||||
{
|
||||
int bt = (byte) ch;
|
63
src/com/annimon/Util.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
51
src/fx/AnimatedImage.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
36
src/fx/BlindsFx.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
119
src/fx/ImageFx.java
Normal file
@ -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);
|
||||
}
|
71
src/fx/PuzzleFx.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
43
src/fx/Slide2Fx.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
67
src/fx/SlideFx.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
60
src/fx/WaveFx.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
46
src/fx/WipeFx.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
BIN
src/icon.png
Before Width: | Height: | Size: 857 B |
264
src/lastfm/HTTPUtil.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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) {}
|
||||
}
|
||||
}
|
||||
}
|
345
src/lastfm/LastFMScrobbler.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MobScrob. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
@ -300,21 +175,6 @@ public class MD5 {
|
||||
update(workingState, buffer, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update this hash with the given data.
|
||||
* <p>
|
||||
* 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.
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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] = '+';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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); }
|
||||
}
|
||||
}
|
||||
}
|
57
src/msapi/J2MEPlayer.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
156
src/msapi/MSPlayer.java
Normal file
@ -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<data.length(); i++) {
|
||||
sb.append(StringEncoder.checkCP1251(data.charAt(i)));//.decodeCharCP1251((byte) data.charAt(i)));
|
||||
}
|
||||
return sb.toString();//data;
|
||||
}
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Ïåðåîïðåäåë¸ííûå ìåòîäû">
|
||||
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();
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
|
||||
|
||||
}
|
37
src/msapi/SPlayer.java
Normal file
@ -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();
|
||||
}
|
79
src/msapi/Track.java
Normal file
@ -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 {
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="FIELDS">
|
||||
/** Íàçâàíèå àëüáîìà */
|
||||
private String album;
|
||||
|
||||
/** Èñïîëíèòåëü */
|
||||
private String artist;
|
||||
|
||||
/** Êàðòèíêà àëüáîìà */
|
||||
private Image cover;
|
||||
|
||||
/** Äëèòåëüíîñòü */
|
||||
private long duration;
|
||||
|
||||
/** Çàãîëîâîê */
|
||||
private String title;
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="GET-METHODS">
|
||||
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;
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="SET-METHODS">
|
||||
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;
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
визуализация смены громкости
|
||||
Быстрая перемотка
|
BIN
src/res/1.swf
Normal file
BIN
src/res/5.swf
Normal file
BIN
src/res/6.swf
Normal file
@ -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
|
||||
Украина, 2011
|
Before Width: | Height: | Size: 751 B |
BIN
src/res/album.xid
Normal file
Before Width: | Height: | Size: 587 B |
BIN
src/res/artist.xid
Normal file
BIN
src/res/exit.png
Before Width: | Height: | Size: 548 B |
3
src/res/exit.xid
Normal file
@ -0,0 +1,3 @@
|
||||
$þ'90z}m}wwwz>?3%wwwcwwwbqwww1¢¹ßwwvœ>36#Ò¢¸<ck°†,CÁ¯×C^BfÖÄJì>fôÐ#õK£Öò5Ò,fóðY)Ó¹6—W–^懕6£Fß+RÛß«…pÓ˜X a°nÀö`»K¸D¨<44>Œ‹í~s‰’„ŽôÏÿ|h<>¨üWF˲k¹àd·EMðÔ•}a²™4·n#™b¿)Iö ;”aµ?~.ª,ì<>ïµ*k„|/ðà/°8{s;Ö}´ù8Ú»j›Gi•@I–v#à#Ç5·×ñ‹o¨“¦‡²} WîN<C3AE>%¹{j’0GóëaÚ²îêz<4I™½É_4 ª.ûœªIkǵOI]Ìiì·þÌ<C3BE>²˜–xQ§òjíL<L‘fGõYþ£¬
|
||||
¦Ã+Áõl<C3B5>–b9<62>›÷}”$ ûÚ<>"\Ÿ¦kûÖÁûô§•ïyŽê‚!1·Aj,ð3¥Ä<C2A5>ÖijÁ_€Æþ@O*¯A¸Çú`ßYVcØÂq4¹â<C2B9>Û£˜›<CB9C>DÒ3é—`ýxðGÿBjÊû¨Ö ¦Lò0<C3B2>ù"«©Â|£slÐÑ,lH]>
|
||||
ò1ÂçNjÈ]È霢„ <09>½žó¯ó8•ôu܃
qryœ4JX_¬:‰bÄ<62>ƒ%>ÈsrÁˆ?m B‹CšbŸX\j7Ùúºí¤wwww>293Ù5õ
|
BIN
src/res/icon.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
src/res/pal.png
Before Width: | Height: | Size: 1.1 KiB |
BIN
src/res/pal.xid
Normal file
Before Width: | Height: | Size: 930 B |
BIN
src/res/pound.xid
Normal file
BIN
src/res/sb.png
Before Width: | Height: | Size: 100 B |
BIN
src/res/sb.xid
Normal file
BIN
src/res/sbl.png
Before Width: | Height: | Size: 231 B |
BIN
src/res/sbl.xid
Normal file
BIN
src/res/slp.xid
Normal file
BIN
src/res/star.png
Before Width: | Height: | Size: 185 B |
BIN
src/res/star.xid
Normal file
BIN
src/res/t.png
Before Width: | Height: | Size: 132 B |
BIN
src/res/t.xid
Normal file
BIN
src/res/tl.png
Before Width: | Height: | Size: 252 B |
BIN
src/res/tl.xid
Normal file
Before Width: | Height: | Size: 803 B |
BIN
src/res/track.xid
Normal file
BIN
src/res/zero.png
Before Width: | Height: | Size: 504 B |
BIN
src/res/zero.xid
Normal file
692
src/seps/Canv.java
Normal file
@ -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; i<m.length; i++) {
|
||||
if(mfwc.stringWidth(m[i])>menuwidth) 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(volumeminus<h) {
|
||||
GraphicsUtil.drawRect(g, Skin.volumeUp, Skin.volumeDn, 0, volumeminus-20, w, 20);
|
||||
GraphicsUtil.drawRect(g, Skin.volumeDn, Skin.volumeUp, 0, volumeminus, w, 20);
|
||||
volumeminus+=VOLUME_Y_STEP;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawVisual(Graphics g) {
|
||||
g.setColor(Skin.background);
|
||||
g.fillRect(0, 0, w, h);
|
||||
//g.setFont(GraphicsUtil.getFont(GraphicsUtil.MEDIUM_BOLD_FONT));
|
||||
int ih = h;//-2*im.statusBarHeight-GraphicsUtil.getHeightFont(GraphicsUtil.MEDIUM_BOLD_FONT)-8;
|
||||
Track current = getPlayer().getTrack();
|
||||
// g.setColor(Skin.valuet);
|
||||
// g.drawString(current.getTitle(), 9, 2, 20);//GraphicsUtil.drawTitle(g, current.getTitle(), im, mode==PLAYER_MODE);
|
||||
album = current.getCover();
|
||||
if (album != null) {
|
||||
if(album.getHeight()>ih) 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; i<w-k; i++) {
|
||||
g.drawImage(im.statusBar, i, py, 20);
|
||||
}
|
||||
g.drawImage(im.statusBarleft, 3, py, 20);
|
||||
g.drawImage(im.statusBarright, w-3, py, 24);
|
||||
g.setColor(Skin.inf);
|
||||
if(repeat==1) g.drawLine(5+(int)(a*div), py, 5+(int)(a*div), py+10);
|
||||
if(repeat==2) {
|
||||
g.drawLine(5+(int)(a*div), py, 5+(int)(a*div), py+10);
|
||||
g.drawLine(5+(int)(b*div), py, 5+(int)(b*div), py+10);
|
||||
}
|
||||
|
||||
album = current.getCover();
|
||||
if (album != null) {
|
||||
int ih = h-fh-2-py-20;
|
||||
if(album.getHeight()>ih) 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; i++) {
|
||||
if(i==cur) {
|
||||
GraphicsUtil.drawRect(g, Skin.softUp1, Skin.softUp2, x, y+fh*i, menuwidth, fh);
|
||||
g.setColor(Skin.valuet);
|
||||
}else{
|
||||
GraphicsUtil.drawRect(g, Skin.softDn1, Skin.softDn2, x, y+fh*i, menuwidth, fh);
|
||||
g.setColor(Skin.text);
|
||||
}
|
||||
g.drawString(m[i], w/2, y+fh*i, 17);
|
||||
}
|
||||
GraphicsUtil.drawTitle(g, Util.getTime(), im, mode==PLAYER_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Îòðèñîâêà ñîôò-êëàâèø
|
||||
* @param g
|
||||
*/
|
||||
private void drawSoft(Graphics g) {
|
||||
int fh = GraphicsUtil.getHeightFont(GraphicsUtil.MEDIUM_BOLD_FONT)+2;
|
||||
int wsoft = 26;
|
||||
int msoft = (w-wsoft*2)/3;
|
||||
g.setFont(GraphicsUtil.getFont(GraphicsUtil.MEDIUM_BOLD_FONT));
|
||||
//Ëèíèÿ
|
||||
g.setColor(0);
|
||||
g.drawLine(0, h-fh-1, w, h-fh-1);
|
||||
//Ìåíþ
|
||||
GraphicsUtil.drawRect(g, (menuup!=0 || menu)?Skin.softUp1:Skin.softDn1, (menuup!=0 || menu)?Skin.softUp2:Skin.softDn2, 0, h-fh, wsoft, fh);
|
||||
g.setColor(Skin.valuet);
|
||||
g.fillTriangle(wsoft/2, h-5, 3, h-fh+7, wsoft-3, h-fh+7);
|
||||
//Âûõîä
|
||||
GraphicsUtil.drawRect(g, rspressed?Skin.softUp1:Skin.softDn1, rspressed?Skin.softUp2:Skin.softDn2, w-wsoft, h-fh, wsoft, fh);
|
||||
g.drawImage(im.exit, w-2, h-fh, 24);
|
||||
//* - Âèçóàëèçàöèÿ
|
||||
GraphicsUtil.drawRect(g, Rms.vis?Skin.softUp1:Skin.softDn1, Rms.vis?Skin.softUp2:Skin.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 - Òåêñòû Ïåñåí
|
||||
GraphicsUtil.drawRect(g, Rms.isLyric?Skin.softUp1:Skin.softDn1, Rms.isLyric?Skin.softUp2:Skin.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);
|
||||
// - Àêñåëåðîìåòð
|
||||
GraphicsUtil.drawRect(g, Rms.accel?Skin.softUp1:Skin.softDn1, Rms.accel?Skin.softUp2:Skin.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);
|
||||
}
|
||||
|
||||
protected void sizeChanged(int w, int h) {
|
||||
this.w = getWidth();
|
||||
this.h = volumeminus = getHeight();
|
||||
I = Image.createImage(w, h);
|
||||
G = I.getGraphics();
|
||||
lyricWidth = w/(GraphicsUtil.getFont(GraphicsUtil.SMALL_BOLD_FONT).charWidth('a')+1);
|
||||
textWidth = lyricWidth - 1;
|
||||
cx = w/2;
|
||||
super.sizeChanged(w, h);
|
||||
}
|
||||
|
||||
protected void keyPressed(int key) {
|
||||
int ga=getGameAction(key);
|
||||
if(key==-6 && !menu) {
|
||||
menuup = menu?1:-1;
|
||||
}
|
||||
if((menuup!=0 || menu) && !vis && !skin) {
|
||||
if(key==-6) {
|
||||
menuup = menu?1:-1;
|
||||
}
|
||||
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) {
|
||||
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-1;}
|
||||
else if(ga==RIGHT) {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]<char_A_width) sleepPos[id]++;
|
||||
else {
|
||||
if (scrolldirection[id]) scrollPos[id]--;
|
||||
else scrollPos[id]++;
|
||||
if (scrollPos[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) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<b) h = 60 * ((g-b)/(v-min))+360;
|
||||
if(v==g) h = 60 * ((b-r)/(v-min))+120;
|
||||
if(v==b) h = 60 * ((r-g)/(v-min))+240;
|
||||
else if(v==r) {
|
||||
h = 60 * ((g-b)/(v-min));
|
||||
if(g<b) h+=360;
|
||||
}
|
||||
else if(v==g) h = 60 * ((b-r)/(v-min))+120;
|
||||
else if(v==b) h = 60 * ((r-g)/(v-min))+240;
|
||||
//saturation
|
||||
if(v==0) s = 0;
|
||||
else s=((v - min)/v);//1-(min/max);
|
@ -1,3 +1,5 @@
|
||||
package seps;
|
||||
|
||||
|
||||
|
||||
import javax.microedition.lcdui.Font;
|
49
src/seps/FirstStartForm.java
Normal file
@ -0,0 +1,49 @@
|
||||
package seps;
|
||||
|
||||
import javax.microedition.lcdui.*;
|
||||
|
||||
/**
|
||||
* Êëàññ ïåðâîíà÷àëüíûõ íàñòðîåê
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class FirstStartForm extends Form implements CommandListener {
|
||||
|
||||
private Command exit, ok;
|
||||
private ChoiceGroup api_options, languageCG;
|
||||
|
||||
|
||||
public FirstStartForm(Lang lng) {
|
||||
super(lng.options+lng.api);
|
||||
ok = new Command(lng.ok, Command.OK, 1);
|
||||
exit = new Command(lng.exit, Command.EXIT, 2);
|
||||
|
||||
api_options = new ChoiceGroup ("", ChoiceGroup.MULTIPLE);
|
||||
api_options.append(lng.accel, null);
|
||||
api_options.append(lng.msapi+lng.api, null);
|
||||
api_options.setSelectedIndex(0, Rms.api_accel);
|
||||
api_options.setSelectedIndex(1, Rms.api_mserv);
|
||||
languageCG = new ChoiceGroup ("Language / ßçûê", ChoiceGroup.EXCLUSIVE);
|
||||
languageCG.append("English", null);
|
||||
languageCG.append("Ðóññêèé", null);
|
||||
languageCG.setSelectedIndex(Rms.lngid, true);
|
||||
append(api_options);
|
||||
append(languageCG);
|
||||
addCommand(ok);
|
||||
addCommand(exit);
|
||||
setCommandListener(FirstStartForm.this);
|
||||
}
|
||||
|
||||
public void commandAction(Command c, Displayable d) {
|
||||
if (c == exit) Main.midlet.destroyApp(true);
|
||||
|
||||
if (c == ok) {
|
||||
Rms.api_accel = api_options.isSelected(0);
|
||||
Rms.api_mserv = api_options.isSelected(1);
|
||||
Rms.lngid = languageCG.getSelectedIndex();
|
||||
Main.midlet.lang = new Lang(Rms.lngid);
|
||||
Main.midlet.cnv = new Canv(Main.midlet.im, Main.midlet.lang);
|
||||
Rms.firstStart = false;
|
||||
Main.midlet.dsp.setCurrent(Main.midlet.cnv);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,10 @@
|
||||
package seps;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.microedition.lcdui.Image;
|
||||
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Èçîáðàæåíèÿ
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class Images {
|
||||
@ -16,7 +12,7 @@ public class Images {
|
||||
public Image titleleft, title, titleright,
|
||||
statusBarleft,statusBar,statusBarright,
|
||||
track, artist, album, exit,
|
||||
star, zero, pound, pal;
|
||||
star, zero, pound, pal, sleep;
|
||||
public int statusBarHeight, statusBarleftWidth;
|
||||
|
||||
public Images() {
|
||||
@ -34,7 +30,9 @@ public class Images {
|
||||
zero = getImage("zero");
|
||||
pound = getImage("pound");
|
||||
pal = getImage("pal");
|
||||
sleep = getImage("slp");
|
||||
//if(Rms.skinid!=0) changeHue();
|
||||
|
||||
//---Ðàçìåðû---//
|
||||
statusBarleftWidth = statusBarleft.getWidth();
|
||||
statusBarHeight = statusBarleft.getHeight();
|
||||
@ -54,13 +52,29 @@ public class Images {
|
||||
}*/
|
||||
|
||||
private Image getImage(String path) {
|
||||
Image img = null;
|
||||
try {
|
||||
img = Image.createImage("/res/"+path+".png");
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
InputStream is = getClass().getResourceAsStream("/res/"+path+".xid");
|
||||
int b1 = is.read();
|
||||
int b2 = is.read();
|
||||
int ii = ((b2 << 8) | b1);
|
||||
|
||||
byte[] data = new byte[ii];
|
||||
is.read(data, 0, ii);
|
||||
is.close();
|
||||
data = invertArray(data);
|
||||
return Image.createImage(data, 0, data.length);
|
||||
} catch (Exception in) {
|
||||
in.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
private byte[] invertArray(byte[] fileData) {
|
||||
int len = fileData.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
fileData[i] ^= 119;
|
||||
}
|
||||
return fileData;
|
||||
}
|
||||
|
||||
private Image flipImage(Image img) {
|
208
src/seps/Info.java
Normal file
@ -0,0 +1,208 @@
|
||||
package seps;
|
||||
|
||||
import com.annimon.GraphicsUtil;
|
||||
import com.annimon.StringEncoder;
|
||||
import com.annimon.Util;
|
||||
import java.io.DataInputStream;
|
||||
import java.util.Vector;
|
||||
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 Canvas {
|
||||
|
||||
private Images im;
|
||||
|
||||
private Font def;
|
||||
private int fontHeight, defHeight;
|
||||
private String str; //òåêñò
|
||||
private int w, h; //ðàçìåðû
|
||||
|
||||
private int mh; //Ðàçìåð îãðàíè÷èâàþùåãî ïðÿìîóãîëüíèêà;
|
||||
private int y0; //Ïîëîæåíèå âåðõíåãî êðàÿ òåêñòà
|
||||
private int dy; //Øàã ïðè ïðîêðóòêå òåêñòà
|
||||
private int textheight; //Îáùàÿ âûñîòà òåêñòà
|
||||
private Vector strLines;
|
||||
|
||||
public Info(Images im) {
|
||||
setFullScreenMode(true);
|
||||
this.im = im;
|
||||
w = getWidth();
|
||||
h = getHeight();
|
||||
str = getText("/res/about");
|
||||
|
||||
fontHeight = GraphicsUtil.getHeightFont(GraphicsUtil.SMALL_BOLD_FONT)+2;
|
||||
def = Font.getDefaultFont();
|
||||
dy = defHeight = def.getHeight()+2;
|
||||
mh = h - fontHeight - 1;
|
||||
SetTextPar();
|
||||
}
|
||||
|
||||
protected void paint(Graphics g) {
|
||||
GraphicsUtil.drawRect(g, Skin.softDn1, Skin.softDn2, 0, 0,w, h);
|
||||
g.setColor(Skin.valuet);
|
||||
g.setFont(def);
|
||||
g.setClip(0, fontHeight+1, w, mh);
|
||||
int y1 = y0;
|
||||
for (int i = 0; i < strLines.size(); i++) {
|
||||
if ((y1 + defHeight) > 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<h3 && (x>w3 && x<(w-w3))) keyPressed(UP);
|
||||
else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyPressed(DOWN);
|
||||
|
||||
if(x<w3 && (y>h3 && y<(h-h3))) keyPressed(LEFT);
|
||||
else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyPressed(RIGHT);
|
||||
|
||||
else if(x<w3 && y>(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<arr.length; i++) {
|
||||
String substr = arr[i];
|
||||
int i0 = 0, space = 0, in = 0, j = 0, jw = 0; //Ñìåùåíèå îò íà÷àëà ñòðîêè
|
||||
int imax = substr.length(); //Äëèíà ñòðîêè
|
||||
boolean isexit = true;
|
||||
y0 = 0;
|
||||
while (isexit) {
|
||||
space = substr.indexOf(" ", i0 + 1);
|
||||
if (space <= i0) {
|
||||
space = imax;
|
||||
isexit = false;
|
||||
}
|
||||
|
||||
j = def.stringWidth(substr.substring(i0, space));
|
||||
if (jw + j < w) {//Ñëîâî óìåùàåòñÿ
|
||||
jw = jw + j;
|
||||
i0 = space;
|
||||
} else {//Ñëîâî íå óìåùàåòñÿ
|
||||
strLines.addElement(substr.substring(in, i0));
|
||||
in = i0 + 1;
|
||||
jw = j;
|
||||
if (j > 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
src/seps/Lang.java
Normal file
@ -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 = "Ïàðîëü";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
package seps;
|
||||
|
||||
|
||||
import com.annimon.StringEncoder;
|
||||
import java.io.*;
|
||||
import java.util.Vector;
|
||||
import javax.microedition.io.*;
|
||||
@ -62,7 +65,7 @@ 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();
|
||||
}*/
|
||||
}
|
51
src/seps/Main.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
102
src/seps/OptionsForm.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
// -= Íàñòðîéêè 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 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 boolean slpmode = false; //Ñïÿùèé ðåæèì
|
||||
public static int dh,dm; //Âðåìÿ âûêëþ÷åíèÿ ïðè ñïÿùåì ðåæèìå
|
||||
|
||||
public static int dh,dm;
|
||||
public static boolean slpmode = false;
|
||||
/**
|
||||
* Ñîõðàíåíèå íàñòðîåê
|
||||
*/
|
||||
@ -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) {}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
60
src/seps/Skin.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
52
src/seps/TestScrobbler.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
30
src/visual/Capuchin.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
86
src/visual/Plasma.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
196
src/visual/Stars.java
Normal file
@ -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; i<max; i++) {
|
||||
starz[i] = (int) (starz[i] - spd * dt / 1000);
|
||||
if(spd>0) {
|
||||
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; i<max; i++) {
|
||||
initStar();
|
||||
}
|
||||
GraphicsUtil.CLS(G);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Îáíîâëĺíčĺ ďŕđŕěĺňđîâ
|
||||
*/
|
||||
private void updateParams() {
|
||||
if(up) {
|
||||
while(cf!=0) {
|
||||
spd++; cf--;
|
||||
}
|
||||
up=false;
|
||||
}
|
||||
if(dn) {
|
||||
while(cf!=0) {
|
||||
spd--; cf--;
|
||||
}
|
||||
dn=false;
|
||||
}
|
||||
int r = rnd.nextInt(50);
|
||||
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(update) if(max>11) 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
70
src/visual/Visual.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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++;
|
||||
@ -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 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;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(25);
|
||||
} catch (InterruptedException ex) {}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
g.drawRGB(pixelArray, 0, w, 0, 0, w, h, true);
|
||||
}
|
||||
|
||||
|
||||
}
|