If you think the Android project EBrowser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2010 Cyril Mottier (http://www.cyrilmottier.com)
*//fromwww.java2s.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package org.greendroid;
import java.util.List;
import com.mrpej.ebrowser.R;
import android.content.Context;
import android.graphics.Rect;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
/**
* A {@link QuickActionGrid} is an implementation of a {@link QuickActionWidget}
* that displays {@link QuickAction}s in a grid manner. This is usually used to create
* a shortcut to jump between different type of information on screen.
*
* @author Benjamin Fellous
* @author Cyril Mottier
*/publicclass QuickActionGrid extends QuickActionWidget {
private GridView mGridView;
public QuickActionGrid(Context context) {
super(context);
setContentView(R.layout.gd_quick_action_grid);
final View v = getContentView();
mGridView = (GridView) v.findViewById(R.id.gdi_grid);
}
@Override
protectedvoid populateQuickActions(final List<QuickAction> quickActions) {
mGridView.setAdapter(new BaseAdapter() {
public View getView(int position, View view, ViewGroup parent) {
TextView textView = (TextView) view;
if (view == null) {
final LayoutInflater inflater = LayoutInflater.from(getContext());
textView = (TextView) inflater.inflate(R.layout.gd_quick_action_grid_item, mGridView, false);
}
QuickAction quickAction = quickActions.get(position);
textView.setText(quickAction.mTitle);
textView.setCompoundDrawablesWithIntrinsicBounds(null, quickAction.mDrawable, null, null);
return textView;
}
publiclong getItemId(int position) {
return position;
}
public Object getItem(int position) {
return null;
}
publicint getCount() {
return quickActions.size();
}
});
mGridView.setOnItemClickListener(mInternalItemClickListener);
}
@Override
protectedvoid onMeasureAndLayout(Rect anchorRect, View contentView) {
contentView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
contentView.measure(MeasureSpec.makeMeasureSpec(getScreenWidth(), MeasureSpec.EXACTLY),
LayoutParams.WRAP_CONTENT);
int rootHeight = contentView.getMeasuredHeight();
int offsetY = getArrowOffsetY();
int dyTop = anchorRect.top;
int dyBottom = getScreenHeight() - anchorRect.bottom;
boolean onTop = (dyTop > dyBottom);
int popupY = (onTop) ? anchorRect.top - rootHeight + offsetY : anchorRect.bottom - offsetY;
setWidgetSpecs(popupY, onTop);
}
private OnItemClickListener mInternalItemClickListener = new OnItemClickListener() {
publicvoid onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
getOnQuickActionClickListener().onQuickActionClicked(QuickActionGrid.this, position);
if (getDismissOnClick()) {
dismiss();
}
}
};
}