]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java
remove redundant type-cast
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / NewTransactionActivity.java
1 package net.ktnx.mobileledger;
2
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;
17
18 import java.util.Objects;
19
20 public class NewTransactionActivity extends AppCompatActivity {
21
22     @Override
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);
28
29         FloatingActionButton fab = findViewById(R.id.fab);
30         fab.setOnClickListener(new View.OnClickListener() {
31             @Override
32             public void onClick(View view) {
33                 Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
34                         .setAction("Action", null).show();
35             }
36         });
37         Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
38     }
39
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);
43
44         return true;
45     }
46
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();
52     }
53
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);
58         acc.setWidth(0);
59
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);
63         amt.setWidth(0);
64         amt.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL );
65         amt.setMinWidth(64);
66         amt.setTextAlignment(EditText.TEXT_ALIGNMENT_VIEW_END);
67
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));
71         row.addView(acc);
72         row.addView(amt);
73         table.addView(row);
74
75         acc.requestFocus();
76     }
77
78 }