You need to sign in or sign up before continuing.
Commit 2b030c7b authored by PANKAJ KUMAR's avatar PANKAJ KUMAR

Receive reminder feature

Able to read File. Parsing and putting it in the view is pending.
parent 85eb5c58
...@@ -49,7 +49,6 @@ dependencies { ...@@ -49,7 +49,6 @@ dependencies {
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
// Lombok Dependencies // Lombok Dependencies
compileOnly 'org.projectlombok:lombok:1.18.10' compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10' annotationProcessor 'org.projectlombok:lombok:1.18.10'
......
/*
* Copyright 2015 Blanyal D'Souza.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.blanyal.remindme; package com.blanyal.remindme;
import android.Manifest; import android.Manifest;
...@@ -23,11 +6,11 @@ import android.app.DatePickerDialog; ...@@ -23,11 +6,11 @@ import android.app.DatePickerDialog;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.SyncStateContract; import android.os.Environment;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
...@@ -41,26 +24,21 @@ import android.widget.TextView; ...@@ -41,26 +24,21 @@ import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import android.widget.Toast; import android.widget.Toast;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import android.os.Environment; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import androidx.core.content.FileProvider;
import java.util.Calendar; import java.util.Calendar;
import com.google.gson.Gson;
import android.Manifest.permission;
public class ReminderAddActivity extends AppCompatActivity { public class ReminderAddActivity extends AppCompatActivity {
private Toolbar mToolbar; private Toolbar mToolbar;
...@@ -376,7 +354,7 @@ public class ReminderAddActivity extends AppCompatActivity { ...@@ -376,7 +354,7 @@ public class ReminderAddActivity extends AppCompatActivity {
return false; return false;
} }
//on clicking the send button //on clicking the send button
public void sendReminder(String filename){ public void saveReminderToTempStorage(String filename){
/* mTitleText = (EditText) findViewById(R.id.reminder_title); /* mTitleText = (EditText) findViewById(R.id.reminder_title);
mDateText = (TextView) findViewById(R.id.set_date); mDateText = (TextView) findViewById(R.id.set_date);
mTimeText = (TextView) findViewById(R.id.set_time); mTimeText = (TextView) findViewById(R.id.set_time);
...@@ -525,22 +503,22 @@ public class ReminderAddActivity extends AppCompatActivity { ...@@ -525,22 +503,22 @@ public class ReminderAddActivity extends AppCompatActivity {
Context context = this; Context context = this;
String filename = Utility.FILE_NAME_PREFIX + "." + Utility.FILE_EXTENSION; //TODO Consecutive filenames should be unique String filename = Utility.FILE_NAME_PREFIX + "." + Utility.FILE_EXTENSION; //TODO Consecutive filenames should be unique
sendReminder(filename); saveReminderToTempStorage(filename);
// //Check the if the file was written correctly.. Should be printed on console //Check the if the file was written correctly.. Should be printed on console
FileInputStream fi = null; // FileInputStream fi = null;
try { // try {
fi = context.openFileInput(filename); // fi = context.openFileInput(filename);
int i; // int i;
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
while ((i=fi.read()) != -1) // while ((i=fi.read()) != -1)
sb.append((char)i); // sb.append((char)i);
System.out.println("******************************************************************"); // System.out.println("******************************************************************");
System.out.println(sb.toString()); // System.out.println(sb.toString());
System.out.println("******************************************************************"); // System.out.println("******************************************************************");
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
//Pick the written file and send //Pick the written file and send
File filePath = context.getFilesDir(); File filePath = context.getFilesDir();
......
package com.blanyal.remindme; package com.blanyal.remindme;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
public class ReminderReceiveActivity extends AppCompatActivity { import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
public class ReminderReceiveActivity extends AppCompatActivity {
private Toolbar mToolbar;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_reminder); setContentView(R.layout.activity_add_reminder);
Context context = this;
// Setup Toolbar
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle(R.string.activity_add_reminder_label);
//Get the file from intent
Intent intent = getIntent(); Intent intent = getIntent();
Toast.makeText(this, "Reminder Received", Toast.LENGTH_LONG); Uri fileUri = intent.getData();
if (intent.getType().equals("text/"+Utility.FILE_EXTENSION)) {
try {
InputStream in = getContentResolver().openInputStream(fileUri);
int i;
StringBuilder sb = new StringBuilder();
while ((i=in.read()) != -1)
sb.append((char)i);
System.out.println("******************************************************************");
System.out.println(sb.toString());
System.out.println("******************************************************************");
} catch (Exception e) {
e.printStackTrace();
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment