Home | History | Annotate | Download | only in SupportLeanbackDemos
      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("/* This file is auto-generated from {}.java.  DO NOT MODIFY. */\n\n".format(name))
     23 
     24 def 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 
     27 file = open('src/com/example/android/leanback/GuidedStepActivity.java', 'r')
     28 outfile = open('src/com/example/android/leanback/GuidedStepSupportActivity.java', 'w')
     29 write_java_head(outfile, "GuidedStepActivity")
     30 for 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)
     37 file.close()
     38 outfile.close()
     39 
     40 file = open('src/com/example/android/leanback/GuidedStepHalfScreenActivity.java', 'r')
     41 outfile = open('src/com/example/android/leanback/GuidedStepSupportHalfScreenActivity.java', 'w')
     42 write_java_head(outfile, "GuidedStepHalfScreenActivity")
     43 for 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)
     51 file.close()
     52 outfile.close()
     53 
     54 file = open('src/com/example/android/leanback/BrowseFragment.java', 'r')
     55 outfile = open('src/com/example/android/leanback/BrowseSupportFragment.java', 'w')
     56 write_java_head(outfile, "BrowseFragment")
     57 for 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)
     71 file.close()
     72 outfile.close()
     73 
     74 file = open('src/com/example/android/leanback/BrowseActivity.java', 'r')
     75 outfile = open('src/com/example/android/leanback/BrowseSupportActivity.java', 'w')
     76 write_java_head(outfile, "BrowseActivity")
     77 for 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)
     83 file.close()
     84 outfile.close()
     85 
     86 file = open('res/layout/browse.xml', 'r')
     87 outfile = open('res/layout/browse_support.xml', 'w')
     88 for 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)
     92 file.close()
     93 outfile.close()
     94 
     95 
     96 file = open('src/com/example/android/leanback/DetailsFragment.java', 'r')
     97 outfile = open('src/com/example/android/leanback/DetailsSupportFragment.java', 'w')
     98 write_java_head(outfile, "DetailsFragment")
     99 for 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)
    107 file.close()
    108 outfile.close()
    109 
    110 file = open('src/com/example/android/leanback/NewDetailsFragment.java', 'r')
    111 outfile = open('src/com/example/android/leanback/NewDetailsSupportFragment.java', 'w')
    112 write_java_head(outfile, "NewDetailsFragment")
    113 for 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)
    121 file.close()
    122 outfile.close()
    123 
    124 file = open('src/com/example/android/leanback/DetailsActivity.java', 'r')
    125 outfile = open('src/com/example/android/leanback/DetailsSupportActivity.java', 'w')
    126 write_java_head(outfile, "DetailsActivity")
    127 for 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)
    137 file.close()
    138 outfile.close()
    139 
    140 file = open('res/layout/details.xml', 'r')
    141 outfile = open('res/layout/details_support.xml', 'w')
    142 for 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)
    146 file.close()
    147 outfile.close()
    148 
    149 
    150 file = open('res/layout/legacy_details.xml', 'r')
    151 outfile = open('res/layout/legacy_details_support.xml', 'w')
    152 for 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)
    156 file.close()
    157 outfile.close()
    158 
    159 
    160 file = open('src/com/example/android/leanback/SearchDetailsActivity.java', 'r')
    161 outfile = open('src/com/example/android/leanback/SearchDetailsSupportActivity.java', 'w')
    162 write_java_head(outfile, "SearchDetailsActivity")
    163 for line in file:
    164     line = line.replace('DetailsActivity', 'DetailsSupportActivity')
    165     outfile.write(line)
    166 file.close()
    167 outfile.close()
    168 
    169 
    170 file = open('src/com/example/android/leanback/SearchFragment.java', 'r')
    171 outfile = open('src/com/example/android/leanback/SearchSupportFragment.java', 'w')
    172 write_java_head(outfile, "SearchFragment")
    173 for line in file:
    174     line = line.replace('SearchFragment', 'SearchSupportFragment')
    175     line = line.replace('DetailsActivity', 'DetailsSupportActivity')
    176     outfile.write(line)
    177 file.close()
    178 outfile.close()
    179 
    180 file = open('src/com/example/android/leanback/SearchActivity.java', 'r')
    181 outfile = open('src/com/example/android/leanback/SearchSupportActivity.java', 'w')
    182 write_java_head(outfile, "SearchActivity")
    183 for 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)
    191 file.close()
    192 outfile.close()
    193 
    194 file = open('res/layout/search.xml', 'r')
    195 outfile = open('res/layout/search_support.xml', 'w')
    196 for 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)
    200 file.close()
    201 outfile.close()
    202 
    203 file = open('src/com/example/android/leanback/VerticalGridFragment.java', 'r')
    204 outfile = open('src/com/example/android/leanback/VerticalGridSupportFragment.java', 'w')
    205 outfile.write("/* This file is auto-generated from VerticalGridFragment.  DO NOT MODIFY. */\n\n")
    206 for 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)
    211 file.close()
    212 outfile.close()
    213 
    214 file = open('src/com/example/android/leanback/VerticalGridActivity.java', 'r')
    215 outfile = open('src/com/example/android/leanback/VerticalGridSupportActivity.java', 'w')
    216 write_java_head(outfile, "VerticalGridActivity")
    217 for 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)
    225 file.close()
    226 outfile.close()
    227 
    228 file = open('res/layout/vertical_grid.xml', 'r')
    229 outfile = open('res/layout/vertical_grid_support.xml', 'w')
    230 for 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)
    234 file.close()
    235 outfile.close()
    236 
    237 
    238 file = open('src/com/example/android/leanback/ErrorFragment.java', 'r')
    239 outfile = open('src/com/example/android/leanback/ErrorSupportFragment.java', 'w')
    240 write_java_head(outfile, "ErrorFragment")
    241 for line in file:
    242     line = line.replace('ErrorFragment', 'ErrorSupportFragment')
    243     outfile.write(line)
    244 file.close()
    245 outfile.close()
    246 
    247 file = open('src/com/example/android/leanback/BrowseErrorActivity.java', 'r')
    248 outfile = open('src/com/example/android/leanback/BrowseErrorSupportActivity.java', 'w')
    249 write_java_head(outfile, "BrowseErrorActivity")
    250 for 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)
    260 file.close()
    261 outfile.close()
    262 
    263 file = open('src/com/example/android/leanback/RowsFragment.java', 'r')
    264 outfile = open('src/com/example/android/leanback/RowsSupportFragment.java', 'w')
    265 write_java_head(outfile, "RowsFragment")
    266 for line in file:
    267     line = line.replace('RowsFragment', 'RowsSupportFragment')
    268     line = line.replace('DetailsActivity', 'DetailsSupportActivity')
    269     outfile.write(line)
    270 file.close()
    271 outfile.close()
    272 
    273 file = open('src/com/example/android/leanback/RowsActivity.java', 'r')
    274 outfile = open('src/com/example/android/leanback/RowsSupportActivity.java', 'w')
    275 write_java_head(outfile, "RowsActivity")
    276 for 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)
    285 file.close()
    286 outfile.close()
    287 
    288 file = open('res/layout/rows.xml', 'r')
    289 outfile = open('res/layout/rows_support.xml', 'w')
    290 for 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)
    294 file.close()
    295 outfile.close()
    296 
    297 
    298 file = open('src/com/example/android/leanback/PlaybackOverlayFragment.java', 'r')
    299 outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportFragment.java', 'w')
    300 write_java_head(outfile, "PlaybackOverlayFragment")
    301 for 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)
    306 file.close()
    307 outfile.close()
    308 
    309 file = open('src/com/example/android/leanback/PlaybackControlHelper.java', 'r')
    310 outfile = open('src/com/example/android/leanback/PlaybackControlSupportHelper.java', 'w')
    311 write_java_head(outfile, "PlaybackControlHelper")
    312 for 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)
    317 file.close()
    318 outfile.close()
    319 
    320 file = open('src/com/example/android/leanback/PlaybackOverlayActivity.java', 'r')
    321 outfile = open('src/com/example/android/leanback/PlaybackOverlaySupportActivity.java', 'w')
    322 write_java_head(outfile, "PlaybackOverlayActivity")
    323 for 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)
    329 file.close()
    330 outfile.close()
    331 
    332 file = open('res/layout/playback_controls.xml', 'r')
    333 outfile = open('res/layout/playback_controls_support.xml', 'w')
    334 for 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)
    338 file.close()
    339 outfile.close()
    340 
    341 file = open('src/com/example/android/leanback/OnboardingActivity.java', 'r')
    342 outfile = open('src/com/example/android/leanback/OnboardingSupportActivity.java', 'w')
    343 write_java_head(outfile, "OnboardingActivity")
    344 for 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)
    352 file.close()
    353 outfile.close()
    354 
    355 file = open('src/com/example/android/leanback/OnboardingDemoFragment.java', 'r')
    356 outfile = open('src/com/example/android/leanback/OnboardingDemoSupportFragment.java', 'w')
    357 write_java_head(outfile, "OnboardingDemoFragment")
    358 for 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)
    365 file.close()
    366 outfile.close()
    367