|
| 1 | +package com.vogella.android.otto; |
| 2 | + |
| 3 | +import android.app.Fragment; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.support.annotation.Nullable; |
| 6 | +import android.support.design.widget.FloatingActionButton; |
| 7 | +import android.view.LayoutInflater; |
| 8 | +import android.view.View; |
| 9 | +import android.view.ViewGroup; |
| 10 | +import android.widget.Button; |
| 11 | +import android.widget.TextView; |
| 12 | + |
| 13 | +import com.squareup.otto.Subscribe; |
| 14 | + |
| 15 | +public class BottomFragment extends Fragment { |
| 16 | + |
| 17 | + private TextView bottomTextView; |
| 18 | + |
| 19 | + @Override |
| 20 | + public void onCreate(@Nullable Bundle savedInstanceState) { |
| 21 | + super.onCreate(savedInstanceState); |
| 22 | + ((MyApplication)getActivity().getApplicationContext()).getOttoBus().register(this); |
| 23 | + } |
| 24 | + |
| 25 | + @Nullable |
| 26 | + @Override |
| 27 | + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| 28 | + View v = inflater.inflate(R.layout.fragment_bottom, container, false); |
| 29 | + bottomTextView = (TextView) v.findViewById(R.id.bottom_textview); |
| 30 | + return v; |
| 31 | + } |
| 32 | + |
| 33 | + @Subscribe |
| 34 | + public void buttonClickAvailable(final View v){ |
| 35 | + if(v instanceof FloatingActionButton) { |
| 36 | + bottomTextView.setVisibility(View.VISIBLE); |
| 37 | + bottomTextView.setText("Button pushed"); |
| 38 | + bottomTextView.animate().alpha(0).setDuration(2000).withEndAction(new Runnable() { |
| 39 | + @Override public void run() { |
| 40 | + bottomTextView.setAlpha(1); |
| 41 | + bottomTextView.setVisibility(View.GONE); |
| 42 | + } |
| 43 | + }); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments