package com.jiuqi.njt.register; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.jiuqi.njt.R; import com.jiuqi.njt.util.UIUtil; @SuppressLint("NewApi") public class IndexActivityViewBean { private View createView; private LinearLayout createLayout; /** * 待创建的按钮对象 */ private Button createButton; /** * 是不是左边的布局 true 是左边的布局 false 是右边的布局 */ private boolean isLeftLayout; private TextView createTextView; private Context context; /** * 按钮显示的文字 */ private String buttonText; /** * 文字颜色 */ private int showTextColor; private int buttonBackgroundResource; /** * 按钮的宽高,默认是自适应权重是1 */ private LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); /** * 控件的宽高,默认是自适应权重是1 */ private LinearLayout.LayoutParams layoutItemParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1); private LinearLayout.LayoutParams layoutViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); /** * 边距 */ private int layoutMagin = 10; /** * 点击事件 */ private OnClickListener buttonClick; /** * 背景图片 */ private int backgroundResource; /** * 布局类型 */ private LayoutType layoutType; /** * 布局里面控件的布局枚举 */ private ViewType viewType; /** * 按钮对应的Activity的索引值 */ private int buttonClassIndex; public LinearLayout getCreateLayout() { return createLayout; } public void setCreateLayout(LinearLayout createLayout) { this.createLayout = createLayout; } public TextView getCreateTextView() { return createTextView; } public void setCreateTextView(TextView createTextView) { this.createTextView = createTextView; } public int getShowTextColor() { return showTextColor; } public void setShowTextColor(int showTextColor) { this.showTextColor = showTextColor; } /** * 按钮操作是不是需要登录 */ private boolean needLogin; /** * * @param context * * @param viewType * 控件的摆放类型 * @param layoutType * 控件父布局的类型 * @param backgroundResource * 控件父布局的背景图片 * @param onClickListener * 点击事件 * @param buttonBackgroundResource * 子控件的背景图片 * @param showText * 子控件 TextView显示的文字 * @param showTextColor * 子控件TextView显示的文字的颜色 */ @SuppressLint("ResourceAsColor") public IndexActivityViewBean(Context context, ViewType viewType, LayoutType layoutType, int backgroundResource, OnClickListener onClickListener, int buttonBackgroundResource, String showText, int showTextColor) { super(); this.context = context; this.createLayout = new LinearLayout(context); this.createLayout.setBackgroundResource(backgroundResource); this.createLayout.setOrientation(LinearLayout.HORIZONTAL); this.createTextView = new TextView(context); this.createButton = new Button(context); switch (layoutType) { case LEFTBOTTPMBUTTON: this.layoutParams.setMargins(layoutMagin, layoutMagin, layoutMagin / 2, layoutMagin); break; case LEFTNOMALBUTTON: this.layoutParams.setMargins(layoutMagin, layoutMagin, layoutMagin / 2, 0); break; case RIGHTBOTTPMBUTTON: this.layoutParams.setMargins(layoutMagin / 2, layoutMagin, layoutMagin, layoutMagin); break; case RIGHTNOMALBUTTON: this.layoutParams.setMargins(layoutMagin / 2, layoutMagin, layoutMagin, 0); break; default: break; } this.createLayout.setLayoutParams(layoutParams); this.createButton.setLayoutParams(layoutViewParams); // this.createTextView.setLayoutParams(layoutViewParams); this.createLayout.setOnClickListener(onClickListener); this.createTextView.setOnClickListener(onClickListener); this.createButton.setOnClickListener(onClickListener); this.createTextView.setText(showText); // this.createTextView.setTextSize(UIUtil.floatToSP(context, 8)); this.createTextView.setTextColor(showTextColor); this.createTextView.setTextAppearance(context, R.style.indextextviewstyle); this.createTextView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, (float) (UIUtil.getScreenWidth(context)*0.045)); this.createTextView.setShadowLayer(1, 0, 1, R.color.white); this.layoutMagin = (int) (UIUtil.getScreenWidth(context) * 0.018); // this.layoutMagin = UIUtil.floatToDP(context, layoutMagin); this.viewType = viewType; this.backgroundResource = backgroundResource; /** * 根据按钮的类型设置按钮的边距 */ Drawable drawable = context.getResources().getDrawable( buttonBackgroundResource); LinearLayout textViewLayout = new LinearLayout(context); LinearLayout buttonLayout = new LinearLayout(context); textViewLayout.setLayoutParams(layoutItemParams); buttonLayout.setLayoutParams(layoutItemParams); switch (viewType) { case LEFT_MIDLE_IMAGE_RIGHT_CETER_TEXT: textViewLayout.setGravity(Gravity.CENTER); buttonLayout.setGravity(Gravity.CENTER); this.createButton.setBackgroundResource(buttonBackgroundResource); // this.createButton.setBackground(null); // drawable.setBounds(0, 0, drawable.getMinimumWidth(), // drawable.getMinimumHeight()); // this.createButton.setCompoundDrawables(null, null, null, drawable); // this.createButton.setShadowLayer(10, 4, 4, R.color.black); textViewLayout.addView(this.createTextView); buttonLayout.addView(this.createButton); this.createLayout.addView(buttonLayout); this.createLayout.addView(textViewLayout); break; case LEFT_TOP_TEXT_RIGHAT_BOTTOM_IMAGE: textViewLayout.setGravity(Gravity.LEFT|Gravity.TOP); buttonLayout.setGravity(Gravity.RIGHT|Gravity.BOTTOM); this.createButton.setBackgroundResource(buttonBackgroundResource); textViewLayout.addView(this.createTextView); buttonLayout.addView(this.createButton); this.createLayout.addView(textViewLayout); this.createLayout.addView(buttonLayout); break; default: break; } } public IndexActivityViewBean() { super(); } public View getCreateView() { return createView; } public void setCreateView(View createView) { this.createView = createView; } /** * 按钮操作是不是需要登录 */ public boolean isNeedLogin() { return needLogin; } /** * 按钮操作是不是需要登录 */ public void setNeedLogin(boolean needLogin) { this.needLogin = needLogin; } /** * 创建的按钮对象 */ public Button getButton() { return createButton; } /** * 按钮文字对象 */ public String getButtonText() { return buttonText; } /** * 按钮类型 */ public LayoutType getButtonType() { return layoutType; } /** * 按钮类型 */ public void setButtonType(LayoutType buttonType) { this.layoutType = buttonType; } public void setButtonText(String buttonText) { this.buttonText = buttonText; } public void setButtonClick(OnClickListener buttonClick) { this.buttonClick = buttonClick; } public int getBackgroundResource() { return backgroundResource; } public void setBackgroundResource(int backgroundResource) { this.backgroundResource = backgroundResource; } public OnClickListener getButtonClick() { return buttonClick; } /** * 按钮对应的Activity的索引值 */ public int getButtonClassIndex() { return buttonClassIndex; } /** * 按钮对应的Activity的索引值 */ public void setButtonClassIndex(int buttonClassIndex) { this.buttonClassIndex = buttonClassIndex; } /** * 布局类型枚举 * * @author joe */ public enum LayoutType { /** * 左布局(普通) */ LEFTNOMALBUTTON, /** * 左布局(底部) */ LEFTBOTTPMBUTTON, /** * 右布局(普通) */ RIGHTNOMALBUTTON, /** * 右布局(底部) */ RIGHTBOTTPMBUTTON, /** * 普通带文字的按钮 */ NOMALBUTTONWITHTEXT, } /** * 控件的布局枚举 * * @author joe * */ public enum ViewType { /** * 文字在左上角、图片在右下角 */ LEFT_TOP_TEXT_RIGHAT_BOTTOM_IMAGE, /** * 图片在左中、文字在右中 */ LEFT_MIDLE_IMAGE_RIGHT_CETER_TEXT, } // /** // * // * @param context // * 创建的按钮上下文环境 // * @param buttonType // * 需要创建的按钮的类型 // * @param backgroundResource // * 按钮对应的背景图片的资源ID // * @param onClickListener // * 按钮对应的点击事件 // */ // // public IndexActivityViewBean(Context context, LayoutType buttonType, // int backgroundResource, OnClickListener onClickListener) { // super(); // this.context = context; // this.createButton = new Button(context); // this.createLayout = new LinearLayout(context); // this.createLayout.setBackgroundResource(backgroundResource); // this.createLayout.setOrientation(LinearLayout.HORIZONTAL); // this.createTextView = new TextView(context); // this.createTextView.setTextColor(showTextColor); // this.createTextView.setTextSize(UIUtil.floatToSP(context, 16)); // this.layoutMagin = (int) (UIUtil.getScreenWidth(context) * 0.02); // this.createTextView.setLayoutParams(layoutItemParams); // this.createButton.setLayoutParams(layoutItemParams); // /** // * 根据按钮的类型设置按钮的边距 // */ // Drawable drawable = context.getResources().getDrawable( // buttonBackgroundResource); // switch (buttonType) { // case LEFTBOTTPMBUTTON: // this.layoutParams.setMargins(layoutMagin, layoutMagin, // layoutMagin / 2, layoutMagin); // break; // case LEFTNOMALBUTTON: // this.layoutParams.setMargins(layoutMagin, layoutMagin, // layoutMagin / 2, 0); // break; // case RIGHTBOTTPMBUTTON: // this.layoutParams.setMargins(layoutMagin / 2, layoutMagin, // layoutMagin, layoutMagin); // break; // case RIGHTNOMALBUTTON: // this.layoutParams.setMargins(layoutMagin / 2, layoutMagin, // layoutMagin, 0); // break; // default: // break; // } // this.createButton.setLayoutParams(layoutParams); // this.backgroundResource = backgroundResource; // this.createButton.setBackgroundResource(backgroundResource); // this.createButton.setOnClickListener(onClickListener); // } }