OSDN Git Service

Fix dependencies of packages that target earlier releases
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / ui / fragments / BaseFragment.java
1 /*
2 * Copyright (C) 2014 The CyanogenMod 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 package com.cyanogenmod.eleven.ui.fragments;
17
18 import android.os.Bundle;
19 import android.support.v4.app.Fragment;
20 import android.view.LayoutInflater;
21 import android.view.MotionEvent;
22 import android.view.View;
23 import android.view.ViewGroup;
24
25 import com.cyanogenmod.eleven.MusicStateListener;
26 import com.cyanogenmod.eleven.R;
27 import com.cyanogenmod.eleven.ui.activities.HomeActivity;
28
29 public abstract class BaseFragment extends Fragment implements MusicStateListener,
30     ISetupActionBar {
31
32     protected ViewGroup mRootView;
33
34     protected abstract String getTitle();
35     protected abstract int getLayoutToInflate();
36
37     protected boolean needsElevatedActionBar() {
38         return true;
39     }
40
41     @Override
42     public void onCreate(Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44         setRetainInstance(true);
45     }
46
47     @Override
48     public void setupActionBar() {
49         getContainingActivity().setupActionBar(getTitle());
50         getContainingActivity().setActionBarAlpha(255);
51         getContainingActivity().setFragmentPadding(true);
52         getContainingActivity().setActionBarElevation(needsElevatedActionBar());
53     }
54
55     protected HomeActivity getContainingActivity() {
56         return (HomeActivity) getActivity();
57     }
58
59     @Override
60     public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
61         // The View for the fragment's UI
62         mRootView = (ViewGroup) inflater.inflate(getLayoutToInflate(), null);
63         // set the background color
64         mRootView.setBackgroundColor(getResources().getColor(R.color.background_color));
65         // eat any touches that fall through to the root so they aren't
66         // passed on to fragments "behind" the current one.
67         mRootView.setOnTouchListener(new View.OnTouchListener() {
68             @Override
69             public boolean onTouch(View v, MotionEvent me) { return true; }
70         });
71
72         setupActionBar();
73         onViewCreated();
74
75         return mRootView;
76     }
77
78     protected void onViewCreated() {
79         getContainingActivity().setMusicStateListenerListener(this);
80     }
81
82     @Override
83     public void onDestroyView() {
84         super.onDestroyView();
85
86         getContainingActivity().removeMusicStateListenerListener(this);
87     }
88
89     @Override
90     public void onMetaChanged() {
91
92     }
93
94     @Override
95     public void onPlaylistChanged() {
96
97     }
98 }