udacity android 实践笔记: lesson 4 part a


作者:干货店打杂的 /titer1 /Archimedes

出处:https://code.csdn.net/titer1

联系:1307316一九六八(短信最佳)

声明:本文採用下面协议进行授权: 自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 ,转载请注明作者及出处。

tips:https://code.csdn.net/titer1/pat_aha/blob/master/Markdown/android/


序言

this is weekend time
last time ,we have learn form the video
and now ,we are run the code directly.
let us go. thanks jackson
版本号变化的
rs232 uart txd rxd clk 115200 10k
usb
at least 5 ,传输类型
1.0 fullspeded <10M
2.0 highspeedd, 30M? 720p 20fps
printer more high than uvc
usb mass storage ..dirver-inside
3.0 >100M i2c
2 line .clk data
400k bps,命令
是否是 fake data,看看 数据里面 有没有 traped in weather station,就知道当前情况了

其它 四大组件

service

broad

content provider

activity

4.01 life cycle





以上介绍了 声明周期

。! 动手笔记 生命周期

看activity的生命周期,就是

看 mainActivity的logcat,非常清楚

操作布凑

进入mainActivity –> detail Activity –>回到 mainActivity

还有 Main Activity –> seting –>切回

为什么能够看到如上的提示,根本原因是有代码logcat,
全部的activity life cycle hanlders

overviw 图



- contract

- db builder

- content provider 四大组件之中的一个

4.02 第四章最基础的代码框架



- 完整的測试框架

- 加入了 location weather的contract

- 加入了 location weather相关的 sql builder

4.03 定义 数据库表项 for location

contract解释

/**
* Defines table and column names for the weather database.
*/

就是定义 表格内容

这里的更新就是 添加了

location table 的列内容定义

4.04 完好 location database

- 目标 測试 weather 数据库 创建 /插入

在数据库初始化代码处。

也就是 weatherDbHelper的位置,

仿照 weather database的创建。

加入下面代码

public class WeatherDbHelper extends SQLiteOpenHelper {
static final String DATABASE_NAME = "weather.db";
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) { final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +
LocationEntry._ID + " INTEGER PRIMARY KEY," +
LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL, " +
LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +
LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL, " +
LocationEntry.COLUMN_COORD_LONG + " REAL NOT NULL " +
" );";
...
sqLiteDatabase.execSQL(SQL_CREATE_LOCATION_TABLE);//新加入的
sqLiteDatabase.execSQL(SQL_CREATE_WEATHER_TABLE);

使能数据库创建測试程序 testCreateDb

程序介绍

        Students: Uncomment this test once you've written the code to create the Location
table. Note that you will have to have chosen the same column names that I did in my solution for this test to compile, so if you haven't yet done that, this is
a good time to change your column names to match mine. Note that this only tests that the Location table has the correct columns, since we
give you the code for the weather table. This test does not look at the

使能 test utilites


/*
Students: You can uncomment this helper function once you have finished creating the
LocationEntry part of the WeatherContract.
*/
static ContentValues createNorthPoleLocationValues() {
// Create a new map of values, where column names are the keys
ContentValues testValues = new ContentValues();
testValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, TEST_LOCATION);
testValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, "North Pole");
testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, 64.7488);
testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, -147.353); return testValues;
} /*
Students: You can uncomment this function once you have finished creating the
LocationEntry part of the WeatherContract as well as the WeatherDbHelper.
*/
static long insertNorthPoleLocationValues(Context context) {
// insert our test records into the database
WeatherDbHelper dbHelper = new WeatherDbHelper(context);//
我的认识。这里会创建一个表
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues testValues = TestUtilities.createNorthPoleLocationValues(); long locationRowId;
locationRowId = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, testValues);
//这里将測试表的插入 // Verify we got a row back.
assertTrue("Error: Failure to insert North Pole Location Values", locationRowId != -1); return locationRowId;
}

上面三处文件更新

4.05 test Location Table

这里 近一处 更新

能够从 凝视里面进一步完好本小节内容

