Displaying a single text in bold in textview in android - android-activity

How to show each word in bold for particular seconds in textview in android

You can use this....
But adding a sleep will block your UI so you better use handlers instead of sleep
textView.setTypeface(null, Typeface.BOLD);
Thread.Sleep(1000);
textView.setTypeface(null, Typeface.NORMAL);
Yes you can do that too...
textView.setText(Html.fromHtml("<b>" + Hello + "</b>" + World));
Thread.Sleep(1000);
textView.setText(Html.fromHtml(Hello + "<b>" + World + "</b>"));
You might need other styles supported by TextView, here you go.
I hope i helped ;)

Related

Cursor in python

I am trying to make a computer-like cursor which moves when you press the arrow keys on the keyboard, I am using the keyboard extension. Here's the code:
import os
import keyboard
cursor = "🡼"
count = 0
cursorPOS=""
cursorPOSl=""
cursorPOSr=""
while True:
count = count + 1
os.system('cls')
print(cursorPOS,cursor)
cursorPOS= cursorPOSl + "" + cursorPOSr
import keyboard
while True:
try:
if keyboard.is_pressed('right'):
print('')
break # finishing the loop
except:
break
I am stuck at the if keyboard is pressed part, there any way to detect and make the cursor move? Also, I didn't make the code for the cursor showing, but that's a second problem
Any tips on how to do those things?
Didn't exactly try something, just trying to discover what to do

Can I insert a zero-width tagged span in a GtkTextView?

I have a GtkTextView in which I would like to have some non-editable spans embedded in an otherwise freely editable document. The problem is, if I delete all the text between two such spans, they "merge together", in the sense that I can no longer insert characters between them. Here's some ruby code demonstrating the problem:
require 'gtk3'
window = Gtk::Window.new("Text view")
window.set_size_request(800, 600)
window.signal_connect("delete-event") { |_widget| Gtk.main_quit }
textview = Gtk::TextView.new
buffer = textview.buffer
buffer.create_tag "locked", {"editable" => false, "background" => "light green"}
iter = buffer.get_iter_at_offset 0
buffer.insert iter, "hello", "locked"
buffer.insert iter, " "
buffer.insert iter, "world", "locked"
window.add(textview)
window.show_all
Gtk.main
Since I have added an editable " " between "hello" and "world", I can insert text between them, but if I delete the space I can no longer add it back, even though "hello" and "world" are two independent locked spans.
Edit: To clarify, by "delete the space" I mean if I click into the text area and hit backspace till the space goes away and the two uneditable spans join together, I can no longer click on the boundary between them and insert text to push them back apart.
You could try replacing the interstitial text with a zero-width space instead of deleting it.

Fading 2 sounds in Wed Audio API

I'm trying to fade out 2 sounds at the same time in the piano app on this page:
http://www.intmath.com/trigonometric-graphs/music-note-frequencies-interactive.php
I'm using the "voices" approach and the exponential fadeout is working fine in single-note mode;
vca.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 1);
oscillator.stop(audioContext.currentTime + 1);
However, after choosing "Combined signal: yes" (where you hear a 220 Hz note plus the note played), the above will fade out the non-220 Hz note correctly, but the fundamental A-220 plays at full volume for the whole 1-second duration after key up. It's ugly, especially on small speakers.
I've disabled the fadeout for now in the "combined" case (both sounds just stop immediately, which is better than having one not fade at all.)
This is the function called on key up:
function doUp(thisKey, e) {
if(audioContext) {
for(i=-1; i<18; i++) {
if( typeof(active_voices['key'+i]) != "undefined") {
active_voices['key'+i].stop();
delete active_voices['key'+i];
}
}
}
audioOn = false;
}
I have tried changing the first line of the middle "if" to the following, but it didn't improve things:
active_voices['key'+i].stop(audioContext.currentTime + 1);
How to fade out 2 voices at the same time?
TIA.

Dynamic set text in GWT Label

