hsiao 7 years ago
parent
commit
f977f9685b

+ 1
- 0
lesson01/src/main/java/io/hsiao/lesson01/MainActivity.java View File

78
     }
78
     }
79
 
79
 
80
     private void notifyToast(String msg) {
80
     private void notifyToast(String msg) {
81
+
81
         Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
82
         Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
82
     }
83
     }
83
 
84
 

+ 3
- 1
lesson02/src/main/AndroidManifest.xml View File

12
         <activity android:name=".MainActivity">
12
         <activity android:name=".MainActivity">
13
             <intent-filter>
13
             <intent-filter>
14
                 <action android:name="android.intent.action.MAIN" />
14
                 <action android:name="android.intent.action.MAIN" />
15
-
16
                 <category android:name="android.intent.category.LAUNCHER" />
15
                 <category android:name="android.intent.category.LAUNCHER" />
17
             </intent-filter>
16
             </intent-filter>
18
         </activity>
17
         </activity>
30
             </intent-filter>
29
             </intent-filter>
31
         </activity>
30
         </activity>
32
     </application>
31
     </application>
32
+    <uses-permission android:name="android.permission.INTERNET" />
33
+    <uses-permission android:name="android.permission.CALL_PHONE"/>
34
+    <uses-permission android:name="android.permission.CAMERA" />
33
 
35
 
34
 </manifest>
36
 </manifest>

+ 67
- 2
lesson02/src/main/java/io/hsiao/lesson02/MainActivity.java View File

7
 import android.util.Log;
7
 import android.util.Log;
8
 import android.view.Menu;
8
 import android.view.Menu;
9
 import android.view.MenuItem;
9
 import android.view.MenuItem;
10
+import android.view.View;
11
+import android.widget.AdapterView;
10
 import android.widget.ArrayAdapter;
12
 import android.widget.ArrayAdapter;
11
 import android.widget.ListView;
13
 import android.widget.ListView;
12
 import android.widget.SimpleAdapter;
14
 import android.widget.SimpleAdapter;
15
+import android.widget.TextView;
13
 import android.widget.Toast;
16
 import android.widget.Toast;
14
 
17
 
15
 import java.text.SimpleDateFormat;
18
 import java.text.SimpleDateFormat;
30
     protected void onCreate(Bundle savedInstanceState) {
33
     protected void onCreate(Bundle savedInstanceState) {
31
         super.onCreate(savedInstanceState);
34
         super.onCreate(savedInstanceState);
32
         setContentView(R.layout.activity_main);
35
         setContentView(R.layout.activity_main);
36
+        //获取应用栏
33
         Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar);
37
         Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar);
38
+        //设置应用栏
34
         setSupportActionBar(toolBar);
39
         setSupportActionBar(toolBar);
35
         Log.i("youmap", "MainActivity创建完成");
40
         Log.i("youmap", "MainActivity创建完成");
36
 
41
 
38
     }
43
     }
39
 
44
 
40
     private void createListView() {
45
     private void createListView() {
46
+        //获取ListView
41
         this.listView = (ListView) findViewById(R.id.main_listview);
47
         this.listView = (ListView) findViewById(R.id.main_listview);
42
-        this.listView.setAdapter(new SimpleAdapter(this, getData(), R.layout.home_list, new String[]{"title", "thumbnail", "date"}, new int[]{R.id.home_list_title, R.id.home_list_date, R.id.home_list_desc}));
48
+
49
+        /**
50
+         * <pre>
51
+         *   新建数据适配器。传入:
52
+         *   1: Activity实例,即this对象。
53
+         *   2: 数据内容
54
+         *   3:Item的布局
55
+         *   4:数据里对应布局的Key值
56
+         *   5:布局与数据对应的组件Id
57
+         * </pre>
58
+         *
59
+         */
60
+        SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.home_list, new String[]{"title", "thumbnail", "date"}, new int[]{R.id.home_list_title, R.id.home_list_date, R.id.home_list_desc});
61
+
62
+        /**
63
+         * 通过setAdapter方法,绑定数据和布局。
64
+         */
65
+        this.listView.setAdapter(adapter);
66
+
67
+        /**
68
+         * 绑定Item的click方法。
69
+         */
70
+        this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
71
+            /**
72
+             *
73
+             * @param parent
74
+             * @param view item控件,即整个Item的布局。
75
+             * @param position
76
+             * @param id
77
+             */
78
+            @Override
79
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
80
+                //在传入的Item布局里获取到需要的控件。
81
+                TextView txt = (TextView) view.findViewById(R.id.home_list_title);
82
+                Toast.makeText(MainActivity.this, txt.getText(), Toast.LENGTH_SHORT).show();
83
+
84
+                Intent intent = new Intent(MainActivity.this, MessageActivity.class);
85
+
86
+                startActivity(intent);
87
+            }
88
+        });
89
+
90
+        /**
91
+         * 绑定Item的长按方法。
92
+         */
93
+        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
94
+            @Override
95
+            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
96
+                Intent intent = new Intent();
97
+                intent.setAction(Intent.ACTION_SEND);
98
+                intent.putExtra(Intent.EXTRA_TEXT, "110");
99
+                intent.setType("text/plain");
100
+
101
+                if (intent.resolveActivity(getPackageManager()) != null) {
102
+                    startActivity(intent);
103
+                }
104
+
105
+                return true;
106
+            }
107
+        });
43
     }
