Procházet zdrojové kódy

Merge branch 'refs/heads/lesson-02'

hsiao před 7 roky
rodič
revize
198cbf04f8

+ 6
- 0
.idea/vcs.xml Zobrazit soubor

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 5
- 1
app/src/main/AndroidManifest.xml Zobrazit soubor

@@ -7,7 +7,8 @@
7 7
         android:icon="@mipmap/ic_launcher"
8 8
         android:label="@string/app_name"
9 9
         android:roundIcon="@mipmap/ic_launcher_round"
10
-        android:supportsRtl="true">
10
+        android:supportsRtl="true"
11
+        android:theme="@style/appTheme">
11 12
         <activity android:name=".MainActivity">
12 13
             <intent-filter>
13 14
                 <action android:name="android.intent.action.MAIN" />
@@ -15,6 +16,9 @@
15 16
                 <category android:name="android.intent.category.LAUNCHER" />
16 17
             </intent-filter>
17 18
         </activity>
19
+        <activity android:name=".MessageActivity" />
20
+        <activity android:name=".UserCenterActivity" />
21
+        <activity android:name=".MicroAppsActivity"></activity>
18 22
     </application>
19 23
 
20 24
 </manifest>

+ 80
- 3
app/src/main/java/io/hsiao/youmap/MainActivity.java Zobrazit soubor

@@ -1,14 +1,91 @@
1 1
 package io.hsiao.youmap;
2 2
 
3
-import android.app.Activity;
4
-import android.support.v7.app.AppCompatActivity;
3
+import android.content.Intent;
5 4
 import android.os.Bundle;
5
+import android.support.v7.app.AppCompatActivity;
6
+import android.support.v7.widget.Toolbar;
7
+import android.util.Log;
8
+import android.view.Menu;
9
+import android.view.MenuItem;
10
+import android.widget.ArrayAdapter;
11
+import android.widget.ListView;
12
+import android.widget.SimpleAdapter;
13
+import android.widget.Toast;
14
+
15
+import java.text.SimpleDateFormat;
16
+import java.util.ArrayList;
17
+import java.util.Date;
18
+import java.util.HashMap;
19
+import java.util.List;
20
+import java.util.Map;
21
+import java.util.Objects;
6 22
 
7
-public class MainActivity extends Activity {
23
+public class MainActivity extends AppCompatActivity {
24
+
25
+    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
26
+    private ListView listView;
8 27
 
9 28
     @Override
10 29
     protected void onCreate(Bundle savedInstanceState) {
11 30
         super.onCreate(savedInstanceState);
12 31
         setContentView(R.layout.activity_main);
32
+        Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar);
33
+        setSupportActionBar(toolBar);
34
+        Log.i("youmap", "MainActivity创建完成");
35
+
36
+        this.createListView();
37
+    }
38
+
39
+    private void createListView() {
40
+        this.listView = (ListView) findViewById(R.id.main_listview);
41
+        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}));
42
+    }
43
+
44
+    private List<HashMap<String, Object>> getData() {
45
+        ArrayList list = new ArrayList();
46
+        for(int i=0;i<100;i++){
47
+            HashMap<String,String> map = new HashMap<>();
48
+            map.put("title","标题 "+i);
49
+            map.put("thumbnail","图片 "+i);
50
+            map.put("date", sdf.format(new Date()));
51
+
52
+            list.add(map);
53
+        }
54
+        return list;
55
+    }
56
+
57
+    @Override
58
+    public boolean onCreateOptionsMenu(Menu menu) {
59
+        getMenuInflater().inflate(R.menu.menu, menu);
60
+        return true;
61
+    }
62
+
63
+    @Override
64
+    public boolean onOptionsItemSelected(MenuItem item) {
65
+        Toast.makeText(this.getApplicationContext(), item.getTitle() + " " + item.getItemId(), Toast.LENGTH_LONG).show();
66
+        Intent intent = null;
67
+        switch (item.getItemId()) {
68
+            case R.id.menu_item_about:
69
+                intent = new Intent(this, MessageActivity.class);
70
+                break;
71
+            case R.id.menu_item_account:
72
+                intent = new Intent(this, UserCenterActivity.class);
73
+                break;
74
+            case R.id.menu_item_contacts:
75
+                intent = new Intent(this, MessageActivity.class);
76
+                break;
77
+            case R.id.menu_item_mapps:
78
+                intent = new Intent(this, MicroAppsActivity.class);
79
+                break;
80
+            case R.id.menu_item_message:
81
+                intent = new Intent(this, MessageActivity.class);
82
+                break;
83
+            case R.id.menu_item_search:
84
+                intent = new Intent(this, MessageActivity.class);
85
+                break;
86
+        }
87
+        startActivity(intent);
88
+
89
+        return true;
13 90
     }
14 91
 }

+ 14
- 0
app/src/main/java/io/hsiao/youmap/MessageActivity.java Zobrazit soubor

