/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.onecable.view.dialog;

import com.ntels.onecable.R;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
 * <pre>
 * 1. ClassName :   CommonToast
 * 2. FileName  :   CommonToast.java
 * 3. Package   :   com.ntels.onecable.view.dialog
 * 4. Date      :   2016-12-05
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class CommonToast extends Toast {

    Context mContext;

    /**
     * 생성자.
     *
     * @param context 컨텍스트
     */
    public CommonToast(Context context) {

        super(context);
        mContext = context;
    }

    /**
     * Toast message display.
     *
     * @param body Message
     * @param duration Duration
     */
    public void showToast(String body, int duration) {
        // http://developer.android.com/guide/topics/ui/notifiers/toasts.html
        LayoutInflater inflater;
        View v;
        if (false) {
            Activity act = (Activity) mContext;
            inflater = act.getLayoutInflater();
            v = inflater.inflate(R.layout.toast_layout, null);
        } else {  // same
            inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.toast_layout, null);
        }
        TextView text = (TextView) v.findViewById(R.id.text);
        text.setText(body);

        show(this, v, duration);
    }

    /**
     * Toast message display.
     *
     * @param toast Toast object
     * @param v Custom view
     * @param duration Duration
     */
    private void show(Toast toast, View v, int duration) {

        toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        toast.setDuration(duration);
        toast.setView(v);
        toast.show();
    }
}