Adding share button to LibGDX for android and iOS - android

I am trying to add a button which when pressed shares the high score of the user to the chosen app (facebook, twitter, messaging etc...)
I have been searching online and I just could not find a clear tutorial on how to do this. It may be because I am not so familiar with the terms such as bindings etc.. so I cannot understand these advanced tutorials. Can anyone explain clearly how I could do this?
Thanks!
p.s it would be great for the share button to work for both android and iOS

For Facebook, check out gdx-facebook.
It's a cool project that integrates libgdx with Facebook's API. I discovered it recently, and so far so good.
Please note: There seems to be some gradle issues with this project when using Eclipse IDE. I've been using it with Android Studio, and it's working fine.

You'll need to have a binding on the user interacting with the button which uses the API of the corresponding service to make a post. It's sufficiently complicated and there are so many ways of doing it that I don't suspect you'll find any one answer to this problem.
The basic part of reacting on a tap or a click will look something like this:
ClickListener shareFacebook = new ClickListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
//Interacting with the facebook API here
}
}
shareButton.addListener(shareFacebook)
In this example, the ClickListener is a listener-type object which will react to the following events happening: enter, exit, touchDown, touchDrag, and touchUp. The binding is the function which we define inside the listener. So if we define a function for touchDown, then whenever someone touches or clicks on the the entity we attach this to, the function we define there will run.
Similarly for the other events: enter on the mouse moving into the element's clickable region, exit on the mouse moving out of the element's clickable region, touchDrag on the mouse moving while being pressed, and touchUp on the mouse being released.

Related

Tutorial first time you enter into an app?

I'm programming an app using android studio. I want to know in which way I can do a tutorial that users will see only the first time that use the app. Tutorial like image or screenshoots
Can someone help me? Thanks
I encountered this thread while looking for a solution for running a tutorial only at the first time (as rbaleksandar suggested), so in case it will be helpful for someone someday, here's a template of a solution that works for me (using the SharedPreferences API):
#Override
protected void onResume() {
super.onResume();
String tutorialKey = "SOME_KEY";
Boolean firstTime = getPreferences(MODE_PRIVATE).getBoolean(tutorialKey, true);
if (firstTime) {
runTutorial(); // here you do what you want to do - an activity tutorial in my case
getPreferences(MODE_PRIVATE).edit().putBoolean(tutorialKey, false).apply();
}
}
EDIT - BONUS - If you're into app tutorial - I'm messing now with the ShowcaseView library (which is amazing - try it out). Apparently they have some shortcut for that issue using a method called singleShot(long) - its input is a key for the SharedPreferences, and it does the exact same thing - runs only in the first activation. Example of usage (taken from here):
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_shot);
Target viewTarget = new ViewTarget(R.id.button, this);
new ShowcaseView.Builder(this)
.setTarget(viewTarget)
.setContentTitle(R.string.title_single_shot)
.setContentText(R.string.R_string_desc_single_shot)
.singleShot(42)
.build();
}
You could always code your own solution, but, let us not reinvent the wheel.
Check this Android Library:
Tour Guide Repository
It allows you to add pointers in your screen, so the user knows where is he supposed to touch next.
It's pretty easy to use, you only need to point to the element you want the user to touch.
From the doc:
Let's say you have a button like this where you want user to click on:
Button button = (Button)findViewById(R.id.button);
You can add the tutorial pointer on top of it by:
TourGuide mTourGuideHandler = TourGuide.init(this).with(TourGuide.Technique.Click)
.setPointer(new Pointer())
.setToolTip(new ToolTip().setTitle("Welcome!").setDescription("Click on Get Started to begin..."))
.setOverlay(new Overlay())
.playOn(button);
Hope this helps!
Some links to libraries for creating introduction and/or tutorial screens.
Horizontal cards like Google Now:
https://github.com/PaoloRotolo/AppIntro
Tutorial screen:
https://github.com/amlcurran/ShowcaseView
As far as I understand the question is not How do I create a tutorial? (as the people who have already posted an answer have concluded) but instead How to show a tutorial upon first launch only?. So here are my two cents on this topic:
I'm not familiar with how your Android app stores its configuration data but I will assume that it's either in a database (SQLite) or a text file (plaintext, YAML, XML - whatever). Add a configuration entry to wherever the app's settings are being stored - something like tutorial_on : false, tutorial_on : 1 etc. depending on the format the configuration is represented in.
The way configurations work is that whenever an app (or software in general) is launched it has to be loaded in the app itself. So add the following to your app (where and how is up to you and your app design):
Check tutorial_on entry
If tutorial_on is set to true/1 whatever
2.1 Display tutorial
2.2 Change tutorial_on to false/0 whatever
2.3 Store the result in your configuration
Continue using the app
By doing so the first time your app launches the flag responsible for displaying the tutorial will be toggled and afterwards every time you start the app the toggle flag will be read leading to omitting the tutorial.
Personally I would suggest that you an option similar to Don't show tutorial anymore along with a description how to re-enable it (by triggering some action in that app's menu etc.). This has two major benefits:
Improved user experience - users like to have control (especially over trivial matters such as showing or hiding a tutorial). Whenever you take the control away from them, they get pissed off.
Enable your user to re-learn forgotten things - a general rule of thumb is to create apps that should not burden the user with a lot of stuff to remember. That is why things should be self-explanatory. However sometimes you may want to do that nonetheless. By adding the possibility that the user re-launches (by simply resetting the tutorial_on flag and repeating the steps from above) the tutorial allows just that - refreshing a user's memory.

