增加共通操作对话框

This commit is contained in:
zengfantian 2015-10-30 20:45:22 +08:00
parent 3d1cf4da8b
commit fb76812bff
18 changed files with 614 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@color/transparent" />
<item android:state_pressed="true" android:drawable="@color/grally_f4f4f4" />
</selector>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@android:color/transparent" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/grally_f4f4f4" />
<item android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<item android:state_pressed="true" android:drawable="@color/grally_f4f4f4" />
</selector>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/shape_common_btn_white_bold_n" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/shape_common_btn_grally_bold_p" />
<item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/shape_common_btn_white_bold_n" />
<item android:state_pressed="true" android:drawable="@drawable/shape_common_btn_grally_bold_p" />
<item android:drawable="@drawable/shape_common_btn_white_bold_n" />
</selector>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@color/white" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/grally_f4f4f4" />
<item android:state_focused="false" android:state_pressed="false" android:drawable="@color/white" />
<item android:state_pressed="true" android:drawable="@color/grally_f4f4f4" />
<item android:drawable="@color/white" />
</selector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 共通机能-灰色[x]关闭按钮选择器 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/common_nav_close_grally_p" android:state_pressed="true"/>
<!-- <item android:drawable="@drawable/common_nav_fav_blue_c" android:state_checked="true"/> -->
<!-- <item android:drawable="@drawable/common_nav_fav_blue_c" android:state_selected="true"/> -->
<item android:drawable="@drawable/common_nav_close_grally_n"></item>
</selector>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- solid的表示填充颜色 -->
<solid android:color="#f4f4f4" />
<!-- stroke的表示描边 -->
<stroke
android:width="0.33dp"
android:color="#dddddd" />
<!-- <corners android:radius="5dp" /> -->
<!-- corners则是表示圆角bottomRightRadius是左下角而不是右下角bottomLeftRadius右下角 -->
<!-- <corners android:topLeftRadius="5dp" -->
<!-- android:topRightRadius="5dp" -->
<!-- android:bottomRightRadius="5dp" -->
<!-- android:bottomLeftRadius="5dp"/> -->
</shape>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- solid的表示填充颜色 -->
<solid android:color="#ffffff" />
<!-- stroke的表示描边 -->
<stroke
android:width="0.33dp"
android:color="#dddddd" />
<!-- <corners android:radius="5dp" /> -->
<!-- corners则是表示圆角bottomRightRadius是左下角而不是右下角bottomLeftRadius右下角 -->
<!-- <corners android:topLeftRadius="5dp" -->
<!-- android:topRightRadius="5dp" -->
<!-- android:bottomRightRadius="5dp" -->
<!-- android:bottomLeftRadius="5dp"/> -->
</shape>

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 共通机能-操作对话框[带关闭][带Item点击][带标题][带ICON] -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- 标题容器 -->
<RelativeLayout
android:id="@+id/rl_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F5F5F5"
android:paddingLeft="@dimen/common_padding_48px" >
<LinearLayout
android:id="@+id/ll_dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp" >
<TextView
android:id="@+id/tv_main_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="赠品详情"
android:textColor="#333333"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_sub_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="2款赠品"
android:textColor="#333333"
android:textSize="14sp"
android:visibility="gone" />
</LinearLayout>
<ImageButton
android:id="@+id/ib_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:src="@drawable/selector_common_grally_close_btn" />
</RelativeLayout>
<!-- 点击条目Item容器 -->
<ListView
android:id="@+id/lv_item_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_title"
android:cacheColorHint="@android:color/transparent"
android:divider="@null"
android:fadingEdge="none"
android:fadingEdgeLength="0dp"
android:listSelector="@drawable/selector_common_btn_white_grally_nobold"
android:overScrollMode="never"
android:scrollbars="none" />
<!-- 底部占位View -->
<RelativeLayout
android:id="@+id/rl_blank"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@+id/lv_item_list"
android:background="#F5F5F5" >
</RelativeLayout>
</RelativeLayout>

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 共通机能-操作对话框item条目布局 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@drawable/selector_common_btn_white_grally_nobold"
android:paddingLeft="@dimen/common_padding_48px"
>
<!-- 左侧标题 -->
<LinearLayout
android:id="@+id/ll_item_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_item_ltitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:maxLines="2"
android:text="定期理财"
android:textColor="#333333"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_item_ltitle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:maxLines="2"
android:text="免服务费"
android:textColor="#999999"
android:textSize="10sp" />
</LinearLayout>
<!-- 右侧标题+图标 -->
<LinearLayout
android:id="@+id/ll_item_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:layout_marginRight="@dimen/common_padding_48px"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_item_rtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="年化收益率3.7%"
android:textColor="#359df5"
android:textSize="14sp" />
<ImageButton
android:id="@+id/ib_item_right_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@android:color/transparent"
android:src="@drawable/arrow_normal" />
<ImageButton
android:id="@+id/ib_item_right_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@android:color/transparent"
android:src="@drawable/item_choose_icon" />
</LinearLayout>
<View
android:id="@+id/buttom_line"
android:layout_width="match_parent"
android:layout_height="0.33dp"
android:layout_alignParentBottom="true"
android:background="#dddddd"
android:visibility="visible" />
</RelativeLayout>

