Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko.home;
8 import org.mozilla.gecko.R;
9 import org.mozilla.gecko.widget.IconTabWidget;
11 import android.content.res.Configuration;
12 import android.os.Bundle;
13 import android.support.v4.app.Fragment;
14 import android.view.LayoutInflater;
15 import android.view.View;
16 import android.view.ViewGroup;
18 public class HistoryPanel extends HomeFragment
19 implements IconTabWidget.OnTabChangedListener {
20 // Logging tag name
21 private static final String LOGTAG = "GeckoHistoryPanel";
22 private IconTabWidget mTabWidget;
23 private int mSelectedTab;
24 private boolean initializeRecentPanel;
26 @Override
27 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
28 return inflater.inflate(R.layout.home_history_panel, container, false);
29 }
31 @Override
32 public void onViewCreated(View view, Bundle savedInstanceState) {
33 super.onViewCreated(view, savedInstanceState);
35 mTabWidget = (IconTabWidget) view.findViewById(R.id.tab_icon_widget);
37 mTabWidget.addTab(R.drawable.icon_most_recent, R.string.home_most_recent_title);
38 mTabWidget.addTab(R.drawable.icon_last_tabs, R.string.home_last_tabs_title);
40 mTabWidget.setTabSelectionListener(this);
41 mTabWidget.setCurrentTab(mSelectedTab);
43 loadIfVisible();
44 }
46 @Override
47 public void load() {
48 // Show most recent panel as the initial panel.
49 // Since we detach/attach on config change, this prevents from replacing current fragment.
50 if (!initializeRecentPanel) {
51 showMostRecentPanel();
52 initializeRecentPanel = true;
53 }
54 }
56 @Override
57 public void onTabChanged(int index) {
58 if (index == mSelectedTab) {
59 return;
60 }
62 if (index == 0) {
63 showMostRecentPanel();
64 } else if (index == 1) {
65 showLastTabsPanel();
66 }
68 mTabWidget.setCurrentTab(index);
69 mSelectedTab = index;
70 }
72 @Override
73 public void onConfigurationChanged(Configuration newConfig) {
74 super.onConfigurationChanged(newConfig);
76 // Rotation should detach and re-attach to use a different layout.
77 if (isVisible()) {
78 getFragmentManager().beginTransaction()
79 .detach(this)
80 .attach(this)
81 .commitAllowingStateLoss();
82 }
83 }
85 private void showSubPanel(Fragment subPanel) {
86 final Bundle args = new Bundle();
87 args.putBoolean(HomePager.CAN_LOAD_ARG, getCanLoadHint());
88 subPanel.setArguments(args);
90 getChildFragmentManager().beginTransaction()
91 .addToBackStack(null).replace(R.id.history_panel_container, subPanel)
92 .commitAllowingStateLoss();
93 }
95 private void showMostRecentPanel() {
96 final MostRecentPanel mostRecentPanel = MostRecentPanel.newInstance();
97 showSubPanel(mostRecentPanel);
98 }
100 private void showLastTabsPanel() {
101 final LastTabsPanel lastTabsPanel = LastTabsPanel.newInstance();
102 showSubPanel(lastTabsPanel);
103 }
104 }