LibGDX DragAndDrop - Drag stop is called immidiatly after drag - android-studio

Im currently developing a basic game for Android, but I'm having a big problem with the com.badlogic.gdx.scenes.scene2d.utils library.
When I started the project I used Eclipse and the DragAndDrop-functionality worked great, but after a while I experienced problems with Gradle which led me to change to Android Studio. So after exporting my project to Android studio, the DragAndDrop just stopped working. When I click a dragobject and start to drag it, it stops immediately and DragStop() is called.
Now I feel I have tried everything there is and the only lead is this thread: https://github.com/libgdx/libgdx/issues/2901 which is basicly the same behavior, but it's caused by something else. By "lead" I mean that maybe the change of LibGDX version is the problem? I have not investigated this any further.
Anyway, I can't even get this simple DragAndDrop example to work:
dragAndDrop = new DragAndDrop();
dragAndDrop.addSource(new DragAndDrop.Source(splashActor)
{
#Override
public DragAndDrop.Payload dragStart(InputEvent event, float x,
float y,int pointer)
{
DragAndDrop.Payload payload = new DragAndDrop.Payload();
payload.setObject(splashActor);
payload.setDragActor(splashActor);
return payload;
}
});
dragAndDrop.addTarget(new DragAndDrop.Target(pauseButton)
{
#Override
public boolean drag(DragAndDrop.Source source, DragAndDrop.Payload payload,
float x, float y, int pointer)
{
return true;
}
#Override
public void drop(DragAndDrop.Source source, DragAndDrop.Payload payload,
float x, float y, int pointer)
{
}
});
Thanks for any help or ideas regarding this problem. I would be truly grateful if I could get my game working again!

This problem was fixed by updating the libgdx version to 1.5.5-SNAPSHOT! Thanks to noone for solving this.

Related

Override Pending Transition not working on android n

Im finishing my activity with an animation and before android n, they worked fine but now the activity just disappears without the transition. Is this a bug or something?
#Override
public void finish() {
super.finish();
//Worked before android n
overridePendingTransition(R.anim.slide_up, R.anim.slide_down);
}

Action listeners not firing

I've been developing with codenameone for over a year, and I never ran into this problem before, I feel like I'm losing my mind. I just redesigned one part of an app I'm working on, and now the ActionListeners aren't firing. I'm attaching them to a Button and a SpanButton in the code:
ActionListener goToDoc = new ActionListener() {
String mDocId = docId;
#Override
public void actionPerformed(ActionEvent evt) {
mStateMachine.currentExpertId = mDocId;
mStateMachine.showForm("DoctorDetails", null);
}
};
name.addActionListener(goToDoc);
Util.downloadImageToStorage(mStateMachine.URL_PREFIX+"images/doctors/"+(String)value.get("doc_pic"),
"doc_post_pic_"+(String)value.get("doc_id")+".png", new Callback<Image>() {
#Override
public void onSucess(Image img) {
pic.setIcon(img.scaledWidth(mStateMachine.getProportionalWidth(.23)));
StateMachine.applyGreenBorder(pic);
pic.addActionListener(goToDoc);
pic.getParent().revalidate();
}
#Override
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
System.out.println("Unable to download expert profile picture");
}
});
When I debug the code, the components do show that the ActionListener is attached, but the actionPerformed method is never reached, no matter how many times I click on the buttons. I experience this problem both on the simulator and on an Android device. I have yet to test on an iPhone.
Did you set a parent to be a lead component or focusable?
The reason the click event wasn't firing was because the Components weren't enabled, possibly a bug in the BUI Builder. After checking off the 'Enabled' and 'Focusable' checkboxes in the GUI Builder, and seeing they were unchecked every time I went back to that form, I just used component.setFocusable(true) and component.setEnabled(true) in the code, and it worked fine after that.

Enable android studio smart variable name on implementation

