package com.archermind.ebook.view.bottombar;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.archermind.ebook.R;
import com.archermind.ebook.data.online.MyLog;
public class BottomBarView extends RelativeLayout implements OnClickListener {
private ImageButton mButtonHelp;
private ImageButton mButtonPrevious;
// add by fengxia.kang@2009-11-18
private TextView mTextViewPage;
private TextView mTextViewTotalItems;
private ImageButton mButtonNext;
private ImageButton mButtonBack;
// public static final int VISIBLE = 0;
// public static final int INVISIBLE = 1;
private OnClickHelpListener mOnClickHelpListener;
private OnClickTextViewListener mOnClickTextViewListener;
private OnClickPreviousListener mOnClickPreviousListener;
private OnClickNextListener mOnClickNextListener;
private OnClickBackListener mOnClickBackListener;
public interface OnClickHelpListener {
void onClickHelp();
}
public interface OnClickTextViewListener {
void onClickTextView();
}
public interface OnClickPreviousListener {
void onClickPrevious();
}
public interface OnClickNextListener {
void onClickNext();
}
public interface OnClickBackListener {
void onClickBack();
}
public BottomBarView(Context context) {
this(context, null);
}
public BottomBarView(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onFinishInflate() {
mButtonHelp = (ImageButton) findViewById(R.id.button_help);
mButtonPrevious = (ImageButton) findViewById(R.id.button_previous);
mTextViewPage = (TextView) findViewById(R.id.textview_page);
mTextViewTotalItems = (TextView) findViewById(R.id.textview_totalitems);
mButtonNext = (ImageButton) findViewById(R.id.button_next);
mButtonBack = (ImageButton) findViewById(R.id.button_back);
mButtonHelp.setOnClickListener(this);
mTextViewPage.setOnClickListener(this);
mButtonPrevious.setOnClickListener(this);
mButtonNext.setOnClickListener(this);
mButtonBack.setOnClickListener(this);
super.onFinishInflate();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_help:
mOnClickHelpListener.onClickHelp();
break;
case R.id.textview_page:
mOnClickTextViewListener.onClickTextView();
break;
case R.id.button_previous:
mOnClickPreviousListener.onClickPrevious();
break;
case R.id.button_next:
mOnClickNextListener.onClickNext();
break;
case R.id.button_back:
mOnClickBackListener.onClickBack();
break;
default:
break;
}
}
public void setOnClickHelpListener(OnClickHelpListener listener) {
mOnClickHelpListener = listener;
}
public void setOnClickTextViewListener(OnClickTextViewListener listener) {
mOnClickTextViewListener = listener;
}
public void setOnClickPreviousListener(OnClickPreviousListener listener) {
mOnClickPreviousListener = listener;
}
public void setOnClickNextListener(OnClickNextListener listener) {
mOnClickNextListener = listener;
}
public void setOnClickBackListener(OnClickBackListener listener) {
mOnClickBackListener = listener;
}
public void setPageVisibility(int visibility) {
switch (visibility) {
case VISIBLE:
// mButtonPrevious.setVisibility(View.VISIBLE);
mTextViewPage.setVisibility(View.VISIBLE);
// mButtonNext.setVisibility(View.VISIBLE);
// mButtonBack.setVisibility(View.VISIBLE);
break;
case INVISIBLE:
// mButtonPrevious.setVisibility(View.INVISIBLE);
mTextViewPage.setVisibility(View.INVISIBLE);
// mButtonNext.setVisibility(View.INVISIBLE);
break;
default:
break;
}
}
public void setButtonBackVisibility(int visibility) {
switch (visibility) {
case VISIBLE:
mButtonBack.setVisibility(View.VISIBLE);
break;
case INVISIBLE:
mButtonBack.setVisibility(View.INVISIBLE);
break;
default:
break;
}
}
public void setTotalItemVisibility(int visibility) {
switch (visibility) {
case VISIBLE:
mTextViewTotalItems.setVisibility(View.VISIBLE);
break;
case INVISIBLE:
mTextViewTotalItems.setVisibility(View.INVISIBLE);
break;
default:
break;
}
}
// add by fengxia.kang@2009-11-18
public void setPage(int currentPage, int totalPage) {
MyLog.d("setPage", "currentPage : " + currentPage + " ; totalPage : "
+ totalPage);
if (currentPage < 0 || totalPage < 0) {
mTextViewPage.setText("");
} else {
String str = String.valueOf(currentPage) + "/"
+ String.valueOf(totalPage);
mTextViewPage.setText(String.valueOf(str));
}
MyLog.d("setPage", "..is shown" + this.isShown());
}
public void setPage(int currentPage, int totalPage, String strTotalItem) {
String str = String.valueOf(currentPage) + "/"
+ String.valueOf(totalPage);
mTextViewPage.setText(String.valueOf(str));
mTextViewTotalItems.setText(strTotalItem);
}
// add by leiming.yu@2009-12-4
public void setPreviousClickable(boolean flag) {
mButtonPrevious.setClickable(flag);
if (flag) {
mButtonPrevious.setImageResource(R.drawable.but_l_a);
} else {
mButtonPrevious.setImageResource(R.drawable.but_l_c);
}
}
public void setNextClickable(boolean flag) {
mButtonNext.setClickable(flag);
if (flag) {
mButtonNext.setImageResource(R.drawable.but_r_a);
} else {
mButtonNext.setImageResource(R.drawable.but_r_c);
}
}
public void clickPrevious() {
mOnClickPreviousListener.onClickPrevious();
}
public void clickNext() {
mOnClickNextListener.onClickNext();
}
}
//application
BottomBarView.OnClickBackListener mClickBack = new BottomBarView.OnClickBackListener() {
public void onClickBack() {
finish();
}
};
private LayoutInflater mInflater;
mInflater = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View view1 = (View) mInflater.inflate(
R.layout.mobile_home_none_recentread_item, RecentInfoView.this,
false);
mRecentRead.addView(item);