• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {}SupportFragment to {}Fragment".format(w, w)
33
34    file = open('java/android/support/v17/leanback/app/{}SupportFragment.java'.format(w), 'r')
35    outfile = open('java/android/support/v17/leanback/app/{}Fragment.java'.format(w), 'w')
36
37    outfile.write("// CHECKSTYLE:OFF Generated code\n")
38    outfile.write("/* This file is auto-generated from {}SupportFragment.java.  DO NOT MODIFY. */\n\n".format(w))
39
40    for line in file:
41        for w in cls:
42            line = line.replace('{}SupportFragment'.format(w), '{}Fragment'.format(w))
43        line = line.replace('androidx.fragment.app.FragmentActivity', 'android.app.Activity')
44        line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
45        line = line.replace('FragmentActivity getActivity()', 'Activity 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 {}SupportFrgamentTestBase to {}FragmentTestBase".format(w, w)
56
57    file = open('java/android/support/v17/leanback/app/{}SupportFragmentTestBase.java'.format(w), 'r')
58    outfile = open('java/android/support/v17/leanback/app/{}FragmentTestBase.java'.format(w), 'w')
59
60    outfile.write("// CHECKSTYLE:OFF Generated code\n")
61    outfile.write("/* This file is auto-generated from {}SupportFrgamentTestBase.java.  DO NOT MODIFY. */\n\n".format(w))
62
63    for line in file:
64        for w in cls:
65            line = line.replace('{}SupportFragment'.format(w), '{}Fragment'.format(w))
66        for w in testcls:
67            line = line.replace('{}SupportFragmentTestBase'.format(w), '{}FragmentTestBase'.format(w))
68            line = line.replace('{}SupportFragmentTestActivity'.format(w), '{}FragmentTestActivity'.format(w))
69            line = line.replace('{}TestSupportFragment'.format(w), '{}TestFragment'.format(w))
70        line = line.replace('androidx.fragment.app.FragmentActivity', 'android.app.Activity')
71        line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
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 {}SupporFrgamentTest to {}tFragmentTest".format(w, w)
82
83    file = open('java/android/support/v17/leanback/app/{}SupportFragmentTest.java'.format(w), 'r')
84    outfile = open('java/android/support/v17/leanback/app/{}FragmentTest.java'.format(w), 'w')
85
86    outfile.write("// CHECKSTYLE:OFF Generated code\n")
87    outfile.write("/* This file is auto-generated from {}SupportFragmentTest.java.  DO NOT MODIFY. */\n\n".format(w))
88
89    for line in file:
90        for w in cls:
91            line = line.replace('{}SupportFragment'.format(w), '{}Fragment'.format(w))
92        for w in testcls:
93            line = line.replace('SingleSupportFragmentTestBase', 'SingleFragmentTestBase')
94            line = line.replace('SingleSupportFragmentTestActivity', 'SingleFragmentTestActivity')
95            line = line.replace('{}SupportFragmentTestBase'.format(w), '{}FragmentTestBase'.format(w))
96            line = line.replace('{}SupportFragmentTest'.format(w), '{}FragmentTest'.format(w))
97            line = line.replace('{}SupportFragmentTestActivity'.format(w), '{}FragmentTestActivity'.format(w))
98            line = line.replace('{}TestSupportFragment'.format(w), '{}TestFragment'.format(w))
99        line = line.replace('androidx.fragment.app.FragmentActivity', 'android.app.Activity')
100        line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
101	line = line.replace('extends FragmentActivity', 'extends Activity')
102	line = line.replace('Activity.this.getSupportFragmentManager', 'Activity.this.getFragmentManager')
103	line = line.replace('tivity.getSupportFragmentManager', 'tivity.getFragmentManager')
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 {}SupportFragmentTestActivity to {}FragmentTestActivity".format(w, w)
114    file = open('java/android/support/v17/leanback/app/{}SupportFragmentTestActivity.java'.format(w), 'r')
115    outfile = open('java/android/support/v17/leanback/app/{}FragmentTestActivity.java'.format(w), 'w')
116    outfile.write("// CHECKSTYLE:OFF Generated code\n")
117    outfile.write("/* This file is auto-generated from {}SupportFragmentTestActivity.java.  DO NOT MODIFY. */\n\n".format(w))
118    for line in file:
119        line = line.replace('{}TestSupportFragment'.format(w), '{}TestFragment'.format(w))
120        line = line.replace('{}SupportFragmentTestActivity'.format(w), '{}FragmentTestActivity'.format(w))
121        line = line.replace('androidx.fragment.app.FragmentActivity', 'android.app.Activity')
122        line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
123        line = line.replace('extends FragmentActivity', 'extends Activity')
124        line = line.replace('getSupportFragmentManager', 'getFragmentManager')
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