View File

@ -150,4 +150,7 @@
<color name="black_alpha">#70000000</color><!--黑色 --> <color name="black_alpha">#70000000</color><!--黑色 -->
<color name="black_05_alpha">#0C000000</color><!--5%黑色 --> <color name="black_05_alpha">#0C000000</color><!--5%黑色 -->
<color name="common_bg_color">#EFEFF4</color><!--共通灰色背景 --> <color name="common_bg_color">#EFEFF4</color><!--共通灰色背景 -->
<color name="grally_f4f4f4">#f4f4f4</color><!--共通灰色背景 -->
<color name="black_80_alpha">#cc000000</color>
</resources> </resources>

View File

@ -45,6 +45,31 @@
<item name="android:windowExitAnimation">@anim/view_kb_dialog_exit</item> <item name="android:windowExitAnimation">@anim/view_kb_dialog_exit</item>
</style> </style>
<!-- 操作对话框(开始) -->
<style name="OperationDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item><!-- 边框 -->
<item name="android:windowNoTitle">true</item><!-- 无标题 -->
<item name="android:windowIsTranslucent">false</item><!-- 是否透明 -->
<item name="android:windowIsFloating">true</item><!-- 是否浮现在activity之上 -->
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">@color/black_80_alpha</item><!-- 自己想要的背景 -->
<item name="android:backgroundDimEnabled">true</item><!-- 模糊 -->
<item name="android:windowAnimationStyle">@style/dialog_animation</item>
</style>
<style name="OperationDialogNoAnim" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item><!-- 边框 -->
<item name="android:windowNoTitle">true</item><!-- 无标题 -->
<item name="android:windowIsTranslucent">false</item><!-- 是否透明 -->
<item name="android:windowIsFloating">true</item><!-- 是否浮现在activity之上 -->
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">@color/black_80_alpha</item><!-- 自己想要的背景 -->
<item name="android:backgroundDimEnabled">true</item><!-- 模糊 -->
</style>
<!-- 操作对话框(结束) -->
<!-- 自定义dialog特效对话框样式开始 --> <!-- 自定义dialog特效对话框样式开始 -->
<style name="DialogWindowTitle"> <style name="DialogWindowTitle">
<item name="android:textSize">22sp</item> <item name="android:textSize">22sp</item>

View File

