1 /* 2 * Copyright (C) 2015 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.android.settings.deviceinfo; 18 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; 35 36 import com.android.settings.R; 37 import com.android.setupwizardlib.SetupWizardLayout; 38 39 import java.text.NumberFormat; 40 import java.util.List; 41 import java.util.Objects; 42 43 public abstract class StorageWizardBase extends Activity { 44 protected StorageManager mStorage; 45 46 protected VolumeInfo mVolume; 47 protected DiskInfo mDisk; 48 49 private View mCustomNav; 50 private Button mCustomNext; 51 52 @Override onCreate(Bundle savedInstanceState)53 protected void onCreate(Bundle savedInstanceState) { 54 super.onCreate(savedInstanceState); 55 56 mStorage = getSystemService(StorageManager.class); 57 58 final String volumeId = getIntent().getStringExtra(VolumeInfo.EXTRA_VOLUME_ID); 59 if (!TextUtils.isEmpty(volumeId)) { 60 mVolume = mStorage.findVolumeById(volumeId); 61 } 62 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(); 68 } 69 70 setTheme(R.style.SetupWizardStorageStyle); 71 72 if (mDisk != null) { 73 mStorage.registerListener(mStorageListener); 74 } 75 } 76 77 @Override setContentView(@ayoutRes int layoutResID)78 public void setContentView(@LayoutRes int layoutResID) { 79 super.setContentView(layoutResID); 80 81 // Our wizard is a unique flower, so it has custom buttons 82 final ViewGroup navParent = (ViewGroup) findViewById(R.id.suw_layout_navigation_bar) 83 .getParent(); 84 mCustomNav = getLayoutInflater().inflate(R.layout.storage_wizard_navigation, 85 navParent, false); 86 87 mCustomNext = (Button) mCustomNav.findViewById(R.id.suw_navbar_next); 88 mCustomNext.setOnClickListener(new View.OnClickListener() { 89 @Override 90 public void onClick(View v) { 91 onNavigateNext(); 92 } 93 }); 94 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); 100 break; 101 } 102 } 103 } 104 105 @Override onPostCreate(Bundle savedInstanceState)106 protected void onPostCreate(Bundle savedInstanceState) { 107 super.onPostCreate(savedInstanceState); 108 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); 114 115 mCustomNav.setSystemUiVisibility( 116 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 117 118 final View scrollView = findViewById(R.id.suw_bottom_scroll_view); 119 scrollView.setVerticalFadingEdgeEnabled(true); 120 scrollView.setFadingEdgeLength(scrollView.getVerticalFadingEdgeLength() * 2); 121 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()); 126 } 127 128 @Override onDestroy()129 protected void onDestroy() { 130 mStorage.unregisterListener(mStorageListener); 131 super.onDestroy(); 132 } 133 getNextButton()134 protected Button getNextButton() { 135 return mCustomNext; 136 } 137 getSetupWizardLayout()138 protected SetupWizardLayout getSetupWizardLayout() { 139 return (SetupWizardLayout) findViewById(R.id.setup_wizard_layout); 140 } 141 getProgressBar()142 protected ProgressBar getProgressBar() { 143 return (ProgressBar) findViewById(R.id.storage_wizard_progress); 144 } 145 setCurrentProgress(int 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)); 150 } 151 setHeaderText(int resId, String... args)152 protected void setHeaderText(int resId, String... args) { 153 final CharSequence headerText = TextUtils.expandTemplate(getText(resId), args); 154 getSetupWizardLayout().setHeaderText(headerText); 155 setTitle(headerText); 156 } 157 setBodyText(int resId, String... args)158 protected void setBodyText(int resId, String... args) { 159 ((TextView) findViewById(R.id.storage_wizard_body)).setText( 160 TextUtils.expandTemplate(getText(resId), args)); 161 } 162 setSecondaryBodyText(int resId, String... 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); 167 } 168 setIllustrationInternal(boolean internal)169 protected void setIllustrationInternal(boolean internal) { 170 if (internal) { 171 getSetupWizardLayout().setIllustration(R.drawable.bg_internal_storage_header, 172 R.drawable.bg_header_horizontal_tile); 173 } else { 174 getSetupWizardLayout().setIllustration(R.drawable.bg_portable_storage_header, 175 R.drawable.bg_header_horizontal_tile); 176 } 177 } 178 setKeepScreenOn(boolean keepScreenOn)179 protected void setKeepScreenOn(boolean keepScreenOn) { 180 getSetupWizardLayout().setKeepScreenOn(keepScreenOn); 181 } 182 onNavigateNext()183 public void onNavigateNext() { 184 throw new UnsupportedOperationException(); 185 } 186 findFirstVolume(int type)187 protected VolumeInfo findFirstVolume(int type) { 188 final List<VolumeInfo> vols = mStorage.getVolumes(); 189 for (VolumeInfo vol : vols) { 190 if (Objects.equals(mDisk.getId(), vol.getDiskId()) && (vol.getType() == type)) { 191 return vol; 192 } 193 } 194 return null; 195 } 196 197 private final StorageEventListener mStorageListener = new StorageEventListener() { 198 @Override 199 public void onDiskDestroyed(DiskInfo disk) { 200 // We know mDisk != null. 201 if (mDisk.id.equals(disk.id)) { 202 finish(); 203 } 204 } 205 }; 206 } 207