I am stuck in a scenario. I have a login Form. I want to show it as disabled for some users. I can get that users but I dont know how to remove the focus from the window.
//to check whether the current user is administrator or not
public void checkAdministrator(){
String owner = ParseValues.parsedGroupList.get(indexofGroup).getGroup_owner();
String currentUser = CCMStaticVariable.loginUserId+"#abc.com";
if(owner.equalsIgnoreCase(currentUser)){
administrator=true;
}
else{
administrator=false;
}
}
Now -
if(!administrator){
//here I want to disable the whole Activity, I just want to show the activity in disabled state
}
First get your parent layout from your login xml and try this
parentLayout.setEnabled(false);
Related
So basically I am implementing talk back feature for my android app.
There is Edit Text View for user to write there phone number and then there is a button for sign up. If user hasn't given any phone number the Sign Up Button is disabled.
When the Button is disabled it the talk back should say "Sign Up Button Disabled, Please enter a valid mobile number." But since there is default string which talk back is saying at the end i.e : Button Disabled.
How to remove the default string being said for a particular view.
verifyButton.disable()
verifyButton.contentDescription = requireContext().getString(R.string.sign_up_button_disabled_phone_number_accessibility_label)
You can achieve this by attaching an AccessibilityDelegate to the view:
ViewCompat.setAccessibilityDelegate(submitButton, object: AccessibilityDelegateCompat() {
override fun onInitializeAccessibilityNodeInfo(
host: View,
info: AccessibilityNodeInfoCompat
) {
super.onInitializeAccessibilityNodeInfo(host, info)
if (!submitButton.isEnabled)
info.stateDescription = getString(R.string.accessibility_button_not_enabled_reason) //"Please enter a phone number"
}
})
This will update every time the state of the view changes so you won't need to manually do it on validation.
This will announce:
"Please enter a phone number, [Button Text], Button, Disabled"
So the user will still be aware of the button and it's intention and additionally why it's disabled!
I'm developing an Android TV application which is using Leanback library. There is a login form with email, password and a login button. I'd like to enable the login button only when the email and password are valid.
Here is my code:
mLoginButtonAction = new GuidedAction.Builder(this.getActivity())
.id(id)
.title(title)
.description(desc)
.build();
actions.add(action);
I disable it at first:
mLoginButtonAction.setEnabled(false);
And then enable it when it's valid:
mLoginButtonAction.setEnabled(valid);
The button is then enabled and I'm able to click it. But the color of the button is still the same color as in disable mode. Any idea? Thanks.
Modification to actions do not trigger notifications to the GuidedStepFragment and must be done so manually.
To notify an action change you first need the items index.
int idx = findActionPositionById(actionId);
Get and modify your action
GuidedAction someAction = getActions().get(idx);
someAction.setEnabled(valid);
Next notify the fragment of the update
notifyActionChanged(idx);
I am wondering how I go about (if it is possible) creating a modal popup in a mono for droid application.
Scenario: The application talks to the customers hosted web server (so this location will be different customer to customer). To use the app the user must specify the connection string of their web server. So when the application starts and it hits the main activity, the first task I do is check if there is a connection string set in the devices application settings. If not I want to throw up a simple modal popup that allows the user to specify a connection to their server.
I dont really want to start a normal activity because the user will be able to click the back button and just go back to the main menu and the app is than in an invalid state because it doesnt know what server to talk to.
Any ideas on how I go about this?
Or should I be structuring the activity chain so that the connection string is entered on the first activity so that if they click back it actually goes out of the app?
Im a little confused.
Thanks in advance
This is possible with AlertDialog. It can create dialogs for simple input with lists, checkboxes, yes/no buttons and custom views.
There is a sample in the Xamarin Sample Repository for different type of dialogs and in the bottom you can find one where a custom view with a username and password field has been added.
So first define your custom view you want to put in the AlertDialog. alert_dialog_connection_entry.xml and is a Layout:
Somewhere in your activity add the code:
var connection_string_view = LayoutInflater.Inflate(Resource.Layout.alert_dialog_connection_entry, null);
var builder = new AlertDialog.Builder(this);
builder.SetTitle("Connection String");
builder.SetView(connection_string_view);
builder.SetPositiveButton("OK", OkClicked);
builder.SetNegativeButton("Cancel", CancelClicked);
builder.Create();
builder.Show();
Add some handlers for the buttons:
private void CancelClicked(object sender, DialogClickEventArgs dialogClickEventArgs)
{
//Todo
}
private void OkClicked(object sender, DialogClickEventArgs dialogClickEventArgs)
{
var dialog = sender as AlertDialog;
if (null != dialog)
{
var connectionEdit = dialog.FindViewById(Resource.Id.connectionstring_edit) as EditText;
if (null != connectionEdit)
Console.WriteLine("Connection String: {0}", connectionEdit.Text);
}
}
That should be it. You should be able to put any kind of custom view in the dialog.
If you just want to display a modal popup for letting users put their connection string, you could try this.
First, you need to have a simple layout for how the dialog is presented. In this case, a TextView displaying something like "Connection string:" and an EditText to let the user put connection string is probably enough to go.
Then, you can put this code somewhere in your MainActivity, like after checking application settings or something similar.
var builder = new AlertDialog.Builder(this);
var view = LayoutInflater.Inflate(Resource.Layout.ModalDialog, null);
builder.SetView(view);
string connectionString = view.FindViewById<EditText>(Resource.Id.ConnectionString).Text;
AlertDialog alert = builder.Create();
alert.SetCancelable(false); //This prevents the dialog from being dismissed by either hit back button or hit out side of the dialog
alert.SetButton("OK", (s,e)=> ToDo(connectionString)); //Now you have the connection string, to do whatever you want.
alert.Show();
As you said, the alternative could be allowing user specify the connection string in the first screen. This is a good approach too. I assume you know how to do it, so I didn't post code here.
when my application is installed for the first time by the user , i want to explain him what each activity does (like a quick tip) , it should look like the below picture
it should have the cancel button , and should not repeat after the first install,
I need suggestion or any useful links ,how to implement it, Any help is appreciated.
You could use SharePreference to store the state whether or not user have viewed your instruction. Just add a boolean value named as 'instructionViewed' to SharePreference. Every time your application launched, check the value. If true, don't show instruction. If false, show instruction. When user click the cancel button, set the value to true.
SharePreference is a very easy-using class to help store some information.You could google how use it.
Hope this helpful.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testpage);
//Check SharePreference
boolean instructionViewed = checkInstrunctionState();
//If the instruction is not viewed, show instruction.
if(!instructionViewed){
RelativeLayout yourLayout = createYourOwnUi();
FrameLayout contentView = (FrameLayout)(getWindow().getDecorView().findViewById(android.R.id.content));
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(MATCH_PARENT,MATCH_PARENT);
contentView.addView(yourLayout, lp);
}
}
I have a unit test that opens up a custom dialog and enters some text. This works, but I am unable to accept the dialog or get hold of the ok button. Please can anyone tell me how to automate the dialog acceptance using junit.
ActivityMonitor activityMonitor = instrumentation.addMonitor(
EditItem.class.getName(), null, false);
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
instrumentation.invokeContextMenuAction(gridList, R.id.add, 0);
Activity activity = instrumentation.waitForMonitorWithTimeout(
activityMonitor, 10);
assertNotNull("Make sure the edit item activity was called", activity);
assertEquals("Make sure the edit item activity was called",
EditItem.class, activity.getClass());
final TextView nameView = (TextView) activity.findViewById(R.id.name);
// this opens the dialog
TouchUtils.clickView(this, nameView);
// this adds some text
for (int i = 0; i < 3; i++)
{
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_X);
}
// here I would like to accept the ok button on the dialog
OK I seem to have worked round this with a combination of key presses
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
The problem is now I can't tell when the dialog has finished being dismissed and returned to the parent Activity to continue the test with a
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
Go a work around for this too now:
instrumentation.waitForIdleSync();
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
Seems a bit clunky, is this how you are supposed to use these tools?
I'm having the same problem. What it looks like is that you will have to create a custom dialog. This will allow you to retrieve the buttons you added using the findViewById(). Here is a link that I found that might get you on the right path.
http://www.mkyong.com/android/android-custom-dialog-example/