use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveenIO.
the class ViewActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.copy) {
Snackbar.make(tv, "Copied!", Snackbar.LENGTH_SHORT).show();
} else if (item.getItemId() == R.id.edit) {
Intent intent = new Intent(ViewActivity.this, EditActivity.class);
intent.putExtra("note", noteText);
intent.putExtra("id", id);
intent.putExtra("title", noteTitle);
intent.putExtra("imp", imp);
startActivity(intent);
} else if (item.getItemId() == R.id.share) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, noteTitle + "\n\n" + noteText);
sendIntent.setType("text/plain");
startActivity(sendIntent);
} else if (item.getItemId() == android.R.id.home)
onBackPressed();
else if (item.getItemId() == R.id.delete) {
final DatabaseHandler db = new DatabaseHandler(this);
List<Note> l = db.getAllNotes();
final Note note = l.get(position);
db.deleteNote(note);
BinDatabaseHandler db2 = new BinDatabaseHandler(ViewActivity.this);
db2.addNote(new Note(note.getNote(), note.getDate(), note.getStar(), note.getTitle()));
Intent i = new Intent(ViewActivity.this, MainActivity.class);
i.putExtra("delete", true);
i.putExtra("note", true);
startActivity(i);
finish();
}
return true;
}
use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveen.
the class MainActivity method populateData.
public void populateData() {
final DatabaseHandler db = new DatabaseHandler(this);
l = db.getAllNotes();
final RecyclerView recyclerView = findViewById(R.id.recyclerView);
final RelativeLayout rl = findViewById(R.id.placeholder);
if (l.isEmpty()) {
recyclerView.setVisibility(View.GONE);
rl.setVisibility(View.VISIBLE);
}
mAdapter = new NoteAdapter(l);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
recyclerView.setAdapter(mAdapter);
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), new ClickListener() {
@Override
public void onClick(View view, final int position) {
if (ser == 0) {
int pos = position;
if (imp == 1)
pos = mAdapter.impPos(position);
final Note note = l.get(pos);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("text", note.getNote());
if (clipboard != null)
clipboard.setPrimaryClip(clip);
Intent intent = new Intent(MainActivity.this, ViewActivity.class);
intent.putExtra("note", note.getNote());
intent.putExtra("id", note.getID());
intent.putExtra("imp", note.getStar());
intent.putExtra("date", note.getDate());
intent.putExtra("title", note.getTitle());
intent.putExtra("pos", pos);
startActivity(intent);
finish();
}
}
}));
}
use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveen.
the class ViewActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.copy) {
Snackbar.make(tv, "Copied!", Snackbar.LENGTH_SHORT).show();
} else if (item.getItemId() == R.id.edit) {
Intent intent = new Intent(ViewActivity.this, EditActivity.class);
intent.putExtra("note", noteText);
intent.putExtra("id", id);
intent.putExtra("title", noteTitle);
intent.putExtra("imp", imp);
startActivity(intent);
} else if (item.getItemId() == R.id.share) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, noteTitle + "\n\n" + noteText);
sendIntent.setType("text/plain");
startActivity(sendIntent);
} else if (item.getItemId() == android.R.id.home)
onBackPressed();
else if (item.getItemId() == R.id.delete) {
final DatabaseHandler db = new DatabaseHandler(this);
List<Note> l = db.getAllNotes();
final Note note = l.get(position);
db.deleteNote(note);
BinDatabaseHandler db2 = new BinDatabaseHandler(ViewActivity.this);
db2.addNote(new Note(note.getNote(), note.getDate(), note.getStar(), note.getTitle()));
Intent i = new Intent(ViewActivity.this, MainActivity.class);
i.putExtra("delete", true);
i.putExtra("note", true);
startActivity(i);
finish();
}
return true;
}
use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveenIO.
the class EditActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(EditActivity.this);
premium = preferences.getInt("premium", 0);
interstitialAd = new InterstitialAd(EditActivity.this);
interstitialAd.setAdUnitId("ca-app-pub-8429477298745270/2004640333");
interstitialAd.loadAd(new AdRequest.Builder().build());
intent = new Intent(EditActivity.this, MainActivity.class);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/whitney.ttf").setFontAttrId(R.attr.fontPath).build());
Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/whitney.ttf");
SpannableStringBuilder SS = new SpannableStringBuilder("Edit Note");
SS.setSpan(new CustomTypefaceSpan("", font2), 0, SS.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(SS);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
String noteText = "", noteTitle = "";
if (getIntent().getExtras() != null) {
noteText = getIntent().getExtras().getString("note");
noteTitle = getIntent().getExtras().getString("title");
}
FloatingActionButton fab = findViewById(R.id.edit_fab);
text = findViewById(R.id.edit_text);
title = findViewById(R.id.edit_title);
text.setText(noteText);
title.setText(noteTitle);
text.setSelection(noteText != null ? noteText.length() : 0);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(@NonNull View v) {
String note = text.getText().toString();
Title = title.getText().toString();
if (note.length() > 0) {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("HH:mm dd/MM/yyyy", Locale.ENGLISH);
String formattedDate = df.format(c.getTime());
int id = 0;
if (getIntent().getExtras() != null) {
id = getIntent().getExtras().getInt("id");
}
DatabaseHandler db = new DatabaseHandler(EditActivity.this);
db.updateNote(new Note(id, note, formattedDate, imp, Title));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("edit", true);
intent.putExtra("note", true);
if (interstitialAd.isLoaded() && premium != 1) {
interstitialAd.show();
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
startActivity(intent);
finish();
}
});
} else {
startActivity(intent);
finish();
}
} else
Snackbar.make(v, "Note is empty!", Snackbar.LENGTH_SHORT).show();
}
});
}
use of io.praveen.typenote.SQLite.DatabaseHandler in project Android-NotesApp by HelloPraveenIO.
the class MainActivity method populateData.
public void populateData() {
final DatabaseHandler db = new DatabaseHandler(this);
l = db.getAllNotes();
final RecyclerView recyclerView = findViewById(R.id.recyclerView);
final RelativeLayout rl = findViewById(R.id.placeholder);
if (l.isEmpty()) {
recyclerView.setVisibility(View.GONE);
rl.setVisibility(View.VISIBLE);
}
mAdapter = new NoteAdapter(l);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
recyclerView.setAdapter(mAdapter);
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), new ClickListener() {
@Override
public void onClick(View view, final int position) {
if (ser == 0) {
int pos = position;
if (imp == 1)
pos = mAdapter.impPos(position);
final Note note = l.get(pos);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("text", note.getNote());
if (clipboard != null)
clipboard.setPrimaryClip(clip);
Intent intent = new Intent(MainActivity.this, ViewActivity.class);
intent.putExtra("note", note.getNote());
intent.putExtra("id", note.getID());
intent.putExtra("imp", note.getStar());
intent.putExtra("date", note.getDate());
intent.putExtra("title", note.getTitle());
intent.putExtra("pos", pos);
startActivity(intent);
finish();
}
}
}));
}
Aggregations