Skip to content

Commit 62983f1

Browse files
Merge pull request #4 from UdacityAndroidBasicsScholarship/master
RepoUpdate
2 parents 2b30206 + c5e564b commit 62983f1

File tree

12 files changed

+239
-14
lines changed

12 files changed

+239
-14
lines changed

app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ dependencies {
2929
implementation 'com.android.support:cardview-v7:27.1.1'
3030
implementation 'com.android.support:design:27.1.1'
3131
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
32+
implementation 'com.android.support:preference-v7:27.1.1'
33+
compile 'com.google.firebase:firebase-database:11.0.4'
34+
compile 'com.google.firebase:firebase-storage:11.0.4'
3235

3336
implementation 'com.stephentuso:welcome:1.4.1'
3437

3538
implementation 'com.android.support:recyclerview-v7:27.1.1'
3639

3740
}
41+
42+
apply plugin: 'com.google.gms.google-services'

app/google-services.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"project_info": {
3+
"project_number": "891850808493",
4+
"firebase_url": "https://daily-goals-a9c53.firebaseio.com",
5+
"project_id": "daily-goals-a9c53",
6+
"storage_bucket": "daily-goals-a9c53.appspot.com"
7+
},
8+
"client": [
9+
{
10+
"client_info": {
11+
"mobilesdk_app_id": "1:891850808493:android:def136320218cb3a",
12+
"android_client_info": {
13+
"package_name": "com.example.dhananjay.dailygoals"
14+
}
15+
},
16+
"oauth_client": [
17+
{
18+
"client_id": "891850808493-9ddh59ootunrok7pfi5kplm48h4jshv5.apps.googleusercontent.com",
19+
"client_type": 1,
20+
"android_info": {
21+
"package_name": "com.example.dhananjay.dailygoals",
22+
"certificate_hash": "dc402beccbec5c64ee1f65fbbb06ddf429efe45a"
23+
}
24+
},
25+
{
26+
"client_id": "891850808493-atp6khfqm1jv21o4a1cqnm8n2jf5f9ag.apps.googleusercontent.com",
27+
"client_type": 3
28+
}
29+
],
30+
"api_key": [
31+
{
32+
"current_key": "AIzaSyAF-ifz80FZWLZJaFYn4uky1Vx1kRNdPG8"
33+
}
34+
],
35+
"services": {
36+
"analytics_service": {
37+
"status": 1
38+
},
39+
"appinvite_service": {
40+
"status": 2,
41+
"other_platform_oauth_client": [
42+
{
43+
"client_id": "891850808493-atp6khfqm1jv21o4a1cqnm8n2jf5f9ag.apps.googleusercontent.com",
44+
"client_type": 3
45+
}
46+
]
47+
},
48+
"ads_service": {
49+
"status": 2
50+
}
51+
}
52+
}
53+
],
54+
"configuration_version": "1"
55+
}

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
android:theme="@style/WelcomeScreenTheme"
2121
android:screenOrientation="portrait"/>
2222
<activity android:name=".TodayActivity"></activity>
23+
<activity android:name=".PopupActivity"
24+
android:theme="@style/AppTheme.CustomTheme"></activity>
25+
<receiver android:name=".NotificationActivity"></receiver>
2326
</application>
24-
27+
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"></uses-permission>
2528
</manifest>

app/src/main/java/com/example/dhananjay/dailygoals/MainActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.os.Bundle;
55
import android.support.v7.widget.LinearLayoutManager;
66
import android.support.v7.widget.RecyclerView;
7+
import android.content.Intent;
8+
import android.view.View;
79

810
import com.stephentuso.welcome.WelcomeHelper;
911

@@ -21,6 +23,7 @@ public class MainActivity extends AppCompatActivity {
2123
ArrayList<Items3> item3List;
2224

2325
// Variable to create a Welcome Screen
26+
2427
private WelcomeHelper welcomeScreen;
2528

2629
@Override
@@ -67,6 +70,13 @@ protected void onCreate(Bundle savedInstanceState) {
6770
recyclerView3.setLayoutManager(rvlayoutmanager3);
6871
TextAdapter3 adapter3=new TextAdapter3(this,item3List);
6972
recyclerView3.setAdapter(adapter3);
73+
74+
ItemClickSupport.addTo( recyclerView ).setOnItemClickListener( new ItemClickSupport.OnItemClickListener() {
75+
@Override
76+
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
77+
startActivity( new Intent(MainActivity.this,TodayActivity.class) );
78+
}
79+
} );
7080

7181
// Show the welcome screen
7282
welcomeScreen = new WelcomeHelper(this, WelcomeScreenActivity.class);
@@ -78,4 +88,4 @@ protected void onSaveInstanceState(Bundle outState) {
7888
super.onSaveInstanceState(outState);
7989
welcomeScreen.onSaveInstanceState(outState);
8090
}
81-
}
91+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.example.dhananjay.dailygoals;
2+
3+
import android.app.AlarmManager;
4+
import android.app.NotificationManager;
5+
import android.app.PendingIntent;
6+
import android.content.BroadcastReceiver;
7+
import android.content.Context;
8+
import android.content.Intent;
9+
import android.support.v4.app.NotificationCompat;
10+
import android.widget.EditText;
11+
12+
/**
13+
* Created by kmurali on 25-04-2018.
14+
*/
15+
16+
public class NotificationActivity extends BroadcastReceiver {
17+
@Override
18+
public void onReceive(Context context, Intent intent) {
19+
NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
20+
Intent repeatIntent=new Intent(context,MainActivity.class);
21+
repeatIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
22+
PendingIntent pendingIntent=PendingIntent.getActivity(context,100,repeatIntent,PendingIntent.FLAG_UPDATE_CURRENT);
23+
24+
NotificationCompat.Builder builder=new NotificationCompat.Builder(context)
25+
.setContentIntent(pendingIntent)
26+
.setSmallIcon(R.drawable.tick)
27+
.setContentTitle("Goal Notification")
28+
.setContentText("Time to perform"+"\n"+"task"+"\n"+"Complete your goal")
29+
.setAutoCancel(true);
30+
notificationManager.notify(100,builder.build());
31+
}
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.dhananjay.dailygoals;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.util.DisplayMetrics;
7+
8+
/**
9+
* Created by kmurali on 25-04-2018.
10+
*/
11+
12+
public class PopupActivity extends AppCompatActivity {
13+
14+
@Override
15+
protected void onCreate(@Nullable Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_popup);
18+
DisplayMetrics dm=new DisplayMetrics();
19+
getWindowManager().getDefaultDisplay().getMetrics(dm);
20+
int width=dm.widthPixels;
21+
int height=dm.heightPixels;
22+
getWindow().setLayout((int)(width*.8),(int)(height*.6));
23+
}
24+
}

app/src/main/java/com/example/dhananjay/dailygoals/TodayActivity.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package com.example.dhananjay.dailygoals;
22

3+
import android.app.AlarmManager;
4+
import android.app.NotificationManager;
5+
import android.app.PendingIntent;
6+
import android.content.Context;
7+
import android.content.Intent;
38
import android.graphics.Color;
4-
import android.graphics.drawable.Drawable;
9+
import android.support.v4.app.NotificationCompat;
510
import android.support.v7.app.AppCompatActivity;
611
import android.os.Bundle;
712
import android.view.View;
@@ -10,21 +15,31 @@
1015
import android.widget.Button;
1116
import android.widget.CalendarView;
1217
import android.widget.CheckBox;
18+
import android.widget.DatePicker;
1319
import android.widget.EditText;
1420
import android.widget.Spinner;
1521
import android.widget.Switch;
1622
import android.widget.TextView;
1723
import android.widget.TimePicker;
1824
import android.widget.Toast;
25+
import com.google.firebase.database.DatabaseReference;
26+
import com.google.firebase.database.FirebaseDatabase;
27+
28+
import java.util.Calendar;
1929

2030
public class TodayActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
2131
EditText nameField;
2232
Spinner spin;
2333
String[] Names = {"Health & fitness", "Study", "Job", "Sport", "Others"};
2434
TextView time;
2535
TimePicker simpleTimePicker;
36+
TimePicker notify;
37+
Switch simpleswitch;
2638
Button simpleButton1 , simpleButton2;
27-
CheckBox simpleCheckBox;
39+
CheckBox simpleCheckBox,MK,daily,reminder;
40+
private int hour;
41+
private int minutes;
42+
private DatabaseReference mDatabase;
2843
CalendarView simpleCalendarView;
2944

