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 17 import os 18 import sys 19 20 print "Generate v4 fragment related code for leanback" 21 22 cls = ['Background', 'Base', 'BaseRow', 'Browse', 'Details', 'Error', 'Headers', 23 'PlaybackOverlay', 'Rows', 'Search', 'VerticalGrid', 'Branded', 'GuidedStep', 'Onboarding'] 24 25 for w in cls: 26 print "copy {}Fragment to {}SupportFragment".format(w, w) 27 28 file = open('src/android/support/v17/leanback/app/{}Fragment.java'.format(w), 'r') 29 outfile = open('src/android/support/v17/leanback/app/{}SupportFragment.java'.format(w), 'w') 30 31 outfile.write("/* This file is auto-generated from {}Fragment.java. DO NOT MODIFY. */\n\n".format(w)) 32 33 for line in file: 34 line = line.replace('IS_FRAMEWORK_FRAGMENT = true', 'IS_FRAMEWORK_FRAGMENT = false'); 35 for w in cls: 36 line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w)) 37 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 38 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 39 line = line.replace('activity.getFragmentManager()', 'activity.getSupportFragmentManager()') 40 line = line.replace('Activity activity', 'FragmentActivity activity') 41 line = line.replace('(Activity', '(FragmentActivity') 42 outfile.write(line) 43 file.close() 44 outfile.close() 45 46 file = open('src/android/support/v17/leanback/app/PlaybackControlGlue.java', 'r') 47 outfile = open('src/android/support/v17/leanback/app/PlaybackControlSupportGlue.java', 'w') 48 outfile.write("/* This file is auto-generated from PlaybackControlGlue.java. DO NOT MODIFY. */\n\n") 49 for line in file: 50 line = line.replace('PlaybackControlGlue', 'PlaybackControlSupportGlue'); 51 line = line.replace('PlaybackOverlayFragment', 'PlaybackOverlaySupportFragment'); 52 outfile.write(line) 53 file.close() 54 outfile.close() 55 56