1.首先看一下效果

这是手机上显示的效果:

1.1首先是一个标题栏,左侧一个左箭头,然后一个图标。

1.2然后下方是一个可以滑动的页面。

1.3分成了7个部分。

1.4DiyCode的图标。

1.5然后是Diycode一个什么样的社区?

1.6我是谁?

1.7我爸爸?

1.8GcsSloop==>一个生活在2.5次元的魔法师。

1.9捐赠一杯咖啡。

1.10License

1.11--diycode--

2.分析一下布局文件

布局文件:activity_about.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. ~ Copyright 2017 GcsSloop
  4. ~
  5. ~ Licensed under the Apache License, Version 2.0 (the "License");
  6. ~ you may not use this file except in compliance with the License.
  7. ~ You may obtain a copy of the License at
  8. ~
  9. ~ http://www.apache.org/licenses/LICENSE-2.0
  10. ~
  11. ~ Unless required by applicable law or agreed to in writing, software
  12. ~ distributed under the License is distributed on an "AS IS" BASIS,
  13. ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ~ See the License for the specific language governing permissions and
  15. ~ limitations under the License.
  16. ~
  17. ~ Last modified 2017-03-25 02:42:10
  18. ~
  19. ~ GitHub: https://github.com/GcsSloop
  20. ~ Website: http://www.gcssloop.com
  21. ~ Weibo: http://weibo.com/GcsSloop
  22. -->
  23.  
  24. <RelativeLayout
  25. xmlns:android="http://schemas.android.com/apk/res/android"
  26. xmlns:tools="http://schemas.android.com/tools"
  27. android:id="@+id/activity_about"
  28. android:layout_width="match_parent"
  29. android:layout_height="match_parent"
  30. tools:context="com.gcssloop.diycode.activity.AboutActivity">
  31.  
  32. <android.support.v7.widget.Toolbar
  33. android:id="@+id/toolbar"
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"/>
  36.  
  37. <android.support.v4.widget.NestedScrollView
  38. android:layout_below="@id/toolbar"
  39. android:layout_width="match_parent"
  40. android:layout_height="match_parent">
  41.  
  42. <LinearLayout
  43. android:layout_width="match_parent"
  44. android:layout_height="match_parent"
  45. android:orientation="vertical">
  46.  
  47. <ImageView
  48. android:layout_width="match_parent"
  49. android:layout_height="50dp"
  50. android:layout_marginTop="30dp"
  51. android:src="@drawable/ic_logo"/>
  52.  
  53. <TextView
  54. android:layout_width="match_parent"
  55. android:layout_height="wrap_content"
  56. android:layout_marginTop="20dp"
  57. android:gravity="center"
  58. android:text="@string/about_diycode_title"
  59. android:textSize="16sp"
  60. android:textStyle="bold"/>
  61.  
  62. <TextView
  63. android:id="@+id/textView2"
  64. android:layout_width="match_parent"
  65. android:layout_height="wrap_content"
  66. android:padding="12dp"
  67. android:text="@string/about_diycode_desc"
  68. android:textSize="14sp"/>
  69.  
  70. <View
  71. android:layout_width="match_parent"
  72. android:layout_height="8dp"
  73. android:layout_marginBottom="10dp"
  74. android:background="@color/diy_white_bg"/>
  75.  
  76. <TextView
  77. android:layout_width="match_parent"
  78. android:layout_height="wrap_content"
  79. android:layout_marginTop="2dp"
  80. android:gravity="center"
  81. android:text="@string/about_me_title"
  82. android:textSize="16sp"
  83. android:textStyle="bold"/>
  84.  
  85. <RelativeLayout
  86. android:layout_width="match_parent"
  87. android:layout_height="wrap_content">
  88.  
  89. <TextView
  90. android:id="@+id/my_desc"
  91. android:layout_width="match_parent"
  92. android:layout_height="wrap_content"
  93. android:paddingLeft="12dp"
  94. android:paddingRight="12dp"
  95. android:paddingTop="12dp"
  96. android:text="@string/about_me_desc"
  97. android:textSize="14sp"/>
  98.  
  99. <TextView
  100. android:id="@+id/feed_back"
  101. android:layout_width="match_parent"
  102. android:layout_height="wrap_content"
  103. android:layout_below="@id/my_desc"
  104. android:gravity="center"
  105. android:paddingBottom="12dp"
  106. android:paddingTop="12dp"
  107. android:text="点击此处告状"
  108. android:textSize="10sp"/>
  109.  
  110. </RelativeLayout>
  111.  
  112. <View
  113. android:layout_width="match_parent"
  114. android:layout_height="8dp"
  115. android:layout_marginBottom="10dp"
  116. android:background="@color/diy_white_bg"/>
  117.  
  118. <TextView
  119. android:layout_width="match_parent"
  120. android:layout_height="wrap_content"
  121. android:layout_marginTop="2dp"
  122. android:gravity="center"
  123. android:text="@string/about_father"
  124. android:textSize="16sp"
  125. android:textStyle="bold"/>
  126.  
  127. <TextView
  128. android:layout_width="match_parent"
  129. android:layout_height="wrap_content"
  130. android:paddingLeft="12dp"
  131. android:paddingRight="12dp"
  132. android:paddingTop="12dp"
  133. android:text="@string/about_father_desc"
  134. android:textSize="14sp"/>
  135.  
  136. <View
  137. android:layout_width="match_parent"
  138. android:layout_height="8dp"
  139. android:layout_marginTop="12dp"
  140. android:background="@color/diy_white_bg"/>
  141.  
  142. <RelativeLayout
  143. android:id="@+id/github"
  144. android:layout_width="match_parent"
  145. android:layout_height="wrap_content"
  146. android:padding="12dp">
  147.  
  148. <ImageView
  149. android:id="@+id/image"
  150. android:layout_width="40dp"
  151. android:layout_height="40dp"
  152. android:layout_marginRight="12dp"
  153. android:src="@drawable/about_sloop"/>
  154.  
  155. <TextView
  156. android:id="@+id/name"
  157. android:layout_width="wrap_content"
  158. android:layout_height="wrap_content"
  159. android:layout_marginTop="2dp"
  160. android:layout_toRightOf="@+id/image"
  161. android:gravity="center"
  162. android:text="GcsSloop"
  163. android:textSize="16sp"
  164. android:textStyle="bold"/>
  165.  
  166. <TextView
  167. android:id="@+id/desc"
  168. android:layout_width="wrap_content"
  169. android:layout_height="wrap_content"
  170. android:layout_below="@+id/name"
  171. android:layout_marginTop="2dp"
  172. android:layout_toRightOf="@+id/image"
  173. android:gravity="center"
  174. android:text="一位生活在 2.5 次元的魔法师。"
  175. android:textSize="12sp"
  176. />
  177. </RelativeLayout>
  178.  
  179. <View
  180. android:layout_width="match_parent"
  181. android:layout_height="8dp"
  182. android:background="@color/diy_white_bg"/>
  183.  
  184. <TextView
  185. android:id="@+id/contribute"
  186. android:layout_width="match_parent"
  187. android:layout_height="wrap_content"
  188. android:layout_marginTop="2dp"
  189. android:gravity="center"
  190. android:padding="12dp"
  191. android:text="¥ 捐赠一杯咖啡"
  192. android:textColor="#4AC432"
  193. android:textSize="16sp"/>
  194.  
  195. <View
  196. android:layout_width="match_parent"
  197. android:layout_height="8dp"
  198. android:background="@color/diy_white_bg"/>
  199.  
  200. <TextView
  201. android:layout_width="match_parent"
  202. android:layout_height="wrap_content"
  203. android:layout_marginTop="12dp"
  204. android:gravity="center"
  205. android:text="License"
  206. android:textSize="16sp"
  207. android:textStyle="bold"/>
  208.  
  209. <TextView
  210. android:layout_width="match_parent"
  211. android:layout_height="wrap_content"
  212. android:padding="12dp"
  213. android:text="@string/about_license_desc"
  214. android:textSize="14sp"/>
  215.  
  216. <TextView
  217. android:layout_width="match_parent"
  218. android:layout_height="wrap_content"
  219. android:background="@color/diy_white_bg"
  220. android:gravity="center_horizontal"
  221. android:paddingBottom="16dp"
  222. android:paddingTop="12dp"
  223. android:text="-- diycode --"/>
  224. </LinearLayout>
  225.  
  226. </android.support.v4.widget.NestedScrollView>
  227.  
  228. </RelativeLayout>