I want to set text of GWT Label dynamically.
For example I am using below code to set text in GWT Label :
Label statusLabel = new Label();
for (int i = 0; i < numX; ++i) {
for (int j = 0; j < numY; ++j) {
statusLabel.setText("Processing " + "(" + (i + 1) + "/" + (j + 1) + " of " + numX + "/" + numY + ") ...");
}
}
And I add this Label in RootPanel one time like this : RootPanel.get().add(statusLabel);
But problem is that Label text is unchnage.
What I missed? Or How can set dynamic text into GWT Lable.
Your loop is just to fast. It does not allow the browser to render the changed text. If your processing is running just inside that loop, the generated JavaScript code will be executed as a single block and will not allow the UI to refresh in-between.
To allow the UI to refresh, you need to use delayed logic.
For example using Scheduler.get().scheduleDeferred.
Deferred means here the JavaScript code returns control to the browser, which refreshes the text, and afterwards the ScheduledCommand gets executed.
To make it short:
Split up your processing in different parts, where each of them changes the text and gets scheduled using a ScheduledCommand.
As an alternative you could keep a counter variable in your class (like in the loop) and just re-schedule ScheduledCommands until your processing is finished.
Just keep in mind that the browser needs some time to refresh the text and that it won't do that until your JavaScript code returns.

gwt firefox getAbsoluteLeft()

I'm seeing a truly weird behavior while trying to set a popup relative to another element in GWT. It seems like setting the popup position (an independent, floating element) changes the answer I get from calls like getAbsoluteRight() or getAbsoluteLeft() for a completely different element, which is static on the page and does not move visually.
I added some print statements to check what was going on, so here is the code:
System.out.println(item.td);
int position = item.td.getAbsoluteRight()-offsetWidth;
System.out.println("left/right:" + item.td.getAbsoluteLeft() + "/" + item.td.getAbsoluteRight() + ". sent:" + (item.td.getAbsoluteRight() - offsetWidth) + "=" + position);
popup.setPopupPosition(position, item.td.getAbsoluteBottom());
System.out.println("left/right:" + item.td.getAbsoluteLeft() + "/" + item.td.getAbsoluteRight() + ". sent:" + (item.td.getAbsoluteRight() - offsetWidth) + "=" + position);
popup.addStyleName("bigger");
System.out.println("left/right:" + item.td.getAbsoluteLeft() + "/" + item.td.getAbsoluteRight() + ". sent:" + (item.td.getAbsoluteRight() - offsetWidth) + "=" + position);
System.out.println(item.td);
Here is the result on Chrome
Menu displayed, widths: 81/340=340
<td class="hover">Daniel?</td>
left/right:1104/1185. sent:845=845
left/right:1121/1202. sent:862=845
left/right:1121/1202. sent:862=845
<td class="hover">Daniel?</td>
Here is the result on Firefox
Menu displayed, widths: 81/340=340
<td class="hover">Daniel?</td>
left/right:1254/1335. sent:995=995
left/right:1273/1354. sent:1014=995
left/right:1273/1354. sent:1014=995
<td class="hover">Daniel?</td>
so the left/right coordinates of the fixed element suddenly change (X coordinate goes from 1254 to 1273) after calling setPopupPosition(), while the relevant element actually stays in the same place (visually). I really have no idea how it happens as the popup doesn't even know of the existence of that element. Even more, while I can reproduce the error consistently, it does not happen if I switch the popup content...
... incidentally, I compared the coordinates given by firefox with a screenshot of the page, and the return values are not only wrong, but impossible given my screen size (1366x768) and no scrolling.
I could probably try setting the position twice, as the second value is actually the correct one, but I would really like to understand what is going on here...
Many thanks!
The differ is exactly 150 pixels. (May be total of 75 pix in left side)
Have you checked page against: http://validator.w3.org/
There's often differences within the margin/padding (also borders in IE).
As i get out of your getAbsoluteRight()-offsetWidth code, you using the td to get absolute right. But setting the position on the popup. This should mean that you have some borders/margins/padding between the popup and the td content.
The getAbsoluteLeft() and getAbsoluteRight() (as well as Top and Bottom) are all calculated based on their parental element's scroll and offset positions.
Also an empty object can often end up in a default width. But as soon as you enter a content, the size adapts to its content.