# Initialization

The method for initializing the Wepin Android Widget Library is as follows.

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

Before creating an instance of `WepinWidget`, please pass the app’s Activity Context, the app ID, and the app key assigned after app registration to the `WepinWidgetParams` object as shown below.

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

Please create a `WepinWidget` instance by passing the previously created `WepinWidgetParams`.

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

After creating the `WepinWidget` instance, call the `initialize` method to complete the initialization.

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

#### parameters

&#x20;`atrributes` \<WepinWidgetAttributes>

* `defualtLanguage` \<String>\
  The default language setting for the Widget screen is `'en'`. Currently supported languages are `'ko'`, `'en'`, and `'ja'`.
* `defualtCurrency` \<String>\
  The default currency setting for the Widget screen is `'USD'`. Currently supported currencies are `'KRW'`, `'USD'`, and `'JPY'`.

#### Return value

`CompletableFuture` \<Boolean>\
Returns **true** if successful, and **false** if it fails.

### 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();

        // Initialize Wepin PIN Pad Library 
        WepinWidgetParams wepinWidgetParams = new WepinWidgetParams(
            this,
            "your-wepin-app-id",
            "your-wepin-app-key"
        );
        wepinWidget = new WepinWidget(wepinWidgetParams);
        
        WepinWidgetAttributes attributes = new WepinWidgetAttributes("en", "USD);
        CompletableFuture<InfResponse> res = wepinPin.initialize(attributes);
        if (res != null) {
            res.whenComplete((infResponse, error) -> {
                if (error == null) {
                    System.out.println(infResponse);
                } 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()
        
        // Initialize Wepin PIN Pad Libary 
        val wepinWidgetParams =  WepinWidgetParams(
            context = this,
            appId = 'your-wepin-app-id',
            appKey = 'your-wepin-app-key'
        )
        wepinWidget = WepinWidget(wepinWidgetParams)       
        var attributes = WepinWidgetAttributes("en", "USD")
        val res = wepinWidget.initialize(attributes)
        res?.whenComplete { infResponse, error ->
          if (error == null) {
            println(infResponse)
          } else {
            println(error) 
          }
      }        
    // ...
}
```

{% endtab %}
{% endtabs %}

## isInitialized

You can use the `isInitialized` method to check if the `WepinPin` instance has been successfully initialized.

The return values are as follows

* \<Boolean>\
  Returns **true** if initialization was successful and **false** if it failed.

### 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")
```

Changes the language displayed on the Widget screen. Currently, only `'ko'`, `'en'`, and `'ja'` are supported.<br>

### **Parameters**

* &#x20;`language` \<String>

### **Return value**

* `CompletableFuture` \<Boolean>\
  Returns **true** if successful and **false** if it fails.

### **Example**

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

```java
wepinWidget.changeLanguage("ko").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/en/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.
