Sửa để hình ảnh có thể hiển thị trên cả status bar Sửa để có thể hiển thị nhiều hình ảnh…
- User
Sửa để hình ảnh có thể hiển thị trên cả status bar Sửa để có thể hiển thị nhiều hình ảnh trên màn hình Nhấn vào imageThumbnail, nếu hình ảnh dòng này đang hiển thị trên màn hình thì sẽ hiển thị lên bảng điều khiển của hình đó trong bảng điều khiển, khi nhấn giữ các nút di chuyển thì sẽ di chuyển nhanh hơn
package com.vn.stt3;
import android.app.Dialog; import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.SeekBar; import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity { private static final int PICK_IMAGES_REQUEST = 1;
// Danh sách hình ảnh private ArrayList<ImageModel> imageList = new ArrayList<>(); private ImageAdapter imageAdapter; // ImageView nổi để hiển thị ảnh khi chọn private ImageView floatingImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = findViewById(R.id.imageListView); Button addImageButton = findViewById(R.id.addImageButton); floatingImageView = findViewById(R.id.floatingImageView); imageAdapter = new ImageAdapter(); listView.setAdapter(imageAdapter); // Mở trình chọn ảnh addImageButton.setOnClickListener(v -> selectImages()); // Nhấn vào ảnh nổi sẽ mở popup điều khiển floatingImageView.setOnClickListener(v -> showControlDialog()); } private void selectImages() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); // Cho phép chọn nhiều ảnh startActivityForResult(Intent.createChooser(intent, "Chọn ảnh"), PICK_IMAGES_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_IMAGES_REQUEST && resultCode == RESULT_OK) { if (data != null) { // Nhiều ảnh được chọn if (data.getClipData() != null) { int count = data.getClipData().getItemCount(); // Số lượng ảnh được chọn for (int i = 0; i < count; i++) { Uri imageUri = data.getClipData().getItemAt(i).getUri(); handleSelectedImage(imageUri); } } // Một ảnh được chọn else if (data.getData() != null) { Uri imageUri = data.getData(); handleSelectedImage(imageUri); } } } } private void handleSelectedImage(Uri imageUri) { // Thêm ảnh (GIF hoặc tĩnh) vào danh sách, dùng Glide để kiểm tra loại file ImageModel imageModel = new ImageModel(imageUri); imageList.add(imageModel); imageAdapter.notifyDataSetChanged(); // Cập nhật giao diện } private void showControlDialog() { Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_control); SeekBar sizeSeekBar = dialog.findViewById(R.id.sizeSeekBar); SeekBar opacitySeekBar = dialog.findViewById(R.id.opacitySeekBar); Button btnLeft = dialog.findViewById(R.id.btnLeft); Button btnUp = dialog.findViewById(R.id.btnUp); Button btnDown = dialog.findViewById(R.id.btnDown); Button btnRight = dialog.findViewById(R.id.btnRight); sizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { float scale = 0.1f + (progress / 100f) * 3; floatingImageView.setScaleX(scale); floatingImageView.setScaleY(scale); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); opacitySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { float alpha = 0.1f + (progress / 100f) * 0.9f; floatingImageView.setAlpha(alpha); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); btnLeft.setOnClickListener(v -> floatingImageView.setX(floatingImageView.getX() - 10)); btnRight.setOnClickListener(v -> floatingImageView.setX(floatingImageView.getX() + 10)); btnUp.setOnClickListener(v -> floatingImageView.setY(floatingImageView.getY() - 10)); btnDown.setOnClickListener(v -> floatingImageView.setY(floatingImageView.getY() + 10)); dialog.show(); } // -------- ImageModel (dùng để chứa dữ liệu ảnh) -------- private static class ImageModel { private Uri uri; // URI của ảnh (dùng cho cả GIF và ảnh tĩnh) private boolean isVisible = true; private float alpha = 1.0f; private float scale = 0.2f; private float positionX = 0; private float positionY = 0; public ImageModel(Uri uri) { this.uri = uri; } public Uri getUri() { return uri; } public boolean isVisible() { return isVisible; } public void setVisible(boolean visible) { isVisible = visible; } public float getAlpha() { return alpha; } public void setAlpha(float alpha) { this.alpha = alpha; } public float getScale() { return scale; } public void setScale(float scale) { this.scale = scale; } public float getPositionX() { return positionX; } public void setPositionX(float positionX) { this.positionX = positionX; } public float getPositionY() { return positionY; } public void setPositionY(float positionY) { this.positionY = positionY; } } // -------- ImageAdapter (hiển thị danh sách hình ảnh) -------- private class ImageAdapter extends BaseAdapter { @Override public int getCount() { return imageList.size(); } @Override public Object getItem(int position) { return imageList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(MainActivity.this); convertView = inflater.inflate(R.layout.image_item, parent, false); } ImageModel imageModel = imageList.get(position); ImageView imageThumbnail = convertView.findViewById(R.id.imageThumbnail); Button btnDisplay = convertView.findViewById(R.id.btnDisplay); Button btnClone = convertView.findViewById(R.id.btnClone); Button btnHide = convertView.findViewById(R.id.btnHide); Button btnDelete = convertView.findViewById(R.id.btnDelete); // Sử dụng Glide để tải ảnh (hỗ trợ cả GIF và ảnh tĩnh) Glide.with(MainActivity.this) .load(imageModel.getUri()) .into(imageThumbnail); btnDisplay.setOnClickListener(v -> { floatingImageView.setVisibility(View.VISIBLE); Glide.with(MainActivity.this) .load(imageModel.getUri()) .into(floatingImageView); // Hiển thị GIF hoặc ảnh tĩnh // Áp dụng trạng thái lưu trước đó floatingImageView.setScaleX(imageModel.getScale()); floatingImageView.setScaleY(imageModel.getScale()); floatingImageView.setAlpha(imageModel.getAlpha()); floatingImageView.setX(imageModel.getPositionX()); floatingImageView.setY(imageModel.getPositionY()); }); btnClone.setOnClickListener(v -> { imageList.add(new ImageModel(imageModel.getUri())); // Clone ảnh notifyDataSetChanged(); }); btnHide.setOnClickListener(v -> { floatingImageView.setVisibility(View.GONE); // Lưu trạng thái ẩn imageModel.setVisible(false); imageModel.setScale(floatingImageView.getScaleX()); imageModel.setAlpha(floatingImageView.getAlpha()); imageModel.setPositionX(floatingImageView.getX()); imageModel.setPositionY(floatingImageView.getY()); }); btnDelete.setOnClickListener(v -> { imageList.remove(position); // Xóa ảnh notifyDataSetChanged(); }); return convertView; } } - Assistant
- User
Bảng điều khiển sẽ hiển thị phía trên hình để có thể thao tác mà không bị hình che phủ. Mỗi hình sẽ chỉ 1 bảng điều khiển, nếu bảng đang hiển thị thì nhấn vào hình sẽ mở lại bảng chứ không tạo thêm 1 bảng mới.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.