Search in sources :

Example 1 with FragmentActivity

use of android.support.v4.app.FragmentActivity in project photo-picker-plus-android by chute.

the class FragmentUtil method replaceContentWithEmptyFragment.

public static void replaceContentWithEmptyFragment(FragmentActivity activity) {
    FragmentTransaction fragmentTransaction = activity.getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.gcFragments, FragmentEmpty.newInstance(), TAG_FRAGMENT_EMPTY);
    fragmentTransaction.commit();
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 2 with FragmentActivity

use of android.support.v4.app.FragmentActivity in project cw-omnibus by commonsguy.

the class ActionBarImpl method selectTab.

@Override
public void selectTab(Tab tab) {
    if (getNavigationMode() != NAVIGATION_MODE_TABS) {
        mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
        return;
    }
    FragmentTransaction trans = null;
    if (mActivity instanceof FragmentActivity) {
        trans = ((FragmentActivity) mActivity).getSupportFragmentManager().beginTransaction().disallowAddToBackStack();
    }
    if (mSelectedTab == tab) {
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
            mTabScrollView.animateToTab(tab.getPosition());
        }
    } else {
        mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
        }
        mSelectedTab = (TabImpl) tab;
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
        }
    }
    if (trans != null && !trans.isEmpty()) {
        trans.commit();
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 3 with FragmentActivity

use of android.support.v4.app.FragmentActivity in project Libraries-for-Android-Developers by eoecn.

the class ActionBarImpl method selectTab.

@Override
public void selectTab(Tab tab) {
    if (getNavigationMode() != NAVIGATION_MODE_TABS) {
        mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
        return;
    }
    FragmentTransaction trans = null;
    if (mActivity instanceof FragmentActivity) {
        trans = ((FragmentActivity) mActivity).getSupportFragmentManager().beginTransaction().disallowAddToBackStack();
    }
    if (mSelectedTab == tab) {
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
            mTabScrollView.animateToTab(tab.getPosition());
        }
    } else {
        mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
        }
        mSelectedTab = (TabImpl) tab;
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
        }
    }
    if (trans != null && !trans.isEmpty()) {
        trans.commit();
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 4 with FragmentActivity

use of android.support.v4.app.FragmentActivity in project CoCoin by Nightonke.

the class MonthViewRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
    if (IS_EMPTY) {
        holder.expanseSum.setText("¥0");
        holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
        holder.emptyTip.setText(mContext.getResources().getString(R.string.tag_empty));
        holder.emptyTip.setTypeface(CoCoinUtil.GetTypeface());
        holder.tags.setVisibility(View.GONE);
        holder.date.setVisibility(View.INVISIBLE);
        holder.pie.setVisibility(View.INVISIBLE);
        holder.iconLeft.setVisibility(View.INVISIBLE);
        holder.iconRight.setVisibility(View.INVISIBLE);
        holder.all.setVisibility(View.GONE);
    } else {
        holder.date.setText(dateStringList.get(position));
        holder.expanseSum.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position)));
        holder.date.setTypeface(CoCoinUtil.GetTypeface());
        holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
        holder.tags.setTypeface(CoCoinUtil.typefaceLatoLight);
        if ("zh".equals(CoCoinUtil.GetLanguage())) {
            holder.tags.setText(" ● " + records + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_records) + tags + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_tags));
        } else {
            holder.tags.setText(" ● " + records + " " + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_records) + " " + tags + " " + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_tags));
        }
        if (SumList.get(position).equals(Double.valueOf(0))) {
            holder.emptyTip.setVisibility(View.VISIBLE);
            holder.emptyTip.setTypeface(CoCoinUtil.typefaceLatoLight);
        } else {
            holder.emptyTip.setVisibility(View.GONE);
        }
        holder.pie.setPieChartData(pieChartDataList.get(position));
        holder.pie.setOnValueTouchListener(new PieValueTouchListener(position));
        holder.pie.setChartRotationEnabled(false);
        if (!SumList.get(position).equals(Double.valueOf(0))) {
            holder.iconRight.setVisibility(View.VISIBLE);
            holder.iconRight.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    selectedPositionList.set(position, (selectedPositionList.get(position) + 1) % sliceValuesList.get(position).size());
                    SelectedValue selectedValue = new SelectedValue(selectedPositionList.get(position), 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) {
                    selectedPositionList.set(position, (selectedPositionList.get(position) - 1 + sliceValuesList.get(position).size()) % sliceValuesList.get(position).size());
                    SelectedValue selectedValue = new SelectedValue(selectedPositionList.get(position), 0, SelectedValue.SelectedValueType.NONE);
                    holder.pie.selectValue(selectedValue);
                }
            });
        } else {
            holder.iconLeft.setVisibility(View.GONE);
            holder.iconRight.setVisibility(View.GONE);
        }
        holder.all.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if ("zh".equals(CoCoinUtil.GetLanguage())) {
                    dialogTitle = mContext.getResources().getString(R.string.in) + dateStringList.get(position) + " " + CoCoinUtil.GetSpendString((int) (double) SumList.get(position));
                } else {
                    dialogTitle = CoCoinUtil.GetSpendString((int) (double) SumList.get(position)) + mContext.getResources().getString(R.string.in) + " " + dateStringList.get(position);
                }
                ((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, list, dialogTitle), "MyDialog").commit();
            }
        });
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) RecordCheckDialogFragment(com.nightonke.saver.fragment.RecordCheckDialogFragment) InjectView(butterknife.InjectView) View(android.view.View) PieChartView(lecho.lib.hellocharts.view.PieChartView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) SelectedValue(lecho.lib.hellocharts.model.SelectedValue)

Example 5 with FragmentActivity

