OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * 'android-apps-page' is the settings page for enabling android apps. | 7 * 'android-apps-page' is the settings page for enabling android apps. |
8 */ | 8 */ |
9 | 9 |
10 Polymer({ | 10 Polymer({ |
11 is: 'settings-android-apps-page', | 11 is: 'settings-android-apps-page', |
12 | 12 |
13 behaviors: [I18nBehavior, PrefsBehavior], | 13 behaviors: [I18nBehavior, PrefsBehavior], |
14 | 14 |
15 properties: { | 15 properties: { |
16 /** Preferences state. */ | 16 /** Preferences state. */ |
17 prefs: { | 17 prefs: Object, |
18 type: Object, | |
19 notify: true, | |
20 }, | |
21 | 18 |
22 /** @private {!AndroidAppsInfo|undefined} */ | 19 /** @private {!AndroidAppsInfo|undefined} */ |
23 androidAppsInfo_: Object, | 20 androidAppsInfo_: Object, |
24 }, | 21 }, |
25 | 22 |
26 /** @private {?settings.AndroidAppsBrowserProxy} */ | 23 /** @private {?settings.AndroidAppsBrowserProxy} */ |
27 browserProxy_: null, | 24 browserProxy_: null, |
28 | 25 |
29 /** @override */ | 26 /** @override */ |
30 created: function() { | 27 created: function() { |
31 this.browserProxy_ = settings.AndroidAppsBrowserProxyImpl.getInstance(); | 28 this.browserProxy_ = settings.AndroidAppsBrowserProxyImpl.getInstance(); |
32 }, | 29 }, |
33 | 30 |
34 /** @override */ | 31 /** @override */ |
35 ready: function() { | 32 ready: function() { |
36 cr.addWebUIListener( | 33 cr.addWebUIListener( |
37 'android-apps-info-update', this.androidAppsInfoUpdate_.bind(this)); | 34 'android-apps-info-update', this.androidAppsInfoUpdate_.bind(this)); |
38 this.browserProxy_.requestAndroidAppsInfo(); | 35 this.browserProxy_.requestAndroidAppsInfo(); |
39 }, | 36 }, |
| 37 |
40 /** | 38 /** |
41 * @param {AndroidAppsInfo} info | 39 * @param {AndroidAppsInfo} info |
42 * @private | 40 * @private |
43 */ | 41 */ |
44 androidAppsInfoUpdate_: function(info) { | 42 androidAppsInfoUpdate_: function(info) { |
45 this.androidAppsInfo_ = info; | 43 this.androidAppsInfo_ = info; |
46 }, | 44 }, |
47 | 45 |
48 /** @return {string} */ | |
49 getSubtext_: function() { | |
50 // TODO(stevenjb): Change the text when appReady to 'toggleOn' or whatever | |
51 // UX finally decides on. Discussion in crbug.com/698463. | |
52 return this.androidAppsInfo_.appReady ? this.i18n('androidAppsSubtext') : | |
53 this.i18n('androidAppsSubtext'); | |
54 }, | |
55 | |
56 /** | 46 /** |
57 * @param {Event} event | 47 * @param {Event} event |
58 * @private | 48 * @private |
59 */ | 49 */ |
60 onEnableTap_: function(event) { | 50 onManageAndroidAppsKeydown_: function(event) { |
61 this.setPrefValue('arc.enabled', true); | 51 if (event.key != 'Enter' && event.key != ' ') |
| 52 return; |
| 53 this.browserProxy_.showAndroidAppsSettings(true /** keyboardAction */); |
62 event.stopPropagation(); | 54 event.stopPropagation(); |
63 }, | 55 }, |
64 | 56 |
65 /** @private */ | 57 /** @private */ |
66 onSubpageTap_: function() { | 58 onManageAndroidAppsTap_: function(event) { |
67 if (!this.androidAppsInfo_.appReady) | 59 this.browserProxy_.showAndroidAppsSettings(false /** keyboardAction */); |
| 60 }, |
| 61 |
| 62 /** |
| 63 * @return {string} |
| 64 * @private |
| 65 */ |
| 66 getDialogBody_: function() { |
| 67 return this.i18nAdvanced( |
| 68 'androidAppsDisableDialogMessage', {substitutions: [], tags: ['br']}); |
| 69 }, |
| 70 |
| 71 /** |
| 72 * Handles the change event for the arc.enabled checkbox. Shows a |
| 73 * confirmation dialog when disabling the preference. |
| 74 * @param {Event} event |
| 75 * @private |
| 76 */ |
| 77 onArcEnabledChange_: function(event) { |
| 78 if (event.target.checked) { |
| 79 /** @type {!SettingsCheckboxElement} */ (event.target).sendPrefChange(); |
68 return; | 80 return; |
69 settings.navigateTo(settings.Route.ANDROID_APPS_DETAILS); | 81 } |
| 82 this.$.confirmDisableDialog.showModal(); |
| 83 }, |
| 84 |
| 85 /** |
| 86 * Handles the shared proxy confirmation dialog 'Confirm' button. |
| 87 * @private |
| 88 */ |
| 89 onConfirmDisableDialogConfirm_: function() { |
| 90 /** @type {!SettingsCheckboxElement} */ (this.$.enabled).sendPrefChange(); |
| 91 this.$.confirmDisableDialog.close(); |
| 92 }, |
| 93 |
| 94 /** |
| 95 * Handles the shared proxy confirmation dialog 'Cancel' button or a cancel |
| 96 * event. |
| 97 * @private |
| 98 */ |
| 99 onConfirmDisableDialogCancel_: function() { |
| 100 /** @type {!SettingsCheckboxElement} */ (this.$.enabled).resetToPrefValue(); |
| 101 this.$.confirmDisableDialog.close(); |
| 102 }, |
| 103 |
| 104 /** |
| 105 * @param {!Event} e |
| 106 * @private |
| 107 */ |
| 108 stopPropagation_: function(e) { |
| 109 e.stopPropagation(); |
70 }, | 110 }, |
71 }); | 111 }); |
OLD | NEW |