Problem:
I cannot run test, because when Activity using fullscreen mode, Android dialog (see picture) is showed.
Goal:
I want to click to GOT IT and close the dialog.
Code (Kotlin):
//device is instance of UiDevice UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val gotIt = device.findObject(UiSelector()
//.clickable(true)
//.checkable(false)
//.className("android.widget.Button")
//.packageName("com.android.launcher3")
//.resourceId("android:id/ok")
//.index(3) //by index for language-independent
.text("GOT IT")
)
if (gotIt.waitForExists(3000)) {
try {
return gotIt.click()
} catch (e: UiObjectNotFoundException) {
e.printStackTrace()
}
} else Log.i(TAG, "clickViewingFullscreenDialog: btn not exists")
I tried many combination of selectors, but i still cannot click to GOT IT. Selectors are correct, but dialog is as "invisible" or unfocusable. Cannot click to dialog.
Additional info:
Trying on Emulator Nexus 5 Android 7.0.
I tried uiautomatorviewer and layoutinspector to get information about View hierarchy to find this Android Dialog, but i can get information only about android home screen (see second picture), not about own Activity (first picture).
is "GOT IT" a positive or neutral button?
if it's positive, click on ID android.R.id.button2.
And in case it's neutral button, click on ID android.R.id.button3
Related
Right now, I am calling this function before calling the fragment
fun toggleUIEventsListener(delay: Long = 1000) {
activity?.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
Timer().schedule(delay) {
activity?.runOnUiThread {
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
}
}
}
I am sure it will happen in a real device as well. Check in other phones and try tapping as fast as you can (twice) and you will realise that its happening in some real devices as well.
The way you can fix this is... make a boolean say, isClicked, set it to true when its been clicked and then do not allow user to click it for atleast 3 seconds, after that the user should again be able to click that button.
In Android Studio I have a Kotlin project with a button that sends an SMS message. When the Send SMS permission for the app is denied, the button is disabled. When a user clicks the disabled button, I would like to display a toast message to the user:
Toast.makeText(this, R.string.smsDisabled, Toast.LENGTH_LONG).show()
However, after much research I haven't been able to make this disabled button clickable. I have tried things like smsButton.isClickable = true on the button, but it still doesn't work. If it is possible to style the button to simply look like it is disabled, that would work too. My button style is currently set to #style/Widget.MaterialComponents.Button and I haven't had any success in changing the button colors. I have tried applying a background, backgroundTint, custom theme, and creating a custom background like in this question.
I am new to Android Studio so I have limited knowledge and experience. Is there a way to achieve this functionality?
Here is what you can do:
if (isPermissions) {
//keep the button as it is or do what you have to when button is enabled
} else {
//change the button color and maybe icon two
button.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.grey))
button.setOnClickListner {
//show toast
Toast.makeText(this, R.string.smsDisabled, Toast.LENGTH_LONG).show()
}
}
isClickable only makes it clickable once again if the click is disabled with the same attribute.
Try:
button.isEnabled = true
When I work with android studio it shows hints very often, I have 2 questions about it:
1) Why do android studio when I press enter (in scenario like on screenshot) makes just
noteRef.get()
.addOnSuccessListener {}
}
instead of
noteRef.get()
.addOnSuccessListener { documentSnapshot -> }
}
Is there a way generate { documentSnapshot -> } automatically?
2) Second problem: imagine, I have code like this:
var planetMarsSize = 0
var planetEarthSize=0
planetMarsSize = 5
for example I made mistake in this code and have to make "planetEarthSize = 5" instead of "planetMarsSize = 5" so i place cursor between "Mars" and "size", delete "Mars" and start tipping "Earth" - in this case Android studio shows me a hint to autocomplete text, I press enter. At the end text become "planetEarthSizeSize = 5" so android studio shows error. How can I make android studio to autocomplete "planetEarthSize" instead of "planetEarthSizeSize"?
Video of problem: https://photos.app.goo.gl/qAbcxtZsV4URwWwR8
1) The only difference between the two methods is that in the second, you can choose the name of the parameter. In the first one, you can access the parameter with it
2) You can press TAB on your keyboard to overwrite the whole variable name (it actually says this in the little dialog that pops up :) )
I am using titanium appecelerator to build an app in both ios and android.
I use the following code to create a tab group and add a tab to it.
var localTabGroup = Ti.UI.createTabGroup();
var planTab = Ti.UI.createTab({
title : NYC.Common.StringConstant.TAB_TITLE_PLAN,
icon : NYC.Common.ResourcePathConstant.IMG_TAB_PLAN,
window : planTabWin
});
localTabGroup.open();
And call the following function to create a window and add it to the tab
addWindowToTabGroup : function(window) {
tabGroup.activeTab.open(window, {
animated : true
});
},
Now, I often have to remove window from the stack of the tab ( eg: on android back button or ios navigation bar back)
Till now, I use window.close() to remove the window from the stack . But, it always shows warnings like.
[ERROR][TiBaseActivity( 378)] (main) [3320,4640528] Layout cleanup.
[WARN][InputManagerService( 62)] Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#406e4258
I was just wondering if I am following the correct approach? Or is there a better way to remove a window from the tab?
Thanks.
Tabs behave a lot differently on iOS and Android, On Android, the tab does not maintain a stack of windows. Calling open opens a new, heavyweight window, which by default covers the tab group entirely.This is very different from iOS, but it is for Android applications. Users always use the Back button to close the window and return to the tab group.
This may be happening because you are trying to remove the window even though natively Android already removes it. Check out the Android Implementation Notes of the docs here
To completely eliminate this problem, I would just open up a modal window without using the TabGroup, this would be more cross platform:
addWindowToTabGroup : function(window) {
window.open({
modal : true,
animated : true
});
}
This will open a modal window which behaves the same on both platforms, and can be handled easily by the native back button functionality.
I'm creating an android app where user loads some data from an online server when he hits a button
I need to add the following :
when user hits the button a pop-up screen shows on top of current screen & shows something like
"loading" "spinning loader" or anything like this
any thoughts ?
Have a look at this Android Developer page at the section "Creating a ProgressDialog". Android offers such a dialog out of the box.
You can try a function like showProgressDialog(Activity activity)with this context:
if ((mySpinnerDialog== null) || (!mySpinnerDialog.isShowing())) {
mySpinnerDialog= new Dialog(activity);
mySpinnerDialog.getWindow().getCurrentFocus();
mySpinnerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mySpinnerDialog.setContentView(R.layout.some_layout);
mySpinnerDialog.setCancelable(false);
mySpinnerDialog.setOwnerActivity(activity);
mySpinnerDialog.show();
} else {
mySpinnerDialog.setOwnerActivity(activity);
}
and dismiss this with mySpinnerDialog.dismiss();. Handle Illegalargumentexception on dismiss()