-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
k.ikata.xperia
committed
May 14, 2011
1 parent
3f2a95e
commit 927f8f4
Showing
12 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="gen"/> | ||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>SocketWriteSample</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ApkBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.jpn.techbooster.SocketWriteSample" | ||
android:versionCode="1" | ||
android:versionName="1.0"> | ||
<application android:icon="@drawable/icon" android:label="@string/app_name"> | ||
<activity android:name=".SocketWriteSample" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
</application> | ||
|
||
|
||
<uses-permission android:name="android.permission.INTERNET"></uses-permission> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system use, | ||
# "build.properties", and override values to adapt the script to your | ||
# project structure. | ||
|
||
# Project target. | ||
target=android-7 |
31 changes: 31 additions & 0 deletions
31
SocketWriteSample/gen/org/jpn/techbooster/SocketWriteSample/R.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* AUTO-GENERATED FILE. DO NOT MODIFY. | ||
* | ||
* This class was automatically generated by the | ||
* aapt tool from the resource data it found. It | ||
* should not be modified by hand. | ||
*/ | ||
|
||
package org.jpn.techbooster.SocketWriteSample; | ||
|
||
public final class R { | ||
public static final class attr { | ||
} | ||
public static final class drawable { | ||
public static final int icon=0x7f020000; | ||
} | ||
public static final class id { | ||
public static final int Button01=0x7f050005; | ||
public static final int EditText01=0x7f050002; | ||
public static final int EditText02=0x7f050004; | ||
public static final int TextView01=0x7f050000; | ||
public static final int TextView02=0x7f050001; | ||
public static final int TextView03=0x7f050003; | ||
} | ||
public static final class layout { | ||
public static final int main=0x7f030000; | ||
} | ||
public static final class string { | ||
public static final int app_name=0x7f040001; | ||
public static final int hello=0x7f040000; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-optimizationpasses 5 | ||
-dontusemixedcaseclassnames | ||
-dontskipnonpubliclibraryclasses | ||
-dontpreverify | ||
-verbose | ||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* | ||
|
||
-keep public class * extends android.app.Activity | ||
-keep public class * extends android.app.Application | ||
-keep public class * extends android.app.Service | ||
-keep public class * extends android.content.BroadcastReceiver | ||
-keep public class * extends android.content.ContentProvider | ||
-keep public class com.android.vending.licensing.ILicensingService | ||
|
||
-keepclasseswithmembernames class * { | ||
native <methods>; | ||
} | ||
|
||
-keepclasseswithmembernames class * { | ||
public <init>(android.content.Context, android.util.AttributeSet); | ||
} | ||
|
||
-keepclasseswithmembernames class * { | ||
public <init>(android.content.Context, android.util.AttributeSet, int); | ||
} | ||
|
||
-keepclassmembers enum * { | ||
public static **[] values(); | ||
public static ** valueOf(java.lang.String); | ||
} | ||
|
||
-keep class * implements android.os.Parcelable { | ||
public static final android.os.Parcelable$Creator *; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
> | ||
<TextView | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/hello" | ||
android:id="@+id/TextView01"/> | ||
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ログインID"></TextView><EditText android:text="@+id/EditText01" android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText><TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="パスワード "></TextView> | ||
|
||
|
||
|
||
|
||
|
||
|
||
<EditText android:layout_width="wrap_content" android:id="@+id/EditText02" android:layout_height="wrap_content" android:text="@+id/EditText02"></EditText> | ||
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="接続"></Button> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="hello">Hello World, SocketWriteSample!</string> | ||
<string name="app_name">SocketWriteSample</string> | ||
</resources> |
143 changes: 143 additions & 0 deletions
143
SocketWriteSample/src/org/jpn/techbooster/SocketWriteSample/SocketWriteSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package org.jpn.techbooster.SocketWriteSample; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.net.Socket; | ||
import java.net.UnknownHostException; | ||
import org.jpn.techbooster.SocketWriteSample.R; | ||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
public class SocketWriteSample extends Activity { | ||
Socket connection = null; | ||
BufferedReader reader = null; | ||
|
||
/** Called when the activity is first created. */ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main); | ||
|
||
Button btn = (Button) findViewById(R.id.Button01); | ||
btn.setOnClickListener(new OnClickListener() { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
connect(); | ||
login(); | ||
} | ||
}); | ||
} | ||
|
||
private void connect() { | ||
TextView tv = (TextView) findViewById(R.id.TextView01); | ||
try { | ||
// サーバーへ接続 | ||
connection = new Socket("pop.mail.yahoo.co.jp", 110); | ||
|
||
// メッセージ取得オブジェクトのインスタンス化 | ||
reader = new BufferedReader(new InputStreamReader(connection | ||
.getInputStream())); | ||
|
||
// サーバーからのメッセージを受信 | ||
String message = reader.readLine(); | ||
|
||
// 接続確認 | ||
if (!(message.matches("^\\+OK.*$"))) { | ||
tv.setText("サーバーからのメッセージ:" + message); | ||
Toast.makeText(this, "サーバーとの接続に失敗しました。", Toast.LENGTH_SHORT) | ||
.show(); | ||
} else { | ||
tv.setText("サーバーからのメッセージ:" + message); | ||
Toast.makeText(this, "サーバーとの接続に成功しました。", Toast.LENGTH_SHORT) | ||
.show(); | ||
} | ||
|
||
} catch (UnknownHostException e) { | ||
e.printStackTrace(); | ||
tv.setText("エラー内容:" + e.toString()); | ||
Toast.makeText(this, "サーバーとの接続に失敗しました。", Toast.LENGTH_SHORT).show(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
tv.setText("エラー内容:" + e.toString()); | ||
Toast.makeText(this, "サーバーとの接続に失敗しました。", Toast.LENGTH_SHORT).show(); | ||
} /*finally { | ||
try { | ||
// 接続終了処理 | ||
reader.close(); | ||
connection.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
tv.setText("エラー内容:" + e.toString()); | ||
Toast.makeText(this, "サーバーとの接続に失敗しました。", Toast.LENGTH_SHORT) | ||
.show(); | ||
} | ||
}*/ | ||
} | ||
|
||
private void login() { | ||
TextView tv = (TextView) findViewById(R.id.TextView01); | ||
|
||
// 入力されたIDを取得 | ||
EditText id = (EditText) findViewById(R.id.EditText01); | ||
CharSequence idStr = id.getText(); | ||
|
||
// 入力されたパスワードを取得 | ||
EditText pass = (EditText) findViewById(R.id.EditText02); | ||
CharSequence passStr = pass.getText(); | ||
|
||
BufferedWriter writer = null; | ||
try { | ||
// メッセージ送信オブジェクトのインスタンス化 | ||
writer = new BufferedWriter(new OutputStreamWriter( | ||
connection.getOutputStream())); | ||
|
||
// ログインIDの送信 | ||
writer.write(idStr.toString() + "\r\n"); | ||
writer.flush(); | ||
|
||
// ログインIDの正否判定 | ||
String message = reader.readLine(); | ||
if (!(message.matches("^\\+OK.*$"))) { | ||
tv.setText("ID認証:OK\r\n"); | ||
} else { | ||
tv.setText("ログインIDが不正です。"); | ||
return; | ||
} | ||
|
||
// ログインパスワードの送信 | ||
writer.write(passStr.toString() + "\r\n"); | ||
writer.flush(); | ||
|
||
// ログインパスワードの正否判定 | ||
message = reader.readLine(); | ||
if (!(message.matches("^\\+OK.*$"))) { | ||
tv.append("パスワード認証:OK"); | ||
} else { | ||
tv.setText("パスワードが不正です。"); | ||
return; | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
tv.setText("エラー内容:" + e.toString()); | ||
Toast.makeText(this, "サーバーとの接続に失敗しました。", Toast.LENGTH_SHORT).show(); | ||
}finally{ | ||
try { | ||
writer.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
tv.setText("エラー内容:" + e.toString()); | ||
Toast.makeText(this, "サーバーとの接続に失敗しました。", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} | ||
} |