KProgressHUD Documentation

repository·master·Indexed 23 days ago

https://github.com/kaopiz/kprogresshud

An Android progress HUD implementation inspired by iOS's MBProgressHUD. It provides indeterminate and determinate progress indicators, support for custom views, and customizable labels and animations. Version 1.2.0.

Tokens
782
Snippets
4
Records
5
Agent score
32%

What's inside KProgressHUD

  1. KProgressHUD Lifecycle and Usage Pattern

    master

    The standard workflow for using KProgressHUD is:

    1. Create and Show: Call KProgressHUD.create(Context) on the UI thread, customize the style, and call .show().
    2. Background Work: Execute long-running tasks in a background worker.
    3. Dismiss:
      • For Indeterminate HUDs: Manually call dismiss() when the task is complete.
      • For Determinate HUDs: The HUD automatically dismisses when setProgress() reaches the value set in setMaxProgress().
  2. Add KProgressHUD to your project via Gradle

    master

    To include KProgressHUD in your Android project, add the following dependency to your app-level build.gradle file.

    dependencies {
        // Other dependencies
        implementation 'com.kaopiz:kprogresshud:1.2.0'
    }
  3. Show a Determinate HUD

    master

    Use a determinate style when you want to track progress. You must set a maximum progress value using .setMaxProgress(). You can update the current progress using the .setProgress(int) method on the returned KProgressHUD instance. The HUD will automatically dismiss when progress reaches its maximum.

    KProgressHUD hud = KProgressHUD.create(MainActivity.this)
    		.setStyle(KProgressHUD.Style.ANNULAR_DETERMINATE)
    		.setLabel("Please wait")
    		.setMaxProgress(100)
    		.show();
    hud.setProgress(90);
  4. Show an Indeterminate HUD

    master

    Use an indeterminate style when the duration of the background task is unknown. You can customize the label, details, animation speed, and dim amount. Use .show() to display it on the UI thread.

    KProgressHUD.create(MainActivity.this)
    	.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
    	.setLabel("Please wait")
    	.setDetailsLabel("Downloading data")
    	.setCancellable(true)
    	.setAnimationSpeed(2)
    	.setDimAmount(0.5f)
    	.show();
  5. Use a Custom View in KProgressHUD

    master

    You can provide a custom view to be displayed within the HUD using .setCustomView(View). If the custom view implements the Determinate or Indeterminate interface, KProgressHUD will treat it as the default determinate or indeterminate view respectively.

    ImageView imageView = new ImageView(this);
    imageView.setBackgroundResource(R.drawable.spin_animation);
    AnimationDrawable drawable = (AnimationDrawable) imageView.getBackground();
    drawable.start();
    KProgressHUD.create(MainActivity.this)
       .setCustomView(imageView)
       .setLabel("This is a custom view")
       .show();