Skip to content

Commit 5ced14d

Browse files
committed
Added haptic feedback
1 parent 8a277cc commit 5ced14d

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.example.teamtrackingapptest2">
44

5+
<uses-permission android:name="android.permission.VIBRATE" />
56
<application
67
android:allowBackup="true"
78
android:icon="@drawable/loginpic"

app/src/main/java/com/example/teamtrackingapptest2/Adapter_name.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.example.teamtrackingapptest2;
22

33
import android.content.Context;
4+
import android.os.Build;
5+
import android.os.VibrationEffect;
6+
import android.os.Vibrator;
47
import android.view.LayoutInflater;
58
import android.view.View;
69
import android.view.ViewGroup;
@@ -17,15 +20,17 @@
1720

1821
public class Adapter_name extends RecyclerView.Adapter<Adapter_name.ViewHolder> implements Filterable {
1922
private Context context;
23+
Vibrator vibrator;
2024
private ArrayList<Student> students;
2125
private ArrayList<Student> studentsfull;
2226
public String studentName;
2327
public TextView textView;
2428
public SearchView searchView;
2529

26-
public Adapter_name(Context context, ArrayList<Student> students, TextView textView, SearchView searchView) {
30+
public Adapter_name(Context context, ArrayList<Student> students, TextView textView, SearchView searchView, Vibrator vibrator) {
2731
this.context = context;
2832
this.students = students;
33+
this.vibrator=vibrator;
2934
this.searchView=searchView;
3035
studentsfull=new ArrayList<>(students);
3136
studentName="";
@@ -53,6 +58,14 @@ public void onClick(View v) {
5358
searchView.setQuery(studentName,false);
5459
searchView.clearFocus();
5560
textView.setText(studentName);
61+
if(Build.VERSION.SDK_INT>=26)
62+
{
63+
vibrator.vibrate(VibrationEffect.createOneShot(50,30));
64+
}
65+
else
66+
{
67+
vibrator.vibrate(50);
68+
}
5669

5770
}
5871
});

app/src/main/java/com/example/teamtrackingapptest2/attendance_main.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.app.DatePickerDialog;
88
import android.content.Intent;
99
import android.os.Bundle;
10+
import android.os.Vibrator;
1011
import android.text.TextUtils;
1112
import android.util.Log;
1213
import android.view.View;
@@ -39,6 +40,7 @@ public class attendance_main extends AppCompatActivity {
3940
private Spinner domain;
4041
private Button add;
4142
private SearchView searchView;
43+
public Vibrator vibrator;
4244

4345
TextView tv1;
4446
RecyclerView rv1;
@@ -62,6 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
6264
edt_from=findViewById(R.id.edt_from);
6365
edt_to=findViewById(R.id.edt_to);
6466
date_picker_from=findViewById(R.id.btn_date_picker_from);
67+
vibrator=(Vibrator) getSystemService(VIBRATOR_SERVICE);
6568
date_picker_to=findViewById(R.id.btn_date_picker_to);
6669
date_picker_from.setOnClickListener(new View.OnClickListener() {
6770
@Override
@@ -118,7 +121,7 @@ public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
118121
Student s=dataSnapshot1.getValue(Student.class);
119122
list.add(s);
120123
}
121-
adapter= new Adapter_name(attendance_main.this,list,tv1,searchView);
124+
adapter= new Adapter_name(attendance_main.this,list,tv1,searchView,vibrator);
122125
rv1.setAdapter(adapter);
123126

124127
}

app/src/main/res/layout/activity_attendance_main.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<TextView
9191
android:layout_width="wrap_content"
9292
android:layout_height="wrap_content"
93+
android:layout_marginLeft="10dp"
9394
android:text="Name : "
9495
android:layout_marginTop="20dp"
9596
android:textSize="24sp"
@@ -103,7 +104,7 @@
103104

104105
<SearchView
105106
android:id="@+id/search_bar"
106-
android:layout_width="250dp"
107+
android:layout_width="270dp"
107108
android:layout_height="30dp"
108109
android:layout_marginTop="20dp"
109110
android:queryHint="Search Here"
@@ -146,6 +147,7 @@
146147
android:layout_width="80dp"
147148
android:layout_height="48dp"
148149
android:layout_weight="2"
150+
android:layout_marginLeft="10dp"
149151
android:text="From : "
150152
android:textSize="24sp"
151153
android:textColor="#ffff"
@@ -194,6 +196,7 @@
194196
android:layout_width="60dp"
195197
android:layout_height="wrap_content"
196198
android:layout_weight="1"
199+
android:layout_marginLeft="10dp"
197200
android:drawableLeft="@drawable/ic_grid_on_black_24dp"
198201
android:text="Pick a Date"
199202
android:textSize="8sp"

app/src/main/res/layout/name_list.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
android:orientation="vertical"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7-
android:id="@+id/linearlayout">
7+
android:id="@+id/linearlayout"
8+
android:hapticFeedbackEnabled="true">
9+
810
<androidx.cardview.widget.CardView
911
android:layout_width="match_parent"
1012
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)