기술참고자료/Android | 2011. 5. 6. 14:13
import android.app.Activity;WebViewClient.java
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
public class WebViewTestActivity extends Activity {
private WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true); // 웹뷰에서 자바스크립트실행가능
mWebView.loadUrl("http://www.google.com"); // 구글홈페이지 지정
mWebView.setWebViewClient(new WebViewClient()); // WebViewClient 지정
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
import android.util.Log;웹뷰에 웹페이지를 출력하는 방법과 링크를 클릭했을때 링크경로를 캐치하여 어떠한 처리를 수행할 수 있는 방법에 대해 포스팅한다. 'WebViewTestActivity.java'가 메인액티비티이며, 'WebViewClient.java'가 이러한 처리를 수행하는 클래스이다. 물론 레이아웃에는 아래처럼 선언되어 있을테고...
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
Log.e("shouldOverrideUrlLoading >>> ", url+"");
return true;
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
super.doUpdateVisitedHistory(view, url, isReload);
Log.e("doUpdateVisitedHistory >>> ", url+"");
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
Log.e("onLoadResource >>> ", url+"");
}
}
<?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"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
[Android] Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE (0) | 2011.05.06 |
---|---|
[Android] EditText 정규식으로 한글제한 체크하기 (2) | 2011.05.06 |
[Android] 코드에서 EditText의 inputType을 password로 지정하기!! (0) | 2011.05.06 |
[Android] 로그캣(logcat) 한글출력 (0) | 2011.05.06 |
[Android] Custom ProgressBar - 프로그래스바 모양 변경 (1) | 2011.05.06 |
기술참고자료/Android | 2011. 5. 6. 14:09
<?xml version="1.0" encoding="utf-8"?>MainActivity.java
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:inputType=""
/>
</LinearLayout>
package com.vartist;저도 몰랐는데, 볼드체 적용된 코드중에 두번째 라인을 적용해주지 않으면 패스워드타입이 적용되지 않는군요.
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.widget.EditText;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText myEditText = (EditText) findViewById(R.id.test);
myEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
myEditText.setTransformationMethod(new PasswordTransformationMethod());
}
}
[Android] EditText 정규식으로 한글제한 체크하기 (2) | 2011.05.06 |
---|---|
[Android] WebView 연습 (0) | 2011.05.06 |
[Android] 로그캣(logcat) 한글출력 (0) | 2011.05.06 |
[Android] Custom ProgressBar - 프로그래스바 모양 변경 (1) | 2011.05.06 |
[Android] BroadcastReceiver 샘플테스트 (0) | 2011.05.06 |
기술참고자료/Android | 2011. 5. 6. 14:07
[Android] WebView 연습 (0) | 2011.05.06 |
---|---|
[Android] 코드에서 EditText의 inputType을 password로 지정하기!! (0) | 2011.05.06 |
[Android] Custom ProgressBar - 프로그래스바 모양 변경 (1) | 2011.05.06 |
[Android] BroadcastReceiver 샘플테스트 (0) | 2011.05.06 |
[Android] Parcelable을 이용해 액티비티간 인텐트로 객체넘기기 (1) | 2011.05.06 |
기술참고자료/Android | 2011. 5. 6. 14:04
1.<?xml version="1.0" encoding="utf-8"?>
2.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:orientation="vertical"
4. android:layout_width="fill_parent"
5. android:layout_height="fill_parent"
6. >
7.<ProgressBar android:id="@+id/ProgressBar01" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/progress_large"/>
8.</LinearLayout>
01.<?xml version="1.0" encoding="utf-8"?>바 로 progress_lage.xml 은 animated-rotate 라는 태그를 보시면보시면 알듯이 회전 애니메이션에 대한 정의가 되어 있습니다. 다른건 별로 중요하지 않지만않지만 android:drawable="@drawable/spinner_white_76" 는 중요하죠.
02.<!--
03./*
04.**
05.** Copyright 2009, The Android Open Source Project
06.**
07.** Licensed under the Apache License, Version 2.0 (the "License");
08.** you may not use this file except in compliance with the License.
09.** You may obtain a copy of the License at
10.**
11.** http://www.apache.org/licenses/LICENSE-2.0
12.**
13.** Unless required by applicable law or agreed to in writing, software
14.** distributed under the License is distributed on an "AS IS" BASIS,
15.** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16.** See the License for the specific language governing permissions and
17.** limitations under the License.
18.*/
19.-->
20.<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
21. android:drawable="@drawable/spinner_white_76"
22. android:pivotX="50%"
23. android:pivotY="50%"
24. />
[Android] 코드에서 EditText의 inputType을 password로 지정하기!! (0) | 2011.05.06 |
---|---|
[Android] 로그캣(logcat) 한글출력 (0) | 2011.05.06 |
[Android] BroadcastReceiver 샘플테스트 (0) | 2011.05.06 |
[Android] Parcelable을 이용해 액티비티간 인텐트로 객체넘기기 (1) | 2011.05.06 |
[Android] Wifi 다루기 (0) | 2011.05.06 |
기술참고자료/Android | 2011. 5. 6. 13:59
나도 최근에 테스트해본 것이지만, 안드로이드에는 브로드캐스트 리시버라는 놈이 있다.
이놈을 간단히 설명하자면, 사용자
또는 주변환경에 의해 단말기의 상태가 변경되어 버릴때 호출되도록 미리 설정을 해 놓으면 그러한 상황이 벌어졌을때에 자동으로
(세상에 자동은 없다. 미리 설정되어 있을뿐...) 호출되는 모 그런놈이란다.
이 브로드캐스트 리시버라는 놈은 두가지 방법으로 설정해줄 수가 있다. 한가지는 XML로 매니페스트 파일에 설정을 하는것이고, 다른 하나는 자바 코드로 클래스상에서 등록해주는 것이다. 두가지 방법에는 큰 차이점이 있었다.
일단 매니페스트에 등록할때의 방법을 살펴보자.
<receiver android:name=".SampleBroadcastReceiver">인터넷에 자료가 많지만, 요놈을 매니페스트의 어느 위치에 설정하는지 나와있는 자료는 좀 드물다. 다들 잘 아는걸까 -_-; 그렇다. 나만 잘 모르는것이다. 나같은 분들은 그냥 <application></application> 사이에 다른 액티비티 설정부분과 동일한 위치에 설정을 해주면 된다.
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE">
</intent-filter>
</receiver>
캐치하고자 하는 단말기의 상태변경항목을 이용해 필터를 생성해주고, 새로운 리시버를 생성한뒤 Activity 클래스의 registerReceiver() 메서드를 이용해서 등록한다. 등록은 이렇게 하고... 그럼 해제해주는 메서드도 있을까? 정답은 있다. 그것도 매우 쉽게 unregisterReceiver(receiver) 라는 메서드로 존재한다.... (생략) ...
final String CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";private BroadcastReceiver receiver;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** 네트워크 상태 표시 */
IntentFilter filter = new IntentFilter(CONNECTIVITY_CHANGE);
receiver = new ULNetworkReceiver(this);
registerReceiver(receiver, filter);
... (생략) ...
package com.vartist;ULNetworkReceiver.java
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.vartist.receiver.ULNetworkReceiver;
public class MainActivity extends Activity {
final String CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";
private TextView myTextView;
private Button myUpdateButton;
private int count = 0;
private BroadcastReceiver receiver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** 레이아웃 가져오기 */
this.myTextView = (TextView) findViewById(R.id.myId);
this.myUpdateButton = (Button) findViewById(R.id.updateButton);
/** 네트워크 상태 표시 */
IntentFilter filter = new IntentFilter(CONNECTIVITY_CHANGE);
receiver = new ULNetworkReceiver(this);
registerReceiver(receiver, filter);
/** 테스트 클릭이벤트 */
this.myUpdateButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
onResume();
}
});
}
@Override
public void onResume() {
super.onResume();
this.myTextView.setText("테스트 어플리케이션... / count : " + this.count++);
}
@Override
protected void onDestroy(){
super.onDestroy();
unregisterReceiver(receiver);
Log.e("info >>> ", "unregisterReceiver()...");
}
}
package com.vartist.receiver;AndroidManifest.xml
import com.vartist.MainActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;
public class ULNetworkReceiver extends BroadcastReceiver {
private Activity activity;
public ULNetworkReceiver() {
super();
}
public ULNetworkReceiver(Activity activity) {
this.activity = activity;
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// 네트웍에 변경이 일어났을때 발생하는 부분
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
try {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
NetworkInfo _wifi_network =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(_wifi_network != null) {
/** 3G, WIFI 둘 중 하나라도 있을 경우 */
if(_wifi_network != null && activeNetInfo != null){
Toast.makeText(context, "상태1 : " + activeNetInfo.getTypeName(), Toast.LENGTH_SHORT).show();
}
/** 3G, WIFI 둘 다 없을 경우 */
else{
Toast.makeText(context, "상태2 : 3G/WIFI 불가능", Toast.LENGTH_SHORT).show();
}
/** 테스트용 */
if(this.activity instanceof MainActivity) {
((MainActivity)this.activity).onResume();
}
}
} catch (Exception e) {
Log.i("ULNetworkReceiver", e.getMessage());
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vartist"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
<receiver android:name=".receiver.ULNetworkReceiver"
android:enabled="true" android:priority="0">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
-->
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
[Android] 로그캣(logcat) 한글출력 (0) | 2011.05.06 |
---|---|
[Android] Custom ProgressBar - 프로그래스바 모양 변경 (1) | 2011.05.06 |
[Android] Parcelable을 이용해 액티비티간 인텐트로 객체넘기기 (1) | 2011.05.06 |
[Android] Wifi 다루기 (0) | 2011.05.06 |
[Android] BroadcastReceiver에서 wifi / 3G 분기하기 (0) | 2011.05.06 |