Android Open Source - Thrift-box Main Activity






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;
//www.ja  va2  s  .co  m
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.SpannableStringBuilder;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.viewpagerindicator.PageIndicator;

import ru.sash0k.thriftbox.fragments.ExpensesFragment;
import ru.sash0k.thriftbox.fragments.InputFragment;
import ru.sash0k.thriftbox.fragments.PieChartFragment;
import ru.sash0k.thriftbox.fragments.SettingsFragment;

public class MainActivity extends FragmentActivity {
    private static Typeface roubleSupportedTypeface;

    SectionsPagerAdapter mSectionsPagerAdapter;
    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        roubleSupportedTypeface = Typeface.createFromAsset(getAssets(), Utils.ROUBLE_FONT);
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setCurrentItem(1);
        PageIndicator indicator = (PageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(mViewPager);
    }
    // ============================================================================

    /**
     * ???? ??????
     */
    private void keyboardClick(String digit) {
        TextView valueTV = (TextView) mViewPager.findViewById(R.id.enter_value);
        if (valueTV != null) {
            String query = valueTV.getText().toString();
            if (getString(R.string.backspace).equals(digit)) {
                final int len = query.length() - 1;
                query = query.substring(0, (len < 0) ? 0 : len);
                if (len == 0) {
                    TextView commentTV = (TextView) mViewPager.findViewById(R.id.comment_value);
                    commentTV.setText("");
                    commentTV.setVisibility(View.GONE);
                }
            } else query += digit;
            valueTV.setText(query);
        }
    }
    // ============================================================================

    /**
     * ????????? ????? ??????????? ??????????
     */
    public void virtualKeyboardClick(View view) {
        final String digit = view.getTag().toString();
        keyboardClick(digit);
    }
    // ============================================================================

    /**
     * ????????? ????? ?????????? ??????????
     */
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_0:
                keyboardClick(getString(R.string.zero));
                return true;
            case KeyEvent.KEYCODE_1:
                keyboardClick(getString(R.string.one));
                return true;
            case KeyEvent.KEYCODE_2:
                keyboardClick(getString(R.string.two));
                return true;
            case KeyEvent.KEYCODE_3:
                keyboardClick(getString(R.string.three));
                return true;
            case KeyEvent.KEYCODE_4:
                keyboardClick(getString(R.string.four));
                return true;
            case KeyEvent.KEYCODE_5:
                keyboardClick(getString(R.string.five));
                return true;
            case KeyEvent.KEYCODE_6:
                keyboardClick(getString(R.string.six));
                return true;
            case KeyEvent.KEYCODE_7:
                keyboardClick(getString(R.string.seven));
                return true;
            case KeyEvent.KEYCODE_8:
                keyboardClick(getString(R.string.eight));
                return true;
            case KeyEvent.KEYCODE_9:
                keyboardClick(getString(R.string.nine));
                return true;
            case KeyEvent.KEYCODE_PERIOD:
                keyboardClick(getString(R.string.dot));
                return true;
            case KeyEvent.KEYCODE_DEL:
                keyboardClick(getString(R.string.backspace));
                return true;
            default:
                return super.onKeyUp(keyCode, keyEvent);
        }
    }
    // ============================================================================

    /**
     * ??????????? ???????? ?????? ?? ??????????? ??????
     */
    public SpannableStringBuilder parseRouble(CharSequence value) {
        if (roubleSupportedTypeface == null) return null;
        else {
            SpannableStringBuilder resultSpan = new SpannableStringBuilder(value);
            for (int i = 0; i < resultSpan.length(); i++) {
                if (resultSpan.charAt(i) == Utils.ROUBLE) {
                    TypefaceSpan2 roubleTypefaceSpan = new TypefaceSpan2(roubleSupportedTypeface);
                    resultSpan.setSpan(roubleTypefaceSpan, i, i + 1, 0);
                }
            }
            return resultSpan;
        }
    }
    // ============================================================================

    /**
     * A {@link android.support.v4.app.FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentStatePagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return PieChartFragment.newInstance();
                case 1:
                    return InputFragment.newInstance();
                case 2:
                    return ExpensesFragment.newInstance();
                default:
                    return SettingsFragment.newInstance();
            }
        }

        @Override
        public int getCount() {
            return 4;
        }
    }
}




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