Skip to content

Commit

Permalink
Fix: Tables/Survey crash with HTML select on Android Lollipop
Browse files Browse the repository at this point in the history
  • Loading branch information
thienmcff committed Mar 19, 2021
1 parent a1dfbd2 commit 4016020
Showing 1 changed file with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
private String loadPageUrl = null;
private String containerFragmentID = null;

private Context odkContext;
/**
* isInactive == true -- when this View is being destroyed
* shouldForceLoadDuringReload == true -- if true, always call loadUrl(loadPageUrl).
Expand Down Expand Up @@ -111,7 +110,7 @@ public String getContainerFragmentID() {
}

public Context getOdkContext() {
return odkContext;
return super.getContext();
}

public void setContainerFragmentID(String containerFragmentID) {
Expand Down Expand Up @@ -173,19 +172,12 @@ public void setContainerFragmentID(String containerFragmentID) {
}
}

private static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1
return context.createConfigurationContext(new Configuration());
return context;
}

public ODKWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
super(context, attrs);

odkContext = context;
// Context is ALWAYS an IOdkDataActivity, IOdkCommonActivity, IAppAwareActivity, IInitResumeActivity...

String appName = ((IAppAwareActivity) odkContext).getAppName();
String appName = ((IAppAwareActivity) context).getAppName();
log = WebLogger.getLogger(appName);
log.i(t, "[" + this.hashCode() + "] ODKWebView()");

Expand All @@ -199,7 +191,7 @@ public ODKWebView(Context context, AttributeSet attrs) {
ws.setCacheMode(WebSettings.LOAD_DEFAULT);
ws.setDatabaseEnabled(false);
int fontSize = CommonToolProperties
.getQuestionFontsize(odkContext.getApplicationContext(), appName);
.getQuestionFontsize(context.getApplicationContext(), appName);
ws.setDefaultFixedFontSize(fontSize);
ws.setDefaultFontSize(fontSize);
ws.setDomStorageEnabled(true);
Expand All @@ -224,11 +216,11 @@ public ODKWebView(Context context, AttributeSet attrs) {
setWebViewClient(new ODKWebViewClient(this));

// set up the odkCommonIf
odkCommon = new OdkCommon((IOdkCommonActivity) odkContext, this);
odkCommon = new OdkCommon((IOdkCommonActivity) context, this);
addJavascriptInterface(odkCommon.getJavascriptInterfaceWithWeakReference(),
Constants.JavaScriptHandles.COMMON);

odkData = new OdkData((IOdkDataActivity) odkContext, this);
odkData = new OdkData((IOdkDataActivity) context, this);
addJavascriptInterface(odkData.getJavascriptInterfaceWithWeakReference(),
Constants.JavaScriptHandles.DATA);
}
Expand Down

0 comments on commit 4016020

Please sign in to comment.