diff --git a/app/src/main/java/com/example/nemophila/MyPageActivity.java b/app/src/main/java/com/example/nemophila/MyPageActivity.java index c6ef3de..e64cb04 100644 --- a/app/src/main/java/com/example/nemophila/MyPageActivity.java +++ b/app/src/main/java/com/example/nemophila/MyPageActivity.java @@ -10,23 +10,39 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.example.nemophila.entities.Post; import com.example.nemophila.viewmodels.AccountViewModel; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static android.os.AsyncTask.execute; public class MyPageActivity extends AppCompatActivity { + private final ExecutorService executor = Executors.newSingleThreadExecutor(); + private final Handler handler = new Handler(); + private String iconUrlString; + private ImageView icon; + //MyPageActivity画面の作成 @Override protected void onCreate(Bundle savedInstanceState) { @@ -43,6 +59,27 @@ TextView id = (TextView) findViewById(R.id.id); id.setText(uid); + //アイコン仮セット + //url作る + icon = findViewById(R.id.icon); + iconUrlString = "http://nitta-lab-www.is.konan-u.ac.jp/nemophila-data/test01.jpg"; + executor.execute(() -> { + try{ + URL url = new URL(iconUrlString); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.connect(); + + InputStream is = con.getInputStream(); + + Bitmap bitmap = BitmapFactory.decodeStream(is); + handler.post(() -> icon.setImageBitmap(bitmap)); + is.close(); + con.disconnect(); + }catch (Exception e){ + e.printStackTrace(); + } + }); + // 「閉じる」ボタンを押したときにメイン画面へ遷移する Button closeButton = (Button) findViewById(R.id.close); closeButton.setOnClickListener(new View.OnClickListener() {