• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2
3# Copyright (C) 2017 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 re
20
21print "Generate framework fragment related code for leanback"
22
23cls = ['Base', 'BaseRow', 'Browse', 'Details', 'Error', 'Headers',
24      'Playback', 'Rows', 'Search', 'VerticalGrid', 'Branded',
25      'GuidedStep', 'Onboarding', 'Video']
26
27for w in cls:
28    print "copy {}SupportFragment to {}Fragment".format(w, w)
29
30    file = open('src/android/support/v17/leanback/app/{}SupportFragment.java'.format(w), 'r')
31    content = "// CHECKSTYLE:OFF Generated code\n"
32    content = content + "/* This file is auto-generated from {}SupportFragment.java.  DO NOT MODIFY. */\n\n".format(w)
33
34    for line in file:
35        line = line.replace('IS_FRAMEWORK_FRAGMENT = false', 'IS_FRAMEWORK_FRAGMENT = true');
36        for w2 in cls:
37            line = line.replace('{}SupportFragment'.format(w2), '{}Fragment'.format(w2))
38        line = line.replace('androidx.fragment.app.FragmentActivity', 'android.app.Activity')
39        line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
40        line = line.replace('activity.getSupportFragmentManager()', 'activity.getFragmentManager()')
41        line = line.replace('FragmentActivity activity', 'Activity activity')
42        line = line.replace('(FragmentActivity', '(Activity')
43        # replace getContext() with FragmentUtil.getContext(XXXFragment.this), but dont match the case "view.getContext()"
44        line = re.sub(r'([^\.])getContext\(\)', r'\1FragmentUtil.getContext({}Fragment.this)'.format(w), line);
45        content = content + line
46    file.close()
47    # add deprecated tag to fragment class and inner classes/interfaces
48    content = re.sub(r'\*\/\n(@.*\n|)(public |abstract public |abstract |)class', '* @deprecated use {@link ' + w + 'SupportFragment}\n */\n@Deprecated\n\\1\\2class', content)
49    content = re.sub(r'\*\/\n    public (static class|interface|final static class|abstract static class)', '* @deprecated use {@link ' + w + 'SupportFragment}\n     */\n    @Deprecated\n    public \\1', content)
50    outfile = open('src/android/support/v17/leanback/app/{}Fragment.java'.format(w), 'w')
51    outfile.write(content)
52    outfile.close()
53
54
55
56print "copy VideoSupportFragmentGlueHost to VideoFragmentGlueHost"
57file = open('src/android/support/v17/leanback/app/VideoSupportFragmentGlueHost.java', 'r')
58content = "// CHECKSTYLE:OFF Generated code\n"
59content = content + "/* This file is auto-generated from VideoSupportFragmentGlueHost.java.  DO NOT MODIFY. */\n\n"
60for line in file:
61    line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
62    line = line.replace('VideoSupportFragment', 'VideoFragment')
63    line = line.replace('PlaybackSupportFragment', 'PlaybackFragment')
64    content = content + line
65file.close()
66# add deprecated tag to class
67content = re.sub(r'\*\/\npublic class', '* @deprecated use {@link VideoSupportFragmentGlueHost}\n */\n@Deprecated\npublic class', content)
68outfile = open('src/android/support/v17/leanback/app/VideoFragmentGlueHost.java', 'w')
69outfile.write(content)
70outfile.close()
71
72
73
74print "copy PlaybackSupportFragmentGlueHost to PlaybackFragmentGlueHost"
75file = open('src/android/support/v17/leanback/app/PlaybackSupportFragmentGlueHost.java', 'r')
76content = "// CHECKSTYLE:OFF Generated code\n"
77content = content + "/* This file is auto-generated from {}PlaybackSupportFragmentGlueHost.java.  DO NOT MODIFY. */\n\n"
78for line in file:
79    line = line.replace('VideoSupportFragment', 'VideoFragment')
80    line = line.replace('PlaybackSupportFragment', 'PlaybackFragment')
81    line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
82    content = content + line
83file.close()
84# add deprecated tag to class
85content = re.sub(r'\*\/\npublic class', '* @deprecated use {@link PlaybackSupportFragmentGlueHost}\n */\n@Deprecated\npublic class', content)
86outfile = open('src/android/support/v17/leanback/app/PlaybackFragmentGlueHost.java', 'w')
87outfile.write(content)
88outfile.close()
89
90
91
92print "copy DetailsSupportFragmentBackgroundController to DetailsFragmentBackgroundController"
93file = open('src/android/support/v17/leanback/app/DetailsSupportFragmentBackgroundController.java', 'r')
94content = "// CHECKSTYLE:OFF Generated code\n"
95content = content + "/* This file is auto-generated from {}DetailsSupportFragmentBackgroundController.java.  DO NOT MODIFY. */\n\n"
96for line in file:
97    line = line.replace('VideoSupportFragment', 'VideoFragment')
98    line = line.replace('DetailsSupportFragment', 'DetailsFragment')
99    line = line.replace('RowsSupportFragment', 'RowsFragment')
100    line = line.replace('androidx.fragment.app.Fragment', 'android.app.Fragment')
101    line = line.replace('mFragment.getContext()', 'FragmentUtil.getContext(mFragment)')
102    content = content + line
103file.close()
104# add deprecated tag to class
105content = re.sub(r'\*\/\npublic class', '* @deprecated use {@link DetailsSupportFragmentBackgroundController}\n */\n@Deprecated\npublic class', content)
106outfile = open('src/android/support/v17/leanback/app/DetailsFragmentBackgroundController.java', 'w')
107outfile.write(content)
108outfile.close()
109