Android: Programatically trigger text selection mode in a WebView on Jelly Bean - java

I need to programatically trigger text selection mode in a WebView, but the code I have used does not work on Jelly Bean?
I have been using the following code but it no longer works on Android 4.1 (Jelly Bean) because WebView.selectText, emulateShiftHeld, and the key dispatch are no longer supported on Jelly Bean.
Following code that works on all versions up to ICS is based on: How to enable the default highlight menus in android webview?
public void selectAndCopyText() {
try {
// ICS
WebView.class.getMethod("selectText").invoke(this);
} catch (Exception e1) {
try {
Method m = WebView.class.getMethod("emulateShiftHeld", (Class[])null);
m.invoke(this, (Object[])null);
} catch (Exception e2) {
// fallback
KeyEvent shiftPressEvent = new KeyEvent(0,0,
KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
shiftPressEvent.dispatch(this);
}
}
}
How do I implement similar functionality that works on Jelly Bean?

I have listed a potential solution in the comments here: How to enable the default highlight menus in android webview?
Here is the content of the potential solution:
After analyzing android.webkit.WebViewClassic I have had some success with the following:
KeyEvent enterEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_ENTER,0,0);
enterEvent.dispatch(this);
I thought more might be required as I needed to scroll down the WebView a little before the above worked when using an emulator, but after testing on a real JellyBean device the above seems to work fine.

Related

How can I add zoom in/out gesture in Android vision CameraSource

I'm trying to develop a simple camera app with face detection and i'm using android-vision sample from here
https://github.com/googlesamples/android-vision/tree/master/visionSamples/FaceTracker
Everything is working fine and i need to add zoom in/out feature in it. I searched SO but found nothing related to vision. Every answer is related to Camera2.
You might try startSmoothZoom:
https://developer.android.com/reference/android/hardware/Camera.html#startSmoothZoom(int)
You'd need to modify the open source version of CameraSource to make this change, since you'd need access to its underlying android.hardware.Camera instance:
https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java#L121
Try this code, it works (Yes, it's reflection)
try {
cameraSource.apply {
start(holder)
javaClass.getDeclaredField("zzg").apply {
isAccessible = true
(get(cameraSource) as Camera).apply {
startSmoothZoom(min(5, parameters.maxZoom))
}
}
}
} catch (e: Throwable) {
Timber.e(e)
}
Notice, that zzg is an obfuscated var of Camera instance and it's name may be different per library releases

JDeveloper ADF: CreateInsert auto committing?

I'm currently starting with ADF Faces technology as well as with JDeveloper. I have a .jspx page where I open a popup in which exists an ADF Form binded with a View Object. Whenever the popup opens it calls a createInsert action, but then some error messages popup as if somewhere a validation is being executed.
Things I've considered or tried so far:
The "SKIP VALIDATION" property of the page is set to TRUE. I don't
know what else to try.
Auto Submit property of each input are set to FALSE.
Consideration
I think the createInsert action is auto submitting but like I said I just started using these technologies a few days ago. So perhaps this "weird behaviour" is being caused by other settings I haven't considered yet.
Here's the code I use when the popup opens (PopUpFecthListener)
public void createInsert(PopupFetchEvent popupFetchEvent) {
try {
System.out.println("Inside function");
ADFUtil.invokeEL("#{bindings.CreateInsertVariable.execute}");
Util.getAppModuleImpl().getFurVariableView1().getCurrentRow().setAttribute("Estado", "I");
System.out.println("Function has been executed");
} catch (Exception e) {
Util.logErrorJava("Error", e.getMessage());
}
}
Here's the method in which I get the AppModuleImpl
public static AppModuleImpl getAppModuleImpl() {
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding vb = context.getApplication().createValueBinding("#{data}");
BindingContext bc = (BindingContext)vb.getValue(context);
DCDataControl dc = bc.findDataControl("AppModuleDataControl");
AppModuleImpl module = (AppModuleImpl)dc.getDataProvider();
return module;
}
I think you should try to use immediate attribute for you input controls.
For best understanding of immediate and validation mechanism read this article

Implementing google places autocomplete in android

Im creating an android app where im reusing the google places api to get the autocomplete function. I way i have succesfully implemented functionality is by using this code.
int PLACE_AUTOCOMPLETE_REQUEST_CODE = 1;
...
try {
Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.build(this);
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
} catch (GooglePlayServicesRepairableException e) {
// TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
// TODO: Handle the error.
}
This code is launched when the user clicks on a menu_button from a popupmenu in the firstscreen (mainscreen)
This code is able to do what i want it to do, but i dont know how to edit the fragment it creates. I want to set a hint thats different from "search" which is by default. The reason i used this code was because its able to create a sort of dialog or dim the background and creating the the autocompletefragment on top of the first screen which is what i want. Is there an another way to implement the autocomplete?
tl:dr
I want to use the google places autocomplete, and i want it to pop up like a dialog (Dim the first screen and the searchbar goes on top of the first screen).
Does anyone have a solution?

How to open the android quick notification setting

In android i want to open android notification quick setting in android program after a lot of searching from all resources found code for opening notification bar only.
Note that this code relies on non-public API's. It is not guaranteed to run correctly on all Android devices.
try {
Object service = getSystemService("statusbar");
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
// expands the notification bar into the quick settings mode
// - replace expandSettingsPanel with expandNotificationsPanel
// if you just want the normal notifications panel shown
Method expand = statusBarManager.getMethod("expandSettingsPanel");
expand.invoke(service);
} catch (Exception e) {
// do something else
}
Don't forget the required manifest permission:
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

Printing Android Advertising ID in a Textview

Problem:
I am trying to write a barebones android application that just shows your advertising ID in a textview. My code compiles fine but when I run it my textview remains unchanged (it just remains as "New Text").
This is a picture of the screen I'm getting on both my AVD and Actual Device
My Code:
I have already imported the google play services SDK and am using this following code within the onCreate method which is within the MainActivity class.
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//The textview I am trying to change
uniqueID = (TextView) findViewById(R.id.special);
// declarations for included ad plugin
adtechView = (AdtechBannerView) findViewById(R.id.ad_container);
adtechView.getAdConfiguration();
Context mContext = MainActivity.this.getApplicationContext();
try {
//This should be getting the advertising ID
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
String AdId = adInfo.getId();
//This should change the textview "uniqueID" to the Ad ID
uniqueID.setText("Your ID is " + AdId);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
What I've tried:
I have looked into the problem through some of related questions. multiple sources say that the code might not work due to not having access to google play services.
I have tried running the code both on my AVD which does not have google play services and on my actual device which does. Both end up with the same result. (textview remains unchanged)
I have written this code based on this website: https://www.safaribooksonline.com/blog/2014/01/16/advertising-id-android-kitkat/
which provides a tutorial for retrieving the Ad-ID.
I have also used this stack overflow as guide, but I am not face with the same issue his code was facing:
AdvertisingIdClient getAdvertisingIdInfo hangs forever
What am I doing wrong? Thanks so much in advance!
You can't get the Advertiser ID from the main thread. https://www.safaribooksonline.com/blog/2014/01/16/advertising-id-android-kitkat/
From the code above, it appears that this is taking place on the main thread. I'd recommend using an AsyncTask. Put the advertising ID in the doInBackground implementation. Since you can only modify UI on the main thread, set the text of the TextView in the onPostExecute implementation.

Categories

Resources