外层:RelativeLayout

然后是一个Toolbar和一个NestedScrollView并列。

2.1.android.support.v7.widget.Toolbar

  参考一下这篇文章==>讲解了Toolbar

   

2.2.android.support.v4.widget.NestedScrollView

   不懂NestedScrollView,可以参考一下这篇文章。 

  

  浅黑色==>TabLayout

  深黑色==>NestedScrollView

3.实现抽象方法

3.1实现一个protected int getLayoutId()

  

  可以知道,这个关于的活动的布局名为:activity_about.

  它有一个toolbar。然后就是一些文字东西了。

  在BaseActivity中已经有关初始化ActivoinBar的东西了,因为只有一个返回的左箭头,所以就不需要其他东西了。

3.2实现一个initViews()

  直接调用了一个函数 setTitle("关于")==>在Activity中可以直接这样调用。

  如果想要为多个控件添加点击事件,可以参考一下源代码。

  第一张图是ViewHolder中的方法,第二张图是AboutActivity中实现BaseActivity中的抽象方法。

  

  

4.实现点击事件

4.1添加了添加事件后是不够的,还要做什么?

  所以这里实现了一个View.OnClickListener接口。所以这个AboutActivity被赋予了一个可以点击的功能。

4.2复写一个onClick函数,就是implements View.OnClickListener后必须要实现的方法。

  因为给3个资源id都赋予了可以被点击的权限,所以这3个资源id都要相应点击后的事件,这里采用了

  switch(v.getId())...case...case...case...

  截图如下:

  

  意思就是打开一个网页,前两个控件的点击事件都是打开一个网页(用默认的浏览器)

  后者的点击事件是转账,跳转到支付宝的转账的页面,而且已经确定好转账人。