@@ -0,0 +1,14 @@
1
+package io.hsiao.youmap;
2
+
3
+import android.app.Activity;
4
+import android.support.v7.app.AppCompatActivity;
5
+import android.os.Bundle;
6
+
7
+public class MessageActivity extends Activity {
8
+
9
+    @Override
10
+    protected void onCreate(Bundle savedInstanceState) {
11
+        super.onCreate(savedInstanceState);
12
+        setContentView(R.layout.activity_message);
13
+    }
14
+}

+ 13
- 0
app/src/main/java/io/hsiao/youmap/MicroAppsActivity.java Zobrazit soubor

@@ -0,0 +1,13 @@
1
+package io.hsiao.youmap;
2
+
3
+import android.app.Activity;
4
+import android.os.Bundle;
5
+
6
+public class MicroAppsActivity extends Activity {
7
+
8
+    @Override
9
+    protected void onCreate(Bundle savedInstanceState) {
10
+        super.onCreate(savedInstanceState);
11
+        setContentView(R.layout.activity_micro_apps);
12
+    }
13
+}

+ 13
- 0
app/src/main/java/io/hsiao/youmap/UserCenterActivity.java Zobrazit soubor

@@ -0,0 +1,13 @@
1
+package io.hsiao.youmap;
2
+
3
+import android.app.Activity;
4
+import android.os.Bundle;
5
+
6
+public class UserCenterActivity extends Activity {
7
+
8
+    @Override
9
+    protected void onCreate(Bundle savedInstanceState) {
10
+        super.onCreate(savedInstanceState);
11
+        setContentView(R.layout.activity_user_center);
12
+    }
13
+}

+ 6
- 0
app/src/main/res/color/primary_text_material_light.xml Zobrazit soubor

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
3
+
4
+    <item android:state_enabled="false" android:alpha="0.03" android:color="@color/primary_text_default_material_light" />
5
+    <item android:color="@color/primary_text_default_material_light" />
6
+</selector>

+ 9
- 0
app/src/main/res/drawable/ic_account_circle_black_24dp.xml Zobrazit soubor

@@ -0,0 +1,9 @@
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="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,5c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM12,19.2c-2.5,0 -4.71,-1.28 -6,-3.22 0.03,-1.99 4,-3.08 6,-3.08 1.99,0 5.97,1.09 6,3.08 -1.29,1.94 -3.5,3.22 -6,3.22z"/>
9
+</vector>

+ 9
- 0
app/src/main/res/drawable/ic_apps_black_24dp.xml Zobrazit soubor

@@ -0,0 +1,9 @@
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
app/src/main/res/drawable/ic_contacts_black_24dp.xml Zobrazit soubor

@@ -0,0 +1,9 @@
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,0L4,0v2h16L20,0zM4,24h16v-2L4,22v2zM20,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM12,6.75c1.24,0 2.25,1.01 2.25,2.25s-1.01,2.25 -2.25,2.25S9.75,10.24 9.75,9 10.76,6.75 12,6.75zM17,17L7,17v-1.5c0,-1.67 3.33,-2.5 5,-2.5s5,0.83 5,2.5L17,17z"/>
9
+</vector>

+ 9
- 0
app/src/main/res/drawable/ic_favorite_black_24dp.xml Zobrazit soubor

@@ -0,0 +1,9 @@
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="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"/>
9
+</vector>

+ 9
- 0
app/src/main/res/drawable/ic_message_black_24dp.xml Zobrazit soubor

@@ -0,0 +1,9 @@
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
app/src/main/res/drawable/ic_search_black_24dp.xml Zobrazit soubor

@@ -0,0 +1,9 @@
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>

+ 13
- 4
app/src/main/res/layout/activity_main.xml Zobrazit soubor

@@ -4,9 +4,18 @@
4 4
     android:layout_height="match_parent"
5 5
     android:orientation="vertical">
6 6
 
7
-    <TextView
8
-        android:id="@+id/textView"
7
+    <android.support.v7.widget.Toolbar
8
+        android:id="@+id/toolbar"
9 9
         android:layout_width="match_parent"
10 10
         android:layout_height="wrap_content"
11
-        android:text="Hello World!!!" />
12
-</LinearLayout>
11
+        android:background="?attr/colorPrimary"
12
+        android:elevation="0dp"
13
+        android:minHeight="?attr/actionBarSize"
14
+        android:theme="?attr/actionBarTheme" />
15
+
16
+    <ListView
17
+        android:id="@+id/main_listview"
18
+        android:layout_width="match_parent"
19
+        android:layout_height="match_parent" />
20
+
21
+</LinearLayout>

+ 12
- 0
app/src/main/res/layout/activity_message.xml Zobrazit soubor

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:layout_width="match_parent"
4
+    android:layout_height="match_parent">
5
+
6
+    <TextView
7
+        android:id="@+id/textView3"
8
+        android:layout_width="wrap_content"
9
+        android:layout_height="wrap_content"
10
+        android:layout_weight="1"
11
+        android:text="消息" />
12
+</LinearLayout>

+ 14
- 0
app/src/main/res/layout/activity_micro_apps.xml Zobrazit soubor

