一、ChooseMsgActivity的实现 
1、布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.just.festival_sms.ChooseMsgActivity"> <ListView
android:id="@+id/id_lv_msgs"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView> <android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/id_fab_toSend"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/icon_to_send"
app:backgroundTint="#0ddcff"
app:borderWidth="0dp"
android:layout_marginBottom="@dimen/fab_margin">
</android.support.design.widget.FloatingActionButton> </RelativeLayout>

在这里布局中,需要注意两点(关于这两点,可以品味一下大神的博客 
http://blog.csdn.net/lmj623565791/article/details/46678867): 
① app:borderWidth="0dp" 如果不设置0dp,那么在4.1的sdk上 FAB 会显示为正方形,而且在5.0以后的sdk没有阴影效果。 
② 预期效果FloatingActionButton会距离屏幕底部有一定的距离,但在实际开发中,在4.0的手机上不用单独设置就可以达到预期效果 
但是在5.0的手机上如果不设置app:borderWidth的话会贴着手机的底部,没有预期的效果,因此在4.0和5.0的手机上设置的margin的值不能相同 
处理方法:在src/main/res/values/dimens.xml中添加一行<dimen name="fab_margin">0dp</dimen> (即默认的版本中) 
然后src/main/res下新建一个values-v21的文件夹,在里面新增一个dimens.xml文件 (即5.0时)

<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>

如图: 

以及ListView的item的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sms_item"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="@+id/id_tv_content"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:id="@+id/id_btn_toSend"
android:drawableLeft="@drawable/icon_to_send"
android:layout_gravity="right"
android:text="发送"/> </LinearLayout>

2、ChooseMsgActivity.Java

public class ChooseMsgActivity extends AppCompatActivity {

    private ListView mLvMsgs;
private FloatingActionButton mFabToSend;//点击之后转到编辑短信的界面 private ArrayAdapter<Msg> mAdapter; private LayoutInflater mInflater; private int mFestivalId; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choose_msg); mInflater=LayoutInflater.from(this); mFestivalId=getIntent().getIntExtra(FestivalCategoryFragment.ID_FESTIVAL,-); setTitle(FestivalLab.getInstance().getFestivalById(mFestivalId).getName()); initViews(); initEvent();
} private void initEvent() {
mFabToSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SendMsgActivity.toActivity(ChooseMsgActivity.this,mFestivalId,-);
}
});
} private void initViews() {
mLvMsgs= (ListView) findViewById(R.id.id_lv_msgs);
mFabToSend= (FloatingActionButton) findViewById(R.id.id_fab_toSend); mLvMsgs.setAdapter(mAdapter=new ArrayAdapter<Msg>(this,-,
FestivalLab.getInstance().getMsgsByFestivalId(mFestivalId)) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_msg, parent, false);
} TextView content = (TextView) convertView.findViewById(R.id.id_tv_content);
Button toSend = (Button) convertView.findViewById(R.id.id_btn_toSend); content.setText(" " + getItem(position).getContent());
toSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SendMsgActivity.toActivity(ChooseMsgActivity.this, mFestivalId, getItem(position).getId());
}
}); return convertView;
}
});
}
}

无论是点击FloatingActionButton还是选择LIstView中相应短信的Button都会跳转到SendMsgActivity,唯一的区别就是点击FloatingActionButton后在SendMsgActivity中的EditText中不会有事先加载好的祝福短信的内容,而是空白的。