5.看一下这个通用类IntentUtil

5.1==>上面点击事件用到了一个通用类IntentUtil,首先看看源代码。

  1. /*
  2. * Copyright 2017 GcsSloop
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. * Last modified 2017-03-28 04:45:19
  17. *
  18. * GitHub: https://github.com/GcsSloop
  19. * Website: http://www.gcssloop.com
  20. * Weibo: http://weibo.com/GcsSloop
  21. */
  22.  
  23. package com.gcssloop.diycode.utils;
  24.  
  25. import android.content.Context;
  26. import android.content.Intent;
  27. import android.net.Uri;
  28. import android.util.Log;
  29. import android.widget.Toast;
  30.  
  31. import com.gcssloop.diycode.utils.customtabs.CustomTabsHelper;
  32.  
  33. public class IntentUtil {
  34.  
  35. /**
  36. * 打开链接
  37. * 根据设置判断是用那种方式打开
  38. *
  39. * @param context 上下文
  40. * @param url url
  41. */
  42. public static void openUrl(Context context, String url) {
  43. // TODO Chrome Custom Tabs
  44. if (null == url || url.isEmpty()) {
  45. Log.i("Diyocde", "Url地址错误");
  46. return;
  47. }
  48. CustomTabsHelper.openUrl(context, url);
  49. }
  50.  
  51. /**
  52. * 打开支付宝
  53. */
  54. public static void openAlipay(Context context) {
  55. if (AppUtil.isAvailable(context, "com.eg.android.AlipayGphone")) {
  56. Intent intent = new Intent(Intent.ACTION_VIEW);
  57. String QRCode = "HTTPS://QR.ALIPAY.COM/FKX07101FYSJGTNCAPQW39";
  58. intent.setData(Uri.parse("alipayqr://platformapi/startapp?saId=10000007&qrcode=" + QRCode));
  59. context.startActivity(intent);
  60. } else {
  61. Toast.makeText(context, "你没有捐赠的权限", Toast.LENGTH_SHORT).show();
  62. }
  63. }
  64. }

