diff --git a/app/src/main/java/com/example/venkat/and/Generate.java b/app/src/main/java/com/example/venkat/and/Generate.java index 1593f04b1325334fd18cb351f39e33d3c7f3b451..ac245208f3e357dfc7469ac5b05b24b4bffd6c05 100644 --- a/app/src/main/java/com/example/venkat/and/Generate.java +++ b/app/src/main/java/com/example/venkat/and/Generate.java @@ -1,6 +1,7 @@ package com.example.venkat.and; import android.content.ActivityNotFoundException; +import android.content.Context; import android.content.Intent; import android.speech.RecognizerIntent; import android.support.v7.app.AppCompatActivity; @@ -10,6 +11,7 @@ import android.widget.TextView; import android.widget.Toast; import java.io.BufferedReader; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -99,19 +101,40 @@ public class Generate extends AppCompatActivity { sb.append(s); String fl="history.txt"; textView.setText("Waiting for the question"); + String FILE_NAME = "history.txt"; try { - OutputStreamWriter out = new OutputStreamWriter(openFileOutput(fl,0)); - out.write(s); - out.close(); - } catch (FileNotFoundException e) { + FileOutputStream fos = openFileOutput(FILE_NAME, Context.MODE_PRIVATE); + fos.write(s.toString().getBytes()); + fos.close(); + Toast.makeText(this, s, Toast.LENGTH_SHORT).show(); + } catch (Exception e) { e.printStackTrace(); + } + BufferedReader bufferedReader ; + + + + String content = "hello world"; + File file1; + FileOutputStream outputStream; + try { + // file = File.createTempFile("MyCache", null, getCacheDir()); + file1 = new File(getCacheDir(), "MyCache"); + + outputStream = new FileOutputStream(file1); + outputStream.write(content.getBytes()); + outputStream.close(); } catch (IOException e) { e.printStackTrace(); } - BufferedReader bufferedReader ; + + + + + String file=null; s=s.toLowerCase(); - Toast.makeText(this, "in this fn", Toast.LENGTH_SHORT).show(); + //Toast.makeText(this, "in this fn", Toast.LENGTH_SHORT).show(); try { bufferedReader =new BufferedReader(new InputStreamReader(getAssets().open("INDEX.txt"))); String st; @@ -121,7 +144,7 @@ public class Generate extends AppCompatActivity { if(s.equals(st)==true) { file=bufferedReader.readLine(); - Toast.makeText(this, file, Toast.LENGTH_SHORT).show(); + // Toast.makeText(this, file, Toast.LENGTH_SHORT).show(); bufferedReader.close(); break; } diff --git a/app/src/main/java/com/example/venkat/and/MainActivity.java b/app/src/main/java/com/example/venkat/and/MainActivity.java index 0b70e6178f6c70d8b0e7d394a7c6cdd5ed0ef400..580e7860f982726e8082a4d4a5d3ae31ec91be6a 100644 --- a/app/src/main/java/com/example/venkat/and/MainActivity.java +++ b/app/src/main/java/com/example/venkat/and/MainActivity.java @@ -104,6 +104,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On int t=10; Toast.makeText(MainActivity.this, ""+star, Toast.LENGTH_SHORT).show(); dialog.cancel(); + + + Toast.makeText(MainActivity.this, "Thank you", Toast.LENGTH_SHORT).show(); } }); @@ -116,7 +119,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); - String shareBody = "The link is still under work"; + String shareBody = "https://drive.google.com/open?id=0B9gW072mnYQzbk9nWVNXZnhqaFU"; sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here"); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(sharingIntent, "Share via")); diff --git a/app/src/main/java/com/example/venkat/and/history.java b/app/src/main/java/com/example/venkat/and/history.java index 6efdb71a5fcc2efefce8b8afbf078ea5d84d927b..98043488e6d0d8358541f823bdda1b635cf10e31 100644 --- a/app/src/main/java/com/example/venkat/and/history.java +++ b/app/src/main/java/com/example/venkat/and/history.java @@ -3,6 +3,7 @@ package com.example.venkat.and; import android.os.Environment; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Adapter; import android.widget.AdapterView; @@ -14,6 +15,7 @@ import android.widget.Toast; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; @@ -28,7 +30,7 @@ public class history extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_history); - + Toast.makeText(this, "open", Toast.LENGTH_SHORT).show(); BufferedReader reader = null; ArrayList<String> s =new ArrayList<String>(); // String s[]={}; @@ -36,42 +38,76 @@ public class history extends AppCompatActivity { final ListView listView=(ListView)findViewById(R.id.lst); int t=0; + + + + + + + BufferedReader input = null; + File file = null; try { - reader = new BufferedReader( - new InputStreamReader(getAssets().open("history.txt"))); + file = new File(getCacheDir(), "MyCache"); // Pass getFilesDir() and "MyFile" to read file + input = new BufferedReader(new InputStreamReader(new FileInputStream(file))); + String line; + StringBuffer buffer = new StringBuffer(); + while ((line = input.readLine()) != null) { + + text.append(line); + text.append('\n'); } - // do reading, usually loop until end of file reading - String mLine; - while ((mLine = reader.readLine()) != null) { - t=1; - // s[i]=mLine; - s.add(mLine); - text.append(mLine); - text.append('\n'); - } } catch (IOException e) { - Toast.makeText(getApplicationContext(), "Error reading file!", Toast.LENGTH_LONG).show(); e.printStackTrace(); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { + }finally { + listView.setAdapter(listAdapter); + } - } - } -// TextView output = (TextView) findViewById(R.id.tu1); -// output.setText((CharSequence) text); - if(t!=0) - { - listView.setAdapter(listAdapter); - } - } + + + + + + + + + +// +// try { +// reader = new BufferedReader( +// new InputStreamReader(getAssets().open("history.txt"))); +// +// +// String mLine; +// while ((mLine = reader.readLine()) != null) { +// t=1; +// s.add(mLine); +// +// text.append(mLine); +// text.append('\n'); +// } +// } catch (IOException e) { +// Toast.makeText(getApplicationContext(), "Error reading file!", Toast.LENGTH_LONG).show(); +// e.printStackTrace(); +// } finally { +// if (reader != null) { +// try { +// reader.close(); +// } catch (IOException e) { +// +// } +// } +// if(t!=0) +// { +// +// listView.setAdapter(listAdapter); +// } +// +// }