From ca382ea3fdf71f8c3904cbf5b901ef59230a9c04 Mon Sep 17 00:00:00 2001 From: Yuriy Liskov Date: Sun, 21 Jan 2018 18:31:49 +0200 Subject: [PATCH] refactoring + license --- License | 339 ++++ .../ime/LeanbackKeyboardContainer.java | 189 ++- .../ime/LeanbackKeyboardController.java | 1509 +++++++++-------- .../leanback/ime/LeanbackKeyboardView.java | 32 +- .../ime/LeanbackSuggestionsFactory.java | 6 +- .../pano/util/TouchNavSpaceTracker.java | 134 +- .../leanback/ime/LeanbackImeService.java | 281 +-- 7 files changed, 1428 insertions(+), 1062 deletions(-) create mode 100644 License diff --git a/License b/License new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/License @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java index f85ead0..1368161 100644 --- a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java +++ b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java @@ -14,6 +14,7 @@ import android.inputmethodservice.Keyboard; import android.inputmethodservice.Keyboard.Key; import android.os.Bundle; import android.speech.RecognitionListener; +import android.speech.RecognizerIntent; import android.speech.SpeechRecognizer; import android.text.TextUtils; import android.util.Log; @@ -101,7 +102,7 @@ public class LeanbackKeyboardContainer { private LeanbackKeyboardContainer.KeyFocus mTempKeyInfo = new LeanbackKeyboardContainer.KeyFocus(); private PointF mTempPoint = new PointF(); private boolean mTouchDown = false; - private int mTouchState = 0; + private int mTouchState = TOUCH_STATE_NO_TOUCH; private final int mVoiceAnimDur; private final LeanbackKeyboardContainer.VoiceIntroAnimator mVoiceAnimator; private RecognizerView mVoiceButtonView; @@ -225,8 +226,8 @@ public class LeanbackKeyboardContainer { final float width = (float) (this.mRootView.getWidth() - this.mRootView.getPaddingRight() - this.mRootView.getPaddingLeft()); final float height = (float) (this.mRootView.getHeight() - this.mRootView.getPaddingTop() - this.mRootView.getPaddingBottom()); final float size = this.mContext.getResources().getDimension(R.dimen.selector_size); - result.x = posXCm / 12.0F * (width - size) + (float) this.mRootView.getPaddingLeft(); - result.y = posYCm / 5.0F * (height - size) + (float) this.mRootView.getPaddingTop(); + result.x = posXCm / PHYSICAL_WIDTH_CM * (width - size) + (float) this.mRootView.getPaddingLeft(); + result.y = posYCm / PHYSICAL_HEIGHT_CM * (height - size) + (float) this.mRootView.getPaddingTop(); return result; } @@ -236,8 +237,8 @@ public class LeanbackKeyboardContainer { float posXCm = (float) (this.mRootView.getWidth() - this.mRootView.getPaddingRight() - this.mRootView.getPaddingLeft()); float posYCm = (float) (this.mRootView.getHeight() - this.mRootView.getPaddingTop() - this.mRootView.getPaddingBottom()); float size = this.mContext.getResources().getDimension(R.dimen.selector_size); - result.x = (x - width - (float) this.mRootView.getPaddingLeft()) * 12.0F / (posXCm - size); - result.y = (y - height - (float) this.mRootView.getPaddingTop()) * 5.0F / (posYCm - size); + result.x = (x - width - (float) this.mRootView.getPaddingLeft()) * PHYSICAL_WIDTH_CM / (posXCm - size); + result.y = (y - height - (float) this.mRootView.getPaddingTop()) * PHYSICAL_HEIGHT_CM / (posYCm - size); } private PointF getTouchSnapPosition() { @@ -359,11 +360,11 @@ public class LeanbackKeyboardContainer { this.mCapCharacters = false; if (var2.privateImeOptions != null) { - if (var2.privateImeOptions.contains("EscapeNorth=1")) { + if (var2.privateImeOptions.contains(IME_PRIVATE_OPTIONS_ESCAPE_NORTH)) { this.mEscapeNorthEnabled = false; } - if (var2.privateImeOptions.contains("VoiceDismiss=1")) { + if (var2.privateImeOptions.contains(IME_PRIVATE_OPTIONS_VOICE_DISMISS)) { this.mVoiceKeyDismissesEnabled = false; } } @@ -442,37 +443,41 @@ public class LeanbackKeyboardContainer { } } - private void setShiftState(int var1) { - this.mMainKeyboardView.setShiftState(var1); + private void setShiftState(int state) { + this.mMainKeyboardView.setShiftState(state); } - private void setTouchStateInternal(int var1) { - this.mTouchState = var1; + private void setTouchStateInternal(int state) { + this.mTouchState = state; } - private void startRecognition(Context var1) { - this.mRecognizerIntent = new Intent("android.speech.action.RECOGNIZE_SPEECH"); - this.mRecognizerIntent.putExtra("android.speech.extra.LANGUAGE_MODEL", "free_form"); - this.mRecognizerIntent.putExtra("android.speech.extra.PARTIAL_RESULTS", true); + private void startRecognition(Context context) { + this.mRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); + this.mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "free_form"); + this.mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); this.mSpeechRecognizer.setRecognitionListener(new RecognitionListener() { float peakRmsLevel = 0.0F; int rmsCounter = 0; + @Override public void onBeginningOfSpeech() { LeanbackKeyboardContainer.this.mVoiceButtonView.showRecording(); } - public void onBufferReceived(byte[] var1) { + @Override + public void onBufferReceived(byte[] bytes) { } + @Override public void onEndOfSpeech() { LeanbackKeyboardContainer.this.mVoiceButtonView.showRecognizing(); LeanbackKeyboardContainer.this.mVoiceOn = false; } - public void onError(int var1) { + @Override + public void onError(int i) { LeanbackKeyboardContainer.this.cancelVoiceRecording(); - switch (var1) { + switch (i) { case 4: Log.d("LbKbContainer", "recognizer error server error"); return; @@ -486,24 +491,28 @@ public class LeanbackKeyboardContainer { Log.d("LbKbContainer", "recognizer error no match"); return; default: - Log.d("LbKbContainer", "recognizer other error " + var1); + Log.d("LbKbContainer", "recognizer other error " + i); } } - public void onEvent(int var1, Bundle var2) { + @Override + public void onEvent(int i, Bundle bundle) { } - public void onPartialResults(Bundle var1) { + @Override + public void onPartialResults(Bundle bundle) { synchronized (this) { } } - public void onReadyForSpeech(Bundle var1) { + @Override + public void onReadyForSpeech(Bundle bundle) { LeanbackKeyboardContainer.this.mVoiceButtonView.showListening(); } - public void onResults(Bundle var1) { - ArrayList var2 = var1.getStringArrayList("results_recognition"); + @Override + public void onResults(Bundle bundle) { + ArrayList var2 = bundle.getStringArrayList("results_recognition"); if (var2 != null && LeanbackKeyboardContainer.this.mVoiceListener != null) { LeanbackKeyboardContainer.this.mVoiceListener.onVoiceResult((String) var2.get(0)); } @@ -511,7 +520,8 @@ public class LeanbackKeyboardContainer { LeanbackKeyboardContainer.this.cancelVoiceRecording(); } - public void onRmsChanged(float param1) { + @Override + public void onRmsChanged(float v) { // $FF: Couldn't be decompiled throw new IllegalStateException("method not implemented"); } @@ -519,14 +529,14 @@ public class LeanbackKeyboardContainer { this.mSpeechRecognizer.startListening(this.mRecognizerIntent); } - public void alignSelector(float var1, float var2, boolean var3) { - var1 -= (float) (this.mSelector.getWidth() / 2); - var2 -= (float) (this.mSelector.getHeight() / 2); - if (!var3) { - this.mSelector.setX(var1); - this.mSelector.setY(var2); + public void alignSelector(final float x, final float y, final boolean playAnimation) { + final float translatedX = x - (float) (this.mSelector.getWidth() / 2); + final float translatedY = y - (float) (this.mSelector.getHeight() / 2); + if (!playAnimation) { + this.mSelector.setX(translatedX); + this.mSelector.setY(translatedY); } else { - this.mSelector.animate().x(var1).y(var2).setInterpolator(sMovementInterpolator).setDuration(150L).start(); + this.mSelector.animate().x(translatedX).y(translatedY).setInterpolator(sMovementInterpolator).setDuration(MOVEMENT_ANIMATION_DURATION).start(); } } @@ -621,8 +631,8 @@ public class LeanbackKeyboardContainer { return this.mActionButtonView; } - public Key getKey(int var1, int var2) { - return var1 == 0 ? this.mMainKeyboardView.getKey(var2) : null; + public Key getKey(int type, int index) { + return type == KeyFocus.TYPE_MAIN ? this.mMainKeyboardView.getKey(index) : null; } public boolean getNextFocusInDirection(int direction, LeanbackKeyboardContainer.KeyFocus startFocus, LeanbackKeyboardContainer.KeyFocus nextFocus) { @@ -846,15 +856,16 @@ public class LeanbackKeyboardContainer { this.setShiftState(var1); } - public void onShiftDoubleClick(boolean var1) { - byte var2; - if (var1) { - var2 = 0; + // TODO: state constants + public void onShiftDoubleClick(boolean wasCapsLockOn) { + byte state; + if (wasCapsLockOn) { + state = 0; } else { - var2 = 2; + state = 2; } - this.setShiftState(var2); + this.setShiftState(state); } public void onSpaceEntry() { @@ -869,8 +880,8 @@ public class LeanbackKeyboardContainer { } - public void onStartInput(EditorInfo var1) { - this.setImeOptions(this.mContext.getResources(), var1); + public void onStartInput(EditorInfo info) { + this.setImeOptions(this.mContext.getResources(), info); this.mVoiceOn = false; } @@ -994,33 +1005,33 @@ public class LeanbackKeyboardContainer { } } - public void setTouchState(int var1) { - switch (var1) { - case 0: - if (this.mTouchState == 2 || this.mTouchState == 3) { - this.mSelectorAnimator.reverse(); + public void setTouchState(final int state) { + switch (state) { + case TOUCH_STATE_NO_TOUCH: + if (mTouchState == TOUCH_STATE_TOUCH_MOVE || mTouchState == TOUCH_STATE_CLICK) { + mSelectorAnimator.reverse(); } break; - case 1: - if (this.mTouchState == 3) { - this.mSelectorAnimator.reverse(); - } else if (this.mTouchState == 2) { - this.mSelectorAnimator.reverse(); + case TOUCH_STATE_TOUCH_SNAP: + if (mTouchState == TOUCH_STATE_CLICK) { + mSelectorAnimator.reverse(); + } else if (mTouchState == TOUCH_STATE_TOUCH_MOVE) { + mSelectorAnimator.reverse(); } break; - case 2: - if (this.mTouchState == 0 || this.mTouchState == 1) { - this.mSelectorAnimator.start(); + case TOUCH_STATE_TOUCH_MOVE: + if (mTouchState == TOUCH_STATE_NO_TOUCH || mTouchState == TOUCH_STATE_TOUCH_SNAP) { + mSelectorAnimator.start(); } break; - case 3: - if (this.mTouchState == 0 || this.mTouchState == 1) { - this.mSelectorAnimator.start(); + case TOUCH_STATE_CLICK: + if (mTouchState == TOUCH_STATE_NO_TOUCH || mTouchState == TOUCH_STATE_TOUCH_SNAP) { + mSelectorAnimator.start(); } } - this.setTouchStateInternal(var1); - this.setKbFocus(this.mCurrKeyInfo, true, true); + setTouchStateInternal(state); + setKbFocus(mCurrKeyInfo, true, true); } public void setVoiceListener(LeanbackKeyboardContainer.VoiceListener var1) { @@ -1093,39 +1104,41 @@ public class LeanbackKeyboardContainer { final Rect rect = new Rect(); int type = -1; - public boolean equals(Object var1) { - if (this != var1) { - if (var1 == null || this.getClass() != var1.getClass()) { + @Override + public boolean equals(Object obj) { + if (this != obj) { + if (obj == null || this.getClass() != obj.getClass()) { return false; } - LeanbackKeyboardContainer.KeyFocus var2 = (LeanbackKeyboardContainer.KeyFocus) var1; - if (this.code != var2.code) { + LeanbackKeyboardContainer.KeyFocus focus = (LeanbackKeyboardContainer.KeyFocus) obj; + if (this.code != focus.code) { return false; } - if (this.index != var2.index) { + if (this.index != focus.index) { return false; } - if (this.type != var2.type) { + if (this.type != focus.type) { return false; } + // TODO: label label31: { if (this.label != null) { - if (this.label.equals(var2.label)) { + if (this.label.equals(focus.label)) { break label31; } - } else if (var2.label == null) { + } else if (focus.label == null) { break label31; } return false; } - if (!this.rect.equals(var2.rect)) { + if (!this.rect.equals(focus.rect)) { return false; } } @@ -1134,33 +1147,33 @@ public class LeanbackKeyboardContainer { } public int hashCode() { - int var2 = this.rect.hashCode(); - int var3 = this.index; - int var4 = this.type; - int var5 = this.code; - int var1; + int hash = this.rect.hashCode(); + int index = this.index; + int type = this.type; + int code = this.code; + int salt; if (this.label != null) { - var1 = this.label.hashCode(); + salt = this.label.hashCode(); } else { - var1 = 0; + salt = 0; } - return (((var2 * 31 + var3) * 31 + var4) * 31 + var5) * 31 + var1; + return (((hash * 31 + index) * 31 + type) * 31 + code) * 31 + salt; } - public void set(LeanbackKeyboardContainer.KeyFocus var1) { - this.index = var1.index; - this.type = var1.type; - this.code = var1.code; - this.label = var1.label; - this.rect.set(var1.rect); + public void set(LeanbackKeyboardContainer.KeyFocus focus) { + this.index = focus.index; + this.type = focus.type; + this.code = focus.code; + this.label = focus.label; + this.rect.set(focus.rect); } public String toString() { - StringBuilder var1 = new StringBuilder(); - var1.append("[type: ").append(this.type).append(", index: ").append(this.index).append(", code: ").append(this.code).append(", label: " + + StringBuilder builder = new StringBuilder(); + builder.append("[type: ").append(this.type).append(", index: ").append(this.index).append(", code: ").append(this.code).append(", label: " + "").append(this.label).append(", rect: ").append(this.rect).append("]"); - return var1.toString(); + return builder.toString(); } } @@ -1179,7 +1192,7 @@ public class LeanbackKeyboardContainer { public ScaleAnimation(FrameLayout var2) { this.mView = var2; this.mParams = var2.getLayoutParams(); - this.setDuration(150L); + this.setDuration(MOVEMENT_ANIMATION_DURATION); this.setInterpolator(LeanbackKeyboardContainer.sMovementInterpolator); } diff --git a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardController.java b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardController.java index a150608..a60b741 100644 --- a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardController.java +++ b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardController.java @@ -15,808 +15,811 @@ import android.view.View.OnTouchListener; import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.RelativeLayout; +import com.google.android.leanback.ime.LeanbackKeyboardContainer.KeyFocus; import com.google.android.pano.util.TouchNavSpaceTracker; import com.liskovsoft.leankeykeyboard.R; import java.util.ArrayList; -public class LeanbackKeyboardController implements LeanbackKeyboardContainer.VoiceListener, LeanbackKeyboardContainer.DismissListener, OnTouchListener, OnHoverListener, Runnable { - public static final int CLICK_MOVEMENT_BLOCK_DURATION_MS = 500; - private static final boolean DEBUG = false; - private static final int KEY_CHANGE_HISTORY_SIZE = 10; - private static final long KEY_CHANGE_REVERT_TIME_MS = 100L; - private static final String TAG = "LbKbController"; - private boolean clickConsumed; - private long lastClickTime; - private LeanbackKeyboardContainer mContainer; - private InputMethodService mContext; - private LeanbackKeyboardController.DoubleClickDetector mDoubleClickDetector; - private LeanbackKeyboardContainer.KeyFocus mDownFocus; - private Handler mHandler; - private LeanbackKeyboardController.InputListener mInputListener; - ArrayList mKeyChangeHistory; - private LeanbackKeyboardContainer.KeyFocus mKeyDownKeyFocus; - private boolean mKeyDownReceived; - private boolean mLongPressHandled; - private int mMoveCount; - private OnLayoutChangeListener mOnLayoutChangeListener; - public float mResizeSquareDistance; - private TouchNavSpaceTracker mSpaceTracker; - private LeanbackKeyboardContainer.KeyFocus mTempFocus; - private PointF mTempPoint; - private LeanbackKeyboardController.TouchEventListener mTouchEventListener; - private long prevTime; +public class LeanbackKeyboardController implements LeanbackKeyboardContainer.VoiceListener, LeanbackKeyboardContainer.DismissListener, + OnTouchListener, OnHoverListener, Runnable { + public static final int CLICK_MOVEMENT_BLOCK_DURATION_MS = 500; + private static final boolean DEBUG = false; + private static final int KEY_CHANGE_HISTORY_SIZE = 10; + private static final long KEY_CHANGE_REVERT_TIME_MS = 100L; + private static final String TAG = "LbKbController"; + private boolean clickConsumed; + private long lastClickTime; + private LeanbackKeyboardContainer mContainer; + private InputMethodService mContext; + private LeanbackKeyboardController.DoubleClickDetector mDoubleClickDetector; + private LeanbackKeyboardContainer.KeyFocus mDownFocus; + private Handler mHandler; + private LeanbackKeyboardController.InputListener mInputListener; + ArrayList mKeyChangeHistory; + private LeanbackKeyboardContainer.KeyFocus mKeyDownKeyFocus; + private boolean mKeyDownReceived; + private boolean mLongPressHandled; + private int mMoveCount; + private OnLayoutChangeListener mOnLayoutChangeListener; + public float mResizeSquareDistance; + private TouchNavSpaceTracker mSpaceTracker; + private LeanbackKeyboardContainer.KeyFocus mTempFocus; + private PointF mTempPoint; + private LeanbackKeyboardController.TouchEventListener mTouchEventListener; + private long prevTime; - public LeanbackKeyboardController(InputMethodService var1, LeanbackKeyboardController.InputListener var2) { - this(var1, var2, new TouchNavSpaceTracker(), new LeanbackKeyboardContainer(var1)); - } + public LeanbackKeyboardController(final InputMethodService context, final LeanbackKeyboardController.InputListener listener) { + this(context, listener, new TouchNavSpaceTracker(), new LeanbackKeyboardContainer(context)); + } - LeanbackKeyboardController(InputMethodService var1, LeanbackKeyboardController.InputListener var2, TouchNavSpaceTracker var3, LeanbackKeyboardContainer var4) { - this.mDoubleClickDetector = new LeanbackKeyboardController.DoubleClickDetector(); - this.mOnLayoutChangeListener = new OnLayoutChangeListener() { - public void onLayoutChange(View var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9) { - var2 = var4 - var2; - var3 = var5 - var3; - if (var2 > 0 && var3 > 0) { - if (LeanbackKeyboardController.this.mSpaceTracker != null) { - LeanbackKeyboardController.this.mSpaceTracker.setPixelSize((float)var2, (float)var3); - } + public LeanbackKeyboardController(final InputMethodService context, final LeanbackKeyboardController.InputListener listener, final TouchNavSpaceTracker tracker, + final LeanbackKeyboardContainer container) { + mDoubleClickDetector = new LeanbackKeyboardController.DoubleClickDetector(); + mOnLayoutChangeListener = new OnLayoutChangeListener() { + @Override + public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { + left = right - left; + top = bottom - top; + if (left > 0 && top > 0) { + if (LeanbackKeyboardController.this.mSpaceTracker != null) { + LeanbackKeyboardController.this.mSpaceTracker.setPixelSize((float) left, (float) top); + } - if (var2 != var8 - var6 || var3 != var9 - var7) { - LeanbackKeyboardController.this.initInputView(); - } + if (left != oldRight - oldLeft || top != oldBottom - oldTop) { + LeanbackKeyboardController.this.initInputView(); + } + } + + } + }; + mTouchEventListener = new LeanbackKeyboardController.TouchEventListener(); + mDownFocus = new LeanbackKeyboardContainer.KeyFocus(); + mTempFocus = new LeanbackKeyboardContainer.KeyFocus(); + mKeyChangeHistory = new ArrayList<>(11); + mTempPoint = new PointF(); + mKeyDownReceived = false; + mLongPressHandled = false; + mContext = context; + mResizeSquareDistance = context.getResources().getDimension(R.dimen.resize_move_distance); + mResizeSquareDistance *= mResizeSquareDistance; + mInputListener = listener; + setSpaceTracker(tracker); + setKeyboardContainer(container); + mContainer.setVoiceListener(this); + mContainer.setDismissListener(this); + } + + private boolean applyLETVFixesDown(int keyCode) { + switch (keyCode) { + case KeyEvent.KEYCODE_MENU: + case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + case KeyEvent.KEYCODE_MEDIA_REWIND: + case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: + return true; + default: + return false; + } + } + + private boolean applyLETVFixesUp(int keyCode) { + switch (keyCode) { + case KeyEvent.KEYCODE_MENU: + this.mContainer.switchToNextKeyboard(); + break; + case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + this.fakeKeyIndex(0, 2); + break; + case KeyEvent.KEYCODE_MEDIA_REWIND: + this.fakeKeyCode(-5); + break; + case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: + this.fakeKeyCode(32); + break; + default: + return false; + } + + return true; + } + + private void beginLongClickCountdown() { + this.clickConsumed = false; + Handler handler = this.mHandler; + if (handler == null) { + handler = new Handler(); + this.mHandler = handler; + } + + handler.removeCallbacks(this); + handler.postDelayed(this, (long) 1000); + } + + private void clearKeyIfNecessary() { + ++this.mMoveCount; + if (this.mMoveCount >= 3) { + this.mMoveCount = 0; + this.mKeyDownKeyFocus = null; + } + + } + + private void commitKey() { + this.commitKey(this.mContainer.getCurrFocus()); + } + + private void commitKey(LeanbackKeyboardContainer.KeyFocus focus) { + if (mContainer != null && focus != null) { + switch (focus.type) { + case KeyFocus.TYPE_VOICE: + mContainer.onVoiceClick(); + return; + case KeyFocus.TYPE_ACTION: + mInputListener.onEntry(InputListener.ENTRY_TYPE_ACTION, 0, null); + return; + case KeyFocus.TYPE_SUGGESTION: + mInputListener.onEntry(InputListener.ENTRY_TYPE_SUGGESTION, 0, mContainer.getSuggestionText(focus.index)); + return; + default: + Key key = mContainer.getKey(focus.type, focus.index); + if (key != null) { + handleCommitKeyboardKey(key.codes[0], key.label); + } + } + } + + } + + private void fakeClickDown() { + mContainer.setTouchState(LeanbackKeyboardContainer.TOUCH_STATE_CLICK); + } + + private void fakeClickUp() { + LeanbackKeyboardContainer container = mContainer; + commitKey(container.getCurrFocus()); + container.setTouchState(0); + } + + private void fakeKeyCode(final int keyCode) { + mContainer.getCurrFocus().code = keyCode; + handleCommitKeyboardKey(keyCode, null); + } + + private void fakeKeyIndex(final int index, final int type) { + LeanbackKeyboardContainer.KeyFocus focus = mContainer.getCurrFocus(); + focus.index = index; + focus.type = type; + commitKey(focus); + } + + private void fakeLongClickDown() { + LeanbackKeyboardContainer container = mContainer; + container.onKeyLongPress(); + container.setTouchState(LeanbackKeyboardContainer.TOUCH_STATE_CLICK); + } + + private void fakeLongClickUp() { + this.mContainer.setTouchState(0); + } + + private PointF getBestSnapPosition(PointF var1, long var2) { + if (this.mKeyChangeHistory.size() <= 1) { + return var1; + } else { + int var4 = 0; + + PointF var5; + while (true) { + var5 = var1; + if (var4 >= this.mKeyChangeHistory.size() - 1) { + break; + } + + LeanbackKeyboardController.KeyChange var6 = (LeanbackKeyboardController.KeyChange) this.mKeyChangeHistory.get(var4); + if (var2 - ((LeanbackKeyboardController.KeyChange) this.mKeyChangeHistory.get(var4 + 1)).time < 100L) { + var5 = var6.position; + this.mKeyChangeHistory.clear(); + this.mKeyChangeHistory.add(new LeanbackKeyboardController.KeyChange(var2, var5)); + break; + } + + ++var4; } - } - }; - this.mTouchEventListener = new LeanbackKeyboardController.TouchEventListener(); - this.mDownFocus = new LeanbackKeyboardContainer.KeyFocus(); - this.mTempFocus = new LeanbackKeyboardContainer.KeyFocus(); - this.mKeyChangeHistory = new ArrayList(11); - this.mTempPoint = new PointF(); - this.mKeyDownReceived = false; - this.mLongPressHandled = false; - this.mContext = var1; - this.mResizeSquareDistance = var1.getResources().getDimension(R.dimen.resize_move_distance); - this.mResizeSquareDistance *= this.mResizeSquareDistance; - this.mInputListener = var2; - this.setSpaceTracker(var3); - this.setKeyboardContainer(var4); - this.mContainer.setVoiceListener(this); - this.mContainer.setDismissListener(this); - } + return var5; + } + } - private boolean applyLETVFixesDown(int var1) { - switch(var1) { - case 82: - case 85: - case 89: - case 90: - return true; - default: - return false; - } - } + private PointF getCurrentKeyPosition() { + if (this.mContainer != null) { + LeanbackKeyboardContainer.KeyFocus var1 = this.mContainer.getCurrFocus(); + return new PointF((float) var1.rect.centerX(), (float) var1.rect.centerY()); + } else { + return null; + } + } - private boolean applyLETVFixesUp(int var1) { - switch(var1) { - case 82: - this.mContainer.switchToNextKeyboard(); - break; - case 85: - this.fakeKeyIndex(0, 2); - break; - case 89: - this.fakeKeyCode(-5); - break; - case 90: - this.fakeKeyCode(32); - break; - default: - return false; - } + private PointF getRelativePosition(View var1, MotionEvent var2) { + int[] var5 = new int[2]; + var1.getLocationOnScreen(var5); + float var3 = var2.getRawX(); + float var4 = var2.getRawY(); + return new PointF(var3 - (float) var5[0], var4 - (float) var5[1]); + } - return true; - } - - private void beginLongClickCountdown() { - this.clickConsumed = false; - Handler var2 = this.mHandler; - Handler var1 = var2; - if (var2 == null) { - var1 = new Handler(); - this.mHandler = var1; - } - - var1.removeCallbacks(this); - var1.postDelayed(this, (long)1000); - } - - private void clearKeyIfNecessary() { - ++this.mMoveCount; - if (this.mMoveCount >= 3) { - this.mMoveCount = 0; - this.mKeyDownKeyFocus = null; - } - - } - - private void commitKey() { - this.commitKey(this.mContainer.getCurrFocus()); - } - - private void commitKey(LeanbackKeyboardContainer.KeyFocus var1) { - if (this.mContainer != null && var1 != null) { - switch(var1.type) { - case 1: - this.mContainer.onVoiceClick(); - return; - case 2: - this.mInputListener.onEntry(5, 0, (CharSequence)null); - return; - case 3: - this.mInputListener.onEntry(2, 0, this.mContainer.getSuggestionText(var1.index)); - return; - default: - Key var2 = this.mContainer.getKey(var1.type, var1.index); - if (var2 != null) { - this.handleCommitKeyboardKey(var2.codes[0], var2.label); - return; - } - } - } - - } - - private void fakeClickDown() { - this.mContainer.setTouchState(3); - } - - private void fakeClickUp() { - LeanbackKeyboardContainer var1 = this.mContainer; - this.commitKey(var1.getCurrFocus()); - var1.setTouchState(0); - } - - private void fakeKeyCode(int var1) { - this.mContainer.getCurrFocus().code = var1; - this.handleCommitKeyboardKey(var1, (CharSequence)null); - } - - private void fakeKeyIndex(int var1, int var2) { - LeanbackKeyboardContainer.KeyFocus var3 = this.mContainer.getCurrFocus(); - var3.index = var1; - var3.type = var2; - this.commitKey(var3); - } - - private void fakeLongClickDown() { - LeanbackKeyboardContainer var1 = this.mContainer; - var1.onKeyLongPress(); - var1.setTouchState(3); - } - - private void fakeLongClickUp() { - this.mContainer.setTouchState(0); - } - - private PointF getBestSnapPosition(PointF var1, long var2) { - if (this.mKeyChangeHistory.size() <= 1) { - return var1; - } else { - int var4 = 0; - - PointF var5; - while(true) { - var5 = var1; - if (var4 >= this.mKeyChangeHistory.size() - 1) { - break; - } - - LeanbackKeyboardController.KeyChange var6 = (LeanbackKeyboardController.KeyChange)this.mKeyChangeHistory.get(var4); - if (var2 - ((LeanbackKeyboardController.KeyChange)this.mKeyChangeHistory.get(var4 + 1)).time < 100L) { - var5 = var6.position; - this.mKeyChangeHistory.clear(); - this.mKeyChangeHistory.add(new LeanbackKeyboardController.KeyChange(var2, var5)); - break; - } - - ++var4; - } - - return var5; - } - } - - private PointF getCurrentKeyPosition() { - if (this.mContainer != null) { - LeanbackKeyboardContainer.KeyFocus var1 = this.mContainer.getCurrFocus(); - return new PointF((float)var1.rect.centerX(), (float)var1.rect.centerY()); - } else { - return null; - } - } - - private PointF getRelativePosition(View var1, MotionEvent var2) { - int[] var5 = new int[2]; - var1.getLocationOnScreen(var5); - float var3 = var2.getRawX(); - float var4 = var2.getRawY(); - return new PointF(var3 - (float)var5[0], var4 - (float)var5[1]); - } - - private int getSimplifiedKey(int var1) { - int var2 = 23; - if (var1 != 23) { - byte var3 = 66; - var2 = var3; - if (var1 != 66) { + private int getSimplifiedKey(int var1) { + int var2 = 23; + if (var1 != 23) { + byte var3 = 66; var2 = var3; - if (var1 != 160) { - var2 = var1; - if (var1 == 96) { - var2 = var3; - } + if (var1 != 66) { + var2 = var3; + if (var1 != 160) { + var2 = var1; + if (var1 == 96) { + var2 = var3; + } + } } - } - } + } - var1 = var2; - if (var2 == 97) { - var1 = 4; - } + var1 = var2; + if (var2 == 97) { + var1 = 4; + } - return var1; - } + return var1; + } - private void handleCommitKeyboardKey(int var1, CharSequence var2) { - switch(var1) { - case -8: - this.mContainer.dismissMiniKeyboard(); - return; - case -7: - this.mContainer.startVoiceRecording(); - return; - case -6: - this.mContainer.onShiftDoubleClick(this.mContainer.isCapsLockOn()); - return; - case -5: - this.mInputListener.onEntry(1, 0, (CharSequence)null); - return; - case -4: - this.mInputListener.onEntry(4, 0, (CharSequence)null); - return; - case -3: - this.mInputListener.onEntry(3, 0, (CharSequence)null); - return; - case -2: - if (Log.isLoggable("LbKbController", Log.DEBUG)) { - Log.d("LbKbController", "mode change"); - } + private void handleCommitKeyboardKey(int keyCode, CharSequence text) { + switch (keyCode) { + case LeanbackKeyboardView.KEYCODE_DISMISS_MINI_KEYBOARD: + this.mContainer.dismissMiniKeyboard(); + return; + case LeanbackKeyboardView.KEYCODE_VOICE: + this.mContainer.startVoiceRecording(); + return; + case LeanbackKeyboardView.KEYCODE_CAPS_LOCK: + this.mContainer.onShiftDoubleClick(this.mContainer.isCapsLockOn()); + return; + case LeanbackKeyboardView.KEYCODE_DELETE: + this.mInputListener.onEntry(InputListener.ENTRY_TYPE_BACKSPACE, LeanbackKeyboardView.SHIFT_OFF, null); + return; + case LeanbackKeyboardView.KEYCODE_RIGHT: + this.mInputListener.onEntry(InputListener.ENTRY_TYPE_RIGHT, LeanbackKeyboardView.SHIFT_OFF, null); + return; + case LeanbackKeyboardView.KEYCODE_LEFT: + this.mInputListener.onEntry(InputListener.ENTRY_TYPE_LEFT, LeanbackKeyboardView.SHIFT_OFF, null); + return; + case LeanbackKeyboardView.KEYCODE_SYM_TOGGLE: + if (Log.isLoggable("LbKbController", Log.DEBUG)) { + Log.d("LbKbController", "mode change"); + } - this.mContainer.onModeChangeClick(); - return; - case -1: - if (Log.isLoggable("LbKbController", Log.DEBUG)) { - Log.d("LbKbController", "shift"); - } + this.mContainer.onModeChangeClick(); + return; + case LeanbackKeyboardView.KEYCODE_SHIFT: + if (Log.isLoggable("LbKbController", Log.DEBUG)) { + Log.d("LbKbController", "shift"); + } - this.mContainer.onShiftClick(); - return; - case 32: - this.mInputListener.onEntry(0, var1, " "); - this.mContainer.onSpaceEntry(); - return; - case 46: - this.mInputListener.onEntry(0, var1, var2); - this.mContainer.onPeriodEntry(); - return; - default: - this.mInputListener.onEntry(0, var1, var2); - this.mContainer.onTextEntry(); - if (this.mContainer.isMiniKeyboardOnScreen()) { - this.mContainer.dismissMiniKeyboard(); - } + this.mContainer.onShiftClick(); + return; + case LeanbackKeyboardView.ASCII_SPACE: + this.mInputListener.onEntry(InputListener.ENTRY_TYPE_STRING, keyCode, " "); + this.mContainer.onSpaceEntry(); + return; + case LeanbackKeyboardView.ASCII_PERIOD: + this.mInputListener.onEntry(InputListener.ENTRY_TYPE_STRING, keyCode, text); + this.mContainer.onPeriodEntry(); + return; + default: + this.mInputListener.onEntry(InputListener.ENTRY_TYPE_STRING, keyCode, text); + this.mContainer.onTextEntry(); + if (this.mContainer.isMiniKeyboardOnScreen()) { + this.mContainer.dismissMiniKeyboard(); + } - } - } + } + } - private boolean handleKeyDownEvent(int var1, int var2) { - var1 = this.getSimplifiedKey(var1); - boolean var3; - boolean var4; - if (var1 == 4) { - this.mContainer.cancelVoiceRecording(); - var3 = false; - } else if (this.mContainer.isVoiceVisible()) { - if (var1 == 22 || var1 == 23 || var1 == 66) { + private boolean handleKeyDownEvent(int var1, int var2) { + var1 = this.getSimplifiedKey(var1); + boolean var3; + boolean var4; + if (var1 == 4) { this.mContainer.cancelVoiceRecording(); - } - - var3 = true; - } else { - var4 = true; - var3 = var4; - switch(var1) { - case 19: - var3 = this.onDirectionalMove(8); - break; - case 20: - var3 = this.onDirectionalMove(2); - break; - case 21: - var3 = this.onDirectionalMove(1); - break; - case 22: - var3 = this.onDirectionalMove(4); - break; - case 23: - case 66: - if (var2 == 0) { - this.mMoveCount = 0; - this.mKeyDownKeyFocus = new LeanbackKeyboardContainer.KeyFocus(); - this.mKeyDownKeyFocus.set(this.mContainer.getCurrFocus()); - } else if (var2 == 1 && this.handleKeyLongPress(var1)) { - this.mKeyDownKeyFocus = null; - } - - var3 = var4; - if (this.isKeyHandledOnKeyDown(this.mContainer.getCurrKeyCode())) { - this.commitKey(); - var3 = var4; - } - break; - case 99: - this.handleCommitKeyboardKey(-5, (CharSequence)null); - var3 = var4; - break; - case 100: - this.handleCommitKeyboardKey(32, (CharSequence)null); - var3 = var4; - break; - case 102: - this.handleCommitKeyboardKey(-3, (CharSequence)null); - var3 = var4; - break; - case 103: - this.handleCommitKeyboardKey(-4, (CharSequence)null); - var3 = var4; - case 106: - case 107: - break; - default: var3 = false; - } - } - - var4 = var3; - if (!var3) { - var4 = this.applyLETVFixesDown(var1); - } - - return var4; - } - - private boolean handleKeyLongPress(int var1) { - boolean var2; - if (this.isEnterKey(var1) && this.mContainer.onKeyLongPress()) { - var2 = true; - } else { - var2 = false; - } - - this.mLongPressHandled = var2; - if (this.mContainer.isMiniKeyboardOnScreen()) { - Log.d("LbKbController", "mini keyboard shown after long press"); - } - - return this.mLongPressHandled; - } - - private boolean handleKeyUpEvent(int var1, long var2) { - var1 = this.getSimplifiedKey(var1); - boolean var4; - boolean var5; - if (var1 == 4) { - var4 = false; - } else if (this.mContainer.isVoiceVisible()) { - var4 = true; - } else { - var5 = true; - var4 = var5; - switch(var1) { - case 19: - case 20: - case 21: - case 22: - this.clearKeyIfNecessary(); - var4 = var5; - break; - case 23: - case 66: - if (this.mContainer.getCurrKeyCode() == -1) { - this.mDoubleClickDetector.addEvent(var2); - var4 = var5; - } else { - var4 = var5; - if (!this.isKeyHandledOnKeyDown(this.mContainer.getCurrKeyCode())) { - this.commitKey(this.mKeyDownKeyFocus); - var4 = var5; - } + } else if (this.mContainer.isVoiceVisible()) { + if (var1 == 22 || var1 == 23 || var1 == 66) { + this.mContainer.cancelVoiceRecording(); } - case 99: - case 100: - case 102: - case 103: - break; - case 106: - this.handleCommitKeyboardKey(-2, (CharSequence)null); - var4 = var5; - break; - case 107: - this.handleCommitKeyboardKey(-6, (CharSequence)null); - var4 = var5; - break; - default: + + var3 = true; + } else { + var4 = true; + var3 = var4; + switch (var1) { + case 19: + var3 = this.onDirectionalMove(8); + break; + case 20: + var3 = this.onDirectionalMove(2); + break; + case 21: + var3 = this.onDirectionalMove(1); + break; + case 22: + var3 = this.onDirectionalMove(4); + break; + case 23: + case 66: + if (var2 == 0) { + this.mMoveCount = 0; + this.mKeyDownKeyFocus = new LeanbackKeyboardContainer.KeyFocus(); + this.mKeyDownKeyFocus.set(this.mContainer.getCurrFocus()); + } else if (var2 == 1 && this.handleKeyLongPress(var1)) { + this.mKeyDownKeyFocus = null; + } + + var3 = var4; + if (this.isKeyHandledOnKeyDown(this.mContainer.getCurrKeyCode())) { + this.commitKey(); + var3 = var4; + } + break; + case 99: + this.handleCommitKeyboardKey(-5, (CharSequence) null); + var3 = var4; + break; + case 100: + this.handleCommitKeyboardKey(32, (CharSequence) null); + var3 = var4; + break; + case 102: + this.handleCommitKeyboardKey(-3, (CharSequence) null); + var3 = var4; + break; + case 103: + this.handleCommitKeyboardKey(-4, (CharSequence) null); + var3 = var4; + case 106: + case 107: + break; + default: + var3 = false; + } + } + + var4 = var3; + if (!var3) { + var4 = this.applyLETVFixesDown(var1); + } + + return var4; + } + + private boolean handleKeyLongPress(int var1) { + boolean var2; + if (this.isEnterKey(var1) && this.mContainer.onKeyLongPress()) { + var2 = true; + } else { + var2 = false; + } + + this.mLongPressHandled = var2; + if (this.mContainer.isMiniKeyboardOnScreen()) { + Log.d("LbKbController", "mini keyboard shown after long press"); + } + + return this.mLongPressHandled; + } + + private boolean handleKeyUpEvent(int var1, long var2) { + var1 = this.getSimplifiedKey(var1); + boolean var4; + boolean var5; + if (var1 == 4) { var4 = false; - } - } + } else if (this.mContainer.isVoiceVisible()) { + var4 = true; + } else { + var5 = true; + var4 = var5; + switch (var1) { + case 19: + case 20: + case 21: + case 22: + this.clearKeyIfNecessary(); + var4 = var5; + break; + case 23: + case 66: + if (this.mContainer.getCurrKeyCode() == -1) { + this.mDoubleClickDetector.addEvent(var2); + var4 = var5; + } else { + var4 = var5; + if (!this.isKeyHandledOnKeyDown(this.mContainer.getCurrKeyCode())) { + this.commitKey(this.mKeyDownKeyFocus); + var4 = var5; + } + } + case 99: + case 100: + case 102: + case 103: + break; + case 106: + this.handleCommitKeyboardKey(-2, (CharSequence) null); + var4 = var5; + break; + case 107: + this.handleCommitKeyboardKey(-6, (CharSequence) null); + var4 = var5; + break; + default: + var4 = false; + } + } - var5 = var4; - if (!var4) { - var5 = this.applyLETVFixesUp(var1); - } + var5 = var4; + if (!var4) { + var5 = this.applyLETVFixesUp(var1); + } - return var5; - } + return var5; + } - private void initInputView() { - this.mContainer.onInitInputView(); - this.updatePositionToCurrentFocus(); - } + private void initInputView() { + this.mContainer.onInitInputView(); + this.updatePositionToCurrentFocus(); + } - private boolean isCallAllowed(int var1) { - long var2 = System.currentTimeMillis(); - if (this.prevTime != 0L && var2 - this.prevTime <= (long)(var1 * 3)) { - if (var2 - this.prevTime > (long)var1) { - this.prevTime = 0L; + private boolean isCallAllowed(int var1) { + long var2 = System.currentTimeMillis(); + if (this.prevTime != 0L && var2 - this.prevTime <= (long) (var1 * 3)) { + if (var2 - this.prevTime > (long) var1) { + this.prevTime = 0L; + return true; + } + } else { + this.prevTime = var2; + } + + return false; + } + + private boolean isDoubleClick() { + long var1 = System.currentTimeMillis(); + long var3 = this.lastClickTime; + if (this.lastClickTime != 0L && var1 - var3 <= (long) 300) { return true; - } - } else { - this.prevTime = var2; - } - - return false; - } - - private boolean isDoubleClick() { - long var1 = System.currentTimeMillis(); - long var3 = this.lastClickTime; - if (this.lastClickTime != 0L && var1 - var3 <= (long)300) { - return true; - } else { - this.lastClickTime = var1; - return false; - } - } - - private boolean isEnterKey(int var1) { - var1 = this.getSimplifiedKey(var1); - return var1 == 23 || var1 == 66; - } - - private boolean isKeyHandledOnKeyDown(int var1) { - return var1 == -5 || var1 == -3 || var1 == -4; - } - - private void moveSelectorToPoint(float var1, float var2) { - LeanbackKeyboardContainer var3 = this.mContainer; - LeanbackKeyboardContainer.KeyFocus var4 = this.mTempFocus; - var3.getBestFocus(new Float(var1), new Float(var2), var4); - this.mContainer.setFocus(this.mTempFocus); - var3 = this.mContainer; - Rect var5 = this.mTempFocus.rect; - var3.alignSelector((float)var5.centerX(), (float)var5.centerY(), false); - } - - private boolean onDirectionalMove(int var1) { - if (this.mContainer.getNextFocusInDirection(var1, this.mDownFocus, this.mTempFocus)) { - this.mContainer.setFocus(this.mTempFocus); - this.mDownFocus.set(this.mTempFocus); - this.clearKeyIfNecessary(); - } - - return true; - } - - private void performBestSnap(long var1) { - LeanbackKeyboardContainer.KeyFocus var3 = this.mContainer.getCurrFocus(); - this.mTempPoint.x = (float)var3.rect.centerX(); - this.mTempPoint.y = (float)var3.rect.centerY(); - PointF var4 = this.getBestSnapPosition(this.mTempPoint, var1); - this.mContainer.getBestFocus(var4.x, var4.y, this.mTempFocus); - this.mContainer.setFocus(this.mTempFocus); - this.updatePositionToCurrentFocus(); - } - - private void setKeyState(int var1, boolean var2) { - LeanbackKeyboardContainer var3 = this.mContainer; - LeanbackKeyboardContainer.KeyFocus var4 = var3.getCurrFocus(); - var4.index = var1; - var4.type = 0; - byte var5; - if (var2) { - var5 = 3; - } else { - var5 = 0; - } - - var3.setTouchState(var5); - } - - private void updatePositionToCurrentFocus() { - PointF var1 = this.getCurrentKeyPosition(); - if (var1 != null && this.mSpaceTracker != null) { - this.mSpaceTracker.setPixelPosition(var1.x, var1.y); - } - - } - - public boolean areSuggestionsEnabled() { - return this.mContainer != null ? this.mContainer.areSuggestionsEnabled() : false; - } - - public boolean enableAutoEnterSpace() { - return this.mContainer != null ? this.mContainer.enableAutoEnterSpace() : false; - } - - public View getView() { - if (this.mContainer != null) { - RelativeLayout var1 = this.mContainer.getView(); - var1.setClickable(true); - var1.setOnTouchListener(this); - var1.setOnHoverListener(this); - Button var2 = this.mContainer.getGoButton(); - var2.setOnTouchListener(this); - var2.setOnHoverListener(this); - var2.setTag("Go"); - return var1; - } else { - return null; - } - } - - public void onDismiss(boolean var1) { - if (var1) { - this.mInputListener.onEntry(8, 0, (CharSequence)null); - } else { - this.mInputListener.onEntry(7, 0, (CharSequence)null); - } - } - - public boolean onGenericMotionEvent(MotionEvent var1) { - return this.mSpaceTracker != null && this.mContext != null && this.mContext.isInputViewShown() && this.mSpaceTracker.onGenericMotionEvent(var1); - } - - public boolean onHover(View var1, MotionEvent var2) { - boolean var4 = this.isCallAllowed(300); - boolean var3 = var4; - if (var4) { - if (var2.getAction() == 7) { - PointF var5 = this.getRelativePosition(this.mContainer.getView(), var2); - this.moveSelectorToPoint(var5.x, var5.y); - } - - var3 = true; - } - - return var3; - } - - public boolean onKeyDown(int var1, KeyEvent var2) { - this.mDownFocus.set(this.mContainer.getCurrFocus()); - if (this.mSpaceTracker != null && this.mSpaceTracker.onKeyDown(var1, var2)) { - return true; - } else { - if (this.isEnterKey(var1)) { - this.mKeyDownReceived = true; - if (var2.getRepeatCount() == 0) { - this.mContainer.setTouchState(3); - } - } - - return this.handleKeyDownEvent(var1, var2.getRepeatCount()); - } - } - - public boolean onKeyUp(int var1, KeyEvent var2) { - if (this.mSpaceTracker != null && this.mSpaceTracker.onKeyUp(var1, var2)) { - return true; - } else { - if (this.isEnterKey(var1)) { - if (!this.mKeyDownReceived || this.mLongPressHandled) { - this.mLongPressHandled = false; - return true; - } - - this.mKeyDownReceived = false; - if (this.mContainer.getTouchState() == 3) { - this.mContainer.setTouchState(1); - } - } - - return this.handleKeyUpEvent(var1, var2.getEventTime()); - } - } - - public void onStartInput(EditorInfo var1) { - if (this.mContainer != null) { - this.mContainer.onStartInput(var1); - this.initInputView(); - } - - } - - public void onStartInputView() { - this.mKeyDownReceived = false; - if (this.mContainer != null) { - this.mContainer.onStartInputView(); - } - - this.mDoubleClickDetector.reset(); - } - - public boolean onTouch(View var1, MotionEvent var2) { - Object var3 = var1.getTag(); - if (var3 != null && "Go".equals(var3)) { - this.fakeKeyIndex(0, 2); - } else { - switch(var2.getAction()) { - case 0: - this.moveSelectorToPoint(var2.getX(), var2.getY()); - this.fakeClickDown(); - this.beginLongClickCountdown(); - break; - case 1: - if (!this.clickConsumed) { - this.clickConsumed = true; - if (this.isDoubleClick()) { - this.mContainer.onKeyLongPress(); - break; - } - - this.fakeClickUp(); - } - - this.fakeLongClickUp(); - break; - default: + } else { + this.lastClickTime = var1; return false; - } - } + } + } - return true; - } + private boolean isEnterKey(int var1) { + var1 = this.getSimplifiedKey(var1); + return var1 == 23 || var1 == 66; + } - public void onVoiceResult(String var1) { - this.mInputListener.onEntry(6, 0, var1); - } + private boolean isKeyHandledOnKeyDown(int var1) { + return var1 == -5 || var1 == -3 || var1 == -4; + } - public void run() { - if (!this.clickConsumed) { - this.clickConsumed = true; - this.fakeLongClickDown(); - } - } + private void moveSelectorToPoint(float var1, float var2) { + LeanbackKeyboardContainer var3 = this.mContainer; + LeanbackKeyboardContainer.KeyFocus var4 = this.mTempFocus; + var3.getBestFocus(new Float(var1), new Float(var2), var4); + this.mContainer.setFocus(this.mTempFocus); + var3 = this.mContainer; + Rect var5 = this.mTempFocus.rect; + var3.alignSelector((float) var5.centerX(), (float) var5.centerY(), false); + } - public void setKeyboardContainer(LeanbackKeyboardContainer var1) { - this.mContainer = var1; - var1.getView().addOnLayoutChangeListener(this.mOnLayoutChangeListener); - } + private boolean onDirectionalMove(int var1) { + if (this.mContainer.getNextFocusInDirection(var1, this.mDownFocus, this.mTempFocus)) { + this.mContainer.setFocus(this.mTempFocus); + this.mDownFocus.set(this.mTempFocus); + this.clearKeyIfNecessary(); + } - public void setSpaceTracker(TouchNavSpaceTracker var1) { - this.mSpaceTracker = var1; - var1.setLPFEnabled(true); - var1.setKeyEventListener(this.mTouchEventListener); - } + return true; + } - public void updateAddonKeyboard() { - this.mContainer.updateAddonKeyboard(); - } + private void performBestSnap(long var1) { + LeanbackKeyboardContainer.KeyFocus var3 = this.mContainer.getCurrFocus(); + this.mTempPoint.x = (float) var3.rect.centerX(); + this.mTempPoint.y = (float) var3.rect.centerY(); + PointF var4 = this.getBestSnapPosition(this.mTempPoint, var1); + this.mContainer.getBestFocus(var4.x, var4.y, this.mTempFocus); + this.mContainer.setFocus(this.mTempFocus); + this.updatePositionToCurrentFocus(); + } - public void updateSuggestions(ArrayList var1) { - if (this.mContainer != null) { - this.mContainer.updateSuggestions(var1); - } + private void setKeyState(int var1, boolean var2) { + LeanbackKeyboardContainer var3 = this.mContainer; + LeanbackKeyboardContainer.KeyFocus var4 = var3.getCurrFocus(); + var4.index = var1; + var4.type = 0; + byte var5; + if (var2) { + var5 = 3; + } else { + var5 = 0; + } - } + var3.setTouchState(var5); + } - private class DoubleClickDetector { - final long DOUBLE_CLICK_TIMEOUT_MS; - boolean mFirstClickShiftLocked; - long mFirstClickTime; + private void updatePositionToCurrentFocus() { + PointF var1 = this.getCurrentKeyPosition(); + if (var1 != null && this.mSpaceTracker != null) { + this.mSpaceTracker.setPixelPosition(var1.x, var1.y); + } - private DoubleClickDetector() { - this.DOUBLE_CLICK_TIMEOUT_MS = 200L; - this.mFirstClickTime = 0L; - } + } - public void addEvent(long var1) { - if (var1 - this.mFirstClickTime > 200L) { - this.mFirstClickTime = var1; - this.mFirstClickShiftLocked = LeanbackKeyboardController.this.mContainer.isCapsLockOn(); - LeanbackKeyboardController.this.commitKey(); - } else { - LeanbackKeyboardController.this.mContainer.onShiftDoubleClick(this.mFirstClickShiftLocked); - this.reset(); - } - } + public boolean areSuggestionsEnabled() { + return this.mContainer != null ? this.mContainer.areSuggestionsEnabled() : false; + } - public void reset() { - this.mFirstClickTime = 0L; - } - } + public boolean enableAutoEnterSpace() { + return this.mContainer != null ? this.mContainer.enableAutoEnterSpace() : false; + } - public interface InputListener { - int ENTRY_TYPE_ACTION = 5; - int ENTRY_TYPE_BACKSPACE = 1; - int ENTRY_TYPE_DISMISS = 7; - int ENTRY_TYPE_LEFT = 3; - int ENTRY_TYPE_RIGHT = 4; - int ENTRY_TYPE_STRING = 0; - int ENTRY_TYPE_SUGGESTION = 2; - int ENTRY_TYPE_VOICE = 6; - int ENTRY_TYPE_VOICE_DISMISS = 8; + public View getView() { + if (this.mContainer != null) { + RelativeLayout var1 = this.mContainer.getView(); + var1.setClickable(true); + var1.setOnTouchListener(this); + var1.setOnHoverListener(this); + Button var2 = this.mContainer.getGoButton(); + var2.setOnTouchListener(this); + var2.setOnHoverListener(this); + var2.setTag("Go"); + return var1; + } else { + return null; + } + } - void onEntry(int var1, int var2, CharSequence var3); - } + public void onDismiss(boolean var1) { + if (var1) { + this.mInputListener.onEntry(8, 0, (CharSequence) null); + } else { + this.mInputListener.onEntry(7, 0, (CharSequence) null); + } + } - private static final class KeyChange { - public PointF position; - public long time; + public boolean onGenericMotionEvent(MotionEvent var1) { + return this.mSpaceTracker != null && this.mContext != null && this.mContext.isInputViewShown() && this.mSpaceTracker.onGenericMotionEvent + (var1); + } - public KeyChange(long var1, PointF var3) { - this.time = var1; - this.position = var3; - } - } - - private class TouchEventListener implements TouchNavSpaceTracker.KeyEventListener { - private TouchEventListener() { - } - - public boolean onKeyDown(int var1, KeyEvent var2) { - if (LeanbackKeyboardController.this.isEnterKey(var1)) { - LeanbackKeyboardController.this.mKeyDownReceived = true; - if (var2.getRepeatCount() == 0) { - LeanbackKeyboardController.this.mContainer.setTouchState(3); - LeanbackKeyboardController.this.mSpaceTracker.blockMovementUntil(var2.getEventTime() + 500L); - LeanbackKeyboardController.this.performBestSnap(var2.getEventTime()); - } - } - - return LeanbackKeyboardController.this.handleKeyDownEvent(var1, var2.getRepeatCount()); - } - - public boolean onKeyLongPress(int var1, KeyEvent var2) { - return LeanbackKeyboardController.this.handleKeyLongPress(var1); - } - - public boolean onKeyUp(int var1, KeyEvent var2) { - if (LeanbackKeyboardController.this.isEnterKey(var1)) { - if (!LeanbackKeyboardController.this.mKeyDownReceived || LeanbackKeyboardController.this.mLongPressHandled) { - LeanbackKeyboardController.this.mLongPressHandled = false; - return true; + public boolean onHover(View var1, MotionEvent var2) { + boolean var4 = this.isCallAllowed(300); + boolean var3 = var4; + if (var4) { + if (var2.getAction() == 7) { + PointF var5 = this.getRelativePosition(this.mContainer.getView(), var2); + this.moveSelectorToPoint(var5.x, var5.y); } - LeanbackKeyboardController.this.mKeyDownReceived = false; - if (LeanbackKeyboardController.this.mContainer.getTouchState() == 3) { - LeanbackKeyboardController.this.mContainer.setTouchState(1); - LeanbackKeyboardController.this.mSpaceTracker.unblockMovement(); - } - } + var3 = true; + } - return LeanbackKeyboardController.this.handleKeyUpEvent(var1, var2.getEventTime()); - } - } + return var3; + } + + public boolean onKeyDown(int var1, KeyEvent event) { + this.mDownFocus.set(this.mContainer.getCurrFocus()); + if (this.mSpaceTracker != null && this.mSpaceTracker.onKeyDown(var1, event)) { + return true; + } else { + if (this.isEnterKey(var1)) { + this.mKeyDownReceived = true; + if (event.getRepeatCount() == 0) { + this.mContainer.setTouchState(3); + } + } + + return this.handleKeyDownEvent(var1, event.getRepeatCount()); + } + } + + public boolean onKeyUp(int var1, KeyEvent var2) { + if (this.mSpaceTracker != null && this.mSpaceTracker.onKeyUp(var1, var2)) { + return true; + } else { + if (this.isEnterKey(var1)) { + if (!this.mKeyDownReceived || this.mLongPressHandled) { + this.mLongPressHandled = false; + return true; + } + + this.mKeyDownReceived = false; + if (this.mContainer.getTouchState() == 3) { + this.mContainer.setTouchState(1); + } + } + + return this.handleKeyUpEvent(var1, var2.getEventTime()); + } + } + + public void onStartInput(EditorInfo var1) { + if (this.mContainer != null) { + this.mContainer.onStartInput(var1); + this.initInputView(); + } + + } + + public void onStartInputView() { + this.mKeyDownReceived = false; + if (this.mContainer != null) { + this.mContainer.onStartInputView(); + } + + this.mDoubleClickDetector.reset(); + } + + public boolean onTouch(View var1, MotionEvent var2) { + Object var3 = var1.getTag(); + if (var3 != null && "Go".equals(var3)) { + this.fakeKeyIndex(0, 2); + } else { + switch (var2.getAction()) { + case 0: + this.moveSelectorToPoint(var2.getX(), var2.getY()); + this.fakeClickDown(); + this.beginLongClickCountdown(); + break; + case 1: + if (!this.clickConsumed) { + this.clickConsumed = true; + if (this.isDoubleClick()) { + this.mContainer.onKeyLongPress(); + break; + } + + this.fakeClickUp(); + } + + this.fakeLongClickUp(); + break; + default: + return false; + } + } + + return true; + } + + public void onVoiceResult(String var1) { + this.mInputListener.onEntry(6, 0, var1); + } + + public void run() { + if (!this.clickConsumed) { + this.clickConsumed = true; + this.fakeLongClickDown(); + } + } + + public void setKeyboardContainer(LeanbackKeyboardContainer var1) { + this.mContainer = var1; + var1.getView().addOnLayoutChangeListener(this.mOnLayoutChangeListener); + } + + public void setSpaceTracker(TouchNavSpaceTracker var1) { + this.mSpaceTracker = var1; + var1.setLPFEnabled(true); + var1.setKeyEventListener(this.mTouchEventListener); + } + + public void updateAddonKeyboard() { + this.mContainer.updateAddonKeyboard(); + } + + public void updateSuggestions(ArrayList var1) { + if (this.mContainer != null) { + this.mContainer.updateSuggestions(var1); + } + + } + + private class DoubleClickDetector { + final long DOUBLE_CLICK_TIMEOUT_MS; + boolean mFirstClickShiftLocked; + long mFirstClickTime; + + private DoubleClickDetector() { + this.DOUBLE_CLICK_TIMEOUT_MS = 200L; + this.mFirstClickTime = 0L; + } + + public void addEvent(long var1) { + if (var1 - this.mFirstClickTime > 200L) { + this.mFirstClickTime = var1; + this.mFirstClickShiftLocked = LeanbackKeyboardController.this.mContainer.isCapsLockOn(); + LeanbackKeyboardController.this.commitKey(); + } else { + LeanbackKeyboardController.this.mContainer.onShiftDoubleClick(this.mFirstClickShiftLocked); + this.reset(); + } + } + + public void reset() { + this.mFirstClickTime = 0L; + } + } + + public interface InputListener { + int ENTRY_TYPE_ACTION = 5; + int ENTRY_TYPE_BACKSPACE = 1; + int ENTRY_TYPE_DISMISS = 7; + int ENTRY_TYPE_LEFT = 3; + int ENTRY_TYPE_RIGHT = 4; + int ENTRY_TYPE_STRING = 0; + int ENTRY_TYPE_SUGGESTION = 2; + int ENTRY_TYPE_VOICE = 6; + int ENTRY_TYPE_VOICE_DISMISS = 8; + + void onEntry(int type, int keyCode, CharSequence text); + } + + private static final class KeyChange { + public PointF position; + public long time; + + public KeyChange(long var1, PointF var3) { + this.time = var1; + this.position = var3; + } + } + + private class TouchEventListener implements TouchNavSpaceTracker.KeyEventListener { + private TouchEventListener() { + } + + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (LeanbackKeyboardController.this.isEnterKey(keyCode)) { + LeanbackKeyboardController.this.mKeyDownReceived = true; + if (event.getRepeatCount() == 0) { + LeanbackKeyboardController.this.mContainer.setTouchState(3); + LeanbackKeyboardController.this.mSpaceTracker.blockMovementUntil(event.getEventTime() + 500L); + LeanbackKeyboardController.this.performBestSnap(event.getEventTime()); + } + } + + return LeanbackKeyboardController.this.handleKeyDownEvent(keyCode, event.getRepeatCount()); + } + + public boolean onKeyLongPress(int keyCode, KeyEvent event) { + return LeanbackKeyboardController.this.handleKeyLongPress(keyCode); + } + + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (LeanbackKeyboardController.this.isEnterKey(keyCode)) { + if (!LeanbackKeyboardController.this.mKeyDownReceived || LeanbackKeyboardController.this.mLongPressHandled) { + LeanbackKeyboardController.this.mLongPressHandled = false; + return true; + } + + LeanbackKeyboardController.this.mKeyDownReceived = false; + if (LeanbackKeyboardController.this.mContainer.getTouchState() == 3) { + LeanbackKeyboardController.this.mContainer.setTouchState(1); + LeanbackKeyboardController.this.mSpaceTracker.unblockMovement(); + } + } + + return LeanbackKeyboardController.this.handleKeyUpEvent(keyCode, event.getEventTime()); + } + } } diff --git a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardView.java b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardView.java index d87cf46..7e32614 100644 --- a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardView.java +++ b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardView.java @@ -258,8 +258,8 @@ public class LeanbackKeyboardView extends FrameLayout { return this.mKeyboard; } - public int getNearestIndex(float x, float y) { - int var7; + public int getNearestIndex(final float x, final float y) { + int result; if (this.mKeys != null && this.mKeys.length != 0) { float var3 = (float) this.getPaddingLeft(); float var4 = (float) this.getPaddingTop(); @@ -269,11 +269,11 @@ public class LeanbackKeyboardView extends FrameLayout { int var10 = this.getColCount(); int var8 = (int) ((y - var4) / var5 * (float) var9); if (var8 < 0) { - var7 = 0; + result = 0; } else { - var7 = var8; + result = var8; if (var8 >= var9) { - var7 = var9 - 1; + result = var9 - 1; } } @@ -287,33 +287,33 @@ public class LeanbackKeyboardView extends FrameLayout { } } - var8 += this.mColCount * var7; - var7 = var8; - if (var8 > 46) { - var7 = var8; + var8 += this.mColCount * result; + result = var8; + if (var8 > ASCII_PERIOD) { + result = var8; if (var8 < 53) { - var7 = 46; + result = ASCII_PERIOD; } } - var8 = var7; - if (var7 >= 53) { - var8 = var7 - 6; + var8 = result; + if (result >= 53) { + var8 = result - 6; } if (var8 < 0) { return 0; } - var7 = var8; + result = var8; if (var8 >= this.mKeys.length) { return this.mKeys.length - 1; } } else { - var7 = 0; + result = 0; } - return var7; + return result; } public int getRowCount() { diff --git a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackSuggestionsFactory.java b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackSuggestionsFactory.java index 36efd56..bd9ea87 100644 --- a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackSuggestionsFactory.java +++ b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackSuggestionsFactory.java @@ -20,9 +20,9 @@ public class LeanbackSuggestionsFactory { private int mNumSuggestions; private final ArrayList mSuggestions = new ArrayList(); - public LeanbackSuggestionsFactory(InputMethodService var1, int var2) { - this.mContext = var1; - this.mNumSuggestions = var2; + public LeanbackSuggestionsFactory(InputMethodService context, int numSuggestions) { + this.mContext = context; + this.mNumSuggestions = numSuggestions; } public void clearSuggestions() { diff --git a/leankeykeyboard/src/main/java/com/google/android/pano/util/TouchNavSpaceTracker.java b/leankeykeyboard/src/main/java/com/google/android/pano/util/TouchNavSpaceTracker.java index b9a7597..86e5e88 100644 --- a/leankeykeyboard/src/main/java/com/google/android/pano/util/TouchNavSpaceTracker.java +++ b/leankeykeyboard/src/main/java/com/google/android/pano/util/TouchNavSpaceTracker.java @@ -127,13 +127,13 @@ public class TouchNavSpaceTracker { return var3; } - private void checkForLongClick(int var1, KeyEvent var2) { + private void checkForLongClick(int var1, KeyEvent event) { if (var1 == 23) { - Message var3 = this.mHandler.obtainMessage(0); - var3.arg1 = var1; - var3.obj = var2; + Message msg = this.mHandler.obtainMessage(0); + msg.arg1 = var1; + msg.obj = event; if (!this.mHandler.hasMessages(0)) { - this.mHandler.sendMessageDelayed(var3, (long)ViewConfiguration.getLongPressTimeout()); + this.mHandler.sendMessageDelayed(msg, (long)ViewConfiguration.getLongPressTimeout()); return; } } @@ -253,16 +253,16 @@ public class TouchNavSpaceTracker { return new PointF(this.getPixelX(this.mPhysicalPosition.x), this.getPixelY(this.mPhysicalPosition.y)); } - public boolean onGenericMotionEvent(MotionEvent var1) { - if (var1 != null && (var1.getSource() & 2097152) == 2097152) { - InputDevice var13 = var1.getDevice(); + public boolean onGenericMotionEvent(MotionEvent event) { + if (event != null && (event.getSource() & InputDevice.SOURCE_TOUCH_NAVIGATION) == InputDevice.SOURCE_TOUCH_NAVIGATION) { + InputDevice var13 = event.getDevice(); if (var13 == null) { return false; } TouchNavMotionTracker var19 = this.getTrackerForDevice(var13); - int var10 = var1.getActionMasked(); - var19.addMovement(var1); + int var10 = event.getActionMasked(); + var19.addMovement(event); boolean var6; if ((var10 & 255) == 6) { var6 = true; @@ -272,19 +272,19 @@ public class TouchNavSpaceTracker { int var7; if (var6) { - var7 = var1.getActionIndex(); + var7 = event.getActionIndex(); } else { var7 = -1; } float var3 = 0.0F; float var2 = 0.0F; - int var9 = var1.getPointerCount(); + int var9 = event.getPointerCount(); for(int var8 = 0; var8 < var9; ++var8) { if (var7 != var8) { - var3 += var1.getX(var8); - var2 += var1.getY(var8); + var3 += event.getX(var8); + var2 += event.getY(var8); } } @@ -297,7 +297,7 @@ public class TouchNavSpaceTracker { float var4 = var3 / (float)var17; float var5 = var2 / (float)var17; - TouchNavSpaceTracker.PhysicalMotionEvent var14 = new TouchNavSpaceTracker.PhysicalMotionEvent(var1.getDeviceId(), var19.getPhysicalX(var4), var19.getPhysicalX(var5), var1.getEventTime()); + TouchNavSpaceTracker.PhysicalMotionEvent var14 = new TouchNavSpaceTracker.PhysicalMotionEvent(event.getDeviceId(), var19.getPhysicalX(var4), var19.getPhysicalX(var5), event.getEventTime()); boolean var18 = false; boolean var12 = false; boolean var11; @@ -312,7 +312,7 @@ public class TouchNavSpaceTracker { var19.setNewValues(var4, var5); var19.updatePrevValues(); - var19.setDownEvent(MotionEvent.obtain(var1)); + var19.setDownEvent(MotionEvent.obtain(event)); if (this.mPixelListener != null) { return false | this.mPixelListener.onDown(var14); } @@ -324,7 +324,7 @@ public class TouchNavSpaceTracker { return false | this.mPixelListener.onUp(var14, this.getPixelX(this.mPhysicalPosition.x), this.getPixelY(this.mPhysicalPosition.y)); } - var16 = new TouchNavSpaceTracker.PhysicalMotionEvent(var1.getDeviceId(), var19.getPhysicalX(var15.getX()), var19.getPhysicalY(var15.getY()), var15.getEventTime()); + var16 = new TouchNavSpaceTracker.PhysicalMotionEvent(event.getDeviceId(), var19.getPhysicalX(var15.getX()), var19.getPhysicalY(var15.getY()), var15.getEventTime()); var6 = var18; if (var19.computeVelocity()) { var6 = var18; @@ -356,7 +356,7 @@ public class TouchNavSpaceTracker { return var6 | var11; case 2: if (var19.getDownEvent() == null) { - var19.setDownEvent(MotionEvent.obtain(var1)); + var19.setDownEvent(MotionEvent.obtain(event)); if (this.mLPFEnabled) { this.mLPFCurrX = var4; this.mLPFCurrY = var5; @@ -375,7 +375,7 @@ public class TouchNavSpaceTracker { if (var19.setNewValues(var3, var2)) { var2 = var19.getPhysicalX(var19.getScrollX()); var3 = var19.getPhysicalY(var19.getScrollY()); - var4 = this.calculateSensitivity(var1, var19.getDownEvent()); + var4 = this.calculateSensitivity(event, var19.getDownEvent()); this.mPhysicalPosition.x = this.mPrevPhysPosition.x + this.getScaledValue(var2, var4); this.mPhysicalPosition.y = this.mPrevPhysPosition.y + this.getScaledValue(var3, var4); this.clampPosition(); @@ -387,7 +387,7 @@ public class TouchNavSpaceTracker { var11 = var12; if (this.mPixelWidth > 0.0F) { var15 = var19.getDownEvent(); - var16 = new TouchNavSpaceTracker.PhysicalMotionEvent(var1.getDeviceId(), var19.getPhysicalX(var15.getX()), var19.getPhysicalY(var15.getY()), var15.getEventTime()); + var16 = new TouchNavSpaceTracker.PhysicalMotionEvent(event.getDeviceId(), var19.getPhysicalX(var15.getX()), var19.getPhysicalY(var15.getY()), var15.getEventTime()); var2 = this.getPixelX(this.mPhysicalPosition.x); var3 = this.getPixelY(this.mPhysicalPosition.y); var11 = false | this.mPixelListener.onMove(var16, var14, var2, var3); @@ -416,28 +416,28 @@ public class TouchNavSpaceTracker { return false; } - public boolean onKeyDown(int var1, KeyEvent var2) { - if (var2 != null && var2.getDevice() != null && (var2.getDevice().getSources() & 2097152) == 2097152) { - if (var2.getRepeatCount() == 0) { - this.checkForLongClick(var1, var2); + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (event != null && event.getDevice() != null && (event.getDevice().getSources() & InputDevice.SOURCE_TOUCH_NAVIGATION) == InputDevice.SOURCE_TOUCH_NAVIGATION) { + if (event.getRepeatCount() == 0) { + checkForLongClick(keyCode, event); } - if (this.mKeyEventListener != null) { - return this.mKeyEventListener.onKeyDown(var1, var2); + if (mKeyEventListener != null) { + return mKeyEventListener.onKeyDown(keyCode, event); } } return false; } - public boolean onKeyUp(int var1, KeyEvent var2) { - if (var2 != null && var2.getDevice() != null && (var2.getDevice().getSources() & 2097152) == 2097152) { - if (var1 == 23) { - this.mHandler.removeMessages(0); + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (event != null && event.getDevice() != null && (event.getDevice().getSources() & InputDevice.SOURCE_TOUCH_NAVIGATION) == InputDevice.SOURCE_TOUCH_NAVIGATION) { + if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { + mHandler.removeMessages(0); } - if (this.mKeyEventListener != null) { - return this.mKeyEventListener.onKeyUp(var1, var2); + if (mKeyEventListener != null) { + return mKeyEventListener.onKeyUp(keyCode, event); } } @@ -445,56 +445,56 @@ public class TouchNavSpaceTracker { } public void onPause() { - this.mHandler.removeMessages(0); + mHandler.removeMessages(0); } - public void setKeyEventListener(TouchNavSpaceTracker.KeyEventListener var1) { - this.mKeyEventListener = var1; + public void setKeyEventListener(TouchNavSpaceTracker.KeyEventListener listener) { + mKeyEventListener = listener; } - public void setLPFEnabled(boolean var1) { - this.mLPFEnabled = var1; + public void setLPFEnabled(boolean enabled) { + mLPFEnabled = enabled; } - public void setPhysicalDensity(float var1) { - this.mPixelsPerMm = var1; - if (var1 > 0.0F) { - this.updatePhysicalSize(); + public void setPhysicalDensity(float density) { + mPixelsPerMm = density; + if (density > 0.0F) { + updatePhysicalSize(); } } - public void setPhysicalPosition(float var1, float var2) { - this.mPhysicalPosition.x = var1; - this.mPhysicalPosition.y = var2; - this.mPrevPhysPosition.x = var1; - this.mPrevPhysPosition.y = var2; - this.clampPosition(); + public void setPhysicalPosition(float x, float y) { + mPhysicalPosition.x = x; + mPhysicalPosition.y = y; + mPrevPhysPosition.x = x; + mPrevPhysPosition.y = y; + clampPosition(); } - public void setPhysicalSize(float var1, float var2) { - if (this.mPixelsPerMm <= 0.0F) { - this.setPhysicalSizeInternal(var1, var2); + public void setPhysicalSize(float widthMm, float heightMm) { + if (mPixelsPerMm <= 0.0F) { + setPhysicalSizeInternal(widthMm, heightMm); } } - public void setPixelPosition(float var1, float var2) { - this.setPhysicalPosition(this.getPhysicalX(var1), this.getPhysicalY(var2)); + public void setPixelPosition(float x, float y) { + setPhysicalPosition(getPhysicalX(x), getPhysicalY(y)); } - public void setPixelSize(float var1, float var2) { - this.mPixelHeight = var2; - this.mPixelWidth = var1; - this.updatePhysicalSize(); + public void setPixelSize(float width, float height) { + mPixelHeight = height; + mPixelWidth = width; + updatePhysicalSize(); } - public void setSensitivity(float var1) { - this.mSensitivity = var1; - this.configureFlicks(this.mUnscaledFlickMinDistance, this.mUnscaledFlickMaxDistance, this.mFlickMaxDuration); + public void setSensitivity(float sensitivity) { + mSensitivity = sensitivity; + configureFlicks(mUnscaledFlickMinDistance, mUnscaledFlickMaxDistance, mFlickMaxDuration); } - public void setTouchEventListener(TouchNavSpaceTracker.TouchEventListener var1) { - this.mPixelListener = var1; + public void setTouchEventListener(TouchNavSpaceTracker.TouchEventListener listener) { + mPixelListener = listener; } public void unblockMovement() { @@ -502,11 +502,11 @@ public class TouchNavSpaceTracker { } public interface KeyEventListener { - boolean onKeyDown(int var1, KeyEvent var2); + boolean onKeyDown(int keyCode, KeyEvent event); - boolean onKeyLongPress(int var1, KeyEvent var2); + boolean onKeyLongPress(int keyCode, KeyEvent event); - boolean onKeyUp(int var1, KeyEvent var2); + boolean onKeyUp(int keyCode, KeyEvent event); } public static class PhysicalMotionEvent { @@ -558,15 +558,15 @@ public class TouchNavSpaceTracker { return false; } - public boolean onKeyDown(int var1, KeyEvent var2) { + public boolean onKeyDown(int keyCode, KeyEvent event) { return false; } - public boolean onKeyLongPress(int var1, KeyEvent var2) { + public boolean onKeyLongPress(int keyCode, KeyEvent event) { return false; } - public boolean onKeyUp(int var1, KeyEvent var2) { + public boolean onKeyUp(int keyCode, KeyEvent event) { return false; } diff --git a/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java b/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java index f924b8a..8412132 100644 --- a/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java +++ b/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java @@ -6,6 +6,7 @@ import android.inputmethodservice.InputMethodService; import android.os.Handler; import android.os.Message; import android.util.Log; +import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@ -13,6 +14,8 @@ import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import com.google.android.leanback.ime.LeanbackKeyboardController; +import com.google.android.leanback.ime.LeanbackKeyboardController.InputListener; +import com.google.android.leanback.ime.LeanbackKeyboardView; import com.google.android.leanback.ime.LeanbackSuggestionsFactory; import com.google.android.leanback.ime.LeanbackUtils; @@ -38,8 +41,9 @@ public class LeanbackImeService extends InputMethodService { } }; private LeanbackKeyboardController.InputListener mInputListener = new LeanbackKeyboardController.InputListener() { - public void onEntry(int var1, int var2, CharSequence var3) { - LeanbackImeService.this.handleTextEntry(var1, var2, var3); + @Override + public void onEntry(int type, int keyCode, CharSequence text) { + LeanbackImeService.this.handleTextEntry(type, keyCode, text); } }; private View mInputView; @@ -56,160 +60,156 @@ public class LeanbackImeService extends InputMethodService { } private void clearSuggestionsDelayed() { - if (!this.mSuggestionsFactory.shouldSuggestionsAmend()) { - this.mHandler.removeMessages(123); - this.mShouldClearSuggestions = true; - this.mHandler.sendEmptyMessageDelayed(123, 1000L); + if (!mSuggestionsFactory.shouldSuggestionsAmend()) { + mHandler.removeMessages(MSG_SUGGESTIONS_CLEAR); + mShouldClearSuggestions = true; + mHandler.sendEmptyMessageDelayed(MSG_SUGGESTIONS_CLEAR, SUGGESTIONS_CLEAR_DELAY); } } - private int getAmpersandLocation(InputConnection var1) { - String var4 = this.getEditorText(var1); - int var3 = var4.indexOf(64); - int var2 = var3; - if (var3 < 0) { - var2 = var4.length(); + private int getAmpersandLocation(InputConnection connection) { + String text = getEditorText(connection); + int pos = text.indexOf(64); + if (pos < 0) { // not found + pos = text.length(); } - return var2; + return pos; } - private int getCharLengthAfterCursor(InputConnection var1) { - int var2 = 0; - CharSequence var3 = var1.getTextAfterCursor(1000, 0); - if (var3 != null) { - var2 = var3.length(); + private int getCharLengthAfterCursor(InputConnection connection) { + int len = 0; + CharSequence after = connection.getTextAfterCursor(1000, 0); + if (after != null) { + len = after.length(); } - return var2; + return len; } - private int getCharLengthBeforeCursor(InputConnection var1) { - int var2 = 0; - CharSequence var3 = var1.getTextBeforeCursor(1000, 0); - if (var3 != null) { - var2 = var3.length(); + private int getCharLengthBeforeCursor(InputConnection connection) { + int len = 0; + CharSequence before = connection.getTextBeforeCursor(1000, 0); + if (before != null) { + len = before.length(); } - return var2; + return len; } - private String getEditorText(InputConnection var1) { - StringBuilder var2 = new StringBuilder(); - CharSequence var3 = var1.getTextBeforeCursor(1000, 0); - CharSequence var4 = var1.getTextAfterCursor(1000, 0); - if (var3 != null) { - var2.append(var3); + private String getEditorText(InputConnection connection) { + StringBuilder result = new StringBuilder(); + CharSequence before = connection.getTextBeforeCursor(1000, 0); + CharSequence after = connection.getTextAfterCursor(1000, 0); + if (before != null) { + result.append(before); } - if (var4 != null) { - var2.append(var4); + if (after != null) { + result.append(after); } - return var2.toString(); + return result.toString(); } - private void handleTextEntry(int var1, int var2, CharSequence var3) { - InputConnection var5 = this.getCurrentInputConnection(); - boolean var4 = true; - if (var5 != null) { - boolean var6; - switch (var1) { - case 0: - this.clearSuggestionsDelayed(); - if (this.mEnterSpaceBeforeCommitting && this.mKeyboardController.enableAutoEnterSpace()) { - if (LeanbackUtils.isAlphabet(var2)) { - var5.commitText(" ", 1); + private void handleTextEntry(final int type, final int keyCode, final CharSequence text) { + final InputConnection connection = getCurrentInputConnection(); + if (connection != null) { + boolean updateSuggestions; + switch (type) { + case InputListener.ENTRY_TYPE_STRING: + clearSuggestionsDelayed(); + if (mEnterSpaceBeforeCommitting && mKeyboardController.enableAutoEnterSpace()) { + if (LeanbackUtils.isAlphabet(keyCode)) { + connection.commitText(" ", 1); } - this.mEnterSpaceBeforeCommitting = false; + mEnterSpaceBeforeCommitting = false; } - var5.commitText(var3, 1); - var6 = var4; - if (var2 == 46) { - this.mEnterSpaceBeforeCommitting = true; - var6 = var4; + connection.commitText(text, 1); + updateSuggestions = true; + if (keyCode == LeanbackKeyboardView.ASCII_PERIOD) { + mEnterSpaceBeforeCommitting = true; } break; - case 1: - this.clearSuggestionsDelayed(); - var5.deleteSurroundingText(1, 0); - this.mEnterSpaceBeforeCommitting = false; - var6 = var4; + case InputListener.ENTRY_TYPE_BACKSPACE: + clearSuggestionsDelayed(); + connection.deleteSurroundingText(1, 0); + mEnterSpaceBeforeCommitting = false; + updateSuggestions = true; break; - case 2: - case 6: - this.clearSuggestionsDelayed(); - if (!this.mSuggestionsFactory.shouldSuggestionsAmend()) { - var5.deleteSurroundingText(this.getCharLengthBeforeCursor(var5), this.getCharLengthAfterCursor(var5)); + case InputListener.ENTRY_TYPE_SUGGESTION: + case InputListener.ENTRY_TYPE_VOICE: + clearSuggestionsDelayed(); + if (!mSuggestionsFactory.shouldSuggestionsAmend()) { + connection.deleteSurroundingText(this.getCharLengthBeforeCursor(connection), this.getCharLengthAfterCursor(connection)); } else { - var1 = this.getAmpersandLocation(var5); - var5.setSelection(var1, var1); - var5.deleteSurroundingText(0, this.getCharLengthAfterCursor(var5)); + int location = this.getAmpersandLocation(connection); + connection.setSelection(location, location); + connection.deleteSurroundingText(0, this.getCharLengthAfterCursor(connection)); } - var5.commitText(var3, 1); - this.mEnterSpaceBeforeCommitting = true; - case 5: - this.sendDefaultEditorAction(false); - var6 = false; + connection.commitText(text, 1); + mEnterSpaceBeforeCommitting = true; + case InputListener.ENTRY_TYPE_ACTION: + sendDefaultEditorAction(false); + updateSuggestions = false; break; - case 3: - case 4: - var3 = var5.getTextBeforeCursor(1000, 0); - if (var3 == null) { - var2 = 0; + case InputListener.ENTRY_TYPE_LEFT: + case InputListener.ENTRY_TYPE_RIGHT: + CharSequence textBeforeCursor = connection.getTextBeforeCursor(1000, 0); + int len; + if (textBeforeCursor == null) { + len = 0; } else { - var2 = var3.length(); + len = textBeforeCursor.length(); } - if (var1 == 3) { - var1 = var2; - if (var2 > 0) { - var1 = var2 - 1; + int index; + if (type == InputListener.ENTRY_TYPE_LEFT) { + index = len; + if (len > 0) { + index = len - 1; } } else { - var3 = var5.getTextAfterCursor(1000, 0); - var1 = var2; - if (var3 != null) { - var1 = var2; - if (var3.length() > 0) { - var1 = var2 + 1; - } + textBeforeCursor = connection.getTextAfterCursor(1000, 0); + index = len; + if (textBeforeCursor != null && textBeforeCursor.length() > 0) { + index = len + 1; } } - var5.setSelection(var1, var1); - var6 = var4; + connection.setSelection(index, index); + updateSuggestions = true; break; - case 7: - var5.performEditorAction(1); - var6 = false; + case InputListener.ENTRY_TYPE_DISMISS: + connection.performEditorAction(EditorInfo.IME_ACTION_NONE); + updateSuggestions = false; break; - case 8: - var5.performEditorAction(2); - var6 = false; + case InputListener.ENTRY_TYPE_VOICE_DISMISS: + connection.performEditorAction(EditorInfo.IME_ACTION_GO); + updateSuggestions = false; break; default: - var6 = var4; + updateSuggestions = true; } - if (this.mKeyboardController.areSuggestionsEnabled() && var6) { - this.mKeyboardController.updateSuggestions(this.mSuggestionsFactory.getSuggestions()); - return; + if (mKeyboardController.areSuggestionsEnabled() && updateSuggestions) { + mKeyboardController.updateSuggestions(mSuggestionsFactory.getSuggestions()); } } - } + @Override public View onCreateInputView() { this.mInputView = this.mKeyboardController.getView(); this.mInputView.requestFocus(); return this.mInputView; } + @Override public void onDisplayCompletions(CompletionInfo[] var1) { if (this.mKeyboardController.areSuggestionsEnabled()) { this.mShouldClearSuggestions = false; @@ -231,47 +231,56 @@ public class LeanbackImeService extends InputMethodService { return true; } + @Override public void onFinishInputView(boolean var1) { super.onFinishInputView(var1); - this.sendBroadcast(new Intent("com.google.android.athome.action.IME_CLOSE")); + this.sendBroadcast(new Intent(IME_CLOSE)); this.mSuggestionsFactory.clearSuggestions(); } - public boolean onGenericMotionEvent(MotionEvent var1) { - return this.isInputViewShown() && (var1.getSource() & 2097152) == 2097152 && this.mKeyboardController.onGenericMotionEvent(var1) ? true : - super.onGenericMotionEvent(var1); + @SuppressLint("NewApi") + @Override + public boolean onGenericMotionEvent(MotionEvent event) { + return isInputViewShown() && + (event.getSource() & InputDevice.SOURCE_TOUCH_NAVIGATION) == InputDevice.SOURCE_TOUCH_NAVIGATION && + mKeyboardController.onGenericMotionEvent(event) || super.onGenericMotionEvent(event); } public void onHideIme() { this.requestHideSelf(0); } + @Override public void onInitializeInterface() { - this.mKeyboardController = new LeanbackKeyboardController(this, this.mInputListener); - this.mEnterSpaceBeforeCommitting = false; - this.mSuggestionsFactory = new LeanbackSuggestionsFactory(this, 10); + mKeyboardController = new LeanbackKeyboardController(this, mInputListener); + mEnterSpaceBeforeCommitting = false; + mSuggestionsFactory = new LeanbackSuggestionsFactory(this, MAX_SUGGESTIONS); } - public boolean onKeyDown(int var1, KeyEvent var2) { - return this.isInputViewShown() && this.mKeyboardController.onKeyDown(var1, var2) ? true : super.onKeyDown(var1, var2); + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + return isInputViewShown() && mKeyboardController.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); } - public boolean onKeyUp(int var1, KeyEvent var2) { - return this.isInputViewShown() && this.mKeyboardController.onKeyUp(var1, var2) ? true : super.onKeyUp(var1, var2); + @Override + public boolean onKeyUp(int keyCode, KeyEvent event) { + return isInputViewShown() && mKeyboardController.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event); } - public boolean onShowInputRequested(int var1, boolean var2) { + @Override + public boolean onShowInputRequested(int flags, boolean configChange) { return true; } - public int onStartCommand(Intent var1, int var2, int var3) { - if (var1 != null) { - super.onStartCommand(var1, var2, var3); - if (var1.getBooleanExtra("restart", false)) { + @Override + public int onStartCommand(final Intent intent, final int flags, final int startId) { + if (intent != null) { + super.onStartCommand(intent, flags, startId); + if (intent.getBooleanExtra("restart", false)) { Log.e("LeanbackImeService", "Service->onStartCommand: trying to restart service"); - LeanbackKeyboardController var4 = this.mKeyboardController; - if (var4 != null) { - var4.updateAddonKeyboard(); + LeanbackKeyboardController controller = mKeyboardController; + if (controller != null) { + controller.updateAddonKeyboard(); } } } @@ -279,25 +288,27 @@ public class LeanbackImeService extends InputMethodService { return 1; } - public void onStartInput(EditorInfo var1, boolean var2) { - super.onStartInput(var1, var2); - this.mEnterSpaceBeforeCommitting = false; - this.mSuggestionsFactory.onStartInput(var1); - this.mKeyboardController.onStartInput(var1); + @Override + public void onStartInput(EditorInfo info, boolean restarting) { + super.onStartInput(info, restarting); + mEnterSpaceBeforeCommitting = false; + mSuggestionsFactory.onStartInput(info); + mKeyboardController.onStartInput(info); } - public void onStartInputView(EditorInfo var1, boolean var2) { - super.onStartInputView(var1, var2); - this.mKeyboardController.onStartInputView(); - this.sendBroadcast(new Intent("com.google.android.athome.action.IME_OPEN")); - if (this.mKeyboardController.areSuggestionsEnabled()) { - this.mSuggestionsFactory.createSuggestions(); - this.mKeyboardController.updateSuggestions(this.mSuggestionsFactory.getSuggestions()); - InputConnection var4 = this.getCurrentInputConnection(); - if (var4 != null) { - String var3 = this.getEditorText(var4); - var4.deleteSurroundingText(this.getCharLengthBeforeCursor(var4), this.getCharLengthAfterCursor(var4)); - var4.commitText(var3, 1); + @Override + public void onStartInputView(EditorInfo info, boolean restarting) { + super.onStartInputView(info, restarting); + mKeyboardController.onStartInputView(); + sendBroadcast(new Intent(IME_OPEN)); + if (mKeyboardController.areSuggestionsEnabled()) { + mSuggestionsFactory.createSuggestions(); + mKeyboardController.updateSuggestions(mSuggestionsFactory.getSuggestions()); + InputConnection connection = getCurrentInputConnection(); + if (connection != null) { + String text = getEditorText(connection); + connection.deleteSurroundingText(getCharLengthBeforeCursor(connection), getCharLengthAfterCursor(connection)); + connection.commitText(text, 1); } }