KitKat Animation and WebView rendering issue - android

I am facing a rendering issue when running animation to simple View. My setup has ViewPager and the first Fragment contains a WebView and the second Fragment has custom progress indicator which I animate.
Following image shows the problem, somehow there is relation with the WebView although the indicator is fully in it's own Fragment. My guess is that the platform uses the same GPU renderer and when having a WebView there it gets broken.
Anyone had same issue/found a workaround?
Thanks.

My guess was somewhat correct. I found a hack to fix this issue.
Extend WebView and override all constructors
Set layer type to software for the custom WebView
API level >= 11
setLayerType(LAYER_TYPE_SOFTWARE, null);
API level < 11
try {
Method setLayerType = getClass().getMethod("setLayerType",
new Class[] { int.class, Paint.class });
if (setLayerType != null)
setLayerType.invoke(this, new Object[] { 1, null });
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
NOTE: This implementation dramatically affects performance of WebView.

Have a look at this,
https://developer.android.com/guide/webapps/migrating.html
In KitKat everything has pretty much changed.
Why don't you try and set the target SDK to 18. If you do this then the webview works in compatibility mode.

Related

How do I programmatically dismiss a crash dialog?

I'm building a DPC (Device Policy Controller), and one of the issues I'm seeing is that while the Play Store and Play Services are being updated, the Google Contact Sync service crashes -- leaving the typical crash dialog on the screen. Since part of the idea of the initial set up process is to have as little user interaction as possible, how can I dismiss this dialog programmatically (since I seem to be pretty much guaranteed that this will happen)?
I've tried dismissing system dialogs...
ctx.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
... but that doesn't seem to do the trick.
Since this is a DPC, anything that requires device ownership/administration is fine.
edit: Usually I have no UI on screen at the time, so if one is necessary please do mention it. Also, preferably the solution should work on at least 6.0+, if not 4.0+.
Try to do it onWindowsFocusChanged method like this for example :
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus) {
Intent ctx= new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(ctx);
}
}
I'm not sure about app crash Dialog but maybe it'll help you
AppErrorDialog can be dismissed by broadcasting ACTION_CLOSE_SYSTEM_DIALOGS if Android version is N.
ctx.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
However, AppErrorDialog won't be displayed if phone is locked.
public boolean canShowErrorDialogs() {
return mShowDialogs && !mSleeping && !mShuttingDown
&& mLockScreenShown != LOCK_SCREEN_SHOWN;
} // ActivityManagerService
Please try this code.
try {
Class ActivityManagerNative = Class.forName("android.app.ActivityManagerNative");
Class IActivityManager = Class.forName("android.app.IActivityManager");
Method getDefault = ActivityManagerNative.getMethod("getDefault", null);
Object am = IActivityManager.cast(getDefault.invoke(ActivityManagerNative, null));
Method closeSystemDialogs = am.getClass().getMethod("closeSystemDialogs", String.class);
closeSystemDialogs.invoke(am, "DPC close");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}

Disable listview overscroll on Samsung Galaxy Tab 2.3.3 android

I need to totally disable overscroll in my listviews so I can implement my own overscroll functionality.
Seems to be simple enough when looking at the core listview classes, just by setting the overscroll mode to OVERSCROLL_NEVER. This fine work on my Samsung Galaxy s2. But doesn't work For Galaxy Tab 2.3.3.
Has anyone had much experience with samsung ListView customizations that can help me?
It worked for me on Samsung Galaxy Tab (with Android 2.2):
try {
// list you want to disable overscroll
// replace 'R.id.services' with your list id
ListView listView = ((ListView)findViewById(R.id.services));
// find the method
Method setEnableExcessScroll =
listView.getClass().getMethod("setEnableExcessScroll", Boolean.TYPE);
// call the method with parameter set to false
setEnableExcessScroll.invoke(listView, Boolean.valueOf(false));
}
catch (SecurityException e) {}
catch (NoSuchMethodException e) {}
catch (IllegalArgumentException e) {}
catch (IllegalAccessException e) {}
catch (InvocationTargetException e) {}

How to select text from a webview and not copy it?

I am creating an application which requires a webview.
I want to enable text selection in webview. (I found a few solutions but none of them worked)
Once the webview is selected, it should not be directly copied. I should be able to expand the selection range with handles (It is possible in version 2.3 and later. But I want this on versions lower than 2.3. HTC's browser gives us this option)
Any idea?
recently i solved that
put this function on create or on load in activity
private void emulateShiftHeld(WebView view)
{
try
{
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(view);
}
catch (Exception e)
{
Log.e("dd", "Exception in emulateShiftHeld()", e);
}
}
it will done...

How to use the hide methods in API?

I have seen some hide methods in
/** #hide */
public void setDiscoverableTimeout(int timeout) {
if (getState() != STATE_ON) return;
try {
mService.setDiscoverableTimeout(timeout);
} catch (RemoteException e) {Log.e(TAG, "", e);}
}
I want to use the above method but still not aware that how can I use this method in my program so that my app should be always in discoverable mode?
you can use reflections, i have been using it. The only flip side is it may be google doesn't provide any guarantee for it.

Android 2.2 webview search problem

I have a webview in my activity. Now when I use WebView.findAll() method to search text in webview it is not highlighting the matching words.
It works fine in Android 1.6 but is not working in 2.2.
There is an issue in Android issue tracker about this: http://code.google.com/p/android/issues/detail?id=9018
I placed this code right after WebView.findAll(), and it made highlighting working:
try
{
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webView, true);
}
catch (Throwable ignored){}
In android 4.0.3, seems the setFindIsUp is a private method. So above code won't work. As getMethod() method won't return the private methods. Following is a work-around to call the private method which works for 4.0.3:
try{
//Can't use getMethod() as it's a private method
for(Method m : WebView.class.getDeclaredMethods()){
if(m.getName().equals("setFindIsUp")){
m.setAccessible(true);
m.invoke(view, true);
break;
}
}
}catch(Exception ignored){}

Categories

Resources