Android Open Source - Thrift-box Input Fragment






From Project

Back to project page Thrift-box.

License

The source code is released under:

GNU General Public License

If you think the Android project Thrift-box listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ru.sash0k.thriftbox.fragments;
/* w w  w . j  av  a2 s .  c om*/
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import ru.sash0k.thriftbox.MainActivity;
import ru.sash0k.thriftbox.R;
import ru.sash0k.thriftbox.Utils;
import ru.sash0k.thriftbox.categories.Categories;
import ru.sash0k.thriftbox.database.DB;

/**
 * ???? ?????
 * Created by saash0k on 28.04.14.
 */
public class InputFragment extends Fragment {
    private static final String TAG = "InputFragment";

    private TextView valueTV;
    private TextView commentTV;
    private Categories categories;

    public static InputFragment newInstance() {
        return new InputFragment();
    }
    // ============================================================================

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
        return inflater.inflate(R.layout.fragment_input, container, false);
    }
    // ============================================================================

    @Override
    public void onActivityCreated(Bundle state) {
        super.onActivityCreated(state);
        final Activity context = getActivity();
        valueTV = (TextView) context.findViewById(R.id.enter_value);
        valueTV.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                final int DRAWABLE_RIGHT = 2;
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (event.getRawX() >= (valueTV.getRight() - valueTV.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                        cleanValues();
                        return true;
                    }
                }
                return false;
            }
        });
        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);
            commentTV.setVisibility(comment.length() == 0 ? View.GONE : View.VISIBLE);
        }
        Button enter = (Button) context.findViewById(R.id.enter_button);
        enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (valueTV != null) {
                    final String textValue = valueTV.getText().toString();
                    final int value = Utils.parseCurrency(textValue);
                    if (value > 0) {
                        final String comment = commentTV.getText().toString();
                        DB.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();
                }
            }
        });
    }
    // ============================================================================

    @Override
    public void onSaveInstanceState(Bundle state) {
        super.onSaveInstanceState(state);
        state.putCharSequence(DB.VALUE, valueTV.getText());
        state.putCharSequence(DB.COMMENT, commentTV.getText());
        state.putInt(DB.CATEGORY, categories.getSelected());
    }
    // ============================================================================


    /**
     * ????????? ??????? ???????????? ?? ???????
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CommentDialog.CODE) {
            if (resultCode == DialogInterface.BUTTON_POSITIVE) {
                final String comment = data.getStringExtra(CommentDialog.TAG);
                if ((comment != null) && (!comment.isEmpty())) {
                    commentTV.setVisibility(View.VISIBLE);
                    commentTV.setText(comment);
                }
            }
        }
    }
    // ============================================================================

    /**
     * ?????? ??????????????? ????????????
     * @param value - ????????
     */
    private void showCommentDialog(CharSequence value) {
        CommentDialog dialog = CommentDialog.newInstance(value);
        dialog.setTargetFragment(InputFragment.this, CommentDialog.CODE);
        dialog.show(getFragmentManager(), CommentDialog.TAG);
    }
    // ============================================================================


    /**
     * ????????? ???????? ????? ????? ? ????????????
     */
    private void cleanValues() {
        valueTV.setText("");
        commentTV.setText("");
        commentTV.setVisibility(View.GONE);
    }
    // ============================================================================

}




Java Source Code List

android.support.v4.preference.PreferenceFragment.java
android.support.v4.preference.PreferenceManagerCompat.java
android.widget_fixed.CursorFilter.java
android.widget_fixed.CursorTreeAdapter.java
com.github.mikephil.charting.charts.Chart.java
com.github.mikephil.charting.charts.PieChart.java
com.github.mikephil.charting.charts.PieRadarChartBase.java
com.github.mikephil.charting.data.ChartData.java
com.github.mikephil.charting.data.DataSet.java
com.github.mikephil.charting.data.Entry.java
com.github.mikephil.charting.data.PieDataSet.java
com.github.mikephil.charting.data.PieData.java
com.github.mikephil.charting.data.filter.Approximator.java
com.github.mikephil.charting.exception.DrawingDataSetNotCreatedException.java
com.github.mikephil.charting.interfaces.ChartInterface.java
com.github.mikephil.charting.interfaces.OnChartGestureListener.java
com.github.mikephil.charting.interfaces.OnChartValueSelectedListener.java
com.github.mikephil.charting.interfaces.OnDrawLineChartTouchListener.java
com.github.mikephil.charting.interfaces.OnDrawListener.java
com.github.mikephil.charting.listener.PieRadarChartTouchListener.java
com.github.mikephil.charting.matrix.Vector3.java
com.github.mikephil.charting.renderer.Transformer.java
com.github.mikephil.charting.utils.ColorFormatter.java
com.github.mikephil.charting.utils.ColorTemplate.java
com.github.mikephil.charting.utils.Highlight.java
com.github.mikephil.charting.utils.LabelBase.java
com.github.mikephil.charting.utils.LargeValueFormatter.java
com.github.mikephil.charting.utils.Legend.java
com.github.mikephil.charting.utils.LimitLine.java
com.github.mikephil.charting.utils.MarkerView.java
com.github.mikephil.charting.utils.PointD.java
com.github.mikephil.charting.utils.SelInfo.java
com.github.mikephil.charting.utils.Utils.java
com.github.mikephil.charting.utils.ValueFormatter.java
com.github.mikephil.charting.utils.XLabels.java
com.github.mikephil.charting.utils.YLabels.java
net.margaritov.preference.colorpicker.AlphaPatternDrawable.java
net.margaritov.preference.colorpicker.ColorPickerDialog.java
net.margaritov.preference.colorpicker.ColorPickerPanelView.java
net.margaritov.preference.colorpicker.ColorPickerPreference.java
net.margaritov.preference.colorpicker.ColorPickerView.java
ru.sash0k.thriftbox.AdapterExpenses.java
ru.sash0k.thriftbox.MainActivity.java
ru.sash0k.thriftbox.TypefaceSpan2.java
ru.sash0k.thriftbox.Utils.java
ru.sash0k.thriftbox.Widget.java
ru.sash0k.thriftbox.categories.Categories.java
ru.sash0k.thriftbox.categories.InterceptingHorizontalScrollView.java
ru.sash0k.thriftbox.database.DBProvider.java
ru.sash0k.thriftbox.database.DB.java
ru.sash0k.thriftbox.fragments.CommentDialog.java
ru.sash0k.thriftbox.fragments.DeleteConfirmDialog.java
ru.sash0k.thriftbox.fragments.ExpandableListFragment.java
ru.sash0k.thriftbox.fragments.ExpensesFragment.java
ru.sash0k.thriftbox.fragments.InputFragment.java
ru.sash0k.thriftbox.fragments.PieChartFragment.java
ru.sash0k.thriftbox.fragments.SettingsFragment.java