Android Graphical UI Builders - Connect event - android

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.

Related

How to add "show text" in Android(x) password preference dialog

There doesn't appear to be a specific password text dialog in the Androidx (or Android) library.
I want to add a button so that the user can switch between text view and password text view (asterisks instead of letters) for this preference even though, as someone might want to tell me, it's not a fabulous idea to store passwords as preferences. Eventually I'll have a more robust approach but in the meantime this is what I've got.
I'm using the code that Android Studio (generously) offers me for "Preference Activity". In all other respects it seems pretty good, and better than I can manage myself yet. It's just got this (annoying lack of) feature.
This question is a little too old to reference Androidx, and according to the (main) relevant answer to my context, I can't use AndroidX here. However, using the code from the Settings Activity I don't explicitly mention DialogPreference at all.
So, is there a way to slot in a "reveal" button in this situation, or should I either not use the "textPassword" input type, or completely rebuild this activity?
I was messing round with something similar the other day. I didn't use a reveal button, but just got it to never show the password:
input_password.setText(prefs.getYourPassword().toAsterix())
private fun String.toAsterix(): String {
return replace("[.]", "*")
}
With a PreferenceActivity, you would have to make a custom view. It would be an EditText and a Button. Clicking the button would set the text to either prefs.getYourPassword() or prefs.getYourPassword().toAsterix().

Updating visual components in android embarcadero c++builder

I need to update several visual components in my app during a timeconsuming function, instead my app seems to hang during this function call, rather than update the visual components on the screen. When the function exit, I see only the last changes to the components.
Is there a simple way to do the updates, or do I need to create a parallel process and have a 'timer' to read the data simultaniously (using semaphores) and present them in the timer call ?
Any suggestions ?
I asked the same question yesterday here. Like mh taqia said you can use Application->ProcessMessages() but you have to be careful with it. For my application, it worked but look at some posts about the function first.
I tried following:
MainForm->Invalidate();
MyControlRoot->Repaint();
MyControlRoot is a control containing somewhat 50-60 different other controls
But MyControlRoot wouldn't repaint with this method. ..
Despite the warnings from you Remy, I tried Application->ProcessMessages();
...works for now...
By the way... I cannot see any warnings in Docwiki on using ProcessMessages... what could I expect?
RG

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.

How to find out a default behavior/value for an Android API?

I am learning Android programming, this seems to be a silly question.
pd = new ProgressDialog(this);
pd.setCancelable(false);
Cancelable can be
true
false
default behavior / not set
Is there an easy way to know the default behavior is either true or false?
In android Studio editor, use ctrl + Q, got this:
Online reference does not help either. setCancelable
I can run the code, then know the result, but it gotta be a easy way, right?
Take a look into its parent class: Dialog.
You can find out this line
/**
* This field should be made private, so it is hidden from the SDK.
* {#hide}
*/
protected boolean mCancelable = true;
By the way ProgressDialog it's not recommend by Google. You should use ProgressBar instead. You have to handle block button or something like this while ProgressBar is showing, but it bring user a better UX
You can control + click (on Android Studio or Eclipse) on the class that interests you and see on the library's source whether the boolean flag is set upon initialization on the class.
Usually, the information would be on the online reference. However, as you point out, it isn't!
Whenever I find I need to know something like that, and it isn't documented, then I check the source code. It is usually quite trivial to search for the specific class source in Google.
This of course, is only showing the value it takes by default for Android 4.4. In this case though, the value is unlikely to have a changed default. You should always bear that possibility in mind.

ECLIPSE comments in Android code - what is this?

I was just writing my code and put a // TODO: comment line, so I don't forget then on the left side a unknown little icon appears.
Does anyone know what this means and how to use this? I could not find anything about this extra feature thingy. Are there more of these? Can one search for "TODOs" somehow?
Thanks
This link should help explain it.
To view the added tasks, you have to open the Tasks window, which is different from the Task List Window. To open the Tasks window:
window -> show view -> other… > general > tasks
If you don’t see general, try typing “task” in the filter text box.
Whenever you create a class with an implemented method usually eclipse will fill it in for you (the unimplemented methods) and it creates the methods and puts that comment in there (it's auto-generated and a method stub)
You can make those To-do blocks yourself as a reminder for unimplemented / not completed methods. If you want to work on an old project you can just check the scrollbar and see for any blue bars so you know you haven't implemented some methods yet and implement them.
Press Window->Show view->Tasks.
This bookmark show all your TODO and another comments marks for your project/workspace
I'm not sure if this is the reason, but I noticed the feature stopped
working sometime after this was announced:
check this
also this post
and this post
this may help you

Categories

Resources