Google Places API AutcompleteSupportFragment not requesting focus - android

I am using the autocomplete support fragment from the Google Places API and am facing a small issue. When I click on the search button (Shown in 1).
I am able to see image 2. But what I want to see is image [3]. I want the keyboard to be up as soon as I click on the search button but instead, I need to make 2 clicks to get the keyboard.

From the looks of the pictures, it seems you're using overlay place picker not full display.
Then your code should be like this using an Autocomplete.IntentBuilder to create an intent to launch the autocomplete widget as an intent:
int AUTOCOMPLETE_REQUEST_CODE = 1;
List<Place.Field> fields = Arrays.asList(Place.Field.ID,
Place.Field.NAME);
// Start the autocomplete intent.
Intent intent = new Autocomplete.IntentBuilder(
AutocompleteActivityMode.FULLSCREEN, fields)
.build(this);
startActivityForResult(intent,
AUTOCOMPLETE_REQUEST_CODE);
You can either replace the FULLSCREEN with OVERLAY depending on your choice.

Related

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

Adding waypoints to navigate in waze map

In my application i want implement waze map navigation for multiple destination,i just achieved single origin and destination navigation ,but here i want to navigation multiple waypoints.
String url = String.format("waze://?ll=" + Double.parseDouble(_Lat) + "," + Double.parseDouble(_Long) + "&navigate=yes");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
I'm looking for a solution to the exact same problem.
Looks like they don't wish to provide - clueless why they are afraid people would use that.
Anyway, would it be possible that the activity which opened the intent also has a simple GPS listener which calculates when you're (almost) reached (or passed) your waypoint, and set the next coordinates (in the opened intent / or new one) ...?
For now I'm using google maps with a full URL, still I wish to send my users straight into navigation, not a browserwindow that may have or may not have a navigation button (Chrome versus other browsers).
A simple A to B is not working for me, I need a "A B C, break, C B A".

Android Expresso/UI Automator How do i automate clicking on Android screens outside my app (app picker)

My Android application has a button to download a file and then send it to an application on the device. Android pops up a screen listing the Applications on the device for the user to select which application to use.
I would like to automate this flow but i can not see how I can automate clicking on the Application Picker that Android presents. I presume this is because it is outside of my application.
I tried using Android Studio's "Record Expresso Test", I performed the following test steps
click on the action which sends my image to an app on the device (action1)
saw the Android Application picker appear and chose photos
Clicked back to close photos app and go back to my app
click on a different action in my app (action2)
I see in the recorded test code for steps 1 and 4 above, but nothing for 2 and 3. Therefore it makes me think that Expresso can not be used for this particular test flow.
Does anyone know how I could test this flow using Expresso?
EDIT:
Thank you to "John O'Reilly" for recommending UI Automator. I can see that I can use the UI Automator code within my Expresso test successfully. However I am having trouble writing a precise verification of the Application Selector.
The selector will have a title of "Open With". Using Android Device Monitor I can see the hierarchy of objects as illustrated below.
Some classes and IDs are internal so I can not search on those things. I do not want to code to look for a specific application as when the test is run on another machine it may not have that application. I just need to verify that the application picker has been displayed.
// the app selector has a FrameLayout as one of its parent views, and a child Text View which has the "Open With" title
UiObject labelOnly = new UiObject(new UiSelector()
.className("android.widget.FrameLayout")
.childSelector(new UiSelector()
.className("android.widget.TextView")
.text(openWithLabel)
)
);
boolean labelOnly_exists = labelOnly.exists();
// the app selector has a FrameLayout as one of its parent views, and a child ListView (containing the apps)
UiObject listOnly = new UiObject(new UiSelector()
.className("android.widget.FrameLayout")
.childSelector(new UiSelector()
.className("android.widget.ListView")
)
);
boolean listOnly_exists = listOnly.exists();
// I can use the listView to search for a specific app, but this makes the tests fragile if a different device does not have that app installed
UiObject listAndAppName = new UiObject(new UiSelector()
.className("android.widget.ListView")
.instance(0)
.childSelector(new UiSelector()
.text("Photos")));
boolean listAndAppName_exists = listAndAppName.exists();
How could i write a statement that verifies that what is on the screen is the application picker? I was hoping maybe have a selector that searches for a FrameLayout which has a child textView containing "Open With" and also contains a child ListView. With these 2 checks together it should identify only the application picker.
The credit for the answer to this question should go to John O'Reilly who pointed me to use the UI Automator.
I resolved the issue of checking what Android screen is invoked when my test clicks on an action by just checking there is a TextView on the screen with the title I am expecting. Its not perfect as this will pass if there is any TextView on the screen with the text so does not precisely check its the application picker.
However, for my test this should be enough of a check as my app (which would be behind the app picker) should not have a TextView with the expected title, so if the title is found its pretty much likely to be the application picker.
public static boolean verifyAndroidScreenTitlePresent(String title) {
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject titleTextUI = new UiObject(new UiSelector()
.className("android.widget.TextView")
.text(title)
);
boolean titleExists = titleTextUI.exists();
// close the app selector to go back to our app so we can carry on with Expresso
mDevice.pressBack();
return titleExists;
}

GuidedAction setEnable won't change the text color

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

Return from Android Gallery in jUnit?

I have an application in which if you click a button, it opens the Android Gallery application. The user can then select an image for my application. The thing is, if I click that button in JUnit, it opens up the Gallery and then just sits there. I have to manually choose a picture. I just want to be able to open the Gallery and then go back or if possible select an image.
I tried several options such as -
sendKeys(KeyEvent.KEYCODE_BACK)
Robotiums goBack(), goBackToActivity(), sendKey() functions
Robotiums clickOnScreen() function to click and select an image
but none of these seem to work. So what do I do?
I had the same problem. You can't do this, as the Android Gallery is another application running in its own sandbox which you cannot reach from your testing code.
However, I came up with the following solution. You can build your own dummy application that provides an Intent filter for opening images. In this application you simply return the intent with an ok.
Now you only have to select your application as the default application when first opening your image from your test application. Afterwards, everything should work automatically.
Once you're done with testing, you can reset the default intent filter in your Android device's settings.
The code for my solution can be found in this discussion: How to provide content for Intent.ACTION_GET_CONTENT
It is possible to simulate response returned from gallery.
The code snippet below do all the work.
final Intent data = new Intent();
data.setData(Uri.parse("content://media/external/images/media/458")); // put here URI that you want select in gallery
Runnable runnable = new Runnable(){
#Override
public void run() {
getActivity().onActivityResult(3333,-1, data);
synchronized(this) {
this.notify();
}
}
};
synchronized(runnable) {
getActivity().runOnUiThread(runnable);
runnable.wait();
}
This method has two drawbacks:
onActivityResult method of your activity should be public which brakes encapsulation.
Test will not actually click button which opens gallery and onClick handler won't be executed.
But the benefit of such approach is that you don't need to build mock application and change any defaults in android settings.

Categories

Resources