# 초기화하기

Wepin Android Widget Library를 초기화하는 방법은 다음과 같습니다.&#x20;

```kotlin
import com.wepin.android.widgetlib.WepinWidget 
```

`WepinWidget`인스턴스를 생성하기전에 아래와 같이 앱의 Activity Context , 앱 등록 후 할당받은 App ID와 App Key를 WepinWidgetParams 객체에 전달해 주세요.

```kotlin
val wepinWidgetParams =  WepinWidgetParams(
            context = this,
            appId = "your-wepin-app-id",
            appKey = "your-wepin-app-key"
        )
```

앞서 생성한 `WepinWidgetParams` 를 전달하면서 `WepinWidget` 인스턴스를 생성해 주세요.

```kotlin
val wepinWidget = WepinWidget(wepinWidgetParams)
```

`WepinWidget` 인스턴스생성 후 `initialize` 메서드를 호출하여 초기화를 합니다.

```kotlin
val res = wepinWidget.initialize(attributes)
```

#### parameters

&#x20;`atrributes` \<WepinWidgetAttribute>

* `defualtLanguage` \<String>\
  위젯 화면의 기본 언어 설정, 기본 값은 `'en'` 입니다. 현재 지원하는 언어는 `'ko'`, `'en'` ,`'ja'`입니다.
* `defaultCurrency`\<String>

  위젯 화면의 기본 통화 설정, 기본 값은 `'USD'` 입니다. 현재 지원하는 통화는 `'KRW'`, `'USD'`, `'JPY'`입니다.

#### Return value

`CompletableFuture` \<Boolean>\
정상적으로 잘 된 경우 **true** , 실패한 경우 **false** 를 반환합니다.

### Example

{% tabs %}
{% tab title="Java" %}

```java
public class MainActivity extends ComponentActivity {
    private WepinWidget wepinWidget;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_example_main);

        initView();
        // Wepin Login Library 초기화
        // ...

        // Wepin PIN Pad Library 초기화        
        WepinWidgetParams wepinWidgetParams = new WepinWidgetParams(
            this,
            "your-wepin-app-id",
            "your-wepin-app-key"
        );
        wepinWidget = new WepinWidget(wepinWidgetParams null);
        
        WepinWidgetAttributes attributes = new WepinWidgetAttributes("en", "USD");
        CompletableFuture<Boolean> res = wepinWidget.initialize(attributes);
        if (res != null) {
            res.whenComplete((result, error) -> {
                if (error == null) {
                    System.out.println(result);
                } else {
                    System.out.println(error);
                }
            });
        }
        // ...
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
class MainActivity : ComponentActivity() {
    private lateinit var wepinWidget: WepinWidget
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_example_main)
    
        initView()
        
        // Wepin Widget Pad Libary 초기화        
        val wepinWidgetParams =  WepinWidgetParams(
            context = this,
            appId = 'your-wepin-app-id',
            appKey = 'your-wepin-app-key'
        )
        wepinWidget = WepinWidget(wepinWidgetParams)       
        var attributes = WepinWidgetAttribute("en", "USD")
        val res = wepinWidget.initialize(attributes)
        res?.whenComplete { infResponse, error ->
          if (error == null) {
            println(infResponse)
          } else {
            println(error) 
          }
      }        
    // ...
}
```

{% endtab %}
{% endtabs %}

## isInitialized

`isInitialized`메서드를 이용해서 `WepinWidget` 인스턴스가 정상적으로 초기화 되었는지 확인할 수 있습니다. &#x20;

반환값은 아래와 같습니다.&#x20;

* \<Boolean>\
  초기화가 정상적으로 잘 된 경우 **true** , 실패한 경우 **false** 를 반환합니다.

### Example

{% tabs %}
{% tab title="Java" %}

```java
if(wepinWidget.isInitialized()){
    // Success to initialize WepinPin
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
if(wepinWidget.isInitialized()){
    // Success to initialize WepinPin
}
```

{% endtab %}
{% endtabs %}

## changeLanguage

```kotlin
wepinWidget.changeLanguage("ko")
```

위젯화면에 표시되는 언어를 변경합니다. 현재 `'ko'`, `'en'`, `'ja'`만 지원됩니다.&#x20;

### **Parameters**

* &#x20;`language` \<String>\
  위젯 화면에 표시될 언어
* `currency` \<String>  *optional*\
  위젯 화면에 표시될&#x20;

### **화Return value**

* `CompletableFuture` \<Boolean>\
  정상적으로 잘 된 경우 **true** , 실패한 경우 **false** 를 반환합니다.

### **Example**

{% tabs %}
{% tab title="Java" %}

```java
wepinWidget.changeLanguage("ko", null).whenComplete((res, err) -> {
    if (err == null) {
        System.out.println(res);
    } else {
        System.out.println(err);
    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
wepinWidget.changeLanguage("ko").whenComplete{ res, err ->
    if (err == null) {
      println(res)
    } else {
      println(err)
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/widget-integration/android-java-and-kotlin-sdk/widget-library/initialization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
