1*90c8c64dSAndroid Build Coastguard Worker /* 2*90c8c64dSAndroid Build Coastguard Worker * Copyright 2014, The Android Open Source Project 3*90c8c64dSAndroid Build Coastguard Worker * 4*90c8c64dSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*90c8c64dSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*90c8c64dSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*90c8c64dSAndroid Build Coastguard Worker * 8*90c8c64dSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*90c8c64dSAndroid Build Coastguard Worker * 10*90c8c64dSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*90c8c64dSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*90c8c64dSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*90c8c64dSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*90c8c64dSAndroid Build Coastguard Worker * limitations under the License. 15*90c8c64dSAndroid Build Coastguard Worker */ 16*90c8c64dSAndroid Build Coastguard Worker 17*90c8c64dSAndroid Build Coastguard Worker package com.example.android.floatingactionbuttonbasic; 18*90c8c64dSAndroid Build Coastguard Worker 19*90c8c64dSAndroid Build Coastguard Worker import com.example.android.common.logger.Log; 20*90c8c64dSAndroid Build Coastguard Worker 21*90c8c64dSAndroid Build Coastguard Worker import android.app.Activity; 22*90c8c64dSAndroid Build Coastguard Worker import android.net.Uri; 23*90c8c64dSAndroid Build Coastguard Worker import android.os.Bundle; 24*90c8c64dSAndroid Build Coastguard Worker import android.support.v4.app.Fragment; 25*90c8c64dSAndroid Build Coastguard Worker import android.view.LayoutInflater; 26*90c8c64dSAndroid Build Coastguard Worker import android.view.View; 27*90c8c64dSAndroid Build Coastguard Worker import android.view.ViewGroup; 28*90c8c64dSAndroid Build Coastguard Worker 29*90c8c64dSAndroid Build Coastguard Worker 30*90c8c64dSAndroid Build Coastguard Worker /** 31*90c8c64dSAndroid Build Coastguard Worker * This fragment inflates a layout with two Floating Action Buttons and acts as a listener to 32*90c8c64dSAndroid Build Coastguard Worker * changes on them. 33*90c8c64dSAndroid Build Coastguard Worker */ 34*90c8c64dSAndroid Build Coastguard Worker public class FloatingActionButtonBasicFragment extends Fragment implements FloatingActionButton.OnCheckedChangeListener{ 35*90c8c64dSAndroid Build Coastguard Worker 36*90c8c64dSAndroid Build Coastguard Worker private final static String TAG = "FloatingActionButtonBasicFragment"; 37*90c8c64dSAndroid Build Coastguard Worker 38*90c8c64dSAndroid Build Coastguard Worker @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)39*90c8c64dSAndroid Build Coastguard Worker public View onCreateView(LayoutInflater inflater, ViewGroup container, 40*90c8c64dSAndroid Build Coastguard Worker Bundle savedInstanceState) { 41*90c8c64dSAndroid Build Coastguard Worker // Inflate the layout for this fragment 42*90c8c64dSAndroid Build Coastguard Worker View rootView = inflater.inflate(R.layout.fab_layout, container, false); 43*90c8c64dSAndroid Build Coastguard Worker 44*90c8c64dSAndroid Build Coastguard Worker // Make this {@link Fragment} listen for changes in both FABs. 45*90c8c64dSAndroid Build Coastguard Worker FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab_1); 46*90c8c64dSAndroid Build Coastguard Worker fab1.setOnCheckedChangeListener(this); 47*90c8c64dSAndroid Build Coastguard Worker FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab_2); 48*90c8c64dSAndroid Build Coastguard Worker fab2.setOnCheckedChangeListener(this); 49*90c8c64dSAndroid Build Coastguard Worker return rootView; 50*90c8c64dSAndroid Build Coastguard Worker } 51*90c8c64dSAndroid Build Coastguard Worker 52*90c8c64dSAndroid Build Coastguard Worker 53*90c8c64dSAndroid Build Coastguard Worker @Override onCheckedChanged(FloatingActionButton fabView, boolean isChecked)54*90c8c64dSAndroid Build Coastguard Worker public void onCheckedChanged(FloatingActionButton fabView, boolean isChecked) { 55*90c8c64dSAndroid Build Coastguard Worker // When a FAB is toggled, log the action. 56*90c8c64dSAndroid Build Coastguard Worker switch (fabView.getId()){ 57*90c8c64dSAndroid Build Coastguard Worker case R.id.fab_1: 58*90c8c64dSAndroid Build Coastguard Worker Log.d(TAG, String.format("FAB 1 was %s.", isChecked ? "checked" : "unchecked")); 59*90c8c64dSAndroid Build Coastguard Worker break; 60*90c8c64dSAndroid Build Coastguard Worker case R.id.fab_2: 61*90c8c64dSAndroid Build Coastguard Worker Log.d(TAG, String.format("FAB 2 was %s.", isChecked ? "checked" : "unchecked")); 62*90c8c64dSAndroid Build Coastguard Worker break; 63*90c8c64dSAndroid Build Coastguard Worker default: 64*90c8c64dSAndroid Build Coastguard Worker break; 65*90c8c64dSAndroid Build Coastguard Worker } 66*90c8c64dSAndroid Build Coastguard Worker } 67*90c8c64dSAndroid Build Coastguard Worker } 68