5.2==>第一个函数打开链接

  

5.3==>分析一下CustomTabsHelper类

  

  这个类就一个函数,而且作用简单,就是打开一个网页,也不用做什么判断。

  我注释了一些东西,效果一样,对于我这台手机没有什么特殊的效果。

  有用的东西就是这三行吧!

  注意这个:CustomTabsIntent就是系统的一个类。

5.4==>分析第二个函数==>打开支付宝并转账

  

  先参考一下这篇文章吧!

  5.4.1.先搞一个支付宝账户的收钱的二维码

  5.4.2.在网站上进入:二维码扫描器

  5.4.3.得到一个支付宝收钱的QRCode==>HTTPS://QR.ALIPAY.COM/FKX02087VITTLOP18Z8F9D

  5.4.4.然后就可以进行intent跳转了。这里采用的是intent.setData(Uri.parse(...));

  5.4.5.注意了,这里Uri必须是这个了,才能打开支付宝,把QRCode换成自己的就可以了。

  5.4.6.注意了,实现要判断手机有没有安装支付宝,支付宝的包名是:com.eg.android.AlipayGphone

6.总结一下

6.1.可以说,AboutActivity是这个项目最简单的一个活动了。其实懂了就应该从简单的开始,这样才能更好地由浅入深

  不然直接入木三分后出不来了。

6.2.知道了为什么会在BaseActivity中定义两个抽象函数。getLayoutId就是获得一个整体的布局文件,包括toolbar,

  我曾经以为toolbar仅仅在BaseActivity中定义就好了,其他活动继承后就不管了,其实不是这样的,它可以在

  BaseActivity中直接添加点击事件,反正名字对应上就好。所以在AboutActivity中,根本看不到back的点击事件。

6.3.在AboutActivity中必须要实现两个抽象函数,其中有一个是initViews,作用很明显,首先是设置标题“关于”,

  现在知道了要在这里设置了,而且有一个给多个资源id添加监听事件学到了,采用int...这里可以无限个参数。

6.4.然后就是知道了它是如何调转到一个网页的。采用了一个通用类,因为很多情况下都要跳转到一个网页嘛,所以这里

  直接就封装起来了。首先判断url是否为null或者为空,然后利用CustomTabsIntent.Builder,来lauchUrl网址即可。

6.5.最后知道了如何打开支付宝,并给某人转账。首先要得到一个二维码,然后解析,生成一个URL,这里称之为QRCode,

  然后intent.setData(Url.parse(...))这个网址就可以了。学到了判断是否安装某个应用。详情参考一下上文即可。