108
     }
44
 
109
 
45
     private List<HashMap<String, Object>> getData() {
110
     private List<HashMap<String, Object>> getData() {
48
             HashMap<String, String> map = new HashMap<>();
113
             HashMap<String, String> map = new HashMap<>();
49
             map.put("title", "标题 " + i);
114
             map.put("title", "标题 " + i);
50
             map.put("thumbnail", "图片 " + i);
115
             map.put("thumbnail", "图片 " + i);
51
-            map.put("date", sdf.format(new Date()));
116
+            //map.put("date", sdf.format(new Date()));
52
 
117
 
53
             list.add(map);
118
             list.add(map);
54
         }
119
         }

+ 1
- 0
lesson02/src/main/java/io/hsiao/lesson02/UserCenterActivity.java View File

21
             public void onClick(View v) {
21
             public void onClick(View v) {
22
                 Intent intent = new Intent();
22
                 Intent intent = new Intent();
23
                 intent.setAction(Intent.ACTION_SEND);
23
                 intent.setAction(Intent.ACTION_SEND);
24
+                //intent.putExtra(Intent.EXTRA_TEXT,"13888888888");
24
                 intent.putExtra(Intent.EXTRA_TEXT,"Hi, 我是John,炒鸡帅男。我的Email是 John@gmail.com。");
25
                 intent.putExtra(Intent.EXTRA_TEXT,"Hi, 我是John,炒鸡帅男。我的Email是 John@gmail.com。");
25
                 intent.setType("text/plain");
26
                 intent.setType("text/plain");
26
 
27
 

+ 9
- 0
lesson02/src/main/res/drawable/ic_apps_black_24dp.xml View File

1
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+        android:width="24dp"
3
+        android:height="24dp"
4
+        android:viewportWidth="24.0"
5
+        android:viewportHeight="24.0">
6
+    <path
7
+        android:fillColor="#FF000000"
8
+        android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z"/>
9
+</vector>

+ 9
- 0
lesson02/src/main/res/drawable/ic_message_black_24dp.xml View File

1
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+        android:width="24dp"
3
+        android:height="24dp"
4
+        android:viewportWidth="24.0"
5
+        android:viewportHeight="24.0">
6
+    <path
7
+        android:fillColor="#FF000000"
8
+        android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/>
9
+</vector>

+ 9
- 0
lesson02/src/main/res/drawable/ic_search_black_24dp.xml View File

1
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+        android:width="24dp"
3
+        android:height="24dp"
4
+        android:viewportWidth="24.0"
5
+        android:viewportHeight="24.0">
6
+    <path
7
+        android:fillColor="#FF000000"
8
+        android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
9
+</vector>

+ 7
- 0
lesson02/src/main/res/layout/activity_user_center.xml View File

24
         android:layout_width="match_parent"
24
         android:layout_width="match_parent"
25
         android:layout_height="wrap_content"
25
         android:layout_height="wrap_content"
26
         android:text="分享我的名片" />
26
         android:text="分享我的名片" />
27
+
28
+    <TextView
29
+        android:id="@+id/usercenter_weblink"
30
+        android:layout_width="match_parent"
31
+        android:layout_height="wrap_content"
32
+        android:autoLink="web"
33
+        android:text="http://www.baidu.com" />
27
 </LinearLayout>
34
 </LinearLayout>

+ 3
- 1
lesson02/src/main/res/menu/menu.xml View File

3
 
3
 
4
     <item
4
     <item
5
         android:id="@+id/menu_item_message"
5
         android:id="@+id/menu_item_message"
6
-        android:title="消息"
6
+        android:icon="@drawable/ic_message_black_24dp"
7
         app:showAsAction="always" />
7
         app:showAsAction="always" />
8
     <item
8
     <item
9
         android:id="@+id/menu_item_mapps"
9
         android:id="@+id/menu_item_mapps"
10
+        android:icon="@drawable/ic_apps_black_24dp"
10
         android:title="微应用"
11
         android:title="微应用"
11
         app:showAsAction="always" />
12
         app:showAsAction="always" />
12
     <item
13
     <item
20
         android:title="通讯录" />
21
         android:title="通讯录" />
21
     <item
22
     <item
22
         android:id="@+id/menu_item_search"
23
         android:id="@+id/menu_item_search"
24
+        android:icon="@drawable/ic_search_black_24dp"
23
         android:title="搜索"
25
         android:title="搜索"
24
         app:showAsAction="always" />
26
         app:showAsAction="always" />
25
 </menu>
27
 </menu>

+ 1
- 1
lesson02/src/main/res/values/colors.xml View File

1
 <?xml version="1.0" encoding="utf-8"?>
1
 <?xml version="1.0" encoding="utf-8"?>
2
 <resources>
2
 <resources>
3
-    <color name="colorPrimary">#1f9cd6</color>
3
+    <color name="colorPrimary">#ff5722</color>
4
 </resources>
4
 </resources>

Loading…
Cancel
Save