Home | History | Annotate | Download | only in com.example.android.floatingactionbuttonbasic
      1 /*
      2  * Copyright 2014, 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 package com.example.android.floatingactionbuttonbasic;
     18 
     19 import com.example.android.common.logger.Log;
     20 
     21 import android.app.Activity;
     22 import android.net.Uri;
     23 import android.os.Bundle;
     24 import android.support.v4.app.Fragment;
     25 import android.view.LayoutInflater;
     26 import android.view.View;
     27 import android.view.ViewGroup;
     28 
     29 
     30 /**
     31  * This fragment inflates a layout with two Floating Action Buttons and acts as a listener to
     32  * changes on them.
     33  */
     34 public class FloatingActionButtonBasicFragment extends Fragment implements FloatingActionButton.OnCheckedChangeListener{
     35 
     36     private final static String TAG = "FloatingActionButtonBasicFragment";
     37 
     38     @Override
     39     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     40                              Bundle savedInstanceState) {
     41         // Inflate the layout for this fragment
     42         View rootView = inflater.inflate(R.layout.fab_layout, container, false);
     43 
     44         // Make this {@link Fragment} listen for changes in both FABs.
     45         FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab_1);
     46         fab1.setOnCheckedChangeListener(this);
     47         FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab_2);
     48         fab2.setOnCheckedChangeListener(this);
     49         return rootView;
     50     }
     51 
     52 
     53     @Override
     54     public void onCheckedChanged(FloatingActionButton fabView, boolean isChecked) {
     55         // When a FAB is toggled, log the action.
     56         switch (fabView.getId()){
     57             case R.id.fab_1:
     58                 Log.d(TAG, String.format("FAB 1 was %s.", isChecked ? "checked" : "unchecked"));
     59                 break;
     60             case R.id.fab_2:
     61                 Log.d(TAG, String.format("FAB 2 was %s.", isChecked ? "checked" : "unchecked"));
     62                 break;
     63             default:
     64                 break;
     65         }
     66     }
     67 }
     68