1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.example.android.support.transition.widget;
18
19import android.os.Bundle;
20import android.view.Menu;
21import android.view.MenuItem;
22import android.view.ViewGroup;
23import android.widget.FrameLayout;
24
25import androidx.transition.Scene;
26import androidx.transition.TransitionManager;
27
28import com.example.android.support.transition.R;
29
30abstract class SceneUsageBase extends TransitionUsageBase {
31
32    private Scene[] mScenes;
33
34    private int mCurrentScene;
35
36    abstract Scene[] setUpScenes(ViewGroup root);
37
38    abstract void go(Scene scene);
39
40    @Override
41    protected void onCreate(Bundle savedInstanceState) {
42        super.onCreate(savedInstanceState);
43
44        FrameLayout root = findViewById(R.id.root);
45        mScenes = setUpScenes(root);
46        TransitionManager.go(mScenes[0]);
47    }
48
49    @Override
50    int getLayoutResId() {
51        return R.layout.scene_usage;
52    }
53
54    @Override
55    public boolean onCreateOptionsMenu(Menu menu) {
56        getMenuInflater().inflate(R.menu.basic_usage, menu);
57        return true;
58    }
59
60    @Override
61    public boolean onOptionsItemSelected(MenuItem item) {
62        switch (item.getItemId()) {
63            case R.id.action_toggle:
64                mCurrentScene = (mCurrentScene + 1) % mScenes.length;
65                go(mScenes[mCurrentScene]);
66                return true;
67        }
68        return false;
69    }
70
71}
72