0

I am trying to make a custom ProgressBar class, in which I want to display a ProgressBar with image rotation.

What I tried was...

my_progress_indeterminate.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spool"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromDegrees="0"
    android:toDegrees="1080">
</rotate>

MyProgress.java

public class MyProgress extends ProgressDialog {
  //private AnimationDrawable animation;
  ProgressBar la;
  public ProgressDialog ctor(Context context) {
    MyProgress dialog = new MyProgress(context);
    dialog.setIndeterminate(true);
    dialog.setIndeterminateDrawable(this.getContext().getResources().getDrawable(R.drawable.my_progress_indeterminate));
    dialog.setCancelable(false);
    return dialog;
  }

  public MyProgress(Context context) {
    super(context);
  }

  public MyProgress(Context context, int theme) {
    super(context, theme);
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_loader);

     la = (ProgressBar) findViewById(R.id.animation);


  }

  @Override
  public void show() {
    super.show();
//show the progressbar which is rotating image

  }

  @Override
  public void dismiss() {
    super.dismiss();
   //hide the progress which is rotating image
  }
}

In my other class where I want to show progress, I am doing like this :

MyProgress rotateImage;
protateImage = new MyProgress(getActivity());

 protateImage.show(); //for showing 

protateImage.hide(); //for hiding 

ViewLoader.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@null"
    >


    <ProgressBar
        android:id="@+id/animation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dip"
        android:indeterminateDrawable="@drawable/my_progress_indeterminate" />

</LinearLayout>

It works well , but I am unable to see my image rotating , only androids custom progressbar spinning style is shown , with a dialog background.

What I want is to show only my image rotating anywhere in my project by creating an instance of my class and showing progressbar (rotating image ) or hiding it ...

How can I make it correct? any help ...

sschrass
  • 7,014
  • 6
  • 43
  • 62

1 Answers1

0

Follow this answer.

The only thing you will need to do in addition to that is to add your custom loading drawable, using setIndeterminateDrawable():

ProgressDialog pd = new ProgressDialog(getActivity(), R.style.MyTheme);
pd.setCancelable(false);
pd.setIndeterminateDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.my_progress_indeterminate));
pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
pd.show();`

No need for a custom ProgressDialog subclass.

Mateus Gondim
  • 5,362
  • 6
  • 31
  • 51