Skip to content

Commit

Permalink
Update README.md (#21)
Browse files Browse the repository at this point in the history
* Add VIBRATE/GENERAL function with time

* Add repeating sound-profile changer function

* fix delay

* Implement multiple slots

* Implement delete slot from DB

* Implement cancel slot from alarm_manager

* Add +button

* fix invalid time input

* Fix duplicate entries

* Add home button

* add comments

* Add toggle

* Remove unnecessary lines and add comments

* fix toggle crash

* updated readme (#9)

* Update README.md

* Update README.md

* Update README.md

* Update README.md (#10)

* Update README.md

* Update README.md (#11)

* Update README.md

* Update README.md (#14)

Add project members information.

* Update README.md (#13)

* Update README.md (#12)

* Update ReadMe (#16)

* Add homescreen screenshot (#17)

* Add screenshot (#18)

* Update screenshots (#19)

* Update Readme (#20)

* Update README.md
  • Loading branch information
nisheeth-golakiya committed Oct 6, 2018
1 parent 589344a commit 9f7ca0c
Show file tree
Hide file tree
Showing 17 changed files with 374 additions and 128 deletions.
17 changes: 16 additions & 1 deletion README.md
@@ -1,2 +1,17 @@
# SoundProfile
This is an android application that will manage your sound profile according to your schedule.
This is an Android application that will manage your sound profile according to your input schedule for the week. It is developed as a course project using principles of Software Engineering.

* It can be disabled for a particular day(in case of a holiday).
* Uses SQLite
* Different schedules can be applied for different days of the week.
# ScreenShots
### Home Screen
![Home Screen](Screenshot_20181002-194340.jpg?raw=true "Home Screen")
### Time Slot Addition
![Time Slot Addition](Screenshot_20181002-194259.jpg?raw=true "Title")
## Project Members:
1. [Ravinder Nehra](https://www.github.com/rnehra01)
2. [Nisheeth Golakiya](https//www.github.com/nisheeth-golakiya)
3. [Suraj Tripathi](https://www.github.com/suraj97)
4. [Sudhanshu Sambharya](https://www.github.com/sudwebd)
5. [Shubham Raj](https://www.github.com/raj808569)
Binary file added Screenshot_20181002-194259.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot_20181002-194340.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions SoundProfile
Submodule SoundProfile added at a45880
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -27,7 +27,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support.constraint:constraint-layout:+'
compile 'com.android.support:design:25.3.1'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'

testCompile 'junit:junit:4.12'
}
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -27,7 +27,11 @@
<receiver android:name=".Alarm_Receiver" />
<service android:name=".ProfileChangeService"
android:enabled="true">
</service>
</service><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>

</manifest>
Expand Up @@ -20,20 +20,16 @@
*/

public class Alarm_Receiver extends BroadcastReceiver {
//private GoogleApiClient client;
//private

//handler for bradcasting event
@Override
public void onReceive(Context context, Intent intent) {
// client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

Log.e("We are in the receiver.", "YAY!");
// final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Log.d("We are in the receiver.", "YAY!");

//create an intent
boolean switchToVibrate = intent.getExtras().getBoolean("switchToVibrate");

Intent service_intent = new Intent(context, ProfileChangeService.class);

service_intent.putExtra("switchToVibrate", switchToVibrate);
context.startService(service_intent);
}
}
195 changes: 187 additions & 8 deletions app/src/main/java/com/example/csn254/soundprofile/Home.java
@@ -1,49 +1,91 @@
package com.example.csn254.soundprofile;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

import java.util.Calendar;

public class Home extends AppCompatActivity {

ImageButton floatButton;
Switch Switch_slot;
ListView slot_list;
Context ctx=this;
Context ctx = this;
private GoogleApiClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
display_slot_list();
floatButton = (ImageButton) findViewById(R.id.addButton);
//listener for add button
floatButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Button Clicked", Toast.LENGTH_SHORT).show();
launch_add_slot_activity();
}
});

Switch_slot = (Switch) findViewById(R.id.switch_slot);
Switch_slot.setChecked(true);
//listener for switch_slot
Switch_slot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked){
Log.e("toggle", "added");
add_all_slots();
}else{
Log.e("toggle", "cancelled");
try{
cancel_all_slot();
}catch (CursorIndexOutOfBoundsException e){
Toast.makeText(getBaseContext(), "Nothing to cancel", Toast.LENGTH_SHORT).show();
Switch_slot.setChecked(true);
}

}

}
});
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
public void launch_add_slot_activity(){
Intent i=new Intent(this, add_slot.class);

//launch the add activity
public void launch_add_slot_activity() {
Intent i = new Intent(this, add_slot.class);
finish();
startActivity(i);
}

public void display_slot_list(){
//fetch all the entries from slot db and display them
public void display_slot_list() {
int count = 0;
time_slot_db DOP = new time_slot_db(ctx);
final Cursor CR = DOP.getInformation(DOP);

Cursor CR = DOP.getInformation(DOP);

CR.moveToFirst();
do {
Expand All @@ -59,18 +101,155 @@ public void display_slot_list(){
do {
slot_day_list[i] = CR.getString(0);
slot_time_list[i] = CR.getString(1) + " - " + CR.getString(2);
Log.e("err", slot_day_list[i]+slot_time_list[i]);
//Log.d("display",slot_day_list[i]+slot_time_list[i]);
i++;
} while (CR.moveToNext());


ListAdapter adapter = new custom_slot_adapter(this, slot_day_list, slot_time_list);
slot_list = (ListView) findViewById(R.id.slot_list);
slot_list.setAdapter(adapter);
//listener for each element in the list while long-pressing
slot_list.setOnItemLongClickListener(
new AdapterView.OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
String day = String.valueOf(parent.getItemAtPosition(position));
String time_duration=String.valueOf(((TextView)parent.getChildAt(position).findViewById(R.id.time_duration)).getText().toString());
String times[] = time_duration.split("-");
time_slot_db DB = new time_slot_db(ctx);
DB.deleteSlot(DB, day, times[0].trim(), times[1].trim());
cancelSlot(day, times[0].trim(), times[1].trim());
finish();
startActivity(getIntent());
Toast.makeText(getBaseContext(),"Cancelled "+day+" "+time_duration, Toast.LENGTH_SHORT).show();
return false;
}
}
);

} catch (CursorIndexOutOfBoundsException e) {
Toast.makeText(getBaseContext(), "Please add a slot FIRST", Toast.LENGTH_LONG).show();
}


}

//cancel all the slote on toggle off
public void cancel_all_slot(){
time_slot_db DOP = new time_slot_db(ctx);
Cursor CR = DOP.getInformation(DOP);

CR.moveToFirst();
do {
cancelSlot(CR.getString(0).trim(), CR.getString(1).trim(), CR.getString(2).trim());
} while (CR.moveToNext());
}

//cancel a particular slot
public void cancelSlot(String day, String start_time, String end_time){
int hours = Integer.parseInt(start_time.split(":")[0].trim());
int mins = Integer.parseInt(start_time.split(":")[1].trim());
if (mins == 0){
mins = 59;
hours = (hours == 0) ? 23:(hours-1);
}else {
mins = (mins-1)%60;
}
int start_req_ID = hours*100+mins;
hours = Integer.parseInt(end_time.split(":")[0].trim());
mins = Integer.parseInt(end_time.split(":")[1].trim());
if (mins == 0){
mins = 59;
hours = (hours == 0) ? 23:(hours-1);
}else {
mins = (mins-1)%60;
}
int end_req_ID = hours*100+mins;
String dayz[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
for (int i=1; i<=7; i++){
if (dayz[i-1].equals(day.trim())){
start_req_ID += i*10000;
end_req_ID += i*10000;
}
}

PendingIntent pendingstartIntent = PendingIntent.getBroadcast(getApplicationContext(), start_req_ID, new Intent(getApplicationContext(), Alarm_Receiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingendIntent = PendingIntent.getService(getApplicationContext(), end_req_ID, new Intent(getApplicationContext(), Alarm_Receiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm_manager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarm_manager.cancel(pendingstartIntent);
Log.e("cancelslot",""+start_time+"-"+start_req_ID);
alarm_manager.cancel(pendingendIntent);
Log.e("cancelslot",""+end_time+"-"+end_req_ID);
}

//add all alots in DB for sound-profile changing
public void add_all_slots(){
time_slot_db DOP = new time_slot_db(ctx);
Cursor CR = DOP.getInformation(DOP);

CR.moveToFirst();
do {
int sHour = Integer.parseInt(CR.getString(1).split(":")[0].trim());
int sMin = Integer.parseInt(CR.getString(1).split(":")[1].trim());
setSlotTime(CR.getString(0).trim(), sHour, sMin, true);
int eHour = Integer.parseInt(CR.getString(2).split(":")[0].trim());
int eMin = Integer.parseInt(CR.getString(2).split(":")[1].trim());
setSlotTime(CR.getString(0).trim(), eHour, eMin, false);
} while (CR.moveToNext());
}

//set a particular slot for sound profile changing
public void setSlotTime(String day, int hours, int minutes, boolean switchToVibrate){
Calendar calendar = Calendar.getInstance();
Intent my_intent = new Intent(getApplicationContext(), Alarm_Receiver.class);
my_intent.putExtra("switchToVibrate", switchToVibrate);

int dayOfWeek=-1;
String dayz[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
for (int i=1; i<=7; i++){
if (dayz[i-1].equals(day.trim())){
dayOfWeek = i;
}
}

calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek);
if (minutes == 0){
minutes = 59;
hours = (hours == 0) ? 23:(hours-1);
}else {
minutes = (minutes-1)%60;
}
calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minutes);
int reqID = dayOfWeek*10000 + hours*100 + minutes;
PendingIntent pending_intent = PendingIntent.getBroadcast(getApplicationContext(), reqID, my_intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm_manager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarm_manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pending_intent);
}

public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Home Page")
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}

@Override
public void onStart() {
super.onStart();
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}

@Override
public void onStop() {
super.onStop();
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
}
Expand Up @@ -15,6 +15,7 @@
/**
* Created by suraj on 2/4/17.
*/
// main function of the app which reads the various time slots in the list and toggles sound profile according to the input schedule

public class ProfileChangeService extends Service {
private AudioManager am;
Expand All @@ -25,10 +26,15 @@ public IBinder onBind(Intent intent) {
return null;
}
public int onStartCommand(Intent intent, int flags, int startId){
boolean switchToVibrate = intent.getExtras().getBoolean("switchToVibrate");
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Log.i("Local Service", "Received start id" + startId + ": " + intent);
Toast.makeText(this, "onStart called", Toast.LENGTH_SHORT).show();
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

if (switchToVibrate){Log.e("err", "1-SILENTMODE");
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}else {Log.e("err", "0-NORMALMODE");
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}

return START_NOT_STICKY;
}
}
Expand Up @@ -5,8 +5,12 @@
public class TableData {
public TableData(){}

// abstract class mapping various strings to their respective variables

public static abstract class TableInfo implements BaseColumns{
public static final String DAY="slot_day";
public static final String START_TIME_REQ_ID="start_time_req_id";
public static final String END_TIME_REQ_ID="end_time_req_id";
public static final String START_TIME="start_time";
public static final String END_TIME="end_time";
public static final String DATABASE_NAME="time_slots";
Expand Down

0 comments on commit 9f7ca0c

Please sign in to comment.