3045
@Override
@@ -33,9 +48,18 @@ protected void onCreate(Bundle savedInstanceState) {
3348
setContentView( R.layout.activity_today );
3449
nameField = (EditText) findViewById(R.id.simple_editText);
3550
String name = nameField.getText().toString();
51+
final Calendar c = Calendar.getInstance();
52+
hour = c.get(Calendar.HOUR_OF_DAY);
53+
minutes = c.get(Calendar.MINUTE);
54+
mDatabase = FirebaseDatabase.getInstance().getReference();
55+
simpleswitch = findViewById(R.id.simpleSwitch);
3656
// time = (TextView) findViewById(R.id.time);
3757
// initiate a check box
3858
simpleCheckBox = (CheckBox) findViewById(R.id.simpleCheckBox);
59+
reminder = findViewById(R.id.reminder);
60+
daily = findViewById(R.id.daily);
61+
MK = findViewById(R.id.MK);
62+
notify = findViewById(R.id.notify);
3963

4064
spin = (Spinner) findViewById(R.id.simple_spinner);
4165
spin.setOnItemSelectedListener(TodayActivity.this);
@@ -84,15 +108,33 @@ public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
84108
simpleButton1 . setOnClickListener ( new View. OnClickListener () {
85109
@Override
86110
public void onClick ( View view) {
87-
Toast . makeText ( getApplicationContext (), "Simple Button 1" ,
88-
Toast . LENGTH_LONG ). show (); //display the text of button1
111+
Intent i = new Intent(getApplicationContext(), TodayActivity.class);
112+
startActivity(i);
89113
}
90114
});
91115
simpleButton2 . setOnClickListener ( new View . OnClickListener () {
92116
@Override
93117
public void onClick ( View view ) {
94-
Toast . makeText ( getApplicationContext (), "Simple Button 2" ,
95-
Toast . LENGTH_LONG ). show (); //display the text of button2
118+
mDatabase.child("Task").setValue(nameField.getText().toString());
119+
mDatabase.child("Type").setValue(spin.getSelectedItem().toString());
120+
mDatabase.child("From Hour").setValue(simpleTimePicker.getCurrentHour());
121+
mDatabase.child("From Minute").setValue(simpleTimePicker.getCurrentMinute());
122+
mDatabase.child("Notify").setValue(simpleCheckBox.isChecked());
123+
mDatabase.child("Notify at hour").setValue(notify.getCurrentHour());
124+
mDatabase.child("Notify minute").setValue(notify.getCurrentMinute());
125+
mDatabase.child("Make habit").setValue(MK.isChecked());
126+
mDatabase.child("Daily").setValue(daily.isChecked());
127+
mDatabase.child("Super Reminder").setValue(reminder.isChecked());
128+
mDatabase.child("Enable notification").setValue(simpleswitch.isActivated());
129+
Intent i = new Intent(getApplicationContext(), PopupActivity.class);
130+
startActivity(i);
131+
Calendar m = Calendar.getInstance();
132+
m.set(Calendar.HOUR_OF_DAY, notify.getCurrentHour());
133+
m.set(Calendar.MINUTE, notify.getCurrentMinute());
134+
Intent intent = new Intent(getApplicationContext(), NotificationActivity.class);
135+
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
136+
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
137+
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, m.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
96138
}
97139
});
98140
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item>
4+
<shape android:shape="rectangle">
5+
<!--make a gradient background-->
6+
<gradient
7+
android:type="linear"
8+
android:startColor="#000000"
9+
android:endColor="#000000"
10+
android:centerColor="#000000"
11+
android:angle="90"
12+
android:gradientRadius="90"
13+
/>
14+
<!--apply a border around button-->
15+
<stroke android:color="#006400" android:width="2dp" />
16+
<!-- make the button corners rounded-->
17+
<corners android:radius="25dp"/>
18+
</shape>
19+
</item>
20+
</selector>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#ffffff"
6+
android:orientation="vertical">
7+
8+
<TextView
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:text="Task Added"
12+
android:layout_marginTop="50dp"
13+
android:layout_gravity="center"
14+
android:fontFamily="cursive"
15+
android:textSize="30sp"/>
16+
17+
<ImageView
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_gravity="center"
21+
android:layout_marginTop="20dp"
22+
android:src="@drawable/tick"/>
23+
24+
</LinearLayout>

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
android:layout_width = "wrap_content"
131131
android:layout_height = "wrap_content"
132132
android:layout_marginLeft="10dp"
133-
android:layout_marginTop="10dp"
133+
134+
android:layout_marginTop="10dp"
134135
android:text = "Daily "
135136
android:textSize="15sp" />
136137

@@ -171,8 +172,10 @@
171172
android:id = "@+id/simpleSwitch"
172173
android:layout_width = "wrap_content"
173174
android:layout_height = "wrap_content"
174-
android:layout_marginLeft="60dp"
175+
android:layout_marginLeft="50dp"
175176
android:checked = "false"
177+
android:textSize="20sp"
178+
android:layout_marginTop="20dp"
176179
android:text = "Enable Notification"
177180
android:textOff = "Off"
178181
android:textOn = "On" />
@@ -189,23 +192,24 @@
189192
android:layout_width = "wrap_content"
190193
android:layout_height = "wrap_content"
191194
android:layout_centerHorizontal = "true"
192-
android:layout_marginTop = "100dp"
195+
android:layout_marginTop = "70dp"
193196
android:layout_marginLeft="25dp"
194197
android:layout_marginBottom="20dp"
195-
android:background = "#5C6BC0"
198+
android:background = "@drawable/button_round"
196199
android:hint = "Add another activity "
197200
android:textColorHint = "#fff"
201+
android:padding="10dp"
198202
android:textSize = "20sp" />
199203

200204
<Button
201205
android:id = "@+id/simpleButton2"
202206
android:layout_width = "wrap_content"
203207
android:layout_height = "wrap_content"
204208
android:layout_centerHorizontal = "true"
205-
android:layout_marginTop = "100dp"
209+
android:layout_marginTop = "70dp"
206210
android:layout_marginLeft="20dp"
207211
android:layout_marginBottom="20dp"
208-
android:background = "#5C6BC0"
212+
android:background = "@drawable/button_round"
209213
android:hint = "Set"
210214
android:textColorHint = "#fff"
211215
android:textSize = "20sp"/>

0 commit comments

Comments
 (0)