2013-01-29 14:43:34 -08:00
|
|
|
/* 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.widget;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.R;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2013-07-25 17:06:02 -07:00
|
|
|
import android.content.res.TypedArray;
|
2013-01-29 14:43:34 -08:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
2013-06-20 16:52:02 -07:00
|
|
|
import android.widget.ImageButton;
|
2013-01-29 14:43:34 -08:00
|
|
|
import android.widget.TabWidget;
|
|
|
|
|
|
|
|
public class IconTabWidget extends TabWidget {
|
|
|
|
private OnTabChangedListener mListener;
|
2013-07-25 17:06:02 -07:00
|
|
|
private final int mButtonLayoutId;
|
2013-01-29 14:43:34 -08:00
|
|
|
|
|
|
|
public static interface OnTabChangedListener {
|
|
|
|
public void onTabChanged(int tabIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IconTabWidget(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2013-07-25 17:06:02 -07:00
|
|
|
|
|
|
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconTabWidget);
|
|
|
|
mButtonLayoutId = a.getResourceId(R.styleable.IconTabWidget_android_layout, 0);
|
|
|
|
a.recycle();
|
|
|
|
|
|
|
|
if (mButtonLayoutId == 0) {
|
|
|
|
throw new RuntimeException("You must supply layout attribute");
|
|
|
|
}
|
2013-01-29 14:43:34 -08:00
|
|
|
}
|
|
|
|
|
2013-06-20 16:52:02 -07:00
|
|
|
public ImageButton addTab(int resId) {
|
2013-07-25 17:06:02 -07:00
|
|
|
ImageButton button = (ImageButton) LayoutInflater.from(getContext()).inflate(mButtonLayoutId, null);
|
2013-06-20 16:52:02 -07:00
|
|
|
button.setImageResource(resId);
|
2013-01-29 14:43:34 -08:00
|
|
|
|
|
|
|
addView(button);
|
|
|
|
button.setOnClickListener(new TabClickListener(getTabCount() - 1));
|
|
|
|
button.setOnFocusChangeListener(this);
|
2013-02-28 16:29:20 -08:00
|
|
|
return button;
|
2013-01-29 14:43:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setTabSelectionListener(OnTabChangedListener listener) {
|
|
|
|
mListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFocusChange(View view, boolean hasFocus) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TabClickListener implements OnClickListener {
|
|
|
|
private final int mIndex;
|
|
|
|
|
|
|
|
public TabClickListener(int index) {
|
|
|
|
mIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (mListener != null)
|
|
|
|
mListener.onTabChanged(mIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|