package com.handset.serialportsensor.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.handset.serialportsensor.R;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Created by zy on 2019/2/28.
 */

public class ViewLogActivity extends AppCompatActivity {

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_log);
    Intent intent = getIntent();
    String filePath = intent.getStringExtra("file_path");

    TextView tv_log = findViewById(R.id.tv_log);
    TextView tvTitle = findViewById(R.id.title_text);
    ImageView ivBack = findViewById(R.id.title_back);
    tvTitle.setText("操作日志");
    ivBack.setVisibility(View.VISIBLE);
    ivBack.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        ViewLogActivity.this.finish();
      }
    });

    if (!TextUtils.isEmpty(filePath)) {
      String ac = getfileC(filePath);
      tv_log.setText(ac);
    }

  }


  private String getfileC(String filePath) {
    String c = "";
    File file = new File(filePath);
    FileInputStream in;
    try {
      in = new FileInputStream(file);
      int l = (int) file.length();
      byte[] filecontent = new byte[l];
      in.read(filecontent);
      in.close();
      c = new String(filecontent);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return c;
  }
}
