0% found this document useful (0 votes)
30 views6 pages

Mad13 1

Uploaded by

kamble04ay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views6 pages

Mad13 1

Uploaded by

kamble04ay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Subject: MAD[22617] Practical no: 13

Performed by: Ritesh Doibale Roll no: 41

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;

public class MainActivity extends AppCompatActivity {

private ProgressBar circularProgressBar;

@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

2-W. a. Program to implement following output.


 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<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;

public class MainActivity extends AppCompatActivity {


Button btnStartProgress;
ProgressDialog progressBar;
private int progressBarStatus = 0;
private Handler progressBarHandler = new Handler();
private long fileSize = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick() {
btnStartProgress = findViewById(R.id.button);
btnStartProgress.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

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

You might also like