1b82192579c3786a4c76e1508fd801765a929110eDake Gu#!/usr/bin/python
2b82192579c3786a4c76e1508fd801765a929110eDake Gu
3b82192579c3786a4c76e1508fd801765a929110eDake Gu# Copyright (C) 2014 The Android Open Source Project
4b82192579c3786a4c76e1508fd801765a929110eDake Gu#
5b82192579c3786a4c76e1508fd801765a929110eDake Gu# Licensed under the Apache License, Version 2.0 (the "License");
6b82192579c3786a4c76e1508fd801765a929110eDake Gu# you may not use this file except in compliance with the License.
7b82192579c3786a4c76e1508fd801765a929110eDake Gu# You may obtain a copy of the License at
8b82192579c3786a4c76e1508fd801765a929110eDake Gu#
9b82192579c3786a4c76e1508fd801765a929110eDake Gu#      http://www.apache.org/licenses/LICENSE-2.0
10b82192579c3786a4c76e1508fd801765a929110eDake Gu#
11b82192579c3786a4c76e1508fd801765a929110eDake Gu# Unless required by applicable law or agreed to in writing, software
12b82192579c3786a4c76e1508fd801765a929110eDake Gu# distributed under the License is distributed on an "AS IS" BASIS,
13b82192579c3786a4c76e1508fd801765a929110eDake Gu# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14b82192579c3786a4c76e1508fd801765a929110eDake Gu# See the License for the specific language governing permissions and
15b82192579c3786a4c76e1508fd801765a929110eDake Gu# limitations under the License.
16b82192579c3786a4c76e1508fd801765a929110eDake Gu
17b82192579c3786a4c76e1508fd801765a929110eDake Guimport os
18b82192579c3786a4c76e1508fd801765a929110eDake Guimport sys
19b82192579c3786a4c76e1508fd801765a929110eDake Gu
20b82192579c3786a4c76e1508fd801765a929110eDake Guprint "Generate v4 fragment related code for leanback"
21b82192579c3786a4c76e1508fd801765a929110eDake Gu
223f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gucls = ['Background', 'Base', 'BaseRow', 'Browse', 'Details', 'Error', 'Headers',
23bc69c4a046bdabeaa72c28fcca0ceeb72517a81fChulwoo Lee      'PlaybackOverlay', 'Rows', 'Search', 'VerticalGrid', 'Branded', 'GuidedStep', 'Onboarding']
24b82192579c3786a4c76e1508fd801765a929110eDake Gu
25b82192579c3786a4c76e1508fd801765a929110eDake Gufor w in cls:
26b82192579c3786a4c76e1508fd801765a929110eDake Gu    print "copy {}Fragment to {}SupportFragment".format(w, w)
27b82192579c3786a4c76e1508fd801765a929110eDake Gu
28b82192579c3786a4c76e1508fd801765a929110eDake Gu    file = open('src/android/support/v17/leanback/app/{}Fragment.java'.format(w), 'r')
29b82192579c3786a4c76e1508fd801765a929110eDake Gu    outfile = open('src/android/support/v17/leanback/app/{}SupportFragment.java'.format(w), 'w')
30b82192579c3786a4c76e1508fd801765a929110eDake Gu
31b82192579c3786a4c76e1508fd801765a929110eDake Gu    outfile.write("/* This file is auto-generated from {}Fragment.java.  DO NOT MODIFY. */\n\n".format(w))
32b82192579c3786a4c76e1508fd801765a929110eDake Gu
33b82192579c3786a4c76e1508fd801765a929110eDake Gu    for line in file:
34b749047cd5b6e0aa4514e5f17c053a256e20e1caDake Gu        line = line.replace('IS_FRAMEWORK_FRAGMENT = true', 'IS_FRAMEWORK_FRAGMENT = false');
35b82192579c3786a4c76e1508fd801765a929110eDake Gu        for w in cls:
36b82192579c3786a4c76e1508fd801765a929110eDake Gu            line = line.replace('{}Fragment'.format(w), '{}SupportFragment'.format(w))
37b82192579c3786a4c76e1508fd801765a929110eDake Gu        line = line.replace('android.app.Fragment', 'android.support.v4.app.Fragment')
38b82192579c3786a4c76e1508fd801765a929110eDake Gu        line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
394e9bfff0d62ddb50391fecefdf8d98d59fb21387Dake Gu        line = line.replace('activity.getFragmentManager()', 'activity.getSupportFragmentManager()')
404e9bfff0d62ddb50391fecefdf8d98d59fb21387Dake Gu        line = line.replace('Activity activity', 'FragmentActivity activity')
4147d21fb23abd7099f1bcfc08365ec9f946f0f6d8Dake Gu        line = line.replace('(Activity', '(FragmentActivity')
42b82192579c3786a4c76e1508fd801765a929110eDake Gu        outfile.write(line)
43b82192579c3786a4c76e1508fd801765a929110eDake Gu    file.close()
44b82192579c3786a4c76e1508fd801765a929110eDake Gu    outfile.close()
457f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Gu
467f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Gufile = open('src/android/support/v17/leanback/app/PlaybackControlGlue.java', 'r')
477f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Guoutfile = open('src/android/support/v17/leanback/app/PlaybackControlSupportGlue.java', 'w')
487f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Guoutfile.write("/* This file is auto-generated from PlaybackControlGlue.java.  DO NOT MODIFY. */\n\n")
497f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Gufor line in file:
507f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Gu    line = line.replace('PlaybackControlGlue', 'PlaybackControlSupportGlue');
517f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Gu    line = line.replace('PlaybackOverlayFragment', 'PlaybackOverlaySupportFragment');
527f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Gu    outfile.write(line)
537f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Gufile.close()
547f3d7b01db6056a4061a8dc52b4c6dea8b4a1881Dake Guoutfile.close()
551c3ce0fa10ec24e4edd5e5ea909b4d4357534b53susnata
56