use of android.support.v4.app.FragmentActivity in project CoCoin by Nightonke.

the class CustomViewFragment method select.

private void select() {
    if (RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS == null || RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.size() == 0) {
        return;
    }
    start = -1;
    end = 0;
    Sum = 0;
    lastPieSelectedPosition = -1;
    if (from.after(RecordManager.RECORDS.get(RecordManager.RECORDS.size() - 1).getCalendar())) {
        return;
    }
    if (to.before(RecordManager.RECORDS.get(0).getCalendar())) {
        return;
    }
    for (int i = RecordManager.RECORDS.size() - 1; i >= 0; i--) {
        if (RecordManager.RECORDS.get(i).getCalendar().before(from)) {
            end = i + 1;
            break;
        } else if (RecordManager.RECORDS.get(i).getCalendar().before(to)) {
            if (start == -1) {
                start = i;
            }
        }
    }
    startDayCalendar = (Calendar) from.clone();
    startDayCalendar.set(Calendar.HOUR_OF_DAY, 0);
    startDayCalendar.set(Calendar.MINUTE, 0);
    startDayCalendar.set(Calendar.SECOND, 0);
    final long startDay = TimeUnit.MILLISECONDS.toDays(startDayCalendar.getTimeInMillis());
    final long days = TimeUnit.MILLISECONDS.toDays(to.getTimeInMillis()) - startDay + 1;
    TagExpanse = new TreeMap<>();
    Expanse = new HashMap<>();
    originalTargets = new float[(int) days];
    int size = RecordManager.TAGS.size();
    for (int j = 2; j < size; j++) {
        TagExpanse.put(RecordManager.TAGS.get(j).getId(), Double.valueOf(0));
        Expanse.put(RecordManager.TAGS.get(j).getId(), new ArrayList<CoCoinRecord>());
    }
    for (int i = start; i >= end; i--) {
        CoCoinRecord coCoinRecord = RecordManager.RECORDS.get(i);
        TagExpanse.put(coCoinRecord.getTag(), TagExpanse.get(coCoinRecord.getTag()) + Double.valueOf(coCoinRecord.getMoney()));
        Expanse.get(coCoinRecord.getTag()).add(coCoinRecord);
        Sum += coCoinRecord.getMoney();
        originalTargets[(int) (TimeUnit.MILLISECONDS.toDays(coCoinRecord.getCalendar().getTimeInMillis()) - startDay)] += coCoinRecord.getMoney();
    }
    expense.setText(CoCoinUtil.GetInMoney(Sum));
    emptyTip.setVisibility(View.GONE);
    TagExpanse = CoCoinUtil.SortTreeMapByValues(TagExpanse);
    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(), CoCoinUtil.GetTagColor(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());
    pie.setPieChartData(pieChartData);
    pie.setChartRotationEnabled(false);
    pie.setVisibility(View.VISIBLE);
    iconRight.setVisibility(View.VISIBLE);
    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);
            pie.selectValue(selectedValue);
        }
    });
    iconLeft.setVisibility(View.VISIBLE);
    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);
            pie.selectValue(selectedValue);
        }
    });
    // set value touch listener of pie//////////////////////////////////////////////////////////////////
    dateShownString = mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + " " + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR);
    pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {

        @Override
        public void onValueSelected(int p, SliceValue sliceValue) {
            // snack bar
            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 = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
            }
            if ("zh".equals(CoCoinUtil.GetLanguage())) {
                dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + "于" + CoCoinUtil.GetTagName(tagId);
            } else {
                dialogTitle = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "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(-3)).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;
            }
        }

        @Override
        public void onValueDeselected() {
        }
    });
    all.setVisibility(View.VISIBLE);
    all.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            List<CoCoinRecord> data = new LinkedList<CoCoinRecord>();
            for (int i = start; i >= end; i--) data.add(RecordManager.RECORDS.get(i));
            if ("zh".equals(CoCoinUtil.GetLanguage())) {
                dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString(Sum) + "于" + CoCoinUtil.GetTagName(tagId);
            } else {
                dialogTitle = CoCoinUtil.GetSpendString(Sum) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "in " + CoCoinUtil.GetTagName(tagId);
            }
            ((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, data, dialogTitle), "MyDialog").commit();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) SliceValue(lecho.lib.hellocharts.model.SliceValue) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SelectedValue(lecho.lib.hellocharts.model.SelectedValue) PieChartData(lecho.lib.hellocharts.model.PieChartData) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) PieChartView(lecho.lib.hellocharts.view.PieChartView) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) CoCoinRecord(com.nightonke.saver.model.CoCoinRecord) PieChartOnValueSelectListener(lecho.lib.hellocharts.listener.PieChartOnValueSelectListener) FragmentActivity(android.support.v4.app.FragmentActivity) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Snackbar(com.nispok.snackbar.Snackbar)

Aggregations

FragmentActivity (android.support.v4.app.FragmentActivity)91 FragmentTransaction (android.app.FragmentTransaction)16 FragmentManager (android.support.v4.app.FragmentManager)16 FragmentTransaction (android.support.v4.app.FragmentTransaction)16 Fragment (android.support.v4.app.Fragment)11 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)11 Intent (android.content.Intent)7 Bundle (android.os.Bundle)5 View (android.view.View)5 TextView (android.widget.TextView)4 DialogFragment (android.support.v4.app.DialogFragment)3 SearchView (android.widget.SearchView)3 Fragment (android.app.Fragment)2 ActionBar (android.support.v7.app.ActionBar)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 MediaRouteDialogFactory (android.support.v7.app.MediaRouteDialogFactory)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ImageView (android.widget.ImageView)2 InjectView (butterknife.InjectView)2 RequestManager (com.bumptech.glide.RequestManager)2