Annie Chin | abd202f | 2016-10-14 14:23:45 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 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.android.calculator2; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.ObjectAnimator; |
| 21 | import android.app.Fragment; |
| 22 | import android.app.FragmentManager; |
| 23 | import android.os.Bundle; |
| 24 | import android.util.Log; |
| 25 | import android.view.LayoutInflater; |
| 26 | import android.view.MenuItem; |
| 27 | import android.view.View; |
| 28 | import android.view.ViewGroup; |
| 29 | import android.widget.Toolbar; |
| 30 | |
| 31 | public class HistoryFragment extends Fragment { |
| 32 | |
| 33 | public static final String TAG = "HistoryFragment"; |
| 34 | |
| 35 | @Override |
| 36 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 37 | Bundle savedInstanceState) { |
| 38 | final View view = inflater.inflate( |
| 39 | R.layout.fragment_history, container, false /* attachToRoot */); |
| 40 | |
| 41 | final Toolbar toolbar = (Toolbar) view.findViewById(R.id.history_toolbar); |
| 42 | toolbar.inflateMenu(R.menu.fragment_history); |
| 43 | toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { |
| 44 | @Override |
| 45 | public boolean onMenuItemClick(MenuItem item) { |
| 46 | if (item.getItemId() == R.id.menu_clear_history) { |
| 47 | clearHistory(); |
| 48 | return true; |
| 49 | } |
| 50 | return onOptionsItemSelected(item); |
| 51 | } |
| 52 | }); |
| 53 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { |
| 54 | @Override |
| 55 | public void onClick(View v) { |
| 56 | final FragmentManager fm = getFragmentManager(); |
| 57 | if (fm.getBackStackEntryCount() > 0) { |
| 58 | fm.popBackStack(); |
| 59 | } |
| 60 | } |
| 61 | }); |
| 62 | |
| 63 | return view; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { |
| 68 | final View view = getView(); |
| 69 | final int height = getResources().getDisplayMetrics().heightPixels; |
| 70 | if (enter) { |
| 71 | return ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, -height, 0f); |
| 72 | } else { |
| 73 | return ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, -height); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private void clearHistory() { |
| 78 | Log.d(TAG, "Dropping history table"); |
| 79 | } |
| 80 | } |