@ -0,0 +1,295 @@
package com.zftlive.android.library.widget;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.zftlive.android.R;
import com.zftlive.android.library.base.BaseEntity;
import com.zftlive.android.library.base.BaseMAdapter;
import java.util.List;
/**
* 自定义操作对话框
*
* @author 曾繁添
* @version 1.0
*
*/
public class OperationDialog extends Dialog {
/**
* 主标题副标题
*/
private TextView mMinTitleTV, mSubTitleTV;
/**
* 标题栏关闭按钮
*/
private ImageButton mTitleCloseBtn;
/**
* 选项列表List
*/
private ListView mItemList;
/**
* 标题栏底部占位View
*/
private RelativeLayout mDialogTitle, mButtomBlank;
/**
* 点击条目Item列表适配器
*/
private DialogItemAdapter mItemListAdapter;
/** 日志输出标志 **/
protected final static String TAG = OperationDialog.class.getSimpleName();
private boolean isShowTitle = true;
private String mMainTitle = "";
private String mSubTitle = "";
private boolean isShowClose = true;
private boolean isShowButtomBlank = true;
private List<ItemBean> mItemData;
private Activity mContext;
private AdapterView.OnItemClickListener mItemClickListener;
private OperationDialog(Builder mBuilder) {
super(mBuilder.mContext,gainResId(mBuilder.mContext, "style", "OperationDialog"));
setContentView(gainResId(mBuilder.mContext, "layout", "common_operation_dialog"));
//初始化界面
isShowTitle = mBuilder.isShowTitle;
mMainTitle = mBuilder.mMainTitle;
mSubTitle = mBuilder.mSubTitle;
isShowClose = mBuilder.isShowClose;
isShowButtomBlank = mBuilder.isShowButtomBlank;
mItemData = mBuilder.mItemData;
mContext = mBuilder.mContext;
mItemClickListener = mBuilder.mItemClickListener;
initView();
}
/**
* 初始化控件
*/
private void initView() {
mDialogTitle = (RelativeLayout) findViewById(gainResId(getContext(), "id", "rl_title"));
mDialogTitle.setVisibility(isShowTitle?View.VISIBLE:View.GONE);
mButtomBlank = (RelativeLayout) findViewById(gainResId(getContext(), "id", "rl_blank"));
mButtomBlank.setVisibility(isShowButtomBlank?View.VISIBLE:View.GONE);
mMinTitleTV = (TextView) findViewById(gainResId(getContext(), "id", "tv_main_title"));
mMinTitleTV.setText(mMainTitle);
mMinTitleTV.setVisibility(TextUtils.isEmpty(mMainTitle)?View.GONE:View.VISIBLE);
mSubTitleTV = (TextView) findViewById(gainResId(getContext(), "id", "tv_sub_title"));
mSubTitleTV.setText(mSubTitle);
mSubTitleTV.setVisibility(TextUtils.isEmpty(mSubTitle)?View.GONE:View.VISIBLE);
mTitleCloseBtn = (ImageButton) findViewById(gainResId(getContext(), "id", "ib_close"));
mTitleCloseBtn.setVisibility(isShowClose?View.VISIBLE:View.GONE);
mTitleCloseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isShowing()){
dismiss();
}
}
});
mItemList = (ListView) findViewById(gainResId(getContext(), "id", "lv_item_list"));
mItemListAdapter = new DialogItemAdapter(mContext);
mItemList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
mItemList.setAdapter(mItemListAdapter);
if(null != mItemData){
mItemListAdapter.addItem(mItemData);
mItemListAdapter.notifyDataSetChanged();
}
if(null != mItemClickListener){
mItemList.setOnItemClickListener(mItemClickListener);
}
}
/**
* 获取资源文件id
*
* @param mContext 上下文
* @param resType 资源类型drawable/string/layout/style/dimen/id/color/array等
* @param resName 资源文件名称
* @return
*/
private static int gainResId(Context mContext, String resType, String resName) {
int result = -1;
try {
String packageName = mContext.getPackageName();
result = mContext.getResources().getIdentifier(resName, resType, packageName);
} catch (Exception e) {
result = -1;
Log.w(TAG, "获取资源文件失败,原因:" + e.getMessage());
}
return result;
}
/**
* item点击列表Adapter
*
*/
class DialogItemAdapter extends BaseMAdapter {
public DialogItemAdapter(Activity mContext) {
super(mContext);
}
@Override
public View getView(int position, View itemView, ViewGroup parent) {
// 查找控件
ViewHolder holder = null;
if(null == itemView){
itemView = LayoutInflater.from(getActivity()).inflate(R.layout.common_operation_dialog_item, parent,false);
itemView.setBackgroundResource(R.drawable.selector_common_btn_white_grally_nobold);
holder = new ViewHolder();
holder.tv_item_ltitle1 = (TextView) itemView.findViewById(R.id.tv_item_ltitle1);
holder.tv_item_ltitle2 = (TextView) itemView.findViewById(R.id.tv_item_ltitle2);
holder.tv_item_rtitle1 = (TextView) itemView.findViewById(R.id.tv_item_rtitle1);
holder.ib_item_right_go = (ImageButton) itemView.findViewById(R.id.ib_item_right_go);
holder.ib_item_right_ok = (ImageButton) itemView.findViewById(R.id.ib_item_right_ok);
holder.buttom_line = itemView.findViewById(R.id.buttom_line);
//缓存View
itemView.setTag(holder);
}else {
holder = (ViewHolder) itemView.getTag();
}
//装填数据
final ItemBean rowData = (ItemBean)getItem(position);
holder.tv_item_ltitle1.setText(rowData.mLeftMainTitle);
holder.tv_item_ltitle1.setVisibility(TextUtils.isEmpty(rowData.mLeftMainTitle)?View.GONE:View.VISIBLE);
holder.tv_item_ltitle2.setText(rowData.mLeftSubTitle);
holder.tv_item_ltitle2.setVisibility(TextUtils.isEmpty(rowData.mLeftSubTitle)?View.GONE:View.VISIBLE);
holder.tv_item_rtitle1.setText(rowData.mRightMainTitle);
holder.tv_item_rtitle1.setVisibility(TextUtils.isEmpty(rowData.mRightMainTitle)?View.GONE:View.VISIBLE);
holder.ib_item_right_go.setVisibility(rowData.isShowGo?View.VISIBLE:View.GONE);
holder.ib_item_right_ok.setVisibility(rowData.isShowOkay?View.VISIBLE:View.GONE);
//最后一项时隐藏line
holder.buttom_line.setVisibility((position+1 == getCount())?View.GONE:View.VISIBLE);
return itemView;
}
class ViewHolder {
TextView tv_item_ltitle1,tv_item_ltitle2, tv_item_rtitle1 ;
ImageButton ib_item_right_go,ib_item_right_ok;
View buttom_line;
}
}
/**
* Item点击条目Bean
*
*/
public static class ItemBean extends BaseEntity{
private static final long serialVersionUID = -669966940645778118L;
/**
* Item左-主标题
*/
public String mLeftMainTitle;
/**
* Item左-副标题
*/
public String mLeftSubTitle;
/**
* Item右-主标题
*/
public String mRightMainTitle;
/**
* 是否显示右箭头图标( > )
*/
public Boolean isShowGo = true;
/**
* 是否显示正确对勾图标
*/
public Boolean isShowOkay = false;
}
/**
* Dialog构造器
*/
public static class Builder {
private boolean isShowTitle = true;
private String mMainTitle;
private String mSubTitle;
private boolean isShowClose = true;
private boolean isShowButtomBlank = true;
private Activity mContext;
private List<ItemBean> mItemData;
private AdapterView.OnItemClickListener mItemClickListener;
public Builder(Activity mContext) {
this.mContext = mContext;
}
public Builder showTitleClose(boolean isShow) {
this.isShowClose = isShow;
return this;
}
public Builder showTopHeader(boolean isShow) {
this.isShowTitle = isShow;
return this;
}
public Builder showButtomFooter(boolean isShow) {
this.isShowButtomBlank = isShow;
return this;
}
public Builder setMainTitle(String mMainTitle) {
this.mMainTitle = mMainTitle;
return this;
}
public Builder setSubTitle(String mSubTitle) {
this.mSubTitle = mSubTitle;
return this;
}
public Builder setItemData(List<ItemBean> mItemData){
this.mItemData = mItemData;
return this;
}
public Builder setItemClickListener(AdapterView.OnItemClickListener mItemClickListener){
this.mItemClickListener = mItemClickListener;
return this;
}
public OperationDialog build() {
return new OperationDialog(this);
}
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
@ -15,7 +16,13 @@ import com.zftlive.android.library.tools.ToolDateTime;
import com.zftlive.android.library.tools.ToolLocation; import com.zftlive.android.library.tools.ToolLocation;
import com.zftlive.android.library.tools.ToolPhone; import com.zftlive.android.library.tools.ToolPhone;
import com.zftlive.android.library.tools.ToolString; import com.zftlive.android.library.tools.ToolString;
import com.zftlive.android.library.tools.ToolToast;
import com.zftlive.android.library.widget.AlignTextView; import com.zftlive.android.library.widget.AlignTextView;
import com.zftlive.android.library.widget.OperationDialog;
import com.zftlive.android.library.widget.OperationDialog.ItemBean;
import java.util.ArrayList;
import java.util.List;
/** /**
* 基本常用操作测试样例 * 基本常用操作测试样例
@ -117,8 +124,44 @@ public class BasicTestActivity extends BaseActivity implements View.OnClickListe
break; break;
case R.id.btn_photo: case R.id.btn_photo:
// ToolPhone.toImagePickerActivity(getContext(), 77); // ToolPhone.toImagePickerActivity(getContext(), 77);
flag = false; // flag = false;
task.interrupt(); // task.interrupt();
//初始化Item数据
List<ItemBean> mItemData = new ArrayList<ItemBean>();
ItemBean item1 = new ItemBean();
item1.isShowGo = false;
item1.isShowOkay = true;
item1.mLeftMainTitle = "定期理财";
item1.mLeftSubTitle = "货币基金";
item1.mRightMainTitle = "年收益率6.5%";
mItemData.add(item1);
ItemBean item2 = new ItemBean();
item2.isShowGo = true;
item2.isShowOkay = false;
item2.mLeftMainTitle = "定期理财";
item2.mLeftSubTitle = "货币基金";
item2.mRightMainTitle = "年收益率6.5%";
mItemData.add(item2);
//创建一个Dialog
OperationDialog mDialog = new OperationDialog.Builder(this)
.setMainTitle("请选择购买的产品")
.setItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ItemBean rowData = (ItemBean) parent.getItemAtPosition(position);
ToolToast.showShort(getContext(), rowData.mLeftMainTitle + "-->"+position);
}
})
.setItemData(mItemData)
.build();
//展示Dialog
mDialog.setCanceledOnTouchOutside(false);
mDialog.show();
break; break;
default: default:
break; break;