How to repaint the progressbar in FMX (Android) - firemonkey

I have a progress bar and a lot of tasks to do. I just want to increase the value of the progress bar when a task (bool and void functions) was completed. For example:
changeClothes();
progressBar1->Value = 20;
eatSandwich();
progressBar1->Value = 40;
if(isWeekend()){
progressBar1->Value = 60;
ShowMessage("Weekend!");
}else
ShowMessage("Not Weekend");
haveDinner();
progressBar1->Value = 80;
timeToSleep();
progressBar1->Value = 100;
I tried to do using a for but no good results. Tried to do in the way that I mentioned, but it does everything and shows the bar already with the value in 100.

Try this:
for(int i = 1; i <= 100; i++){
ProgressBar1->Value = i;
Sleep(50);
Application->ProcessMessages();
}
Although, it is recommended that you don't call ProcessMessages very often as it will slow down the application. Maybe like this would be better:
if(!(i % 10))
Application->ProcessMessages();
In your case try it like this:
changeClothes();
progressBar1->Value = 20;
Application->ProcessMessages();
eatSandwich();
progressBar1->Value = 40;
Application->ProcessMessages();
if(isWeekend()){
progressBar1->Value = 60;
Application->ProcessMessages();
ShowMessage("Weekend!");
}else
ShowMessage("Not Weekend");
haveDinner();
progressBar1->Value = 80;
Application->ProcessMessages();
timeToSleep();
progressBar1->Value = 100;
Application->ProcessMessages();

Related

How to use FF_CONSTANT for Force feedback for Linux?

I am not able to utilize FF_CONSTANT force effect. My try code is:
struct ff_effect joy_effect_, joy_effect_2;
if (iwantconstantforce)
{
joy_effect_.id = -1;
joy_effect_.type = FF_CONSTANT;
joy_effect_.direction = 0x0000; // down
joy_effect_.replay.length = 100;
joy_effect_.replay.delay = 0;
joy_effect_.trigger.button = 0;
joy_effect_.trigger.interval = 100;
joy_effect_.u.constant.level = 65535;
joy_effect_.u.constant.envelope.attack_length = joy_effect_.replay.length / 10;
joy_effect_.u.constant.envelope.fade_length = joy_effect_.replay.length / 10;
joy_effect_.u.constant.envelope.attack_level = joy_effect_.u.constant.level / 10;
joy_effect_.u.constant.envelope.fade_level = joy_effect_.u.constant.level / 10;
}
I am able to produce FF_SPRING and FF_DAMPER effects with following codes.
if (youwantdampereffect)
{
joy_effect_.id = -1;
joy_effect_.direction = 0; // down
joy_effect_.type = FF_DAMPER;
joy_effect_.replay.length = 20;
joy_effect_.replay.delay = 0;
joy_effect_.u.condition[0].right_saturation = 65535;
joy_effect_.u.condition[0].left_saturation = 65535;
joy_effect_.u.condition[0].right_coeff = 65535 / 2;
joy_effect_.u.condition[0].left_coeff = 65535 / 2;
joy_effect_.u.condition[0].deadband = 0;
joy_effect_.u.condition[0].center = 0;
int ret = ioctl(ff_fd_, EVIOCSFF, &joy_effect_); // upload the effect
}
if (youwantspringeffect)
{
joy_effect_2.id = -1;
joy_effect_2.direction = 0; // down
joy_effect_2.type = FF_SPRING;
joy_effect_2.replay.length = 20;
joy_effect_2.replay.delay = 0;
joy_effect_2.u.condition[0].right_saturation = 65535 / 2;
joy_effect_2.u.condition[0].left_saturation = 65535 / 2;
joy_effect_2.u.condition[0].right_coeff = 32767;
joy_effect_2.u.condition[0].left_coeff = 32767;
joy_effect_2.u.condition[0].deadband = 0;
joy_effect_2.u.condition[0].center = 0;
int ret = ioctl(ff_fd_, EVIOCSFF, &joy_effect_2); // upload the effect
}
I do not find any info about what is constant force effect feels like or when it makes sense to use it.
Can somebody brief its importance and usage?
Thanks :)

how to make staggered array out of a for loop javafx

