1#!/usr/bin/python 2 3# Copyright (C) 2015 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import os 18import sys 19import getopt 20 21def write_java_head(tofile, name): 22 tofile.write("/* This file is auto-generated from {}.java. DO NOT MODIFY. */\n\n".format(name)) 23 24def replace_xml_head(line, name): 25 return line.replace('<?xml version="1.0" encoding="utf-8"?>', '<?xml version="1.0" encoding="utf-8"?>\n<!-- This file is auto-generated from {}.xml. DO NOT MODIFY. -->\n'.format(name)) 26 27file = open('src/com/example/android/leanback/GuidedStepActivity.java', 'r') 28outfile = open('src/com/example/android/leanback/GuidedStepSupportActivity.java', 'w') 29write_java_head(outfile, "GuidedStepActivity") 30for line in file: 31 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 32 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 33 line = line.replace('GuidedStepFragment', 'GuidedStepSupportFragment') 34 line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity') 35 line = line.replace('extends Activity', 'extends FragmentActivity') 36 outfile.write(line) 37file.close() 38outfile.close() 39 40file = open('src/com/example/android/leanback/GuidedStepHalfScreenActivity.java', 'r') 41outfile = open('src/com/example/android/leanback/GuidedStepSupportHalfScreenActivity.java', 'w') 42write_java_head(outfile, "GuidedStepHalfScreenActivity") 43for line in file: 44 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 45 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 46 line = line.replace('GuidedStepFragment', 'GuidedStepSupportFragment') 47 line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity') 48 line = line.replace('GuidedStepHalfScreenActivity', 'GuidedStepSupportHalfScreenActivity') 49 line = line.replace('extends Activity', 'extends FragmentActivity') 50 outfile.write(line) 51file.close() 52outfile.close() 53 54file = open('src/com/example/android/leanback/BrowseFragment.java', 'r') 55outfile = open('src/com/example/android/leanback/BrowseSupportFragment.java', 'w') 56write_java_head(outfile, "BrowseFragment") 57for line in file: 58 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 59 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 60 line = line.replace('BrowseFragment', 'BrowseSupportFragment') 61 line = line.replace('GuidedStepFragment', 'GuidedStepSupportFragment') 62 line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity') 63 line = line.replace('getActivity().getFragmentManager()', 'getActivity().getSupportFragmentManager()') 64 line = line.replace('BrowseActivity', 'BrowseSupportActivity') 65 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 66 line = line.replace('SearchActivity', 'SearchSupportActivity') 67 line = line.replace('RowsActivity', 'RowsSupportActivity') 68 line = line.replace('RowsFragment', 'RowsSupportFragment') 69 line = line.replace('GuidedStepHalfScreenActivity', 'GuidedStepSupportHalfScreenActivity') 70 outfile.write(line) 71file.close() 72outfile.close() 73 74file = open('src/com/example/android/leanback/BrowseActivity.java', 'r') 75outfile = open('src/com/example/android/leanback/BrowseSupportActivity.java', 'w') 76write_java_head(outfile, "BrowseActivity") 77for line in file: 78 line = line.replace('BrowseActivity', 'BrowseSupportActivity') 79 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 80 line = line.replace('extends Activity', 'extends FragmentActivity') 81 line = line.replace('R.layout.browse', 'R.layout.browse_support') 82 outfile.write(line) 83file.close() 84outfile.close() 85 86file = open('res/layout/browse.xml', 'r') 87outfile = open('res/layout/browse_support.xml', 'w') 88for line in file: 89 line = replace_xml_head(line, "browse") 90 line = line.replace('com.example.android.leanback.BrowseFragment', 'com.example.android.leanback.BrowseSupportFragment') 91 outfile.write(line) 92file.close() 93outfile.close() 94 95 96file = open('src/com/example/android/leanback/DetailsFragment.java', 'r') 97outfile = open('src/com/example/android/leanback/DetailsSupportFragment.java', 'w') 98write_java_head(outfile, "DetailsFragment") 99for line in file: 100 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 101 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 102 line = line.replace('DetailsFragment', 'DetailsSupportFragment') 103 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 104 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 105 line = line.replace('SearchActivity', 'SearchSupportActivity') 106 outfile.write(line) 107file.close() 108outfile.close() 109 110file = open('src/com/example/android/leanback/NewDetailsFragment.java', 'r') 111outfile = open('src/com/example/android/leanback/NewDetailsSupportFragment.java', 'w') 112write_java_head(outfile, "NewDetailsFragment") 113for line in file: 114 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 115 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 116 line = line.replace('DetailsFragment', 'DetailsSupportFragment') 117 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 118 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 119 line = line.replace('SearchActivity', 'SearchSupportActivity') 120 outfile.write(line) 121file.close() 122outfile.close() 123 124file = open('src/com/example/android/leanback/DetailsActivity.java', 'r') 125outfile = open('src/com/example/android/leanback/DetailsSupportActivity.java', 'w') 126write_java_head(outfile, "DetailsActivity") 127for line in file: 128 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 129 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 130 line = line.replace('extends Activity', 'extends FragmentActivity') 131 line = line.replace('R.layout.details', 'R.layout.details_support') 132 line = line.replace('R.layout.legacy_details', 'R.layout.legacy_details_support') 133 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 134 line = line.replace('DetailsFragment', 'DetailsSupportFragment') 135 line = line.replace('NewDetailsFragment', 'NewDetailsSupportFragment') 136 outfile.write(line) 137file.close() 138outfile.close() 139 140file = open('res/layout/details.xml', 'r') 141outfile = open('res/layout/details_support.xml', 'w') 142for line in file: 143 line = replace_xml_head(line, "details") 144 line = line.replace('com.example.android.leanback.NewDetailsFragment', 'com.example.android.leanback.NewDetailsSupportFragment') 145 outfile.write(line) 146file.close() 147outfile.close() 148 149 150file = open('res/layout/legacy_details.xml', 'r') 151outfile = open('res/layout/legacy_details_support.xml', 'w') 152for line in file: 153 line = replace_xml_head(line, "legacy_details") 154 line = line.replace('com.example.android.leanback.DetailsFragment', 'com.example.android.leanback.DetailsSupportFragment') 155 outfile.write(line) 156file.close() 157outfile.close() 158 159 160file = open('src/com/example/android/leanback/SearchDetailsActivity.java', 'r') 161outfile = open('src/com/example/android/leanback/SearchDetailsSupportActivity.java', 'w') 162write_java_head(outfile, "SearchDetailsActivity") 163for line in file: 164 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 165 outfile.write(line) 166file.close() 167outfile.close() 168 169 170file = open('src/com/example/android/leanback/SearchFragment.java', 'r') 171outfile = open('src/com/example/android/leanback/SearchSupportFragment.java', 'w') 172write_java_head(outfile, "SearchFragment") 173for line in file: 174 line = line.replace('SearchFragment', 'SearchSupportFragment') 175 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 176 outfile.write(line) 177file.close() 178outfile.close() 179 180file = open('src/com/example/android/leanback/SearchActivity.java', 'r') 181outfile = open('src/com/example/android/leanback/SearchSupportActivity.java', 'w') 182write_java_head(outfile, "SearchActivity") 183for line in file: 184 line = line.replace('SearchActivity', 'SearchSupportActivity') 185 line = line.replace('extends Activity', 'extends FragmentActivity') 186 line = line.replace('R.layout.search', 'R.layout.search_support') 187 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 188 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 189 line = line.replace('SearchFragment', 'SearchSupportFragment') 190 outfile.write(line) 191file.close() 192outfile.close() 193 194file = open('res/layout/search.xml', 'r') 195outfile = open('res/layout/search_support.xml', 'w') 196for line in file: 197 line = replace_xml_head(line, "search") 198 line = line.replace('com.example.android.leanback.SearchFragment', 'com.example.android.leanback.SearchSupportFragment') 199 outfile.write(line) 200file.close() 201outfile.close() 202 203file = open('src/com/example/android/leanback/VerticalGridFragment.java', 'r') 204outfile = open('src/com/example/android/leanback/VerticalGridSupportFragment.java', 'w') 205outfile.write("/* This file is auto-generated from VerticalGridFragment. DO NOT MODIFY. */\n\n") 206for line in file: 207 line = line.replace('VerticalGridFragment', 'VerticalGridSupportFragment') 208 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 209 line = line.replace('SearchActivity', 'SearchSupportActivity') 210 outfile.write(line) 211file.close() 212outfile.close() 213 214file = open('src/com/example/android/leanback/VerticalGridActivity.java', 'r') 215outfile = open('src/com/example/android/leanback/VerticalGridSupportActivity.java', 'w') 216write_java_head(outfile, "VerticalGridActivity") 217for line in file: 218 line = line.replace('VerticalGridActivity', 'VerticalGridSupportActivity') 219 line = line.replace('extends Activity', 'extends FragmentActivity') 220 line = line.replace('R.layout.vertical_grid', 'R.layout.vertical_grid_support') 221 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 222 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 223 line = line.replace('VerticalGridFragment', 'VerticalGridSupportFragment') 224 outfile.write(line) 225file.close() 226outfile.close() 227 228file = open('res/layout/vertical_grid.xml', 'r') 229outfile = open('res/layout/vertical_grid_support.xml', 'w') 230for line in file: 231 line = replace_xml_head(line, "vertical_grid") 232 line = line.replace('com.example.android.leanback.VerticalGridFragment', 'com.example.android.leanback.VerticalGridSupportFragment') 233 outfile.write(line) 234file.close() 235outfile.close() 236 237 238file = open('src/com/example/android/leanback/ErrorFragment.java', 'r') 239outfile = open('src/com/example/android/leanback/ErrorSupportFragment.java', 'w') 240write_java_head(outfile, "ErrorFragment") 241for line in file: 242 line = line.replace('ErrorFragment', 'ErrorSupportFragment') 243 outfile.write(line) 244file.close() 245outfile.close() 246 247file = open('src/com/example/android/leanback/BrowseErrorActivity.java', 'r') 248outfile = open('src/com/example/android/leanback/BrowseErrorSupportActivity.java', 'w') 249write_java_head(outfile, "BrowseErrorActivity") 250for line in file: 251 line = line.replace('BrowseErrorActivity', 'BrowseErrorSupportActivity') 252 line = line.replace('extends Activity', 'extends FragmentActivity') 253 line = line.replace('R.layout.browse', 'R.layout.browse_support') 254 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 255 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 256 line = line.replace('ErrorFragment', 'ErrorSupportFragment') 257 line = line.replace('SpinnerFragment', 'SpinnerSupportFragment') 258 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 259 outfile.write(line) 260file.close() 261outfile.close() 262 263file = open('src/com/example/android/leanback/RowsFragment.java', 'r') 264outfile = open('src/com/example/android/leanback/RowsSupportFragment.java', 'w') 265write_java_head(outfile, "RowsFragment") 266for line in file: 267 line = line.replace('RowsFragment', 'RowsSupportFragment') 268 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 269 outfile.write(line) 270file.close() 271outfile.close() 272 273file = open('src/com/example/android/leanback/RowsActivity.java', 'r') 274outfile = open('src/com/example/android/leanback/RowsSupportActivity.java', 'w') 275write_java_head(outfile, "RowsActivity") 276for line in file: 277 line = line.replace('RowsActivity', 'RowsSupportActivity') 278 line = line.replace('extends Activity', 'extends FragmentActivity') 279 line = line.replace('R.layout.rows', 'R.layout.rows_support') 280 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 281 line = line.replace('RowsFragment', 'RowsSupportFragment') 282 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 283 line = line.replace('SearchActivity', 'SearchSupportActivity') 284 outfile.write(line) 285file.close() 286outfile.close() 287 288file = open('res/layout/rows.xml', 'r') 289outfile = open('res/layout/rows_support.xml', 'w') 290for line in file: 291 line = replace_xml_head(line, "rows") 292 line = line.replace('com.example.android.leanback.RowsFragment', 'com.example.android.leanback.RowsSupportFragment') 293 outfile.write(line) 294file.close() 295outfile.close() 296 297 298file = open('src/com/example/android/leanback/PlaybackOverlayFragment.java', 'r') 299outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportFragment.java', 'w') 300write_java_head(outfile, "PlaybackOverlayFragment") 301for line in file: 302 line = line.replace('PlaybackOverlayFragment', 'PlaybackOverlaySupportFragment') 303 line = line.replace('PlaybackControlHelper', 'PlaybackControlSupportHelper') 304 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 305 outfile.write(line) 306file.close() 307outfile.close() 308 309file = open('src/com/example/android/leanback/PlaybackControlHelper.java', 'r') 310outfile = open('src/com/example/android/leanback/PlaybackControlSupportHelper.java', 'w') 311write_java_head(outfile, "PlaybackControlHelper") 312for line in file: 313 line = line.replace('PlaybackControlHelper', 'PlaybackControlSupportHelper') 314 line = line.replace('PlaybackControlGlue', 'PlaybackControlSupportGlue') 315 line = line.replace('PlaybackOverlayFragment', 'PlaybackOverlaySupportFragment') 316 outfile.write(line) 317file.close() 318outfile.close() 319 320file = open('src/com/example/android/leanback/PlaybackOverlayActivity.java', 'r') 321outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportActivity.java', 'w') 322write_java_head(outfile, "PlaybackOverlayActivity") 323for line in file: 324 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 325 line = line.replace('extends Activity', 'extends FragmentActivity') 326 line = line.replace('R.layout.playback_controls', 'R.layout.playback_controls_support') 327 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 328 outfile.write(line) 329file.close() 330outfile.close() 331 332file = open('res/layout/playback_controls.xml', 'r') 333outfile = open('res/layout/playback_controls_support.xml', 'w') 334for line in file: 335 line = replace_xml_head(line, "playback_controls") 336 line = line.replace('com.example.android.leanback.PlaybackOverlayFragment', 'com.example.android.leanback.PlaybackOverlaySupportFragment') 337 outfile.write(line) 338file.close() 339outfile.close() 340 341file = open('src/com/example/android/leanback/OnboardingActivity.java', 'r') 342outfile = open('src/com/example/android/leanback/OnboardingSupportActivity.java', 'w') 343write_java_head(outfile, "OnboardingActivity") 344for line in file: 345 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 346 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 347 line = line.replace('OnboardingActivity', 'OnboardingSupportActivity') 348 line = line.replace('OnboardingDemoFragment', 'OnboardingDemoSupportFragment') 349 line = line.replace('extends Activity', 'extends FragmentActivity') 350 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 351 outfile.write(line) 352file.close() 353outfile.close() 354 355file = open('src/com/example/android/leanback/OnboardingDemoFragment.java', 'r') 356outfile = open('src/com/example/android/leanback/OnboardingDemoSupportFragment.java', 'w') 357write_java_head(outfile, "OnboardingDemoFragment") 358for line in file: 359 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 360 line = line.replace('import android.app.Activity', 'import android.support.v4.app.FragmentActivity') 361 line = line.replace('OnboardingDemoFragment', 'OnboardingDemoSupportFragment') 362 line = line.replace('OnboardingFragment', 'OnboardingSupportFragment') 363 line = line.replace('OnboardingActivity', 'OnboardingSupportActivity') 364 outfile.write(line) 365file.close() 366outfile.close() 367