下面小节的内容将会被充实代码



  /*
Students: Here is where you will build code to test that we can insert and query the location database.
We've done a lot of work for you. You'll want to look in TestUtilitie
where you can uncomment out the "createNorthPoleLocationValues" function. You can also make use of the ValidateCurrentRecord function from within TestUtilities.
*/
public void testLocationTable() {
// First step: Get reference to writable database // Create ContentValues of what you want to insert
// (you can use the createNorthPoleLocationValues if you wish) // Insert ContentValues into database and get a row ID back // Query the database and receive a Cursor back // Move the cursor to a valid database row // Validate data in resulting Cursor with the original ContentValues
// (you can use the validateCurrentRecord function in TestUtilities to validate the
// query if you like) // Finally, close the cursor and database }``` ### 6步 測试table(insert/quiery ...)
全部更新的代码在此
``` java
public void testLocationTable() { // First step: Get reference to writable database
// If there's an error in those massive SQL table creation Strings,
// errors will be thrown here when you try to get a writable database.
WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
SQLiteDatabase db = dbHelper.getWritableDatabase(); // Second Step: Create ContentValues of what you want to insert
// (you can use the createNorthPoleLocationValues if you wish)
ContentValues testValues = TestUtilities.createNorthPoleLocationValues(); // Third Step: Insert ContentValues into database and get a row ID back
long locationRowId;
locationRowId = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, testValues); // Verify we got a row back.
assertTrue(locationRowId != -1); // Data's inserted. IN THEORY. Now pull some out to stare at it and verify it made
// the round trip. // Fourth Step: Query the database and receive a Cursor back
// A cursor is your primary interface to the query results.
Cursor cursor = db.query(
WeatherContract.LocationEntry.TABLE_NAME, // Table to Query
null, // all columns
null, // Columns for the "where" clause
null, // Values for the "where" clause
null, // columns to group by
null, // columns to filter by row groups
null // sort order
); // Move the cursor to a valid database row and check to see if we got any records back
// from the query
assertTrue( "Error: No Records returned from location query", cursor.moveToFirst() ); // Fifth Step: Validate data in resulting Cursor with the original ContentValues
// (you can use the validateCurrentRecord function in TestUtilities to validate the
// query if you like)
TestUtilities.validateCurrentRecord("Error: Location Query Validation Failed",
cursor, testValues); // Move the cursor to demonstrate that there is only one record in the database
assertFalse( "Error: More than one record returned from location query",
cursor.moveToNext() ); // Sixth Step: Close Cursor and Database
cursor.close();
db.close();
} <div class="se-preview-section-delimiter"></div>

!! todo 效果截图

这处 等待网络 联通后,应该有 详细的效果图展示,

初步看到这里有若干的assert

//执行方法:lesson 4a 28 - SQLiteOpenHelper and Sunshine Database.mp4中

我把 问题的环境 执行方法 已经 整理。待后期更新

4.06 test weather table

和上面一样,改动的唯独 testDb.java

编辑器里面 有 主题切换。能够后界面颜色 ,字体,保护眼睛。你懂的

<div class="se-preview-section-delimiter"></div>
  • 不只像上面 又一次 写了一个 test*****talbe的函数。
  • 在testWeatherTalbe程序中,先调用了 testLoactionTalbe的代码,

    该代码被封装起来为insertLocation。事实上内容就是 testLocationTable

  • 函数的返回值是 相应项目 query后的rowid 。

两者衔接的代码例如以下,

        long locationRowId = insertLocation();

        // Second Step (Weather): Create weather values
ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId); //*.insert //*.query <div class="se-preview-section-delimiter"></div>
至于是否起到 外键的作用。待证明

小憩时间

至此。逻辑正确的话。两个数据表格都測到測试

未来目标是 4.24..还有非常多。



- 给出初步的 创建 weather表的表框架

- 创建 location 表

- 填充 test location

- 填充 test weather location (insert query …,调用了 testlocation的结果)

一句话 ,期中 4.06是一个 小的 里程碑

udacity android 实践笔记: lesson 4 part a的更多相关文章

  1. udacity android 实践笔记: lesson 4 part b

    udacity android 实践笔记: lesson 4 part b 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...

  2. udacity android 学习笔记: lesson 4 part b

    udacity android 学习笔记: lesson 4 part b 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...

  3. udacity android 学习笔记: lesson 4 part a

    udacity android 学习笔记: lesson 4 part a 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...

  4. Udacity调试课笔记之断言异常

    Udacity调试课笔记之断言异常 这一单元的内容不是很多,如Zeller教授所说,就是如何写.检查断言,并如何使用工具实现自动推导出断言的条件. 现在,多数的编程语言,尤其是高级编程语言都会有内置的 ...

  5. android 应用笔记

    android 应用笔记 android 应用笔记 小书匠 Android 综合教程 Android常用技巧 安卓系统架构 安卓源码开发 安卓驱动 Linux内核 安卓应用开发 Java 教程 tic ...

  6. Android 学习笔记之Volley(七)实现Json数据加载和解析...

    学习内容: 1.使用Volley实现异步加载Json数据...   Volley的第二大请求就是通过发送请求异步实现Json数据信息的加载,加载Json数据有两种方式,一种是通过获取Json对象,然后 ...

  7. Android开发笔记:打包数据库

    对于数据比较多的控制一般会加入SQLite数据库进行数据存储,在打包时这些数据库是不自动打包到apk中的,如何创建数据库呢 方法1:将创建数据库的sql语句在SQLiteHelper继承类中实现,在第 ...

  8. Android学习笔记进阶之在图片上涂鸦(能清屏)

    Android学习笔记进阶之在图片上涂鸦(能清屏) 2013-11-19 10:52 117人阅读 评论(0) 收藏 举报 HandWritingActivity.java package xiaos ...

  9. android学习笔记36——使用原始XML文件

    XML文件 android中使用XML文件,需要开发者手动创建res/xml文件夹. 实例如下: book.xml==> <?xml version="1.0" enc ...

随机推荐

  1. 《深入理解java虚拟机》学习笔记四/垃圾收集器GC学习/一

    Grabage Collection      GC GC要完毕的三件事情: 哪些内存须要回收? 什么时候回收? 怎样回收? 内存运行时区域的各个部分中: 程序计数器.虚拟机栈.本地方法栈这3个区域随 ...

  2. hdu 1003 Max Sum 最大字段和 dp

    今天看了一上午dp.看不太懂啊.dp确实不简单.今天開始学习dp,搜了杭电的dp46道,慢慢来吧.白书上的写的 又不太具体,先写几道题目再说. .. 题目连接:id=516&page=1&qu ...

  3. 「微信小程序」有哪些冲击与机会?

    昨天晚上相信大家的朋友圈被「微信小程序」刷屏了,这影响力赶上了国务院出台新政策一样,足以说明微信在中国的影响力之大. 然后今天公号后台一大堆人问我怎么看这件事,不少人非常忧虑,仿佛自己将要失业一样. ...

  4. ReactJs 入门DEMO(转自别人)

    附件是分享的一些他人的ReactJs入门DEMO,以前版本使用的是JSXTransformer.js,新版的用browser.min.js替代了. DEMO 下载地址:http://files.cnb ...

  5. jodd-servlet工具集锦

    Jodd提供了许多servlet和jsp相关的工具. Utils ServletUtils类集成了不同的servlet工具,你可以检测multipart请求,读取授权头,下载预备,cookie操作,读 ...

  6. 暴力破解FTP服务器技术探讨与防范措施

    暴力破解FTP服务器技术探讨与防范措施 随着Internet的发展出现了由于大量傻瓜化黑客工具任何一种黑客攻击手段的门槛都降低了很多但是暴力破解法的工具制作都已经非常容易大家通常会认为暴力破解攻击只是 ...

  7. Tuple<int, int> Dictionary<string, object>妙用

    Tuple<int, int> Dictionary<string, object>妙用

  8. BZOJ1009: [HNOI2008]GT考试(KMP+矩阵乘法)

    Description 阿申准备报名参加GT考试,准考证号为N位数X1X2....Xn(0<=Xi<=9),他不希望准考证号上出现不吉利的数字.他的不吉利数学A1A2...Am(0< ...

  9. java 钩子方法

    Runtime.getRuntime().addShutdownHook(shutdownHook);    这个方法的含义说明:        这个方法的意思就是在jvm中增加一个关闭的钩子,当jv ...

  10. 终于研究出如何设置新版paypal付款时汇率损失方的问题了

    http://bbs.55haitao.com/thread-1686005-1-1.html 终于研究出如何设置新版paypal付款时汇率损失方的问题了 登录paypal后,选"设置&qu ...