From 84208a3f089637236412dc792389d1ce610edd45 Mon Sep 17 00:00:00 2001
From: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Date: Wed, 25 Sep 2013 13:18:37 -0400
Subject: [PATCH] * #30590: show/hide keyboard in call

---
 AndroidManifest.xml                           |  3 ++-
 .../sflphone/fragments/CallFragment.java      | 19 ++++++++++++++++---
 .../sflphone/fragments/DialingFragment.java   |  2 --
 .../sflphone/model/BubblesView.java           |  4 ++++
 4 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 93d8dd9d1..af1532d0e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -90,7 +90,8 @@ as that of the covered work.
         <activity
             android:name="com.savoirfairelinux.sflphone.client.CallActivity"
             android:label="@string/app_name"
-            android:screenOrientation="portrait" >
+            android:screenOrientation="portrait"
+            android:windowSoftInputMode="adjustPan" >
             <intent-filter>
                 <action android:name="android.intent.action.CALL_PRIVILEGED" />
 
diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java
index f7a75fd43..f0d6b0266 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java
@@ -52,8 +52,11 @@ import android.view.LayoutInflater;
 import android.view.SurfaceHolder;
 import android.view.SurfaceHolder.Callback;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.ImageButton;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -275,7 +278,7 @@ public class CallFragment extends Fragment implements Callback, SensorEventListe
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false);
+        final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false);
 
         view = (BubblesView) rootView.findViewById(R.id.main_view);
         view.setFragment(this);
@@ -288,6 +291,15 @@ public class CallFragment extends Fragment implements Callback, SensorEventListe
         call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call);
         transfer_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_phones_call_transfer_icon);
 
+        ((ImageButton) rootView.findViewById(R.id.dialpad_btn)).setOnClickListener(new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+                lManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
+            }
+        });
+
         // Do nothing here, the view is not initialized yet.
         return rootView;
     }
@@ -381,7 +393,6 @@ public class CallFragment extends Fragment implements Callback, SensorEventListe
         int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE);
         getBubbleFor(myself, model.width / 2, model.height / 2 + radiusCalls);
         getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2 - radiusCalls);
-        
 
         model.clearAttractors();
         model.addAttractor(new Attractor(new PointF(model.width / 2, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() {
@@ -505,7 +516,6 @@ public class CallFragment extends Fragment implements Callback, SensorEventListe
     public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
 
         if (conf.getParticipants().size() == 1) {
-
             if (conf.getParticipants().get(0).isIncoming() && conf.getParticipants().get(0).isRinging()) {
                 initIncomingCallDisplay();
             } else {
@@ -551,6 +561,9 @@ public class CallFragment extends Fragment implements Callback, SensorEventListe
 
     @Override
     public void surfaceDestroyed(SurfaceHolder holder) {
+        // check that soft input is hidden
+        InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+        lManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
     }
 
     public BubblesView getBubbleView() {
diff --git a/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java b/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java
index f3399c152..2e3b030bd 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java
@@ -35,7 +35,6 @@ import android.app.Activity;
 import android.app.Fragment;
 import android.content.Context;
 import android.os.Bundle;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -162,7 +161,6 @@ public class DialingFragment extends Fragment implements OnTouchListener {
     @Override
     public boolean onTouch(View v, MotionEvent event) {
         InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
-        lManager.showSoftInput(textField.getEdit_text(), 0);
         textField.setError(null);
         lManager.hideSoftInputFromWindow(textField.getWindowToken(), 0);
         return false;
diff --git a/src/com/savoirfairelinux/sflphone/model/BubblesView.java b/src/com/savoirfairelinux/sflphone/model/BubblesView.java
index c5b093366..799d0a0a4 100644
--- a/src/com/savoirfairelinux/sflphone/model/BubblesView.java
+++ b/src/com/savoirfairelinux/sflphone/model/BubblesView.java
@@ -137,6 +137,10 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
     @Override
     public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
         Log.w(TAG, "surfaceChanged " + width + "-" + height);
+        if(height < model.height) // probably showing the keyboard, don't move!
+            return;
+
+        
         thread.setSurfaceSize(width, height);
     }
 
-- 
GitLab