0% found this document useful (0 votes)
22 views35 pages

Android App Development Examples

The document outlines a series of experiments for creating Android applications, including a 'Hello World' app, a calculator app, a tic-tac-toe game, a login application, and a college course description app. Each experiment includes Java and XML code snippets necessary for implementation. The document serves as a guide for beginners to understand the structure and components of Android app development.

Uploaded by

mrravipatel111
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

Topics covered

  • Android Manifest,
  • Intent Handling,
  • Firebase Authentication,
  • Activity Lifecycle,
  • Java Code,
  • Shopping Bill Calculator,
  • User Experience,
  • User Authentication,
  • Mobile Applications,
  • XML Namespaces
0% found this document useful (0 votes)
22 views35 pages

Android App Development Examples

The document outlines a series of experiments for creating Android applications, including a 'Hello World' app, a calculator app, a tic-tac-toe game, a login application, and a college course description app. Each experiment includes Java and XML code snippets necessary for implementation. The document serves as a guide for beginners to understand the structure and components of Android app development.

Uploaded by

mrravipatel111
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

Topics covered

  • Android Manifest,
  • Intent Handling,
  • Firebase Authentication,
  • Activity Lifecycle,
  • Java Code,
  • Shopping Bill Calculator,
  • User Experience,
  • User Authentication,
  • Mobile Applications,
  • XML Namespaces

EXPERIMENT NO.

1
Hello world application to the middle screen in emulator as well as android
phone
Java file
package com.example.helloworld;
import android.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

Xml file
<?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:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

1
2
EXPERIMENT NO 2
Create a calculator app that performs addition , multiplication , sub on
numbers
Mainactivity.java file
package zone.eloy.projects.android calculator; import
android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View; import
android.widget.Button; import
android.widget.TextView; import
android.widget.Toast;

import java.math.BigDecimal;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,


View.OnTouchListener
{
private int openParenthesis = 0;

private boolean dotUsed = false;

private boolean equalClicked = false;


private String lastExpression = "";

private final static int EXCEPTION = -1;


private final static int IS_NUMBER = 0;
private final static int IS_OPERAND = 1;
private final static int IS_OPEN_PARENTHESIS = 2;
private final static int IS_CLOSE_PARENTHESIS = 3;
private final static int IS_DOT = 4;

Button buttonNumber0;
Button buttonNumber1;
Button buttonNumber2;
Button buttonNumber3;
Button buttonNumber4;
Button buttonNumber5;
Button buttonNumber6;

3
Button buttonNumber8;
Button buttonNumber9;

Button buttonClear; Button


buttonParentheses; Button
buttonPercent; Button
buttonDivision;
Button buttonMultiplication;
Button buttonSubtraction;
Button buttonAddition; Button
buttonEqual;
Button buttonDot;

TextView textViewInputNumbers;

ScriptEngine scriptEngine; @Override


protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scriptEngine = new ScriptEngineManager().getEngineByName("rhino");

initializeViewVariables();
setOnClickListeners();
setOnTouchListener();
}

private void initializeViewVariables()


{
buttonNumber0 = (Button) findViewById(R.id.button_zero);
buttonNumber1 = (Button) findViewById(R.id.button_one);
buttonNumber2 = (Button) findViewById(R.id.button_two);
buttonNumber3 = (Button) findViewById(R.id.button_three);
buttonNumber4 = (Button) findViewById(R.id.button_four);
buttonNumber5 = (Button) findViewById(R.id.button_five);
buttonNumber6 = (Button) findViewById(R.id.button_six);
buttonNumber7 = (Button) findViewById(R.id.button_seven);
buttonNumber8 = (Button) findViewById(R.id.button_eight);
buttonNumber9 = (Button) findViewById(R.id.button_nine);

buttonEqual = (Button) findViewById(R.id.button_equal);


buttonDot = (Button) findViewById(R.id.button_dot);
textViewInputNumbers = (TextView) findViewById(R.id.textView_input_numbers);
}

Xml file
<?xml version="1.0" encoding="utf-8"?>

4
<LinearLayout 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"
android:orientation="vertical"
android:layout_marginTop="0.5dp"
tools:context="projects.eloy.zone.androidtestproject.MainActivity">

<LinearLayout android:layout_marginTop="0.1dp"
android:layout_marginLeft="0.9dp"
android:layout_marginRight="0.1dp"
android:background="@android:color/black"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">

<TextView android:id="@+id/textView_input_numbers"
android:layout_marginTop="25dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:gravity="end"
android:textColor="@android:color/holo_purple"
android:textSize="40sp" />

</LinearLayout>

android:id="@+id/button_seven"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="0.9dp"
android:layout_marginRight="0.1dp"
android:layout_marginTop="0.1dp"
android:layout_weight="1"
android:background="@android:color/black"
android:text="7"
android:textColor="@android:color/white"
android:textSize="30sp" />

<Button android:id="@+id/button_eight"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="0.1dp"
android:layout_marginTop="0.1dp"
android:layout_weight="1"

5
android:background="@android:color/black"
android:text="8"
android:textColor="@android:color/white"
android:textSize="30sp" />
<Button android:id="@+id/button_multiplication"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="0.1dp"
android:layout_marginTop="0.1dp"
android:layout_weight="1"
android:background="@android:color/black"
android:text="x
<LinearLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">

<Button
android:id="@+id/button_four"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="0.9dp"
android:layout_marginRight="0.1dp"
android:layout_marginTop="0.1dp"
android:layout_weight="1"
android:background="@android:color/black"
android:text="4"

</LinearLayout>

<LinearLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">

<Button
android:id="@+id/button_zero"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="0.1dp"
android:layout_marginLeft="0.9dp"
android:layout_marginRight="0.1dp"
android:layout_marginTop="0.1dp"
android:layout_weight="2"
android:background="@android:color/black"
android:text="0"
android:textColor="@android:color/white"

6
android:textSize="30sp" />

<Button
android:id="@+id/button_dot"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="0.1dp"
android:layout_marginRight="0.1dp"
android:layout_marginTop="0.1dp"
android:layout_weight="1"
android:background="@android:color/black"
android:text="."
android:textColor="@android:color/white"
android:textSize="30sp" />

<Button android:id="@+id/button_equal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="0.1dp"
android:layout_marginRight="0.1dp"
android:layout_marginTop="0.1dp"
android:layout_weight="1"
android:background="@android:color/holo_blue_light"
android:text="="
android:textColor="@android:color/white"
android:textSize="40sp" />
</LinearLayout>

7
8
EXPERIMENT 3

Create a tic - tac - toe app


Layout xml 1
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/bg1"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:fontFamily="@font/poppins"
android:textColor="#FFFFFF"
android:textSize="40sp" android:text="Tic
Tac Toe" />

<Button android:id="@+id/button"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="@font/poppins"
android:textColor="#000000"
android:textSize="18sp"
android:background="@drawable/buttonshape"
android:text="Play with computer" />

<Button
android:id="@+id/button2"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_centerInParent="
9
<?xml
version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aditi.platform.tic tac toe">

<application android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar"
></activity>
</application>

</manifest>
Java.1

package com.aditi.platform.tic tac toe;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
10
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main2);
}
}

Java.2
package com.aditi.platform.tic tac toe;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager; import
android.widget.Button;

public class MainActivity extends AppCompatActivity {

Button button,button2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
button2 = findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),Main2Activity.class);
startActivity(intent);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),Main2Activity.class);
startActivity(intent)}}}

11
12
EXPERIMENT 4
Create a login application to verify the username and password .
Xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:focusableInTouchMode="true"
tools:context=".MainActivity">

<FrameLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/good_morning_img" />

</FrameLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gotham"
android:text="Hello "
android:textColor="#ffffff"
android:textSize="32sp"

13
@Override
public boolean onDown(MotionEvent e) {
return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD)
{
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
result = true;
}
}
else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) >
SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottom();
} else {
onSwipe Top();
}
result = true;
}
} catch (Exception exception) { exception.printStackTrace();
}
return result;
}
}

