| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,13 +2,13 @@ | |||
| 2 | 2 | import textBase = require("ui/text-base"); | |
| 3 | 3 | import dependencyObservable = require("ui/core/dependency-observable"); | |
| 4 | 4 | import enums = require("ui/enums"); | |
| 5 | + import utils = require("utils/utils"); | ||
| 5 | 6 | ||
| 6 | 7 | export class EditableTextBase extends common.EditableTextBase { | |
| 7 | 8 | private _android: android.widget.EditText; | |
| 8 | 9 | /* tslint:disable */ | |
| 9 | 10 | private _dirtyTextAccumulator: string; | |
| 10 | 11 | /* tslint:enable */ | |
| 11 | - private _imm: android.view.inputmethod.InputMethodManager; | ||
| 12 | 12 | ||
| 13 | 13 | constructor(options?: textBase.Options) { | |
| 14 | 14 | super(options); | |
@@ -18,9 +18,7 @@ export class EditableTextBase extends common.EditableTextBase { | |||
| 18 | 18 | return this._android; | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | - public _createUI() { | ||
| 22 | - this._imm = <android.view.inputmethod.InputMethodManager>this._context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE); | ||
| 23 | - | ||
| 21 | + public _createUI() { | ||
| 24 | 22 | this._android = new android.widget.EditText(this._context); | |
| 25 | 23 | this._configureEditText(); | |
| 26 | 24 | this.android.setTag(this.android.getKeyListener()); | |
@@ -103,23 +101,20 @@ export class EditableTextBase extends common.EditableTextBase { | |||
| 103 | 101 | } | |
| 104 | 102 | ||
| 105 | 103 | public _onDetached(force?: boolean) { | |
| 106 | - this._imm = undefined; | ||
| 107 | 104 | this._android = undefined; | |
| 108 | 105 | ||
| 109 | 106 | super._onDetached(force); | |
| 110 | 107 | } | |
| 111 | 108 | ||
| 112 | 109 | public dismissSoftInput() { | |
| 113 | - if (this._imm) { | ||
| 114 | - this._imm.hideSoftInputFromWindow(this._android.getWindowToken(), 0); | ||
| 115 | - } | ||
| 110 | + utils.ad.dismissSoftInput(this._nativeView); | ||
| 116 | 111 | } | |
| 117 | 112 | ||
| 118 | 113 | public focus(): boolean { | |
| 119 | 114 | var result = super.focus(); | |
| 120 | 115 | ||
| 121 | - if (result && this._nativeView) { | ||
| 122 | - this._imm.showSoftInput(this._nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT); | ||
| 116 | + if (result) { | ||
| 117 | + utils.ad.showSoftInput(this._nativeView); | ||
| 123 | 118 | } | |
| 124 | 119 | ||
| 125 | 120 | return result; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,4 +50,7 @@ export class SearchBar extends view.View implements definition.SearchBar { | |||
| 50 | 50 | value instanceof color.Color ? value : new color.Color(<any>value)); | |
| 51 | 51 | } | |
| 52 | 52 | ||
| 53 | + public dismissSoftInput() { | ||
| 54 | + // | ||
| 55 | + } | ||
| 53 | 56 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,6 +96,20 @@ global.moduleMerge(common, exports); | |||
| 96 | 96 | export class SearchBar extends common.SearchBar { | |
| 97 | 97 | private _android: android.widget.SearchView; | |
| 98 | 98 | ||
| 99 | + public dismissSoftInput() { | ||
| 100 | + utils.ad.dismissSoftInput(this._nativeView); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public focus(): boolean { | ||
| 104 | + var result = super.focus(); | ||
| 105 | + | ||
| 106 | + if (result) { | ||
| 107 | + utils.ad.showSoftInput(this._nativeView); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + return result; | ||
| 111 | + } | ||
| 112 | + | ||
| 99 | 113 | public _createUI() { | |
| 100 | 114 | this._android = new android.widget.SearchView(this._context); | |
| 101 | 115 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,5 +78,10 @@ declare module "ui/search-bar" { | |||
| 78 | 78 | * Raised when a search bar search is closed. | |
| 79 | 79 | */ | |
| 80 | 80 | on(event: "close", callback: (args: observable.EventData) => void, thisArg?: any); | |
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Hides the soft input method, ususally a soft keyboard. | ||
| 84 | + */ | ||
| 85 | + dismissSoftInput(): void; | ||
| 81 | 86 | } | |
| 82 | 87 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,6 +115,10 @@ export class SearchBar extends common.SearchBar { | |||
| 115 | 115 | super.onUnloaded(); | |
| 116 | 116 | } | |
| 117 | 117 | ||
| 118 | + public dismissSoftInput() { | ||
| 119 | + (<UIResponder>this.ios).resignFirstResponder(); | ||
| 120 | + } | ||
| 121 | + | ||
| 118 | 122 | get ios(): UISearchBar { | |
| 119 | 123 | return this._ios; | |
| 120 | 124 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,6 +51,28 @@ export module ad { | |||
| 51 | 51 | export function getApplication() { return <android.app.Application>(<any>com.tns).NativeScriptApplication.getInstance(); } | |
| 52 | 52 | export function getApplicationContext() { return <android.content.Context>getApplication().getApplicationContext(); } | |
| 53 | 53 | ||
| 54 | + var inputMethodManager: android.view.inputmethod.InputMethodManager; | ||
| 55 | + export function getInputMethodManager() { | ||
| 56 | + if (!inputMethodManager) { | ||
| 57 | + inputMethodManager = <android.view.inputmethod.InputMethodManager>getApplicationContext().getSystemService(android.content.Context.INPUT_METHOD_SERVICE); | ||
| 58 | + } | ||
| 59 | + return inputMethodManager; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + export function showSoftInput(nativeView: android.view.View) : void { | ||
| 63 | + var imm = getInputMethodManager(); | ||
| 64 | + if (imm && nativeView instanceof android.view.View) { | ||
| 65 | + imm.showSoftInput(nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT); | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + export function dismissSoftInput(nativeView: android.view.View): void { | ||
| 70 | + var imm = getInputMethodManager(); | ||
| 71 | + if (imm && nativeView instanceof android.view.View) { | ||
| 72 | + imm.hideSoftInputFromWindow(nativeView.getWindowToken(), 0); | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 54 | 76 | export module collections { | |
| 55 | 77 | export function stringArrayToStringSet(str: string[]): any { | |
| 56 | 78 | var hashSet = new java.util.HashSet(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,6 +66,21 @@ | |||
| 66 | 66 | */ | |
| 67 | 67 | export function getApplicationContext(): android.content.Context; | |
| 68 | 68 | ||
| 69 | + /** | ||
| 70 | + * Gets the native Android input method manager. | ||
| 71 | + */ | ||
| 72 | + export function getInputMethodManager(): android.view.inputmethod.InputMethodManager; | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * Hides the soft input method, ususally a soft keyboard. | ||
| 76 | + */ | ||
| 77 | + export function dismissSoftInput(nativeView: android.view.View): void; | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * Shows the soft input method, ususally a soft keyboard. | ||
| 81 | + */ | ||
| 82 | + export function showSoftInput(nativeView: android.view.View): void; | ||
| 83 | + | ||
| 69 | 84 | /** | |
| 70 | 85 | * Utility module dealing with some android collections. | |
| 71 | 86 | */ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments