2012-06-18 12:39: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;
|
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import org.mozilla.gecko.AwesomeBar.ContextMenuSubject;
|
|
|
|
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
|
|
|
|
2012-06-18 12:39:13 -07:00
|
|
|
import android.content.ContentResolver;
|
2012-06-18 12:39:13 -07:00
|
|
|
import android.content.Context;
|
2012-06-18 12:39:13 -07:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2012-07-13 12:49:58 -07:00
|
|
|
import android.net.Uri;
|
2012-06-18 12:39:13 -07:00
|
|
|
import android.text.TextUtils;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.view.ContextMenu;
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2012-06-18 12:39:13 -07:00
|
|
|
import android.view.LayoutInflater;
|
2012-06-18 12:39:13 -07:00
|
|
|
import android.view.View;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2012-06-18 12:39:13 -07:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TabHost.TabContentFactory;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.widget.TextView;
|
2012-06-18 12:39:13 -07:00
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
abstract public class AwesomeBarTab {
|
2012-06-18 12:39:13 -07:00
|
|
|
abstract public String getTag();
|
|
|
|
abstract public int getTitleStringId();
|
|
|
|
abstract public void destroy();
|
|
|
|
abstract public TabContentFactory getFactory();
|
2012-06-18 12:39:13 -07:00
|
|
|
abstract public boolean onBackPressed();
|
|
|
|
abstract public ContextMenuSubject getSubject(ContextMenu menu, View view, ContextMenuInfo menuInfo);
|
2012-06-18 12:39:13 -07:00
|
|
|
|
2012-07-19 12:08:55 -07:00
|
|
|
protected View mView = null;
|
2012-06-18 12:39:13 -07:00
|
|
|
protected View.OnTouchListener mListListener;
|
|
|
|
private AwesomeBarTabs.OnUrlOpenListener mListener;
|
|
|
|
private LayoutInflater mInflater = null;
|
|
|
|
private ContentResolver mContentResolver = null;
|
|
|
|
private Resources mResources;
|
2012-06-18 12:39:13 -07:00
|
|
|
// FIXME: This value should probably come from a prefs key
|
|
|
|
public static final int MAX_RESULTS = 100;
|
|
|
|
protected Context mContext = null;
|
|
|
|
|
|
|
|
public AwesomeBarTab(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
2012-06-18 12:39:13 -07:00
|
|
|
public void setListTouchListener(View.OnTouchListener listener) {
|
|
|
|
mListListener = listener;
|
2012-07-19 12:08:55 -07:00
|
|
|
if (mView != null)
|
|
|
|
mView.setOnTouchListener(mListListener);
|
2012-06-18 12:39:13 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
protected class AwesomeEntryViewHolder {
|
2012-06-18 12:39:13 -07:00
|
|
|
public TextView titleView;
|
|
|
|
public TextView urlView;
|
|
|
|
public ImageView faviconView;
|
|
|
|
public ImageView bookmarkIconView;
|
|
|
|
}
|
2012-06-18 12:39:13 -07:00
|
|
|
|
|
|
|
protected LayoutInflater getInflater() {
|
|
|
|
if (mInflater == null) {
|
|
|
|
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
}
|
|
|
|
return mInflater;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected AwesomeBarTabs.OnUrlOpenListener getUrlListener() {
|
|
|
|
return mListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setUrlListener(AwesomeBarTabs.OnUrlOpenListener listener) {
|
|
|
|
mListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected ContentResolver getContentResolver() {
|
|
|
|
if (mContentResolver == null) {
|
|
|
|
mContentResolver = mContext.getContentResolver();
|
|
|
|
}
|
|
|
|
return mContentResolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Resources getResources() {
|
|
|
|
if (mResources == null) {
|
|
|
|
mResources = mContext.getResources();
|
|
|
|
}
|
|
|
|
return mResources;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getReaderForUrl(String url) {
|
|
|
|
// FIXME: still need to define the final way to open items from
|
|
|
|
// reading list. For now, we're using an about:reader page.
|
2012-08-07 07:23:20 -07:00
|
|
|
return "about:reader?url=" + Uri.encode(url) + "&readingList=1";
|
2012-06-18 12:39:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateFavicon(ImageView faviconView, Cursor cursor) {
|
|
|
|
byte[] b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
|
|
|
|
if (b == null) {
|
|
|
|
faviconView.setImageDrawable(null);
|
|
|
|
} else {
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
|
|
|
|
faviconView.setImageBitmap(bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateTitle(TextView titleView, Cursor cursor) {
|
|
|
|
int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
|
|
|
|
String title = cursor.getString(titleIndex);
|
|
|
|
|
|
|
|
// Use the URL instead of an empty title for consistency with the normal URL
|
|
|
|
// bar view - this is the equivalent of getDisplayTitle() in Tab.java
|
|
|
|
if (TextUtils.isEmpty(title)) {
|
|
|
|
int urlIndex = cursor.getColumnIndexOrThrow(URLColumns.URL);
|
|
|
|
title = cursor.getString(urlIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
titleView.setText(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateUrl(TextView urlView, Cursor cursor) {
|
|
|
|
int urlIndex = cursor.getColumnIndexOrThrow(URLColumns.URL);
|
|
|
|
String url = cursor.getString(urlIndex);
|
|
|
|
|
|
|
|
urlView.setText(url);
|
|
|
|
}
|
2012-06-18 12:39:13 -07:00
|
|
|
|
|
|
|
protected boolean hideSoftInput(View view) {
|
|
|
|
InputMethodManager imm =
|
|
|
|
(InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
|
|
|
return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
|
|
}
|
2012-06-18 12:39:13 -07:00
|
|
|
}
|