public void onSwipeRight() {


}

public void onSwipeLeft() {


}

public void onSwipeTop() {


}
14
15
EXPERIMENT 5
Create an app which describe all courses of college
Mainacivity.xml

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


<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:layout_marginTop="40dp"
android:orientation="vertical" tools:context=".MainActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="All courses of college"
android:textSize="14pt" android:textStyle="bold"
android:textColor="#000"/>
</RelativeLayout>

<LinearLayout
android:id="@+id/btnsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="25dp"
android:paddingLeft="25dp"
android:paddingTop="40dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_conte

16
myList.setListItemsIcons(listItemsIcons);
myList.setTitle("Unexpandable..");
//myList.setListData(listData);
//myList.setListItemMenu(defaultListMenu);
((LinearLayout)findViewById(R.id.expandabLe Container)).addView(myList);
(findViewById(R.id.backToMainBtn)).setVisibility(View.VISIBLE);
(findViewById(R.id.expandabLe Container)).setVisibility(View.VISIBLE);
(findViewById(R.id.backToMainBtn)).setVisibility(View.VISIBLE);
(findViewById(R.id.expandabLe Container)).setVisibility(View.VISIBLE);
(findViewById(R.id.backToMainBtn)).setAnimation(animation);
(findViewById(R.id.expandabLe Container)).setAnimation(animation);
}

}
});
(findViewById(R.id.customUiBtn1)).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
if(isDialog){
(findViewById(R.id.btnsContainer)).setVisibility(View.VISIBLE); (new
ExpanditDialogList(MainActivity.this,"custom item details
1",listItemsTitles,listData,listItemsIcons,listMenuId,R.layout.custom_item_details_view)).show();
}
if (!isDialog){
(findViewById(R.id.btnsContainer)).setVisibility(View.GONE);
((LinearLayout)findViewById(R.id.expandabLe Container)).addView(new
ExpanditActivityList(MainActivity.this,"custom item details
1",listItemsTitles,listData,listItemsIcons,listMenuId,R.layout.custom_item_details_view));
(findViewById(R.id.backToMainBtn)).setVisibility(View.VISIBLE);
(findViewById(R.id.expandabLe Container)).setVisibility(View.VISIBLE);
(findViewById(R.id.backToMainBtn)).setAnimation(animation);
(findViewById(R.id.expandabLe Container)).setAnimation(animation);
}
}
});
(findViewById(R.id.customUiBtn2)).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
if(isDialog){
(findViewById(R.id.btnsContainer)).setVisibility(View.VISIBLE); (new
ExpanditDialogList(MainActivity.this,"custom item details
2",listItemsTitles2,listData,listItemsIcons2,listMenuId,R.layout.custom_item_details_view2)).show();
}
if (!isDialog){
(findViewById(R.id.btnsContainer)).setVisibility(View.GONE);
((LinearLayout)findViewById(R.id.expandabLe Container)).addView(new
ExpanditActivityList(MainActivity.this,"custom item details
17
18
EXPERIMENT 6
create an app that uses radio button group calculating shopping bill amount

Xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shopping Bill Calculator"
android:textSize="24sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
<EditText
android:id="@+id/etAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Enter
Bill Amount" android:inputType="numberDecimal"
android:padding="10dp" android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<RadioGroup android:id="@+id/rgDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical">
<RadioButton
android:id="@+id/rb10"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="10%
Discount"/>

<RadioButt

19
import
android.widget.TextView; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


private EditText etAmount;
private RadioGroup rgDiscount; private
RadioButton rb10, rb20, rb30; private
Button btnCalculate;
private TextView tvDiscountAmount, tvFinalAmount;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etAmount = findViewById(R.id.etAmount);
rgDiscount = findViewById(R.id.rgDiscount); rb10
= findViewById(R.id.rb10);
rb20 = findViewById(R.id.rb20); rb30
= findViewById(R.id.rb30);
btnCalculate = findViewById(R.id.btnCalculate); tvDiscountAmount =
findViewById(R.id.tvDiscountAmount); tvFinalAmount =
findViewById(R.id.tvFinalAmount);

btnCalculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (etAmount.getText().toString().isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter bill amount", Toast.LENGTH_SHORT).show();
return;
}double amount = Double.parseDouble(etAmount.getText().toString()); double
discount = 0;
if (rb10.isChecked()) {
discount = 0.1;
} else if (rb20.isChecked()) {
discount = 0.2;
} else if (rb30.isChecked()) {
discount = 0.3;
}

double discountAmount = amount * discount;


double finalAmount = amount - discountAmount;

20
}
});
}
}

21
EXPERIMENT 7
create an app that uses table layout with text view
Xml file
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<TablAeRow>
<TextView
android:text="Name"
android:textStyle="bold"
android:textSize="30dp"
android:textColor="@color/material_dynamic_primary70" android:padding="10dp" />

<TextView
android:text="Age"
android:textColor="@color/material_dynamic_primary70" android:textStyle="bold"
android:textSize="30dp"
android:padding="20dp" />

<TextView
android:text="Gender"
android:textColor="@color/material_dynamic_primary70" android:textStyle="bold"
android:textSize="30dp"
android:padding="10dp" />
</TableRow>

<TableRow>
<TextView android:text="John"
android:textColor="@color/purple_200"
android:textSize="30dp"
android:padding="10dp" />

<TextView android:text="25"
android:textColor="@color/design_default_color_error"
android:textSize="30dp"
android:padding="10dp" />

<TextView

22
android:text="Male"
android:textColor="@color/purple_500"
android:textSize="30dp"
android:padding="10dp" />
</TableRow>

<TableRow>
<TextView android:text="Aditi"
android:textColor="@color/purple_200"
android:textSize="30dp"
android:padding="10dp" />

<TextView android:text="30"
android:textColor="@color/design_default_color_error"
android:padding="10dp"
android:textSize="30dp"/>

<TextView
android:text="Female"
android:textSize="30dp"
android:textColor="@color/purple_500"
android:padding="10dp" />
</TableRow>

</TableLayout>

Java file

package com.example.tablelayout;
import android.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}public class MainActivity extends AppCompatActivity {

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

23
24
EXPERIMENT 8
Create a spinner application with string taken from resources directory and on changing the
spinner value with image is saved in the draw table in the directory.

package com.commandiron.spinwheelcompose
import android.os.Bundle
import androidx. activity. ComponentActivity
import androidx.activity.compose.setContent
import android x.compose. animation.core.LinearOut SlowInEasing import android
x.compose.foundation.background
import android x.compose.foundation.layout.*
import android.composite.material.Icon import
android x.compose. material. Text import
android.composite.material.icons. Icons
import android.composite.material.icons.filled. Star import
androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import
android x.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import android x.compose.ui.Alignment
import android x.compose.ui. Modifier import
android x.compose.ui.graphics.Color import
android x.compose.ui.unit.dp
import com.commandiron.spin_wheel_compose. Spinwheel
import com.commandiron.spin_wheel_compose. SpinwheelDefaults
import com.commandiron.spin_wheel_compose.state.rememberSpinwheelState import
com.commandiron.spinwheelcompose.ui.theme. SpinwheelComposeTheme import
kotlin.coroutines.launch
class MainActivity: ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SpinwheelCompose Theme {
Column(
modifier Modifier
.fillMaxSize()
.background (Color(0xFF370083)),
horizontalAlignment
=
verticalArrangement
Alignment.CenterHorizontally,
25
Arrangement.Center
mutablestateof(
>
listOf("Pie 1", "Pie 2", "Pie 3", "Pie 4", "Pie 5", "Pie 6", "Pie 7", "Pie 8") val
state = remember SpinWheelState()
val scope = remember CoroutineScope()
SpinWheel(
state state,
onclick= { scope.launch state. animate (pieIndex -> } } }
){ pieIndex -> Text
(text
=
textList[pieIndex])
}
val iconlist by remember {
mutableStateOf(
listOf(
Icons.Default.Star,
Icons.Default.Star,
Icons.Default.Star,
Icons.Default.Star,
repeat (3) {
SpinWheel(
state = rememberSpinWheelState(
),
pieCount = 4,
durationMillis = 20000,
delayMillis rotationPerSecond
= 200,
= 2f,
= 90F,
easing LinearOut SlowInEasing, start
Degree
result Degree = 212F, autoSpinDelay
=0
dimensions - SpinWheel Defaults chinWheel Dimensional
}
startDegree = 90f, result Degree = 212F,
autoSpinDelay = 0
),
dimensions
SpinwheelDefaults.spinWheelDimensions (

26
spinWheelSize = 180.dp,
frameWidth = 20.dp,
selectorWidth = 10. dp
SpinwheelDefaults.spinWheelColors (
),
colors frameColor
Color (0xFF403d39),
)
dividerColor = Color(0xFFFFFcf2),
selectorColor = Color (0xFFdc0073), listOf(
pieColors =
Color(0xFFdabfff),
Color(0xFF907ad6),
Color(0xFF4F518c),
Color(0xFF2c2a4a)
){ pieIndex ->
Icon(
image vector
=
iconlist [pieIndex], tint
Color. White, content
Description = null
)
}
Spacer (modifier = Modifier.height(32.dp))

}
}
}

27
28
EXPERIMENT 9
Create a menu with five options the selected option should appear in the
text box

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


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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No option selected"
android:textSize="20sp" />

</RelativeLayout>

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


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/option1" android:title="Option
1" />
<item
android:id="@+id/option2" android:title="Option
2" />
<item
android:id="@+id/option3" android:title="Option
3" />
<item
android:id="@+id/option4" android:title="Option
4" />
<item
android:id="@+id/option5" android:title="Option
5" />
</menu>

package com.example.mainactivity;

import android.appcompat.app.AppCompatActivity;

29
import android.os.Bundle; import
android.view.Menu; import
android.view.MenuItem; import
android.widget.TextView;

public class MainActivity extends AppCompatActivity { TextView

textView;

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

textView = findViewById(R.id.textView);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu); return
true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) { int
id = item.getItemId();

switch (id) {
case R.id.option 1:
textView.setText("Option 1 selected"); return
true;
case R.id.option 2:
textView.setText("Option 2 selected"); return
true;
case R.id.option3:
textView.setText("Option 3 selected");
return true;
case R.id.option4:
textView.setText("Option 4 selected");
return true;
case R.id.option5:
textView.setText("Option 5 selected");
return true;
}

return super.onOptionsItemSelected(item);

30
31
EXPERIMENT 10
Create an app to perform the options of firebase or CRUD using
MongoDB

implementation 'com.google.firebase:firebase-auth:19.4.0'
FirebaseAuth mAuth = FirebaseAuth.getInstance();
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();

mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override
public void onComplete(@NonNull Task<AuthResult> task) { if
(task.isSuccessful()) {
// User is successfully logged in
} else {
// Authentication failed
}
}
});
FirebaseAuth mAuth = FirebaseAuth.getInstance();
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();

mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override
public void onComplete(@NonNull Task<AuthResult> task) { if
(task.isSuccessful()) {
// User account created successfully
} else {
// Account creation failed
}
}
});

public class LoginActivity extends AppCompatActivity {

private EditText emailEditText;


private EditText passwordEditText;
private Button loginButton;

32
private FirebaseAuth mAuth;

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

mAuth = FirebaseAuth.getInstance(); emailEditText =

findViewById(R.id.email_edittext);
passwordEditText = findViewById(R.id.password_edittext);
loginButton = findViewById(R.id.login_button);

loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();

mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() { @Override
public void onComplete(@NonNull Task<AuthResult> task) { if
(task.isSuccessful()) {
// User is successfully logged in
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
} else {
// Authentication failed Toast.makeText(LoginActivity.this,
"Authentication failed.",
Toast.LENGTH_SHORT

33
34
35

You might also like