@@ -0,0 +1,14 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:app="http://schemas.android.com/apk/res-auto"
4
+    xmlns:tools="http://schemas.android.com/tools"
5
+    android:layout_width="match_parent"
6
+    android:layout_height="match_parent"
7
+    tools:context="io.hsiao.youmap.MicroAppsActivity">
8
+
9
+    <TextView
10
+        android:id="@+id/textView5"
11
+        android:layout_width="wrap_content"
12
+        android:layout_height="wrap_content"
13
+        android:text="微应用" />
14
+</android.support.constraint.ConstraintLayout>

+ 12
- 0
app/src/main/res/layout/activity_user_center.xml Zobrazit soubor

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:layout_width="match_parent"
4
+    android:layout_height="match_parent">
5
+
6
+    <TextView
7
+        android:id="@+id/textView4"
8
+        android:layout_width="wrap_content"
9
+        android:layout_height="wrap_content"
10
+        android:layout_weight="1"
11
+        android:text="TextView" />
12
+</LinearLayout>

+ 41
- 0
app/src/main/res/layout/home_list.xml Zobrazit soubor

@@ -0,0 +1,41 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+
4
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
5
+    xmlns:app="http://schemas.android.com/apk/res-auto"
6
+    xmlns:tools="http://schemas.android.com/tools"
7
+    android:layout_width="match_parent"
8
+    android:layout_height="match_parent">
9
+
10
+
11
+    <TextView
12
+        android:id="@+id/home_list_title"
13
+        android:layout_width="wrap_content"
14
+        android:layout_height="wrap_content"
15
+        android:layout_weight="1"
16
+        android:text="@android:string/dialog_alert_title"
17
+        tools:layout_editor_absoluteY="0dp"
18
+        android:layout_marginLeft="0dp"
19
+        app:layout_constraintLeft_toLeftOf="parent" />
20
+
21
+    <TextView
22
+        android:id="@+id/home_list_date"
23
+        android:layout_width="wrap_content"
24
+        android:layout_height="wrap_content"
25
+        android:layout_weight="1"
26
+        android:text="date"
27
+        android:textAlignment="viewEnd"
28
+        app:layout_constraintRight_toRightOf="parent"
29
+        tools:layout_editor_absoluteY="0dp" />
30
+
31
+    <TextView
32
+        android:id="@+id/home_list_desc"
33
+        android:layout_width="wrap_content"
34
+        android:layout_height="wrap_content"
35
+        android:layout_marginTop="16dp"
36
+        android:layout_weight="1"
37
+        android:text="TextView"
38
+        app:layout_constraintTop_toBottomOf="@+id/home_list_title"
39
+        tools:layout_editor_absoluteX="0dp" />
40
+
41
+</android.support.constraint.ConstraintLayout>

+ 31
- 0
app/src/main/res/menu/menu.xml Zobrazit soubor

@@ -0,0 +1,31 @@
1
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
2
+    xmlns:app="http://schemas.android.com/apk/res-auto">
3
+
4
+    <item
5
+        android:id="@+id/menu_item_message"
6
+        android:icon="@drawable/ic_message_black_24dp"
7
+        android:title="消息"
8
+        app:showAsAction="always" />
9
+    <item
10
+        android:id="@+id/menu_item_mapps"
11
+        android:icon="@drawable/ic_apps_black_24dp"
12
+        android:title="微应用"
13
+        app:showAsAction="always" />
14
+    <item
15
+        android:id="@+id/menu_item_about"
16
+        android:title="关于友图" />
17
+    <item
18
+        android:id="@+id/menu_item_account"
19
+        android:icon="@drawable/ic_account_circle_black_24dp"
20
+        android:title="账户中心" />
21
+    <item
22
+        android:id="@+id/menu_item_contacts"
23
+        android:icon="@drawable/ic_contacts_black_24dp"
24
+        android:title="通讯录" />
25
+    <item
26
+        android:id="@+id/menu_item_search"
27
+        android:actionViewClass="android.widget.SearchView"
28
+        android:icon="@drawable/ic_search_black_24dp"
29
+        android:title="搜索"
30
+        app:showAsAction="always" />
31
+</menu>

+ 2
- 0
app/src/main/res/values/colors.xml Zobrazit soubor

@@ -1,3 +1,5 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <resources>
3
+    <color name="foreground_material_light">#ffffff</color>
4
+    <color name="primary_text_default_material_light">#deffffff</color>
3 5
 </resources>

+ 5
- 1
app/src/main/res/values/styles.xml Zobrazit soubor

@@ -1,3 +1,7 @@
1 1
 <resources>
2
-
2
+    <style name="appTheme" parent="Theme.AppCompat.Light.NoActionBar">
3
+        <item name="colorAccent">@android:color/holo_orange_light</item>
4
+        <item name="colorPrimaryDark">@android:color/holo_orange_dark</item>
5
+        <item name="colorPrimary">@android:color/holo_orange_dark</item>
6
+    </style>
3 7
 </resources>

Loading…
Zrušit
Uložit