Search in sources :

Example 6 with Snackbar

use of com.nispok.snackbar.Snackbar in project snackbar by nispok.

the class SnackbarSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    Button singleLineButton = (Button) findViewById(R.id.single_line);
    singleLineButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("Single-line snackbar"));
        }
    });
    Button singleLineWithActionButton = (Button) findViewById(R.id.single_line_with_action);
    singleLineWithActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("Something has been done").actionLabel("Undo").swipeListener(new ActionSwipeListener() {

                @Override
                public void onSwipeToDismiss() {
                    Toast.makeText(SnackbarSampleActivity.this, "swipe to dismiss", Toast.LENGTH_SHORT).show();
                }
            }).actionListener(new ActionClickListener() {

                @Override
                public void onActionClicked(Snackbar snackbar) {
                    Toast.makeText(SnackbarSampleActivity.this, "Action undone", Toast.LENGTH_SHORT).show();
                }
            }));
        }
    });
    Button multiLineButton = (Button) findViewById(R.id.multi_line);
    multiLineButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).type(SnackbarType.MULTI_LINE).text("This is a multi-line snackbar. Keep in mind that snackbars" + " are meant for VERY short messages"));
        }
    });
    Button multiLineWithActionButton = (Button) findViewById(R.id.multi_line_with_action);
    multiLineWithActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).type(SnackbarType.MULTI_LINE).text("This is a multi-line snackbar with an action button. Note " + "that multi-line snackbars are 2 lines max").actionLabel("Action").actionListener(new ActionClickListener() {

                @Override
                public void onActionClicked(Snackbar snackbar) {
                    Toast.makeText(SnackbarSampleActivity.this, "Action clicked", Toast.LENGTH_SHORT).show();
                }
            }));
        }
    });
    Button noAnimationButton = (Button) findViewById(R.id.no_animation);
    noAnimationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("No animation :(").animation(false).duration(2500l));
        }
    });
    Button eventListenerButton = (Button) findViewById(R.id.event_listener);
    eventListenerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("I'm showing a toast on exit").eventListener(new EventListener() {

                @Override
                public void onShow(Snackbar snackbar) {
                    Log.i(TAG, String.format("Snackbar will show. Width: %d Height: %d Offset: %d", snackbar.getWidth(), snackbar.getHeight(), snackbar.getOffset()));
                }

                @Override
                public void onShowByReplace(Snackbar snackbar) {
                    Log.i(TAG, String.format("Snackbar will show by replace. Width: %d Height: %d Offset: %d", snackbar.getWidth(), snackbar.getHeight(), snackbar.getOffset()));
                }

                @Override
                public void onShown(Snackbar snackbar) {
                    Log.i(TAG, String.format("Snackbar shown. Width: %d Height: %d Offset: %d", snackbar.getWidth(), snackbar.getHeight(), snackbar.getOffset()));
                }

                @Override
                public void onDismiss(Snackbar snackbar) {
                    Log.i(TAG, String.format("Snackbar will dismiss. Width: %d Height: %d Offset: %d", snackbar.getWidth(), snackbar.getHeight(), snackbar.getOffset()));
                }

                @Override
                public void onDismissByReplace(Snackbar snackbar) {
                    Log.i(TAG, String.format("Snackbar will dismiss by replace. Width: %d Height: %d Offset: %d", snackbar.getWidth(), snackbar.getHeight(), snackbar.getOffset()));
                }

                @Override
                public void onDismissed(Snackbar snackbar) {
                    Toast.makeText(SnackbarSampleActivity.this, String.format("Snackbar dismissed. Width: %d Height: %d Offset: %d", snackbar.getWidth(), snackbar.getHeight(), snackbar.getOffset()), Toast.LENGTH_SHORT).show();
                }
            }));
        }
    });
    Button customColorsButton = (Button) findViewById(R.id.custom_colors);
    customColorsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("Different colors!!!").textColor(Color.parseColor("#ff9d9d9c")).color(Color.parseColor("#ff914300")).actionLabel("Action").actionColor(Color.parseColor("#ff5a2900")).actionListener(new ActionClickListener() {

                @Override
                public void onActionClicked(Snackbar snackbar) {
                    Log.i(TAG, "Action touched");
                }
            }).duration(Snackbar.SnackbarDuration.LENGTH_SHORT));
        }
    });
    Button unswipeableButton = (Button) findViewById(R.id.unswipeable);
    unswipeableButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("Try to swipe me off from the screen").swipeToDismiss(false));
        }
    });
    Button indefiniteButton = (Button) findViewById(R.id.indefinite);
    indefiniteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE).text("Indefinite duration, ideal for communicating errors"));
        }
    });
    Button listSampleButton = (Button) findViewById(R.id.list_example);
    listSampleButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent sampleIntent = new Intent(SnackbarSampleActivity.this, SnackbarListViewSampleActivity.class);
            startActivity(sampleIntent);
        }
    });
    Button recyclerSampleButton = (Button) findViewById(R.id.recycler_example);
    recyclerSampleButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent sampleIntent = new Intent(SnackbarSampleActivity.this, SnackbarRecyclerViewSampleActivity.class);
            startActivity(sampleIntent);
        }
    });
    Button customTypefaceButton = (Button) findViewById(R.id.typeface_example);
    customTypefaceButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-LightItalic.ttf");
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("Custom font!").textTypeface(tf).actionLabel("Cool").actionLabelTypeface(tf));
        }
    });
    Button navigationBarTranslucentButton = (Button) findViewById(R.id.navigation_bar_translucent);
    navigationBarTranslucentButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SnackbarNavigationBarTranslucentSampleActivity.isTranslucentSystemBarsCapable()) {
                Intent sampleIntent = new Intent(SnackbarSampleActivity.this, SnackbarNavigationBarTranslucentSampleActivity.class);
                startActivity(sampleIntent);
            } else {
                Toast.makeText(SnackbarSampleActivity.this, "Translucent System bars only available for KITKAT or newer", Toast.LENGTH_SHORT).show();
            }
        }
    });
    Button immersiveModeButton = (Button) findViewById(R.id.immersive_mode_example);
    immersiveModeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SnackbarImmersiveModeSampleActivity.isImmersiveModeCapable()) {
                Intent sampleIntent = new Intent(SnackbarSampleActivity.this, SnackbarImmersiveModeSampleActivity.class);
                startActivity(sampleIntent);
            } else {
                Toast.makeText(SnackbarSampleActivity.this, "Immersive mode only available for KITKAT or newer", Toast.LENGTH_SHORT).show();
            }
        }
    });
    Button showInDialogButton = (Button) findViewById(R.id.show_in_dialog_example);
    showInDialogButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent sampleIntent = new Intent(SnackbarSampleActivity.this, SnackbarShowInDialogSampleActivity.class);
            startActivity(sampleIntent);
        }
    });
    Button singleLineMarginsButton = (Button) findViewById(R.id.single_line_margins);
    singleLineMarginsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).margin(25).text("Single-line Margins"));
        }
    });
    Button singleLineTopButton = (Button) findViewById(R.id.single_line_top);
    singleLineTopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).position(Snackbar.SnackbarPosition.TOP).text("Single-line Top"));
        }
    });
    Button singleLineButtonInside = (Button) findViewById(R.id.single_line_inside);
    singleLineButtonInside.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).text("Single-line Inside RelativeLayout"), (android.view.ViewGroup) findViewById(R.id.view_relative_layout));
        }
    });
    Button singleLineTopButtonInside = (Button) findViewById(R.id.single_line_top_inside);
    singleLineTopButtonInside.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).position(Snackbar.SnackbarPosition.TOP).margin(25, 15).text("Single-line TOP Inside LinearLayout"), (android.view.ViewGroup) findViewById(R.id.view_linear_layout));
        }
    });
    Button singleLineButtonCustomShape = (Button) findViewById(R.id.single_line_shape);
    singleLineButtonCustomShape.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SnackbarManager.show(Snackbar.with(SnackbarSampleActivity.this).position(Snackbar.SnackbarPosition.TOP).margin(15, 15).backgroundDrawable(R.drawable.custom_shape).text("Single-line Custom Shape"));
        }
    });
}
Also used : Typeface(android.graphics.Typeface) ActionSwipeListener(com.nispok.snackbar.listeners.ActionSwipeListener) Intent(android.content.Intent) View(android.view.View) ActionClickListener(com.nispok.snackbar.listeners.ActionClickListener) Button(android.widget.Button) EventListener(com.nispok.snackbar.listeners.EventListener) Snackbar(com.nispok.snackbar.Snackbar)

Example 7 with Snackbar

use of com.nispok.snackbar.Snackbar in project CoCoin by Nightonke.

the class AccountBookListViewActivity method activityOnItemRemoved.

private void activityOnItemRemoved(int position) {
    if (RecordManager.SELECTED_RECORDS.size() == 0) {
        emptyTip.setVisibility(View.VISIBLE);
        verticalRecyclerViewFastScroller.setVisibility(View.INVISIBLE);
    }
    lastPosition = RecordManager.SELECTED_RECORDS.size() - position;
    undid = false;
    Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(-3)).text(mContext.getResources().getString(R.string.deleting)).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.undo)).actionColor(Color.WHITE).actionListener(new ActionClickListener() {

        @Override
        public void onActionClicked(Snackbar snackbar) {
            RecordManager.SELECTED_RECORDS.add(lastPosition, CoCoinUtil.backupCoCoinRecord);
            RecordManager.SELECTED_SUM += CoCoinUtil.backupCoCoinRecord.getMoney();
            changeTitleSlider();
            CoCoinUtil.backupCoCoinRecord = null;
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
            int firstVisiblePosition = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
            int lastVisiblePosition = linearLayoutManager.findLastCompletelyVisibleItemPosition();
            final int insertPosition = RecordManager.SELECTED_RECORDS.size() - 1 - lastPosition;
            if (firstVisiblePosition < insertPosition && insertPosition <= lastVisiblePosition) {
            } else {
                recyclerView.scrollToPosition(insertPosition);
            }
            mAdapter.notifyItemInserted(insertPosition);
            mAdapter.notifyDataSetChanged();
            if (RecordManager.SELECTED_RECORDS.size() != 0) {
                emptyTip.setVisibility(View.GONE);
                verticalRecyclerViewFastScroller.setVisibility(View.VISIBLE);
            }
        }
    }).eventListener(new EventListener() {

        @Override
        public void onShow(Snackbar snackbar) {
        }

        @Override
        public void onShowByReplace(Snackbar snackbar) {
        }

        @Override
        public void onShown(Snackbar snackbar) {
        }

        @Override
        public void onDismiss(Snackbar snackbar) {
            if (CoCoinUtil.backupCoCoinRecord != null) {
                RecordManager.deleteRecord(CoCoinUtil.backupCoCoinRecord, true);
            }
            CoCoinUtil.backupCoCoinRecord = null;
        }

        @Override
        public void onDismissByReplace(Snackbar snackbar) {
            if (CoCoinUtil.backupCoCoinRecord != null) {
                RecordManager.deleteRecord(CoCoinUtil.backupCoCoinRecord, true);
            }
            CoCoinUtil.backupCoCoinRecord = null;
        }

        @Override
        public void onDismissed(Snackbar snackbar) {
            if (CoCoinUtil.backupCoCoinRecord != null) {
                RecordManager.deleteRecord(CoCoinUtil.backupCoCoinRecord, true);
            }
            CoCoinUtil.backupCoCoinRecord = null;
        }
    });
    SnackbarManager.show(snackbar);
}
Also used : EventListener(com.nispok.snackbar.listeners.EventListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ActionClickListener(com.nispok.snackbar.listeners.ActionClickListener) Snackbar(com.nispok.snackbar.Snackbar)

Example 8 with Snackbar

use of com.nispok.snackbar.Snackbar in project CoCoin by Nightonke.

the class TodayViewRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
    switch(getItemViewType(position)) {
        case TYPE_HEADER:
            holder.date.setText(dateString);
            holder.dateBottom.setText(dateString);
            holder.expanseSum.setText(CoCoinUtil.GetInMoney((int) Sum));
            holder.date.setTypeface(CoCoinUtil.GetTypeface());
            holder.dateBottom.setTypeface(CoCoinUtil.GetTypeface());
            holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
            if (IS_EMPTY) {
                holder.emptyTip.setVisibility(View.VISIBLE);
                holder.emptyTip.setText(CoCoinUtil.GetTodayViewEmptyTip(fragmentPosition));
                holder.emptyTip.setTypeface(CoCoinUtil.GetTypeface());
                holder.reset.setVisibility(View.GONE);
                holder.pie.setVisibility(View.GONE);
                holder.iconLeft.setVisibility(View.GONE);
                holder.iconRight.setVisibility(View.GONE);
                holder.histogram.setVisibility(View.GONE);
                holder.histogram_icon_left.setVisibility(View.GONE);
                holder.histogram_icon_right.setVisibility(View.GONE);
                holder.all.setVisibility(View.GONE);
                holder.dateBottom.setVisibility(View.GONE);
            } else {
                holder.emptyTip.setVisibility(View.GONE);
                final ArrayList<SliceValue> sliceValues = new ArrayList<>();
                for (Map.Entry<Integer, Double> entry : TagExpanse.entrySet()) {
                    if (entry.getValue() >= 1) {
                        SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), mContext.getApplicationContext().getResources().getColor(CoCoinUtil.GetTagColorResource(entry.getKey())));
                        sliceValue.setLabel(String.valueOf(entry.getKey()));
                        sliceValues.add(sliceValue);
                    }
                }
                final PieChartData pieChartData = new PieChartData(sliceValues);
                pieChartData.setHasLabels(false);
                pieChartData.setHasLabelsOnlyForSelected(false);
                pieChartData.setHasLabelsOutside(false);
                pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
                holder.pie.setPieChartData(pieChartData);
                holder.pie.setChartRotationEnabled(false);
                // two control button of pie////////////////////////////////////////////////////////////////////////
                holder.iconRight.setVisibility(View.VISIBLE);
                holder.iconRight.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (lastPieSelectedPosition != -1) {
                            pieSelectedPosition = lastPieSelectedPosition;
                        }
                        pieSelectedPosition = (pieSelectedPosition - 1 + sliceValues.size()) % sliceValues.size();
                        SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                        holder.pie.selectValue(selectedValue);
                    }
                });
                holder.iconLeft.setVisibility(View.VISIBLE);
                holder.iconLeft.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (lastPieSelectedPosition != -1) {
                            pieSelectedPosition = lastPieSelectedPosition;
                        }
                        pieSelectedPosition = (pieSelectedPosition + 1) % sliceValues.size();
                        SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                        holder.pie.selectValue(selectedValue);
                    }
                });
                final List<Column> columns = new ArrayList<>();
                final ColumnChartData columnChartData = new ColumnChartData(columns);
                if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                    for (int i = 0; i < columnNumber; i++) {
                        if (lastHistogramSelectedPosition == -1 && originalTargets[i] == 0) {
                            lastHistogramSelectedPosition = i;
                        }
                        SubcolumnValue value = new SubcolumnValue(originalTargets[i], CoCoinUtil.GetRandomColor());
                        List<SubcolumnValue> subcolumnValues = new ArrayList<>();
                        subcolumnValues.add(value);
                        Column column = new Column(subcolumnValues);
                        column.setHasLabels(false);
                        column.setHasLabelsOnlyForSelected(false);
                        columns.add(column);
                    }
                    Axis axisX = new Axis();
                    List<AxisValue> axisValueList = new ArrayList<>();
                    for (int i = 0; i < columnNumber; i++) {
                        axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetAxisDateName(axis_date, i)));
                    }
                    axisX.setValues(axisValueList);
                    Axis axisY = new Axis().setHasLines(true);
                    columnChartData.setAxisXBottom(axisX);
                    columnChartData.setAxisYLeft(axisY);
                    columnChartData.setStacked(true);
                    holder.histogram.setColumnChartData(columnChartData);
                    holder.histogram.setZoomEnabled(false);
                    // two control button of histogram//////////////////////////////////////////////////////////////////
                    holder.histogram_icon_left.setVisibility(View.VISIBLE);
                    holder.histogram_icon_left.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                lastHistogramSelectedPosition = (lastHistogramSelectedPosition - 1 + columnNumber) % columnNumber;
                            } while (columnChartData.getColumns().get(lastHistogramSelectedPosition).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(lastHistogramSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                            holder.histogram.selectValue(selectedValue);
                        }
                    });
                    holder.histogram_icon_right.setVisibility(View.VISIBLE);
                    holder.histogram_icon_right.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                lastHistogramSelectedPosition = (lastHistogramSelectedPosition + 1) % columnNumber;
                            } while (columnChartData.getColumns().get(lastHistogramSelectedPosition).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(lastHistogramSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                            holder.histogram.selectValue(selectedValue);
                        }
                    });
                }
                if (fragmentPosition == TODAY || fragmentPosition == YESTERDAY) {
                    holder.histogram_icon_left.setVisibility(View.INVISIBLE);
                    holder.histogram_icon_right.setVisibility(View.INVISIBLE);
                    holder.histogram.setVisibility(View.GONE);
                    holder.dateBottom.setVisibility(View.GONE);
                    holder.reset.setVisibility(View.GONE);
                }
                // set value touch listener of pie//////////////////////////////////////////////////////////////////
                holder.pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {

                    @Override
                    public void onValueSelected(int p, SliceValue sliceValue) {
                        // snack bar
                        RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
                        String text;
                        tagId = Integer.valueOf(String.valueOf(sliceValue.getLabelAsChars()));
                        double percent = sliceValue.getValue() / Sum * 100;
                        if ("zh".equals(CoCoinUtil.GetLanguage())) {
                            text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + CoCoinUtil.GetPercentString(percent) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
                        } else {
                            text = "Spend " + (int) sliceValue.getValue() + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
                        }
                        if ("zh".equals(CoCoinUtil.GetLanguage())) {
                            dialogTitle = dateShownString + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
                        } else {
                            dialogTitle = "Spend " + (int) sliceValue.getValue() + dateShownString + "\n" + "in " + CoCoinUtil.GetTagName(tagId);
                        }
                        Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(fragmentPosition - 2)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForPie());
                        SnackbarManager.show(snackbar);
                        if (p == lastPieSelectedPosition) {
                            return;
                        } else {
                            lastPieSelectedPosition = p;
                        }
                        if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                            // histogram data///////////////////////////////////////////////////////////////////////////////////
                            float[] targets = new float[columnNumber];
                            for (int i = 0; i < columnNumber; i++) targets[i] = 0;
                            for (int i = Expanse.get(tagId).size() - 1; i >= 0; i--) {
                                CoCoinRecord coCoinRecord = Expanse.get(tagId).get(i);
                                if (axis_date == Calendar.DAY_OF_WEEK) {
                                    if (CoCoinUtil.WEEK_START_WITH_SUNDAY) {
                                        targets[coCoinRecord.getCalendar().get(axis_date) - 1] += coCoinRecord.getMoney();
                                    } else {
                                        targets[(coCoinRecord.getCalendar().get(axis_date) + 5) % 7] += coCoinRecord.getMoney();
                                    }
                                } else if (axis_date == Calendar.DAY_OF_MONTH) {
                                    targets[coCoinRecord.getCalendar().get(axis_date) - 1] += coCoinRecord.getMoney();
                                } else {
                                    targets[coCoinRecord.getCalendar().get(axis_date)] += coCoinRecord.getMoney();
                                }
                            }
                            lastHistogramSelectedPosition = -1;
                            for (int i = 0; i < columnNumber; i++) {
                                if (lastHistogramSelectedPosition == -1 && targets[i] != 0) {
                                    lastHistogramSelectedPosition = i;
                                }
                                columnChartData.getColumns().get(i).getValues().get(0).setTarget(targets[i]);
                            }
                            holder.histogram.startDataAnimation();
                        }
                    }

                    @Override
                    public void onValueDeselected() {
                    }
                });
                if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                    // set value touch listener of histogram////////////////////////////////////////////////////////////
                    holder.histogram.setOnValueTouchListener(new ColumnChartOnValueSelectListener() {

                        @Override
                        public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
                            lastHistogramSelectedPosition = columnIndex;
                            timeIndex = columnIndex;
                            // snack bar
                            RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
                            String text = CoCoinUtil.GetSpendString((int) value.getValue());
                            if (tagId != -1)
                                // belongs a tag
                                if ("zh".equals(CoCoinUtil.GetLanguage()))
                                    text = getSnackBarDateString() + text + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
                                else
                                    text += getSnackBarDateString() + "\n" + "in " + CoCoinUtil.GetTagName(tagId);
                            else // don't belong to any tag
                            if ("zh".equals(CoCoinUtil.GetLanguage()))
                                text = getSnackBarDateString() + "\n" + text;
                            else
                                text += "\n" + getSnackBarDateString();
                            // setting the snack bar and dialog title of histogram//////////////////////////////////////////////
                            dialogTitle = text;
                            Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(fragmentPosition - 2)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForHistogram());
                            SnackbarManager.show(snackbar);
                        }

                        @Override
                        public void onValueDeselected() {
                        }
                    });
                }
                // set the listener of the reset button/////////////////////////////////////////////////////////////
                if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                    holder.reset.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            tagId = -1;
                            lastHistogramSelectedPosition = -1;
                            for (int i = 0; i < columnNumber; i++) {
                                if (lastHistogramSelectedPosition == -1 && originalTargets[i] != 0) {
                                    lastHistogramSelectedPosition = i;
                                }
                                columnChartData.getColumns().get(i).getValues().get(0).setTarget(originalTargets[i]);
                            }
                            holder.histogram.startDataAnimation();
                        }
                    });
                }
                // set the listener of the show all button//////////////////////////////////////////////////////////
                holder.all.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, allData, getAllDataDialogTitle()), "MyDialog").commit();
                    }
                });
            }
            break;
        case TYPE_BODY:
            holder.tagImage.setImageResource(CoCoinUtil.GetTagIcon(allData.get(position - 1).getTag()));
            holder.money.setText((int) allData.get(position - 1).getMoney() + "");
            holder.money.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.cell_date.setText(allData.get(position - 1).getCalendarString());
            holder.cell_date.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.remark.setText(allData.get(position - 1).getRemark());
            holder.remark.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.index.setText(position + "");
            holder.index.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.layout.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String subTitle;
                    double spend = allData.get(position - 1).getMoney();
                    int tagId = allData.get(position - 1).getTag();
                    if ("zh".equals(CoCoinUtil.GetLanguage())) {
                        subTitle = CoCoinUtil.GetSpendString((int) spend) + "于" + CoCoinUtil.GetTagName(tagId);
                    } else {
                        subTitle = "Spend " + (int) spend + "in " + CoCoinUtil.GetTagName(tagId);
                    }
                    dialog = new MaterialDialog.Builder(mContext).icon(CoCoinUtil.GetTagIconDrawable(allData.get(position - 1).getTag())).limitIconToDefaultSize().title(subTitle).customView(R.layout.dialog_a_record, true).positiveText(R.string.get).show();
                    dialogView = dialog.getCustomView();
                    TextView remark = (TextView) dialogView.findViewById(R.id.remark);
                    TextView date = (TextView) dialogView.findViewById(R.id.date);
                    remark.setText(allData.get(position - 1).getRemark());
                    date.setText(allData.get(position - 1).getCalendarString());
                }
            });
            break;
    }
}
Also used : ArrayList(java.util.ArrayList) SliceValue(lecho.lib.hellocharts.model.SliceValue) RecordCheckDialogFragment(com.nightonke.saver.fragment.RecordCheckDialogFragment) Column(lecho.lib.hellocharts.model.Column) SubcolumnValue(lecho.lib.hellocharts.model.SubcolumnValue) TextView(android.widget.TextView) Axis(lecho.lib.hellocharts.model.Axis) SelectedValue(lecho.lib.hellocharts.model.SelectedValue) PieChartData(lecho.lib.hellocharts.model.PieChartData) ColumnChartOnValueSelectListener(lecho.lib.hellocharts.listener.ColumnChartOnValueSelectListener) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) PieChartView(lecho.lib.hellocharts.view.PieChartView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ColumnChartView(lecho.lib.hellocharts.view.ColumnChartView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) CoCoinRecord(com.nightonke.saver.model.CoCoinRecord) PieChartOnValueSelectListener(lecho.lib.hellocharts.listener.PieChartOnValueSelectListener) FragmentActivity(android.support.v4.app.FragmentActivity) AxisValue(lecho.lib.hellocharts.model.AxisValue) RecordManager(com.nightonke.saver.model.RecordManager) ColumnChartData(lecho.lib.hellocharts.model.ColumnChartData) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Snackbar(com.nispok.snackbar.Snackbar)

Example 9 with Snackbar

use of com.nispok.snackbar.Snackbar in project qksms by moezbhatti.

the class DefaultSmsHelper method showIfNotDefault.

public void showIfNotDefault(ViewGroup viewGroup) {
    if (!mIsDefault) {
        long deltaTime = (System.nanoTime() / 1000000) - sLastShown;
        long duration = deltaTime > 60 * 1000 ? 8000 : 3000;
        Snackbar snackBar = Snackbar.with(mContext).type(getSnackBarType()).text(mMessage).duration(duration).actionColor(ThemeManager.getColor()).actionLabel(R.string.upgrade_now).actionListener(this);
        if (viewGroup == null) {
            SnackbarManager.show(snackBar);
        } else {
            SnackbarManager.show(snackBar, viewGroup);
        }
        sLastShown = System.nanoTime() / 1000000;
    }
}
Also used : Snackbar(com.nispok.snackbar.Snackbar)

Example 10 with Snackbar

use of com.nispok.snackbar.Snackbar in project Material-Movies by saulmm.

the class MoviesActivity method showLoadingLabel.

@Override
public void showLoadingLabel() {
    Snackbar loadingSnackBar = Snackbar.with(this).text(getString(R.string.activity_movies_message_more_films)).actionLabel(getString(R.string.action_cancel)).duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE).color(getResources().getColor(R.color.theme_primary)).actionColor(getResources().getColor(R.color.theme_accent));
    SnackbarManager.show(loadingSnackBar);
}
Also used : Snackbar(com.nispok.snackbar.Snackbar)

Aggregations

Snackbar (com.nispok.snackbar.Snackbar)10 ActionClickListener (com.nispok.snackbar.listeners.ActionClickListener)5 View (android.view.View)4 EventListener (com.nispok.snackbar.listeners.EventListener)3 PieChartOnValueSelectListener (lecho.lib.hellocharts.listener.PieChartOnValueSelectListener)3 SliceValue (lecho.lib.hellocharts.model.SliceValue)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2 Intent (android.content.Intent)2 Typeface (android.graphics.Typeface)2 FragmentActivity (android.support.v4.app.FragmentActivity)2 Button (android.widget.Button)2 TextView (android.widget.TextView)2 CoCoinRecord (com.nightonke.saver.model.CoCoinRecord)2 ActionSwipeListener (com.nispok.snackbar.listeners.ActionSwipeListener)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 PieChartData (lecho.lib.hellocharts.model.PieChartData)2