add a dialog for creating new notes

This commit is contained in:
tibbi 2016-10-01 11:35:24 +02:00
parent 87530d9fbc
commit 5f4001e71a
7 changed files with 69 additions and 1 deletions

View File

@ -4,10 +4,12 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
@ -81,7 +83,29 @@ public class MainActivity extends SimpleActivity {
@OnClick(R.id.notes_fab)
public void fabClicked(View view) {
final View newNoteView = getLayoutInflater().inflate(R.layout.new_note, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getString(R.string.new_note));
builder.setView(newNoteView);
builder.setPositiveButton(R.string.ok, null);
builder.setNegativeButton(R.string.cancel, null);
final AlertDialog alertDialog = builder.create();
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText titleET = (EditText) newNoteView.findViewById(R.id.note_name);
final String title = titleET.getText().toString().trim();
if (title.isEmpty()) {
Utils.showToast(getApplicationContext(), R.string.no_title);
} else {
alertDialog.dismiss();
}
}
});
}
private void saveText() {

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin">
<EditText
android:id="@+id/note_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:inputType="textCapSentences" />
</LinearLayout>

View File

@ -8,6 +8,11 @@
<string name="cannot_share_empty_text">Leerer Text kann nicht geteilt werden</string>
<string name="note_saved">Text gespeichert</string>
<string name="simple_note">Einfache Notiz</string>
<string name="new_note">Add a new note</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="no_title">Please name your note</string>
<string name="title_taken">A note with that title already exists</string>
<!-- Settings -->
<string name="settings">Einstellungen</string>

View File

@ -8,6 +8,11 @@
<string name="cannot_share_empty_text">Impossibile condividere un testo vuoto</string>
<string name="note_saved">Testo salvato</string>
<string name="simple_note">Simple Note</string>
<string name="new_note">Add a new note</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="no_title">Please name your note</string>
<string name="title_taken">A note with that title already exists</string>
<!-- Settings -->
<string name="settings">Impostazioni</string>

View File

@ -4,10 +4,15 @@
<string name="widget_config">シンプルメモのご利用ありがとうございます。\n他のシンプルアプリは SimpleMobileTools.com をご覧ください。\n</string>
<string name="save">保存</string>
<string name="share">共有</string>
<string name="share_via">共有...</string>
<string name="share_via">共有&#8230;</string>
<string name="cannot_share_empty_text">空のテキストは共有できません</string>
<string name="note_saved">テキストを保存しました</string>
<string name="simple_note">シンプル メモ</string>
<string name="new_note">Add a new note</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="no_title">Please name your note</string>
<string name="title_taken">A note with that title already exists</string>
<!-- Settings -->
<string name="settings">設定</string>

View File

@ -8,6 +8,11 @@
<string name="cannot_share_empty_text">Det går inte att dela utan text</string>
<string name="note_saved">Text sparad</string>
<string name="simple_note">Simple Note</string>
<string name="new_note">Add a new note</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="no_title">Please name your note</string>
<string name="title_taken">A note with that title already exists</string>
<!-- Settings -->
<string name="settings">Inställningar</string>

View File

@ -8,6 +8,11 @@
<string name="cannot_share_empty_text">Cannot share empty text</string>
<string name="note_saved">Note saved</string>
<string name="simple_note">Simple Note</string>
<string name="new_note">Add a new note</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="no_title">Please name your note</string>
<string name="title_taken">A note with that title already exists</string>
<!-- Settings -->
<string name="settings">Settings</string>