Home | History | Annotate | Download | only in widget
      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 
     17 package com.example.android.support.transition.widget;
     18 
     19 import android.os.Bundle;
     20 import android.view.Menu;
     21 import android.view.MenuItem;
     22 import android.view.ViewGroup;
     23 import android.widget.FrameLayout;
     24 
     25 import androidx.transition.Scene;
     26 import androidx.transition.TransitionManager;
     27 
     28 import com.example.android.support.transition.R;
     29 
     30 abstract 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