Android UI Components and Functionality
Android UI Components and Functionality
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
[Link]([Link]());
if ([Link]() ==
[Link]()) {
[Link]();
}
}
} catch (Exception e) {
[Link]();
}
}
}).start();
}
});
}
}
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?> package [Link];
<LinearLayout import [Link];
import [Link];
xmlns:android="[Link] import [Link];
res/android" import [Link];
android:layout_width="match_parent" public class MainActivity extends AppCompatActivity {
android:layout_height="match_parent" ListView l;
android:orientation="vertical" String tutorials[]
android:padding="16dp"> ={
"Android","Java","PHP","Hadoop","Sap","Python","Ajax","C+
<ListView +","Roby","Rails" };
android:id="@+id/list" @Override
android:layout_width="match_parent" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="match_parent" /> [Link](savedInstanceState);
</LinearLayout> setContentView([Link].activity_main);
l = findViewById([Link]);
ArrayAdapter<String> arr = new ArrayAdapter<String>(
this,
[Link].simple_list_item_1,
tutorials);
[Link](arr);
}
}
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?> package [Link];
<LinearLayout
xmlns:android="[Link] import [Link];
com/apk/res/android" import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link];
android:orientation="vertical" import [Link];
android:padding="16dp">
public class MainActivity extends AppCompatActivity {
<ImageView
android:id="@+id/imageView" ImageView imageView;
android:layout_width="match_parent" Button buttonChangeImage;
android:layout_height="wrap_content" boolean isImage1 = true;
android:src="@drawable/a">
@Override
</ImageView> protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
<Button setContentView([Link].activity_main);
android:id="@+id/buttonChangeImage"
android:layout_width="wrap_content" imageView = findViewById([Link]);
android:layout_height="wrap_content" buttonChangeImage =
android:text="Change Image" /> findViewById([Link]);
</LinearLayout> [Link](new
[Link]() {
@Override
public void onClick(View v) {
if (isImage1) {
[Link]([Link].a);
} else {
[Link]([Link].b);
}
isImage1 = !isImage1;
}
});
}
}
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?> package [Link];
<RelativeLayout xmlns:android="[Link] import [Link];
[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
.[Link]/tools" import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link];
tools:context=".MainActivity"> import [Link];
public class MainActivity extends AppCompatActivity {
<GridView private static final int NUM_BUTTONS = 15;
android:id="@+id/gridView" @Override
android:layout_width="match_parent" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="match_parent" [Link](savedInstanceState);
android:numColumns="3" setContentView([Link].activity_main);
android:columnWidth="100dp" GridView gridView = findViewById([Link]);
android:verticalSpacing="10dp" [Link](new ButtonAdapter());
android:horizontalSpacing="10dp" }
android:gravity="center"/> private class ButtonAdapter extends BaseAdapter {
@Override
</RelativeLayout> public int getCount() {
return NUM_BUTTONS;
}@Override
public Object getItem(int position) {
return null;
}@Override
public long getItemId(int position) {
return 0; }
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
Button button;
if (convertView == null) {
button = new Button([Link]);
[Link](new
[Link](200, 200));
[Link](8, 8, 8, 8);
} else {
button = (Button) convertView;
}
[Link]("Button " + (position + 1));
[Link](new [Link]() {
@Override
public void onClick(View v) { }
});
return button;
}
}
}
XML FILE:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_marginTop="1000dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your long text goes here..."
android:textSize="18sp" />
</ScrollView>
</RelativeLayout>
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link] package [Link];
[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
.[Link]/tools" import [Link];
android:layout_width="match_parent" public class MainActivity extends AppCompatActivity {
android:layout_height="match_parent" @Override
tools:context=".MainActivity"> protected void onCreate(Bundle savedInstanceState) {
<TimePicker [Link](savedInstanceState);
android:id="@+id/timePicker24" setContentView([Link].activity_main);
android:layout_width="wrap_content" TimePicker timePicker24 =
android:layout_height="wrap_content" findViewById([Link].timePicker24);
android:timePickerMode="spinner"/> timePicker24.setIs24HourView(true);
<TimePicker }
android:id="@+id/t" }
android:layout_width="wrap_content"
android:layout_marginTop="200dp"
android:layout_height="wrap_content"
android:timePickerMode="spinner"/>
<TimePicker
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_marginTop="400dp"
android:layout_height="wrap_content"
android:timePickerMode="clock"/>
</RelativeLayout>
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?> package [Link];
<RelativeLayout xmlns:android="[Link] import [Link];
.[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
.[Link]/tools" import [Link];
android:layout_width="match_parent" import [Link].*;
android:layout_height="match_parent" import [Link];
tools:context=".MainActivity"> import [Link];
<Button import [Link];
android:id="@+id/selectDateButton" public class MainActivity extends AppCompatActivity {
android:layout_width="wrap_content" private TextView selectedDateTextView;
android:layout_height="wrap_content" private TextView selectedTimeTextView;
android:text="Select Date" @Override
android:layout_centerInParent="true" protected void onCreate(Bundle savedInstanceState) {
android:onClick="showDatePicker"/> [Link](savedInstanceState);
<Button setContentView([Link].activity_main);
android:id="@+id/selectTimeButton" selectedDateTextView =
android:layout_width="wrap_content" findViewById([Link]);
android:layout_height="wrap_content" selectedTimeTextView =
android:text="Select Time" findViewById([Link]); }
android:layout_below="@+id/select public void showDatePicker(View view) {
DateButton" final Calendar calendar = [Link]();
android:layout_centerHorizontal="true" int currentYear = [Link]([Link]);
android:layout_marginTop="16dp" int currentMonth = [Link]([Link]);
android:onClick="showTimePicker"/> int currentDay = [Link](Calendar.DAY_OF_MONTH);
<TextView DatePickerDialog datePickerDialog = new
android:id="@+id/selectedDateTextView" DatePickerDialog(this,
android:layout_width="wrap_content" new [Link]() {
android:layout_height="wrap_content" @Override
android:text="" public void onDateSet(DatePicker view, int year, int
android:layout_below="@+id/select month, int dayOfMonth) {
TimeButton" [Link]([Link], year);
android:layout_centerHorizontal="true" [Link]([Link], month);
android:layout_marginTop="16dp"/> [Link](Calendar.DAY_OF_MONTH,
<TextView dayOfMonth);
android:id="@+id/selectedTimeTextView" updateSelectedDateTextView(calendar);} },
android:layout_width="wrap_content" currentYear,
android:layout_height="wrap_content" currentMonth,
android:text="" currentDay );
android:layout_below="@+id/selected [Link](); }
DateTextView" public void showTimePicker(View view) {
android:layout_centerHorizontal="true" final Calendar calendar = [Link]();
android:layout_marginTop="16dp"/> int currentHour = [Link](Calendar.HOUR_OF_DAY);
</RelativeLayout> int currentMinute = [Link]([Link]);
TimePickerDialog timePickerDialog = new
TimePickerDialog(
this,
new [Link]() {
@Override
public void onTimeSet(TimePicker view, int
hourOfDay, int minute) {
[Link](Calendar.HOUR_OF_DAY,
hourOfDay);
[Link]([Link], minute);
updateSelectedTimeTextView(calendar);
}
},
currentHour,
currentMinute,
true
);
[Link]();
}
private void updateSelectedDateTextView(Calendar
calendar) {
DateFormat dateFormat = [Link]();
String selectedDate =
[Link]([Link]());
[Link](selectedDate);
}
private void updateSelectedTimeTextView(Calendar
calendar) {
DateFormat timeFormat = [Link]();
String selectedTime =
[Link]([Link]());
[Link](selectedTime);
}
}
JAVA FILE:-
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
Log.d(TAG, "onCreate: Activity created");
}
@Override
protected void onStart() {
[Link]();
Log.d(TAG, "onStart: Activity started");
}
@Override
protected void onResume() {
[Link]();
Log.d(TAG, "onResume: Activity resumed");
}
@Override
protected void onPause() {
[Link]();
Log.d(TAG, "onPause: Activity paused");
}
@Override
protected void onStop() {
[Link]();
Log.d(TAG, "onStop: Activity stopped");
}
@Override
protected void onDestroy() {
[Link]();
Log.d(TAG, "onDestroy: Activity destroyed");
}
}
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?> package [Link];
<LinearLayout xmlns:android="[Link] import [Link];
[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
[Link]/tools" import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link].*;
android:orientation="vertical" public class MainActivity extends AppCompatActivity {
tools:context=".MainActivity"> @Override
<EditText protected void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" [Link](savedInstanceState);
android:layout_height="wrap_content" setContentView([Link].activity_main);
android:id="@+id/e1"/> Button b1=findViewById([Link].b);
<Button EditText e1=findViewById([Link].e1);
android:layout_width="wrap_content" [Link](new [Link]() {
android:layout_height="wrap_content" @Override
android:text="Navigate" public void onClick(View v) {
android:id="@+id/b" String s=[Link]().toString();
/> Intent i=new Intent(Intent.ACTION_VIEW, [Link](s));
</LinearLayout> startActivity(i);
}
});
}
}
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?> package [Link];
<LinearLayout xmlns:android="[Link] import [Link];
[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
.[Link]/tools" import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link].*;
android:orientation="vertical" public class MainActivity extends AppCompatActivity {
tools:context=".MainActivity"> @Override
<Button protected void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" [Link](savedInstanceState);
android:layout_height="wrap_content" setContentView([Link].activity_main);
android:text="Go to" Button b1=findViewById([Link].b);
android:id="@+id/b" [Link](new [Link]() {
/> @Override
</LinearLayout> public void onClick(View v) {
Intent i=new Intent(Intent.ACTION_DIAL,
[Link]("tel: +919325025671"));
startActivity(i);
}
});
}
}
XML FILE: - JAVA FILE: -
Activity_main.xml package [Link];
<?xml version="1.0" encoding="utf-8"?> import [Link];
<LinearLayout xmlns:android="[Link] import [Link];
.[Link]/apk/res/android" import [Link];
xmlns:app="[Link] import [Link];
[Link]/apk/res-auto" import [Link].*;
xmlns:tools="[Link] public class MainActivity extends AppCompatActivity {
android:layout_width="match_parent" @Override
android:layout_height="match_parent" protected void onCreate(Bundle savedInstanceState) {
android:orientation="vertical" [Link](savedInstanceState);
tools:context=".MainActivity"> setContentView([Link].activity_main);
<EditText Button b=findViewById([Link]);
android:layout_width="wrap_content" final EditText et=findViewById([Link].e);
android:layout_height="wrap_content" [Link](new [Link]()
android:id="@+id/e"/> {@Override
<Button public void onClick(View v) {
android:layout_width="wrap_content" int n= [Link]([Link]().toString());
android:layout_height="wrap_content" int fact=1;
android:text="Calculate" for (int i = 1; i <= n; ++i) {
android:id="@+id/btn"/> fact=fact*i;
</LinearLayout> }
Intent i=new
[Link] Intent([Link],[Link]);
<LinearLayout xmlns:android="[Link] [Link]("factorial", [Link](fact));
[Link]/apk/res/android" startActivity(i); }
android:layout_width="match_parent" });
xmlns:tools="[Link] }
tools:context=".result" }
android:layout_height="match_parent">
<TextView [Link]
android:layout_width="wrap_content" package [Link];
android:layout_height="wrap_content" import [Link];
android:id="@+id/t1"/> import [Link];
</LinearLayout> import [Link].*;
public class result extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link]);
TextView t = findViewById([Link].t1);
String s = getIntent().getStringExtra("factorial");
[Link](s);
}
}
Activity_Main.xml [Link]
<?xml version="1.0" encoding="utf-8"?> package [Link];// [Link]
<RelativeLayout import [Link];
xmlns:android="[Link] import [Link];
[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
[Link]/tools" import [Link];
android:layout_width="match_parent"
android:layout_height="match_parent" import [Link];
tools:context=".MainActivity">
public class MainActivity extends AppCompatActivity {
<EditText
android:id="@+id/editTextName" @Override
android:layout_width="wrap_content" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="wrap_content" [Link](savedInstanceState);
android:hint="Enter your name" setContentView([Link].activity_main);
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" /> final EditText nameInput =
findViewById([Link]);
<Button Button submitButton =
android:id="@+id/buttonSubmit" findViewById([Link]);
android:layout_width="wrap_content"
android:layout_height="wrap_content" [Link](new
android:text="Submit" [Link]() {
@Override
android:layout_below="@id/editTextName" public void onClick(View v) {
android:layout_centerHorizontal="true" String name = [Link]().toString();
android:layout_marginTop="16dp" /> Intent intent = new Intent([Link],
[Link]);
</RelativeLayout> [Link]("NAME", name);
startActivity(intent);
}
});
}
}
Activity_display.xml [Link]
<?xml version="1.0" encoding="utf-8"?> package [Link];// [Link]
<RelativeLayout import [Link];
xmlns:android="[Link] import [Link];
[Link]/apk/res/android"
xmlns:tools="[Link] import [Link];
[Link]/tools"
android:layout_width="match_parent" public class DisplayActivity extends AppCompatActivity {
android:layout_height="match_parent"
tools:context=".DisplayActivity"> @Override
protected void onCreate(Bundle savedInstanceState) {
<TextView [Link](savedInstanceState);
android:id="@+id/textViewName" setContentView([Link].activity_display);
android:layout_width="wrap_content"
android:layout_height="wrap_content" TextView nameTextView =
android:textSize="24sp" findViewById([Link]);
android:layout_centerInParent="true"/>
// Retrieve the name from the intent
</RelativeLayout> String name = getIntent().getStringExtra("NAME");
[Link](getApplicationContext(),"Service
Started",Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
[Link]();
[Link](getApplicationContext(),"Service
Stopped",Toast.LENGTH_LONG).show();
}
}
JAVA FILE: - [Link]
package [Link]; package [Link];
import [Link]; import [Link];
import [Link]; import [Link];
import [Link]; import [Link];
import [Link]; import [Link];
import [Link];
import public class MyReceiver extends
[Link]; BroadcastReceiver {
public class MainActivity extends
AppCompatActivity { @Override
MyReceiver m=new MyReceiver(); public void onReceive(Context context, Intent
@Override protected void onCreate(Bundle intent) {
savedInstanceState) { [Link](context,"Time
[Link](savedInstanceState); Changed",Toast.LENGTH_LONG).show();
setContentView([Link].activity_main); }
IntentFilter i=new }
IntentFilter(Intent.ACTION_TIME_CHANGED);
registerReceiver(m,i);
}}
XML FILE: - JAVA FILE: -
<LinearLayout package [Link];
xmlns:android="[Link] import [Link];
[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
[Link]/tools" import [Link];
android:layout_width="match_parent" import [Link];
android:orientation="vertical" import [Link];
android:layout_height="match_parent" public class MainActivity extends AppCompatActivity {
tools:context=".MainActivity"> private TextView textViewSensors;
<TextView @Override
android:layout_width="wrap_content" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="wrap_content" [Link](savedInstanceState);
android:id="@+id/l"/> setContentView([Link].activity_main);
</LinearLayout> textViewSensors = findViewById([Link].l);
SensorManager sensorManager = (SensorManager)
getSystemService(SENSOR_SERVICE);
List<Sensor> sensorList =
[Link](Sensor.TYPE_ALL);
StringBuilder sensorNamesBuilder = new StringBuilder();
for (Sensor sensor : sensorList) {
[Link]([Link]()).append("\n");
}
[Link]([Link]());
}
}
XML FILE: - JAVA FILE: -
<?xml version="1.0" encoding="utf-8"?> package [Link];// [Link]
<RelativeLayout import [Link];
xmlns:android="[Link] import [Link];
[Link]/apk/res/android" import [Link];
xmlns:tools="[Link] import [Link];
[Link]/tools" public class MainActivity extends AppCompatActivity {
android:layout_width="match_parent" @Override
android:layout_height="match_parent" protected void onCreate(Bundle savedInstanceState) {
android:padding="16dp" [Link](savedInstanceState);
tools:context=".MainActivity"> setContentView([Link].activity_main);
Button button = findViewById([Link]);
<Button [Link](new [Link]() {
android:id="@+id/button" @Override
android:layout_width="wrap_content" public void onClick(View v) {
android:layout_height="wrap_content" // Call the method to show custom toast
android:text="Show Custom Toast" showCustomToast();
android:layout_centerInParent="true"/> }
});
</RelativeLayout> }
private void showCustomToast() {
Custom_Toast_layout.xml [Link](getApplicationContext(), "Custom
<?xml version="1.0" encoding="utf-8"?> toast message");
<LinearLayout }
xmlns:android="[Link] }
[Link]/apk/res/android" [Link]
android:id="@+id/customToastLayout" package [Link];// [Link]
android:layout_width="wrap_content" import [Link];
android:layout_height="wrap_content" import [Link];
android:background="@drawable import [Link];
/ic_launcher_background" import [Link];
android:orientation="horizontal" import [Link];
android:padding="16dp"> import [Link];
public class CustomToast {
<ImageView public static void showToast(Context context, String message) {
android:id="@+id/imageView" LayoutInflater inflater = (LayoutInflater)
android:layout_width="wrap_content" [Link](Context.LAYOUT_INFLATER_SERVICE);
android:layout_height="wrap_content" View layout = [Link]([Link].custom_toast_layout,
android:src="@drawable null); ImageView imageView =
/ic_launcher_foreground" /> [Link]([Link]);
TextView textView = [Link]([Link]);
<TextView [Link]([Link].ic_launcher_foreground);
android:id="@+id/textView" [Link](message);
android:layout_width="wrap_content" Toast toast = new Toast(context);
android:layout_height="wrap_content" [Link](Toast.LENGTH_LONG);
android:textColor="#FFFFFF" [Link](layout);
android:text="Custom Toast" /> [Link]();
}
</LinearLayout> }
XML FILE: - Custom_Toast_Layout.xml
<RelativeLayout xmlns:android="[Link] <?xml version="1.0" encoding="utf-8"?>
[Link]/apk/res/android" <LinearLayout xmlns:android="[Link]
xmlns:tools="[Link] [Link]/apk/res/android"
[Link]/tools" android:id="@+id/customToastLayout"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:padding="16dp" android:background="#ADA0A0"
tools:context=".MainActivity"> android:orientation="horizontal"
<CheckBox android:padding="16dp">
android:id="@+id/checkBox1" <TextView
android:layout_width="wrap_content" android:id="@+id/textView"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Pizza" android:layout_height="wrap_content"
android:layout_marginTop="20dp"/> android:textColor="#FF0000"
<CheckBox android:text="Custom Toast" />
android:id="@+id/checkBox2"
android:layout_width="wrap_content" </LinearLayout>
android:layout_height="wrap_content"
android:text="Burger"
android:layout_below="@id/checkBox1"
android:layout_marginTop="20dp"/>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffe"
android:layout_below="@id/checkBox2"
android:layout_marginTop="20dp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order"
android:layout_below="@id/checkBox3"
android:layout_marginTop="20dp"/>
</RelativeLayout>
[Link] [Link]
package [Link]; package [Link];
import import [Link];
[Link]; import [Link];
import [Link]; import [Link];
import [Link]; import [Link];
import [Link]; import [Link];
import [Link]; public class CustomToast {
public class MainActivity extends public static void showToast(Context context, String message)
AppCompatActivity { {
LayoutInflater inflater = (LayoutInflater)
CheckBox checkBox1, checkBox2, checkBox3; [Link](Context.LAYOUT_INFLATER_SERVICE);
View layout = [Link]([Link].custom_toast_layout,
@Override null);
protected void onCreate(Bundle TextView textView = [Link]([Link]);
savedInstanceState) { [Link](message);
[Link](savedInstanceState); Toast toast = new Toast(context);
setContentView([Link].activity_main); [Link](Toast.LENGTH_LONG);
[Link](layout);
checkBox1 = findViewById([Link].checkBox1); [Link]();
checkBox2 = findViewById([Link].checkBox2); }
checkBox3 = findViewById([Link].checkBox3); }
[Link](getApplicationContext(),
[Link]());
}
}
[Link] [Link](new
package [Link]; [Link]() {
@SuppressLint("MissingPermission")
import [Link]; @Override
import [Link]; public void onClick(View v) {
import [Link]; if ([Link]()) {
import [Link]; [Link]();
import [Link]; [Link]([Link], "Bluetooth turned
import [Link]; off", To
import [Link]; ast.LENGTH_SHORT).show();
} else {
import [Link]; [Link]([Link], "Bluetooth
is
public class MainActivity extends AppCompatActivity { already off", Toast.LENGTH_SHORT).show();
}
private BluetoothAdapter bluetoothAdapter; }
});
@Override
protected void onCreate(Bundle savedInstanceState) [Link](new
{ [Link]() {
[Link](savedInstanceState); @SuppressLint("MissingPermission")
setContentView([Link].activity_main); @Override
public void onClick(View v) {
bluetoothAdapter = Intent discoverableIntent = new
[Link](); Intent(Bluetoot
hAdapter.ACTION_REQUEST_DISCOVERABLE);
Button turnOnBtn = findViewById([Link]); [Link](Bluetooth
Button turnOffBtn = findViewById([Link]); Adapter.EXTRA_DISCOVERABLE_DURATION, 300
Button discoverableBtn = startActivity(discoverableIntent);
findViewById([Link]); }
Button showPairedDevicesBtn = });
findViewById([Link]);
[Link](new
[Link](new View.
[Link]() { OnClickListener() {
@SuppressLint("MissingPermission") @Override
@Override public void onClick(View v) {
public void onClick(View v) {
if (![Link]()) { [Link](getApplicationContext(),"Device N
Intent enableBtIntent = new ot found",Toast.LENGTH_LONG).show();
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); }
startActivity(enableBtIntent); });
} else { }
[Link]([Link], "Bluetooth }
is already on", Toast.LENGTH_SHORT).show();
}
}
});
[Link](new
[Link]() {
Activity_main.xml
<LinearLayout xmlns:android="[Link]
[Link]/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<Button
android:id="@+id/turnOnBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn On Bluetooth" />
<Button
android:id="@+id/turnOffBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn Off Bluetooth" />
<Button
android:id="@+id/discoverableBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Make Discoverable" />
<Button
android:id="@+id/showPairedDevicesBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Paired Devices" />
</LinearLayout>
Activity_main.xml Fade_anim.xml
<RelativeLayout xmlns:android="[Link] <?xml version="1.0" encoding="utf-8"?>
[Link]/apk/res/android" <alpha
xmlns:tools="[Link] xmlns:android="[Link]
[Link]/tools" android:duration="1000"
android:layout_width="match_parent" android:fromAlpha="0.0"
android:layout_height="match_parent" android:toAlpha="1.0" />
tools:context=".MainActivity">
<ImageView Slide_anim.xml
android:id="@+id/imageView" <?xml version="1.0" encoding="utf-8"?>
android:layout_width="200dp" <translate
android:layout_height="200dp" xmlns:android="[Link]
android:duration="1000"
android:src="@drawable/ic_launcher_background" android:fromXDelta="-100%"
android:layout_centerHorizontal="true" android:toXDelta="0%"
android:layout_marginTop="50dp"/> android:fromYDelta="0%"
<Button android:toYDelta="0%" />
android:id="@+id/buttonFade"
android:layout_width="wrap_content" Zoom_anim.xml
android:layout_height="wrap_content" <?xml version="1.0" encoding="utf-8"?>
android:text="Fade" <scale
android:layout_below="@id/imageView" xmlns:android="[Link]
android:layout_alignParentStart="true" android:duration="1000"
android:layout_margin="16dp"/> android:fromXScale="0.0"
<Button android:fromYScale="0.0"
android:id="@+id/buttonZoom" android:pivotX="50%"
android:layout_width="wrap_content" android:pivotY="50%"
android:layout_height="wrap_content" android:toXScale="1.0"
android:text="Zoom" android:toYScale="1.0" />
android:layout_below="@id/imageView"
android:layout_alignParentEnd="true" rotate_anim.xml
android:layout_margin="16dp"/> <?xml version="1.0" encoding="utf-8"?>
<Button <rotate
android:id="@+id/buttonRotate" xmlns:android="[Link]
android:layout_width="wrap_content" android:duration="1000"
android:layout_height="wrap_content" android:fromDegrees="0"
android:text="Rotate" android:toDegrees="360"
android:layout_below="@id/buttonFade" android:pivotX="50%"
android:layout_alignParentStart="true" android:pivotY="50%" />
android:layout_margin="16dp"/>
<Button
android:id="@+id/buttonSlide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Slide"
android:layout_below="@id/buttonZoom"
android:layout_alignParentEnd="true"
android:layout_margin="16dp"/>
</RelativeLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private Button buttonFade, buttonZoom, buttonRotate, buttonSlide;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
imageView = findViewById([Link]);
buttonFade = findViewById([Link]);
buttonZoom = findViewById([Link]);
buttonRotate = findViewById([Link]);
buttonSlide = findViewById([Link]);
[Link](new [Link]() {@Override
public void onClick(View v) {
Animation fadeAnimation = [Link](getApplicationContext(),
[Link].fade_animation);
[Link](fadeAnimation);}
});
[Link](new [Link]() { @Override
public void onClick(View v) {
Animation zoomAnimation = [Link](getApplicationContext(),
[Link].zoom_animation);
[Link](zoomAnimation);
}
});
[Link](new [Link]() {@Override
public void onClick(View v) {
Animation rotateAnimation = [Link](getApplicationContext(),
[Link].rotate_animation);
[Link](rotateAnimation);
}
});
[Link](new [Link]() { @Override
public void onClick(View v) {
Animation slideAnimation = [Link](getApplicationContext(),
[Link].slide_animation);
[Link](slideAnimation);
}
});
}