use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.
the class DragingDialogs method editColorsPanel.
public static void editColorsPanel(final FrameLayout anchor, final DocumentController controller, final DrawView drawView, final boolean force) {
drawView.setOnFinishDraw(new Runnable() {
@Override
public void run() {
String annotationDrawColor = AppState.get().annotationDrawColor;
if (TxtUtils.isEmpty(annotationDrawColor)) {
annotationDrawColor = AppState.get().COLORS.get(0);
}
controller.saveChanges(drawView.getPoints(), Color.parseColor(annotationDrawColor));
drawView.clear();
controller.saveAnnotationsToFile();
}
});
new DragingPopup(R.string.annotations_draw, anchor, 250, 150) {
@Override
public void closeDialog() {
super.closeDialog();
AppState.get().editWith = AppState.EDIT_NONE;
AppState.get().annotationDrawColor = "";
drawView.setVisibility(View.GONE);
drawView.clear();
}
@Override
public View getContentView(final LayoutInflater inflater) {
View a = inflater.inflate(R.layout.edit_panel, null, false);
final GridView grid = (GridView) a.findViewById(R.id.gridColors);
if (AppState.get().editWith == AppState.EDIT_DELETE) {
AppState.get().annotationDrawColor = AppState.get().COLORS.get(0);
}
final BaseItemAdapter<String> adapter = new BaseItemAdapter<String>(AppState.get().COLORS) {
@Override
public View getView(int pos, View arg1, ViewGroup arg2, String color) {
View view = null;
if (pos == 0) {
view = inflater.inflate(R.layout.item_color_cut, arg2, false);
} else if (pos == 1) {
view = inflater.inflate(R.layout.item_color_spinner, arg2, false);
final Spinner spinner = (Spinner) view.findViewById(R.id.spinner1);
final List<Float> values = Arrays.asList(0.5f, 0.75f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f);
spinner.setAdapter(new BaseItemLayoutAdapter<Float>(anchor.getContext(), android.R.layout.simple_spinner_dropdown_item, values) {
@Override
public void populateView(View inflate, int arg1, Float value) {
TextView text = Views.text(inflate, android.R.id.text1, "" + value + "");
}
});
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
spinner.setSelection(position);
AppState.get().editLineWidth = values.get(position);
int acolor = IMG.alphaColor(AppState.get().editAlphaColor, AppState.get().annotationDrawColor);
drawView.setColor(acolor, AppState.get().editLineWidth);
try {
TextView textView = (TextView) spinner.getChildAt(0);
textView.setTextAppearance(controller.getActivity(), R.style.textLinkStyle);
} catch (Exception e) {
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinner.setSelection(values.indexOf(AppState.get().editLineWidth));
} else if (pos == 2121) {
view = inflater.inflate(R.layout.item_color_spinner, arg2, false);
final Spinner spinner = (Spinner) view.findViewById(R.id.spinner1);
final List<Integer> values = Arrays.asList(100, 90, 80, 70, 60, 50, 40, 30, 20, 10);
spinner.setAdapter(new BaseItemLayoutAdapter<Integer>(anchor.getContext(), android.R.layout.simple_spinner_dropdown_item, values) {
@Override
public void populateView(View inflate, int arg1, Integer value) {
TextView text = Views.text(inflate, android.R.id.text1, "" + value + "%");
}
});
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
spinner.setSelection(position);
AppState.get().editAlphaColor = values.get(position);
int acolor = IMG.alphaColor(AppState.get().editAlphaColor, AppState.get().annotationDrawColor);
drawView.setColor(acolor, AppState.get().editLineWidth);
// ((TextView)
// spinner.getChildAt(0)).setTextColor(anchor.getResources().getColor(R.color.grey_800));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinner.setSelection(values.indexOf(AppState.get().editAlphaColor));
} else {
view = inflater.inflate(R.layout.item_color, arg2, false);
int acolor = IMG.alphaColor(AppState.get().editAlphaColor, color);
view.findViewById(R.id.itColor).setBackgroundColor(acolor);
}
view.setTag(color);
if (color.equals(AppState.get().annotationDrawColor)) {
view.setBackgroundResource(R.drawable.bg_border_1_lines);
} else {
view.setBackgroundColor(Color.TRANSPARENT);
}
return view;
}
};
grid.setAdapter(adapter);
grid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AppState.get().editWith = AppState.EDIT_PEN;
if (view.getTag().equals(AppState.get().annotationDrawColor)) {
AppState.get().annotationDrawColor = "";
drawView.setVisibility(View.GONE);
} else {
AppState.get().annotationDrawColor = (String) view.getTag();
int acolor = IMG.alphaColor(AppState.get().editAlphaColor, AppState.get().annotationDrawColor);
drawView.setColor(acolor, AppState.get().editLineWidth);
drawView.setVisibility(View.VISIBLE);
if (position == 0) {
drawView.setVisibility(View.GONE);
AppState.get().editWith = AppState.EDIT_DELETE;
}
}
adapter.notifyDataSetChanged();
}
});
return a;
}
}.show(EDIT_COLORS_PANEL, force);
}
use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.
the class MyPopupMenu method show.
public void show(int pos) {
final ListPopupWindow p1 = new ListPopupWindow(c);
p1.setModal(true);
p1.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
p1.dismiss();
if (isTabsActivity) {
if (AppState.get().isFullScreenMain) {
Keyboards.hideNavigation((Activity) c);
}
} else {
if (AppState.get().isFullScreen) {
Keyboards.hideNavigation((Activity) c);
}
}
}
});
BaseItemLayoutAdapter<Menu> a = new BaseItemLayoutAdapter<Menu>(c, R.layout.item_dict_line, list) {
@Override
public void populateView(View layout, int position, final Menu item) {
TextView textView = (TextView) layout.findViewById(R.id.text1);
textView.setText(item.stringRes);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
if (TxtUtils.isNotEmpty(item.fontPath)) {
textView.setTypeface(BookCSS.getTypeFaceForFont(item.fontPath));
}
ImageView imageView = (ImageView) layout.findViewById(R.id.image1);
if (item.iconRes != 0) {
imageView.setImageResource(item.iconRes);
if (item.iconRes == R.drawable.icon_pdf_pro) {
TintUtil.setNoTintImage(imageView);
} else {
if (isTabsActivity) {
if (AppState.get().isInkMode || AppState.get().isWhiteTheme) {
TintUtil.setTintImageWithAlpha(imageView, TintUtil.color);
} else {
TintUtil.setTintImageWithAlpha(imageView, Color.LTGRAY);
}
} else {
if (AppState.get().isDayNotInvert) {
TintUtil.setTintImageWithAlpha(imageView, TintUtil.color);
} else {
TintUtil.setTintImageWithAlpha(imageView, Color.LTGRAY);
}
}
}
} else {
imageView.setVisibility(View.GONE);
}
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
item.click.onMenuItemClick(null);
try {
p1.dismiss();
} catch (Exception e) {
LOG.e(e);
}
}
});
layout.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (item.onLongClick == null) {
return false;
}
item.onLongClick.onMenuItemClick(null);
try {
p1.dismiss();
} catch (Exception e) {
LOG.e(e);
}
return true;
}
});
}
};
p1.setAnchorView(anchor);
p1.setAdapter(a);
try {
p1.setWidth(measureContentWidth(a, c) + Dips.dpToPx(20));
} catch (Exception e) {
p1.setWidth(200);
}
p1.show();
if (pos != -1) {
p1.setSelection(pos - 2);
}
}
use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.
the class Dialogs method showTagsDialog.
public static void showTagsDialog(final Context a, File file, final Runnable refresh) {
final FileMeta fileMeta = AppDB.get().getOrCreate(file.getPath());
LOG.d("showTagsDialog book tags", fileMeta.getTag());
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
// builder.setTitle(R.string.tag);
View inflate = LayoutInflater.from(a).inflate(R.layout.dialog_tags, null, false);
final ListView list = (ListView) inflate.findViewById(R.id.listView1);
final TextView add = (TextView) inflate.findViewById(R.id.addTag);
TxtUtils.underline(add, "+ " + a.getString(R.string.add_tag));
final List<String> tags = StringDB.asList(AppState.get().bookTags);
List<String> fileTags = StringDB.asList(fileMeta.getTag());
for (String fileTag : fileTags) {
if (!StringDB.contains(AppState.get().bookTags, fileTag)) {
tags.add(fileTag);
}
}
Collections.sort(tags);
Iterator<String> iterator = tags.iterator();
while (iterator.hasNext()) {
if (TxtUtils.isEmpty(iterator.next().trim())) {
iterator.remove();
}
}
final Set<Integer> checked = new HashSet<>();
final BaseItemLayoutAdapter<String> adapter = new BaseItemLayoutAdapter<String>(a, R.layout.tag_item, tags) {
@Override
public void populateView(View layout, final int position, final String tagName) {
CheckBox text = (CheckBox) layout.findViewById(R.id.tagName);
text.setText(tagName);
text.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
checked.add(position);
} else {
checked.remove(position);
}
}
});
text.setChecked(StringDB.contains(fileMeta.getTag(), tagName));
layout.findViewById(R.id.deleteTag).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog((Activity) a, a.getString(R.string.do_you_want_to_delete_this_tag_from_all_books_), new Runnable() {
@Override
public void run() {
checked.clear();
AppState.get().bookTags = StringDB.delete(AppState.get().bookTags, tagName);
tags.clear();
tags.addAll(StringDB.asList(AppState.get().bookTags));
notifyDataSetChanged();
List<FileMeta> allWithTag = AppDB.get().getAllWithTag(tagName);
for (FileMeta meta : allWithTag) {
meta.setTag(StringDB.delete(meta.getTag(), tagName));
}
AppDB.get().updateAll(allWithTag);
if (refresh != null) {
refresh.run();
}
}
});
}
});
}
};
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addTagsDialog(a, new Runnable() {
@Override
public void run() {
tags.clear();
tags.addAll(StringDB.asList(AppState.get().bookTags));
adapter.notifyDataSetChanged();
}
});
}
});
list.setAdapter(adapter);
builder.setView(inflate);
builder.setNegativeButton(R.string.close, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setPositiveButton(R.string.apply, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String res = "";
for (int i : checked) {
res = StringDB.add(res, tags.get(i));
}
LOG.d("showTagsDialog", res);
fileMeta.setTag(res);
AppDB.get().update(fileMeta);
if (refresh != null) {
refresh.run();
}
TempHolder.listHash++;
}
});
AlertDialog create = builder.create();
create.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Keyboards.close((Activity) a);
Keyboards.hideNavigation((Activity) a);
}
});
create.show();
}
Aggregations