Search in sources :

Example 1 with MainActivity

use of ru.sash0k.thriftbox.MainActivity in project Thrift-box by Sash0k.

the class InputFragment method onActivityCreated.

// ============================================================================
@Override
public void onActivityCreated(Bundle state) {
    super.onActivityCreated(state);
    final Activity context = getActivity();
    Toolbar toolbar = (Toolbar) context.findViewById(R.id.toolbar);
    valueTV = (TextView) toolbar.findViewById(R.id.enter_value);
    valueTV.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (view instanceof TextView && ((TextView) view).length() != 0) {
                showCommentDialog(commentTV.getText());
            }
        }
    });
    commentTV = (TextView) context.findViewById(R.id.comment_value);
    commentTV.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            showCommentDialog(((TextView) view).getText());
        }
    });
    categories = (Categories) context.findViewById(R.id.categories);
    if (state != null) {
        categories.setSelected(state.getInt(DB.CATEGORY));
        valueTV.setText(state.getCharSequence(DB.VALUE));
        CharSequence comment = state.getCharSequence(DB.COMMENT);
        commentTV.setText(comment);
    }
    FloatingActionButton fab = (FloatingActionButton) context.findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            enterValue(context);
        }
    });
    // обработка длинного нажатия
    ImageButton clear = (ImageButton) context.findViewById(R.id.del);
    clear.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            ((MainActivity) context).clearAnimation(view);
            return true;
        }
    });
}
Also used : ImageButton(android.widget.ImageButton) MainActivity(ru.sash0k.thriftbox.MainActivity) Activity(android.app.Activity) FloatingActionButton(com.melnykov.fab.FloatingActionButton) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with MainActivity

use of ru.sash0k.thriftbox.MainActivity in project Thrift-box by Sash0k.

the class InputFragment method enterValue.

// ============================================================================
private void enterValue(Context context) {
    if (valueTV != null) {
        final String textValue = valueTV.getText().toString();
        final int value = Utils.parseCurrency(textValue);
        if (value > 0) {
            final String comment = commentTV.getText().toString();
            new DB(context).insertItem(context, value, categories.getSelected(), comment);
            Toast.makeText(context, ((MainActivity) context).parseRouble(getString(R.string.enter_value_done) + " " + textValue + Utils.ROUBLE + " " + comment), Toast.LENGTH_SHORT).show();
            cleanValues();
            Utils.updateWidgets(context);
        } else
            Toast.makeText(context, getString(R.string.enter_value_invalid), Toast.LENGTH_SHORT).show();
    }
}
Also used : MainActivity(ru.sash0k.thriftbox.MainActivity) DB(ru.sash0k.thriftbox.database.DB)

Aggregations

MainActivity (ru.sash0k.thriftbox.MainActivity)2 Activity (android.app.Activity)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 TextView (android.widget.TextView)1 FloatingActionButton (com.melnykov.fab.FloatingActionButton)1 DB (ru.sash0k.thriftbox.database.DB)1