DiyCode开源项目 AboutActivity分析的更多相关文章

  1. Diycode开源项目 BaseApplication分析+LeakCanary第三方+CrashHandler自定义异常处理

    1.BaseApplication整个应用的开始 1.1.看一下代码 /* * Copyright 2017 GcsSloop * * Licensed under the Apache Licens ...

  2. DiyCode开源项目 BaseActivity 分析

    1.首先将这个项目的BaseActivity源码拷贝过来. /* * Copyright 2017 GcsSloop * * Licensed under the Apache License, Ve ...

  3. Diycode开源项目 MainActivity分析

    1.分析MainActivity整体结构 1.1.首先看一下这个界面的整体效果. 1.2.活动源代码如下 /* * Copyright 2017 GcsSloop * * Licensed under ...

  4. Diycode开源项目 ImageActivity分析

    1.首先看一下效果 1.1做成了一个GIF 1.2.我用格式工厂有点问题,大小无法调到手机这样的大小,目前还没有解决方案. 1.3.网上有免费的MP4->GIF,参考一下这个网站吧. 1.4.讲 ...

  5. Diycode开源项目 UserActivity分析

    1.效果预览 1.1.实际界面预览 1.2. 这是MainActivity中的代码 这里执行了跳转到自己的用户界面的功能. 1.3.点击头像或者用户名跳转到别人的页面 UserActivity的结构由 ...

  6. Diycode开源项目 TopicContentActivity分析

    1.效果预览以及布局分析 1.1.实际效果预览 左侧话题列表的布局是通过TopicProvider来实现的,所以当初分析话题列表就没有看到布局. 这里的话题内容不是一个ListView,故要自己布局. ...

  7. Diycode开源项目 LoginActivity分析

    1.首先看一下效果 1.1.预览一下真实页面 1.2.分析一下: 要求输入Email或者用户名,点击编辑框,弹出键盘,默认先进入输入Email或用户名编辑框. 点击密码后,密码字样网上浮动一段距离,E ...

  8. DiyCode开源项目 TopicActivity 分析

    1.首先看看TopActivity效果.    2.TopicActivity是一个继承BaseActivity的.前面分析过BaseActivity了.主要有一个标题栏,有返回的图标. 3.贴一下T ...

  9. Diycode开源项目 SitesListFragment分析

    1.效果预览 1.1.网站列表实际界面 1.2.注意这个界面没有继承SimpleRefreshRecycleFragment 前面的话题和新闻继承了SimpleRefreshRecyclerFragm ...

随机推荐

  1. webpack实用小功能介绍

    1.overlay overlay属于devServer的属性,配置案例如下: ? 1 2 3 4 5 6 devServer: {  overlay: {   errors: true,   war ...

  2. [转]git修改远程仓库地址

    原文链接:http://www.cnblogs.com/lazb/articles/5597878.html 问:Coding远程仓库地址变了,本地git仓库地址如何更新为最新地址 git修改远程仓库 ...

  3. Cypress测试工具

    参考博客:  https://testerhome.com/articles/19035 最近一段时间学习了cypress的测试工具, 她是一个端到端的测试web工具. 环境准备 1.工具:vs co ...

  4. ConcurrentHashMap源码刨析(基于jdk1.7)

    看源码前我们必须先知道一下ConcurrentHashMap的基本结构.ConcurrentHashMap是采用分段锁来进行并发控制的. 其中有一个内部类为Segment类用来表示锁.而Segment ...

  5. The 12th Zhejiang Provincial Collegiate Programming Contest - I Earthstone Keeper浙江省赛

    题目:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5501 思路:DFS,用了递归就溢出,所以可能得用非递归的. ...

  6. 判断一个字符串是否为GUID的方法

    在.net4.0后出现的TryParse方法可以完成这件事情,至于4.0之前的话,也只能是guid.parse()这个方法加上异常去判断了. 方法具体如下: Guid newGuid = Guid.E ...

  7. 2018.10.03 NOIP+ 模拟赛 解题报告

    得分: \(30+5+0=35\)(考得真不咋滴) \(T1\):奥义商店(点此看题面) 以为很简单,对着这题想了一个多小时,最后果断打了个暴力交了... ... 看完题解发现其实也不是很难. 对于\ ...

  8. 【BZOJ1972】[SDOI2010] 猪国杀(恶心的大模拟)

    点此看题面 大致题意: 让你模拟一个游戏猪国杀的过程. 几大坑点 对于这种模拟题,具体思路就不讲了,就说说有哪些坑点. 题面有锅,反猪是\(FP\). 数据有锅,牌堆中的牌可能不够用,牌堆为空之后需一 ...

  9. Luogu P5008 逛庭院

    题目传送门 我校神仙出的神仙题 \(\%\%\%\) 30分 找出所有有入度的点,排序,选前\(k\)个点,好了,30分到手. #include<iostream> #include< ...

  10. Activiti学习记录(一)

    1.工作流的概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档.信息或任务的过程自动进行,从而实现 ...