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