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
19
20print "Generate v4 fragment related code for leanback"
21
22####### generate XXXTestFragment classes #######
23
24files = ['BrowseTest', 'GuidedStepTest', 'PlaybackTest', 'DetailsTest']
25
26cls = ['BrowseTest', 'Background', 'Base', 'BaseRow', 'Browse', 'Details', 'Error', 'Headers',
27      'PlaybackOverlay', 'Rows', 'Search', 'VerticalGrid', 'Branded',
28      'GuidedStepTest', 'GuidedStep', 'RowsTest', 'PlaybackTest', 'Playback', 'Video',
29      'DetailsTest']
30
31for w in files:
32    print "copy {}Fragment to {}SupportFragment".format(w, w)
33
34    file = open('java/android/support/v17/leanback/app/{}Fragment.java'.format(w), 'r')
35    outfile = open('java/android/support/v17/leanback/app/{}SupportFragment.java'.format(w), 'w')
36
37    outfile.write("// CHECKSTYLE:OFF Generated code\n")
38    outfile.write("/* This file is auto-generated from {}Fragment.java.  DO NOT MODIFY. */\n\n".format(w))
39
40    for line in file:
41        for w in cls:
42            line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w))
43        line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
44        line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
45        line = line.replace('Activity getActivity()', 'FragmentActivity getActivity()')
46        outfile.write(line)
47    file.close()
48    outfile.close()
49
50####### generate XXXFragmentTestBase classes #######
51
52testcls = ['GuidedStep', 'Single']
53
54for w in testcls:
55    print "copy {}FrgamentTestBase to {}SupportFragmentTestBase".format(w, w)
56
57    file = open('java/android/support/v17/leanback/app/{}FragmentTestBase.java'.format(w), 'r')
58    outfile = open('java/android/support/v17/leanback/app/{}SupportFragmentTestBase.java'.format(w), 'w')
59
60    outfile.write("// CHECKSTYLE:OFF Generated code\n")
61    outfile.write("/* This file is auto-generated from {}FrgamentTestBase.java.  DO NOT MODIFY. */\n\n".format(w))
62
63    for line in file:
64        for w in cls:
65            line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w))
66        for w in testcls:
67            line = line.replace('{}FragmentTestBase'.format(w), '{}SupportFragmentTestBase'.format(w))
68            line = line.replace('{}FragmentTestActivity'.format(w), '{}SupportFragmentTestActivity'.format(w))
69            line = line.replace('{}TestFragment'.format(w), '{}TestSupportFragment'.format(w))
70        line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
71        line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
72        outfile.write(line)
73    file.close()
74    outfile.close()
75
76####### generate XXXFragmentTest classes #######
77
78testcls = ['Browse', 'GuidedStep', 'VerticalGrid', 'Playback', 'Video', 'Details', 'Rows', 'Headers']
79
80for w in testcls:
81    print "copy {}FrgamentTest to {}SupportFragmentTest".format(w, w)
82
83    file = open('java/android/support/v17/leanback/app/{}FragmentTest.java'.format(w), 'r')
84    outfile = open('java/android/support/v17/leanback/app/{}SupportFragmentTest.java'.format(w), 'w')
85
86    outfile.write("// CHECKSTYLE:OFF Generated code\n")
87    outfile.write("/* This file is auto-generated from {}FragmentTest.java.  DO NOT MODIFY. */\n\n".format(w))
88
89    for line in file:
90        for w in cls:
91            line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w))
92        for w in testcls:
93            line = line.replace('SingleFragmentTestBase', 'SingleSupportFragmentTestBase')
94            line = line.replace('SingleFragmentTestActivity', 'SingleSupportFragmentTestActivity')
95            line = line.replace('{}FragmentTestBase'.format(w), '{}SupportFragmentTestBase'.format(w))
96            line = line.replace('{}FragmentTest'.format(w), '{}SupportFragmentTest'.format(w))
97            line = line.replace('{}FragmentTestActivity'.format(w), '{}SupportFragmentTestActivity'.format(w))
98            line = line.replace('{}TestFragment'.format(w), '{}TestSupportFragment'.format(w))
99        line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
100        line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
101	line = line.replace('extends Activity', 'extends FragmentActivity')
102	line = line.replace('Activity.this.getFragmentManager', 'Activity.this.getSupportFragmentManager')
103	line = line.replace('tivity.getFragmentManager', 'tivity.getSupportFragmentManager')
104        outfile.write(line)
105    file.close()
106    outfile.close()
107
108
109####### generate XXXTestActivity classes #######
110testcls = ['Browse', 'GuidedStep', 'Single']
111
112for w in testcls:
113    print "copy {}FragmentTestActivity to {}SupportFragmentTestActivity".format(w, w)
114    file = open('java/android/support/v17/leanback/app/{}FragmentTestActivity.java'.format(w), 'r')
115    outfile = open('java/android/support/v17/leanback/app/{}SupportFragmentTestActivity.java'.format(w), 'w')
116    outfile.write("// CHECKSTYLE:OFF Generated code\n")
117    outfile.write("/* This file is auto-generated from {}FragmentTestActivity.java.  DO NOT MODIFY. */\n\n".format(w))
118    for line in file:
119        line = line.replace('{}TestFragment'.format(w), '{}TestSupportFragment'.format(w))
120        line = line.replace('{}FragmentTestActivity'.format(w), '{}SupportFragmentTestActivity'.format(w))
121        line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
122        line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
123        line = line.replace('extends Activity', 'extends FragmentActivity')
124        line = line.replace('getFragmentManager', 'getSupportFragmentManager')
125        outfile.write(line)
126    file.close()
127    outfile.close()
128
129####### generate Float parallax test #######
130
131print "copy ParallaxIntEffectTest to ParallaxFloatEffectTest"
132file = open('java/android/support/v17/leanback/widget/ParallaxIntEffectTest.java', 'r')
133outfile = open('java/android/support/v17/leanback/widget/ParallaxFloatEffectTest.java', 'w')
134outfile.write("// CHECKSTYLE:OFF Generated code\n")
135outfile.write("/* This file is auto-generated from ParallaxIntEffectTest.java.  DO NOT MODIFY. */\n\n")
136for line in file:
137    line = line.replace('IntEffect', 'FloatEffect')
138    line = line.replace('IntParallax', 'FloatParallax')
139    line = line.replace('IntProperty', 'FloatProperty')
140    line = line.replace('intValue()', 'floatValue()')
141    line = line.replace('int screenMax', 'float screenMax')
142    line = line.replace('assertEquals((int)', 'assertFloatEquals((float)')
143    line = line.replace('(int)', '(float)')
144    line = line.replace('int[', 'float[')
145    line = line.replace('Integer', 'Float');
146    outfile.write(line)
147file.close()
148outfile.close()
149
150
151print "copy ParallaxIntTest to ParallaxFloatTest"
152file = open('java/android/support/v17/leanback/widget/ParallaxIntTest.java', 'r')
153outfile = open('java/android/support/v17/leanback/widget/ParallaxFloatTest.java', 'w')
154outfile.write("// CHECKSTYLE:OFF Generated code\n")
155outfile.write("/* This file is auto-generated from ParallaxIntTest.java.  DO NOT MODIFY. */\n\n")
156for line in file:
157    line = line.replace('ParallaxIntTest', 'ParallaxFloatTest')
158    line = line.replace('IntParallax', 'FloatParallax')
159    line = line.replace('IntProperty', 'FloatProperty')
160    line = line.replace('verifyIntProperties', 'verifyFloatProperties')
161    line = line.replace('intValue()', 'floatValue()')
162    line = line.replace('int screenMax', 'float screenMax')
163    line = line.replace('assertEquals((int)', 'assertFloatEquals((float)')
164    line = line.replace('(int)', '(float)')
165    outfile.write(line)
166file.close()
167outfile.close()
168
169####### generate glue support test #######
170
171print "copy PlaybackControlGlueTest to PlaybackControlSupportGlueTest"
172file = open('java/android/support/v17/leanback/app/PlaybackControlGlueTest.java', 'r')
173outfile = open('java/android/support/v17/leanback/app/PlaybackControlSupportGlueTest.java', 'w')
174outfile.write("// CHECKSTYLE:OFF Generated code\n")
175outfile.write("/* This file is auto-generated from PlaybackControlGlueTest.java.  DO NOT MODIFY. */\n\n")
176for line in file:
177    line = line.replace('PlaybackControlGlue', 'PlaybackControlSupportGlue')
178    line = line.replace('PlaybackOverlayFragment', 'PlaybackOverlaySupportFragment')
179    line = line.replace('PlaybackGlueHostOld', 'PlaybackSupportGlueHostOld')
180    outfile.write(line)
181file.close()
182outfile.close()
183
184