How to use hints of Android Studio correctly - android

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 :) )

Related

Android AccessibilityService: AccessibilityNodeInfo.ACTION_SET_SELECTION not working properly with multiline fields in Browser apps

I'm working on an app with intense usage of AccessibilityService. The app works great with other Android apps, I can use text selection properly.
The problem comes with multiline fields in browsers: when trying to perform the action AccessibilityNodeInfo.ACTION_SET_SELECTION, it results in a wrong selection.
Here's my example code snippet. It may not be functional, but it helps with stating the issue:
override fun onAccessibilityEvent(event: AccessibilityEvent) {
val nodeInfo = event.source
if (AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED == event.eventType
|| (AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED == event.eventType
&& event.contentChangeTypes and AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT == AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT)) {
nodeInfo?.text?.let {
val arguments = Bundle()
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 20)
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 20)
event.source.performAction(AccessibilityNodeInfo.ACTION_SET_SELECTION, arguments)
}
}
}
As an example of what is happening, when in https://translate.google.com/, if you write:
selection is
not
working
and after writing this text you run the code, after performing the action the caret should be placed somewhere here:
selection is
not
work|ing
but instead, it is placed here:
sel|ection is
not
working
The problem seems to be related to endlines. Everything works great if you just write and select in a single line, but when using multiline, it's not working properly.
Any clue??? Did someone experience the same issue?

Highlight the Menu Item found in Search Result of Android Settings App

Inside Android core Settings App, when we search anything in the search bar, then the result of that search is highlighted automatically.
For e.g. please see below image where I highlighted my application name in the Notification Access section.
I achieved this by following code:
val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS").apply {
val app = "${application.packageName}/${NotificationListener::class.java.name}" //Here NotificationListener is a service name
val fragmentKey = ":settings:fragment_args_key"
val showFragmentKey = ":settings:show_fragment_args"
putExtra(fragmentKey, app)
putExtra(showFragmentKey, Bundle().apply { putString(fragmentKey, app) })
}
I referred to the Solution on this LINK
However, I want to highlight my application name in the Usage Access Setting.
i.e. when I open the intent for Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) then inside the list of apps, my app name must be highlighted.
However the above logic/approach is not working for Usage Access Screen.
My application opens the intent but does not highlight my app name there.
I did a detailed research but I am still facing challenge.
Hence, I request you all to please assist.
For ACTION_USAGE_ACCESS_SETTINGS , I can't find one. Have you seen it anywhere? If so, please show me on which app. I've requested about this here:
https://issuetracker.google.com/issues/165311852
https://issuetracker.google.com/issues/160303945
And one in general, for all settings:
https://issuetracker.google.com/issues/163176781
As for notification-access, check here: stackoverflow.com/a/63914445/878126

Google Places Autocomplete plugin isnt working in Firefox android

We are using google's places-autocomplete plugin on our website.
Of late we have received several complaints from our website visitors that this plugin isn't working in the Android version of Firefox. It works fine in the desktop version of Firefox however.
The problem can be simply observed by
Going to the places-autocomplete example here
Trying to enter a zip code in the "Enter a location" search input
You will observe the following 2 issues -
Google Auto-complete should show suggestions as you start typing the
zip code. But it doesn't until one types a space or , after the 5 digit zip code.
When the suggestions do show up (after typing space or ,), you can't choose the first suggestion. As you tap on it, the cursor moves back to the search input. You can however choose the second or third suggestion correctly.
Problem #2 is extremely annoying and frustrating for the user. We've had received several complaints about this.
I have confirmed this on Firefox version 36.0.2 on a Samsung S4 running Android 4.4.2.
How can this be resolved?
A work around for the second issue is to give the first autocomplete suggestion a top margin so the user can click it. Its not pretty but its functional.
css
.FirefoxAndroid .pac-container .pac-item:first-child {
margin-top: 20px;
}
js
<script>
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var is_android = navigator.userAgent.toLowerCase().indexOf('android') > -1;
if(is_firefox && is_android){
$('html').addClass('FirefoxAndroid');
}
</script>
I encountered the same issue today - the website I am working on is working perfectly on every web browser, the auto-complete as well except on FF mobile.
After trying 3-4 solutions the one that worked for me was to declare the var place at the top of my code.
I have something like that
var autocomplete;
var place;
var input = document.getElementById('location');
var options = {
componentRestrictions: {'country':'be'},
types: ['(regions)'] // (cities)
};
autocomplete = new google.maps.places.Autocomplete(input,options);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
place = autocomplete.getPlace();
...
}
It was not working only on FF mobile because I wasn't declaring place at the top.
Maybe it will help someone in the future who knows

