1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/home/HistoryPanel.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.home; 1.10 + 1.11 +import org.mozilla.gecko.R; 1.12 +import org.mozilla.gecko.widget.IconTabWidget; 1.13 + 1.14 +import android.content.res.Configuration; 1.15 +import android.os.Bundle; 1.16 +import android.support.v4.app.Fragment; 1.17 +import android.view.LayoutInflater; 1.18 +import android.view.View; 1.19 +import android.view.ViewGroup; 1.20 + 1.21 +public class HistoryPanel extends HomeFragment 1.22 + implements IconTabWidget.OnTabChangedListener { 1.23 + // Logging tag name 1.24 + private static final String LOGTAG = "GeckoHistoryPanel"; 1.25 + private IconTabWidget mTabWidget; 1.26 + private int mSelectedTab; 1.27 + private boolean initializeRecentPanel; 1.28 + 1.29 + @Override 1.30 + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 1.31 + return inflater.inflate(R.layout.home_history_panel, container, false); 1.32 + } 1.33 + 1.34 + @Override 1.35 + public void onViewCreated(View view, Bundle savedInstanceState) { 1.36 + super.onViewCreated(view, savedInstanceState); 1.37 + 1.38 + mTabWidget = (IconTabWidget) view.findViewById(R.id.tab_icon_widget); 1.39 + 1.40 + mTabWidget.addTab(R.drawable.icon_most_recent, R.string.home_most_recent_title); 1.41 + mTabWidget.addTab(R.drawable.icon_last_tabs, R.string.home_last_tabs_title); 1.42 + 1.43 + mTabWidget.setTabSelectionListener(this); 1.44 + mTabWidget.setCurrentTab(mSelectedTab); 1.45 + 1.46 + loadIfVisible(); 1.47 + } 1.48 + 1.49 + @Override 1.50 + public void load() { 1.51 + // Show most recent panel as the initial panel. 1.52 + // Since we detach/attach on config change, this prevents from replacing current fragment. 1.53 + if (!initializeRecentPanel) { 1.54 + showMostRecentPanel(); 1.55 + initializeRecentPanel = true; 1.56 + } 1.57 + } 1.58 + 1.59 + @Override 1.60 + public void onTabChanged(int index) { 1.61 + if (index == mSelectedTab) { 1.62 + return; 1.63 + } 1.64 + 1.65 + if (index == 0) { 1.66 + showMostRecentPanel(); 1.67 + } else if (index == 1) { 1.68 + showLastTabsPanel(); 1.69 + } 1.70 + 1.71 + mTabWidget.setCurrentTab(index); 1.72 + mSelectedTab = index; 1.73 + } 1.74 + 1.75 + @Override 1.76 + public void onConfigurationChanged(Configuration newConfig) { 1.77 + super.onConfigurationChanged(newConfig); 1.78 + 1.79 + // Rotation should detach and re-attach to use a different layout. 1.80 + if (isVisible()) { 1.81 + getFragmentManager().beginTransaction() 1.82 + .detach(this) 1.83 + .attach(this) 1.84 + .commitAllowingStateLoss(); 1.85 + } 1.86 + } 1.87 + 1.88 + private void showSubPanel(Fragment subPanel) { 1.89 + final Bundle args = new Bundle(); 1.90 + args.putBoolean(HomePager.CAN_LOAD_ARG, getCanLoadHint()); 1.91 + subPanel.setArguments(args); 1.92 + 1.93 + getChildFragmentManager().beginTransaction() 1.94 + .addToBackStack(null).replace(R.id.history_panel_container, subPanel) 1.95 + .commitAllowingStateLoss(); 1.96 + } 1.97 + 1.98 + private void showMostRecentPanel() { 1.99 + final MostRecentPanel mostRecentPanel = MostRecentPanel.newInstance(); 1.100 + showSubPanel(mostRecentPanel); 1.101 + } 1.102 + 1.103 + private void showLastTabsPanel() { 1.104 + final LastTabsPanel lastTabsPanel = LastTabsPanel.newInstance(); 1.105 + showSubPanel(lastTabsPanel); 1.106 + } 1.107 +}