generatev4.py revision 47d21fb23abd7099f1bcfc08365ec9f946f0f6d8
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 = ['Background', 'Base', 'BaseRow', 'Browse', 'Details', 'Error', 'Headers', 23 'PlaybackOverlay', 'Rows', 'Search', 'VerticalGrid', 'Branded', 'GuidedStep'] 24 25for 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 for w in cls: 35 line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w)) 36 line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment') 37 line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity') 38 line = line.replace('activity.getFragmentManager()', 'activity.getSupportFragmentManager()') 39 line = line.replace('Activity activity', 'FragmentActivity activity') 40 line = line.replace('(Activity', '(FragmentActivity') 41 outfile.write(line) 42 file.close() 43 outfile.close() 44