hsiao 7 лет назад
Родитель
Сommit
0c1acd51ca

+ 13
- 3
lesson02/src/main/AndroidManifest.xml Просмотреть файл

@@ -16,9 +16,19 @@
16 16
                 <category android:name="android.intent.category.LAUNCHER" />
17 17
             </intent-filter>
18 18
         </activity>
19
-        <activity android:name=".MessageActivity"></activity>
20
-        <activity android:name=".MicroAppsActivity"></activity>
21
-        <activity android:name=".UserCenterActivity"></activity>
19
+        <activity android:name=".MessageActivity" />
20
+        <activity android:name=".MicroAppsActivity" />
21
+        <activity android:name=".UserCenterActivity" />
22
+        <activity android:name=".SendToActivity">
23
+            <intent-filter>
24
+                <action android:name="android.intent.action.SEND_MULTIPLE" />
25
+                <action android:name="android.intent.action.SEND" />
26
+                <category android:name="android.intent.category.DEFAULT"/>
27
+                <data android:mimeType="text/plain" />
28
+                <data android:mimeType="text/html" />
29
+                <data android:mimeType="image/*" />
30
+            </intent-filter>
31
+        </activity>
22 32
     </application>
23 33
 
24 34
 </manifest>

+ 12
- 5
lesson02/src/main/java/io/hsiao/lesson02/MainActivity.java Просмотреть файл

@@ -21,6 +21,7 @@ import java.util.Map;
21 21
 import java.util.Objects;
22 22
 
23 23
 public class MainActivity extends AppCompatActivity {
24
+    private final String TAG = "lesson02";
24 25
 
25 26
     private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
26 27
     private ListView listView;
@@ -43,10 +44,10 @@ public class MainActivity extends AppCompatActivity {
43 44
 
44 45
     private List<HashMap<String, Object>> getData() {
45 46
         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);
47
+        for (int i = 0; i < 100; i++) {
48
+            HashMap<String, String> map = new HashMap<>();
49
+            map.put("title", "标题 " + i);
50
+            map.put("thumbnail", "图片 " + i);
50 51
             map.put("date", sdf.format(new Date()));
51 52
 
52 53
             list.add(map);
@@ -84,8 +85,14 @@ public class MainActivity extends AppCompatActivity {
84 85
                 intent = new Intent(this, MessageActivity.class);
85 86
                 break;
86 87
         }
87
-        startActivity(intent);
88
+        startActivityForResult(intent, 0);
88 89
 
89 90
         return true;
90 91
     }
92
+
93
+    @Override
94
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
95
+        if (data != null)
96
+            Log.i(TAG, data.getStringExtra("result"));
97
+    }
91 98
 }

+ 5
- 0
lesson02/src/main/java/io/hsiao/lesson02/MicroAppsActivity.java Просмотреть файл

@@ -1,6 +1,7 @@
1 1
 package io.hsiao.lesson02;
2 2
 
3 3
 import android.app.Activity;
4
+import android.content.Intent;
4 5
 import android.os.Bundle;
5 6
 
