2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.deviceinfo;
19 import android.annotation.LayoutRes;
20 import android.app.Activity;
21 import android.graphics.Color;
22 import android.os.Bundle;
23 import android.os.storage.DiskInfo;
24 import android.os.storage.StorageEventListener;
25 import android.os.storage.StorageManager;
26 import android.os.storage.VolumeInfo;
27 import android.text.TextUtils;
28 import android.view.View;
29 import android.view.ViewGroup;
30 import android.view.Window;
31 import android.view.WindowManager;
32 import android.widget.Button;
33 import android.widget.ProgressBar;
34 import android.widget.TextView;
36 import com.android.settings.R;
37 import com.android.setupwizardlib.SetupWizardLayout;
39 import java.text.NumberFormat;
40 import java.util.List;
41 import java.util.Objects;
43 public abstract class StorageWizardBase extends Activity {
44 protected StorageManager mStorage;
46 protected VolumeInfo mVolume;
47 protected DiskInfo mDisk;
49 private View mCustomNav;
50 private Button mCustomNext;
53 protected void onCreate(Bundle savedInstanceState) {
54 super.onCreate(savedInstanceState);
56 mStorage = getSystemService(StorageManager.class);
58 final String volumeId = getIntent().getStringExtra(VolumeInfo.EXTRA_VOLUME_ID);
59 if (!TextUtils.isEmpty(volumeId)) {
60 mVolume = mStorage.findVolumeById(volumeId);
63 final String diskId = getIntent().getStringExtra(DiskInfo.EXTRA_DISK_ID);
64 if (!TextUtils.isEmpty(diskId)) {
65 mDisk = mStorage.findDiskById(diskId);
66 } else if (mVolume != null) {
67 mDisk = mVolume.getDisk();
70 setTheme(R.style.SetupWizardStorageStyle);
73 mStorage.registerListener(mStorageListener);
78 public void setContentView(@LayoutRes int layoutResID) {
79 super.setContentView(layoutResID);
81 // Our wizard is a unique flower, so it has custom buttons
82 final ViewGroup navParent = (ViewGroup) findViewById(R.id.suw_layout_navigation_bar)
84 mCustomNav = getLayoutInflater().inflate(R.layout.storage_wizard_navigation,
87 mCustomNext = (Button) mCustomNav.findViewById(R.id.suw_navbar_next);
88 mCustomNext.setOnClickListener(new View.OnClickListener() {
90 public void onClick(View v) {
95 // Swap our custom navigation bar into place
96 for (int i = 0; i < navParent.getChildCount(); i++) {
97 if (navParent.getChildAt(i).getId() == R.id.suw_layout_navigation_bar) {
98 navParent.removeViewAt(i);
99 navParent.addView(mCustomNav, i);
106 protected void onPostCreate(Bundle savedInstanceState) {
107 super.onPostCreate(savedInstanceState);
109 final Window window = getWindow();
110 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
111 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
112 WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
113 window.setStatusBarColor(Color.TRANSPARENT);
115 mCustomNav.setSystemUiVisibility(
116 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
118 final View scrollView = findViewById(R.id.suw_bottom_scroll_view);
119 scrollView.setVerticalFadingEdgeEnabled(true);
120 scrollView.setFadingEdgeLength(scrollView.getVerticalFadingEdgeLength() * 2);
122 // Our header assets already have padding baked in
123 final View title = findViewById(R.id.suw_layout_title);
124 title.setPadding(title.getPaddingLeft(), 0, title.getPaddingRight(),
125 title.getPaddingBottom());
129 protected void onDestroy() {
130 mStorage.unregisterListener(mStorageListener);
134 protected Button getNextButton() {
138 protected SetupWizardLayout getSetupWizardLayout() {
139 return (SetupWizardLayout) findViewById(R.id.setup_wizard_layout);
142 protected ProgressBar getProgressBar() {
143 return (ProgressBar) findViewById(R.id.storage_wizard_progress);
146 protected void setCurrentProgress(int progress) {
147 getProgressBar().setProgress(progress);
148 ((TextView) findViewById(R.id.storage_wizard_progress_summary)).setText(
149 NumberFormat.getPercentInstance().format((double) progress / 100));
152 protected void setHeaderText(int resId, String... args) {
153 final CharSequence headerText = TextUtils.expandTemplate(getText(resId), args);
154 getSetupWizardLayout().setHeaderText(headerText);
155 setTitle(headerText);
158 protected void setBodyText(int resId, String... args) {
159 ((TextView) findViewById(R.id.storage_wizard_body)).setText(
160 TextUtils.expandTemplate(getText(resId), args));
163 protected void setSecondaryBodyText(int resId, String... args) {
164 final TextView secondBody = ((TextView) findViewById(R.id.storage_wizard_second_body));
165 secondBody.setText(TextUtils.expandTemplate(getText(resId), args));
166 secondBody.setVisibility(View.VISIBLE);
169 protected void setIllustrationInternal(boolean internal) {
171 getSetupWizardLayout().setIllustration(R.drawable.bg_internal_storage_header,
172 R.drawable.bg_header_horizontal_tile);
174 getSetupWizardLayout().setIllustration(R.drawable.bg_portable_storage_header,
175 R.drawable.bg_header_horizontal_tile);
179 public void onNavigateNext() {
180 throw new UnsupportedOperationException();
183 protected VolumeInfo findFirstVolume(int type) {
184 final List<VolumeInfo> vols = mStorage.getVolumes();
185 for (VolumeInfo vol : vols) {
186 if (Objects.equals(mDisk.getId(), vol.getDiskId()) && (vol.getType() == type)) {
193 private final StorageEventListener mStorageListener = new StorageEventListener() {
195 public void onDiskDestroyed(DiskInfo disk) {
196 // We know mDisk != null.
197 if (mDisk.id.equals(disk.id)) {