package com.njnu.kai.practice.za;

import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.njnu.kai.practice.R;
import com.njnu.kai.support.BaseTestFragment;
import com.njnu.kai.support.ViewUtils;

import org.threeten.bp.Instant;
import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.format.DateTimeFormatter;

/**
 * @author hongkai.qian
 * @version 1.0.0
 * @since 16/5/15
 */
public class EditTextOutputFragment extends BaseTestFragment {

    private EditText mEdtResult;

    @Override
    protected View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frament_edit_text_output, container, false);
        mEdtResult = ViewUtils.findEditTextById(view, R.id.edt_result);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Instant nowInstant = Instant.now();
        appendResult(nowInstant);
        ZonedDateTime nowZonedDateTime = ZonedDateTime.now();
        appendResult(nowZonedDateTime);
        appendResult(nowZonedDateTime.withDayOfMonth(1).format(DateTimeFormatter.ISO_DATE_TIME));
        appendResult(nowZonedDateTime.plusDays(2).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        Resources resources = getResources();
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 0));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 1));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 2));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 3));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 4));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 5));
        appendResult("xxxx");
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 0, 0));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 1, 1));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 2, 2));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 3, 3));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 4, 4));
        appendResult(resources.getQuantityString(R.plurals.plurals_test, 5, 5));

        appendResult(resources.getQuantityString(R.plurals.buy_kindle, 1));
        appendResult(resources.getQuantityString(R.plurals.buy_kindle, 2));
    }

    private String transformToStr(Object object) {
        return object != null ? object.toString() : "<object=null>";
    }

    public void setResult(Object object) {
        mEdtResult.setText(transformToStr(object));
    }

    public void appendResult(Object object) {
        String oriStr = mEdtResult.getText().toString();
        mEdtResult.setText(oriStr + "\n" + transformToStr(object));
    }
}

@@ -909,24 +909,182 @@
 dt_result);%0A
+        mEdtResult.setSingleLine(true);%0A%0A        mEdtResult.setLines(10); //%E5%89%8D%E9%9D%A2%E8%A2%AB%E8%AE%BE%E7%BD%AE%E8%BF%87singleLine true%E5%90%8E, %E6%AD%A4%E5%A4%84lines 10%E4%BC%9A%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%0A        mEdtResult.setSingleLine(false);%0A%0A
         retu

test single line and lines