6 7
 public class MicroAppsActivity extends Activity {
@@ -9,5 +10,9 @@ public class MicroAppsActivity extends Activity {
9 10
     protected void onCreate(Bundle savedInstanceState) {
10 11
         super.onCreate(savedInstanceState);
11 12
         setContentView(R.layout.activity_micro_apps);
13
+
14
+        Intent resultData = new Intent();
15
+        resultData.putExtra("result","hello there");
16
+        this.setResult(0,resultData);
12 17
     }
13 18
 }

+ 67
- 0
lesson02/src/main/java/io/hsiao/lesson02/SendToActivity.java Просмотреть файл

@@ -0,0 +1,67 @@
1
+package io.hsiao.lesson02;
2
+
3
+import android.content.ContentResolver;
4
+import android.content.Intent;
5
+import android.graphics.Bitmap;
6
+import android.graphics.BitmapFactory;
7
+import android.net.Uri;
8
+import android.os.Bundle;
9
+import android.support.v7.app.AppCompatActivity;
10
+import android.util.Log;
11
+import android.widget.ImageView;
12
+import android.widget.TextView;
13
+
14
+import java.io.FileInputStream;
15
+import java.io.FileNotFoundException;
16
+import java.io.InputStream;
17
+import java.util.Iterator;
18
+
19
+public class SendToActivity extends AppCompatActivity {
20
+    private final String TAG="youmap_app";
21
+    @Override
22
+    protected void onCreate(Bundle savedInstanceState) {
23
+        super.onCreate(savedInstanceState);
24
+        setContentView(R.layout.activity_send_to);
25
+
26
+        TextView title = (TextView)this.findViewById(R.id.sento_label);
27
+        TextView txt = (TextView)this.findViewById(R.id.sento_txt);
28
+        ImageView img = (ImageView) this.findViewById(R.id.sento_img);
29
+
30
+        Intent intent = this.getIntent();
31
+        String type = intent.getType();
32
+        Log.i(TAG,"shared content type: "+type);
33
+
34
+        switch (type){
35
+            case "text/plain":
36
+                String content = intent.getStringExtra(Intent.EXTRA_TEXT);
37
+                String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
38
+                txt.setText(content);
39
+                title.setText(subject);
40
+                break;
41
+            case "image/*":
42
+                Bundle bdl = intent.getExtras();
43
+                Uri file = (Uri) bdl.get(Intent.EXTRA_STREAM);
44
+
45
+                ContentResolver resolver = getContentResolver();
46
+                try {
47
+                    InputStream in = resolver.openInputStream(file);
48
+                    Bitmap bmp = BitmapFactory.decodeStream(in);
49
+                    Log.i(TAG,bmp.toString());
50
+                    img.setImageBitmap(bmp);
51
+                } catch (Exception e) {
52
+                    e.printStackTrace();
53
+                }
54
+
55
+
56
+                break;
57
+        }
58
+
59
+        Bundle bdl = intent.getExtras();
60
+        Iterator<String> iter = bdl.keySet().iterator();
61
+        while(iter.hasNext()){
62
+            String key = iter.next();
63
+            Log.i(TAG,key+"="+bdl.get(key));
64
+        }
65
+
66
+    }
67
+}

+ 20
- 0
lesson02/src/main/java/io/hsiao/lesson02/UserCenterActivity.java Просмотреть файл

@@ -1,7 +1,11 @@
1 1
 package io.hsiao.lesson02;
2 2
 
3 3
 import android.app.Activity;
4
+import android.content.Intent;
4 5
 import android.os.Bundle;
6
+import android.view.View;
7
+import android.widget.Button;
8
+import android.widget.TextView;
5 9
 
6 10
 public class UserCenterActivity extends Activity {
7 11
 
@@ -9,5 +13,21 @@ public class UserCenterActivity extends Activity {
9 13
     protected void onCreate(Bundle savedInstanceState) {
10 14
         super.onCreate(savedInstanceState);
11 15
         setContentView(R.layout.activity_user_center);
16
+
17
+        Button shareBtn = (Button) this.findViewById(R.id.usercenter_sharebtn);
18
+
19
+        shareBtn.setOnClickListener(new View.OnClickListener() {
20
+            @Override
21
+            public void onClick(View v) {
22
+                Intent intent = new Intent();
23
+                intent.setAction(Intent.ACTION_SEND);
24
+                intent.putExtra(Intent.EXTRA_TEXT,"Hi, 我是John,炒鸡帅男。我的Email是 John@gmail.com。");
25
+                intent.setType("text/plain");
26
+
27
+                if(intent.resolveActivity(getPackageManager()) !=null){
28
+                    startActivity(intent);
29
+                }
30
+            }
31
+        });
12 32
     }
13 33
 }

+ 40
- 0
lesson02/src/main/res/layout/activity_send_to.xml Просмотреть файл

@@ -0,0 +1,40 @@
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.lesson02.SendToActivity">
8
+
9
+    <TextView
10
+        android:id="@+id/sento_label"
11
+        android:layout_width="0dp"
12
+        android:layout_height="wrap_content"
13
+        android:layout_marginEnd="8dp"
14
+        android:layout_marginStart="8dp"
15
+        app:layout_constraintEnd_toEndOf="parent"
16
+        app:layout_constraintStart_toStartOf="parent" />
17
+
18
+    <TextView
19
+        android:id="@+id/sento_txt"
20
+        android:layout_width="0dp"
21
+        android:layout_height="wrap_content"
22
+        android:layout_marginEnd="8dp"
23
+        android:layout_marginStart="8dp"
24
+        android:layout_marginTop="8dp"
25
+        app:layout_constraintEnd_toEndOf="parent"
26
+        app:layout_constraintStart_toStartOf="parent"
27
+        app:layout_constraintTop_toBottomOf="@+id/sento_label" />
28
+
29
+    <ImageView
30
+        android:id="@+id/sento_img"
31
+        android:layout_width="0dp"
32
+        android:layout_height="wrap_content"
33
+        android:layout_marginEnd="16dp"
34
+        android:layout_marginStart="16dp"
35
+        android:layout_marginTop="24dp"
36
+        app:layout_constraintEnd_toEndOf="parent"
37
+        app:layout_constraintStart_toStartOf="parent"
38
+        app:layout_constraintTop_toBottomOf="@id/sento_txt"
39
+        app:srcCompat="@color/colorPrimary" />
40
+</android.support.constraint.ConstraintLayout>

+ 19
- 4
lesson02/src/main/res/layout/activity_user_center.xml Просмотреть файл

@@ -1,12 +1,27 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3
     android:layout_width="match_parent"
4
-    android:layout_height="match_parent">
4
+    android:layout_height="match_parent"
5
+    android:orientation="vertical">
5 6
 
6 7
     <TextView
7
-        android:id="@+id/textView4"
8
+        android:id="@+id/usercenter_mobile"
9
+        android:layout_width="match_parent"
10
+        android:layout_height="wrap_content"
11
+        android:text="18288888888"
12
+        android:autoLink="phone"
13
+        />
14
+
15
+    <TextView
16
+        android:id="@+id/usercenter_useremail"
8 17
         android:layout_width="wrap_content"
18
+        android:autoLink="email"
19
+        android:layout_height="wrap_content"
20
+        android:text="John@gmail.com" />
21
+
22
+    <Button
23
+        android:id="@+id/usercenter_sharebtn"
24
+        android:layout_width="match_parent"
9 25
         android:layout_height="wrap_content"
10
-        android:layout_weight="1"
11
-        android:text="TextView" />
26
+        android:text="分享我的名片" />
12 27
 </LinearLayout>

+ 9
- 0
lesson02/src/main/res/values-v21/styles.xml Просмотреть файл

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<resources>
3
+
4
+    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
5
+        <item name="colorPrimary">@color/colorPrimary</item>
6
+        <item name="colorAccent">@color/colorPrimary</item>
7
+        <item name="android:statusBarColor">@color/colorPrimary</item>
8
+    </style>
9
+</resources>

+ 1
- 3
lesson02/src/main/res/values/colors.xml Просмотреть файл

@@ -1,6 +1,4 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <resources>
3
-    <color name="colorPrimary">#3F51B5</color>
4
-    <color name="colorPrimaryDark">#303F9F</color>
5
-    <color name="colorAccent">#FF4081</color>
3
+    <color name="colorPrimary">#1f9cd6</color>
6 4
 </resources>

+ 4
- 5
lesson02/src/main/res/values/styles.xml Просмотреть файл

@@ -1,8 +1,7 @@
1
+<?xml version="1.0" encoding="utf-8"?>
1 2
 <resources>
2
-
3
-    <!-- Base application theme. -->
4
-    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
5
-
3
+    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
4
+        <item name="colorPrimary">@color/colorPrimary</item>
5
+        <item name="colorAccent">@color/colorPrimary</item>
6 6
     </style>
7
-
8 7
 </resources>

Загрузка…
Отмена
Сохранить