Mad13 1
Mad13 1
Exercise:
1-W a Program to implement cicular progressbar.
Activity_main.xml
<RelativeLayout
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"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/circularProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="gone"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/startButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Circular Progress Bar"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"/>
</RelativeLayout>
1|Page
Subject: MAD[22617] Practical no: 13
Performed by: Ritesh Doibale Roll no: 41
MainActivity.java
package com.example.circularprogressbar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
circularProgressBar = findViewById(R.id.circularProgressBar);
Button startButton = findViewById(R.id.startButton);
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
circularProgressBar.setVisibility(View.VISIBLE);
}
});
}
}
2|Page
Subject: MAD[22617] Practical no: 13
Performed by: Ritesh Doibale Roll no: 41
Output:
3|Page
Subject: MAD[22617] Practical no: 13
Performed by: Ritesh Doibale Roll no: 41
<Button
android:id="@+id/button"
android:layout_width="225dp"
android:layout_height="88dp"
android:textSize="50px"
android:layout_gravity="center"
android:text="download file" />
</FrameLayout>
MainActivity.java
package com.example.progressbar;
import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
4|Page
Subject: MAD[22617] Practical no: 13
Performed by: Ritesh Doibale Roll no: 41
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus = 0;
fileSize = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
progressBarStatus = doOperation();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
if (progressBarStatus >= 100) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBar.dismiss();
}
}
}).start();
}
});
}
public int doOperation() {
while (fileSize <= 10000) {
fileSize++;
if (fileSize == 1000) {
return 10;
} else if (fileSize == 2000) {
return 20;
} else if (fileSize == 3000) {
return 30;
} else if (fileSize == 4000) {
return 40;
}
}
return 100;
}
}
Output:
5|Page
Subject: MAD[22617] Practical no: 13
Performed by: Ritesh Doibale Roll no: 41
6|Page