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

Mad Exp13 Deepesh

The document describes an Android layout with a circular progress bar. It includes XML code for the layout, drawable resources, and Java code to update the progress bar over time.

Uploaded by

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

Mad Exp13 Deepesh

The document describes an Android layout with a circular progress bar. It includes XML code for the layout, drawable resources, and Java code to update the progress bar over time.

Uploaded by

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

<?xml version="1.0" encoding="utf-8"?

>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Exp13_1:circular progress bar"
android:textSize="18dp"
android:textColor="#0000FF"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<RelativeLayout
android:id="@+id/progress_layout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">

<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shape"
android:indeterminate="false"
android:progressDrawable="@drawable/cicrular"
android:textAlignment="center" />

<TextView
android:id="@+id/progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:textColor="#00ff00"
android:textSize="28sp"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="~Developed by Deepesh Navani - 15"
android:textColor="#0000FF"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="35dp"
android:layout_marginEnd="35dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

circular.xml:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">

<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="8dp"
android:useLevel="true">
<gradient
android:angle="0"
android:endColor="#00ff00"
android:startColor="#00ff00"
android:type="sweep"
android:useLevel="false" />
</shape>

</rotate>
shape.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="3dp"
android:useLevel="false">
<solid android:color="#00ff00" />
</shape>

MainActivity.java:
package com.example.exp13_1;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private ProgressBar progressBar;


private TextView progressText;
int i = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = findViewById(R.id.progress_bar);
progressText = findViewById(R.id.progress_text);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (i <= 100) {
progressText.setText("" + i);
progressBar.setProgress(i);
i++;
handler.postDelayed(this, 200);
} else {
handler.removeCallbacks(this);
}
}
}, 200);
}
}

Output:
Exp13_2: Write a program to show the following output.
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Exp13_2:Progress Bar Output"
android:textSize="18dp"
android:textColor="#0000FF"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<RelativeLayout
android:id="@+id/progress_layout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DOWNLOAD FILE"
android:background="@color/cardview_light_background"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="~Developed By Deepesh Navani - 15"
android:textColor="#0000FF"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="35dp"
android:layout_marginEnd="35dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.exp13_2;

import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

ProgressDialog pb;
int progressStatus=0;
TextView tv;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler handler=new Handler();

b1=(Button) findViewById(R.id.btn);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pb=new ProgressDialog(v.getContext());
pb.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pb.setCancelable(true);
pb.setMessage("File downloading...");
pb.setProgress(0);
pb.setMax(100);
pb.show();
new Thread(new Runnable() {
@Override
public void run() {
while (progressStatus <100) {
progressStatus += 1;
handler.post(new Runnable() {
@Override
public void run() {
pb.setProgress(progressStatus);
}

});

try {
Thread.sleep(50);
} catch (Exception e) {
e.printStackTrace();
}
}
if(progressStatus>=100)
{
try{
Thread.sleep(1000);
}
catch (Exception e) {
e.printStackTrace();
}
pb.dismiss();
progressStatus=0;
}
}
}).start();
}
});
}
}

Output:

You might also like