How to set orientation and copies dynamically with pageDialog? - java

When I call my pageDialog with printerJob.pageDialog(pageFormat), the dialog box pops up as it should prompting the user to modify the page format of the print job.
Some settings work however some do not such as the orientation radio buttons.
I know I need to use the setOrientation method however, how can I retrieve information from the dialog box such as which radio button did the user click on for portrait or landscape?
Same goes for retrieving the information for how many copies did the user request from the printerJob.printDialog method?
Thank you

Related

Android firebase favorite button changes

I have a list. I shoot data using firebase database. I have a favorite button image on my list. When I click the button, favorites are added to the favorite page. When I click the button, the favorite button image changes. But when I scroll up or down on the page or switch to another page, this changed image returns to its original state. What can I do.
The state of the button is not preserved when moving through activities, because the activity object is re-instantiated each time, so in order to fix it, you just make it a static variable.
private static boolean isCandyPressed = false;
Then in your onclick() of button, set it to true. And thus, handle your logic throughout by cheking this variable.
Hope this solves your problem

Android task: click a button, go to a layout to edit personal info. click the submit button, save and display the info

I am working on a small task for an android app. And I dont really know what are the things I need to do or things I should be careful for.
In a user's personal page, there is a button where the user can click in. Then it goes to a layout where there are two buttons "cancel" and "submit". Below them, there is a blank space where the user can edit his personal info. (Here the keyboard should automatically pop up).
After he clicks "submit", the info is saved and the app goes back to the personal page and the info he just entered will be displayed.
If a user already has some text for his info, after he clicks the edit button, the whitebox in the layout should has the info that he has previously entered. from that he can re-edit and submit again.
Any type of hints and guidelines will be greatly appreciated!! Thank you so much!!!
This sounds like a good place to use Activity results. You can make the screen where the user enters the information an Activity, and then start it by calling Activity.startActivityForResult(). Once the user is finished and clicks done, you store the result with Activity.setResult() and call finish() to close that activity. The original Activity that opened that screen will then get a callback in onActivityResult() with the data that you set in setResult(). This is a pretty common task so there should be plenty of examples around.

Keyboard doesn't show when EditText is clicked

I'm having a problem with the softkeyboard not showing when i click on a EditText.
The activity goes like this.
1. Activity starts
2. Dialog box opens with a custom keyboard
3. And then I try to click on an empty EditText field to put in data, but nothing happens. The field get focus, but keyboard doesn't show up.
I haven't done anything funky with disabling keyboard..
Anyone know whats going on?
If you're using AVD manager add a hardware property Keyboard support and set it to false.
That should disable the shown keyboard, and show the virtual one.

"removedialog" issue when displaying 2 dialogs at the same time

In the method "OnCreate" of my actvity, I'm displaying a little progress dialog while loading data. It's done every time the "OnCreate" method is called so even when the screen orientation change.$
In the nominal case, there is no problem even if the user change the screen orientation.
But, if the user opens another dialog (used to select an item in a list), then change the orientation, the progress dialog is displayed behind the "list" dialog and is not impacted by the "removeDialog".
Do you have any clues on that behavior ?
Thanks
call "removeDialog" or "dismissDialog" before "startDialog" with try-catch and so on. You can call "removeDialog" or "dismissDialog" several times...

In Android, how would you develop this? (activity and views question)

When the user opens the application, there is a screen with a button on it, which says "login."
The user clicks on the button, and a webview pops up to allow him to log in to the website.
After logging in (the app would need to know somehow), the webview would disappear, and then a list of usernames will pop up. (ListView?)
When the user clicks on one of the usernames, a webview of the username's profile will pop up. Of course, when the user pushes "back", it goes back to the list of usernames.
Can someone explain this to me in terms of Activity and Views? Am I using two activities to do this? Do I hide webview or listview when the user clicks between them?
I did the tutorial (notepad tutorial), but I'm still confused as to what is the best way to develop this.
Thanks
When the user opens the application, there is a screen with a button on it, which says "login." The user clicks on the button, and a webview pops up to allow him to log in to the website. After logging in (the app would need to know somehow),
Yo can do this with two separate Activity classes. I would put the WebView in its own Activity. This is easier than managing lots of different View objects yourself. Also, you'll get transitions between different things if you put each part in its own Activity.
You'll can launch the login Activity with the startActivityForResult() method, allowing it to return if the login was successful or not.
If you want to detect the login, you can monitor events in a WebView using a WebViewClient. You set the WebViewClient of your WebView using the setWebViewClient() method.
the webview would disappear,
Simply start the next Activity using an Intent and call the finish() method on your first Activity. If you do this then the use won't come back to login button Activity if they click back as it won't be on the stack any more.
What I'm not clear on is how long the login at the website will be valid for. You may need to set the flags on the Activities in your Manifest, to ensure the user has to log in again if they leave and then return to your application.
and then a list of usernames will pop up. (ListView?)
Use a ListActivity. This is an Activity which comes with the API designed for displaying a single ListView.
When the user clicks on one of the usernames, a webview of the username's profile will pop up. Of course, when the user pushes "back", it goes back to the list of usernames.
So use the onListItemClick() method in ListActivity to detect the touch and launch a new Activity containing the WebView to show the profile. As this is in a new Activity the back handling is all automatic.
Essentially it could all be done within one activity. I can try to easily demonstrate how it could be done.
When you run your app, Activity (AndroidManifest.xml) is called.
View (could be called, main.xml) is shown displaying a login button
Upon clicking the button, you launch your WebView
Successful login, switches the View to a custom view displaying usernames on a ListView (might be a predefined XML file you create named userlist.xml)
Using onClick on a specific username will launch a WebView regarding that specific username.
To return back to your application when the user hits the Back button, you might need to utilize onPause and onResume but I am not sure.
This may not be the best approach, or even a good one, but it might help clear up any confusion.
EDIT:
An Activity is what gets bound to the AndroidManifest.xml as the main entry point into an application. A View contains user interactive components within your Activity, such as a login button, displaying username's, viewing contents on the web (WebView), etc.
First of all I'd consider a different way of approaching this problem.
You could create your own login layout in Andoid and send your login data to the website. After doing this you should create a ListView of all user names. If the user selects one of these user names you should open a WebView.
The problem would be, that you would have to check whether the login was successful or not! Basically you need to do a HttpRequest, parse the output and check it.
If it's your website you want to login you could write a small wrapper for your login which returns true/false for your login. (php wrapper which returns xml or plaintext)
Anyway, if you really want to do the login via WebView you can check it via:
private void initWebView(final WebView mWebView) {
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Page = new WebView(YourClass.this);
Page.getSettings().setJavaScriptEnabled(true);
Page.loadUrl(url);
if(url.contains("OkDoLogIn.php")) {
/* Check if login was successful if true start new Activity */
}
return true;
}
});
}
With url.contains("OkDoLogIn.php") you basically check which url is about to open. In your case it would be the url or a part of the url of your login button.
Nevertheless you would have to check if your login was successful or not!
Edit: See 1st comment!

Categories