1 package net.ktnx.mobileledger;
3 import android.os.Bundle;
4 import android.support.design.widget.FloatingActionButton;
5 import android.support.design.widget.Snackbar;
6 import android.support.v4.app.DialogFragment;
7 import android.support.v7.app.AppCompatActivity;
8 import android.support.v7.widget.Toolbar;
9 import android.text.InputType;
10 import android.view.Menu;
11 import android.view.MenuItem;
12 import android.view.View;
13 import android.widget.AutoCompleteTextView;
14 import android.widget.EditText;
15 import android.widget.TableLayout;
16 import android.widget.TableRow;
18 import java.util.Objects;
20 public class NewTransactionActivity extends AppCompatActivity {
23 protected void onCreate(Bundle savedInstanceState) {
24 super.onCreate(savedInstanceState);
25 setContentView(R.layout.activity_new_transaction);
26 Toolbar toolbar = findViewById(R.id.toolbar);
27 setSupportActionBar(toolbar);
29 FloatingActionButton fab = findViewById(R.id.fab);
30 fab.setOnClickListener(new View.OnClickListener() {
32 public void onClick(View view) {
33 Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
34 .setAction("Action", null).show();
37 Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
40 public boolean onCreateOptionsMenu(Menu menu) {
41 // Inflate the menu; this adds items to the action bar if it is present.
42 getMenuInflater().inflate(R.menu.new_transaction, menu);
47 public void pickTransactionDate(View view) {
48 DialogFragment picker = new DatePickerFragment();
49 picker.show(getSupportFragmentManager(), "datePicker");
50 // Snackbar.make(view, "Date editing not yet ready", Snackbar.LENGTH_LONG)
51 // .setAction("Action", null).show();
54 public void addTransactionAccountFromMenu(MenuItem item) {
55 final AutoCompleteTextView acc = new AutoCompleteTextView(this);
56 acc.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 9f));
57 acc.setHint(R.string.new_transaction_account_hint);
60 final EditText amt = new EditText(this);
61 amt.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
62 amt.setHint(R.string.new_transaction_amount_hint);
64 amt.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL );
66 amt.setTextAlignment(EditText.TEXT_ALIGNMENT_VIEW_END);
68 final TableLayout table = findViewById(R.id.new_transaction_accounts_table);
69 final TableRow row = new TableRow(this);
70 row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));