Can I get some help with this project I am trying to make a 9x9 of ellipsis in javafx. I have the code for the ellipsis but I can't figure out the logic to make the following happen.
Example of what I am looking for
I have used the regular for loop that just gives me 9x9. ellipsis stacked on top of one another
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
so what do I have to do to this for loop, to make it look like the picture above
any help would be great thanks.
Just determine the horizontal/vertical offset of the circles.
Every other row contains one more circle and starts half of the offset further to the left than the smaller rows.
final double fieldWidth = 50;
final double fieldHeight = 50;
final double radius = 20;
Pane parent = new Pane();
boolean bigRow = true;
final int rows = 9;
final int columns = 9;
for (int y = 0; y < rows; y++, bigRow = !bigRow) {
double offsetX = bigRow ? fieldWidth / 2 : fieldWidth;
double offsetY = fieldHeight * y + fieldHeight / 2;
for (int x = 0, size = bigRow ? columns : columns - 1; x < size; x++) {
Circle c = new Circle(offsetX + x * fieldWidth, offsetY, radius, Color.TRANSPARENT);
c.setStroke(Color.BLACK);
parent.getChildren().add(c);
}
}

Fully Associative Cache implementation

I don't understand why my code for the fully associative cache doesn't match the trace files that I'm given.
The parameters are each cache line is 32 bytes and the total cache size is 16KB.
My implementations for set associative caches of 2,4,8,and 16 all work perfectly (using least recently used replacement policy). But for fully associative, which could also just be described as a set associative of 32, is VERY close to the trace file but not quite. Frankly, I don't know how to debug this one since there's a vast amount of steps (at least the way I did it)
Here's the relevant parts of my code (excuse the inefficiency)
//Fully Associative
int **fullyAssoc;
fullyAssoc = new int*[64]; //where fullyAssoc[0][index] is way 0, fullyAssoc[2][index] is way 1 etc..
int **LRU32;
LRU32 = new int*[32];
for (int i = 0; i < 64; ++i){ //Initialize all entries in fullyAssoc to 0
fullyAssoc[i] = new int[16 * CACHE_LINE / 32];
}
for (int i = 0; i < 16; i++){ //Initialize LRU array
LRU32[0][i] = 0;
LRU32[1][i] = 1;
LRU32[2][i] = 2;
LRU32[3][i] = 3;
LRU32[4][i] = 4;
LRU32[5][i] = 5;
LRU32[6][i] = 6;
LRU32[7][i] = 7;
LRU32[8][i] = 8;
LRU32[9][i] = 9;
LRU32[10][i] = 10;
LRU32[11][i] = 11;
LRU32[12][i] = 12;
LRU32[13][i] = 13;
LRU32[14][i] = 14;
LRU32[15][i] = 15;
LRU32[16][i] = 16;
LRU32[17][i] = 17;
LRU32[18][i] = 18;
LRU32[19][i] = 19;
LRU32[20][i] = 20;
LRU32[21][i] = 21;
LRU32[22][i] = 22;
LRU32[23][i] = 23;
LRU32[24][i] = 24;
LRU32[25][i] = 25;
LRU32[26][i] = 26;
LRU32[27][i] = 27;
LRU32[28][i] = 28;
LRU32[29][i] = 29;
LRU32[30][i] = 30;
LRU32[31][i] = 31;
}
int fullyAssocLRU = 0;
int memCount = 0;
while(getline(fileIn, line)){
stringstream s(line);
s >> instruction >> hex >> address;
int indexFull;
int tagFull;
unsigned long long address, addressFull;
address = address >> 5; //Byte offset
addressFull = address;
indexFull = addressFull % 16;
tagFull = addressFull >> 4;
if (assocCache(fullyAssoc, indexFull, 32, tagFull, LRU32) == 1){
fullyAssocLRU++;
}
}
void LRU_update(int **lru, int index, int way, int ways){
int temp = 0;
int temp2[ways];
int temp_index = 0;
int i = 0;
while(i < ways){
if (lru[i][index] == way/2){
temp = lru[i][index];
i++;
continue;
}
else{
temp2[temp_index] = lru[i][index];
temp_index++;
}
i++;
}
for (int j = 0; j < ways - 1; j++){
lru[j][index] = temp2[j];
}
lru[ways - 1][index] = temp;
}
bool assocCache(int **block, int index, int ways, int tag, int **lru){
bool retVal = false;
for(int i = 0; i < 2*ways; i = i + 2){
if (block[i][index] == 0){
block[i][index] = 1;
block[i+1][index] = tag;
LRU_update(lru, index, i, ways);
return retVal;
}
else{
if (block[i+1][index] == tag){
retVal = true;
LRU_update(lru, index, i, ways);
return retVal;
}
else{
continue;
}
}
}
int head = 2 * lru[0][index];
block[head][index] = 1;
block[head+1][index] = tag;
LRU_update(lru, index, head, ways);
return retVal;
}
The trace files is supposed to be:
837589,1122102; 932528,1122102; 972661,1122102; 1005547,1122102; //For direct mapped
993999,1122102; 999852,1122102; 999315,1122102; 1000092,1122102; //For set associative
1000500,1122102; //For fully associative (LRU)
My output is:
837589,1122102; 932528,1122102; 972661,1122102; 1005547,1122102;
939999,1122102; 999852,1122102; 999315,1122102; 1000092,1122102;
1000228,1122102;
As you can see, for the fully associative one, it's only 272 off the correct output. Why would it be off when switching from 16 ways to 32 ways?
Ah, I mistakenly though a fully associative cache for a 32 line size cache of 16KB cache size is 32 ways, when it's actually 512 ways.

