Seekbar OnProgressChanged doesn't get fired when moving manually - android-seekbar

I have an app that is supposed to do some stuff when the seekbar is moved (manually). However, onProgressChanged never gets executed, even though I made sure that the progress value does change when moving the bar.
onStartTrackingTouch and onStopTrackingTouch both get fired without any problems.
public class MainActivity extends ActionBarActivity implements OnSeekBarChangeListener{
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar1);
seekBar.setOnSeekBarChangeListener(this);
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
...
}

I have similar problem, onProgressChanged() not fired, but onStartTrackingTouch() and onStopTrackingTouch() no such problem.
In my case, user not able to drag seekbar after re-enter the activity page, it happen randomly.
It's because of mediaControl.seek() code inside onProgressChanged() stuck. The way I fixed it is to ensure mediaControl object assigned is the latest one with valid duration (i.e. mediaControl.getDuration()'s onSucces() != 0L).
So if you have similar problem, please first check your object inside onProgressChanged(), it probably something wrong with that object.

Related

How to change method order intellij?

Assume I have a class written as below
public MyClass{
public void method2(){
}
public void method1(){
}
}
but I would like to see method1() appearing first and method2() appearing second.
Is there anyway to do that with intellij without manually copy pasting? I cant find any tool inside method summary window.
If you only want to move the method up/down you can simply select it and usectrl + shift + (up/down) in order to move it as wished.

Libgdx multiple screens

Thanks to the help I got with my other problems on this forum, I managed to advance my project, but yet another obstacle appears in my way.
I am having trouble implementing multiple Screens in libgdx for java. I would like to know how can I implement multiple screens (one for the main menu, one for play, one for loading screen, ...).
An example or some explanations of how should I structure my screen classes would be really helpful. I tried implementing my own screen manager but that didn't go very well... Also some pointers on how should I dispose screens, since creating screens every time you go from main menu to play or to options menu isn't a very good idea. Any ideas or code example or advice is much appreciated.
What I have now are some classes of game screens which when you render them they will draw some GUI on the screen, but functions like the back button don't work since I don't know how to make the link between them.
Let's say you got 3 screens, MainMenuScreen, OptionsScreen, GameScreen.
First you need to declare them in your main class.
It will look like this
public class MainClass extends Game implements ApplicationListener {
private GameScreen gameScreen;
private MenuScreen menuScreen;
private OptionsScreen optionsScreen;
#Override
public void create() {
}
setGameScreen()
{
gameScreen=new GameScreen(this);
setScreen(gameScreen);
}
setMenuScreen()
{
menuScreen=new menuScreen(this);
setScreen(menuScreen);
}
setOptionsScreen()
{
optionsScreen=new OptionsScreen(this);
setScreen(gameScreen);
}
#Override
public void dispose() {
super.dispose();
}
#Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
super.render();
}
#Override
public void resize(int width, int height) {
super.resize(width, height);
}
#Override
public void pause() {
super.pause();
}
#Override
public void resume() {
super.resume();
}
}
Now every screen you got, needs to have a MainClass variable and a constructor of it.
Lets say for the GameScreen class, it will be like
public class GameScreen implements Screen{
private MainClass mainClass;
public GameScreen(MainClass mc)
{
mainClass=mc;
}
// your methods (show,render, pause, etc)
}
Now when you want to change the screen just use in your screen
mainClass.setMenuScreen();

Preventing hide of the main dialog

I'm trying prevent the close of my application, but looking at JavaFX docs (and after some implementations) I noticed that setOnCloseRequest() is efficient only when the user try to close the window using close button or ALT+F4 shortcut. As I need intercept internal tries of close, I'm using setOnHiding(), this way I can catch all tries of close the main dialog of the application, however I still can't prevent the closing:
public abstract class AppBase extends Application {
public void init(){
dialogoPrincipal.getPainel().getScene().getWindow().setOnHiding(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent event) {
event.consume();
}
});
}
}
Is there something I'm doing wrong? Is there another approach to solve this problem?
CloseRequest events are fired by the GUI user and Hide events are called programmatically. So you can control the flow of code for hide event calls. Implement some wrapper util class like StageUtil.hideRequest(stage) or extend your own as stage.myHide() etc. The hiding event seems cannot be consumed and I think it is a right decision by design. The purpose of hiding and hidden events are described in their javadocs and there is no mention about consuming of them.
Try implementing a window event handler on your controller:
public class XYZ implements EventHandler<WindowEvent>
{
#Override
public void handle( WindowEvent closeEvent )
{
closeEvent.consume();
}
}
Or try implementing it on your AppBase class.

Play framework event on Model delete

I am using Play framework 1.2.6. I am trying to get a Event or Listen some event if in my application any model call the delete or add. i.e. if deletion of data or addition happens in database through Model, then is there any way to get a event for this.
Please let me know if I am not very clear.
Thank you.
Try the #PreRemove annotation on your model method.
http://www.playframework.com/documentation/1.2.4/cheatsheet/model
You can override the _save() and _delete() methods in your model.
#Override
public void _delete() {
// .. do something
super._delete();
}
#Override
public void _save() {
// .. do something
super._save();
}

Static classes and "this" keyword

I have a static class with a custom event in it, as below:
//The delegate
public static delegate void eventDoneDelegate(object sender, WebLoaderEventArgs e);
//The event that uses the delegate
public static event eventDoneDelegate PageRequestDone;
//Calls the event
private static void onPageRequestDoneChanged(WebLoaderEventArgs e)
{
if (PageRequestDone != null)
PageRequestDone(this, e);
}
I know "this" can't be used because it references the current instance, but how can I pass the currect class as a parameter?
Or maybe my logic is wrong, please aware me as I am new to this.
Thanks.
The semantic meaning of the sender argument value depends on a vague agreement between the event publisher and the event subscribers; there is no universal standard. In your example, I can't see any need for a sender value at all, you might as well pass null.

Resources