Android 2.2: Screen doesn't wake up after timeout when brightness set to zero - android-2.2-froyo

Im using the following code to adjust the brightness of the screen:
public void SetBright(float value) {
Window mywindow = getWindow();
WindowManager.LayoutParams lp = mywindow.getAttributes();
lp.screenBrightness = value;
mywindow.setAttributes(lp);
}
But i want the brightness to be 0% for a specific time. But when i use SetBright(0.0f), i cant change it back. I made a timer that runs for a minute with 0% brightness, then turns it back to 100%. Works when i use 10% for example. But when i turn it to 0% i cant seem to wake it up again. Any ideas how to solve this?

Related

THREE.Audio filter not ramping up with linearRampToValueAtTime

I'm having a little trouble working with the linearRampToValueAtTime on a BiQuadFilter applied to a WebAudio.
The audio works ok, and the initial lowpass filter is applied.
Problem is, as soon as I use the linearRamp method to bring up the frequency, it seems to ignore the endTime parameter (or better, it's not time correctly).
Some code to explain it better.
Here's the instancing:
this.audioLoader.load( 'public/media/soundtrack-es_cobwebs_in_the_sky.mp3', buffer => {
this.sounds.soundtrack = new THREE.Audio(this.listener);
const audioContext = this.sounds.soundtrack.context;
this.biquadFilter = audioContext.createBiquadFilter();
this.biquadFilter.type = "lowpass"; // Low pass filter
this.biquadFilter.frequency.setValueAtTime(200, audioContext.currentTime);
this.sounds.soundtrack.setBuffer(buffer);
this.sounds.soundtrack.setFilter(this.biquadFilter);
this.sounds.soundtrack.setVolume(0.5);
this.sounds.soundtrack.play();
})
Until here, everything looks ok. The sound plays muffled as needed.
Then, after a certain event, there's a camera transition, where I want the sound to gradually open up.
As a endTime parameter, I'm passing 2 seconds + the internal context delta.
this.sounds.soundtrack.filters[0].frequency.linearRampToValueAtTime(2400, 2 + this.sounds.soundtrack.context.currentTime);
Expecting to hear the ramp in two seconds, but the sound opens up immediately.
What am I missing?
The linear ramp will be applied using the previous event as the startTime. In your case that will be audioContext.currentTime at the point in time when you created the filter. If that is sufficiently long ago it will sound as if the ramp jumps right to the end value. You can fix that by inserting a new event right before the ramp.
const currentTime = this.sounds.soundtrack.context.currentTime;
const filter = this.sounds.soundtrack.filters[0];
filter.frequency.setValueAtTime(200, currentTime);
filter.frequency.linearRampToValueAtTime(2400, currentTime + 2);

How to Display hints to user when he is inactive for more than 5 sec in unity?

I have made a 2D Game using unity in which user has to select objects of similar color and now i want to display hint when user is unable to select the color for more than four seconds.
I want something similar to candy crush hint displaying system in which candy crush shows hint by highlighting the possible combination if user is not able to identify any combination himself.
I cannot figure out how to find if the user is inactive so that i can display hints.
I would really appreciate if someone can help me in figuring it out. Thanks in advance.
I dont agree with Joe Blow on this one that you need to call that EVERYWHERE in your code the user does something. What a user can do is press a key on the keyboard(also count on gamepads and controllers) or move the mouse(on mobile the mouse is simulated so that works too). So if you have a single class that looks something like this :
using UnityEngine;
public class TestInActive : MonoBehaviour {
private Vector3 prevMousePosition = Vector3.zero;
void ShowGameHintInvoke()
{
CancelInvoke();
Invoke("GameHint", 5);
}
void GameHint()
{
Debug.Log("This is a Hint");
}
// Update is called once per frame
void Update () {
if (Input.anyKeyDown || Input.mousePosition != prevMousePosition)
ShowGameHintInvoke();
prevMousePosition = Input.mousePosition;
}
}
It should work just fine. This calls ShowGameHintInvoke() once after the user has been inactive for 5 secs. Then it will not call it again until the user does something.
You can use DateTime type and set it on Update, so when the user doesnt do anything, you see all frames if DateTime (now) and the saved DateTime, the difference is more or equal to 5 seconds, there you show.
If the user touches, you flag that the user had done that, so next frame, you will see he didn't touch, and you set again DateTime and start seeing if exceeds 5 seconds.
Do you get what I mean ?
You could use some Coroutines with Yields of 5 seconds (WaitForSeconds) and you put 5 seconds and if it continues the yield, you show hint.

Timeline animation in JavaFX

I've been trying to add an animation to my bubble chart in my UI but have ran into some issues. I'm trying to increase the size of the bubble at different stages to show a gradual change but its just drawing it at its full size instead of at every stage.
Here's the timeline code
tl.getKeyFrames().add(
new KeyFrame(Duration.seconds(30),
new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent actionEvent) {
//for (XYChart.Series<Number, Number> series : liveDemoBubbleChart.getData()) {
for(int i = 10; i>0; i--) {
series1.getData().add(new XYChart.Data(5,5, ProjectProperties.getInstance().getSportsTweetsCount()/i));
}
The sport tweet count is the final value for the bubble and I'm dividing it by different amounts to show the build up to the final value.
Does anyone have any ideas as to why this isn't working as I expect?
The KeyFrame taking a Duration and an EventHandler<ActionEvent> simply executes the EventHandler's handle(...) method after the time specified by the Duration. So your code causes the entire for loop to be executed after a pause of 30 seconds.
You probably want to supply a KeyValue instead, providing a property to be set and the target value after 30 seconds. The value will then be interpolated at times in between. Have a look at the tutorial to see if it helps.

JavaFX: pause transition, not equal times

I have written a small application that performs some long-running tasks. Instead of having the user to wait and seeing just a progress bar, I would like to display some (changing) information about the application.
For that purpose, I wrote the following code within the constructor of an extended Pane:
FadeTransition fadeOutTransition = new FadeTransition(Duration.millis(1000), this);
fadeOutTransition.setFromValue(0.8);
fadeOutTransition.setToValue(0.0);
Similarly the fadeInTransition. And further...
SequentialTransition seqTransition = new SequentialTransition (
new Transition() {
{ setInterpolator(Interpolator.DISCRETE);
setCycleDuration(Duration.seconds(1)); }
protected void interpolate(double frac) {
int nextElement = (int) ((explenations.size() - 1) * Math.random());
Explenation explenation = explenations.get(nextElement);
questionLabel.setText(explenation.getQuestion());
answerLabel.setText(explenation.getAnswer());
}
},
fadeInTransition,
new PauseTransition(Duration.seconds(15)),
fadeOutTransition
);
What I woud like is the text to fade in, stay there for ~15 seconds and then fade out again. Unfortunately, the animation flickers, moves faster and slower - and the PauseTransition never takes 15 seconds! What is wrong about the code? I'm using Java 7, and JavaFX 2.2 on Mac OS X.
The problem seems to be that I called the function
seqTransition.play();
multiple times. From there comes probably the flickering and the unequal waiting time.

Testing to see if a window is maximized

I noticed that in Windows, if you maximize a window you can not resize it until you un-maximized it again. This appears to be a normal behaviour, so I would like to remove my resize gripper when the window is maximised.
At the moment I can't find a property to detect if a window is maximized, and although I could add a boolean in my controller, it wouldn't necessarily catch requests to maximize from the OS.
So if you know of a reliable way to test if a window is maximized please let me know.
On a related note, I am using custom chrome, and when I maximize a window it overlaps the windows task bar. I can think of hacks to detect available screen size (using a transparent system chrome window), but it would be good to know of a better method.
Thanks
Rob
In your application (MXML) on the in the init method you ussually call on creationComplete:
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="init()" >
Add the following code:
this.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, trackState);
the method looks like this:
public function trackState(event:NativeWindowDisplayStateEvent):void
{
if (event.afterDisplayState == NativeWindowDisplayState.MAXIMIZED)
{
isMaximised = true;
} else {
isMaximised = false;
}
}
I have figured out how this can best be done thanks to some pointers from TheBrain.
Firstly you need to watch for resize events to the window your want to control:
NativeApplication.nativeApplication.activeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, onWindowResize);
Then handle that event to decide if the window is maximised or not:
public function onWindowResize(event:NativeWindowBoundsEvent):void
{
if (event.afterBounds.height >= Screen.mainScreen.visibleBounds.height && event.afterBounds.width >= Screen.mainScreen.visibleBounds.width)
isMaximised = true;
else
isMaximised = false;
}
You then need to catch or create your own maximize button, and when clicked perform the following code:
if (isMaximised)
{
var bounds:Rectangle = Screen.mainScreen.visibleBounds;
NativeApplication.nativeApplication.activeWindow.bounds = bounds;
}
else
{
NativeApplication.nativeApplication.activeWindow.bounds = new Rectangle(100, 100, 500, 600);
}
You can modify the bounds to over maximize (which is handy for custom chrome windows with shadows), and you can also set the application to reset to a default size if the maximize button is clicked when it's already maximized (or do nothing).
I had issues about when to assign the window resize listner, and ended up removing and adding it every time the maximize button was clicked. It's a bit of overkill, but not too bad.
There is Win32 API Call that will do this for you:
BOOL IsZoomed( HWND hWnd );
to get the actual usable space from the screen, use the flash.display.Screen class, or you can use the systemMaxSize() which returns the largest window size allowed by the OS. For maximization you have some events that the window is dispaching when maximized/minimized/restored. You can find more info on the adobe pages (the link under systemMaxSize).
To detect if window is maximized...I don't think there is such a function (I might be wrong) but you can test if the app size is equal with the available screen size which means it's maximized. Or hook on the resize event which is triggered when the app is maximized/minimized/resized
Here is an easier way of checking if a window is maximized:
if(stage.nativeWindow.displayState == NativeWindowDisplayState.MAXIMIZED)
{
//do something
}
The following worked for me. No need to set event listeners, this code can be used to check the real-time state of the native window:
if (nativeWindow.displayState == 'maximized')
{
trace('Maximized');
}
else
{
trace('Minimized');
}
Can you use something like this to hook the maximize() event?

Resources