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();
}
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();
}
}
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();
}
}
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();
}
});
}
}
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();
}
});
}
Aggregations