mad code essy
mad code essy
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="@+id/num1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter first number"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/num2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter second number"
android:inputType="numberDecimal" />
<Button
android:id="@+id/addBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
<Button
android:id="@+id/subBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtract" />
<Button
android:id="@+id/mulBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Multiply" />
<Button
android:id="@+id/divBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Divide" />
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Result: "
android:textSize="20sp"
android:paddingTop="20dp" />
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Linking with UI
num1 = findViewById(R.id.num1);
num2 = findViewById(R.id.num2);
addBtn = findViewById(R.id.addBtn);
subBtn = findViewById(R.id.subBtn);
mulBtn = findViewById(R.id.mulBtn);
divBtn = findViewById(R.id.divBtn);
result = findViewById(R.id.result);
// Add Button
addBtn.setOnClickListener(v -> calculate("+"));
// Subtract Button
subBtn.setOnClickListener(v -> calculate("-"));
// Multiply Button
mulBtn.setOnClickListener(v -> calculate("*"));
// Divide Button
divBtn.setOnClickListener(v -> calculate("/"));
}
switch (operator) {
case "+": res = number1 + number2; break;
case "-": res = number1 - number2; break;
case "*": res = number1 * number2; break;
case "/":
if (number2 == 0) {
Toast.makeText(this, "Cannot divide by zero", Toast.LENGTH_SHORT).show();
return;
}
res = number1 / number2;
break;
}
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:label="@string/app_name">
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng myPlace = new LatLng(28.6139, 77.2090); // Example: New Delhi
mMap.addMarker(new MarkerOptions().position(myPlace).title("Marker in Delhi"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPlace, 10));
}
}
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
3. Explain property animation method to animate the properties of view object with
example.
A property animation changes a property's (a field in an object) value over a specified length
of time. To animate something, you specify the object property that you want to animate,
such as an object's position on the screen, how long you want to animate it for, and what
values you want to animate between.
The property animation system lets you define the following characteristics of an animation:
Duration: You can specify the duration of an animation. The default length is 300 ms.
Time interpolation: You can specify how the values for the property are calculated as a function of the animation's
current elapsed time.
Repeat count and behavior: You can specify whether or not to have an animation repeat
when it reaches the end of a duration and how many times to repeat the animation. You can
also specify whether you want the animation to play back in reverse. Setting it to reverse
plays the animation forwards then backwards repeatedly, until the number of repeats is
reached.
Animator sets: You can group animations into logical sets that play together or sequentially
or after specified delays.
Frame refresh delay: You can specify how often to refresh frames of your animation. The
default is set to refresh every 10 ms, but the speed in which your application can refresh
frames is ultimately dependent on how busy the system is overall and how fast the system
can service the underlying timer.
import android.animation.ObjectAnimator;
fadeOut.setDuration(1000); // 1 second
fadeOut.start();
<ListView
android:id="@+id/bluetoothListView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Now, in MainActivity.java, write the code to list the paired Bluetooth devices
// 1. Required Imports
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Set;
ListView listView;
BluetoothAdapter bluetoothAdapter;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find ListView by ID
listView = findViewById(R.id.bluetoothListView);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
int i = 0;
names[i++] = device.getName();
listView.setAdapter(adapter);
1) TextView
Attributes:
Attributes:
Attributes:
Attributes:
Attributes:
android:textOn: The text shown when the button is in the "on" state.
android:textOff: The text shown when the button is in the "off" state.
android:checked: Specifies whether the button is initially in the "on" state.
android:background: Sets the background of the toggle button.
A RadioGroup is used to group RadioButton widgets together, where only one can be selected at a time.
Attributes:
Attributes:
Attributes:
Example:
xml
CopyEdit
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Example:
xml
CopyEdit
<GridView
android:id="@+id/myGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3" />
Example:
xml
CopyEdit
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Add more content here -->
</LinearLayout>
</ScrollView>
Example:
java
CopyEdit
Toast toast = new Toast(getApplicationContext());
View view = getLayoutInflater().inflate(R.layout.custom_toast, null);
toast.setView(view);
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();