generatev4.py revision 4702556bfd15c9819a7b2af759aee0f719cd631f
1#!/usr/bin/python
2
3# Copyright (C) 2014 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
22cls = ['Base', 'BaseRow', 'Browse', 'Details', 'Error', 'Headers',
23      'PlaybackOverlay', 'Playback', 'Rows', 'Search', 'VerticalGrid', 'Branded',
24      'GuidedStep', 'Onboarding', 'Video']
25
26for w in cls:
27    print "copy {}Fragment to {}SupportFragment".format(w, w)
28
29    file = open('src/android/support/v17/leanback/app/{}Fragment.java'.format(w), 'r')
30    outfile = open('src/android/support/v17/leanback/app/{}SupportFragment.java'.format(w), 'w')
31
32    outfile.write("/* This file is auto-generated from {}Fragment.java.  DO NOT MODIFY. */\n\n".format(w))
33
34    for line in file:
35        line = line.replace('IS_FRAMEWORK_FRAGMENT = true', 'IS_FRAMEWORK_FRAGMENT = false');
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        line = line.replace('activity.getFragmentManager()', 'activity.getSupportFragmentManager()')
41        line = line.replace('Activity activity', 'FragmentActivity activity')
42        line = line.replace('(Activity', '(FragmentActivity')
43        outfile.write(line)
44    file.close()
45    outfile.close()
46
47print "copy VideoFragmentGlueHost to VideoSupportFragmentGlueHost".format(w, w)
48file = open('src/android/support/v17/leanback/app/VideoFragmentGlueHost.java'.format(w), 'r')
49outfile = open('src/android/support/v17/leanback/app/VideoSupportFragmentGlueHost.java'.format(w), 'w')
50
51outfile.write("/* This file is auto-generated from {}VideoFragmentGlueHost.java.  DO NOT MODIFY. */\n\n".format(w))
52
53for line in file:
54    line = line.replace('IS_FRAMEWORK_FRAGMENT = true', 'IS_FRAMEWORK_FRAGMENT = false');
55    line = line.replace('VideoSupportFragmentGlueHost'.format(w), 'VideoSupportFragmentGlueHost'.format(w))
56    line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
57    line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
58    line = line.replace('activity.getFragmentManager()', 'activity.getSupportFragmentManager()')
59    line = line.replace('Activity activity', 'FragmentActivity activity')
60    line = line.replace('VideoFragment', 'VideoSupportFragment')
61    line = line.replace('PlaybackFragmentGlueHost', 'PlaybackSupportFragmentGlueHost')
62    line = line.replace('(Activity', '(FragmentActivity')
63    outfile.write(line)
64file.close()
65outfile.close()
66
67print "copy PlaybackFragmentGlueHost to PlaybackSupportFragmentGlueHost".format(w, w)
68file = open('src/android/support/v17/leanback/app/PlaybackFragmentGlueHost.java'.format(w), 'r')
69outfile = open('src/android/support/v17/leanback/app/PlaybackSupportFragmentGlueHost.java'.format(w), 'w')
70
71outfile.write("/* This file is auto-generated from {}PlaybackFragmentGlueHost.java.  DO NOT MODIFY. */\n\n".format(w))
72
73for line in file:
74    line = line.replace('IS_FRAMEWORK_FRAGMENT = true', 'IS_FRAMEWORK_FRAGMENT = false');
75    line = line.replace('VideoSupportFragmentGlueHost'.format(w), 'VideoSupportFragmentGlueHost'.format(w))
76    line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
77    line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
78    line = line.replace('activity.getFragmentManager()', 'activity.getSupportFragmentManager()')
79    line = line.replace('Activity activity', 'FragmentActivity activity')
80    line = line.replace('PlaybackFragment', 'PlaybackSupportFragment')
81    line = line.replace('PlaybackFragmentGlueHost', 'PlaybackSupportFragmentGlueHost')
82    line = line.replace('(Activity', '(FragmentActivity')
83    outfile.write(line)
84file.close()
85outfile.close()
86