Skip to content

Commit

Permalink
End task
Browse files Browse the repository at this point in the history
  • Loading branch information
somyaguglani committed Jul 7, 2019
1 parent daf2a11 commit 31a638a
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".BMIActivity"></activity>
<activity android:name=".ChoosingActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<activity android:name=".NoteStartActivity"></activity>
<activity android:name=".NoteEditorActivity" />
<activity android:name=".BMIActivity" />
<activity android:name=".ChoosingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".OtherActivity"/>
<activity android:name=".MainActivity"></activity>
<activity android:name=".OtherActivity" />
<activity android:name=".MainActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class ChoosingActivity extends AppCompatActivity {

ImageButton bmi,bmr;
ImageButton bmi,bmr,takenotes;


@Override
Expand Down Expand Up @@ -42,6 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {

bmi= findViewById(R.id.imbtn_bmi);
bmr = findViewById(R.id.imbtn_bmr);
takenotes = findViewById(R.id.imbtn_bmi_takenotes);

bmi.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -57,6 +58,14 @@ public void onClick(View view) {
startActivity(i);
}
});
takenotes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(ChoosingActivity.this,NoteStartActivity.class);
startActivity(i);

}
});



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.example.bmrcalculator;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import java.util.HashSet;

public class NoteEditorActivity extends AppCompatActivity {

int noteId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_editor);

EditText editText= findViewById(R.id.et_inputnote);
noteId = getIntent().getIntExtra("noteId",-1);//imp since indexing starts from 0 this checks for something invalid
if(noteId!=-1){
editText.setText(NoteStartActivity.notes.get(noteId));
}else{
NoteStartActivity.notes.add("");
noteId= NoteStartActivity.notes.size()-1;
NoteStartActivity.arrayAdapter.notifyDataSetChanged();

}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
NoteStartActivity.notes.set(noteId,String.valueOf(charSequence));
NoteStartActivity.arrayAdapter.notifyDataSetChanged();

SharedPreferences sharedPreferences= getApplicationContext().getSharedPreferences("com.example.bmrcalculator", Context.MODE_PRIVATE);
HashSet<String> set= new HashSet<>(NoteStartActivity.notes);
sharedPreferences.edit().putStringSet("notes",set).apply();

}

@Override
public void afterTextChanged(Editable editable) {

}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.example.bmrcalculator;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.HashSet;

public class NoteStartActivity extends AppCompatActivity {
ListView listView;

static ArrayAdapter<String> arrayAdapter;
static ArrayList<String > notes = new ArrayList<>();

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.add_new_menu,menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
super.onOptionsItemSelected(item);
if(item.getItemId()==R.id.add_note){
Intent intent = new Intent(getApplicationContext(),NoteEditorActivity.class);
startActivity(intent);
return true;
}
return false;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView= findViewById(R.id.lv_listview);//use ..toi save space we don't want duplicates //new concept learn
SharedPreferences sharedPreferences= getApplicationContext().getSharedPreferences("com.example.bmrcalculator", Context.MODE_PRIVATE);
HashSet<String> set = (HashSet<String>) sharedPreferences.getStringSet("notes",null);

if(set==null)
notes.add("Example note");
else
notes = new ArrayList<>(set);


arrayAdapter= new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1,
notes);

listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent= new Intent(getApplicationContext(),NoteEditorActivity.class);
intent.putExtra("noteId",i);
startActivity(intent);
}
});


listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {

final int item_to_delete = i;
new AlertDialog.Builder( NoteStartActivity.this)
.setCancelable(false)
.setTitle("Are yiou sure?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage("Do you want to delete this note?")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
notes.remove(item_to_delete);
arrayAdapter.notifyDataSetChanged();

SharedPreferences sharedPreferences= getApplicationContext().getSharedPreferences("com.example.bmrcalculator", Context.MODE_PRIVATE);
HashSet<String> set= new HashSet<>(NoteStartActivity.notes);
sharedPreferences.edit().putStringSet("notes",set).apply();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

}
})
.show();


return true;
}
});

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@
android:layout_width="137dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="130dp"
android:layout_marginTop="30dp"
android:src="@drawable/bmi_pic" />

<ImageButton
android:id="@+id/imbtn_bmi_takenotes"
android:layout_width="137dp"
android:layout_height="135dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:src="@drawable/note_taking" />


</LinearLayout>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".NoteEditorActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:gravity="top"
android:id="@+id/et_inputnote"/>

</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"

tools:context=".MainActivity">

<ListView

android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv_listview">

</ListView>

</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/add_note"
android:title="@string/add">

</item>

</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
<string name="severe_underweighgt">Severe Underweight</string>
<string name="moderate_weight">Moderate weight</string>
<string name="body_fat_percentage_is">BODY FAT PERCENTAGE IS</string>
<string name="add_note">add_note</string>
<string name="add">Add note</string>
</resources>

0 comments on commit 31a638a

Please sign in to comment.