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