mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
135 lines
4.6 KiB
Java
135 lines
4.6 KiB
Java
/* -*- 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;
|
|
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.database.Cursor;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.text.TextUtils;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.widget.TextView;
|
|
import android.widget.ImageView;
|
|
import android.widget.TabHost.TabContentFactory;
|
|
import android.view.inputmethod.InputMethodManager;
|
|
import android.view.ContextMenu;
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.mozilla.gecko.db.BrowserContract.Combined;
|
|
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
|
import org.mozilla.gecko.AwesomeBar.ContextMenuSubject;
|
|
|
|
abstract public class AwesomeBarTab {
|
|
abstract public String getTag();
|
|
abstract public int getTitleStringId();
|
|
abstract public void destroy();
|
|
abstract public TabContentFactory getFactory();
|
|
abstract public boolean onBackPressed();
|
|
abstract public ContextMenuSubject getSubject(ContextMenu menu, View view, ContextMenuInfo menuInfo);
|
|
|
|
protected View.OnTouchListener mListListener;
|
|
private AwesomeBarTabs.OnUrlOpenListener mListener;
|
|
private LayoutInflater mInflater = null;
|
|
private ContentResolver mContentResolver = null;
|
|
private Resources mResources;
|
|
// 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;
|
|
}
|
|
|
|
public void setListTouchListener(View.OnTouchListener listener) {
|
|
mListListener = listener;
|
|
}
|
|
|
|
protected class AwesomeEntryViewHolder {
|
|
public TextView titleView;
|
|
public TextView urlView;
|
|
public ImageView faviconView;
|
|
public ImageView bookmarkIconView;
|
|
}
|
|
|
|
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.
|
|
return "about:reader?url=" + url;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
protected boolean hideSoftInput(View view) {
|
|
InputMethodManager imm =
|
|
(InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
}
|
|
}
|