blob: 7cd8d52f03e8324a141c1e728d04578f4c1b2bd8 [file] [log] [blame]
Annie Chinabd202f2016-10-14 14:23:45 -07001/*
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
17package com.android.calculator2;
18
19import android.animation.Animator;
20import android.animation.ObjectAnimator;
21import android.app.Fragment;
22import android.app.FragmentManager;
23import android.os.Bundle;
24import android.util.Log;
25import android.view.LayoutInflater;
26import android.view.MenuItem;
27import android.view.View;
28import android.view.ViewGroup;
29import android.widget.Toolbar;
30
31public 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}