1. Luke Plant
  2. net.learnscripture.webviewapp

Commits

Luke Plant  committed dc793fe

Get keyboard to show if user presses 'Enter'/'Go' instead of space for testing words

  • Participants
  • Parent commits 047cd07
  • Branches default

Comments (0)

Files changed (3)

File app/src/main/AndroidManifest.xml

View file
         android:allowBackup="true"
         android:icon="@drawable/ic_launcher"
         android:label="@string/app_name"
+        android:windowSoftInputMode="adjustResize"
         android:theme="@style/AppTheme" >
         <activity
             android:name="net.learnscripture.webviewapp.Dashboard"
             android:configChanges="orientation|keyboardHidden"
             android:label="@string/app_name"
+            android:windowSoftInputMode="adjustResize"
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen">            
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />

File app/src/main/java/net/learnscripture/webviewapp/Dashboard.java

View file
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.pm.PackageInfo;
+import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.net.MailTo;
 import android.net.Uri;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.inputmethod.InputMethodManager;
 import android.view.View;
 import android.view.WindowManager;
 import android.webkit.WebChromeClient;
 import android.webkit.WebViewClient;
 import android.widget.ProgressBar;
 
+import static android.content.res.Configuration.*;
+
 public class Dashboard extends Activity {
 
 	public String BASE_URL = "http://learnscripture.net/";
 	public String CONTACT_URL = BASE_URL + "contact/";
 
 	private JavascriptInterface jsInterface;
+	private View activeInput = null;
 
 	@SuppressLint("SetJavaScriptEnabled")
 	@Override
 		engine.setWebViewClient(new FixedWebViewClient() {
 			public void onPageStarted(WebView view, String url, Bitmap favicon)
 			{
+				activeInput = null;
 				jsInterface.enablePreferencesMenu  = false;
 				jsInterface.modalIsVisible = false;
 				jsInterface.urlForSharing = null;
 			}
 		});
 		engine.getSettings().setJavaScriptEnabled(true);
-		jsInterface = new JavascriptInterface();
+		jsInterface = new JavascriptInterface(this);
 		try {
 			ComponentName comp = new ComponentName(this, Dashboard.class);
 			PackageInfo pinfo = getPackageManager().getPackageInfo(comp.getPackageName(), 0);
 		return (WebView) findViewById(R.id.web_engine);
 	}
 
+	private boolean isHardwareKeyboardAvailable() {
+		return getResources().getConfiguration().keyboard == KEYBOARD_QWERTY;
+	}
+
+	public void showKeyboard() {
+		if (isHardwareKeyboardAvailable()) {
+			return;
+		}
+
+		if (activeInput != null) {
+			InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
+			imm.showSoftInput(activeInput, 0);
+		}
+	}
+
+	public void showMenu() {
+		this.openOptionsMenu();
+	}
+
+	public void registerInputFocused() {
+		activeInput = getCurrentFocus();
+	}
+
 	public void onBackPressed() {
 		WebView engine = getEngine();
 		String url = engine.getUrl(); 
 		public boolean modalIsVisible = false;
 		public int versionCode = 0;
 		public String urlForSharing = null;
+		private Dashboard dashboard;
+
+		public JavascriptInterface(Dashboard dashboard) {
+			this.dashboard = dashboard;
+		}
 
 		public void setEnablePreferencesMenu() {
 			enablePreferencesMenu = true;
 		public void setUrlForSharing(String url) {
 			urlForSharing = url;
 		}
+
+		public void showKeyboard() {
+			this.dashboard.showKeyboard();
+		}
+
+		public void showMenu() {
+			this.dashboard.showMenu();
+		}
+
+		public void registerInputFocused() {
+			this.dashboard.registerInputFocused();
+		}
 	}
 
 }

File app/src/main/res/layout/activity_dashboard.xml

View file
               android:orientation="vertical"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
+              android:windowSoftInputMode="adjustResize"
         >
 	<ProgressBar android:id="@+id/progressbar"
 		 		 style="?android:attr/progressBarStyleHorizontal"
     <WebView android:id="@+id/web_engine"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
+             android:windowSoftInputMode="adjustResize"
             />
 </LinearLayout>