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("// CHECKSTYLE:OFF Generated code\n") 23 tofile.write("/* This file is auto-generated from {}.java. DO NOT MODIFY. */\n\n".format(name)) 24 25def 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 28file = open('src/com/example/android/leanback/GuidedStepActivity.java', 'r') 29outfile = open('src/com/example/android/leanback/GuidedStepSupportActivity.java', 'w') 30write_java_head(outfile, "GuidedStepActivity") 31for 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) 38file.close() 39outfile.close() 40 41file = open('src/com/example/android/leanback/GuidedStepHalfScreenActivity.java', 'r') 42outfile = open('src/com/example/android/leanback/GuidedStepSupportHalfScreenActivity.java', 'w') 43write_java_head(outfile, "GuidedStepHalfScreenActivity") 44for 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) 52file.close() 53outfile.close() 54 55file = open('src/com/example/android/leanback/BrowseFragment.java', 'r') 56outfile = open('src/com/example/android/leanback/BrowseSupportFragment.java', 'w') 57write_java_head(outfile, "BrowseFragment") 58for 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) 72file.close() 73outfile.close() 74 75file = open('src/com/example/android/leanback/BrowseActivity.java', 'r') 76outfile = open('src/com/example/android/leanback/BrowseSupportActivity.java', 'w') 77write_java_head(outfile, "BrowseActivity") 78for 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) 84file.close() 85outfile.close() 86 87file = open('res/layout/browse.xml', 'r') 88outfile = open('res/layout/browse_support.xml', 'w') 89for 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) 93file.close() 94outfile.close() 95 96 97file = open('src/com/example/android/leanback/DetailsFragment.java', 'r') 98outfile = open('src/com/example/android/leanback/DetailsSupportFragment.java', 'w') 99write_java_head(outfile, "DetailsFragment") 100for 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) 108file.close() 109outfile.close() 110 111file = open('src/com/example/android/leanback/NewDetailsFragment.java', 'r') 112outfile = open('src/com/example/android/leanback/NewDetailsSupportFragment.java', 'w') 113write_java_head(outfile, "NewDetailsFragment") 114for 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) 127file.close() 128outfile.close() 129 130file = open('src/com/example/android/leanback/DetailsActivity.java', 'r') 131outfile = open('src/com/example/android/leanback/DetailsSupportActivity.java', 'w') 132write_java_head(outfile, "DetailsActivity") 133for 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) 141file.close() 142outfile.close() 143 144file = open('src/com/example/android/leanback/SearchDetailsActivity.java', 'r') 145outfile = open('src/com/example/android/leanback/SearchDetailsSupportActivity.java', 'w') 146write_java_head(outfile, "SearchDetailsActivity") 147for line in file: 148 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 149 outfile.write(line) 150file.close() 151outfile.close() 152 153 154file = open('src/com/example/android/leanback/SearchFragment.java', 'r') 155outfile = open('src/com/example/android/leanback/SearchSupportFragment.java', 'w') 156write_java_head(outfile, "SearchFragment") 157for line in file: 158 line = line.replace('SearchFragment', 'SearchSupportFragment') 159 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 160 outfile.write(line) 161file.close() 162outfile.close() 163 164file = open('src/com/example/android/leanback/SearchActivity.java', 'r') 165outfile = open('src/com/example/android/leanback/SearchSupportActivity.java', 'w') 166write_java_head(outfile, "SearchActivity") 167for 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) 175file.close() 176outfile.close() 177 178file = open('res/layout/search.xml', 'r') 179outfile = open('res/layout/search_support.xml', 'w') 180for 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) 184file.close() 185outfile.close() 186 187file = open('src/com/example/android/leanback/VerticalGridFragment.java', 'r') 188outfile = open('src/com/example/android/leanback/VerticalGridSupportFragment.java', 'w') 189write_java_head(outfile, "VerticalGridFragment") 190for 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) 195file.close() 196outfile.close() 197 198file = open('src/com/example/android/leanback/VerticalGridActivity.java', 'r') 199outfile = open('src/com/example/android/leanback/VerticalGridSupportActivity.java', 'w') 200write_java_head(outfile, "VerticalGridActivity") 201for 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) 209file.close() 210outfile.close() 211 212file = open('res/layout/vertical_grid.xml', 'r') 213outfile = open('res/layout/vertical_grid_support.xml', 'w') 214for 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) 218file.close() 219outfile.close() 220 221 222file = open('src/com/example/android/leanback/ErrorFragment.java', 'r') 223outfile = open('src/com/example/android/leanback/ErrorSupportFragment.java', 'w') 224write_java_head(outfile, "ErrorFragment") 225for line in file: 226 line = line.replace('ErrorFragment', 'ErrorSupportFragment') 227 outfile.write(line) 228file.close() 229outfile.close() 230 231file = open('src/com/example/android/leanback/BrowseErrorActivity.java', 'r') 232outfile = open('src/com/example/android/leanback/BrowseErrorSupportActivity.java', 'w') 233write_java_head(outfile, "BrowseErrorActivity") 234for 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) 244file.close() 245outfile.close() 246 247file = open('src/com/example/android/leanback/RowsFragment.java', 'r') 248outfile = open('src/com/example/android/leanback/RowsSupportFragment.java', 'w') 249write_java_head(outfile, "RowsFragment") 250for line in file: 251 line = line.replace('RowsFragment', 'RowsSupportFragment') 252 line = line.replace('DetailsActivity', 'DetailsSupportActivity') 253 outfile.write(line) 254file.close() 255outfile.close() 256 257file = open('src/com/example/android/leanback/RowsActivity.java', 'r') 258outfile = open('src/com/example/android/leanback/RowsSupportActivity.java', 'w') 259write_java_head(outfile, "RowsActivity") 260for 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) 269file.close() 270outfile.close() 271 272file = open('res/layout/rows.xml', 'r') 273outfile = open('res/layout/rows_support.xml', 'w') 274for 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) 278file.close() 279outfile.close() 280 281file = open('src/com/example/android/leanback/PlaybackFragment.java', 'r') 282outfile = open('src/com/example/android/leanback/PlaybackSupportFragment.java', 'w') 283write_java_head(outfile, "PlaybackFragment") 284for line in file: 285 line = line.replace('PlaybackFragment', 'PlaybackSupportFragment') 286 line = line.replace('PlaybackActivity', 'PlaybackSupportActivity') 287 outfile.write(line) 288file.close() 289outfile.close() 290 291file = open('src/com/example/android/leanback/PlaybackActivity.java', 'r') 292outfile = open('src/com/example/android/leanback/PlaybackSupportActivity.java', 'w') 293write_java_head(outfile, "PlaybackActivity") 294for 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) 300file.close() 301outfile.close() 302 303file = open('res/layout/playback_activity.xml', 'r') 304outfile = open('res/layout/playback_activity_support.xml', 'w') 305for 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) 309file.close() 310outfile.close() 311 312file = open('src/com/example/android/leanback/PlaybackTransportControlFragment.java', 'r') 313outfile = open('src/com/example/android/leanback/PlaybackTransportControlSupportFragment.java', 'w') 314write_java_head(outfile, "PlaybackTransportControlFragment") 315for 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) 320file.close() 321outfile.close() 322 323file = open('src/com/example/android/leanback/PlaybackTransportControlActivity.java', 'r') 324outfile = open('src/com/example/android/leanback/PlaybackTransportControlSupportActivity.java', 'w') 325write_java_head(outfile, "PlaybackTransportControlActivity") 326for 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) 332file.close() 333outfile.close() 334 335file = open('res/layout/playback_transportcontrol_activity.xml', 'r') 336outfile = open('res/layout/playback_transportcontrol_activity_support.xml', 'w') 337for 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) 341file.close() 342outfile.close() 343 344 345 346file = open('src/com/example/android/leanback/PlaybackOverlayFragment.java', 'r') 347outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportFragment.java', 'w') 348write_java_head(outfile, "PlaybackOverlayFragment") 349for 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) 354file.close() 355outfile.close() 356 357 358file = open('src/com/example/android/leanback/PlaybackControlHelper.java', 'r') 359outfile = open('src/com/example/android/leanback/PlaybackControlSupportHelper.java', 'w') 360write_java_head(outfile, "PlaybackControlHelper") 361for 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) 366file.close() 367outfile.close() 368 369file = open('src/com/example/android/leanback/PlaybackOverlayActivity.java', 'r') 370outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportActivity.java', 'w') 371write_java_head(outfile, "PlaybackOverlayActivity") 372for 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) 378file.close() 379outfile.close() 380 381file = open('res/layout/playback_controls.xml', 'r') 382outfile = open('res/layout/playback_controls_support.xml', 'w') 383for 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) 387file.close() 388outfile.close() 389 390file = open('src/com/example/android/leanback/OnboardingActivity.java', 'r') 391outfile = open('src/com/example/android/leanback/OnboardingSupportActivity.java', 'w') 392write_java_head(outfile, "OnboardingActivity") 393for 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) 401file.close() 402outfile.close() 403 404file = open('src/com/example/android/leanback/OnboardingDemoFragment.java', 'r') 405outfile = open('src/com/example/android/leanback/OnboardingDemoSupportFragment.java', 'w') 406write_java_head(outfile, "OnboardingDemoFragment") 407for 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) 414file.close() 415outfile.close() 416 417file = open('src/com/example/android/leanback/SampleVideoFragment.java', 'r') 418outfile = open('src/com/example/android/leanback/SampleVideoSupportFragment.java', 'w') 419write_java_head(outfile, "OnboardingDemoFragment") 420for 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) 426file.close() 427outfile.close() 428 429file = open('src/com/example/android/leanback/VideoActivity.java', 'r') 430outfile = open('src/com/example/android/leanback/VideoSupportActivity.java', 'w') 431write_java_head(outfile, "OnboardingDemoFragment") 432for 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) 440file.close() 441outfile.close() 442