示例#1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.home_bookmarks_panel, container, false);

    mList = (BookmarksListView) view.findViewById(R.id.bookmarks_list);

    mList.setContextMenuInfoFactory(
        new HomeContextMenuInfo.Factory() {
          @Override
          public HomeContextMenuInfo makeInfoForCursor(
              View view, int position, long id, Cursor cursor) {
            final int type = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.TYPE));
            if (type == Bookmarks.TYPE_FOLDER) {
              // We don't show a context menu for folders
              return null;
            }
            final HomeContextMenuInfo info = new HomeContextMenuInfo(view, position, id);
            info.url = cursor.getString(cursor.getColumnIndexOrThrow(Bookmarks.URL));
            info.title = cursor.getString(cursor.getColumnIndexOrThrow(Bookmarks.TITLE));
            info.bookmarkId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
            return info;
          }
        });

    return view;
  }
示例#2
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final Activity activity = getActivity();

    // Setup the list adapter.
    mListAdapter = new BookmarksListAdapter(activity, null, mSavedParentStack);
    mListAdapter.setOnRefreshFolderListener(
        new OnRefreshFolderListener() {
          @Override
          public void onRefreshFolder(FolderInfo folderInfo, RefreshType refreshType) {
            // Restart the loader with folder as the argument.
            Bundle bundle = new Bundle();
            bundle.putParcelable(BOOKMARKS_FOLDER_INFO, folderInfo);
            bundle.putParcelable(BOOKMARKS_REFRESH_TYPE, refreshType);
            getLoaderManager().restartLoader(LOADER_ID_BOOKMARKS_LIST, bundle, mLoaderCallbacks);
          }
        });
    mList.setAdapter(mListAdapter);

    // Create callbacks before the initial loader is started.
    mLoaderCallbacks = new CursorLoaderCallbacks();
    loadIfVisible();
  }
示例#3
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    OnUrlOpenListener listener = null;
    try {
      listener = (OnUrlOpenListener) getActivity();
    } catch (ClassCastException e) {
      throw new ClassCastException(
          getActivity().toString() + " must implement HomePager.OnUrlOpenListener");
    }

    mList.setTag(HomePager.LIST_TAG_BOOKMARKS);
    mList.setOnUrlOpenListener(listener);

    registerForContextMenu(mList);
  }
示例#4
0
  private void updateUiFromCursor(Cursor c) {
    if ((c == null || c.getCount() == 0) && mEmptyView == null) {
      // Set empty page view. We delay this so that the empty view won't flash.
      final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub);
      mEmptyView = emptyViewStub.inflate();

      final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image);
      emptyIcon.setImageResource(R.drawable.icon_bookmarks_empty);

      final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text);
      emptyText.setText(R.string.home_bookmarks_empty);

      mList.setEmptyView(mEmptyView);
    }
  }