一、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. holder.js如何使用

    holder.js的使用 一.总结 一句话总结:使用:holder.js后面接图片宽高 <img src="holder.js/300x200" /> 1.holder ...

  2. 4.dubbo-demo+简易监控中心安装+管理控制台安装

    转自:https://blog.csdn.net/zhangweigangweiwu/article/details/52244099 tomcat:apache-tomcat-6.0.39 需要用到 ...

  3. 将vue-cli 2.x的项目升级到3.x

    尝试将vue-cli 2.x的项目升级到3.x,记录一下升级过程,和遇到的坑 1. 直接复制替换src文件夹 2. 安装项目需要的依赖 (可以将原来package.json dependencies下 ...

  4. (转)Linux下使用rsync最快速删除海量文件的方法

    转自 : http://www.ha97.com/4107.html 昨天遇到了要在Linux下删除海量文件的情况,需要删除数十万个文件.这个是之前的程序写的日志,增长很快,而且没什么用.这个时候,我 ...

  5. 【习题 7-1 UVA-208】Firetruck

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 预处理一下终点能到达哪些点. 暴力就好. 输出结果的时候,数字之间一个空格.. [代码] /* 1.Shoud it use lon ...

  6. 用c实现的各种排序的方法

    #include <stdio.h> void swap(int *a, int *b); void bubble_sort(int a[], int n); void select_so ...

  7. event事件对象 兼容写法:var oEvent=ev||event;和取消事件冒泡

    要在整个页面添加事件要使用document,例如要捕抓鼠标位置 document.onclink=function(ev)  //FireFox Chrome默认都是有一个值传进来的 { var oE ...

  8. golang 获取环境信息

    os.Environ() os.Getenv("TMP")

  9. go package的理解

    golang package是基本的管理单元, 同一个package下面,可以有非常多的不同文件,只要 每个文件的头部    都有 如 "package xxx" 的相同name, ...

  10. 上拉刷新,下拉加载(JQuery)

    <script type="text/javascript">        $(document).ready(function() {            $(w ...