2013-05-30 17:53:13 -07:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko.home;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.R;
|
2013-06-11 09:57:45 -07:00
|
|
|
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
2013-05-30 17:53:13 -07:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A page in about:home that displays a ListView of bookmarks.
|
|
|
|
*/
|
2013-06-14 12:00:59 -07:00
|
|
|
public class BookmarksPage extends HomeFragment {
|
2013-05-30 17:53:13 -07:00
|
|
|
public static final String LOGTAG = "GeckoBookmarksPage";
|
|
|
|
|
|
|
|
// The view shown by the fragment.
|
2013-06-14 12:00:59 -07:00
|
|
|
private BookmarksListView mList;
|
2013-05-30 17:53:13 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
2013-06-14 11:58:30 -07:00
|
|
|
return inflater.inflate(R.layout.home_bookmarks_page, null);
|
2013-05-30 17:53:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
|
2013-06-14 13:07:18 -07:00
|
|
|
OnUrlOpenListener listener = null;
|
|
|
|
try {
|
|
|
|
listener = (OnUrlOpenListener) getActivity();
|
|
|
|
} catch (ClassCastException e) {
|
|
|
|
throw new ClassCastException(getActivity().toString()
|
|
|
|
+ " must implement HomePager.OnUrlOpenListener");
|
|
|
|
}
|
|
|
|
|
2013-06-14 12:00:59 -07:00
|
|
|
mList = (BookmarksListView) view.findViewById(R.id.bookmarks_list);
|
2013-06-14 13:07:18 -07:00
|
|
|
mList.setOnUrlOpenListener(listener);
|
2013-05-30 17:53:13 -07:00
|
|
|
|
2013-06-14 09:35:11 -07:00
|
|
|
registerForContextMenu(mList);
|
2013-05-30 17:53:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
mList = null;
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
|
|
|
// Reattach the fragment, forcing a reinflation of its view.
|
|
|
|
// We use commitAllowingStateLoss() instead of commit() here to avoid
|
|
|
|
// an IllegalStateException. If the phone is rotated while Fennec
|
|
|
|
// is in the background, onConfigurationChanged() is fired.
|
|
|
|
// onConfigurationChanged() is called before onResume(), so
|
|
|
|
// using commit() would throw an IllegalStateException since it can't
|
|
|
|
// be used between the Activity's onSaveInstanceState() and
|
|
|
|
// onResume().
|
|
|
|
if (isVisible()) {
|
|
|
|
getFragmentManager().beginTransaction()
|
|
|
|
.detach(this)
|
|
|
|
.attach(this)
|
|
|
|
.commitAllowingStateLoss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|