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
22files = ['BrowseTest']
23
24cls = ['BrowseTest', 'Background', 'Base', 'BaseRow', 'Browse', 'Details', 'Error', 'Headers',
25      'PlaybackOverlay', 'Rows', 'Search', 'VerticalGrid', 'Branded']
26
27for w in files:
28    print "copy {}Fragment to {}SupportFragment".format(w, w)
29
30    file = open('src/android/support/v17/leanback/app/{}Fragment.java'.format(w), 'r')
31    outfile = open('src/android/support/v17/leanback/app/{}SupportFragment.java'.format(w), 'w')
32
33    outfile.write("/* This file is auto-generated from {}Fragment.java.  DO NOT MODIFY. */\n\n".format(w))
34
35    for line in file:
36        for w in cls:
37            line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w))
38        line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
39        line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
40        outfile.write(line)
41    file.close()
42    outfile.close()
43
44testcls = ['Browse']
45
46for w in testcls:
47    print "copy {}FrgamentTest to {}SupportFragmentTest".format(w, w)
48
49    file = open('src/android/support/v17/leanback/app/{}FragmentTest.java'.format(w), 'r')
50    outfile = open('src/android/support/v17/leanback/app/{}SupportFragmentTest.java'.format(w), 'w')
51
52    outfile.write("/* This file is auto-generated from {}FrgamentTest.java.  DO NOT MODIFY. */\n\n".format(w))
53
54    for line in file:
55        for w in cls:
56            line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w))
57        for w in testcls:
58            line = line.replace('{}FragmentTest'.format(w), '{}SupportFragmentTest'.format(w))
59            line = line.replace('{}FragmentTestActivity'.format(w), '{}SupportFragmentTestActivity'.format(w))
60            line = line.replace('{}TestFragment'.format(w), '{}TestSupportFragment'.format(w))
61        outfile.write(line)
62    file.close()
63    outfile.close()
64
65
66print "copy BrowseFragmentTestActivity to BrowseSupportFragmentTestActivity"
67file = open('src/android/support/v17/leanback/app/BrowseFragmentTestActivity.java', 'r')
68outfile = open('src/android/support/v17/leanback/app/BrowseSupportFragmentTestActivity.java', 'w')
69outfile.write("/* This file is auto-generated from BrowseFragmentTestActivity.java.  DO NOT MODIFY. */\n\n")
70for line in file:
71    line = line.replace('BrowseTestFragment', 'BrowseTestSupportFragment')
72    line = line.replace('BrowseFragmentTestActivity', 'BrowseSupportFragmentTestActivity')
73    line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
74    line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
75    line = line.replace('extends Activity', 'extends FragmentActivity')
76    line = line.replace('getFragmentManager', 'getSupportFragmentManager')
77    outfile.write(line)
78file.close()
79outfile.close()
80
81