Skip to content

Commit

Permalink
Fixed focusing issues with soft IME.
Browse files Browse the repository at this point in the history
  • Loading branch information
DrDab committed Nov 17, 2018
1 parent e47875e commit d8ec44f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions app/src/main/java/trc3543/trcscoutingapp/SetCompetitionName.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package trc3543.trcscoutingapp;

import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
Expand Down Expand Up @@ -453,4 +457,31 @@ else if (competitionType == 3)

public void cancel(View view) { finish(); }

/**
* This code snippet written by ZMan; may great honor be laid upon this act of chivalry:
*
* Answer: https://stackoverflow.com/questions/4828636/edittext-clear-focus-on-touch-outside
* User: https://stackoverflow.com/users/1591623/zman
*/
@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
View v = getCurrentFocus();
if ( v instanceof EditText)
{
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if (!outRect.contains((int)event.getRawX(), (int)event.getRawY()))
{
v.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
}
return super.dispatchTouchEvent(event);
}

}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="361dp"
android:text="Version: 1.0-ftc-awoo0"
android:text="Version: 1.0-ftc-awoo1"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit d8ec44f

Please sign in to comment.