2 * Copyright (C) 2014 The CyanogenMod Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.cyanogenmod.eleven.ui.fragments;
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;
25 import com.cyanogenmod.eleven.MusicStateListener;
26 import com.cyanogenmod.eleven.R;
27 import com.cyanogenmod.eleven.ui.activities.HomeActivity;
29 public abstract class BaseFragment extends Fragment implements MusicStateListener,
32 protected ViewGroup mRootView;
34 protected abstract String getTitle();
35 protected abstract int getLayoutToInflate();
37 protected boolean needsElevatedActionBar() {
42 public void onCreate(Bundle savedInstanceState) {
43 super.onCreate(savedInstanceState);
44 setRetainInstance(true);
48 public void setupActionBar() {
49 getContainingActivity().setupActionBar(getTitle());
50 getContainingActivity().setActionBarAlpha(255);
51 getContainingActivity().setFragmentPadding(true);
52 getContainingActivity().setActionBarElevation(needsElevatedActionBar());
55 protected HomeActivity getContainingActivity() {
56 return (HomeActivity) getActivity();
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() {
69 public boolean onTouch(View v, MotionEvent me) { return true; }
78 protected void onViewCreated() {
79 getContainingActivity().setMusicStateListenerListener(this);
83 public void onDestroyView() {
84 super.onDestroyView();
86 getContainingActivity().removeMusicStateListenerListener(this);
90 public void onMetaChanged() {
95 public void onPlaylistChanged() {