package org.ntlab.acanthus_client.views.animation_detail;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.R;
import org.ntlab.acanthus_client.entities.Animation;
import org.ntlab.acanthus_client.views.animation.AnimationActivity;
import org.ntlab.acanthus_client.views.animation.AnimationCanvas;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class AnimationDetailActivity extends AppCompatActivity  {

    private AnimationCanvas animationDetails;
    private View view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Acanthus acanthus = (Acanthus) getApplication();
        Animation currentAnimation = acanthus.getCurrentAnimation();
        setContentView(R.layout.activity_animation_detail);

        //文字入力テスト
        EditText editText = findViewById(R.id.edit_text);
        TextView wordText = findViewById(R.id.word_text);
        TextView wordText2 = findViewById(R.id.word_text2);
        Button wordButton = findViewById(R.id.word_button);
        TextView wordText15 = findViewById(R.id.textView15);
        wordText15.setText(currentAnimation.getName());
        TextView wordText16 = findViewById(R.id.textView16);
        wordText16.setText(currentAnimation.getAid().toString());
        TextView wordText17 = findViewById(R.id.textView17);
        wordText17.setText(currentAnimation.getCreatedDate().toString());
        TextView wordText18 = findViewById(R.id.textView18);

        wordButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // エディットテキストのテキストを取得
                String text = editText.getText().toString();
                // 取得したテキストを TextView に張り付ける
                wordText.setText(text);
                wordText2.setText(text);
            }
        });

        //画面を閉じる
        Button returnButton = findViewById(R.id.return_button);
        returnButton.setOnClickListener(v -> finish());

        //作成者のページに移動（今は仮でアニメーション画面へ）
        Button buttonEditor1 = findViewById(R.id.button_editor1);
        buttonEditor1.setOnClickListener((View v) -> {
                    Intent intent = new Intent(AnimationDetailActivity.this, AnimationActivity.class);
                    startActivity(intent);
                }
        );

 /*       //作成者のページに移動（今は仮でアニメーション画面へ）
        Button buttonEditor2 = findViewById(R.id.button_editor2);
        buttonEditor2.setOnClickListener((View v) -> {
                    Intent intent = new Intent(AnimationDetailActivity.this, AnimationActivity.class);
                    startActivity(intent);
                }
        );


*//*        //レイアウトパラム定数(縦横の長さの定数)の格納
        final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
        final int MP = ViewGroup.LayoutParams.MATCH_PARENT;*//*

        //基礎画面の作成
        LinearLayout oLayout = new LinearLayout(getApplicationContext());
        oLayout.setOrientation(LinearLayout.VERTICAL);
        setContentView(oLayout);

*//*        //普通のviewの生成
        ImageView oImg = new ImageView(getApplicationContext());
        //横MAXの縦幅は画像と同じ高さ
        oImg.setLayoutParams(new LinearLayout.LayoutParams(MP, WC));*//*

        ImageView oImg = findViewById(R.id.samune);

        URL url;
        InputStream stream;
        try {
            //画像のURLを直うち
            url = new URL("http://nitta-lab-www.is.konan-u.ac.jp/gallery/test/0/test.jpg");
            //インプットストリームで画像を読み込む
            stream = url.openStream();
            //読み込んだファイルをビットマップに変換
            Bitmap oBmp = BitmapFactory.decodeStream(stream);
            //ビットマップをImageViewに設定
            oImg.setImageBitmap(oBmp);
            //インプットストリームを閉じる
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        oLayout.addView(oImg);*/
    }

}



