Home | History | Annotate | Download | only in cts
      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 
     18 package android.fragment.cts;
     19 
     20 import android.os.Bundle;
     21 import android.view.LayoutInflater;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 
     25 public class StrictViewFragment extends StrictFragment {
     26     boolean mOnCreateViewCalled, mOnViewCreatedCalled, mOnDestroyViewCalled;
     27     int mLayoutId = R.layout.strict_view_fragment;
     28 
     29     public void setLayoutId(int layoutId) {
     30         mLayoutId = layoutId;
     31     }
     32 
     33     public static StrictViewFragment create(int layoutId) {
     34         StrictViewFragment fragment = new StrictViewFragment();
     35         fragment.mLayoutId = layoutId;
     36         return fragment;
     37     }
     38 
     39     @Override
     40     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     41             Bundle savedInstanceState) {
     42         checkGetActivity();
     43         checkState("onCreateView", CREATED);
     44         final View result = inflater.inflate(mLayoutId, container, false);
     45         mOnCreateViewCalled = true;
     46         return result;
     47     }
     48 
     49     @Override
     50     public void onViewCreated(View view, Bundle savedInstanceState) {
     51         if (view == null) {
     52             throw new IllegalArgumentException("onViewCreated view argument should not be null");
     53         }
     54         checkGetActivity();
     55         checkState("onViewCreated", CREATED);
     56         mOnViewCreatedCalled = true;
     57     }
     58 
     59     @Override
     60     public void onDestroyView() {
     61         super.onDestroyView();
     62         if (getView() == null) {
     63             throw new IllegalStateException("getView returned null in onDestroyView");
     64         }
     65         checkGetActivity();
     66         checkState("onDestroyView", CREATED);
     67         mOnDestroyViewCalled = true;
     68     }
     69 }
     70