package com.firemint.realracing; import android.annotation.TargetApi; import android.content.Context; import android.text.Editable; import android.text.TextWatcher; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import com.ironsource.v8; import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode; /* loaded from: classes2.dex */ class CheatView extends FrameLayout implements TextView.OnEditorActionListener { boolean m_bEnableLogging; LinearLayout m_layout; CheatListener m_listener; CheatEditText m_text; boolean touchOffToClose; public interface CheatListener { void onInputDone(boolean z, CharSequence charSequence); CharSequence onInputUpdate(boolean z, CharSequence charSequence); } public class CheatEditText extends EditText { private CheatListener m_cheatListener; public CheatEditText(Context context, CheatListener cheatListener) { super(context); this.m_cheatListener = cheatListener; } @Override // android.widget.TextView, android.view.View public boolean onKeyPreIme(int i, KeyEvent keyEvent) { if (i == 4) { CheatView.this.Log("Consume the back key before it gets to the keyboard"); this.m_cheatListener.onInputDone(false, ""); return true; } if (i == 82) { CheatView.this.Log("Consume the menu key before it gets to the keyboard"); return true; } return super.onKeyPreIme(i, keyEvent); } } public void Log(String str) { if (this.m_bEnableLogging) { str.length(); } } public CheatView(Context context, CheatListener cheatListener, boolean z) { super(context); this.m_bEnableLogging = false; this.m_listener = cheatListener; CheatEditText cheatEditText = new CheatEditText(context, this.m_listener); this.m_text = cheatEditText; cheatEditText.setWidth(0); this.m_text.setHeight(0); LinearLayout linearLayout = new LinearLayout(context); this.m_layout = linearLayout; linearLayout.addView(this.m_text); addView(this.m_layout); this.touchOffToClose = true; this.m_layout.setVisibility(4); this.m_text.setRawInputType(z ? 129 : 1); this.m_text.setImeOptions(268435462); this.m_text.setOnEditorActionListener(this); this.m_text.addTextChangedListener(new TextWatcher() { // from class: com.firemint.realracing.CheatView.1 @Override // android.text.TextWatcher public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { CheatView cheatView = CheatView.this; CharSequence onInputUpdate = cheatView.m_listener.onInputUpdate(true, cheatView.m_text.getText()); String trim = onInputUpdate.toString().trim(); String trim2 = CheatView.this.m_text.getText().toString().trim(); CheatView.this.Log("onTextChanged: " + CheatView.this.m_text.getText().toString() + " to: " + onInputUpdate.toString()); if (!trim.equals(trim2)) { CheatView.this.m_text.setText(onInputUpdate); } CheatEditText cheatEditText2 = CheatView.this.m_text; cheatEditText2.setSelection(cheatEditText2.getText().length()); } @Override // android.text.TextWatcher public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { CheatView.this.Log("beforeTextChanged: " + charSequence.toString()); } @Override // android.text.TextWatcher public void afterTextChanged(Editable editable) { CheatView.this.Log("afterTextChanged: " + editable.toString()); } }); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { if (this.touchOffToClose) { if (motionEvent.getActionMasked() != 0) { return true; } Log("cancel"); this.m_listener.onInputDone(false, ""); return true; } onResume(); return false; } @Override // android.widget.TextView.OnEditorActionListener public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i != 6) { return false; } Log("IME_ACTION_DONE"); this.m_listener.onInputDone(true, textView.getText()); return false; } public void onResume() { MainActivity.instance.runOnUiThread(new Runnable() { // from class: com.firemint.realracing.CheatView.2 @Override // java.lang.Runnable public void run() { CheatView.this.Log(v8.h.u0); CheatView.this.m_text.requestFocus(); ((InputMethodManager) CheatView.this.getContext().getSystemService("input_method")).showSoftInput(CheatView.this.m_text, MainActivity.getIsAmazon() ? 1 : 2); } }); } public void onPause() { end(); } @TargetApi(11) public void begin(String str) { Log("begin"); MainActivity.instance.getWindow().setSoftInputMode(48); this.m_text.setText(str); onResume(); } public void end() { MainActivity.instance.runOnUiThread(new Runnable() { // from class: com.firemint.realracing.CheatView.3 @Override // java.lang.Runnable public void run() { CheatView.this.Log(TtmlNode.END); ((InputMethodManager) CheatView.this.getContext().getSystemService("input_method")).hideSoftInputFromWindow(CheatView.this.m_text.getWindowToken(), MainActivity.getIsAmazon() ? 1 : 0); MainActivity.instance.getWindow().setSoftInputMode(0); MainActivity.HideSystemKeys(MainActivity.instance.getWindow().getDecorView()); } }); } }