Robotium ---> Instead of webview button, it clicks on edittext box

I'm pretty new with Appium. I tried robotium blackbox way with .apk file to fill up a small web-view form which is auto injected by other rails server and every thing is working fine for me but
When i tried to click on Save & Next button it clicks on the edit-text box in which my previous entry filed through script.
I used all the way
solo.waitForText("SaveAndNext");
solo.clickOnWebElement(By.id("SaveAndNext"));
solo.clickOnWebElement(By.name("Save & Next"));
solo.clickOnWebElement(By.textContent("Save & Next"));
But it click on the edittext box.
Here is my code :-
solo.waitForActivity("ViewQuestions");
getInstrumentation().waitForIdleSync();
solo.clickOnText("(?i).*?Yes.*");
solo.enterTextInWebElement(By.className("text_answer"), "2");
solo.hideSoftKeyboard();
solo.waitForText("SaveAndNext");
//solo.clickOnWebElement(By.id("SaveAndNext"));
//solo.clickOnWebElement(By.name("Save & Next"));
//solo.clickOnWebElement(By.textContent("Save & Next"));
for (WebElement webElement : solo.getCurrentWebElements()) {
Log.d("Robotium", "id: " + webElement.getId() + " textContent: "
+ webElement.getTagName());
if (webElement.getId() == "SaveAndNext") {
solo.clickOnWebElement(By.id("SaveAndNext"));
}
}
I have checked that if (webElement.getId() == "SaveAndNext") is found passed.
And in logcat
**Robotium id: SaveAndNext textContent: INPUT**
is shown.
Any help will be appreciate.
Remove this for loop and use just:
solo.clickOnWebElement(By.id("SaveAndNext"));
Btw you cannot compare Strings like:
webElement.getId() == "SaveAndNext"
You should rather use equals:
"SaveAndNext".equals(webElement.getId())
I had a similar problem with view clicks were not proper. Got this solution from robotium.org
Why do text and button clicks get wrong?
If this problem happens on one of the supported versions then try to add this tag to the test project's AndroidManifest.xml
uses-sdk android:targetSdkVersion="YOUR_VERSION"
Where YOUR_VERSION is 6 for Android 2.0, 7 for Android 2.1 and 8 for Android 2.2.
If that does not solve the problem then try to add this tag to the AndroidManifest.xml of the application you want to test:
supports-screens android:anyDensity="true"

Recent Apps on UiAutomator

I am now working with Android UiAutomator on for UI Test on my Android app. My app has a function that requires the user to verify the email to continue, so I try to do it like this: after reach to that function -> getUiDevice.pressHome -> Browser -> try to log in email -> PressHome again -> Press RecentApps then I stuck here, I cannot press on my Apps to return to it again. I try another way by clicking on my App icon but it starts my app again, not at the state before. Can anyone suggest me a solution for this? Any help is appreciate.
Thanks in advance.
Try this :
UiObject appBackground = new UiObject(new UiSelector().description("ABC"));
appBackground.click();
It did not show any description through 'uiautomatorviewer' command but this worked for me.
I could manage to create this behavior with:
fun backgroundAndForeground() {
val device = UiDevice.getInstance(getInstrumentation())
device.pressHome()
// Pressing app switch two times makes the last app put on background come to foreground.
device.pressKeyCode(KeyEvent.KEYCODE_APP_SWITCH)
device.pressKeyCode(KeyEvent.KEYCODE_APP_SWITCH)
}
In this case, I think that android only resume app when clicking the recent app image. It does not work on clicking display text or app icon. So, we need to click image of your app in recent app list. At that time you need to write as below. I always do that for similar case.
// Take all image view by class type and click by instance no.
new UiObject(new UiSelector().className("android.widget.ImageView").instance(3)).click();
You need to count instance no of your recent app image view. Not app icon image in recent app scroll view. Please try this. Thanks.
I've spent half a day on this and concluded I needed to issue a device.click(). Since my use-case is that my app was the last one running (not switching to the browser like you), I can safely click the middle of the screen and it'll always work.
If you're the 2nd to last running app, you can probably do x: 0 and y: device.displayHeight/2.
I've not tested this on many operating systems, only 9.

Categories

Resources