Initial
This commit is contained in:
commit
f35ef0b2dc
83
build.xml
Normal file
83
build.xml
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<project name="Libraries" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project .</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
pre-init: called before initialization of project properties
|
||||
post-init: called after initialization of project properties
|
||||
pre-preprocess: called before text preprocessing of sources
|
||||
post-preprocess: called after text preprocessing of sources
|
||||
pre-compile: called before source compilation
|
||||
post-compile: called after source compilation
|
||||
pre-obfuscate: called before obfuscation
|
||||
post-obfuscate: called after obfuscation
|
||||
pre-preverify: called before preverification
|
||||
post-preverify: called after preverification
|
||||
pre-jar: called before jar building
|
||||
post-jar: called after jar building
|
||||
pre-build: called before final distribution building
|
||||
post-build: called after final distribution building
|
||||
pre-clean: called before cleaning build products
|
||||
post-clean: called after cleaning build products
|
||||
|
||||
Example of pluging a my-special-task after the compilation could look like
|
||||
|
||||
<target name="post-compile">
|
||||
<my-special-task>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</my-special-task>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
Other way how to customize the build is by overriding existing main targets.
|
||||
The target of interest are:
|
||||
|
||||
preprocess: preprocessing
|
||||
extract-libs: extraction of libraries and resources
|
||||
compile: compilation
|
||||
create-jad: construction of jad and jar manifest source
|
||||
obfuscate: obfuscation
|
||||
preverify: preverification
|
||||
jar: jar archive building
|
||||
run: execution
|
||||
debug: execution in debug mode
|
||||
build: building of the final distribution
|
||||
javadoc: javadoc generation
|
||||
|
||||
Example of overriding the target for project execution could look like
|
||||
|
||||
<target name="run" depends="init,jar">
|
||||
<my-special-exec jadfile="${dist.dir}/${dist.jad}"/>
|
||||
</target>
|
||||
|
||||
Be careful about correct dependencies when overriding original target.
|
||||
Again, for list of available properties which you can use check the target
|
||||
you are overriding in nbproject/build-impl.xml file.
|
||||
|
||||
A special target for-all-configs can be used to run some specific targets for
|
||||
all project configurations in a sequence. File nbproject/build-impl.xml
|
||||
already contains some "for-all" targets:
|
||||
|
||||
jar-all
|
||||
javadoc-all
|
||||
clean-all
|
||||
|
||||
Example of definition of target iterating over all project configurations:
|
||||
|
||||
<target name="jar-all">
|
||||
<property name="target.to.call" value="jar"/>
|
||||
<antcall target="for-all-configs"/>
|
||||
</target>
|
||||
|
||||
-->
|
||||
</project>
|
1247
nbproject/build-impl.xml
Normal file
1247
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
build.xml.data.CRC32=0bd023a7
|
||||
build.xml.script.CRC32=f96cb661
|
||||
build.xml.stylesheet.CRC32=9c6a911d
|
||||
nbproject/build-impl.xml.data.CRC32=0bd023a7
|
||||
nbproject/build-impl.xml.script.CRC32=fb00cb98
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=e46c2d22
|
7
nbproject/private/private.properties
Normal file
7
nbproject/private/private.properties
Normal file
@ -0,0 +1,7 @@
|
||||
#Sun, 20 Feb 2011 23:20:17 +0200
|
||||
app-version.autoincrement=true
|
||||
config.active=
|
||||
deployment.counter=4
|
||||
deployment.number=0.0.3
|
||||
javadoc.preview=true
|
||||
netbeans.user=C:\\Users\\aNNiMON\\AppData\\Roaming\\NetBeans\\dev
|
5
nbproject/private/private.xml
Normal file
5
nbproject/private/private.xml
Normal file
@ -0,0 +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>
|
142
nbproject/project.properties
Normal file
142
nbproject/project.properties
Normal file
@ -0,0 +1,142 @@
|
||||
abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,NOKIAUI=1.0,JSR226=1.0,capuchin=1.0,MIDP=2.1,JSR229=1.1.0,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,eSWT=1.1,J2MEWS=1.0,VSCL=2.1,WMA=2.0,JSR172=1.0,JSR256=1.1,SEMC_EXT_JP8=1.0,ColorScreen,NokiaUI=1.0,OBEX=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,MascotV3=1.0,JSR75=1.0,IAPInfo=1.0,SATSAPKI=1.0,JSR184=1.1,ScreenHeight=321,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0,
|
||||
all.configurations=\
|
||||
application.args=
|
||||
application.description=
|
||||
application.description.detail=
|
||||
application.name=
|
||||
application.vendor=Vendor
|
||||
build.classes.dir=${build.dir}/compiled
|
||||
build.classes.excludes=**/*.java,**/*.form,**/*.class,**/.nbintdb,**/*.mvd,**/*.wsclient,**/*.vmd
|
||||
build.dir=build/${config.active}
|
||||
build.root.dir=build
|
||||
debug.level=debug
|
||||
debugger.timeout=
|
||||
deployment.copy.target=deploy
|
||||
deployment.instance=default
|
||||
deployment.jarurl=${dist.jar}
|
||||
deployment.method=NONE
|
||||
deployment.override.jarurl=false
|
||||
dist.dir=dist/${config.active}
|
||||
dist.jad=Libraries.jad
|
||||
dist.jar=Libraries.jar
|
||||
dist.javadoc.dir=${dist.dir}/doc
|
||||
dist.root.dir=dist
|
||||
extra.classpath=
|
||||
filter.exclude.tests=false
|
||||
filter.excludes=
|
||||
filter.more.excludes=**/overview.html,**/package.html
|
||||
filter.use.standard=true
|
||||
jar.compress=true
|
||||
javac.debug=true
|
||||
javac.deprecation=false
|
||||
javac.encoding=UTF-8
|
||||
javac.optimize=false
|
||||
javac.source=1.3
|
||||
javac.target=1.1
|
||||
javadoc.author=false
|
||||
javadoc.encoding=
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
libs.classpath=
|
||||
main.class=
|
||||
main.class.class=applet
|
||||
manifest.apipermissions=
|
||||
manifest.file=manifest.mf
|
||||
manifest.is.liblet=false
|
||||
manifest.jad=
|
||||
manifest.manifest=
|
||||
manifest.midlets=MIDlet-1: Midlet, , Midlet\n
|
||||
manifest.others=MIDlet-Vendor: Vendor\nMIDlet-Name: Libraries\nMIDlet-Version: 1.0\n
|
||||
manifest.pushregistry=
|
||||
name=Libraries
|
||||
no.dependencies=false
|
||||
nokiaS80.application.icon=
|
||||
nsicom.application.monitorhost=
|
||||
nsicom.application.runremote=
|
||||
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=0
|
||||
obfuscator.destjar=${build.dir}/obfuscated.jar
|
||||
obfuscator.srcjar=${build.dir}/before-obfuscation.jar
|
||||
platform.active=Sony_Ericsson_SDK_2_5_0_6_for_the_Java_TM__ME_Platform_Emulator_
|
||||
platform.active.description=Sony Ericsson SDK 2.5.0.6 for the Java(TM) ME Platform(Emulator)
|
||||
platform.apis=JSR239-1.0,WMA-2.0,MascotV3-1.0,JSR82-1.1,JSR184-1.1,SATSA-JCRMI-1.0,VSCL-2.1,NokiaUI-1.0,VSCL-2.0,eSWT-1.1,JSR172-1.0,JSR234-1.0,SATSA-APDU-1.0,OBEX-1.0,SATSA-CRYPTO-1.0,JSR75-1.0,JSR238-1.0,JSR179-1.0.1,JSR226-1.0,JSR180-1.0.1,JSR211-1.0,JSR177-1.0,IAPInfo-1.0,J2ME-XMLRPC-1.0,SATSA-PKI-1.0,SEMC_EXT_JP8-1.0,capuchin-1.0,J2ME-WS-1.0,NOKIAUI-1.0,JSR229-1.1.0,JSR256-1.1,MMAPI-1.1
|
||||
platform.bootclasspath=${platform.home}/lib/eswt.jar:${platform.home}/lib/mascotv3.jar:${platform.home}/lib/jsr226.jar:${platform.home}/lib/jsr256.jar:${platform.home}/lib/satsa-crypto.jar:${platform.home}/lib/jsr229.jar:${platform.home}/lib/jsr238.jar:${platform.home}/lib/j2me-xmlrpc.jar:${platform.home}/lib/jsr211.jar:${platform.home}/lib/vscl21.jar:${platform.home}/lib/satsa-jcrmi.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/satsa-apdu.jar:${platform.home}/lib/jsr184.jar:${platform.home}/lib/nokiaext.jar:${platform.home}/lib/capuchin.jar:${platform.home}/lib/jsr239.jar:${platform.home}/lib/jsr75.jar:${platform.home}/lib/satsa-pki.jar:${platform.home}/lib/jsr179.jar:${platform.home}/lib/jsr180.jar:${platform.home}/lib/iapinfo.jar:${platform.home}/lib/vscl.jar:${platform.home}/lib/mmapi.jar:${platform.home}/lib/j2me-ws.jar:${platform.home}/lib/wma20.jar:${platform.home}/lib/jsr234.jar:${platform.home}/lib/semc_ext_jp8.jar:${platform.home}/lib/cldcapi11.jar:${platform.home}/lib/midpapi20.jar
|
||||
platform.configuration=CLDC-1.1
|
||||
platform.device=SonyEricsson_JP8_240x320_Emu
|
||||
platform.fat.jar=true
|
||||
platform.profile=MIDP-2.0
|
||||
platform.trigger=CLDC
|
||||
platform.type=UEI-1.0.1
|
||||
preprocessed.dir=${build.dir}/preprocessed
|
||||
preverify.classes.dir=${build.dir}/preverified
|
||||
preverify.sources.dir=${build.dir}/preverifysrc
|
||||
resources.dir=resources
|
||||
ricoh.application.email=
|
||||
ricoh.application.fax=
|
||||
ricoh.application.icon=
|
||||
ricoh.application.target-jar=
|
||||
ricoh.application.telephone=
|
||||
ricoh.application.uid=09498641
|
||||
ricoh.application.version=
|
||||
ricoh.dalp.application-desc.auto-run=false
|
||||
ricoh.dalp.application-desc.energy-save=
|
||||
ricoh.dalp.application-desc.exec-auth=
|
||||
ricoh.dalp.application-desc.visible=true
|
||||
ricoh.dalp.argument=
|
||||
ricoh.dalp.codebase=
|
||||
ricoh.dalp.display-mode.color=true
|
||||
ricoh.dalp.display-mode.is-4line-support=false
|
||||
ricoh.dalp.display-mode.is-hvga-support=true
|
||||
ricoh.dalp.display-mode.is-vga-support=false
|
||||
ricoh.dalp.display-mode.is-wvga-support=false
|
||||
ricoh.dalp.information.abbreviation=
|
||||
ricoh.dalp.information.icon.basepath=
|
||||
ricoh.dalp.information.icon.location=
|
||||
ricoh.dalp.information.is-icon-used=true
|
||||
ricoh.dalp.install.destination=hdd
|
||||
ricoh.dalp.install.mode.auto=true
|
||||
ricoh.dalp.install.work-dir=hdd
|
||||
ricoh.dalp.is-managed=true
|
||||
ricoh.dalp.resources.dsdk.version=2.0
|
||||
ricoh.dalp.resources.jar.basepath=
|
||||
ricoh.dalp.resources.jar.version=
|
||||
ricoh.dalp.version=
|
||||
ricoh.icon.invert=false
|
||||
ricoh.platform.target.version=
|
||||
run.cmd.options=
|
||||
run.jvmargs=
|
||||
run.method=STANDARD
|
||||
run.security.domain=trusted
|
||||
run.use.security.domain=false
|
||||
savaje.application.icon=
|
||||
savaje.application.icon.focused=
|
||||
savaje.application.icon.small=
|
||||
savaje.application.uid=TBD
|
||||
savaje.bundle.base=
|
||||
savaje.bundle.debug=false
|
||||
savaje.bundle.debug.port=
|
||||
semc.application.caps=
|
||||
semc.application.icon=
|
||||
semc.application.icon.count=
|
||||
semc.application.icon.splash=
|
||||
semc.application.icon.splash.installonly=false
|
||||
semc.application.uid=E1186354
|
||||
semc.certificate.path=
|
||||
semc.private.key.password=
|
||||
semc.private.key.path=
|
||||
sign.alias=
|
||||
sign.enabled=false
|
||||
sign.keystore=
|
||||
src.dir=src
|
||||
use.emptyapis=true
|
||||
use.preprocessor=true
|
10
nbproject/project.xml
Normal file
10
nbproject/project.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.kjava.j2meproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2me-project">
|
||||
<name>Libraries</name>
|
||||
<minimum-ant-version>1.6</minimum-ant-version>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
95
src/Midlet.java
Normal file
95
src/Midlet.java
Normal file
@ -0,0 +1,95 @@
|
||||
import javax.microedition.lcdui.Command;
|
||||
import javax.microedition.lcdui.CommandListener;
|
||||
import javax.microedition.lcdui.Display;
|
||||
import javax.microedition.lcdui.Displayable;
|
||||
import javax.microedition.lcdui.Form;
|
||||
import javax.microedition.midlet.MIDlet;
|
||||
import javax.microedition.sensor.SensorInfo;
|
||||
import javax.microedition.sensor.SensorManager;
|
||||
import javax.microedition.sensor.MeasurementRange;
|
||||
import javax.microedition.sensor.ChannelInfo;
|
||||
|
||||
public class Midlet extends MIDlet implements CommandListener {
|
||||
private SensorInfo[] infos;
|
||||
private MeasurementRange[] ranges;
|
||||
private Form form;
|
||||
private Command exitCommand;
|
||||
|
||||
public Midlet() {
|
||||
form = new Form("Sensor Info");
|
||||
exitCommand = new Command("Exit", Command.EXIT, 1);
|
||||
form.addCommand(exitCommand);
|
||||
form.setCommandListener(this);
|
||||
Display.getDisplay(this).setCurrent(form);
|
||||
}
|
||||
|
||||
public void startApp() {
|
||||
listSensors();
|
||||
}
|
||||
|
||||
public void destroyApp(boolean unconditional) {}
|
||||
|
||||
public void pauseApp() {}
|
||||
|
||||
/**
|
||||
* Lists all the sensors in the device and the following details:<BR>
|
||||
* - sensor quantity<BR>
|
||||
* - readable description of the sensor<BR>
|
||||
* - the context type of the sensor<BR>
|
||||
* - the model of the sensor<BR>
|
||||
* - the URL needed to open a SensorConnection<BR>
|
||||
* - the datatype of the sensor<BR>
|
||||
* - the measurement range: smallest and largest values and the resolution<BR>
|
||||
* - channel info: the datatypes of the channels, their names, scales and units<BR>
|
||||
*/
|
||||
private void listSensors() {
|
||||
infos = SensorManager.findSensors(null, null);
|
||||
if (infos.length==0) return;
|
||||
int length = infos.length;
|
||||
int datatypes[] = new int[length];
|
||||
for (int i = 0; i < length; i ++) {
|
||||
datatypes[i] = infos[i].getChannelInfos()[0].getDataType();
|
||||
ranges = infos[i].getChannelInfos()[0].getMeasurementRanges();
|
||||
addText("Sensor #" + (i+1) + ": Quantity: " + infos[i].getQuantity());
|
||||
addText("Sensor #" + (i+1) + ": Description: " + infos[i].getDescription());
|
||||
addText("Sensor #" + (i+1) + ": ContextType: " + infos[i].getContextType());
|
||||
addText("Sensor #" + (i+1) + ": Model: " + infos[i].getModel());
|
||||
addText("Sensor #" + (i+1) + ": Url: " + infos[i].getUrl());
|
||||
String datatype = "";
|
||||
if (datatypes[i] == 1) datatype = "TYPE_DOUBLE"; //ChannelInfo.TYPE_DOUBLE = 1
|
||||
else if (datatypes[i] == 2) datatype = "TYPE_INT"; //ChannelInfo.TYPE_INT = 2
|
||||
else if (datatypes[i] == 4) datatype = "TYPE_OBJECT"; //ChannelInfo.TYPE_OBJECT = 4
|
||||
addText("Sensor #" + (i+1) + ": DataType: " + datatype);
|
||||
addText("Sensor #" + (i+1) + ": MeasurementRange, smallest value: " + ranges[0].getSmallestValue());
|
||||
addText("Sensor #" + (i+1) + ": MeasurementRange, largest value: " + ranges[0].getLargestValue());
|
||||
addText("Sensor #" + (i+1) + ": MeasurementRange, resolution: " + ranges[0].getResolution());
|
||||
SensorInfo sensorinfo = infos[i];
|
||||
ChannelInfo channelInfo[] = sensorinfo.getChannelInfos();
|
||||
for(int j = 0; j < channelInfo.length; j++) {
|
||||
ChannelInfo channelinfo = channelInfo[j];
|
||||
addText("Sensor #" + (i+1) + ": " + (j+1) + ". channel, accuracy:" + channelinfo.getAccuracy());
|
||||
int d_type = channelinfo.getDataType();
|
||||
if (d_type == 1) datatype = "TYPE_DOUBLE"; //ChannelInfo.TYPE_DOUBLE = 1
|
||||
else if (d_type == 2) datatype = "TYPE_INT"; //ChannelInfo.TYPE_INT = 2
|
||||
else if (d_type == 4) datatype = "TYPE_OBJECT"; //ChannelInfo.TYPE_OBJECT = 4
|
||||
addText("Sensor #" + (i+1) + ": " + (j+1) + ". channel, data type: " + datatype);
|
||||
addText("Sensor #" + (i+1) + ": " + (j+1) + ". channel, name: " + channelinfo.getName());
|
||||
int scale = channelinfo.getScale();
|
||||
String scaleString = "";
|
||||
if (scale == 0) scaleString = "scaling not needed";
|
||||
else scaleString = "" + scale;
|
||||
addText("Sensor #" + (i+1) + ": " + (j+1) + ". channel, scale: " + scaleString);
|
||||
addText("Sensor #" + (i+1) + ": " + (j+1) + ". channel, unit: " + channelinfo.getUnit());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addText(String text) {
|
||||
form.append(text + "\n");
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
public void commandAction(Command c, Displayable d) {
|
||||
if (c == exitCommand) notifyDestroyed();
|
||||
}
|
||||
}
|
55
src/StringEncoder.java
Normal file
55
src/StringEncoder.java
Normal file
@ -0,0 +1,55 @@
|
||||
public class StringEncoder {
|
||||
|
||||
protected static char cp1251[] = {
|
||||
'\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416',
|
||||
'\u0417', '\u0418', '\u0419', '\u041A', '\u041B', '\u041C', '\u041D',
|
||||
'\u041E', '\u041F', '\u0420', '\u0421', '\u0422', '\u0423', '\u0424',
|
||||
'\u0425', '\u0426', '\u0427', '\u0428', '\u0429', '\u042A', '\u042B',
|
||||
'\u042C', '\u042D', '\u042E', '\u042F', '\u0430', '\u0431', '\u0432',
|
||||
'\u0433', '\u0434', '\u0435', '\u0436', '\u0437', '\u0438', '\u0439',
|
||||
'\u043A', '\u043B', '\u043C', '\u043D', '\u043E', '\u043F', '\u0440',
|
||||
'\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447',
|
||||
'\u0448', '\u0449', '\u044A', '\u044B', '\u044C', '\u044D', '\u044E',
|
||||
'\u044F'
|
||||
};
|
||||
|
||||
public static char decodeCharCP1251(byte b) {
|
||||
int ich = b & 0xff;
|
||||
if (ich == 0xb8) {
|
||||
return 0x0451;
|
||||
} else if (ich == 0xa8) {
|
||||
return 0x0401;
|
||||
} else if (ich >= 0xc0) {
|
||||
return cp1251[ich - 192];
|
||||
}
|
||||
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;
|
||||
if (bt < 0) {
|
||||
return decodeCharCP1251((byte) (256 + bt));
|
||||
} else {
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
}
|
238
src/com/annimon/ExtendMath.java
Normal file
238
src/com/annimon/ExtendMath.java
Normal file
@ -0,0 +1,238 @@
|
||||
/*
|
||||
* aNNiMON 2012
|
||||
* For more info visit http://annimon.com/
|
||||
*/
|
||||
package com.annimon;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class ExtendMath {
|
||||
|
||||
private static final double LOGdiv2 = -0.6931471805599453094;
|
||||
|
||||
public static double atan(double x) {
|
||||
boolean signChange = false;
|
||||
boolean Invert = false;
|
||||
int sp = 0;
|
||||
double x2, a;
|
||||
// check up the sign change
|
||||
if (x < 0.) {
|
||||
x = -x;
|
||||
signChange = true;
|
||||
}
|
||||
// check up the invertation
|
||||
if (x > 1.) {
|
||||
x = 1 / x;
|
||||
Invert = true;
|
||||
}
|
||||
double SQRT3 = 1.732050807568877294;
|
||||
// process shrinking the domain until x<PI/12
|
||||
while (x > Math.PI / 12) {
|
||||
sp++;
|
||||
a = x + SQRT3;
|
||||
a = 1 / a;
|
||||
x = x * SQRT3;
|
||||
x = x - 1;
|
||||
x = x * a;
|
||||
}
|
||||
// calculation core
|
||||
x2 = x * x;
|
||||
a = x2 + 1.4087812;
|
||||
a = 0.55913709 / a;
|
||||
a = a + 0.60310579;
|
||||
a = a - (x2 * 0.05160454);
|
||||
a = a * x;
|
||||
// process until sp=0
|
||||
while (sp > 0) {
|
||||
a = a + Math.PI / 6;
|
||||
sp--;
|
||||
}
|
||||
// invertation took place
|
||||
if (Invert) {
|
||||
a = Math.PI / 2 - a;
|
||||
}
|
||||
// sign change took place
|
||||
if (signChange) {
|
||||
a = -a;
|
||||
}
|
||||
//
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Реализация неточного алгоритма.
|
||||
* @param y
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static double aTan2(double y, double x) {
|
||||
double coeff_1 = Math.PI / 4d;
|
||||
double abs_y = Math.abs(y);
|
||||
double angle;
|
||||
if (x >= 0d) {
|
||||
double r = (x - abs_y) / (x + abs_y);
|
||||
angle = coeff_1 - coeff_1 * r;
|
||||
} else {
|
||||
double r = (x + abs_y) / (abs_y - x);
|
||||
double coeff_2 = 3d * coeff_1;
|
||||
angle = coeff_2 - coeff_1 * r;
|
||||
}
|
||||
return y < 0d ? -angle : angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Реализация точного алгоритма.
|
||||
* @param y
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static double atan2(double y, double x) {
|
||||
// if x=y=0
|
||||
if (y == 0. && x == 0.) {
|
||||
return 0.;
|
||||
}
|
||||
// if x>0 atan(y/x)
|
||||
if (x > 0.) {
|
||||
return atan(y / x);
|
||||
}
|
||||
// if x<0 sign(y)*(pi - atan(|y/x|))
|
||||
if (x < 0.) {
|
||||
if (y < 0.) {
|
||||
return -(Math.PI - atan(y / x));
|
||||
} else {
|
||||
return Math.PI - atan(-y / x);
|
||||
}
|
||||
}
|
||||
// if x=0 y!=0 sign(y)*pi/2
|
||||
if (y < 0.) {
|
||||
return -Math.PI / 2.;
|
||||
} else {
|
||||
return Math.PI / 2.;
|
||||
}
|
||||
}
|
||||
|
||||
public static double exp(double x) {
|
||||
if (x == 0.) return 1.;
|
||||
double f = 1;
|
||||
long d = 1;
|
||||
double k;
|
||||
boolean isless = (x < 0.);
|
||||
if (isless) x = -x;
|
||||
k = x / d;
|
||||
//
|
||||
for (long i = 2; i < 50; i++) {
|
||||
f += k;
|
||||
k *= (x / i);
|
||||
}
|
||||
//
|
||||
if (isless) return 1 / f;
|
||||
else return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Реализация быстрого, но неточного логарифма.
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static double log_v2(double x) {
|
||||
long l = Double.doubleToLongBits(x);
|
||||
long exp = ((0x7ff0000000000000L & l) >> 52) - 1023;
|
||||
double man = (0x000fffffffffffffL & l) / (double) 0x10000000000000L + 1.0;
|
||||
double lnm = 0.0;
|
||||
double a = (man - 1) / (man + 1);
|
||||
for (int n = 1; n < 7; n += 2) lnm += pow(a, n) / n;
|
||||
return 2 * lnm + exp * 0.69314718055994530941723212145818;
|
||||
}
|
||||
|
||||
/**
|
||||
* Реализация точного, но медленного логарифма.
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static double log(double x) {
|
||||
if (!(x > 0.)) {
|
||||
return Double.NaN;
|
||||
//
|
||||
}
|
||||
if (x == 1.0) {
|
||||
return 0.0;
|
||||
// Argument of _log must be (0; 1]
|
||||
}
|
||||
if (x > 1.) {
|
||||
x = 1 / x;
|
||||
return -_log(x);
|
||||
}
|
||||
//
|
||||
return _log(x);
|
||||
}
|
||||
|
||||
public static double pow(double base, int exp) {
|
||||
if (exp == 0) return 1;
|
||||
double res = base;
|
||||
for (; exp > 1; --exp) res *= base;
|
||||
return res;
|
||||
}
|
||||
|
||||
public static double pow(double x, double y) {
|
||||
if (y == 0.) return 1.;
|
||||
else if(y == 1.) return x;
|
||||
|
||||
if (x == 0.) return 0.;
|
||||
else if (x == 1.) return 1.;
|
||||
|
||||
long l = (long) Math.floor(y);
|
||||
boolean integerValue = (y == (double) l);
|
||||
//
|
||||
if (integerValue) {
|
||||
boolean neg = (y < 0.);
|
||||
double result = x;
|
||||
for (long i = 1; i < (neg ? -l : l); i++) {
|
||||
result = result * x;
|
||||
//
|
||||
}
|
||||
if (neg) {
|
||||
return 1. / result;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
if (x > 0.) return exp(y * log(x));
|
||||
else return Double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
private static double _log(double x) {
|
||||
if (!(x > 0.)) return Double.NaN;
|
||||
double f = 0.0;
|
||||
//
|
||||
int appendix = 0;
|
||||
while (x > 0.0 && x <= 1.0) {
|
||||
x *= 2.0;
|
||||
appendix++;
|
||||
}
|
||||
//
|
||||
x /= 2.0;
|
||||
appendix--;
|
||||
//
|
||||
double y1 = x - 1.;
|
||||
double y2 = x + 1.;
|
||||
double y = y1 / y2;
|
||||
//
|
||||
double k = y;
|
||||
y2 = k * y;
|
||||
//
|
||||
for (long i = 1; i < 50; i += 2) {
|
||||
f += k / i;
|
||||
k *= y2;
|
||||
}
|
||||
//
|
||||
f *= 2.0;
|
||||
for (int i = 0; i < appendix; i++) {
|
||||
f += LOGdiv2;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
}
|
111
src/com/annimon/TimeSpeakerUtil.java
Normal file
111
src/com/annimon/TimeSpeakerUtil.java
Normal file
@ -0,0 +1,111 @@
|
||||
package com.annimon;
|
||||
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/*
|
||||
* aNNiMON 2012
|
||||
* For more info visit http://annimon.com/
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class TimeSpeakerUtil {
|
||||
|
||||
private static final String[] NORMAL_1_TO_20 = {
|
||||
"Двенадцать", "Один", "Два", "Три", "Четыре", "Пять", "Шесть", "Семь",
|
||||
"Восемь", "Девять", "Десять", "Одиннадцать", "Двенадцать",
|
||||
"Тринадцать", "Четырнадцать", "Пятнадцать", "Шестнадцать",
|
||||
"Семнадцать", "Восемнадцать", "Девятнадцать", "Двадцать"
|
||||
};
|
||||
|
||||
private static final String[] NAMES_TEN = {
|
||||
"Десять", "Двадцать", "Тридцать", "Сорок", "Пятьдесят"
|
||||
};
|
||||
|
||||
private static final String[] NAMES_1_2 = {
|
||||
"Одна", "Две"
|
||||
};
|
||||
|
||||
private static final String[] NAMES_HOUR = {
|
||||
"Час", "Часа", "Часов"
|
||||
};
|
||||
|
||||
private static final String[] NAMES_MINUTE = {
|
||||
"Минут", "Минута", "Минуты"
|
||||
};
|
||||
|
||||
/**
|
||||
* Получить время
|
||||
* @return строка с временем вида: HH:MM
|
||||
*/
|
||||
public static String getTime() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
// Час
|
||||
int tmp = cal.get(Calendar.HOUR_OF_DAY);
|
||||
if(tmp <= 9) sb.append('0');
|
||||
sb.append(tmp);
|
||||
sb.append(':');
|
||||
// Минута
|
||||
tmp = cal.get(Calendar.MINUTE);
|
||||
if(tmp <= 9) sb.append('0');
|
||||
sb.append(tmp);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getTimeString() {
|
||||
System.out.println(getTime());
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
// Час
|
||||
int hour = cal.get(Calendar.HOUR_OF_DAY);
|
||||
appendHourString(sb, hour);
|
||||
// Минута
|
||||
int minute = cal.get(Calendar.MINUTE);
|
||||
appendMinuteString(sb, minute);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void appendHourString(StringBuffer sb, int hour) {
|
||||
int minHour = Math.min(hour, 20);
|
||||
sb.append(NORMAL_1_TO_20[minHour]); // 0..20
|
||||
if (hour > 20) sb.append(NORMAL_1_TO_20[hour % 20]); //21..23
|
||||
// Час
|
||||
if ( (hour == 1) || (hour == 21) ) sb.append(NAMES_HOUR[0]);
|
||||
else if ( ((1 < hour) && (hour <= 4)) || ((21 < hour) && (hour <= 23)) ) sb.append(NAMES_HOUR[1]);
|
||||
else sb.append(NAMES_HOUR[2]);
|
||||
}
|
||||
|
||||
private static void appendMinuteString(StringBuffer sb, int minute) {
|
||||
// Ноль минут нет
|
||||
if (minute == 0) return;
|
||||
|
||||
// От пяти до двадцати одинаково
|
||||
if ((5 <= minute) && (minute <= 20) ) {
|
||||
sb.append(NORMAL_1_TO_20[minute]);
|
||||
sb.append(NAMES_MINUTE[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Десятки минут
|
||||
int tenMinute = minute / 10;
|
||||
if (tenMinute != 0) sb.append(NAMES_TEN[tenMinute - 1]);
|
||||
|
||||
int modMinute = minute % 10;
|
||||
// Одна минута / две минуты
|
||||
if ( (modMinute == 1) || (modMinute == 2)) {
|
||||
sb.append(NAMES_1_2[modMinute - 1]);
|
||||
sb.append(NAMES_MINUTE[modMinute]);
|
||||
return;
|
||||
}
|
||||
// без десятков
|
||||
if (modMinute != 0) sb.append(NORMAL_1_TO_20[modMinute]);
|
||||
|
||||
// x2, x3, x4 минуты
|
||||
if ( (2 <= modMinute) && (modMinute <= 4) ) sb.append(NAMES_MINUTE[2]);
|
||||
else sb.append(NAMES_MINUTE[0]); // минут
|
||||
}
|
||||
}
|
55
src/com/annimon/TimeUtil.java
Normal file
55
src/com/annimon/TimeUtil.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.annimon;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class TimeUtil {
|
||||
|
||||
/**
|
||||
* Получить дату и время.
|
||||
* @return строка вида: YYYY-MM-DD HH:MM
|
||||
*/
|
||||
public static String getDateAndTime() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
StringBuffer time = new StringBuffer();
|
||||
|
||||
// Год
|
||||
int value = cal.get(Calendar.YEAR);
|
||||
time.append(value);
|
||||
time.append('-');
|
||||
|
||||
// Месяц
|
||||
value = cal.get(Calendar.MONTH) + 1;
|
||||
if (value < 10) time.append(0);
|
||||
time.append(value);
|
||||
time.append('-');
|
||||
|
||||
// День
|
||||
value = cal.get(Calendar.DAY_OF_MONTH);
|
||||
if (value < 10) time.append(0);
|
||||
time.append(value);
|
||||
time.append(' ');
|
||||
|
||||
// Час
|
||||
value = cal.get(Calendar.HOUR_OF_DAY);
|
||||
if (value < 10) time.append(0);
|
||||
time.append(value);
|
||||
time.append(':');
|
||||
|
||||
// Минута
|
||||
value = cal.get(Calendar.MINUTE);
|
||||
if (value < 10) time.append(0);
|
||||
time.append(value);
|
||||
time.append(':');
|
||||
|
||||
// Секунда
|
||||
value = cal.get(Calendar.SECOND);
|
||||
if (value < 10) time.append(0);
|
||||
time.append(value);
|
||||
|
||||
return time.toString();
|
||||
}
|
||||
}
|
182
src/com/annimon/image/Scale.java
Normal file
182
src/com/annimon/image/Scale.java
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* aNNiMON 2011
|
||||
* For more info visit http://annimon.com/
|
||||
*/
|
||||
package com.annimon.image;
|
||||
|
||||
import javax.microedition.lcdui.Image;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class Scale {
|
||||
|
||||
private int w, h;
|
||||
private int[] rawInput;
|
||||
|
||||
public Scale(Image src) {
|
||||
w = src.getWidth();
|
||||
h = src.getHeight();
|
||||
rawInput = new int[w * h];
|
||||
src.getRGB(rawInput, 0, w, 0, 0, w, h);
|
||||
}
|
||||
|
||||
public Scale(int[] pix, int w, int h) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.rawInput = pix;
|
||||
}
|
||||
|
||||
public Image scaleBresenham(int newWidth, int newHeight, boolean bgTrans) {
|
||||
int[] out = new int[newWidth * newHeight];
|
||||
|
||||
// YD compensates for the x loop by subtracting the width back out
|
||||
int YD = (h / newHeight) * w - w;
|
||||
int YR = h % newHeight;
|
||||
int XD = w / newWidth;
|
||||
int XR = w % newWidth;
|
||||
int outOffset = 0;
|
||||
int inOffset = 0;
|
||||
|
||||
for (int y = newHeight, YE = 0; y > 0; y--) {
|
||||
for (int x = newWidth, XE = 0; x > 0; x--) {
|
||||
out[outOffset++] = rawInput[inOffset];
|
||||
inOffset += XD;
|
||||
XE += XR;
|
||||
if (XE >= newWidth) {
|
||||
XE -= newWidth;
|
||||
inOffset++;
|
||||
}
|
||||
}
|
||||
inOffset += YD;
|
||||
YE += YR;
|
||||
if (YE >= newHeight) {
|
||||
YE -= newHeight;
|
||||
inOffset += w;
|
||||
}
|
||||
}
|
||||
return Image.createRGBImage(out, newWidth, newHeight, bgTrans);
|
||||
}
|
||||
|
||||
public Image scaleBresenhamSelf(int newWidth, int newHeight, boolean bgTrans) {
|
||||
int[] out = new int[newWidth * newHeight];
|
||||
|
||||
// YD compensates for the x loop by subtracting the width back out
|
||||
int YD = (h / newHeight) * w - w;
|
||||
int YR = h % newHeight;
|
||||
int XD = w / newWidth;
|
||||
int XR = w % newWidth;
|
||||
int outOffset = 0;
|
||||
int inOffset = 0;
|
||||
|
||||
for (int y = newHeight, YE = 0; y > 0; y--) {
|
||||
for (int x = newWidth, XE = 0; x > 0; x--) {
|
||||
out[outOffset++] = rawInput[inOffset];
|
||||
inOffset += XD;
|
||||
XE += XR;
|
||||
if (XE >= newWidth) {
|
||||
XE -= newWidth;
|
||||
inOffset++;
|
||||
}
|
||||
}
|
||||
inOffset += YD;
|
||||
YE += YR;
|
||||
if (YE >= newHeight) {
|
||||
YE -= newHeight;
|
||||
inOffset += w;
|
||||
}
|
||||
}
|
||||
return Image.createRGBImage(out, newWidth, newHeight, bgTrans);
|
||||
}
|
||||
|
||||
public Image scaleBilinear(int newWidth, int newHeight) {
|
||||
int orgMax = (w * h) - 1;
|
||||
|
||||
int[] out = new int[newWidth * newHeight];
|
||||
|
||||
int yd = (h / newHeight - 1) * w;
|
||||
int yr = h % newHeight;
|
||||
int xd = w / newWidth;
|
||||
int xr = w % newWidth;
|
||||
int outOffset = 0;
|
||||
int inOffset = 0;
|
||||
|
||||
// Whole pile of non array variables for the loop.
|
||||
int pixelA, pixelB, pixelC, pixelD;
|
||||
int xo, yo;
|
||||
int weightA, weightB, weightC, weightD;
|
||||
int redA, redB, redC, redD;
|
||||
int greenA, greenB, greenC, greenD;
|
||||
int blueA, blueB, blueC, blueD;
|
||||
int red, green, blue;
|
||||
|
||||
for (int y = newHeight, ye = 0; y > 0; y--) {
|
||||
for (int x = newWidth, xe = 0; x > 0; x--) {
|
||||
|
||||
// Set source pixels.
|
||||
pixelA = inOffset;
|
||||
pixelB = pixelA + 1;
|
||||
pixelC = pixelA + w;
|
||||
pixelD = pixelC + 1;
|
||||
|
||||
// Get pixel values from array for speed, avoiding overflow.
|
||||
pixelA = rawInput[pixelA];
|
||||
pixelB = pixelB > orgMax ? pixelA : rawInput[pixelB];
|
||||
pixelC = pixelC > orgMax ? pixelA : rawInput[pixelC];
|
||||
pixelD = pixelD > orgMax ? pixelB : rawInput[pixelD];
|
||||
|
||||
// Calculate pixel weights from error values xe & ye.
|
||||
xo = (xe << 8) / newWidth;
|
||||
yo = (ye << 8) / newHeight;
|
||||
weightD = xo * yo;
|
||||
weightC = (yo << 8) - weightD;
|
||||
weightB = (xo << 8) - weightD;
|
||||
weightA = 0x10000 - weightB - weightC - weightD;
|
||||
|
||||
// Isolate colour channels.
|
||||
redA = pixelA >> 16;
|
||||
redB = pixelB >> 16;
|
||||
redC = pixelC >> 16;
|
||||
redD = pixelD >> 16;
|
||||
greenA = pixelA & 0x00FF00;
|
||||
greenB = pixelB & 0x00FF00;
|
||||
greenC = pixelC & 0x00FF00;
|
||||
greenD = pixelD & 0x00FF00;
|
||||
blueA = pixelA & 0x0000FF;
|
||||
blueB = pixelB & 0x0000FF;
|
||||
blueC = pixelC & 0x0000FF;
|
||||
blueD = pixelD & 0x0000FF;
|
||||
|
||||
// Calculate new pixels colour and mask.
|
||||
red = 0x00FF0000 & (redA * weightA + redB * weightB + redC * weightC + redD * weightD);
|
||||
green = 0xFF000000 & (greenA * weightA + greenB * weightB + greenC * weightC + greenD * weightD);
|
||||
blue = 0x00FF0000 & (blueA * weightA + blueB * weightB + blueC * weightC + blueD * weightD);
|
||||
|
||||
// Store pixel in output buffer and increment offset.
|
||||
out[outOffset++] = red + (((green | blue) >> 16));
|
||||
|
||||
// Increment input by x delta.
|
||||
inOffset += xd;
|
||||
|
||||
// Correct if we have a roll over error.
|
||||
xe += xr;
|
||||
if (xe >= newWidth) {
|
||||
xe -= newWidth;
|
||||
inOffset++;
|
||||
}
|
||||
}
|
||||
|
||||
// Increment input by y delta.
|
||||
inOffset += yd;
|
||||
|
||||
// Correct if we have a roll over error.
|
||||
ye += yr;
|
||||
if (ye >= newHeight) {
|
||||
ye -= newHeight;
|
||||
inOffset += w;
|
||||
}
|
||||
}
|
||||
return Image.createRGBImage(out, newWidth, newHeight, false);
|
||||
}
|
||||
}
|
106
src/com/annimon/sensor/AccelUtil.java
Normal file
106
src/com/annimon/sensor/AccelUtil.java
Normal file
@ -0,0 +1,106 @@
|
||||
package com.annimon.sensor;
|
||||
|
||||
/*
|
||||
* aNNiMON 2011
|
||||
* For more info visit http://annimon.com/
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.microedition.io.Connector;
|
||||
import javax.microedition.sensor.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class AccelUtil implements DataListener {
|
||||
|
||||
private int[] channels;
|
||||
private String[] channelNames;
|
||||
private SensorConnection sensor;
|
||||
private String URL; //URL для коннекта
|
||||
private int numChannels; //количество каналов
|
||||
private int dataType; //тип приёма данных
|
||||
private double
|
||||
minValue,//минимальное значение
|
||||
maxValue; //максимальное значение
|
||||
|
||||
public AccelUtil() {
|
||||
getInfo();
|
||||
}
|
||||
|
||||
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);
|
||||
sensor.setDataListener(this, 1); //1 - размер буфера
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void dataReceived(SensorConnection sensor, Data[] data, boolean isDataLost) {
|
||||
//Обработка данных
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
//Получаем имя канала и сравниваем с сохраненными раннее
|
||||
//Данные получаем в виде int от -1024 до 1024
|
||||
for(int j = 0; j < numChannels; j++) {
|
||||
String name = data[i].getChannelInfo().getName();
|
||||
if (name.equals(channelNames[j])) {
|
||||
channels[j] = getValue(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Преобразование в 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;
|
||||
}
|
||||
}
|
219
src/com/annimon/ui/TextViewer.java
Normal file
219
src/com/annimon/ui/TextViewer.java
Normal file
@ -0,0 +1,219 @@
|
||||
package com.annimon.ui;
|
||||
|
||||
/*
|
||||
* aNNiMON 2010
|
||||
* For more info visit http://annimon.com/
|
||||
*/
|
||||
|
||||
/*
|
||||
* На основе класса MultiLineText от А.С. Ледкова
|
||||
* www.mobilab.ru
|
||||
*/
|
||||
import java.util.Vector;
|
||||
import javax.microedition.lcdui.Canvas;
|
||||
import javax.microedition.lcdui.Font;
|
||||
import javax.microedition.lcdui.Graphics;
|
||||
import javax.microedition.lcdui.Image;
|
||||
|
||||
public class TextViewer extends Canvas {
|
||||
|
||||
/** Размер экрана */
|
||||
private int w, h;
|
||||
|
||||
/** Размер шрифта */
|
||||
private int defHeight;
|
||||
|
||||
/** Максимальная высота выводимого текста */
|
||||
private int maxHeight;
|
||||
|
||||
/** Высота, с которой будет отрисовываться текст */
|
||||
private int minHeight;
|
||||
|
||||
/** Шаг при прокрутке текста */
|
||||
private int stepY;
|
||||
|
||||
/** Текущая высота текста */
|
||||
private int textHeight;
|
||||
|
||||
/** Фон */
|
||||
private Image background;
|
||||
|
||||
/** Шрифт */
|
||||
private Font def;
|
||||
|
||||
/** Массив строк */
|
||||
private Vector strLines;
|
||||
|
||||
|
||||
public TextViewer(String path) {
|
||||
setFullScreenMode(true);
|
||||
w = getWidth();
|
||||
h = getHeight();
|
||||
def = Font.getDefaultFont();
|
||||
stepY = defHeight = def.getHeight() + 2;
|
||||
maxHeight = h - defHeight - 1;
|
||||
initParameters(path);
|
||||
|
||||
}
|
||||
|
||||
public void setTitle(String s) {
|
||||
super.setTitle(s);
|
||||
}
|
||||
|
||||
public void setBackground(Image image) {
|
||||
background = image;
|
||||
}
|
||||
|
||||
protected void paint(Graphics g) {
|
||||
g.drawImage(background, 0, 0, Graphics.LEFT | Graphics.TOP);
|
||||
g.setFont(def);
|
||||
g.setColor(0xFFFFFF);
|
||||
g.drawString(getTitle(), w / 2, 1, 17);
|
||||
g.setClip(0, defHeight + 1, w, maxHeight);
|
||||
|
||||
int y1 = minHeight;
|
||||
|
||||
for (int i = 0; i < strLines.size(); i++) {
|
||||
if ((y1 + defHeight) > 0) {
|
||||
g.drawString(strLines.elementAt(i).toString(), 1, defHeight + 5 + y1, Graphics.LEFT | Graphics.TOP);
|
||||
}
|
||||
|
||||
y1 = y1 + defHeight;
|
||||
|
||||
if (y1 > maxHeight) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g.setClip(0, 0, w, h);
|
||||
}
|
||||
|
||||
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) || (key == KEY_STAR)) {
|
||||
// Back
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Расчет параметров
|
||||
*/
|
||||
private void initParameters(String path) {
|
||||
|
||||
// Разбиваем строку на массив строк
|
||||
strLines = new Vector();
|
||||
|
||||
String str = null;//Util.getText(path, true);
|
||||
String[] arr = null;//Util.splitString(str, "\n");
|
||||
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
String substr = arr[i];
|
||||
int i0 = 0,
|
||||
in = 0,
|
||||
jw = 0; // Смещение от начала строки
|
||||
int imax = substr.length(); // Длина строки
|
||||
boolean isexit = true;
|
||||
|
||||
minHeight = 0;
|
||||
|
||||
while (isexit) {
|
||||
int space = substr.indexOf(" ", i0 + 1);
|
||||
|
||||
if (space <= i0) {
|
||||
space = imax;
|
||||
isexit = false;
|
||||
}
|
||||
|
||||
int 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 void moveDown() {
|
||||
if (textHeight > maxHeight) {
|
||||
minHeight = minHeight - stepY;
|
||||
|
||||
if (maxHeight - minHeight > textHeight) {
|
||||
minHeight = maxHeight - textHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveUp() {
|
||||
if (textHeight > maxHeight) {
|
||||
minHeight = minHeight + stepY;
|
||||
|
||||
if (minHeight > 0) {
|
||||
minHeight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void pageUp() {
|
||||
if (textHeight > maxHeight) {
|
||||
minHeight = minHeight + maxHeight;
|
||||
|
||||
if (minHeight > 0) {
|
||||
minHeight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void pageDown() {
|
||||
if (textHeight > maxHeight) {
|
||||
minHeight = minHeight - maxHeight;
|
||||
|
||||
if (maxHeight - minHeight > textHeight) {
|
||||
minHeight = maxHeight - textHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
210
src/com/next9/TextGraphics.java
Normal file
210
src/com/next9/TextGraphics.java
Normal file
@ -0,0 +1,210 @@
|
||||
package com.next9;
|
||||
|
||||
import java.util.Vector;
|
||||
import javax.microedition.lcdui.Font;
|
||||
import javax.microedition.lcdui.Graphics;
|
||||
import javax.microedition.lcdui.Image;
|
||||
|
||||
/**
|
||||
* Класс для вывода текста.
|
||||
*
|
||||
* @author Next9
|
||||
* @author aNNiMON
|
||||
* @version 4.0
|
||||
*/
|
||||
public class TextGraphics {
|
||||
|
||||
private Font font;
|
||||
private Graphics G;
|
||||
private Image image;
|
||||
private Image background;
|
||||
private String fullText;
|
||||
private Vector lines;
|
||||
|
||||
private boolean scrollBarShow;
|
||||
private int width, height;
|
||||
private int textColor;
|
||||
private int backgroundColor;
|
||||
private int scrollBarColor;
|
||||
private int fontHeight;
|
||||
private int fullTextHeight;
|
||||
private int currentLine;
|
||||
private int linesCount;
|
||||
|
||||
|
||||
public TextGraphics(int width, int height, Font font) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
if (font == null) {
|
||||
font = Font.getDefaultFont();
|
||||
}
|
||||
this.font = font;
|
||||
|
||||
scrollBarShow = true;
|
||||
textColor = 0x00;
|
||||
scrollBarColor = 0x00;
|
||||
backgroundColor = 0xFFFFFF;
|
||||
currentLine = 0;
|
||||
lines = new Vector();
|
||||
fontHeight = font.getHeight();
|
||||
fullTextHeight = height / fontHeight;
|
||||
|
||||
image = Image.createImage(width, height);
|
||||
G = image.getGraphics();
|
||||
G.setFont(font);
|
||||
}
|
||||
|
||||
public String getScreenText() {
|
||||
StringBuffer out = new StringBuffer();
|
||||
int endText = Math.min(currentLine + fullTextHeight, linesCount);
|
||||
for (int i = currentLine; i < endText; i++) {
|
||||
out.append((String) lines.elementAt(i));
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public void setScreenText(String text) {
|
||||
fullText = text;
|
||||
process(currentLine, Math.min(currentLine + fullTextHeight, linesCount), true);
|
||||
}
|
||||
|
||||
public void setShowScrollBar(boolean scrollbar) {
|
||||
this.scrollBarShow = scrollbar;
|
||||
}
|
||||
|
||||
public boolean isShowScrollBar() {
|
||||
return scrollBarShow;
|
||||
}
|
||||
|
||||
public String getAllText() {
|
||||
StringBuffer out = new StringBuffer();
|
||||
for (int i = 0; i < linesCount; i++) {
|
||||
out.append((String) lines.elementAt(i));
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public void setBackgroundImage(Image image) {
|
||||
background = image;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(int color) {
|
||||
backgroundColor = color;
|
||||
}
|
||||
|
||||
public void setTextColor(int color) {
|
||||
textColor = color;
|
||||
}
|
||||
|
||||
public void setScrollBarColor(int color) {
|
||||
scrollBarColor = color;
|
||||
}
|
||||
|
||||
public void append(String text) {
|
||||
this.fullText = text;
|
||||
process(0, 0, false);
|
||||
}
|
||||
|
||||
public Image paint() {
|
||||
G.setColor(backgroundColor);
|
||||
G.fillRect(0, 0, width, height);
|
||||
if (background != null) {
|
||||
G.drawImage(background, 0, 0, 20);
|
||||
}
|
||||
G.setColor(textColor);
|
||||
|
||||
if (linesCount != 0) {
|
||||
final int endText = Math.min(fullTextHeight, linesCount);
|
||||
for (int linePos = 0; linePos < endText; linePos++) {
|
||||
String textLine = (String) lines.elementAt(currentLine + linePos);
|
||||
if (textLine == null) {
|
||||
textLine = " ";
|
||||
} else if (textLine.endsWith("\n")) {
|
||||
textLine = textLine.substring(0, textLine.length() - 1);
|
||||
}
|
||||
G.drawString(textLine, 0, linePos * fontHeight, 20);
|
||||
}
|
||||
|
||||
G.setColor(backgroundColor);
|
||||
G.fillRect(width - 2, 0, 3, height);
|
||||
if (scrollBarShow) {
|
||||
G.setColor(scrollBarColor);
|
||||
G.drawLine(width - 2, 0, width - 2, height);
|
||||
G.drawRect(width - 3, currentLine * height / linesCount, 2, (fullTextHeight - 1) * height / linesCount);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public void lineUp() {
|
||||
if (currentLine > 0) {
|
||||
currentLine--;
|
||||
}
|
||||
}
|
||||
|
||||
public void lineDown() {
|
||||
if (currentLine < linesCount - fullTextHeight) {
|
||||
currentLine++;
|
||||
}
|
||||
}
|
||||
|
||||
public void screenUp() {
|
||||
if (currentLine < fullTextHeight) {
|
||||
currentLine = 0;
|
||||
} else {
|
||||
currentLine -= fullTextHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public void screenDown() {
|
||||
if (currentLine < linesCount - 2 * fullTextHeight + 1) {
|
||||
currentLine += fullTextHeight;
|
||||
} else {
|
||||
currentLine = linesCount - fullTextHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
linesCount = 0;
|
||||
currentLine = 0;
|
||||
lines.removeAllElements();
|
||||
}
|
||||
|
||||
private void process(int removeFrom, int removeTo, boolean edit) {
|
||||
int ed = removeFrom;
|
||||
if (edit) {
|
||||
for (int q = removeFrom; q < removeTo; q++) {
|
||||
lines.removeElementAt(removeFrom);
|
||||
}
|
||||
}
|
||||
while (fullText != null && fullText.length() != 0) {
|
||||
int col = 0;
|
||||
int x = 0;
|
||||
while (x + font.charWidth(fullText.charAt(col)) <= width - 2) {
|
||||
x += font.charWidth(fullText.charAt(col));
|
||||
col++;
|
||||
if (fullText.length() == col || fullText.charAt(col - 1) == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (edit) {
|
||||
lines.insertElementAt(fullText.substring(0, col), ed);
|
||||
} else {
|
||||
lines.addElement(fullText.substring(0, col));
|
||||
}
|
||||
if (fullText.length() != col) {
|
||||
fullText = fullText.substring(col, fullText.length());
|
||||
} else {
|
||||
fullText = null;
|
||||
}
|
||||
ed++;
|
||||
}
|
||||
linesCount = lines.size();
|
||||
if (edit && linesCount > fullTextHeight && currentLine > linesCount - fullTextHeight && linesCount - fullTextHeight >= 0) {
|
||||
currentLine = linesCount - fullTextHeight;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user