OSDN Git Service

74bc465ce8b5bcc71f9dd30142691292a4c3d230
[android-x86/external-koush-Widgets.git] / Widgets / src / com / koushikdutta / widgets / NativeFragment.java
1 /*
2  * Copyright (C) 2013 Koushik Dutta (@koush)
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.koushikdutta.widgets;
18
19 import android.app.Activity;
20 import android.app.Fragment;
21 import android.content.Context;
22 import android.content.res.Configuration;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.Menu;
26 import android.view.MenuInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29
30
31 public abstract class NativeFragment<T extends FragmentInterface> extends Fragment implements FragmentInterfaceWrapper {
32     public abstract T createFragmentInterface();
33     
34     @Override
35     public void onResume() {
36         super.onResume();
37     }
38     
39     @Override
40     public Context getContext() {
41         return getActivity();
42     }
43     
44     public void onDetach() {
45         super.onDetach();
46         internal.onDetach();
47     };
48     
49     public void onAttach(Activity activity) {
50         super.onAttach(activity);
51         internal.onAttach(activity);
52     };
53     
54     T internal;
55     public NativeFragment() {
56         internal = createFragmentInterface();
57     }
58
59     @Override
60     public T getInternal() {
61         return internal;
62     }
63     
64     @Override
65     public void onCreate(Bundle savedInstanceState) {
66         super.onCreate(savedInstanceState);
67         internal.onCreate(savedInstanceState);
68     }
69     
70     @Override
71     public void onConfigurationChanged(Configuration newConfig) {
72         super.onConfigurationChanged(newConfig);
73         internal.onConfigurationChanged(newConfig);
74     }
75     
76     @Override
77     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
78         return internal.onCreateView(inflater, container, savedInstanceState);
79     }
80     
81     @Override
82     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
83         super.onCreateOptionsMenu(menu, inflater);
84         
85         internal.onCreateOptionsMenu(menu, inflater);
86     }
87 }