Last active
July 15, 2021 08:08
-
-
Save ParkSangGwon/4b5c8c581eb74a6c82ac07395d72e656 to your computer and use it in GitHub Desktop.
Progress dialog using GIF image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseActivity extends AppCompatActivity { | |
public void progressON() { | |
BaseApplication.getInstance().progressON(this, null); | |
} | |
public void progressON(String message) { | |
BaseApplication.getInstance().progressON(this, message); | |
} | |
public void progressOFF() { | |
BaseApplication.getInstance().progressOFF(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseApplication extends Application { | |
private static BaseApplication baseApplication; | |
AppCompatDialog progressDialog; | |
public static BaseApplication getInstance() { | |
return baseApplication; | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
baseApplication = this; | |
} | |
public void progressON(Activity activity, String message) { | |
if (activity == null || activity.isFinishing()) { | |
return; | |
} | |
if (progressDialog != null && progressDialog.isShowing()) { | |
progressSET(message); | |
} else { | |
progressDialog = new AppCompatDialog(activity); | |
progressDialog.setCancelable(false); | |
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); | |
progressDialog.setContentView(R.layout.progress_loading); | |
progressDialog.show(); | |
} | |
final ImageView img_loading_frame = (ImageView) progressDialog.findViewById(R.id.iv_frame_loading); | |
final AnimationDrawable frameAnimation = (AnimationDrawable) img_loading_frame.getBackground(); | |
img_loading_frame.post(new Runnable() { | |
@Override | |
public void run() { | |
frameAnimation.start(); | |
} | |
}); | |
TextView tv_progress_message = (TextView) progressDialog.findViewById(R.id.tv_progress_message); | |
if (!TextUtils.isEmpty(message)) { | |
tv_progress_message.setText(message); | |
} | |
} | |
public void progressSET(String message) { | |
if (progressDialog == null || !progressDialog.isShowing()) { | |
return; | |
} | |
TextView tv_progress_message = (TextView) progressDialog.findViewById(R.id.tv_progress_message); | |
if (!TextUtils.isEmpty(message)) { | |
tv_progress_message.setText(message); | |
} | |
} | |
public void progressOFF() { | |
if (progressDialog != null && progressDialog.isShowing()) { | |
progressDialog.dismiss(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" | |
android:oneshot="false"> | |
<item android:drawable="@drawable/frame_loading_01" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_02" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_03" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_04" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_05" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_06" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_07" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_08" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_09" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_10" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_11" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_12" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_13" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_14" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_15" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_16" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_17" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_18" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_19" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_20" android:duration="30"/> | |
<item android:drawable="@drawable/frame_loading_21" android:duration="30"/> | |
</animation-list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/loading_frame_container" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_centerInParent="true" | |
android:gravity="center" | |
android:orientation="vertical"> | |
<ImageView | |
android:id="@+id/iv_frame_loading" | |
android:layout_width="80dp" | |
android:layout_height="80dp" | |
android:background="@drawable/frame_loading"/> | |
<TextView | |
android:id="@+id/tv_progress_message" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:text="Loading.." | |
android:textAppearance="?android:attr/textAppearanceLarge" | |
android:textColor="#ffffff"/> | |
</LinearLayout> | |
</RelativeLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment