Android Open Source - Thrift-box Categories






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.categories;
//w w  w .java  2s. c o  m
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import ru.sash0k.thriftbox.R;
import ru.sash0k.thriftbox.Utils;


/**
 * ???????, ??????????? ???????? ?????????
 *
 * @author sash0k
 */
public class Categories extends LinearLayout {

    /**
     * ??????????? ????????
     */
    // ============================================================================
    private static final int[] mImages = {R.drawable.star,
            R.drawable.trolley, R.drawable.filling, R.drawable.transport, R.drawable.restaurants,
            R.drawable.culture, R.drawable.shopping, R.drawable.mobile,
            R.drawable.housing, R.drawable.family, R.drawable.medicine, R.drawable.air};

    private final String[] categories;
    private final Context mContext;

    // ????????? ????????????
    final static int pic_width = 48;
    final static int pic_height = 48;
    final static int padding = 4;
    final static int selection_color = Color.rgb(0xFB, 0xD2, 0xB5);

    private int getPx(int value) {
        final float scale = getResources().getDisplayMetrics().density;
        return (int) ((float) value * scale + 0.5f);
    }
    // ============================================================================

    private int selected = -1;

    public int getSelected() {
        return selected;
    }

    public void setSelected(int position) {
        if (position != selected) {
            Utils.log("Categories: select " + position);
            unselect(selected);
            select(position);
            selected = position;
        }
    }

    /**
     * ????????????? ????????
     *
     * @param context
     */
    // ============================================================================
    public Categories(Context context) {
        super(context);
        mContext = context;
        categories = context.getResources().getStringArray(R.array.categories);
        build();
    }

    public Categories(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        categories = context.getResources().getStringArray(R.array.categories);
        build();
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public Categories(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
        categories = context.getResources().getStringArray(R.array.categories);
        build();
    }
    // ============================================================================

    /**
     * ????? ???????? ????? ????????
     */
    // ============================================================================
    private void build() {
        for (int i = 0; i < mImages.length; i++)
            addView(getImageView(i));
        setSelected(0);
    }

    // ============================================================================

    /**
     * ????????? ???????????? ?? ????????
     *
     * @param position - ????? ???????????? ? ?????????
     * @return - ImageView
     */
    // ============================================================================
    ImageView getImageView(int position) {
        final ImageView imageView = new ImageView(mContext);
        imageView.setLayoutParams(new LayoutParams(getPx(pic_width), getPx(pic_height)));
        //imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        final int px = getPx(padding);
        imageView.setPadding(px, px, px, px);
        imageView.setTag(position);
        imageView.setImageResource(mImages[position]);
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                //v.setBackgroundColor(selection_color);
                setSelected((Integer) view.getTag());
            }
        });

        imageView.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                Toast.makeText(mContext, categories[(Integer)view.getTag()], Toast.LENGTH_SHORT).show();
                return false;
            }
        });

        return imageView;
    }
    // ============================================================================

    private void unselect(int position) {
        View v = findViewWithTag(position);
        if (v != null) v.setBackgroundColor(Color.TRANSPARENT);
    }
    // ============================================================================

    private void select(int position) {
        View v = findViewWithTag(position);
        if (v != null) v.setBackgroundColor(selection_color);
    }
    // ============================================================================

}




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