Howdyho!
I'm using a mortscript to "control" an assortment of applications that together form a semi-proper landscape "fix" for the SE X1.
Currently, I'm having not one but two problems with it, of which one is a major one.
Lets start out small;
1) The script sometimes needs to refer to files. Is there any way I can use the %CE% codes to point it in the right direction? I need this to make it localization independent, without having to place it in the windows folder.
2) Measured with SKTools' CPU monitor, it turns out that my script uses ~15 to 20% CPU (From a 528mhz Qualcomm in the X1!!) power!
How the hell can this be? All I do is change some registry values and check for some variables on a 1sec loop.
As I'm very new to mortscript, perhaps someone can help me improve my code?
Thanks in advance!
Code:
# Created by Angelusz
# Special thanks to Chalid andKarlsson2k as it's based on their initial code.
# Note: Using this script will disable the hardware camera button.
RegWriteDWord("HKCU","Software\AnX1","IsLandscape",0)
RegWriteDWord("HKCU","Software\AnX1","IsScript",0)
RegWriteDWord("HKCU","Software\ANX1","IsManila",0)
RegWriteDWord("HKCU","Software\ANX1","IsAnX1",0)
RegWriteDWord("HKCU","Software\ANX1","IsCamera",0)
RegWriteDWord("HKCU","Software\ANX1","IsPrevented",0)
If(Screen("landscape"))
RegWriteDWord("HKCU","Software\ANX1","IsLandscape",1)
EndIf
While((ProcExists("manila.exe")=0) AND ((ProcExists("_mpman.exe")=0)))
Sleep(1000)
EndWhile
while((ProcExists("manila.exe")) OR (ProcExists("_mpman.exe")))
Sleep(1000)
If(ProcExists("SecondToday.exe")=0)
Run("Windows\AnX1\TF3DLandscape\Modules\SecondToday\SecondToday.exe")
Sleep(500)
EndIf
RegWriteDWord("HKCU","Software\ANX1","IsAnX1",0)
RegWriteDWord("HKCU","Software\ANX1","IsCamera",0)
RegWriteDWord("HKCU","Software\ANX1","IsManila",0)
If(ActiveWindow() eq "Start")
RegWriteDWord("HKCU","Software\ANX1","IsManila",1)
ElseIf(ActiveWindow() eq "AnX1Landscape")
RegWriteDWord("HKCU","Software\ANX1","IsAnX1",1)
ElseIf(ActiveWindow() eq "Camera")
RegWriteDWord("HKCU","Software\ANX1","IsCamera",1)
EndIf
RegWriteDWord("HKLM","System\GDI\Rotation","CamAppActive",0)
IsRotated=RegRead("HKLM","System\GDI\Rotation","SlideKey")
IsScript=RegRead("HKCU","Software\AnX1","IsScript")
IsLandscape=RegRead("HKCU","Software\AnX1","IsLandscape")
IsManila=RegRead("HKCU","Software\AnX1","IsManila")
IsAnX1=RegRead("HKCU","Software\AnX1","IsAnX1")
IsCamera=RegRead("HKCU","Software\AnX1","IsCamera")
IsPrevented=RegRead("HKCU","Software\AnX1","IsPrevented")
If((IsManila) OR (IsAnX1) OR (IsCamera))
RegWriteDWord("HKLM","System\GDI\Rotation","CamAppActive",1)
EndIf
If(((IsScript) OR (IsRotated)) OR ((IsScript) AND (IsRotated)))
If(IsManila)
If(IsPrevented)
RegWriteDWord("HKLM","System\GDI\Rotation","CamAppActive",1)
Else
If(IsLandscape=0)
RegWriteDWord("HKCU","Software\AnX1","IsLandscape",1)
Show("AnX1Landscape")
If(Screen("portrait")=1)
Rotate(270)
EndIf
Else
If(IsAnX1=0)
Show("AnX1Landscape")
EndIf
If(Screen("portrait")=1)
Rotate(270)
EndIf
EndIf
EndIf
Else
If(IsAnX1=0)
If(IsLandscape=0)
Minimize("AnX1Landscape")
Rotate(270)
RegWriteDWord("HKCU","Software\ANX1","IsLandscape",1)
EndIf
Else
If(Screen("portrait")=1)
Rotate(270)
EndIf
EndIf
EndIf
ElseIf((IsScript=0) AND (IsRotated=0))
If(IsAnX1=0)
Minimize("AnX1Landscape")
EndIf
If((Screen("landscape")=1) AND (IsCamera=0))
Rotate(0)
EndIf
RegWriteDWord("HKCU","Software\ANX1","IsLandscape",0)
EndIf
EndWhile
RegWriteDWord("HKLM","System\GDI\Rotation","CamAppActive",0)
While((ProcExists("manila.exe")=0) AND ((ProcExists("_mpman.exe")=0)))
Sleep(1000)
EndWhile
CallScript("\Windows\AnX1\TF3DLandscape\AnX1LS.mscr")
Can anyone please take a look at it for me?
Related
On this page: http://msdn2.microsoft.com/en-us/library/aa926591.aspx it lists the default DSCP settings used by the RTC Client in Windows Mobile 6. The default DSCP value for SIP signalling an RTP media is 0x38 (or DSCP 56, IP Precedence 7). I wish to change this however adding the relevent values to the registry does not change what DSCP values are set; they always remain at 0x38:
Code:
REGEDIT4
[HKEY_LOCAL_MACHINE\Comm\RTC\QoS]
"Disabled"=dword:00000000
"DSCPSIP"=dword:00000018
"DSCPAudioRTP"=dword:0000002e
"DSCPAudioRTCP"=dword:0000002e
This should in theory set DSCP 24 (0x18) or SIP Signalling packets and DSCP 46 (0x2e) for RTP & RTCP packets. I have made the registry changes, left it for a while and soft-reset. Following bootup I have checked that the settings are stored in the registry, however if I make a call and capture the traffic I can still only see DSCP being set to 56 (0x38). Has anyone else played around with the QoS settings?
I am using version 5.2.318 (Build 15342) with the replacement VoIP files to get around the issue with L2TP/IPSec.
Andy
VoipSipSdk
VoipSipSdk
I am now looking for voip solutions. And found information about Voip sdk.
According to their website www.voipsipsdk.com
Voip sdk is based on IETF standards (SIP, STUN, etc.), so it should be compatible with other standard based products such as Asterisk, OpenSER other.
They have all features I need:
# Dynamically loadable codecs
# Registrar support
# Play wav files into conversation
# Record conversation into file
# Hold/Retrieve call
# Forward Call (Blind Call Transfer)
# Transfer Call (Attended Transfer)
# Mute Sound
# VPN support
# Noise reduction
# Auto gain
# Jitter buffer parameters
# Samples on Delphi, C#, VB, VB.NET, C++ 2005, C++ 6.0, HTML (SIP ActiveX)
# Windowless samples on C++ and .NET
# DTMF
# Adaptive silence detection
# Adaptive jitter buffer
# STUN support
# Comes as ActiveX control
But before I will download the evaluation version I would like to hear other people experience.
Ok, I didn't like to open a new thread about OBEX and android, but, as I explain in this post http://forum.xda-developers.com/showpost.php?p=3932525&postcount=57 , I got OBEX working in my G1, and now I'm thinking about integrating a clean and elegant OBEX support into our ROMS.
Yes, there is already an application in the market for receiving and sending files via OBEX, but I simply don't like to pay for a feature that should be supported by default in every mobile phone.
I was wondering how would be the first approach for integrating the obexserver by default, and it would be really easy executing at boot time something like:
Code:
sdptool add --channel=4 OPUSH
test -d /sdcard/bluetooth_received || mkdir /sdcard/bluetooth_received
cd /sdcard/bluetooth_received && ( while true; do obexserver; done ) &
The only problem, is that disabling bluetooth and enabling it again, it loses the OPUSH service added by sdptool.
So, I'm now trying to find a way to tell the bluetooth daemons that they should add the OPUSH service when they are enabled, and here is where I need your help. Anybody knows how can this be done?
Also, another way would be simply executing a GScript when the OPUSH service is needed.
What do you think?
Thanks!
EDIT: Here is a simple script that enables the OBEX profile and receives 1 file. It is necessary to re-execute it to receive more files.
obex_get.sh:
Code:
#!/system/bin/sh
obex_status=`sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push|^Failed to connect"`
case "$obex_status" in
Failed*)
# bt disabled
echo "Please, enable bluetooth first!"
exit
;;
"")
# bt enabled, but no OPUSH profile
sdptool add --channel=4 OPUSH
;;
*)
# bt enabled, opush enabled
;;
esac
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
cd /sdcard/bluetooth_downloads && obexserver
EDIT: Daemonized version of the script. It can be run as service at boot time, and every 3 seconds it will check if the opush profile has been lost.
Code:
#!/system/bin/sh
# create the download directory if it doesn't exist
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
while sleep 3; do
# get bluetooth status
hcid_status_now="`getprop init.svc.hcid`"
# do nothing if bluetooth is stopped
test "$hcid_status_now" == "stopped" && continue
# if bluetooth is enabled, get opush profile status
obex_status=`sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push|^Failed to connect"`
case "$obex_status" in
"")
# bt enabled, but no OPUSH profile
sdptool add --channel=4 OPUSH; echo
;;
Failed*)
# bt disabled
#echo "Please, enable bluetooth first!"; echo
continue
;;
*)
# bt enabled, opush enabled
;;
esac
# if obexserver isn't already running, execute it.
pidof obexserver >/dev/null || ( cd /sdcard/bluetooth_downloads && obexserver ) &
done
EDIT: Ok, a definitely better version of the daemon:
Code:
#!/system/bin/sh
# create the download directory if it doesn't exist
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
# in case /sdcard/bluetooth_downloads already exists, and is not a directory. Exit
test -d /sdcard/bluetooth_downloads || exit
# execute the obexserver loop (for it to be multifile)
( cd /sdcard/bluetooth_downloads && while true; do obexserver; done ) &
# execute the sdptool add OPUSH loop
while sleep 3; do
# get bluetooth status
hcid_status_now="`getprop init.svc.hcid`"
# do nothing if bluetooth is stopped
test "$hcid_status_now" == "stopped" && continue
# if bluetooth is enabled and no obex profile exists, add it
sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push" >/dev/null || sdptool add --channel=4 OPUSH
done
Still don't like to query the "sdptool browse local" every 3 seconds
Bugs and corrections are welcome.
juanmasg said:
Ok, I didn't like to open a new thread about OBEX and android, but, as I explain in this post http://forum.xda-developers.com/showpost.php?p=3932525&postcount=57 , I got OBEX working in my G1, and now I'm thinking about integrating a clean and elegant OBEX support into our ROMS.
Yes, there is already an application in the market for receiving and sending files via OBEX, but I simply don't like to pay for a feature that should be supported by default in every mobile phone.
I was wondering how would be the first approach for integrating the obexserver by default, and it would be really easy executing at boot time something like:
Code:
sdptool add --channel=4 OPUSH
test -d /sdcard/bluetooth_received || mkdir /sdcard/bluetooth_received
cd /sdcard/bluetooth_received && ( while true; do obexserver; done ) &
The only problem, is that disabling bluetooth and enabling it again, it loses the OPUSH service added by sdptool.
So, I'm now trying to find a way to say the bluetooth daemons that they should add the OPUSH service when they are enabled, and here is where I need your help. Anybody knows how can this be done?
Also, another way would be simply executing a GScript when the OPUSH service is needed.
What do you think?
Thanks!
Click to expand...
Click to collapse
I am not really sure how the bluetooth stack works, but does the OPUSH profile has its own process or it there someway to detect its presence?
If so we could easily implement some detecting mechanism in the loop body.
Another possibility is to check the error returned by obexserver if it implements any.
im gonna check out the source tree for you, cause i was just looking last night. i will post again as a read into the source a lot more
billc.cn said:
I am not really sure how the bluetooth stack works, but does the OPUSH profile has its own process or it there someway to detect its presence?
If so we could easily implement some detecting mechanism in the loop body.
Another possibility is to check the error returned by obexserver if it implements any.
Click to expand...
Click to collapse
The obex profile does not have it's own process, sdptool simply enables it in one of the bluez daemons (don't know which of them)
The "problem" here is that obexserver does not get any error when I disable bluetooth, it simply continues waiting for a connection. I'll try to look at the openobex API to see if we can get the bluetooth status or force some error. Sorry, my knowledgement about the bluetooth protocol is quite limited.
The curious thing about this, is that if I execute obexserver, disable bt, re-enable bt, and add the opush profile, without restarting the obexserver it still works.
juanmasg said:
The obex profile does not have it's own process, sdptool simply enables it in one of the bluez daemons (don't know which of them)
The "problem" here is that obexserver does not get any error when I disable bluetooth, it simply continues waiting for a connection. I'll try to look at the openobex API to see if we can get the bluetooth status or force some error. Sorry, my knowledgement about the bluetooth protocol is quite limited.
The curious thing about this, is that if I execute obexserver, disable bt, re-enable bt, and add the opush profile, without restarting the obexserver it still works.
Click to expand...
Click to collapse
so maybe this is running on a seperate process? no its entirely own, but maybe a child process? seems kinda weird to me... and its gonna be a while before i can start checking this out along with you, i need to re-download the android repo >.<
As long as you have that script that has to be run every time you want 1 file, would it be possible to do that every, say, 3 seconds in a loop? Maybe even have an obex app where you can press a button to have the script start running the loop and press again to kill the process. I'm thinking something similar to the wifi tether for root users in terms of interface.
EDIT: so something similar to this in terms of scriptage(can't remember the exact syntax for loops)
Code:
while 1
do
#!/system/bin/sh
obex_status=`sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push|^Failed to connect"`
case "$obex_status" in
Failed*)
# bt disabled
echo "Please, enable bluetooth first!"
exit
;;
"")
# bt enabled, but no OPUSH profile
sdptool add --channel=4 OPUSH
;;
*)
# bt enabled, opush enabled
;;
esac
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
cd /sdcard/bluetooth_downloads && obexserver
sleep 3;
done;
corp769 said:
so maybe this is running on a seperate process? no its entirely own, but maybe a child process? seems kinda weird to me...
Click to expand...
Click to collapse
I think that we shouldn't monitor the obex profile status, but spawn the profile activation when bluetooth gets active. This will be more efficient.
We can monitor the bluetooth status with "getprop init.svc.hcid". This could be used in the script loop, but it would save a lot of work if we simply could (de)activate it when the bluetooth gets enabled or disabled.
I'm looking at /etc/bluez in the G1 and in my linux desktop to see if some file could do the magic.
i need to re-download the android repo
Click to expand...
Click to collapse
be patient my friend
Can't you just do this from init with the other daemons?
service hfag /system/bin/sdptool add --channel=10 HFAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
service hsag /system/bin/sdptool add --channel=11 HSAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
...etc
haha, i have no patience man, i'm in the military, and patience is not a virtue to me, i just want to get sh*t done
as far as what you are talking about, i understand what you mean. i'm also looking at the obex source in my linux distro (fedora 10) and kinda pondering if we could write a completely new routine (as a script for now of course) that would only be called when we need it, as in running it at boot and run in the background constantly. that hopefully wouldn't run up the processor tho...
and by the way, i would really like to help in everyway because i always wanted bluetooth file transfer on my G1
cyanogen said:
Can't you just do this from init with the other daemons?
service hfag /system/bin/sdptool add --channel=10 HFAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
service hsag /system/bin/sdptool add --channel=11 HSAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
...etc
Click to expand...
Click to collapse
Already tried that, but didn't work . Those "services" seem to be requested by the a2dp daemon when it starts, and the a2dp daemon starts and stops when bluetooth is enabled or disabled, so we still would need to get our daemon spawned with all the bluetooth stuff.
Thanks anyways.
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
cyanogen said:
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
Click to expand...
Click to collapse
Thanks cyanogen, that is what I was looking for.
I wanted to avoid to recompile the android core server, but It seems that we'll have to :-/.
cyanogen said:
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
Click to expand...
Click to collapse
Exactly. Let's add the opush service here...
I'd love to patch it into my next ROM release
I added to the first post a modified version of the script that can be run as a "daemon".
Anyway, the way to implement this seems to be patching BluetoothDeviceService.java.
cyanogen said:
I'd love to patch it into my next ROM release
Click to expand...
Click to collapse
Can't wait for it
As for sending files, I was thinking about creating a mime handler that could be used with, p.e Filer (http://android.hlidskialf.com/software/filer) so that it could be able to send files via OBEX also.
Any idea?
cyanogen said:
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
Click to expand...
Click to collapse
The more I think about it, the more I feel, that it should be done in ObexServer initialisation (ObexServer.java) ... which should be started from BluetoothDeviceService
here is my question... ok, we have the obex server for receiving files. now as far as sending files, how will that be set up? like will it be a seperate script to run the program, or will it be combined with the obex server?
an idea or two... juan, you mentioned about setting up a mime handler to send files. what it be possible to set up the handler for both receiving and sending files? it could most definitely be accomplished by creating a whole separate APK, and have that register the handles for the system, running as a service in the background. also we could use that for a graphical interface in the long run after we get the basics down pat, and have a file browser for sending files. i know this is jumping the gun, but it is all my ideas i have going on. on that note though, i think it would be the best way, unless you have a better idea
EDIT: now that i think of it, the APK would be best off other wise so we wouldnt have to have everyone who wants file transfer to reflash their whole phone just for a partially modified kernel
corp769 said:
EDIT: now that i think of it, the APK would be best off other wise so we wouldnt have to have everyone who wants file transfer to reflash their whole phone just for a partially modified kernel
Click to expand...
Click to collapse
I'd rather make part of the framework ready to be accepted by the AOSP than some kind of hack running only on rooted devices. Which brings another question: I was just starting to port the obexserver, when I realized that the OpenOBEX library is licensed under LGPL ... can we use it?
hello,
I'm writing a Android App (java) - but I guess this question is pretty general, and isn't java-specific:
so I have an Array of Elements
and I let a random-number-generator pick one array-element randomly and hand it to me.
now I've also built in a "score"-field into each array Element
so what I want to do now, is that the random-number-generator takes the array's "score" in consideration, and gives me the array-elements with the higher/lower scores with a higher/lower probability
I dont want it to ALWAYS/NEVER give me the elements with the highest/lowest score - just with a higher/lower probability
I hope I could describe my problem in a proper way....
does anybody know how to achieve this?
(as I said, i use java, but i guess code in any language - or even pseudo-code would help me out)
*bump*
anybody?
Try this, it's in C# but it's pretty close to Java.
You cannot directly weight the random function so you have to use a different method.
By applying a weight to each item in the array, then using a random function to select using the weighting values, the results of the selection can be swayed.
The weighting values are relative to each other.
Using the values in the code, 'B' should turn up about three times more often than 'A'
The only object that may need some explanation is Random:
http://msdn.microsoft.com/en-us/library/system.random(v=VS.80).aspx
Code:
using System;
namespace RandomWeighting
{
class Program
{
static void Main(string[] args)
{
char[] Select = new char[10] {'A','B','C','D','E','F','G','H','I','J'};
int[] Weight = new int[10] {10,30,25,60,20,70,10,80,20,30};
int[] WeightSum = new int[10];
int i,j,k;
Random Rnd = new Random();
WeightSum[0]=Weight[0];
for (i = 1; i < 10; i++)
WeightSum[i] = WeightSum[i - 1] + Weight[i];
for (j = 0; j < 70; j++)
{
k = Rnd.Next(WeightSum[9]);
for (i = 0; k > WeightSum[i]; i++) ;
Console.Write(Select[i]);
}
Console.WriteLine();
}
}
}
Output:
Code:
HEFIBHHCCFBCAEFFDHACHBEJHHFDFIDFEDFFCHHDJBIDJEHHFHCJJJBHJGBDDGFDDFHHHB
Note the low density of A and G as opposed to H
It is just a sample at random, but 2 'A's and 7 'B's roughly matches the conjecture above, but over a million selections, the distribution is as follows:
Code:
A 30664
B 84187
C 70648
D 168481
E 56529
F 197311
G 28145
H 225764
I 56613
J 81658
If your code changes values in the Weight array then the WeightSum array must be recalculated.
wow, thats a lot!
The only thing I dont understand about the code is this line:
k = Rnd.Next(WeightSum[9]);
for (i = 0; k > WeightSum; i++) ;
what exactly happens here?
what kind of a for-loop is this?
why is there no body?
and strangely, while debugging this line, i noticed that the value of i jumps to some random number in this line - and I have no idea why and how
------
by the way: I've already tried it out, it works pretty good.
although I noticed that the first element always gets picked ALOT, no matter how low the weight.
I think thats a flaw in the algorithm
After the following code:
Code:
for (i = 1; i < 10; i++)
WeightSum[i] = WeightSum[i - 1] + Weight[i];
The WeightSum array contains the following values:
Code:
[0] 10
[1] 40
[2] 65
[3] 125
[4] 145
[5] 215
[6] 225
[7] 305
[8] 325
[9] 355
The Random.Next() function that takes a single integer as an argument is defined as:
-------- Courtesy of MS VS .NET Help ------
public virtual int Next(int maxValue)
Parameters maxValue Type: System.Int32
The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to zero.
Return Value Type: System.Int32
A 32-bit signed integer greater than or equal to zero, and less than maxValue; that is, the range of return values ordinarily includes zero but not maxValue. However, if maxValue equals zero, maxValue is returned.
-------------- End of Help ----------------
So, we are asking for a random value between 0 and 354,(element WeightSum[9] above). The following code then finds which is the lowest element of WeightSum which holds a value greater than the one we have been given. When this happens 'i' contains the index to use for the selection.
Code:
for (i = 0; k > WeightSum[i]; i++);
The standard construction of a for loop in C is
for(One or more initialisation statements; Do_While_True Condition; One or more iteration statements)
{
loop processing code;
}
If there is nothing to do in the loop body, you don't need it, and you can replace it with the ';' at the end of the for statement. In effect, it is identical to the following code:-
Code:
i=0;
while(k > WeightSum[i])
{
i++;
}
As regards the first element being picked more than the others, have a look at the distribution table in post #3. It is what you would expect for the values given. I assume the difference is either the Random function in Java or some different implementation between C# and Java.
You may have to change some of the code slightly, i.e. change the for() loop to the while() loop above and step though it in the Java debugger to get to the root of the problem.
You can't debug a for loop followed by an immediate ';' The entire for loop is executed to completion when you use debug and try and step through it. To debug it place a dummy statement in the for loop. A breakpoint may now be set on this line.
Code:
int i,z;
for (i = 0; k > WeightSum[i]; i++)
{
z=0;
}
ActionScript and Javascript versions ...
Thanks for the great write-up! In case anyone is interested, I've adapted this into a javascript and ActionScript class. If anyone is interested, I've attached the code. For a more in-depth post, check out blog.teamthinklabs.com.
Cheers!
Kipp Ashford
Art Director
Seven2 Interactive
I'm stuck. I am building a custom Settings.apk for a new tablet and I've run across an error I can't find.
Any dialog that displays a SeekBar or variation simply FC's with a null pointer exception. I have a reference source tree that is a virgin copy from the android git. If I compile the stock Settings.apk, it does the same thing at the same places as my custom version.
The error occurs in the BrightnessPreference.java and the RingerVolumePreference.java files any time the dialog containing a SeekBar or Volumizer tries to display.
Here's an example of the code:
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
mSeekBar = getSeekBar(view);
mSeekBar.setMax(MAXIMUM_BACKLIGHT - mMinBrightness); <-- errors here
It errors at setMax with a null pointer error, like the setMax method doesn't exist. My build environment seems fine. Everything I've built runs on the target devices, but this one has me stumped. Has anyone else tried building a Settings.apk lately, and does it display the volume (in sound) and brightness (in Display) dialogs?
BTW, the target is Froyo
Thanks,
--- Jem
Are you sure the mMinBrightness variable is defined? BrightnessPreference.java as shown here instead uses MINIMUM_BACKLIGHT and is defined as:
Code:
private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10;
It is then used to set the seekbar max:
Code:
mSeekBar.setMax(MAXIMUM_BACKLIGHT - MINIMUM_BACKLIGHT);
You can also look at the onBindDialogView in RingerVolumePreference.java here. If you want to check whether the java files change from the version I linked(2.2.1 Froyo), just use the arrows on either side of the currently listed version.
I appreciate the response. Yes it is defined and initialized earlier as referenced below.
=== Code ===
private int mMinBrightness;
private boolean mAutomaticAvailable;
// Backlight range is from 0 - 255. Need to make sure that user
// doesn't set the backlight to 0 and get stuck
private static final int MINIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_DIM + 10;
private static final int MAXIMUM_BACKLIGHT = android.os.Power.BRIGHTNESS_ON;
public BrightnessPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mAutomaticAvailable = context.getResources().getBoolean(
com.android.internal.R.bool.config_automatic_brightness_available);
setDialogLayoutResource(R.layout.preference_dialog_brightness);
setDialogIcon(R.drawable.ic_settings_display);
mMinBrightness = MINIMUM_BACKLIGHT;
if (Settings.System.getInt(context.getContentResolver(),
Settings.System.LIGHT_SENSOR_CUSTOM, 0) != 0) {
mMinBrightness = Settings.System.getInt(context.getContentResolver(),
Settings.System.LIGHT_SCREEN_DIM, mMinBrightness);
}
}
=== code ===
Thanks,
--- Jem
It might be useful to rule out an issue with mMinBrightness not getting set or getting set incorrectly by either replacing it with MINIMUM_BACKLIGHT in the setMax line or using a toast message to display the value of mMinBrightness before setMax. If that doesn't reveal anything, could you paste the relevant logcat output for the error/fc and also upload your BrightnessPreference.java file somewhere so it could be downloaded.
I saved the dir's with my modified package and blew away the entire repo structure. I then reloaded the official Android tree from kernel.org. I have compiled the Settings.apk app ALL STOCK, and I get the same errors in the brightness and volume areas. A copy of the brightnesspreference.java and a log screenshot of the error tracking can be found at:
mlsoft dot sytes dot net/brightness.zip (I can't post the direct link)
The only change in the error is the line number (same call though).
At this point, I am wondering if anyone can build the Settings.apk from the repo and get it to display a seekbar or variant in brightness or volume settings using 2.2.1 (froyo). I am comfortable at this point thinking that it is in the tree structure and not my build environment. At least I have a place to hunt if you can reproduce the error on your end.
I really appreciate your help.
--- Jem
android:id="@*android
Yeah, same thing happened to me and I found answer.
I hope this might help.
You will find that two xml files using "@*android".
"It gives access to internal resources for platform apps.
It is NOT safe to build apps with such declarations unless you are building a bundled app within a full system image."
- from stackoverflow
"What is the purpose of the star in the ID string?"
Sorry that I can not post URL. I'm new user.
Sorry about not yet having built and tested the Settings.apk on my end but I haven't found the time to do so yet. Your issue could very well be what You Kim posted about and I'm sure I wouldn't have noticed that for awhile if at all. Here's the link to the stack overflow topic You Kim referenced. The two xml files in the Settings package this occurs in are res/layout/preference_dialog_brightness.xml and res/layout/preference_dialog_ringervolume.xml. That part looks like this:
Code:
<!-- In brightness layout -->
<[COLOR="Red"]SeekBar android:id="@*android:id/seekbar"[/COLOR]
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dip" />
<!-- In ringervolume layout -->
<!-- Used for the ring volume. This is what the superclass VolumePreference uses. -->
<[COLOR="red"]SeekBar android:id="@*android:id/seekbar"[/COLOR]
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dip"
android:paddingLeft="20dip"
android:paddingRight="20dip" />
Thank you both. I have been through those files more than once and didn't notice the declarations. Outstanding work guys. I'm off to edit/recompile/test.
Thanks again,
--- Jem
Unfortunately, these changes didn't stop the null pounter errors. Something, somewhere HAS to be uninitialized, but damned if I can find it in the absseekbar, progressbar, or any other class in the seekbar hierarchy. I even tried setting a value of 255 in setMax to rule out variable problems, but that produces the same error at the same line.
I know there is a fix, Settings works on millions of Android devices, so it has to be something stupid I'm overlooking.
--- Jem
Well, it's almost 3am, but I fixed the problem in the brightness preference. SeekBarPreference handles the getSeekBar function, but it doesn't work as expected.
It assigns a static system res ID that obviously doesn't work as intended. So, I overrode the routine just above the call to onBindDialogView. Here is the routine in the seekbarpreference file:
(at sign)Override
protected static SeekBar getSeekBar(View dialogView) {
return (SeekBar) dialogView.findViewById(com.android.internal.R.id.seekbar);
}
Overridden in the brightnes preference file to this:
(at sign)Override
protected static SeekBar getSeekBar(View dialogView) {
return (SeekBar) dialogView.findViewById(R.id.seekbar);
}
I'll go back and write the original to accept a res ID as an argument later. For now at least the brightness control works. Tomorrow I'll go after the volume controls.
--- Jem
I have a listbox, with custom items. Code:
Code:
<ListBox Height="600" HorizontalAlignment="Left" Margin="7,6,0,0" Name="friendList" VerticalAlignment="Top" Width="449" ItemsSource="{Binding Friends}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="5,0">
<Image Height="120" HorizontalAlignment="Left" Name="image" Stretch="Fill" VerticalAlignment="Top" Width="120" Source="{Binding ImageUri}" GotFocus="image_GotFocus"/>
<CheckBox Height="78" HorizontalAlignment="Left" Margin="65,63,0,0" x:Name="selectedChckbox" VerticalAlignment="Top" Width="55" IsChecked="{Binding Selected, Mode=TwoWay}"/>
<TextBlock Height="58" HorizontalAlignment="Left" Margin="0,122,0,0" x:Name="nameTextBlck" VerticalAlignment="Top" Text ="{Binding Title}" Width="120" TextWrapping="Wrap" GotFocus="name_GotFocus"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I've created a veiwmodel for the values for binding, and when I click on one item I want to change the checkbox state like so:
Code:
friendSelectionViewModel.Friends[_selectFriendContent.friendList.SelectedIndex].Selected = !friendSelectionViewModel.Friends[_selectFriendContent.friendList.SelectedIndex].Selected;
But the only way the listbox gets the values updated, if I set the datacontext to null and than assign the viewmodel aggain like so:
Code:
_selectFriendContent.DataContext = null;
_selectFriendContent.DataContext = friendSelectionViewModel;
But this takes about 5-10 seconds to refresh the list. I know there is a better solution, I just cant figure out how.
Thanks in advance!
I don't know what datatype your collection 'friends' is from what you've posted, but I assume it's some kind of collection of objects of type 'Friend' class, and if so you can achieve what you want as long as the 'Friend' class itself is also a viewmodel (i.e. implements INotifyPropertyChanged) and has a property on it called 'Selected'. It's that class that any bindings in your datatemplate will look to as a viewmodel.
Taking the above to be true; what you need is to bind your ListBox's SelectedItem property, e.g.:
<ListBox
x:Name="lbFriendsList"
SelectedItem="{Binding SelectedFriend, Mode=TwoWay}"
...
in your 'friendSelectionViewModel', when an item in the list is selected it will trigger code in the 'SelectedFriend' property's "set" method, where you will have access to the Friend object that has been selected, and you will be able to do whatever you want to it, e.g. to always have it 'checked' when it is tapped, you might have this kind of code in your friendSelectionViewModel (assuming you've got the xaml in place that I've written above):
public Friend SelectedFriend
{
get
{
...
}
set
{
if(value != null)
value.Selected = true;
}
}
As long as you've set up the class Friend as a viewmodel too, and code a 'Selected' property in the Friend class (and as with most properties in viewmodels you set it up to call the typical OnPropertyChanged("Selected "); in its 'set' method) then that will trigger the update of the checkbox that you've set up in the datatemplate (because you've already got that bound to the property 'Selected' in your Xaml).
Hope that's clear and helps
Ian
yes that was the problem, and I missed to implement INotifyPropertyChanged for the TempFriends Class
thanks