TransitionUsageBase.java revision d5b720e30a9d82b5f81ec8eac2803e213f2f1c41
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 com.example.android.support.transition.R; 20 21import android.os.Bundle; 22import android.support.transition.Scene; 23import android.support.transition.TransitionManager; 24import android.support.v7.app.AppCompatActivity; 25import android.support.v7.widget.Toolbar; 26import android.view.Menu; 27import android.view.MenuItem; 28import android.view.ViewGroup; 29import android.widget.FrameLayout; 30 31/** 32 * Base class for usages of the Transition API. 33 */ 34abstract class TransitionUsageBase extends AppCompatActivity { 35 36 protected Scene[] mScenes; 37 38 private int mCurrentScene; 39 40 abstract Scene[] setUpScenes(ViewGroup root); 41 42 abstract void go(Scene scene); 43 44 @Override 45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 setContentView(R.layout.basic_usage); 48 49 // Retrieve the Toolbar from our content view, and set it as the action bar 50 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 51 setSupportActionBar(toolbar); 52 53 FrameLayout root = (FrameLayout) findViewById(R.id.root); 54 mScenes = setUpScenes(root); 55 TransitionManager.go(mScenes[0]); 56 } 57 58 @Override 59 public boolean onCreateOptionsMenu(Menu menu) { 60 getMenuInflater().inflate(R.menu.basic_usage, menu); 61 return true; 62 } 63 64 @Override 65 public boolean onOptionsItemSelected(MenuItem item) { 66 switch (item.getItemId()) { 67 case R.id.action_toggle: 68 mCurrentScene = (mCurrentScene + 1) % mScenes.length; 69 go(mScenes[mCurrentScene]); 70 return true; 71 } 72 return false; 73 } 74 75} 76