use of com.ichi2.ui.WarpLinearLayout in project AnkiChinaAndroid by ankichinateam.
the class PosterActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
Themes.setThemeLegacy(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_poster);
String poster = getIntent().getStringExtra("poster");
root = new JSONObject(poster);
JSONArray members = root.getJSONArray("members");
setText(R.id.content_title, root.getString("title"));
setText(R.id.content_classify, root.getString("level") + "/" + root.getString("subject"));
setText(R.id.content_price_origin, "原价¥ " + root.getString("origin_price"));
// 中划线
((TextView) findViewById(R.id.content_price_origin)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
setText(R.id.content_price, "¥ " + root.getString("team_price"));
setText(R.id.content_num, root.getString("study_users") + "人正在学习");
setText(R.id.content_time_remain, "拼团特惠仅剩" + root.getInt("quota") + "名额\n" + convertSeconds(root.getInt("countDown")) + "后结束");
setText(R.id.content_num_remain, "还差" + (root.getInt("users") - members.length()) + "人,特享团购价");
ImageView qrcode = findViewById(R.id.qr_code);
Bitmap mBitmap = QRCodeUtil.createQRCodeBitmap(root.getString("link"), Utils.dp2px(this, 160), Utils.dp2px(this, 160));
qrcode.setImageBitmap(mBitmap);
LinearLayout memberLayout = findViewById(R.id.join_list);
for (int i = 0; i < members.length(); i++) {
if (root.getInt("users") > 3) {
// 需要人数大于3个,那就保留一个空位
if (i > 1) {
// 最多添加2个
break;
}
}
// if(root.getInt("users")==3) {
// //需要人数刚好是3个,那就三个都占满
// if (i > 2) {
// break;
// }
// }
View view = getLayoutInflater().inflate(R.layout.item_poster_avatar, null);
ImageView avatar = view.findViewById(R.id.avatar);
if (i == 0) {
view.findViewById(R.id.host_role).setVisibility(View.VISIBLE);
}
Glide.with(this).asBitmap().load(members.getJSONObject(i).getString("avatar")).into(avatar);
memberLayout.addView(view);
}
for (int i = memberLayout.getChildCount(); i < 3; i++) {
View view = getLayoutInflater().inflate(R.layout.item_poster_avatar_empty, null);
memberLayout.addView(view);
}
JSONArray tags = root.getJSONArray("tags");
for (int i = 0; i < tags.length(); i++) {
View view = getLayoutInflater().inflate(R.layout.item_warp_poster, null);
Button button = view.findViewById(R.id.text);
button.setText(tags.getString(i));
((WarpLinearLayout) findViewById(R.id.tags_layout)).addView(view);
}
showShareDialog(findViewById(R.id.rootView));
}
use of com.ichi2.ui.WarpLinearLayout in project AnkiChinaAndroid by ankichinateam.
the class SelfStudyActivity method showScreenDialog.
private void showScreenDialog() {
InputMethodManager manager = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
if (manager != null && getCurrentFocus() != null) {
manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
View dialog = getLayoutInflater().inflate(R.layout.pop_window_screen_self_study, null);
mPopupWindow = new PopupWindow(dialog, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
TextView studyTitle = dialog.findViewById(R.id.memory_title);
TextView markTitle = dialog.findViewById(R.id.mark_title);
TextView answerTitle = dialog.findViewById(R.id.answer_title);
WarpLinearLayout studyLayout = dialog.findViewById(R.id.memory_layout);
WarpLinearLayout markLayout = dialog.findViewById(R.id.mark_layout);
WarpLinearLayout answerLayout = dialog.findViewById(R.id.answer_layout);
studyLayout.setVisibility(mTabType != TAB_MARK_STATE && mTabType != TAB_ANSWER_STATE ? View.VISIBLE : View.GONE);
studyTitle.setVisibility(studyLayout.getVisibility());
markLayout.setVisibility(View.VISIBLE);
markTitle.setVisibility(View.VISIBLE);
answerLayout.setVisibility(mTabType != TAB_MARK_STATE && mTabType != TAB_STUDY_STATE ? View.VISIBLE : View.GONE);
answerTitle.setVisibility(answerLayout.getVisibility());
List<Button> studyButtonList = new ArrayList<>();
for (int i = 0; i < mArrayStudy.length; i++) {
View view = getLayoutInflater().inflate(R.layout.item_warp, null);
Button button = view.findViewById(R.id.text);
button.setSelected(mSelectedStudyButtonList.contains(i));
button.setText(mArrayStudy[i]);
button.setTag(i);
button.setOnClickListener(v -> {
if ((Integer) v.getTag() == 0) {
for (int m = 1; m < studyButtonList.size(); m++) {
if (mSelectedStudyButtonList.contains(m)) {
mSelectedStudyButtonList.remove((Object) m);
}
studyButtonList.get(m).setSelected(false);
}
} else {
studyButtonList.get(0).setSelected(false);
if (mSelectedStudyButtonList.contains(0)) {
mSelectedStudyButtonList.remove((Object) 0);
}
}
if (mSelectedStudyButtonList.contains(v.getTag())) {
mSelectedStudyButtonList.remove(v.getTag());
} else {
mSelectedStudyButtonList.add((Integer) v.getTag());
}
v.setSelected(!v.isSelected());
});
studyButtonList.add(button);
studyLayout.addView(view);
}
List<Button> markButtonList = new ArrayList<>();
for (int i = 0; i < mArrayMark.length; i++) {
View view = getLayoutInflater().inflate(R.layout.item_warp, null);
Button button = view.findViewById(R.id.text);
button.setSelected(mSelectedMarkButtonList.contains(i));
button.setText(mArrayMark[i]);
button.setTag(i);
button.setOnClickListener(v -> {
if ((Integer) v.getTag() == 0) {
for (int m = 1; m < markButtonList.size(); m++) {
if (mSelectedMarkButtonList.contains(m)) {
mSelectedMarkButtonList.remove((Object) m);
}
markButtonList.get(m).setSelected(false);
}
} else {
markButtonList.get(0).setSelected(false);
if (mSelectedMarkButtonList.contains(0)) {
mSelectedMarkButtonList.remove((Object) 0);
}
}
if (mSelectedMarkButtonList.contains(v.getTag())) {
mSelectedMarkButtonList.remove(v.getTag());
} else {
mSelectedMarkButtonList.add((Integer) v.getTag());
}
v.setSelected(!v.isSelected());
});
markButtonList.add(button);
markLayout.addView(view);
}
List<Button> answerButtonList = new ArrayList<>();
for (int i = 0; i < mArrayAnswer.length; i++) {
View view = getLayoutInflater().inflate(R.layout.item_warp, null);
Button button = view.findViewById(R.id.text);
button.setSelected(mSelectedAnswerButtonList.contains(i));
button.setText(mArrayAnswer[i]);
button.setTag(i);
button.setOnClickListener(v -> {
if ((Integer) v.getTag() == 0) {
for (int m = 1; m < answerButtonList.size(); m++) {
if (mSelectedAnswerButtonList.contains(m)) {
mSelectedAnswerButtonList.remove((Object) m);
}
answerButtonList.get(m).setSelected(false);
}
} else {
answerButtonList.get(0).setSelected(false);
if (mSelectedAnswerButtonList.contains(0)) {
mSelectedAnswerButtonList.remove((Object) 0);
}
}
if (mSelectedAnswerButtonList.contains(v.getTag())) {
mSelectedAnswerButtonList.remove(v.getTag());
} else {
mSelectedAnswerButtonList.add((Integer) v.getTag());
}
v.setSelected(!v.isSelected());
});
answerButtonList.add(button);
answerLayout.addView(view);
}
RangeSeekBar answerTimesSeekBar = dialog.findViewById(R.id.answer_times_seek_bar);
answerTimesSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {
@Override
public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
if (mTabType == TAB_CUSTOM_STATE) {
((TextView) dialog.findViewById(R.id.answer_times_num)).setText(leftValue == answerTimesSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "最近%.0f天", leftValue));
} else {
((TextView) dialog.findViewById(R.id.answer_times_num)).setText(String.format(Locale.CHINA, "最近%.0f天", leftValue));
}
if (leftValue == answerTimesSeekBar.getMaxProgress()) {
mRangeSearchAnswerFilter = "";
} else {
mRangeSearchAnswerFilter = String.format(Locale.CHINA, "(rated:%.0f)", leftValue);
}
}
@Override
public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
@Override
public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
});
answerTimesSeekBar.setRange(0, mTabType == TAB_CUSTOM_STATE ? 31 : 30);
answerTimesSeekBar.setProgress(mTabType == TAB_CUSTOM_STATE ? 31 : 30);
RangeSeekBar createTimeSeekBar = dialog.findViewById(R.id.create_time_seek_bar);
createTimeSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {
@Override
public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
((TextView) dialog.findViewById(R.id.create_time_num)).setText(leftValue == createTimeSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "最近%.0f天", leftValue));
if (leftValue == createTimeSeekBar.getMaxProgress()) {
mRangeCreateTimeFilter = "";
} else {
mRangeCreateTimeFilter = String.format(Locale.CHINA, "(added:%.0f)", leftValue);
}
}
@Override
public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
@Override
public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
});
createTimeSeekBar.setRange(0, 366);
createTimeSeekBar.setProgress(366);
dialog.findViewById(R.id.answer_times_seek_layout).setVisibility(mTabType == TAB_ANSWER_STATE || mTabType == TAB_CUSTOM_STATE || mTabType == TAB_MAIN_STATE ? View.VISIBLE : View.GONE);
RangeSeekBar reviewTimesSeekBar = dialog.findViewById(R.id.review_times_seek_bar);
reviewTimesSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {
@Override
public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
String rightStr = rightValue == reviewTimesSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "%.0f", rightValue);
((TextView) dialog.findViewById(R.id.review_times_num)).setText(String.format(Locale.CHINA, "%.0f-%s", leftValue, rightStr));
if (rightValue == reviewTimesSeekBar.getMaxProgress()) {
if (leftValue > 0) {
mRangeSearchReviewTimesFilter = String.format(Locale.CHINA, "(prop:reps>=%.0f)", leftValue);
} else {
mRangeSearchReviewTimesFilter = "";
}
} else {
mRangeSearchReviewTimesFilter = String.format(Locale.CHINA, "(prop:reps>=%.0f prop:reps<=%.0f)", leftValue, rightValue);
}
}
@Override
public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
@Override
public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
});
reviewTimesSeekBar.setRange(0, 20);
reviewTimesSeekBar.setProgress(0, 20);
RangeSeekBar forgetTimesSeekBar = dialog.findViewById(R.id.forget_times_seek_bar);
forgetTimesSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {
@Override
public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
String rightStr = rightValue == forgetTimesSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "%.0f", rightValue);
((TextView) dialog.findViewById(R.id.forget_times_num)).setText(String.format(Locale.CHINA, "%.0f-%s", leftValue, rightStr));
if (rightValue == forgetTimesSeekBar.getMaxProgress()) {
if (leftValue > 0) {
mRangeSearchForgetTimesFilter = String.format(Locale.CHINA, "(prop:lapses>=%.0f)", leftValue);
} else {
mRangeSearchForgetTimesFilter = "";
}
} else {
mRangeSearchForgetTimesFilter = String.format(Locale.CHINA, "(prop:lapses>=%.0f prop:lapses<=%.0f)", leftValue, rightValue);
}
}
@Override
public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
@Override
public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
});
forgetTimesSeekBar.setRange(0, 10);
forgetTimesSeekBar.setProgress(0, 10);
Spinner deck_spinner = dialog.findViewById(R.id.deck_spinner);
deck_spinner.setAdapter(mDropDownDeckAdapter);
deck_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mSelectedDropDownDeckPosition = position;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// do nothing
}
});
deck_spinner.setSelection(mSelectedDropDownDeckPosition);
RelativeLayout tag_spinner = dialog.findViewById(R.id.tag_spinner);
tag_spinner.setVisibility(mTabType == TAB_CUSTOM_STATE || mTabType == TAB_MAIN_STATE ? View.VISIBLE : View.GONE);
TextView tag_selected = dialog.findViewById(R.id.tag_selected);
tag_spinner.setOnClickListener(v -> showTagsDialog(tag_selected));
Button reset = dialog.findViewById(R.id.reset);
Button confirm = dialog.findViewById(R.id.confirm);
reset.setOnClickListener(v -> {
resetFilter();
// 重置卡组选择
deck_spinner.setSelection(mSelectedDropDownDeckPosition);
for (int i = 1; i < studyLayout.getChildCount(); i++) {
studyLayout.getChildAt(i).setSelected(false);
}
for (int i = 1; i < markLayout.getChildCount(); i++) {
markLayout.getChildAt(i).setSelected(false);
}
for (int i = 1; i < answerLayout.getChildCount(); i++) {
answerLayout.getChildAt(i).setSelected(false);
}
switch(mTabType) {
case TAB_STUDY_STATE:
studyLayout.getChildAt(1).performClick();
break;
case TAB_MARK_STATE:
markLayout.getChildAt(1).performClick();
break;
case TAB_ANSWER_STATE:
answerLayout.getChildAt(1).performClick();
break;
case TAB_CUSTOM_STATE:
case TAB_MAIN_STATE:
break;
}
forgetTimesSeekBar.setProgress(0, 10);
reviewTimesSeekBar.setProgress(0, 20);
answerTimesSeekBar.setProgress(mTabType == TAB_CUSTOM_STATE || mTabType == TAB_MAIN_STATE ? 31 : 30);
});
confirm.setOnClickListener(v -> {
if (mTabType == TAB_MAIN_STATE) {
for (int i = 0; i < mTabLayout.getTabCount(); i++) {
mTabLayout.getTabAt(i).getCustomView().setSelected(false);
}
} else if (mTabType != TAB_CUSTOM_STATE) {
mTabLayout.getTabAt(mSelectedTabIndex - 1).getCustomView().setSelected(false);
}
mRestrictOnTab = "";
// 标签选择
updateTagsSearchTerms();
// 卡牌选择
deckDropDownItemChanged(mSelectedDropDownDeckPosition);
// 按钮选择
updateButtonFilter();
mPopupWindow.dismiss();
searchCards();
});
mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
mPopupWindow.setOutsideTouchable(false);
mPopupWindow.setFocusable(true);
mPopupWindow.setOnDismissListener(() -> findViewById(R.id.shadeView).setVisibility(View.GONE));
mPopupWindow.showAsDropDown(mToolbar, 0, 0);
findViewById(R.id.shadeView).setVisibility(View.VISIBLE);
}
Aggregations