I am following a course on Udacity on android development. When I try something like this with auto complete:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
}
});
you can see that the primitive variable got the names i, and j. In this video, I believe android studio automatically gave the int variable the name "position". Do I need to enable this in android studio's settings, or is did the developer in the video just manually changed the name?
Much likely he changed it on his own. That's because the method of the AdapterView.Class defines the OnItemClickListener interface as follows:
public static interface OnItemClickListener {
void onItemClick(
android.widget.AdapterView<?> adapterView,
android.view.View view,
int i, // <-- position
long l);
}
As you can see, the position is named i that's why the Auto-Completion names it this way.

Catch events from a TextField

I'm building my app using the Nokia SDK 1.0 for the Asha 501
What I want to know, is how to capture events by pressing a TextArea. I'm porting an app from the S40 and using the code below, the TextArea doesn't capture the events
TextArea itemText = new TextArea("Hello I'm a TextArea", 2, 22) {
public void pointerPressed(int x, int y) {
System.out.println("PRESSED");
}
public void pointerReleased(int x, int y) {
System.out.println("HI!");
}
};
itemText.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("HI");
}
});
itemText.setEditable(false);
itemText.setFocusable(false);
itemText.getStyle().setBorder(null);
itemText.getStyle().setFgColor(Constants.Style.Color.GREY_DATE);
itemText.getStyle().setBgTransparency(Constants.Style.TRANSPARENT);
itemText.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
EDIT
Someone in the Nokia Forum, tells me to delete the itemText.setFocusable(false); line, but it doesn't work.
I've finally found what is the problem, I don't know the reason why but that's it.
Removing this line
itemText.setEditable(false);
the TextArea catches the events.
I don't find the reason that in Nokia SDK 2.0 this code is working and why here is not. Ande there is another fact. I set the TextAreato editable, and it is not editable o_O

Having trouble with AsyncTask using a recursive method

I've been reading about AsyncTasks and Hanlders and Loopers but I still can't figure out where I'm going wrong in my code. I'm trying to run code that will look over a Tic Tac Toe grid and determine the best move for the computer. I want this code to run in the background 'cause it can take some time and then I can update the UI level with a textbox that says something like "I'm Thinking". I've tried this a bunch of different ways, none with success.
private class PostTask extends AsyncTask<String, Integer, String> {
private Board _b;
private Welcome.Player _opp;
private int _depth;
#Override
protected void onPreExecute() {
super.onPreExecute();
}
protected void SetVars(Board b, Player p, int depth){
_b = b;
_opp = p;
_depth = depth;
}
#Override
protected String doInBackground(String... params) {
Looper.prepare();
try{
_bestMove = _b.GetBestMove(_opp,_depth);
}
catch(Exception err){
_bestMove = -1;
}
return "All done";
}
#Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(_bestMove == -1){
TextView tv = (TextView) findViewById(R.id.tv_Score);
tv.setText("Had and error, couldn't make a move.");
}
FollowUpComputerMove(this);
}
The above code will work for exactly 5 moves and then it crashes. When I watch in the debugger I see new theads being created named Thread<#> AsyncTask #1. Once I get to five of those AsyncTasks it goes back to try and grab the first AsyncTask and crashes. When it crashes I'm shown the ThreadPoolExecutor.class file.
I've also read that I shouldn't be using both the AsyncTask and the Looper objects together so I've tried taking the Loooper.prepare() statement out, but then my AsyncTask fails immediately with the error message:
Can't create handler inside thread that has not called Looper.prepare() - AsyncTask inside a dialog
I've read repeatedly that you shouldn't be trying to update the UI from an AsyncTask and that often the above error is because of that, but GetBestMove isn't updating the UI thread. When I trace through to see where the error comes, it fails when calling a constructor saying it can't find the class.
Can anyone point me in the right direction? My end goal is to use one main thread and only one background thread, and just keep re-using the background thread whenever the computer needs to make a move. I know that the recursive method GetBestMove works when I run this program in a single-thread manner. But the screen freezes for too long on some moves as the method is being run. Thank you so much.
-NifflerX
Apologies for answering my own question, but the issue I was facing had nothing to do with recursion. The class I was calling was extending the class Activity, and while trying to call that from an AsyncTask the program was erroring out. When I removed the extends Activity from the class definition it started working again. Sorry for the post.
-NifflerX

Resources