Search in sources :

Example 6 with DatabaseHandler

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;
}
Also used : BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) Note(io.praveen.typenote.SQLite.Note) Intent(android.content.Intent)

Example 7 with DatabaseHandler

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();
            }
        }
    }));
}
Also used : RecyclerTouchListener(io.praveen.typenote.SQLite.RecyclerTouchListener) ClipboardManager(android.content.ClipboardManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) SuppressLint(android.annotation.SuppressLint) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) Note(io.praveen.typenote.SQLite.Note) RelativeLayout(android.widget.RelativeLayout) NoteAdapter(io.praveen.typenote.SQLite.NoteAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ClipData(android.content.ClipData) ClickListener(io.praveen.typenote.SQLite.ClickListener)

Example 8 with DatabaseHandler

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;
}
Also used : BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) BinDatabaseHandler(io.praveen.typenote.SQLite.BinDatabaseHandler) Note(io.praveen.typenote.SQLite.Note) Intent(android.content.Intent)

Example 9 with DatabaseHandler

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();
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) Typeface(android.graphics.Typeface) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) Intent(android.content.Intent) View(android.view.View) AdListener(com.google.android.gms.ads.AdListener) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) Note(io.praveen.typenote.SQLite.Note) FloatingActionButton(android.support.design.widget.FloatingActionButton) InterstitialAd(com.google.android.gms.ads.InterstitialAd) SimpleDateFormat(java.text.SimpleDateFormat) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 10 with DatabaseHandler

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();
            }
        }
    }));
}
Also used : RecyclerTouchListener(io.praveen.typenote.SQLite.RecyclerTouchListener) ClipboardManager(android.content.ClipboardManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) SuppressLint(android.annotation.SuppressLint) DatabaseHandler(io.praveen.typenote.SQLite.DatabaseHandler) Note(io.praveen.typenote.SQLite.Note) RelativeLayout(android.widget.RelativeLayout) NoteAdapter(io.praveen.typenote.SQLite.NoteAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ClipData(android.content.ClipData) ClickListener(io.praveen.typenote.SQLite.ClickListener)

Aggregations

Intent (android.content.Intent)10 DatabaseHandler (io.praveen.typenote.SQLite.DatabaseHandler)10 Note (io.praveen.typenote.SQLite.Note)10 View (android.view.View)8 SharedPreferences (android.content.SharedPreferences)6 Typeface (android.graphics.Typeface)6 SpannableStringBuilder (android.text.SpannableStringBuilder)6 AdListener (com.google.android.gms.ads.AdListener)6 InterstitialAd (com.google.android.gms.ads.InterstitialAd)6 SuppressLint (android.annotation.SuppressLint)4 PendingIntent (android.app.PendingIntent)4 FloatingActionButton (android.support.design.widget.FloatingActionButton)4 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)4 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 RelativeLayout (android.widget.RelativeLayout)4 BinDatabaseHandler (io.praveen.typenote.SQLite.BinDatabaseHandler)4 ClickListener (io.praveen.typenote.SQLite.ClickListener)4 NoteAdapter (io.praveen.typenote.SQLite.NoteAdapter)4