Skip to content

Commit fd29f6a

Browse files
committed
Added code for notification Logic
1 parent 60a8414 commit fd29f6a

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

.idea/misc.xml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/example/m3/Fhome.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
import java.util.Date;
2828
import java.util.Objects;
2929

30-
public class Fhome extends Fragment {
31-
32-
//private FirebaseAuth fAuth;
30+
public class Fhome extends Fragment
31+
{
3332
private MediaPlayer mediaPlayer;
3433
AutoTypeTextView AutoTypeLabel;
3534
public String UID,FName,Dob;
@@ -67,8 +66,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6766
/**
6867
* Starts playing Audio/music from the given link
6968
*/
70-
private void playAudio() {
71-
String audioUrl = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3";
69+
private void playAudio()
70+
{
71+
String audioUrl = "https://github.com/iatharva/iatharva.github.io/raw/master/images/03.%20Morph.mp3";
7272
mediaPlayer = new MediaPlayer();
7373
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
7474
try {
@@ -83,7 +83,8 @@ private void playAudio() {
8383
/**
8484
* Method stops the audio/music if it is playing
8585
*/
86-
private void stopAudio() {
86+
private void stopAudio()
87+
{
8788
if (mediaPlayer != null) {
8889
mediaPlayer.stop();
8990
mediaPlayer.reset();
@@ -124,7 +125,8 @@ public void getUserData()
124125
/**
125126
* Shows the message respective to the time
126127
*/
127-
public void typeWriterMessages(String FName,String Dob) {
128+
public void typeWriterMessages(String FName,String Dob)
129+
{
128130
AutoTypeLabel = view.findViewById(R.id.AutoTypeLabel);
129131
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
130132
String currentDateandTime = sdf.format(new Date());
@@ -141,7 +143,8 @@ public void typeWriterMessages(String FName,String Dob) {
141143
{
142144
AutoTypeLabel.setTextAutoTyping("Today is your birthday, Happy birthday, "+FName+"!"+"\n"+"Hope you make this day one of the best."+"\n"+"🥳 ");
143145
}
144-
else {
146+
else
147+
{
145148
//If time is before 12pm and after 6 am then show message "Good Morning, let's start the day"
146149
if (currentDateandTime.compareTo("06:00:00") > 0 && currentDateandTime.compareTo("12:00:00") < 0) {
147150
AutoTypeLabel.setTextAutoTyping("Good Morning " + FName + ","+"\n"+"Let's start the day" + "\n" + "🌞");
@@ -152,7 +155,7 @@ else if (currentDateandTime.compareTo("12:00:00") > 0 && currentDateandTime.comp
152155
}
153156
//If time is after 6 pm and before 12 am then show message "Hope your day was as you planned :)"
154157
else if (currentDateandTime.compareTo("18:00:00") > 0 && currentDateandTime.compareTo("24:00:00") < 0) {
155-
AutoTypeLabel.setTextAutoTyping("Hope your day was as you "+"\n"+"planned :)" + "\n" + "🌃 ");
158+
AutoTypeLabel.setTextAutoTyping("Hope your day was as you "+"\n"+"planned 🌃 :)");
156159
}
157160
}
158161
}

app/src/main/java/com/example/m3/Settings.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.example.m3;
22

3+
import static com.example.m3.extras.App.CHANNEL_2_ID;
4+
5+
import android.app.Notification;
36
import android.content.Intent;
47
import android.net.Uri;
58
import android.os.Bundle;
@@ -8,11 +11,17 @@
811
import android.view.ViewGroup;
912
import android.widget.Button;
1013
import android.widget.TextView;
14+
import android.widget.Toast;
1115

16+
import androidx.core.app.NotificationCompat;
17+
import androidx.core.app.NotificationManagerCompat;
1218
import androidx.fragment.app.Fragment;
1319

20+
import java.util.Objects;
21+
1422
public class Settings extends Fragment {
1523
public TextView tncBtn,alarmBtn,sysBtn,aboutBtn;
24+
public NotificationManagerCompat notificationManager;
1625
View view;
1726
@Override
1827
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -23,12 +32,23 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
2332
sysBtn = view.findViewById(R.id.sysBtn);
2433
tncBtn = view.findViewById(R.id.tncBtn);
2534
aboutBtn = view.findViewById(R.id.aboutBtn);
26-
35+
notificationManager = NotificationManagerCompat.from(requireActivity());
2736
alarmBtn.setOnClickListener(view -> {
2837

2938
});
39+
3040
sysBtn.setOnClickListener(view -> {
3141

42+
Notification notification = new NotificationCompat.Builder(getActivity(), CHANNEL_2_ID)
43+
.setSmallIcon(R.drawable.m3logoonly)
44+
.setContentTitle("Sample notification")
45+
.setContentText("Your notification will look like this")
46+
.setPriority(NotificationCompat.PRIORITY_HIGH)
47+
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
48+
.build();
49+
notificationManager.notify(2, notification);
50+
Toast.makeText(getActivity(),"Notification should be visible",Toast.LENGTH_SHORT).show();
51+
3252
});
3353

3454
tncBtn.setOnClickListener(view -> {
@@ -38,9 +58,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
3858
i.setData(Uri.parse(url));
3959
startActivity(i);
4060
});
61+
4162
aboutBtn.setOnClickListener(view -> {
4263

4364
});
65+
4466
return view;
4567
}
4668
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.example.m3.extras;
2+
3+
import android.app.Application;
4+
import android.app.NotificationChannel;
5+
import android.app.NotificationManager;
6+
import android.os.Build;
7+
8+
public class App extends Application {
9+
public static final String CHANNEL_1_ID = "channel1";
10+
public static final String CHANNEL_2_ID = "channel2";
11+
@Override
12+
public void onCreate() {
13+
super.onCreate();
14+
createNotificationChannels();
15+
}
16+
private void createNotificationChannels() {
17+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
18+
NotificationChannel channel1 = new NotificationChannel(
19+
CHANNEL_1_ID,
20+
"Channel 1",
21+
NotificationManager.IMPORTANCE_HIGH
22+
);
23+
channel1.setDescription("This is Channel 1");
24+
25+
NotificationChannel channel2 = new NotificationChannel(
26+
CHANNEL_2_ID,
27+
"Channel 2",
28+
NotificationManager.IMPORTANCE_LOW
29+
);
30+
channel2.setDescription("This is Channel 2");
31+
32+
NotificationManager manager = getSystemService(NotificationManager.class);
33+
manager.createNotificationChannel(channel1);
34+
manager.createNotificationChannel(channel2);
35+
}
36+
}
37+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@
1515
android:text="@string/settings"
1616
android:textColor="@color/black"
1717
android:textSize="30sp"
18-
1918
android:textStyle="bold" />
2019

20+
<TextView
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:layout_marginStart="165dp"
24+
android:layout_marginTop="60dp"
25+
android:text="(v1.10)"
26+
android:textSize="20sp" />
27+
2128
<TextView
2229
android:id="@+id/alarmBtn"
2330
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)