二、SendMsgActivity的实现 
1、布局文件

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SendMsgActivity"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"> <EditText
android:id="@+id/id_et_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="180dp"
android:textSize="14sp"
android:background="@drawable/sms_item"
android:gravity="left|top"
android:textColor="#777"/> <Button
android:id="@+id/id_btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="添加联系人"/> <com.example.just.festival_sms.view.FlowLayout
android:id="@+id/id_fl_contacts"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.example.just.festival_sms.view.FlowLayout> </LinearLayout> <android.support.design.widget.FloatingActionButton
android:id="@+id/id_fab_send"
android:src="@drawable/icon_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="@dimen/fab_margin"
app:backgroundTint="#0ddcff"
app:borderWidth="0dp">
</android.support.design.widget.FloatingActionButton> <FrameLayout
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:id="@+id/id_layout_loading"
android:background="#33bbbbbb">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发送中..."
android:layout_gravity="center_vertical"/>
</LinearLayout>
</FrameLayout> </FrameLayout>

当显示id_layout_loading布局时,表明短信正在发送,要屏蔽用户的点击操作,所以要加上Android:clickable="true"但是默认是不显示的,在SendMsgActivity中通过setVisibility(View.GONE)实现

FlowLayout用于展示添加的联系人。

2、SendMsgActivity.java

public class SendMsgActivity extends AppCompatActivity {
public static final String KEY_ID_FESTIVAL="FestivalId";
public static final String KEY_ID_MSG="MsgId"; private int mFestivalId;
private int mMsgId; private Festival mFestival;
private Msg mMsg; private EditText mEdMsg;
private Button mBtnAdd;
private FlowLayout mFlContacts;
private FloatingActionButton mFabSend;
private View mLayoutLoading; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send_msg); initDatas(); initViews();
} private void initViews() {
mEdMsg= (EditText) findViewById(R.id.id_et_content);
mBtnAdd= (Button) findViewById(R.id.id_btn_add);
mFlContacts= (FlowLayout) findViewById(R.id.id_fl_contacts);
mFabSend= (FloatingActionButton) findViewById(R.id.id_fab_send);
mLayoutLoading=findViewById(R.id.id_layout_loading); mLayoutLoading.setVisibility(View.GONE);//隐藏mLayoutLoading if(mMsgId!=-) {
mMsg= FestivalLab.getInstance().getMsgByFestivalIdAndMsgId(mFestivalId,mMsgId);//这里不同于视频中的getMsgById(mMsgId)
mEdMsg.setText(mMsg.getContent());
}
} private void initDatas() {
mFestivalId=getIntent().getIntExtra(KEY_ID_FESTIVAL,-);
mMsgId=getIntent().getIntExtra(KEY_ID_MSG,-); mFestival=FestivalLab.getInstance().getFestivalById(mFestivalId);
setTitle(mFestival.getName());
} public static void toActivity(Context context, int festivalId, int msgId) {
Intent intent=new Intent(context,SendMsgActivity.class);
intent.putExtra(KEY_ID_FESTIVAL,festivalId);
intent.putExtra(KEY_ID_MSG,msgId);
context.startActivity(intent);
}
}

可以看到,在SendMsgActivity中有一个静态方法,用于从某个Activity跳转到SendMsgActivity,那么这样做有什么好处呢? 
答案,很简单,就是为了方便。因为从某个Activity跳转到SendMsgActivity所需要的参数是固定的且一定需要的,所以可以把方法写到目标的Activity类中(即SendMsgActivity),因此当某个Activity需要跳转到目标Activity时会比较容易,且参数不容易出错。

