Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.example.android.systemupdatersample.ui; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 21 | import android.graphics.Color; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 22 | import android.os.Build; |
| 23 | import android.os.Bundle; |
| 24 | import android.os.UpdateEngine; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | import android.view.View; |
| 27 | import android.widget.ArrayAdapter; |
| 28 | import android.widget.Button; |
| 29 | import android.widget.ProgressBar; |
| 30 | import android.widget.Spinner; |
| 31 | import android.widget.TextView; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 32 | |
| 33 | import com.example.android.systemupdatersample.R; |
| 34 | import com.example.android.systemupdatersample.UpdateConfig; |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 35 | import com.example.android.systemupdatersample.UpdateManager; |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 36 | import com.example.android.systemupdatersample.util.PayloadSpecs; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 37 | import com.example.android.systemupdatersample.util.UpdateConfigs; |
| 38 | import com.example.android.systemupdatersample.util.UpdateEngineErrorCodes; |
| 39 | import com.example.android.systemupdatersample.util.UpdateEngineStatuses; |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 40 | import com.example.android.systemupdatersample.util.UpdaterStates; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 41 | |
| 42 | import java.util.List; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * UI for SystemUpdaterSample app. |
| 46 | */ |
| 47 | public class MainActivity extends Activity { |
| 48 | |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 49 | private static final String TAG = "MainActivity"; |
| 50 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 51 | private TextView mTextViewBuild; |
| 52 | private Spinner mSpinnerConfigs; |
| 53 | private TextView mTextViewConfigsDirHint; |
| 54 | private Button mButtonReload; |
| 55 | private Button mButtonApplyConfig; |
| 56 | private Button mButtonStop; |
| 57 | private Button mButtonReset; |
| 58 | private ProgressBar mProgressBar; |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 59 | private TextView mTextViewUpdaterState; |
| 60 | private TextView mTextViewEngineStatus; |
| 61 | private TextView mTextViewEngineErrorCode; |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 62 | private TextView mTextViewUpdateInfo; |
| 63 | private Button mButtonSwitchSlot; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 64 | |
| 65 | private List<UpdateConfig> mConfigs; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 66 | |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 67 | private final UpdateManager mUpdateManager = |
| 68 | new UpdateManager(new UpdateEngine(), new PayloadSpecs()); |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 69 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 70 | @Override |
| 71 | protected void onCreate(Bundle savedInstanceState) { |
| 72 | super.onCreate(savedInstanceState); |
| 73 | setContentView(R.layout.activity_main); |
| 74 | |
| 75 | this.mTextViewBuild = findViewById(R.id.textViewBuild); |
| 76 | this.mSpinnerConfigs = findViewById(R.id.spinnerConfigs); |
| 77 | this.mTextViewConfigsDirHint = findViewById(R.id.textViewConfigsDirHint); |
| 78 | this.mButtonReload = findViewById(R.id.buttonReload); |
| 79 | this.mButtonApplyConfig = findViewById(R.id.buttonApplyConfig); |
| 80 | this.mButtonStop = findViewById(R.id.buttonStop); |
| 81 | this.mButtonReset = findViewById(R.id.buttonReset); |
| 82 | this.mProgressBar = findViewById(R.id.progressBar); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 83 | this.mTextViewUpdaterState = findViewById(R.id.textViewUpdaterState); |
| 84 | this.mTextViewEngineStatus = findViewById(R.id.textViewEngineStatus); |
| 85 | this.mTextViewEngineErrorCode = findViewById(R.id.textViewEngineErrorCode); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 86 | this.mTextViewUpdateInfo = findViewById(R.id.textViewUpdateInfo); |
| 87 | this.mButtonSwitchSlot = findViewById(R.id.buttonSwitchSlot); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 88 | |
| 89 | this.mTextViewConfigsDirHint.setText(UpdateConfigs.getConfigsRoot(this)); |
| 90 | |
| 91 | uiReset(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 92 | loadUpdateConfigs(); |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 93 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 94 | this.mUpdateManager.setOnStateChangeCallback(this::onUpdaterStateChange); |
| 95 | this.mUpdateManager.setOnEngineStatusUpdateCallback(this::onEngineStatusUpdate); |
| 96 | this.mUpdateManager.setOnEngineCompleteCallback(this::onEnginePayloadApplicationComplete); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 97 | this.mUpdateManager.setOnProgressUpdateCallback(this::onProgressUpdate); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | protected void onDestroy() { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 102 | this.mUpdateManager.setOnEngineStatusUpdateCallback(null); |
| 103 | this.mUpdateManager.setOnProgressUpdateCallback(null); |
| 104 | this.mUpdateManager.setOnEngineCompleteCallback(null); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 105 | super.onDestroy(); |
| 106 | } |
| 107 | |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 108 | @Override |
| 109 | protected void onResume() { |
| 110 | super.onResume(); |
| 111 | this.mUpdateManager.bind(); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | protected void onPause() { |
| 116 | this.mUpdateManager.unbind(); |
| 117 | super.onPause(); |
| 118 | } |
| 119 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 120 | /** |
| 121 | * reload button is clicked |
| 122 | */ |
| 123 | public void onReloadClick(View view) { |
| 124 | loadUpdateConfigs(); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * view config button is clicked |
| 129 | */ |
| 130 | public void onViewConfigClick(View view) { |
| 131 | UpdateConfig config = mConfigs.get(mSpinnerConfigs.getSelectedItemPosition()); |
| 132 | new AlertDialog.Builder(this) |
| 133 | .setTitle(config.getName()) |
| 134 | .setMessage(config.getRawJson()) |
| 135 | .setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss()) |
| 136 | .show(); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * apply config button is clicked |
| 141 | */ |
| 142 | public void onApplyConfigClick(View view) { |
| 143 | new AlertDialog.Builder(this) |
| 144 | .setTitle("Apply Update") |
| 145 | .setMessage("Do you really want to apply this update?") |
| 146 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 147 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
| 148 | uiSetUpdating(); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 149 | uiResetEngineText(); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 150 | mUpdateManager.applyUpdate(this, getSelectedConfig()); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 151 | }) |
| 152 | .setNegativeButton(android.R.string.cancel, null) |
| 153 | .show(); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * stop button clicked |
| 158 | */ |
| 159 | public void onStopClick(View view) { |
| 160 | new AlertDialog.Builder(this) |
| 161 | .setTitle("Stop Update") |
| 162 | .setMessage("Do you really want to cancel running update?") |
| 163 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 164 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 165 | mUpdateManager.cancelRunningUpdate(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 166 | }) |
| 167 | .setNegativeButton(android.R.string.cancel, null).show(); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * reset button clicked |
| 172 | */ |
| 173 | public void onResetClick(View view) { |
| 174 | new AlertDialog.Builder(this) |
| 175 | .setTitle("Reset Update") |
| 176 | .setMessage("Do you really want to cancel running update" |
| 177 | + " and restore old version?") |
| 178 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 179 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 180 | mUpdateManager.resetUpdate(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 181 | }) |
| 182 | .setNegativeButton(android.R.string.cancel, null).show(); |
| 183 | } |
| 184 | |
| 185 | /** |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 186 | * switch slot button clicked |
| 187 | */ |
| 188 | public void onSwitchSlotClick(View view) { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 189 | mUpdateManager.setSwitchSlotOnReboot(); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /** |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 193 | * Invoked when SystemUpdaterSample app state changes. |
| 194 | * Value of {@code state} will be one of the |
| 195 | * values from {@link UpdaterStates}. |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 196 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 197 | private void onUpdaterStateChange(int state) { |
| 198 | Log.i(TAG, "onUpdaterStateChange invoked state=" + state); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 199 | runOnUiThread(() -> { |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 200 | setUiUpdaterState(state); |
| 201 | }); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Invoked when {@link UpdateEngine} status changes. Value of {@code status} will |
| 206 | * be one of the values from {@link UpdateEngine.UpdateStatusConstants}. |
| 207 | */ |
| 208 | private void onEngineStatusUpdate(int status) { |
| 209 | runOnUiThread(() -> { |
| 210 | Log.e(TAG, "StatusUpdate - status=" |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 211 | + UpdateEngineStatuses.getStatusText(status) |
| 212 | + "/" + status); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 213 | if (status == UpdateEngine.UpdateStatusConstants.IDLE) { |
| 214 | Log.d(TAG, "status changed, resetting ui"); |
| 215 | uiReset(); |
| 216 | } else { |
| 217 | Log.d(TAG, "status changed, setting ui to updating mode"); |
| 218 | uiSetUpdating(); |
| 219 | } |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 220 | setUiEngineStatus(status); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 221 | }); |
| 222 | } |
| 223 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 224 | /** |
| 225 | * Invoked when the payload has been applied, whether successfully or |
| 226 | * unsuccessfully. The value of {@code errorCode} will be one of the |
| 227 | * values from {@link UpdateEngine.ErrorCodeConstants}. |
| 228 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 229 | private void onEnginePayloadApplicationComplete(int errorCode) { |
| 230 | final String completionState = UpdateEngineErrorCodes.isUpdateSucceeded(errorCode) |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 231 | ? "SUCCESS" |
| 232 | : "FAILURE"; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 233 | runOnUiThread(() -> { |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 234 | Log.i(TAG, |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 235 | "Completed - errorCode=" |
| 236 | + UpdateEngineErrorCodes.getCodeName(errorCode) + "/" + errorCode |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 237 | + " " + completionState); |
| 238 | setUiEngineErrorCode(errorCode); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 239 | if (errorCode == UpdateEngineErrorCodes.UPDATED_BUT_NOT_ACTIVE) { |
| 240 | // if update was successfully applied. |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 241 | if (mUpdateManager.isManualSwitchSlotRequired()) { |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 242 | // Show "Switch Slot" button. |
| 243 | uiShowSwitchSlotInfo(); |
| 244 | } |
| 245 | } |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 246 | }); |
| 247 | } |
| 248 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Invoked when update progress changes. |
| 251 | */ |
| 252 | private void onProgressUpdate(double progress) { |
| 253 | mProgressBar.setProgress((int) (100 * progress)); |
| 254 | } |
| 255 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 256 | /** resets ui */ |
| 257 | private void uiReset() { |
| 258 | mTextViewBuild.setText(Build.DISPLAY); |
| 259 | mSpinnerConfigs.setEnabled(true); |
| 260 | mButtonReload.setEnabled(true); |
| 261 | mButtonApplyConfig.setEnabled(true); |
| 262 | mButtonStop.setEnabled(false); |
| 263 | mButtonReset.setEnabled(false); |
| 264 | mProgressBar.setProgress(0); |
| 265 | mProgressBar.setEnabled(false); |
| 266 | mProgressBar.setVisibility(ProgressBar.INVISIBLE); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 267 | uiHideSwitchSlotInfo(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 270 | private void uiResetEngineText() { |
| 271 | mTextViewEngineStatus.setText(R.string.unknown); |
| 272 | mTextViewEngineErrorCode.setText(R.string.unknown); |
| 273 | // Note: Do not reset mTextViewUpdaterState; UpdateManager notifies properly. |
| 274 | } |
| 275 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 276 | /** sets ui updating mode */ |
| 277 | private void uiSetUpdating() { |
| 278 | mTextViewBuild.setText(Build.DISPLAY); |
| 279 | mSpinnerConfigs.setEnabled(false); |
| 280 | mButtonReload.setEnabled(false); |
| 281 | mButtonApplyConfig.setEnabled(false); |
| 282 | mButtonStop.setEnabled(true); |
| 283 | mProgressBar.setEnabled(true); |
| 284 | mButtonReset.setEnabled(true); |
| 285 | mProgressBar.setVisibility(ProgressBar.VISIBLE); |
| 286 | } |
| 287 | |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 288 | private void uiShowSwitchSlotInfo() { |
| 289 | mButtonSwitchSlot.setEnabled(true); |
| 290 | mTextViewUpdateInfo.setTextColor(Color.parseColor("#777777")); |
| 291 | } |
| 292 | |
| 293 | private void uiHideSwitchSlotInfo() { |
| 294 | mTextViewUpdateInfo.setTextColor(Color.parseColor("#AAAAAA")); |
| 295 | mButtonSwitchSlot.setEnabled(false); |
| 296 | } |
| 297 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 298 | /** |
| 299 | * loads json configurations from configs dir that is defined in {@link UpdateConfigs}. |
| 300 | */ |
| 301 | private void loadUpdateConfigs() { |
| 302 | mConfigs = UpdateConfigs.getUpdateConfigs(this); |
| 303 | loadConfigsToSpinner(mConfigs); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * @param status update engine status code |
| 308 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 309 | private void setUiEngineStatus(int status) { |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 310 | String statusText = UpdateEngineStatuses.getStatusText(status); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 311 | mTextViewEngineStatus.setText(statusText + "/" + status); |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /** |
| 315 | * @param errorCode update engine error code |
| 316 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 317 | private void setUiEngineErrorCode(int errorCode) { |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 318 | String errorText = UpdateEngineErrorCodes.getCodeName(errorCode); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 319 | mTextViewEngineErrorCode.setText(errorText + "/" + errorCode); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * @param state updater sample state |
| 324 | */ |
| 325 | private void setUiUpdaterState(int state) { |
| 326 | String stateText = UpdaterStates.getStateText(state); |
| 327 | mTextViewUpdaterState.setText(stateText + "/" + state); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | private void loadConfigsToSpinner(List<UpdateConfig> configs) { |
| 331 | String[] spinnerArray = UpdateConfigs.configsToNames(configs); |
| 332 | ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, |
| 333 | android.R.layout.simple_spinner_item, |
| 334 | spinnerArray); |
| 335 | spinnerArrayAdapter.setDropDownViewResource(android.R.layout |
| 336 | .simple_spinner_dropdown_item); |
| 337 | mSpinnerConfigs.setAdapter(spinnerArrayAdapter); |
| 338 | } |
| 339 | |
| 340 | private UpdateConfig getSelectedConfig() { |
| 341 | return mConfigs.get(mSpinnerConfigs.getSelectedItemPosition()); |
| 342 | } |
| 343 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 344 | } |