modifying the lengthY of some cubes is slow

I want to write a 3d version of a fft. (Like this:https://wiki.mozilla.org/File:Fft.png)
So I created a few bars and in an outside function, my first aproach was to set the lengthY to a value. Then I call bar.modified() to force it to be repainted.
If I now use more than 50 bars, it is horrible slow (on my 4 core CPU). I guess there's a better way to do it, right?
Source:
var elements = new Array();
create3d = function(len) {
var r = new X.renderer3D();
r.init();
if(a.length == 0){
for ( var y = 0; y < len; y++) {
var c = new X.cube();
a.push(c);
}
}
for ( var i = 0; i < len; i++) {
a[i].center = [i*2 , 0, 0];
a[i].lengthX = 1;
a[i].lengthY = 20;
a[i].lengthZ = 1;
a[i].color = [i%2,0,0];
r.add(a[i]);
}
r.render();
};
function setVal(index,val){
var element = a[index];
element.lengthY = val;
element.modified();
}
I created a JSFiddle on how to do that and it is pretty fast for 1000 cubes
http://jsfiddle.net/haehn/6fVRC/

add custom clickable buttons

I am developing an app for win phone 7. In that I need to add clickable buttons(not specific number) into a grid dynamically.and navigate the page with some information to other page.
can any body help me please....
private void buildThumbs(Grid gridThumb, int p) {
int n;
if (p % 3 == 0)
n = p / 3;
else
n = (p / 3) + 1;
GridLength height = new GridLength(100);
for (int i = 0; i < n; i++)
{
RowDefinition rowDef = new RowDefinition();
rowDef.MinHeight = 100;
gridThumb.RowDefinitions.Add(rowDef);
}
MovieThumb[,] thumb = new MovieThumb[n, 3];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 3; j++)
{
Image ni=new Image();
ImageSourceConverter ims = new ImageSourceConverter();
ni.SetValue(Image.SourceProperty ,ims.ConvertFromString( "/Images/book1.png"));
thumb[i, j].SetValue(Grid.ColumnProperty, j);
thumb[i,j].SetValue(Grid.RowProperty,i);
thumb.Click += new RoutedEventHandler(thumb_click("sandy"));
thumb[i, j].CoverImage = ni;
thumb[i, j].Loading = "Loading";
thumb[i, j].progress = false;
gridThumb.Children.Add(thumb);
}
}
}
I am not quite sure if I understand your problem, but if you want to set the Column and Row number for your dynamically created buttons, you may do so with Grid.SetColumn(buttonname, column); Grid.SetRow(buttonname, row); before you add the object to the gridThumb.
We need some more information for what exactly you want to accomplish and what doesn't work for you to help :)

Resources