Android 节日短信送祝福(UI篇:3-选择短信与发送短信的Activity的实现)的更多相关文章

  1. Android 节日短信送祝福(功能篇:1-数据库操作类与自定义ContentProvider)

    首先,还是展示一下部分目录结构:  在节日短信送祝福的功能实现方面,为了能够方便直观展示实现过程,小编我以Java文件为基础,一个一个来展示,免得到时候这个java文件写点,一下又跳到另外一个java ...

  2. Android 节日短信送祝福(功能篇:2-短信历史记录Fragment的编写)

    因为用于展示短信记录的是一个ListView,但是为了方便,可以直接继承自ListFragment,就可以免去写ListView对应的布局了,只需要写其item对应的布局即可. item_sended ...

  3. android: 接收和发送短信

    8.2    接收和发送短信 收发短信应该是每个手机最基本的功能之一了,即使是许多年前的老手机也都会具备这 项功能,而 Android 作为出色的智能手机操作系统,自然也少不了在这方面的支持.每个 A ...

  4. Android开发之发送短信

    本实例通过SmsManager的sendTextMessage方法实现发送短信关于SmsManager的具体解释大家能够參照:Android开发之SmsManager具体解释 实例执行效果图: 程序代 ...

  5. iOS摇一摇功能、震动功能、简单的摇动动画、生成二维码图片与发送短信等几个功能

    有一个开锁的功能,具体的需求就类似于微信的"摇一摇"功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最 ...

  6. iOS中发送短信/发送邮件的实现 韩俊强的博客

    需要引入框架: MessageUI.framework 布局如下: 短信和邮件: #import "ViewController.h" #import <MessageUI/ ...

  7. 在子线程中发送短信,静态注册SentMsgReceiver。

    1. 应该在子线程中执行发送短信的操作. 如果没有在子线程中发送短信会出现错误:点击发送短信之后,立即跳转到其他界面,那么这次发送短信可能就会失败! 请注意往子线程方法中传入外部的实参必须由final ...

  8. iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等

    有一个开锁的功能,具体的需求就类似于微信的“摇一摇”功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最简单的功能了. 在v ...

  9. 个人永久性免费-Excel催化剂功能第85波-灵活便捷的批量发送短信功能(使用腾讯云接口)

    微信时代的今天,短信一样不可缺席,大系统都有集成短信接口.若只是临时用一下,若能够直接在Excel上加工好内容就可以直接发送,这些假设在此篇批量群发短信功能中都为大家带来完美答案. 业务场景 不多说, ...

随机推荐

  1. sql简单的语句

    选择:select * from table1 where 范围 插入:insert into table1(field1,field2) values(value1,value2) 删除:delet ...

  2. 内存卡(TF或其它)的标准

    内存卡(TF或其它)的标准 来源 https://zh.wikipedia.org/wiki/SDXC 一般的内存卡是SD2.0的规范的,就是 Class10(10M/sec)或低于 Class10 ...

  3. CISP/CISA 每日一题 12

    CISA 每日一题(答) 支付系统模式有哪些: 电子现金模式:支付者不必在线,无条件不可追溯性 电子支票模式:支付者不必在线,涉及个人隐私 电子转帐模式:收款人不必在线 图象处理中,应该有适当的___ ...

  4. 纯C++实现的HTTP请求封装(POST/GET)

    纯C++实现的HTTP请求(POST/GET),支持windows和linux, 进行简单的封装, 方便调用.实现如下: #include "HttpConnect.h" #ifd ...

  5. WebSocket兼容到低版本浏览器

    就目前而言,WebSocket是最好的Web通信解决方案了.但是IE从10才开始兼容它,对于目前大量IE8存在的市场,原生的WebSocket显然不太实用,我们需要低版本兼容的解决方案.于是我模拟We ...

  6. Python3的取余操作

    https://blog.csdn.net/u014647208/article/details/53368244 取余代码: 输入以下代码: >>>10%2 >>> ...

  7. Java web开发了解

    1.什么是Java web项目? F.A.Q: 服务器 服务器,也称伺服器,是提供计算服务的设备.由于服务器需要响应服务请求,并进行处理,因此一般来说服务器应具备承担服务并且保障服务的能力.服务器的构 ...

  8. C#集合类:动态数组、队列、栈、哈希表、字典

    1.动态数组:ArrayList 主要方法:Add.AddRange.RemoveAt.Remove 2.队列:Queue 主要方法:Enqueue入队列.Dequeue出队列.Peek返回Queue ...

  9. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  10. oracle主机名修改

    转自:http://www.cnblogs.com/tippoint/archive/2013/04/07/3003810.html 有的情况下,我们需要修改已经安装oracle数据库的主机名.以下是 ...