Search in sources :

Example 56 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project PhotoBlog-Android-Blog-App by akshayejh.

the class SetupActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup);
    Toolbar setupToolbar = findViewById(R.id.setupToolbar);
    setSupportActionBar(setupToolbar);
    getSupportActionBar().setTitle("Account Setup");
    firebaseAuth = FirebaseAuth.getInstance();
    user_id = firebaseAuth.getCurrentUser().getUid();
    firebaseFirestore = FirebaseFirestore.getInstance();
    storageReference = FirebaseStorage.getInstance().getReference();
    setupImage = findViewById(R.id.setup_image);
    setupName = findViewById(R.id.setup_name);
    setupBtn = findViewById(R.id.setup_btn);
    setupProgress = findViewById(R.id.setup_progress);
    setupProgress.setVisibility(View.VISIBLE);
    setupBtn.setEnabled(false);
    firebaseFirestore.collection("Users").document(user_id).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {

        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
            if (task.isSuccessful()) {
                if (task.getResult().exists()) {
                    String name = task.getResult().getString("name");
                    String image = task.getResult().getString("image");
                    mainImageURI = Uri.parse(image);
                    setupName.setText(name);
                    RequestOptions placeholderRequest = new RequestOptions();
                    placeholderRequest.placeholder(R.drawable.default_image);
                    Glide.with(SetupActivity.this).setDefaultRequestOptions(placeholderRequest).load(image).into(setupImage);
                }
            } else {
                String error = task.getException().getMessage();
                Toast.makeText(SetupActivity.this, "(FIRESTORE Retrieve Error) : " + error, Toast.LENGTH_LONG).show();
            }
            setupProgress.setVisibility(View.INVISIBLE);
            setupBtn.setEnabled(true);
        }
    });
    setupBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String user_name = setupName.getText().toString();
            if (!TextUtils.isEmpty(user_name) && mainImageURI != null) {
                setupProgress.setVisibility(View.VISIBLE);
                if (isChanged) {
                    user_id = firebaseAuth.getCurrentUser().getUid();
                    File newImageFile = new File(mainImageURI.getPath());
                    try {
                        compressedImageFile = new Compressor(SetupActivity.this).setMaxHeight(125).setMaxWidth(125).setQuality(50).compressToBitmap(newImageFile);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    compressedImageFile.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                    byte[] thumbData = baos.toByteArray();
                    UploadTask image_path = storageReference.child("profile_images").child(user_id + ".jpg").putBytes(thumbData);
                    image_path.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {

                        @Override
                        public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                            if (task.isSuccessful()) {
                                storeFirestore(task, user_name);
                            } else {
                                String error = task.getException().getMessage();
                                Toast.makeText(SetupActivity.this, "(IMAGE Error) : " + error, Toast.LENGTH_LONG).show();
                                setupProgress.setVisibility(View.INVISIBLE);
                            }
                        }
                    });
                } else {
                    storeFirestore(null, user_name);
                }
            }
        }
    });
    setupImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (ContextCompat.checkSelfPermission(SetupActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(SetupActivity.this, "Permission Denied", Toast.LENGTH_LONG).show();
                    ActivityCompat.requestPermissions(SetupActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 1);
                } else {
                    BringImagePicker();
                }
            } else {
                BringImagePicker();
            }
        }
    });
}
Also used : Task(com.google.android.gms.tasks.Task) UploadTask(com.google.firebase.storage.UploadTask) RequestOptions(com.bumptech.glide.request.RequestOptions) Compressor(id.zelory.compressor.Compressor) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) View(android.view.View) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) UploadTask(com.google.firebase.storage.UploadTask) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) NonNull(android.support.annotation.NonNull) File(java.io.File) Toolbar(android.support.v7.widget.Toolbar)

Example 57 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MyBaseApplication by BanShouWeng.

the class GlideUtils method loadImageViewPriority.

// 设置下载优先级
public static void loadImageViewPriority(Context mContext, String path, ImageView mImageView) {
    RequestOptions options = new RequestOptions().priority(Priority.NORMAL);
    Glide.with(mContext).load(path).apply(options).into(mImageView);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 58 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MyBaseApplication by BanShouWeng.

the class GlideUtils method loadImageViewLodingSize.

// 设置加载中以及加载失败图片并且指定大小
public static void loadImageViewLodingSize(Context mContext, String path, int width, int height, ImageView mImageView, int lodingImage, int errorImageView) {
    RequestOptions options = new RequestOptions().centerCrop().override(width, height).placeholder(lodingImage).error(errorImageView);
    Glide.with(mContext).load(path).apply(options).into(mImageView);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 59 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MyBaseApplication by BanShouWeng.

the class GlideUtils method loadImageViewCache.

// 设置跳过内存缓存
public static void loadImageViewCache(Context mContext, String path, ImageView mImageView) {
    RequestOptions options = new RequestOptions().skipMemoryCache(true);
    Glide.with(mContext).load(path).apply(options).into(mImageView);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 60 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MyBaseApplication by BanShouWeng.

the class GlideUtils method loadImageViewDiskCache.

/**
 * 策略解说:
 * <p>
 * all:缓存源资源和转换后的资源
 * <p>
 * none:不作任何磁盘缓存
 * <p>
 * source:缓存源资源
 * <p>
 * result:缓存转换后的资源
 */
// 设置缓存策略
public static void loadImageViewDiskCache(Context mContext, String path, ImageView mImageView) {
    RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL);
    Glide.with(mContext).load(path).apply(options).into(mImageView);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Aggregations

RequestOptions (com.bumptech.glide.request.RequestOptions)96 ImageView (android.widget.ImageView)23 View (android.view.View)18 Drawable (android.graphics.drawable.Drawable)16 TextView (android.widget.TextView)13 Bitmap (android.graphics.Bitmap)9 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 File (java.io.File)8 Uri (android.net.Uri)7 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Context (android.content.Context)5 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 DataSource (com.bumptech.glide.load.DataSource)5 GlideException (com.bumptech.glide.load.engine.GlideException)5 FitCenter (com.bumptech.glide.load.resource.bitmap.FitCenter)5 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)5 Test (org.junit.Test)5 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3