Home SMS 입력 화면
Post
Cancel

SMS 입력 화면

SMS 입력 화면

XML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent" >  
  
 <RelativeLayout  
  android:id="@+id/inputlayout"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent"  
  android:layout_alignParentTop="true"  
  android:layout_above="@+id/buttonLayout"  
  >  
  
 <EditText  
  android:id="@+id/inputMessage"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent"  
  android:layout_above="@+id/inputCount"  
  android:layout_alignParentTop="false"  
  android:layout_marginLeft="5dp"  
  android:layout_marginRight="5dp"  
  android:cacheColorHint="#00000000"  
  android:gravity="top"  
  android:listSelector="#00000000"  
  android:maxLength="80"  
  android:textSize="48sp" />  
  
 <TextView  
  android:id="@+id/inputCount"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_alignParentBottom="true"  
  android:layout_alignParentRight="true"  
  android:text="0 / 80 바이트"  
  android:textColor="#ffff00ff"  
  android:layout_marginRight="10dp"  
  android:layout_marginTop="10dp"  
  android:layout_marginBottom="10dp"  
  android:textSize="18sp"  
  />  
  
 </RelativeLayout>  
 <LinearLayout  
  android:id="@+id/buttonLayout"  
  android:orientation="vertical"  
  android:layout_width="match_parent"  
  android:layout_height="wrap_content"  
  android:layout_alignParentBottom="true"  
  >  
  
 <LinearLayout  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_gravity="center_horizontal"  
  android:orientation="horizontal">  
  
 <Button  
  android:id="@+id/sendButton"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_margin="20dp"  
  android:paddingLeft="20dp"  
  android:paddingRight="20dp"  
  android:text="전송"  
  android:textSize="18sp" />  
  
 <Button  
  android:id="@+id/closeButton"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_margin="20dp"  
  android:paddingLeft="20dp"  
  android:paddingRight="20dp"  
  android:text="닫기"  
  android:textSize="18sp" />  
 </LinearLayout>  
 </LinearLayout>  
  
</RelativeLayout>

JAVA

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class MainActivity extends AppCompatActivity {
	EditText inputMessage;
	TextView inputCount;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		inputMessage = findViewById(R.id.inputMessage);
		inputCount = findViewById(R.id.inputCount);

		Button sendButton = findViewById(R.id.sendButton);
		sendButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				String message = inputMessage.getText().toString();
				Toast.makeText(getApplicationContext(), "전송할 메시지\n\n" + message, Toast.LENGTH_LONG).show();
			}
		});
		
		Button closeButton = findViewById(R.id.closeButton);
		closeButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
		
		TextWatcher watcher = new TextWatcher() {
			public void onTextChanged(CharSequence str, int start, int before, int count) {
				byte[] bytes = null;
				try {
					bytes = str.toString().getBytes("KSC5601");
					int strCount = bytes.length;
					inputCount.setText(strCount + " / 80바이트");
				} catch (UnsupportedEncodingException ex) {
					ex.printStackTrace();
				}
			}

			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			public void afterTextChanged(Editable strEditable) {
				String str = strEditable.toString();
				try {
					byte[] strBytes = str.getBytes("KSC5601");
					if (strBytes.length > 80) {
						strEditable.delete(strEditable.length() - 2, strEditable.length() - 1);
					}
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		};
		
		inputMessage.addTextChangedListener(watcher);
	}
}

1

This post is licensed under CC BY 4.0 by the author.