Skip to content

Commit 2bcc42d

Browse files
committed
Conflicts: README.md examples/0302/MyAndroidTutorial/src/net/macdidi/myandroidtutorial/ItemAc tivity.java examples/0303/MyAndroidTutorial/src/net/macdidi/myandroidtutorial/ItemAc tivity.java examples/0304/MyAndroidTutorial/src/net/macdidi/myandroidtutorial/ItemAc tivity.java examples/0401/MyAndroidTutorial/src/net/macdidi/myandroidtutorial/ItemAc tivity.java
2 parents 6e80f1c + 6b8ef40 commit 2bcc42d

5 files changed

Lines changed: 711 additions & 0 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#AndroidTutorial
2+
3+
你對「Tutorial」有什麼樣的感覺?每一種技術的Tutorial都告訴你這是學習的開始,不過最後好像都會變成折磨的開始。或許可以找出一種方式,讓Tutorial變成大家會很想要點它的超連結!
4+
5+
要認識一種開發技術,每個人選擇的方式都會不太一樣,如果再加上只能使用非常簡短的時間,你會選擇哪一種方式呢?我的決定是選一個Android APP!
6+
7+
這個Android APP會在短短六小時的課程內容,帶領你認識大部份Android APP開發時會遇到的主題,從APP的規劃開始,畫面、互動、資料庫、多媒體、檔案、服務、通知、位置、地圖還有小工具,這些就是你會學到的東西。
8+
9+
* Android Tutorial 第一堂
10+
* [西遊記裡的那隻潑猴](http://www.codedata.com.tw/mobile/android-tutorial-the-1st-class-1-sunwukong/)
11+
* [準備Android開發環境](http://www.codedata.com.tw/mobile/android-tutorial-the-1st-class-2-android-sdk/)
12+
* [開始設計Android應用程式](http://www.codedata.com.tw/mobile/android-tutorial-the-1st-class-3-app-project/)
13+
* [開發Android應用程式的準備工作](http://www.codedata.com.tw/mobile/android-tutorial-the-1st-class-4-before-developing-an-app/)
14+
* Android Tutorial 第二堂
15+
* [建立應用程式需要的資源](http://www.codedata.com.tw/mobile/android-tutorial-the-2nd-class-1-res/)
16+
* [設計應用程式使用者介面](http://www.codedata.com.tw/mobile/android-tutorial-the-2nd-class-2-ui/)
17+
* [應用程式與使用者的互動](http://www.codedata.com.tw/mobile/android-tutorial-the-2nd-class-3-interaction/)
18+
* [建立與使用Activity元件](http://www.codedata.com.tw/mobile/android-tutorial-the-2nd-class-4-activity/)
19+
* Android Tutorial 第三堂
20+
* [為ListView元件建立自定畫面](http://www.codedata.com.tw/mobile/android-tutorial-the-3rd-class-1-listview/)
21+
* [儲存與讀取應用程式資訊](http://www.codedata.com.tw/mobile/android-tutorial-the-3rd-class-2-preference)
22+
* [使用Android內建的SQLite資料庫](http://www.codedata.com.tw/mobile/android-tutorial-the-3rd-class-3-sqlite/)
23+
* [存取Android檔案系統](http://www.codedata.com.tw/mobile/android-tutorial-the-3rd-class-4-filesystem/)
24+
* Android Tutorial 第四堂
25+
* [使用照相機與麥克風](http://www.codedata.com.tw/mobile/android-tutorial-the-4th-class-1-camera-microphone/)
26+
27+
===============
28+
http://www.codedata.com.tw/author/michael
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package net.macdidi.myandroidtutorial;
2+
3+
import java.util.Date;
4+
5+
import android.app.Activity;
6+
import android.content.Intent;
7+
import android.content.SharedPreferences;
8+
import android.os.Bundle;
9+
import android.preference.PreferenceManager;
10+
import android.view.View;
11+
import android.widget.EditText;
12+
13+
public class ItemActivity extends Activity {
14+
15+
private EditText title_text, content_text;
16+
17+
private static final int START_CAMERA = 0;
18+
private static final int START_RECORD = 1;
19+
private static final int START_LOCATION = 2;
20+
private static final int START_ALARM = 3;
21+
private static final int START_COLOR = 4;
22+
23+
private Item item;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_item);
29+
30+
processViews();
31+
32+
Intent intent = getIntent();
33+
String action = intent.getAction();
34+
35+
if (action.equals("net.macdidi.myandroidtutorial.EDIT_ITEM")) {
36+
item = (Item) intent.getExtras().getSerializable(
37+
"net.macdidi.myandroidtutorial.Item");
38+
title_text.setText(item.getTitle());
39+
content_text.setText(item.getContent());
40+
}
41+
else {
42+
item = new Item();
43+
// 建立SharedPreferences物件
44+
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
45+
// 讀取設定的預設顏色
46+
int color = sharedPreferences.getInt("DEFAULT_COLOR", -1);
47+
item.setColor(getColors(color));
48+
}
49+
}
50+
51+
@Override
52+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
53+
if (resultCode == Activity.RESULT_OK) {
54+
switch (requestCode) {
55+
case START_CAMERA:
56+
break;
57+
case START_RECORD:
58+
break;
59+
case START_LOCATION:
60+
break;
61+
case START_ALARM:
62+
break;
63+
case START_COLOR:
64+
int colorId = data.getIntExtra(
65+
"colorId", Colors.LIGHTGREY.parseColor());
66+
item.setColor(getColors(colorId));
67+
break;
68+
}
69+
}
70+
}
71+
72+
// 改為public static
73+
public static Colors getColors(int color) {
74+
Colors result = Colors.LIGHTGREY;
75+
76+
if (color == Colors.BLUE.parseColor()) {
77+
result = Colors.BLUE;
78+
}
79+
else if (color == Colors.PURPLE.parseColor()) {
80+
result = Colors.PURPLE;
81+
}
82+
else if (color == Colors.GREEN.parseColor()) {
83+
result = Colors.GREEN;
84+
}
85+
else if (color == Colors.ORANGE.parseColor()) {
86+
result = Colors.ORANGE;
87+
}
88+
else if (color == Colors.RED.parseColor()) {
89+
result = Colors.RED;
90+
}
91+
92+
return result;
93+
}
94+
95+
private void processViews() {
96+
title_text = (EditText) findViewById(R.id.title_text);
97+
content_text = (EditText) findViewById(R.id.content_text);
98+
}
99+
100+
public void onSubmit(View view) {
101+
if (view.getId() == R.id.ok_teim) {
102+
String titleText = title_text.getText().toString();
103+
String contentText = content_text.getText().toString();
104+
105+
item.setTitle(titleText);
106+
item.setContent(contentText);
107+
108+
if (getIntent().getAction().equals(
109+
"net.macdidi.myandroidtutorial.EDIT_ITEM")) {
110+
item.setLastModify(new Date().getTime());
111+
}
112+
// 新增記事
113+
else {
114+
item.setDatetime(new Date().getTime());
115+
}
116+
117+
Intent result = getIntent();
118+
result.putExtra("net.macdidi.myandroidtutorial.Item", item);
119+
setResult(Activity.RESULT_OK, result);
120+
}
121+
122+
finish();
123+
}
124+
125+
public void clickFunction(View view) {
126+
int id = view.getId();
127+
128+
switch (id) {
129+
case R.id.take_picture:
130+
break;
131+
case R.id.record_sound:
132+
break;
133+
case R.id.set_location:
134+
break;
135+
case R.id.set_alarm:
136+
break;
137+
case R.id.select_color:
138+
startActivityForResult(
139+
new Intent(this, ColorActivity.class), START_COLOR);
140+
break;
141+
}
142+
143+
}
144+
145+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package net.macdidi.myandroidtutorial;
2+
3+
import java.util.Date;
4+
5+
import android.app.Activity;
6+
import android.content.Intent;
7+
import android.content.SharedPreferences;
8+
import android.os.Bundle;
9+
import android.preference.PreferenceManager;
10+
import android.view.View;
11+
import android.widget.EditText;
12+
13+
public class ItemActivity extends Activity {
14+
15+
private EditText title_text, content_text;
16+
17+
private static final int START_CAMERA = 0;
18+
private static final int START_RECORD = 1;
19+
private static final int START_LOCATION = 2;
20+
private static final int START_ALARM = 3;
21+
private static final int START_COLOR = 4;
22+
23+
private Item item;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_item);
29+
30+
processViews();
31+
32+
Intent intent = getIntent();
33+
String action = intent.getAction();
34+
35+
if (action.equals("net.macdidi.myandroidtutorial.EDIT_ITEM")) {
36+
item = (Item) intent.getExtras().getSerializable(
37+
"net.macdidi.myandroidtutorial.Item");
38+
title_text.setText(item.getTitle());
39+
content_text.setText(item.getContent());
40+
}
41+
else {
42+
item = new Item();
43+
// 建立SharedPreferences物件
44+
SharedPreferences sharedPreferences =
45+
PreferenceManager.getDefaultSharedPreferences(this);
46+
// 讀取設定的預設顏色
47+
int color = sharedPreferences.getInt("DEFAULT_COLOR", -1);
48+
item.setColor(getColors(color));
49+
}
50+
}
51+
52+
@Override
53+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
54+
if (resultCode == Activity.RESULT_OK) {
55+
switch (requestCode) {
56+
case START_CAMERA:
57+
break;
58+
case START_RECORD:
59+
break;
60+
case START_LOCATION:
61+
break;
62+
case START_ALARM:
63+
break;
64+
case START_COLOR:
65+
int colorId = data.getIntExtra(
66+
"colorId", Colors.LIGHTGREY.parseColor());
67+
item.setColor(getColors(colorId));
68+
break;
69+
}
70+
}
71+
}
72+
73+
// 改為public static
74+
public static Colors getColors(int color) {
75+
Colors result = Colors.LIGHTGREY;
76+
77+
if (color == Colors.BLUE.parseColor()) {
78+
result = Colors.BLUE;
79+
}
80+
else if (color == Colors.PURPLE.parseColor()) {
81+
result = Colors.PURPLE;
82+
}
83+
else if (color == Colors.GREEN.parseColor()) {
84+
result = Colors.GREEN;
85+
}
86+
else if (color == Colors.ORANGE.parseColor()) {
87+
result = Colors.ORANGE;
88+
}
89+
else if (color == Colors.RED.parseColor()) {
90+
result = Colors.RED;
91+
}
92+
93+
return result;
94+
}
95+
96+
private void processViews() {
97+
title_text = (EditText) findViewById(R.id.title_text);
98+
content_text = (EditText) findViewById(R.id.content_text);
99+
}
100+
101+
public void onSubmit(View view) {
102+
if (view.getId() == R.id.ok_teim) {
103+
String titleText = title_text.getText().toString();
104+
String contentText = content_text.getText().toString();
105+
106+
item.setTitle(titleText);
107+
item.setContent(contentText);
108+
109+
if (getIntent().getAction().equals(
110+
"net.macdidi.myandroidtutorial.EDIT_ITEM")) {
111+
item.setLastModify(new Date().getTime());
112+
}
113+
// 新增記事
114+
else {
115+
item.setDatetime(new Date().getTime());
116+
}
117+
118+
Intent result = getIntent();
119+
result.putExtra("net.macdidi.myandroidtutorial.Item", item);
120+
setResult(Activity.RESULT_OK, result);
121+
}
122+
123+
finish();
124+
}
125+
126+
public void clickFunction(View view) {
127+
int id = view.getId();
128+
129+
switch (id) {
130+
case R.id.take_picture:
131+
break;
132+
case R.id.record_sound:
133+
break;
134+
case R.id.set_location:
135+
break;
136+
case R.id.set_alarm:
137+
break;
138+
case R.id.select_color:
139+
startActivityForResult(
140+
new Intent(this, ColorActivity.class), START_COLOR);
141+
break;
142+
}
143+
144+
}
145+
146+
}

0 commit comments

Comments
 (0)