2012년 9월 12일 수요일

account setting example 스리슬쩍 노트

내가 볼려고 적어놂.

Android 기본 example


com.example.android.samplessync.authenticator.AuthenticatorActivity 분석(겁나 길다)



SDK 깔면 기본으로 있는 Example 분석.



우선 파일 3개만 있으면 Account & Sync에서 보인다.



\android-sdk\samples\android-14\SampleSyncAdapter

요깄다.



우선 manifest를 까보면



여러 내용이 있는데




android:name=".authenticator.AuthenticationService"

android:exported="true">




android:name="android.accounts.AccountAuthenticator" />




android:name="android.accounts.AccountAuthenticator"

android:resource="@xml/authenticator" />



얘가 시스템의 android.accounts.AccountAuthenticator 를 받는 애다.



http://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html

여기보면



This service must specify the following intent filter and metadata tags in its AndroidManifest.xml file










android:resource="@xml/authenticator" />

요래 되어 있다.



그냥 법이다.



android:resource="@xml/authenticator" /> 이 부분을 보고



res/xml 폴더에서 authenticator.xml을 찾는다.




android:accountType="com.example.android.samplesync"

android:icon="@drawable/icon"

android:smallIcon="@drawable/icon"

android:label="@string/label"

/>



android developer 사이트에 있는 거랑 같다. 법이다.

아이콘 따위는 여기서 설정해 주면 됨.





자 그럼 파일 2개다.



마지막 하나는..



위에서 말했던...




android:name=".authenticator.AuthenticationService"

android:exported="true">



요녀석... .authenticator 패키지 밑에 보면

AuthenticationService.java가 있다.



세넘만 있으면 Account & Settings에서 AddAccount시에 Account가 보이게 된다.



--------------------------------------------------------------------------------



AuthenticationService.java를 보자.



mAuthenticator = new Authenticator(this);



여기서 생성하고



return mAuthenticator.getIBinder(); 를 한다.



IBinder는



public final IBinder getIBinder ()

Since: API Level 5

Returns

the IBinder for the AccountAuthenticator



이런 애다.



class Authenticator를 보면



extends AbstractAccountAuthenticator {



이다. GetIBinder가 리턴을 해야할 기본 구조가 있다는 뜻.



플랫폼에서 만든 규칙이니 잘 지켜주면 된다.

다시 말하면 설계자가 만든 interface라 지킬 수 밖에 없는 것이다.



기본 구조는 다음과 같다.



package com.example.android.samplesync.authenticator;



import android.accounts.AbstractAccountAuthenticator;

import android.accounts.Account;

import android.accounts.AccountAuthenticatorResponse;

import android.accounts.NetworkErrorException;

import android.content.Context;

import android.os.Bundle;



public class MyAuth extends AbstractAccountAuthenticator {



public MyAuth(Context context) {

super(context);

// TODO Auto-generated constructor stub

}



@Override

public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType,

String[] requiredFeatures, Bundle options) throws NetworkErrorException {

// TODO Auto-generated method stub

return null;

}



@Override

public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options)

throws NetworkErrorException {

// TODO Auto-generated method stub

return null;

}



@Override

public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {

// TODO Auto-generated method stub

return null;

}



@Override

public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,

Bundle options) throws NetworkErrorException {

// TODO Auto-generated method stub

return null;

}



@Override

public String getAuthTokenLabel(String authTokenType) {

// TODO Auto-generated method stub

return null;

}



@Override

public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)

throws NetworkErrorException {

// TODO Auto-generated method stub

return null;

}



@Override

public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType,

Bundle options) throws NetworkErrorException {

// TODO Auto-generated method stub

return null;

}



}



여기다가 채워주면 된다.

-------------------------------------------------------------------------------

Authenticator.java에서



public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,



딱봐도 요녀석이 Account 추가해 주는 넘이다.



final Intent intent = new Intent(mContext, AuthenticatorActivity.class);



보면 액티비티를 하나 호출해 준다.



아 요넘이 어카운트 추가 때 띄우는 Activity 구나.



들어가서 onCreate를 본다.



그려주는 부분이 거기 있다. 관심사는 Sign In 버튼을 눌렀을 때 어떻게 될 것인가?



setContentView(R.layout.login_activity);



니까 login_activity.xml 을 보면



댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...