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 17 import os 18 import sys 19 import getopt 20 21 def write_java_head(tofile, name): 22 tofile.write("// CHECKSTYLE:OFF Generated code\n") 23 tofile.write("/* This file is auto-generated from {}.java. DO NOT MODIFY. */\n\n".format(name)) 24 25 def replace_xml_head(line, name): 26 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)) 27 28 file = open('src/com/example/android/leanback/GuidedStepActivity.java', 'r') 29 outfile = open('src/com/example/android/leanback/GuidedStepSupportActivity.java', 'w') 30 write_java_head(outfile, "GuidedStepActivity") 31 for line in file: 32 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 33 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 34 line = line.replace('GuidedStepFragment', 'GuidedStepSupportFragment') 35 line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity') 36 line = line.replace('extends Activity', 'extends FragmentActivity') 37 outfile.write(line) 38 file.close() 39 outfile.close() 40 41 file = open('src/com/example/android/leanback/GuidedStepHalfScreenActivity.java', 'r') 42 outfile = open('src/com/example/android/leanback/GuidedStepSupportHalfScreenActivity.java', 'w') 43 write_java_head(outfile, "GuidedStepHalfScreenActivity") 44 for line in file: 45 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 46 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 47 line = line.replace('GuidedStepFragment', 'GuidedStepSupportFragment') 48 line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity') 49 line = line.replace('GuidedStepHalfScreenActivity', 'GuidedStepSupportHalfScreenActivity') 50 line = line.replace('extends Activity', 'extends FragmentActivity') 51 outfile.write(line) 52 file.close() 53 outfile.close() 54 55 file = open('src/com/example/android/leanback/BrowseFragment.java', 'r') 56 outfile = open('src/com/example/android/leanback/BrowseSupportFragment.java', 'w') 57 write_java_head(outfile, "BrowseFragment") 58 for line in file: 59 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 60 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 61 line = line.replace('BrowseFragment', 'BrowseSupportFragment') 62 line = line.replace('GuidedStepFragment', 'GuidedStepSupportFragment') 63 line = line.replace('GuidedStepActivity', 'GuidedStepSupportActivity') 64 line = line.replace('getActivity().getFragmentManager()', 'getActivity().getSupportFragmentManager()') 65 line = line.replace('BrowseActivity', 'BrowseSupportActivity') 66 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 67 line = line.replace('SearchActivity', 'SearchSupportActivity') 68 line = line.replace('RowsActivity', 'RowsSupportActivity') 69 line = line.replace('RowsFragment', 'RowsSupportFragment') 70 line = line.replace('GuidedStepHalfScreenActivity', 'GuidedStepSupportHalfScreenActivity') 71 outfile.write(line) 72 file.close() 73 outfile.close() 74 75 file = open('src/com/example/android/leanback/BrowseActivity.java', 'r') 76 outfile = open('src/com/example/android/leanback/BrowseSupportActivity.java', 'w') 77 write_java_head(outfile, "BrowseActivity") 78 for line in file: 79 line = line.replace('BrowseActivity', 'BrowseSupportActivity') 80 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 81 line = line.replace('extends Activity', 'extends FragmentActivity') 82 line = line.replace('R.layout.browse', 'R.layout.browse_support') 83 outfile.write(line) 84 file.close() 85 outfile.close() 86 87 file = open('res/layout/browse.xml', 'r') 88 outfile = open('res/layout/browse_support.xml', 'w') 89 for line in file: 90 line = replace_xml_head(line, "browse") 91 line = line.replace('com.example.android.leanback.BrowseFragment', 'com.example.android.leanback.BrowseSupportFragment') 92 outfile.write(line) 93 file.close() 94 outfile.close() 95 96 97 file = open('src/com/example/android/leanback/DetailsFragment.java', 'r') 98 outfile = open('src/com/example/android/leanback/DetailsSupportFragment.java', 'w') 99 write_java_head(outfile, "DetailsFragment") 100 for line in file: 101 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 102 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 103 line = line.replace('DetailsFragment', 'DetailsSupportFragment') 104 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 105 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 106 line = line.replace('SearchActivity', 'SearchSupportActivity') 107 outfile.write(line) 108 file.close() 109 outfile.close() 110 111 file = open('src/com/example/android/leanback/NewDetailsFragment.java', 'r') 112 outfile = open('src/com/example/android/leanback/NewDetailsSupportFragment.java', 'w') 113 write_java_head(outfile, "NewDetailsFragment") 114 for line in file: 115 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 116 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 117 line = line.replace('DetailsFragment', 'DetailsSupportFragment') 118 line = line.replace('DetailsSupportFragmentVideoHelper', 'DetailsFragmentVideoHelper') 119 line = line.replace('VideoFragment', 'VideoSupportFragment') 120 line = line.replace('PlaybackFragmentGlueHost', 'PlaybackSupportFragmentGlueHost') 121 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 122 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 123 line = line.replace('SearchActivity', 'SearchSupportActivity') 124 line = line.replace('SearchActivity', 'SearchSupportActivity') 125 line = line.replace('getRowsFragment', 'getRowsSupportFragment') 126 outfile.write(line) 127 file.close() 128 outfile.close() 129 130 file = open('src/com/example/android/leanback/DetailsActivity.java', 'r') 131 outfile = open('src/com/example/android/leanback/DetailsSupportActivity.java', 'w') 132 write_java_head(outfile, "DetailsActivity") 133 for line in file: 134 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 135 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 136 line = line.replace('extends Activity', 'extends FragmentActivity') 137 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 138 line = line.replace('DetailsFragment', 'DetailsSupportFragment') 139 line = line.replace('NewDetailsFragment', 'NewDetailsSupportFragment') 140 outfile.write(line) 141 file.close() 142 outfile.close() 143 144 file = open('src/com/example/android/leanback/SearchDetailsActivity.java', 'r') 145 outfile = open('src/com/example/android/leanback/SearchDetailsSupportActivity.java', 'w') 146 write_java_head(outfile, "SearchDetailsActivity") 147 for line in file: 148 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 149 outfile.write(line) 150 file.close() 151 outfile.close() 152 153 154 file = open('src/com/example/android/leanback/SearchFragment.java', 'r') 155 outfile = open('src/com/example/android/leanback/SearchSupportFragment.java', 'w') 156 write_java_head(outfile, "SearchFragment") 157 for line in file: 158 line = line.replace('SearchFragment', 'SearchSupportFragment') 159 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 160 outfile.write(line) 161 file.close() 162 outfile.close() 163 164 file = open('src/com/example/android/leanback/SearchActivity.java', 'r') 165 outfile = open('src/com/example/android/leanback/SearchSupportActivity.java', 'w') 166 write_java_head(outfile, "SearchActivity") 167 for line in file: 168 line = line.replace('SearchActivity', 'SearchSupportActivity') 169 line = line.replace('extends Activity', 'extends FragmentActivity') 170 line = line.replace('R.layout.search', 'R.layout.search_support') 171 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 172 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 173 line = line.replace('SearchFragment', 'SearchSupportFragment') 174 outfile.write(line) 175 file.close() 176 outfile.close() 177 178 file = open('res/layout/search.xml', 'r') 179 outfile = open('res/layout/search_support.xml', 'w') 180 for line in file: 181 line = replace_xml_head(line, "search") 182 line = line.replace('com.example.android.leanback.SearchFragment', 'com.example.android.leanback.SearchSupportFragment') 183 outfile.write(line) 184 file.close() 185 outfile.close() 186 187 file = open('src/com/example/android/leanback/VerticalGridFragment.java', 'r') 188 outfile = open('src/com/example/android/leanback/VerticalGridSupportFragment.java', 'w') 189 write_java_head(outfile, "VerticalGridFragment") 190 for line in file: 191 line = line.replace('VerticalGridFragment', 'VerticalGridSupportFragment') 192 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 193 line = line.replace('SearchActivity', 'SearchSupportActivity') 194 outfile.write(line) 195 file.close() 196 outfile.close() 197 198 file = open('src/com/example/android/leanback/VerticalGridActivity.java', 'r') 199 outfile = open('src/com/example/android/leanback/VerticalGridSupportActivity.java', 'w') 200 write_java_head(outfile, "VerticalGridActivity") 201 for line in file: 202 line = line.replace('VerticalGridActivity', 'VerticalGridSupportActivity') 203 line = line.replace('extends Activity', 'extends FragmentActivity') 204 line = line.replace('R.layout.vertical_grid', 'R.layout.vertical_grid_support') 205 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 206 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 207 line = line.replace('VerticalGridFragment', 'VerticalGridSupportFragment') 208 outfile.write(line) 209 file.close() 210 outfile.close() 211 212 file = open('res/layout/vertical_grid.xml', 'r') 213 outfile = open('res/layout/vertical_grid_support.xml', 'w') 214 for line in file: 215 line = replace_xml_head(line, "vertical_grid") 216 line = line.replace('com.example.android.leanback.VerticalGridFragment', 'com.example.android.leanback.VerticalGridSupportFragment') 217 outfile.write(line) 218 file.close() 219 outfile.close() 220 221 222 file = open('src/com/example/android/leanback/ErrorFragment.java', 'r') 223 outfile = open('src/com/example/android/leanback/ErrorSupportFragment.java', 'w') 224 write_java_head(outfile, "ErrorFragment") 225 for line in file: 226 line = line.replace('ErrorFragment', 'ErrorSupportFragment') 227 outfile.write(line) 228 file.close() 229 outfile.close() 230 231 file = open('src/com/example/android/leanback/BrowseErrorActivity.java', 'r') 232 outfile = open('src/com/example/android/leanback/BrowseErrorSupportActivity.java', 'w') 233 write_java_head(outfile, "BrowseErrorActivity") 234 for line in file: 235 line = line.replace('BrowseErrorActivity', 'BrowseErrorSupportActivity') 236 line = line.replace('extends Activity', 'extends FragmentActivity') 237 line = line.replace('R.layout.browse', 'R.layout.browse_support') 238 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 239 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 240 line = line.replace('ErrorFragment', 'ErrorSupportFragment') 241 line = line.replace('SpinnerFragment', 'SpinnerSupportFragment') 242 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 243 outfile.write(line) 244 file.close() 245 outfile.close() 246 247 file = open('src/com/example/android/leanback/RowsFragment.java', 'r') 248 outfile = open('src/com/example/android/leanback/RowsSupportFragment.java', 'w') 249 write_java_head(outfile, "RowsFragment") 250 for line in file: 251 line = line.replace('RowsFragment', 'RowsSupportFragment') 252 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 253 outfile.write(line) 254 file.close() 255 outfile.close() 256 257 file = open('src/com/example/android/leanback/RowsActivity.java', 'r') 258 outfile = open('src/com/example/android/leanback/RowsSupportActivity.java', 'w') 259 write_java_head(outfile, "RowsActivity") 260 for line in file: 261 line = line.replace('RowsActivity', 'RowsSupportActivity') 262 line = line.replace('extends Activity', 'extends FragmentActivity') 263 line = line.replace('R.layout.rows', 'R.layout.rows_support') 264 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 265 line = line.replace('RowsFragment', 'RowsSupportFragment') 266 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 267 line = line.replace('SearchActivity', 'SearchSupportActivity') 268 outfile.write(line) 269 file.close() 270 outfile.close() 271 272 file = open('res/layout/rows.xml', 'r') 273 outfile = open('res/layout/rows_support.xml', 'w') 274 for line in file: 275 line = replace_xml_head(line, "rows") 276 line = line.replace('com.example.android.leanback.RowsFragment', 'com.example.android.leanback.RowsSupportFragment') 277 outfile.write(line) 278 file.close() 279 outfile.close() 280 281 file = open('src/com/example/android/leanback/PlaybackFragment.java', 'r') 282 outfile = open('src/com/example/android/leanback/PlaybackSupportFragment.java', 'w') 283 write_java_head(outfile, "PlaybackFragment") 284 for line in file: 285 line = line.replace('PlaybackFragment', 'PlaybackSupportFragment') 286 line = line.replace('PlaybackActivity', 'PlaybackSupportActivity') 287 outfile.write(line) 288 file.close() 289 outfile.close() 290 291 file = open('src/com/example/android/leanback/PlaybackActivity.java', 'r') 292 outfile = open('src/com/example/android/leanback/PlaybackSupportActivity.java', 'w') 293 write_java_head(outfile, "PlaybackActivity") 294 for line in file: 295 line = line.replace('PlaybackActivity', 'PlaybackSupportActivity') 296 line = line.replace('extends Activity', 'extends FragmentActivity') 297 line = line.replace('R.layout.playback_activity', 'R.layout.playback_activity_support') 298 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 299 outfile.write(line) 300 file.close() 301 outfile.close() 302 303 file = open('res/layout/playback_activity.xml', 'r') 304 outfile = open('res/layout/playback_activity_support.xml', 'w') 305 for line in file: 306 line = replace_xml_head(line, "playback_controls") 307 line = line.replace('com.example.android.leanback.PlaybackFragment', 'com.example.android.leanback.PlaybackSupportFragment') 308 outfile.write(line) 309 file.close() 310 outfile.close() 311 312 file = open('src/com/example/android/leanback/PlaybackTransportControlFragment.java', 'r') 313 outfile = open('src/com/example/android/leanback/PlaybackTransportControlSupportFragment.java', 'w') 314 write_java_head(outfile, "PlaybackTransportControlFragment") 315 for line in file: 316 line = line.replace('PlaybackFragment', 'PlaybackSupportFragment') 317 line = line.replace('PlaybackTransportControlFragment', 'PlaybackTransportControlSupportFragment') 318 line = line.replace('PlaybackTransportControlActivity', 'PlaybackTransportControlSupportActivity') 319 outfile.write(line) 320 file.close() 321 outfile.close() 322 323 file = open('src/com/example/android/leanback/PlaybackTransportControlActivity.java', 'r') 324 outfile = open('src/com/example/android/leanback/PlaybackTransportControlSupportActivity.java', 'w') 325 write_java_head(outfile, "PlaybackTransportControlActivity") 326 for line in file: 327 line = line.replace('PlaybackTransportControlActivity', 'PlaybackTransportControlSupportActivity') 328 line = line.replace('extends Activity', 'extends FragmentActivity') 329 line = line.replace('R.layout.playback_transportcontrol_activity', 'R.layout.playback_transportcontrol_activity_support') 330 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 331 outfile.write(line) 332 file.close() 333 outfile.close() 334 335 file = open('res/layout/playback_transportcontrol_activity.xml', 'r') 336 outfile = open('res/layout/playback_transportcontrol_activity_support.xml', 'w') 337 for line in file: 338 line = replace_xml_head(line, "playback_transportcontrols") 339 line = line.replace('com.example.android.leanback.PlaybackTransportControlFragment', 'com.example.android.leanback.PlaybackTransportControlSupportFragment') 340 outfile.write(line) 341 file.close() 342 outfile.close() 343 344 345 346 file = open('src/com/example/android/leanback/PlaybackOverlayFragment.java', 'r') 347 outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportFragment.java', 'w') 348 write_java_head(outfile, "PlaybackOverlayFragment") 349 for line in file: 350 line = line.replace('PlaybackOverlayFragment', 'PlaybackOverlaySupportFragment') 351 line = line.replace('PlaybackControlHelper', 'PlaybackControlSupportHelper') 352 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 353 outfile.write(line) 354 file.close() 355 outfile.close() 356 357 358 file = open('src/com/example/android/leanback/PlaybackControlHelper.java', 'r') 359 outfile = open('src/com/example/android/leanback/PlaybackControlSupportHelper.java', 'w') 360 write_java_head(outfile, "PlaybackControlHelper") 361 for line in file: 362 line = line.replace('PlaybackControlHelper', 'PlaybackControlSupportHelper') 363 line = line.replace('PlaybackControlGlue', 'PlaybackControlSupportGlue') 364 line = line.replace('PlaybackOverlayFragment', 'PlaybackOverlaySupportFragment') 365 outfile.write(line) 366 file.close() 367 outfile.close() 368 369 file = open('src/com/example/android/leanback/PlaybackOverlayActivity.java', 'r') 370 outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportActivity.java', 'w') 371 write_java_head(outfile, "PlaybackOverlayActivity") 372 for line in file: 373 line = line.replace('PlaybackOverlayActivity', 'PlaybackOverlaySupportActivity') 374 line = line.replace('extends Activity', 'extends FragmentActivity') 375 line = line.replace('R.layout.playback_controls', 'R.layout.playback_controls_support') 376 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 377 outfile.write(line) 378 file.close() 379 outfile.close() 380 381 file = open('res/layout/playback_controls.xml', 'r') 382 outfile = open('res/layout/playback_controls_support.xml', 'w') 383 for line in file: 384 line = replace_xml_head(line, "playback_controls") 385 line = line.replace('com.example.android.leanback.PlaybackOverlayFragment', 'com.example.android.leanback.PlaybackOverlaySupportFragment') 386 outfile.write(line) 387 file.close() 388 outfile.close() 389 390 file = open('src/com/example/android/leanback/OnboardingActivity.java', 'r') 391 outfile = open('src/com/example/android/leanback/OnboardingSupportActivity.java', 'w') 392 write_java_head(outfile, "OnboardingActivity") 393 for line in file: 394 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 395 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 396 line = line.replace('OnboardingActivity', 'OnboardingSupportActivity') 397 line = line.replace('OnboardingDemoFragment', 'OnboardingDemoSupportFragment') 398 line = line.replace('extends Activity', 'extends FragmentActivity') 399 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 400 outfile.write(line) 401 file.close() 402 outfile.close() 403 404 file = open('src/com/example/android/leanback/OnboardingDemoFragment.java', 'r') 405 outfile = open('src/com/example/android/leanback/OnboardingDemoSupportFragment.java', 'w') 406 write_java_head(outfile, "OnboardingDemoFragment") 407 for line in file: 408 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 409 line = line.replace('import android.app.Activity', 'import android.support.v4.app.FragmentActivity') 410 line = line.replace('OnboardingDemoFragment', 'OnboardingDemoSupportFragment') 411 line = line.replace('OnboardingFragment', 'OnboardingSupportFragment') 412 line = line.replace('OnboardingActivity', 'OnboardingSupportActivity') 413 outfile.write(line) 414 file.close() 415 outfile.close() 416 417 file = open('src/com/example/android/leanback/SampleVideoFragment.java', 'r') 418 outfile = open('src/com/example/android/leanback/SampleVideoSupportFragment.java', 'w') 419 write_java_head(outfile, "OnboardingDemoFragment") 420 for line in file: 421 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 422 line = line.replace('import android.app.Activity', 'import android.support.v4.app.FragmentActivity') 423 line = line.replace('SampleVideoFragment', 'SampleVideoSupportFragment') 424 line = line.replace('VideoFragment', 'VideoSupportFragment') 425 outfile.write(line) 426 file.close() 427 outfile.close() 428 429 file = open('src/com/example/android/leanback/VideoActivity.java', 'r') 430 outfile = open('src/com/example/android/leanback/VideoSupportActivity.java', 'w') 431 write_java_head(outfile, "OnboardingDemoFragment") 432 for line in file: 433 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 434 line = line.replace('import android.app.Activity', 'import android.support.v4.app.FragmentActivity') 435 line = line.replace('VideoActivity', 'VideoSupportActivity') 436 line = line.replace('extends Activity', 'extends FragmentActivity') 437 line = line.replace('getFragmentManager()', 'getSupportFragmentManager()') 438 line = line.replace('SampleVideoFragment', 'SampleVideoSupportFragment') 439 outfile.write(line) 440 file.close() 441 outfile.close() 442