Handle touch events in watch face

I have a watch face built upon latest API (extending CanvasWatchFaceService.Engine). Now I'd like to get touch event to have kind of active area in watch face that can be touched to open settings, etc.
A CanvasWatchFaceService.Engine inherits from WallpaperService.Engine, which declares two important methods: setTouchEventsEnabled(boolean) and onTouchEvent(MotionEvent).
But even when I call setTouchEventsEnabled(true) in onCreate() method of the Engine I never receive a call to onTouchEvent(MotionEvent) in my engine implementation.
Am I doing something wrong or is it simply not possible? I'm aware of some watch faces that offer active areas, but I'm not sure if these are built upon latest API or if they are build upon deprecated API (using layouts and GUI elements).
Use the Interactive Watch Face API in new Android Wear 1.3:
http://developer.android.com/training/wearables/watch-faces/interacting.html
http://android-developers.blogspot.hu/2015/08/interactive-watch-faces-with-latest.html
UPDATE:
Add just one line to the init function in the onCreate function in your CanvasWatchFaceService.Engine based class:
setWatchFaceStyle(new WatchFaceStyle.Builder(mService)
.setAcceptsTapEvents(true)
// other style customizations
.build());
And manage the tap events under
#Override
public void onTapCommand(int tapType, int x, int y, long eventTime) { }
Notes:
you'll have to add your own code to find which touch targets (if any) were tapped (tapType==TAP_TYPE_TAP)
you can only detect single, short taps, no swipes or long presses.
by detecting TAP_TYPE_TOUCH and TAP_TYPE_TOUCH_CANCEL you can kind of guess swipe gestures, though TAP_TYPE_TOUCH_CANCEL doesn't provide the exit coordinates.
For more control your only bet is to add a SYSTEM_ALERT layer and toggle it on/off based on information you can gather from onVisibilityChanged and onAmbientModeChanged...
It is not possible. I guess I read it in a thread on Google Plus on the Android developers group.
The watch face is meant to be a "static" thing, just there, just showing the time. Touch events are never dispatched to it.
The suggested pattern for Settings is to implement it on a companion app on the phone app.

Android Graphical UI Builders - Connect event

Maybe this question has been ask already, but could not find any answer for almost 2hours of internet search.
There is a graphical UI designer wich is coming along with the last android SDK.
Looks pretty cool and well done.
Nevertheless I * cannot find how to attach an event to the control through the graphical editor.
Of course I can add it manually into the xml, but in that case, what's the purpose of having such tool without that function ?
I mean all the other SDK I had in other languages always include that function.
I've also not been able to find doc about how to use this tool. Quite sad...
Thanks
If you want to add a click event handler, select the button (widget) in the GUI that you want to listen for, and look for the property onClick. Enter the name of the method you want to call when the user clicks on that widget, like.. onMyButtonClick
Then add the method to your Activity
public void onMyButtonClick(View v) {
// I heard the button click
}
The GUI builder is getting there, and is not yet as easy to use as the one in XCode, but it's not hard when you get used to it.

Overriding onTouchEvent with Flixel (Android port)

So I followed Mathew Casperson's Making Games on Android Tutorial and got a small game running a few days ago, now I am trying to switch the controls to touchscreen instead of the D-pad.
I am running into some problems and was wondering if anyone here could help me. Flixel doesn't have any built in touchscreen functions so I am overriding onTouchEvent(MotionEvent event) in my Activity (FlixelDemo.java in the tutorial) and hopefully getting the coordinates of the touch.
I then have a function in my Player.java that given the touch coordinates could tell me whether my player has been touched.
The problem I am having is trying to figure out how to get to/call that function (isCollision) from in the activity.
It seems that I can only override the onTouchEvent in FlixelDemo.java and that I can only use the isCollision function in GameState.java where I add the player.
How do I get the info from the overridden touch event to any of my other classes? Can anyone tell me what I am doing wrong or help me figure out a different way of implementing touch events?
Looking at the code, FlixelDemo is really just a container for org.flixel.FlxGameView (via the res/layout/main.xml file).
The onTouchEvent method can be applied to any View, so you can apply it to just the flixel viewport.
And in fact, that's probably what you want to do here: Add your handler directly to FlxGameView.java, and then let it call a method on the internal GameThread class.
It's already handling the other events this way. See FlxGameView.onKeyDown (and the associated FlxGameView.GameThread.doKeyDown) for a good example.

button events in android

I want to develop in android a simple application: when the user push a button, an index will be incremented until the button is released. Which button events i have to use?
Thanks
Use an OnTouchListener. And as the others said, you should accept answers to some of your previous questions.
This code implements an open-source prototype, the Android HCI Extractor, which tracks and monitor the user and system interaction events in multimodal applications (e.g. touch, keypresses, scroll, number of elements provided by the system, etc.)
Android HCI Extractor code: http://code.google.com/p/android-hci-extractor/
In the source code you can find the class /android.hci.extractor/src/org/mmi/android/instrumentation/filters/NavigationInputFilter.java in one method is aimed to control the touch-press, the touch-move and the touch-release events. The method is called "public boolean onTouch (View v, MotionEvent event)", and the MotionEvent is the extra information that describes you the action made with the finger.
In this clas you can also find other methods aimed to control clicks and itemClicks.
Further information about the MIM project (including tutorials about the tool integration and usage): http://www.catedrasaes.org/trac/wiki/MIM
I hope it helps you!!

Categories

Resources