Android 节日短信送祝福(UI篇:3-选择短信与发送短信的Activity的实现)
一、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的实现)的更多相关文章
- Android 节日短信送祝福(功能篇:1-数据库操作类与自定义ContentProvider)
首先,还是展示一下部分目录结构: 在节日短信送祝福的功能实现方面,为了能够方便直观展示实现过程,小编我以Java文件为基础,一个一个来展示,免得到时候这个java文件写点,一下又跳到另外一个java ...
- Android 节日短信送祝福(功能篇:2-短信历史记录Fragment的编写)
因为用于展示短信记录的是一个ListView,但是为了方便,可以直接继承自ListFragment,就可以免去写ListView对应的布局了,只需要写其item对应的布局即可. item_sended ...
- android: 接收和发送短信
8.2 接收和发送短信 收发短信应该是每个手机最基本的功能之一了,即使是许多年前的老手机也都会具备这 项功能,而 Android 作为出色的智能手机操作系统,自然也少不了在这方面的支持.每个 A ...
- Android开发之发送短信
本实例通过SmsManager的sendTextMessage方法实现发送短信关于SmsManager的具体解释大家能够參照:Android开发之SmsManager具体解释 实例执行效果图: 程序代 ...
- iOS摇一摇功能、震动功能、简单的摇动动画、生成二维码图片与发送短信等几个功能
有一个开锁的功能,具体的需求就类似于微信的"摇一摇"功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最 ...
- iOS中发送短信/发送邮件的实现 韩俊强的博客
需要引入框架: MessageUI.framework 布局如下: 短信和邮件: #import "ViewController.h" #import <MessageUI/ ...
- 在子线程中发送短信,静态注册SentMsgReceiver。
1. 应该在子线程中执行发送短信的操作. 如果没有在子线程中发送短信会出现错误:点击发送短信之后,立即跳转到其他界面,那么这次发送短信可能就会失败! 请注意往子线程方法中传入外部的实参必须由final ...
- iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等
有一个开锁的功能,具体的需求就类似于微信的“摇一摇”功能:摇动手机,手机震动,手机上的锁的图片摇动一下,然后发送开锁指令.需求简单,但用到了许多方面的知识. 1.摇一摇 相对这是最简单的功能了. 在v ...
- 个人永久性免费-Excel催化剂功能第85波-灵活便捷的批量发送短信功能(使用腾讯云接口)
微信时代的今天,短信一样不可缺席,大系统都有集成短信接口.若只是临时用一下,若能够直接在Excel上加工好内容就可以直接发送,这些假设在此篇批量群发短信功能中都为大家带来完美答案. 业务场景 不多说, ...
随机推荐
- 1.lombok系列1:初识lombok
转自:https://www.imooc.com/article/18156 初识lombok 官网:https://projectlombok.org/ 什么是lombok 连官网都懒得废话,只给出 ...
- Vue 打包后报错 Uncaught TypeError: Cannot redefine property: $router
原因:就如报错提示所描述的,不能重新定义$router,说明是重复定了$router.通常是因为在项目中安装了vue-router的依赖并且用Vue.use()使用了vue-router,还在inde ...
- 在 Swift 專案中使用 Javascript:編寫一個將 Markdown 轉為 HTML 的編輯器
原文:Using JavaScript in Swift Projects: Building a Markdown to HTML Editor 作者:GABRIEL THEODOROPOULOS ...
- LINUX设备驱动程序笔记(三)字符设备驱动程序
<一>.主设备号和次设备号 对字符设备的訪问时通过文件系统内的设备名称进行的.那些设备名称简单称之为文件系统树的节点,它们通常位于/dev文件夹. 字符设备驱动程 ...
- js无缝滚动原理及详解[转自刹那芳华]
刚刚接触JS,网上找了一些关于无缝滚动的教程,但都大同小异,对我这种新手来说也只是会用,不知道什么意思,想要自己写个更是一头雾水.于是找了一些资料,详细说明一下JS无缝滚动的原理,相信看过这篇文章之后 ...
- 1.1 Introduction中 Producers官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Producers 生产者(Producers) Producers publish ...
- FreeMarker template error: The following has evaluated to null or missing
使用freemarker前端分页,报错: FreeMarker template error: The following has evaluated to null or missing 后端直接赋 ...
- git在本地分支上 git pull远程分支时,状况
git 在pull或者合并分支的时候有时会遇到这个界面.可以不管(直接下面3,4步),如果要输入解释的话就需要: 1.按键盘字母 i 进入insert模式 2.修改最上面那行黄色合并信息,可以不修改 ...
- subline Text3 安装及汉化
因为自己的subline 有问题 所以决心重新改一下了. 三步: http://www.sublimetext.com/3 官网下载subline3 https://www.imjeff. ...
- 洛谷 P2095 营养膳食
洛谷 P2095 营养膳食 题目描述 Mr.L正在完成自己的增肥计划. 为了增肥,Mr.L希望吃到更多的脂肪.然而也不能只吃高脂肪食品,那样的话就会导致缺少其他营养.Mr.L通过研究发现:真正的营养膳 ...