use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class DragingDialogs method moreBookSettings.
public static DragingPopup moreBookSettings(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
final int initCssHash = BookCSS.get().toCssString().hashCode();
DragingPopup dialog = new DragingPopup(R.string.reading_settings, anchor, PREF_WIDTH, PREF_HEIGHT) {
@Override
public void beforeCreate() {
titleAction = controller.getString(R.string.preferences);
titleRunnable = new Runnable() {
@Override
public void run() {
if (initCssHash != BookCSS.get().toCssString().hashCode()) {
AlertDialogs.showDialog(controller.getActivity(), controller.getString(R.string.you_neet_to_apply_the_new_settings), controller.getString(R.string.apply), new Runnable() {
@Override
public void run() {
closeDialog();
}
});
} else {
preferences(anchor, controller, onRefresh, updateUIRefresh);
}
}
};
}
@Override
public View getContentView(final LayoutInflater inflater) {
View inflate = inflater.inflate(R.layout.dialog_reading_pref, null, false);
final CustomSeek fontWeight = (CustomSeek) inflate.findViewById(R.id.fontWeight);
fontWeight.init(1, 9, BookCSS.get().fontWeight / 100);
fontWeight.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
fontWeight.setValueText("" + (result * 100));
BookCSS.get().fontWeight = result * 100;
return false;
}
});
fontWeight.setValueText("" + BookCSS.get().fontWeight);
// begin styles
final List<String> docStyles = //
Arrays.asList(//
controller.getString(R.string.document_styles) + " + " + controller.getString(R.string.user_styles), //
controller.getString(R.string.document_styles), controller.getString(R.string.user_styles));
final TextView docStyle = (TextView) inflate.findViewById(R.id.documentStyle);
docStyle.setText(docStyles.get(BookCSS.get().documentStyle));
TxtUtils.underlineTextView(docStyle);
inflate.findViewById(R.id.documentStyleLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
docStyle.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (int i = 0; i < docStyles.size(); i++) {
String type = docStyles.get(i);
final int j = i;
popupMenu.getMenu().add(type).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
BookCSS.get().documentStyle = j;
docStyle.setText(docStyles.get(BookCSS.get().documentStyle));
TxtUtils.underlineTextView(docStyle);
return false;
}
});
}
popupMenu.show();
}
});
// end styles
// hypens
boolean isSupportHypens = controller.isTextFormat();
CheckBox isAutoHypens = (CheckBox) inflate.findViewById(R.id.isAutoHypens);
isAutoHypens.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
isAutoHypens.setChecked(BookCSS.get().isAutoHypens);
isAutoHypens.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
BookCSS.get().isAutoHypens = isChecked;
}
});
final TextView hypenLangLabel = (TextView) inflate.findViewById(R.id.hypenLangLabel);
final TextView hypenLang = (TextView) inflate.findViewById(R.id.hypenLang);
hypenLang.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
hypenLangLabel.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
// hypenLang.setVisibility(View.GONE);
// hypenLangLabel.setVisibility(View.GONE);
hypenLang.setText(DialogTranslateFromTo.getLanuageByCode(BookCSS.get().hypenLang));
TxtUtils.underlineTextView(hypenLang);
hypenLang.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
HyphenPattern[] values = HyphenPattern.values();
List<String> all = new ArrayList<String>();
for (HyphenPattern p : values) {
String e = DialogTranslateFromTo.getLanuageByCode(p.lang) + ":" + p.lang;
all.add(e);
}
Collections.sort(all);
for (final String langFull : all) {
String[] split = langFull.split(":");
final String titleLang = split[0];
final String code = split[1];
popupMenu.getMenu().add(titleLang).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
BookCSS.get().hypenLang = code;
hypenLang.setText(titleLang);
TxtUtils.underlineTextView(hypenLang);
FileMeta load = AppDB.get().load(controller.getCurrentBook().getPath());
if (load != null) {
load.setLang(code);
AppDB.get().update(load);
}
return false;
}
});
}
popupMenu.show();
}
});
// - hypens
View customCSS = inflate.findViewById(R.id.customCSS);
// TxtUtils.underlineTextView(customCSS);
customCSS.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setTitle(R.string.custom_css);
final EditText edit = new EditText(v.getContext());
edit.setMinWidth(Dips.dpToPx(1000));
edit.setLines(8);
edit.setGravity(Gravity.TOP);
edit.setText(BookCSS.get().customCSS1);
builder.setView(edit);
builder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
BookCSS.get().customCSS1 = edit.getText().toString();
BookCSS.get().save(v.getContext());
}
});
builder.show();
}
});
final CustomSeek lineHeight = (CustomSeek) inflate.findViewById(R.id.lineHeight);
lineHeight.init(0, 30, BookCSS.get().lineHeight);
lineHeight.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().lineHeight = result;
return false;
}
});
final CustomSeek paragraphHeight = (CustomSeek) inflate.findViewById(R.id.paragraphHeight);
paragraphHeight.init(0, 20, BookCSS.get().paragraphHeight);
paragraphHeight.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().paragraphHeight = result;
return false;
}
});
final CustomSeek fontParagraph = (CustomSeek) inflate.findViewById(R.id.fontParagraph);
fontParagraph.init(0, 30, BookCSS.get().textIndent);
fontParagraph.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().textIndent = result;
return false;
}
});
final CustomSeek emptyLine = (CustomSeek) inflate.findViewById(R.id.emptyLine);
// || //
boolean isShow = BookType.FB2.is(controller.getCurrentBook().getPath());
// BookType.HTML.is(controller.getCurrentBook().getPath()) || //
// BookType.TXT.is(controller.getCurrentBook().getPath());//
emptyLine.setVisibility(isShow ? View.VISIBLE : View.GONE);
emptyLine.init(0, 30, BookCSS.get().emptyLine);
emptyLine.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().emptyLine = result;
return false;
}
});
// Margins
final CustomSeek marginTop = (CustomSeek) inflate.findViewById(R.id.marginTop);
marginTop.init(0, 30, BookCSS.get().marginTop);
marginTop.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().marginTop = result;
return false;
}
});
final CustomSeek marginBottom = (CustomSeek) inflate.findViewById(R.id.marginBottom);
marginBottom.init(0, 30, BookCSS.get().marginBottom);
marginBottom.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().marginBottom = result;
return false;
}
});
final CustomSeek marginLeft = (CustomSeek) inflate.findViewById(R.id.marginLeft);
marginLeft.init(0, 30, BookCSS.get().marginLeft);
marginLeft.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().marginLeft = result;
return false;
}
});
final CustomSeek marginRight = (CustomSeek) inflate.findViewById(R.id.marginRight);
marginRight.init(0, 30, BookCSS.get().marginRight);
marginRight.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
BookCSS.get().marginRight = result;
return false;
}
});
// font folder
LOG.d("fontFolder2-2", BookCSS.get().fontFolder);
final TextView fontsFolder = (TextView) inflate.findViewById(R.id.fontsFolder);
TxtUtils.underline(fontsFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
fontsFolder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ChooserDialogFragment.chooseFolder((FragmentActivity) controller.getActivity(), BookCSS.get().fontFolder).setOnSelectListener(new ResultResponse2<String, Dialog>() {
@Override
public boolean onResultRecive(String nPath, Dialog dialog) {
File result = new File(nPath);
BookCSS.get().fontFolder = result.getPath();
TxtUtils.underline(fontsFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
BookCSS.get().save(controller.getActivity());
dialog.dismiss();
return false;
}
});
}
});
final View downloadFonts = inflate.findViewById(R.id.downloadFonts);
downloadFonts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FontExtractor.showDownloadFontsDialog(controller.getActivity(), downloadFonts, fontsFolder);
}
});
// / aling
final Map<Integer, String> alignConst = new LinkedHashMap<Integer, String>();
alignConst.put(BookCSS.TEXT_ALIGN_JUSTIFY, controller.getString(R.string.width));
alignConst.put(BookCSS.TEXT_ALIGN_LEFT, controller.getString(R.string.left));
alignConst.put(BookCSS.TEXT_ALIGN_RIGHT, controller.getString(R.string.right));
alignConst.put(BookCSS.TEXT_ALIGN_CENTER, controller.getString(R.string.center));
// align
final TextView textAlign = (TextView) inflate.findViewById(R.id.textAlign);
textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
textAlign.setOnClickListener(new OnClickListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT <= 10) {
BookCSS.get().textAlign += 1;
if (BookCSS.get().textAlign == 4) {
BookCSS.get().textAlign = 0;
}
textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
return;
}
final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
for (final int key : alignConst.keySet()) {
String name = alignConst.get(key);
popupMenu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
BookCSS.get().textAlign = key;
textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
return false;
}
});
}
popupMenu.show();
}
});
// link color
final CustomColorView linkColorDay = (CustomColorView) inflate.findViewById(R.id.linkColorDay);
linkColorDay.withDefaultColors(Color.parseColor(BookCSS.LINK_COLOR_DAY), Color.parseColor(BookCSS.LINK_COLOR_UNIVERSAL));
linkColorDay.init(Color.parseColor(BookCSS.get().linkColorDay));
linkColorDay.setOnColorChanged(new StringResponse() {
@Override
public boolean onResultRecive(String string) {
BookCSS.get().linkColorDay = string;
return false;
}
});
final CustomColorView linkColorNight = (CustomColorView) inflate.findViewById(R.id.linkColorNight);
linkColorNight.withDefaultColors(Color.parseColor(BookCSS.LINK_COLOR_NIGHT), Color.parseColor(BookCSS.LINK_COLOR_UNIVERSAL));
linkColorNight.init(Color.parseColor(BookCSS.get().linkColorNight));
linkColorNight.setOnColorChanged(new StringResponse() {
@Override
public boolean onResultRecive(String string) {
BookCSS.get().linkColorNight = string;
return false;
}
});
linkColorDay.getText1().getLayoutParams().width = Dips.dpToPx(150);
linkColorNight.getText1().getLayoutParams().width = Dips.dpToPx(150);
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onResetStyles)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialogs.showOkDialog(controller.getActivity(), controller.getString(R.string.restore_defaults_full), new Runnable() {
@Override
public void run() {
BookCSS.get().resetToDefault(controller.getActivity());
fontsFolder.setText(TxtUtils.underline(TxtUtils.lastTwoPath(BookCSS.get().fontFolder)));
textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
fontWeight.reset(BookCSS.get().fontWeight / 100);
fontWeight.setValueText("" + BookCSS.get().fontWeight);
lineHeight.reset(BookCSS.get().lineHeight);
paragraphHeight.reset(BookCSS.get().paragraphHeight);
fontParagraph.reset(BookCSS.get().textIndent);
//
marginTop.reset(BookCSS.get().marginTop);
marginBottom.reset(BookCSS.get().marginBottom);
marginLeft.reset(BookCSS.get().marginLeft);
marginRight.reset(BookCSS.get().marginRight);
emptyLine.reset(BookCSS.get().emptyLine);
linkColorDay.init(Color.parseColor(BookCSS.get().linkColorDay));
linkColorNight.init(Color.parseColor(BookCSS.get().linkColorNight));
}
});
}
});
return inflate;
}
};
dialog.show(DragingPopup.PREF + "_moreBookSettings");
dialog.setOnCloseListener(new Runnable() {
@Override
public void run() {
if (initCssHash != BookCSS.get().toCssString().hashCode()) {
AppState.get().save(controller.getActivity());
if (onRefresh != null) {
onRefresh.run();
}
controller.restartActivity();
}
}
});
return dialog;
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class ExportSettingsManager method importAll.
public boolean importAll(File file) {
if (file == null) {
return false;
}
LOG.d("TEST", "Import all from " + file.getPath());
try {
String json = new Scanner(file).useDelimiter("\\A").next();
LOG.d("[IMPORT]", json);
JSONObject jsonObject = new JSONObject(json);
importFromJSon(jsonObject.optJSONObject(PREFIX_PDF), pdfSP);
importFromJSon(jsonObject.optJSONObject(PREFIX_BOOKS), booksSP);
importFromJSon(jsonObject.optJSONObject(PREFIX_BOOKMARKS_PREFERENCES), viewerSP);
importFromJSon(jsonObject.optJSONObject(PREFIX_BOOK_CSS), bookCSS);
jsonToMeta(jsonObject.optJSONArray(PREFIX_RECENT), new ResultResponse<String>() {
@Override
public boolean onResultRecive(String result) {
AppDB.get().addRecent(result);
return false;
}
});
jsonToMeta(jsonObject.optJSONArray(PREFIX_STARS_Books), new ResultResponse<String>() {
@Override
public boolean onResultRecive(String result) {
AppDB.get().addStarFile(result);
return false;
}
});
jsonToMeta(jsonObject.optJSONArray(PREFIX_STARS_Folders), new ResultResponse<String>() {
@Override
public boolean onResultRecive(String result) {
AppDB.get().addStarFolder(result);
return false;
}
});
jsonTagsToMeta(jsonObject.optJSONArray(PREFIX_TAGS_BOOKS), new ResultResponse<Pair<String, String>>() {
@Override
public boolean onResultRecive(Pair<String, String> result) {
try {
if (new File(result.first).isFile()) {
FileMeta meta = AppDB.get().getOrCreate(result.first);
meta.setTag(result.second);
AppDB.get().update(meta);
}
} catch (Exception e) {
LOG.e(e);
}
return false;
}
});
return true;
} catch (Exception e) {
LOG.e(e);
Toast.makeText(c, e.getMessage(), Toast.LENGTH_LONG).show();
}
return false;
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class RecentBooksWidget method onReceive.
@SuppressLint("NewApi")
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
String testLocale = intent.getStringExtra(TEST_LOCALE);
if (LOG.isEnable && testLocale != null) {
// Toast.makeText(context, testLocale, Toast.LENGTH_LONG).show();
String DIR = "/storage/emulated/0/Download/BookTestingDB/My_Books/";
FileMeta MUSIC = new FileMeta(DIR + "Ludwig van Beethoven - Sonata No. 14, 'Moonlight'.pdf");
FileMeta PDF = new FileMeta(DIR + "Android-5.8-CC.pdf");
FileMeta Alice = new FileMeta(DIR + "Carroll_-_Alice's_adventures_in_Wonderland.epub");
String[] split = testLocale.split(",");
String languageToLoad = split[0];
int id = Integer.parseInt(split[1]);
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
// AppState.get().tintColor =
// Color.parseColor(AppState.STYLE_COLORS.get(new
// Random().nextInt(AppState.STYLE_COLORS.size() - 1)));
// TintUtil.tintRandomColor();
AppState.get().isMusicianMode = false;
AppState.get().isShowToolBar = true;
AppState.get().lastClosedActivity = null;
int i = 1;
// MUSIC.setIsRecent(false);
// AppDB.get().update(MUSIC);
// PDF.setIsRecent(false);
// AppDB.get().update(PDF);
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(0));
TintUtil.init();
if (id == i++) {
// 1
AppState.get().isWhiteTheme = true;
AppState.get().libraryMode = AppState.MODE_GRID;
mainTabsTest(context, 0, "id0");
}
if (id == i++) {
// 2
mainTabsTest(context, 1, "");
}
if (id == i++) {
// 3
mainTabsTest(context, 2, "");
}
if (id == i++) {
// 4
AppState.get().isUseBGImageNight = false;
AppState.get().colorNigthBg = Color.parseColor("#3a3a3a");
AppState.get().colorNigthText = Color.parseColor("#c8c8c8");
// nighh
AppState.get().isDayNotInvert = false;
easyMode(context, Alice, "", false);
}
if (id == i++) {
// 5
AppState.get().isUseBGImageDay = true;
AppState.get().bgImageDayTransparency = AppState.DAY_TRANSPARENCY;
AppState.get().bgImageDayPath = MagicHelper.IMAGE_BG_1;
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = false;
easyMode(context, Alice, "", true);
}
if (id == i++) {
// 6
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = true;
easyMode(context, Alice, "id1", false);
}
if (id == i++) {
// 7
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = true;
easyMode(context, Alice, "id2", true);
}
if (id == i++) {
// 8
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = false;
easyMode(context, Alice, "id3", false);
}
if (id == i++) {
// 9 PDF
AppState.get().isCustomizeBgAndColors = false;
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
AppState.get().isUseBGImageDay = false;
AppState.get().selectedText = "Install";
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = true;
advMode(context, PDF, "id2", true);
}
if (id == i++) {
// 10 MUSIC
AppState.get().isCustomizeBgAndColors = false;
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
AppState.get().isUseBGImageDay = false;
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = false;
AppState.get().isShowToolBar = false;
AppState.get().isMusicianMode = true;
advMode(context, MUSIC, "id1", false);
}
if (id == i++) {
// 11
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(4));
AppState.get().isWhiteTheme = false;
TintUtil.init();
mainTabsTest(context, 4, "");
}
if (id == i++) {
// 12
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(3));
AppState.get().isWhiteTheme = false;
AppState.get().libraryMode = AppState.MODE_LIST;
TintUtil.init();
mainTabsTest(context, 0, "id0");
}
if (// 13 //dict
id == i++) {
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(0));
TintUtil.init();
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = true;
AppState.get().selectedText = "There was";
easyMode(context, Alice, "id4", true);
}
if (// 14 //TTS
id == i++) {
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(0));
TintUtil.init();
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = true;
easyMode(context, Alice, "id5", true);
}
if (// 15 //more book settings
id == i++) {
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(0));
TintUtil.init();
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = true;
easyMode(context, Alice, "id6", true);
}
if (// 16 //file info
id == i++) {
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(0));
TintUtil.init();
AppState.get().isDayNotInvert = true;
AppState.get().isEditMode = true;
easyMode(context, Alice, "id7", true);
}
if (id == i++) {
// 17
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(3));
AppState.get().isWhiteTheme = true;
AppState.get().libraryMode = AppState.MODE_AUTHORS;
TintUtil.init();
mainTabsTest(context, 0, "");
}
if (id == i++) {
// 18
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(2));
AppState.get().isWhiteTheme = true;
AppState.get().libraryMode = AppState.MODE_GENRE;
TintUtil.init();
mainTabsTest(context, 0, "");
}
if (id == i++) {
// 19
AppState.get().tintColor = Color.parseColor(AppState.STYLE_COLORS.get(2));
AppState.get().isWhiteTheme = true;
AppState.get().libraryMode = AppState.MODE_LIST;
TintUtil.init();
mainTabsTest(context, 0, "id1");
}
return;
}
if (intent.getAction().equals(ACTION_MY)) {
String className = VerticalViewActivity.class.getName();
if (AppState.get().isAlwaysOpenAsMagazine) {
className = HorizontalViewActivity.class.getName();
}
Intent nintent = new Intent(Intent.ACTION_VIEW, (Uri) intent.getParcelableExtra("uri"));
nintent.setClassName(context, className);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, nintent, 0);
try {
pendingIntent.send();
} catch (CanceledException e) {
}
}
if (intent.getAction().equals("android.appwidget.action.APPWIDGET_UPDATE")) {
int[] appWidgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, RecentBooksWidget.class));
if (Build.VERSION.SDK_INT >= 16 && AppState.get().widgetType == AppState.WIDGET_GRID) {
AppWidgetManager.getInstance(context).notifyAppWidgetViewDataChanged(appWidgetIds, R.id.gridView1);
}
onUpdate(context, AppWidgetManager.getInstance(context), appWidgetIds);
}
super.onReceive(context, intent);
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class SearchAdapter method getView.
@Override
public View getView(final int i, View convertView, ViewGroup viewGroup) {
View browserItem = convertView;
if (browserItem != null && ((Holder) browserItem.getTag()).libMode != AppState.get().libraryMode) {
browserItem = null;
}
if (browserItem == null) {
if (AppState.get().libraryMode == AppState.MODE_GRID || AppState.get().libraryMode == AppState.MODE_COVERS) {
browserItem = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.browse_item_grid, viewGroup, false);
} else {
browserItem = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.browse_item_list, viewGroup, false);
}
Holder holder = new Holder();
holder.imageView = (ImageView) browserItem.findViewById(R.id.browserItemIcon);
holder.starIcon = (ImageView) browserItem.findViewById(R.id.starIcon);
holder.title1 = (TextView) browserItem.findViewById(R.id.title1);
holder.title2 = (TextView) browserItem.findViewById(R.id.title2);
holder.textPath = (TextView) browserItem.findViewById(R.id.browserPath);
holder.textSize = (TextView) browserItem.findViewById(R.id.browserSize);
holder.textDate = (TextView) browserItem.findViewById(R.id.browseDate);
holder.textExt = (TextView) browserItem.findViewById(R.id.browserExt);
holder.layoutBootom = browserItem.findViewById(R.id.layoutBootom);
holder.libMode = AppState.get().libraryMode;
View progresLayout = browserItem.findViewById(R.id.progresLayout);
if (progresLayout != null) {
progresLayout.setVisibility(View.GONE);
}
View delete = browserItem.findViewById(R.id.delete);
if (delete != null) {
delete.setVisibility(View.GONE);
}
browserItem.setTag(holder);
}
final Holder holder = (Holder) browserItem.getTag();
final FileMeta fileMeta = getItem(i);
ImageView menuIcon = (ImageView) browserItem.findViewById(R.id.itemMenu);
menuIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onMenuPressed != null) {
onMenuPressed.onResultRecive(new File(fileMeta.getPath()));
}
}
});
if (AppState.get().isCropBookCovers) {
holder.imageView.setScaleType(ScaleType.CENTER_CROP);
} else {
holder.imageView.setScaleType(ScaleType.FIT_CENTER);
}
holder.title1.setText(fileMeta.getTitle());
holder.title2.setText(fileMeta.getAuthor());
holder.textPath.setText(fileMeta.getPath());
holder.textSize.setText("" + fileMeta.getSize());
holder.textDate.setText("" + fileMeta.getDate());
holder.textExt.setText(fileMeta.getExt());
if (AppState.get().libraryMode == AppState.MODE_GRID || AppState.get().libraryMode == AppState.MODE_COVERS) {
holder.textPath.setVisibility(View.GONE);
holder.textSize.setVisibility(View.GONE);
IMG.updateImageSizeBig(holder.imageView);
IMG.updateImageSizeBig((View) holder.imageView.getParent());
if (AppState.get().libraryMode == AppState.MODE_COVERS) {
holder.layoutBootom.setVisibility(View.GONE);
}
} else {
holder.textPath.setVisibility(View.VISIBLE);
IMG.updateImageSizeSmall(holder.imageView);
IMG.updateImageSizeSmall((View) holder.imageView.getParent());
}
if (AppState.get().libraryMode == AppState.MODE_LIST && AppState.get().coverSmallSize >= IMG.TWO_LINE_COVER_SIZE) {
holder.title1.setSingleLine(false);
holder.title1.setLines(2);
} else {
holder.title1.setSingleLine(true);
holder.title1.setLines(1);
}
if (AppState.get().libraryMode == AppState.MODE_GRID && AppState.get().coverBigSize <= IMG.TWO_LINE_COVER_SIZE) {
holder.textDate.setVisibility(View.GONE);
} else {
holder.textDate.setVisibility(View.VISIBLE);
}
TintUtil.setTintImageWithAlpha(menuIcon);
// int size = AppState.get().libraryMode == AppState.MODE_LIST ?
// AppState.get().coverSmallSize : AppState.get().coverBigSize;
// StarsWrapper.addStars(holder.starIcon, info);
IMG.getCoverPageWithEffect(holder.imageView, fileMeta.getPath(), IMG.getImageSize(), new ImageLoadingListener() {
@Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
// TODO Auto-generated method stub
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
FileMeta fileMeta = getItem(i);
holder.title1.setText(fileMeta.getTitle());
holder.title2.setText(fileMeta.getAuthor());
holder.textPath.setText(fileMeta.getPath());
holder.textSize.setText("" + fileMeta.getSize());
holder.textDate.setText("" + fileMeta.getDate());
holder.textExt.setText(fileMeta.getExt());
if (TxtUtils.isEmpty(fileMeta.getAuthor()) && AppState.get().libraryMode == AppState.MODE_LIST) {
holder.title2.setVisibility(View.GONE);
} else {
holder.title2.setVisibility(View.VISIBLE);
}
}
@Override
public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub
}
});
return browserItem;
}
use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.
the class SearchCore method search.
private static void search(File root, List<String> exts, List<FileMeta> items) {
if (root.isFile() && endWith(root.getName(), exts)) {
items.add(new FileMeta(root.getPath()));
return;
} else if (root.isFile()) {
return;
}
File[] listFiles = root.listFiles();
if (listFiles == null) {
return;
}
for (File file : listFiles) {
if (file.isDirectory()) {
if (!findOnce && file.getPath().endsWith("/Android/data")) {
LOG.d("Skip path", file.getPath());
findOnce = true;
continue;
}
search(file, exts, items);
} else if (endWith(file.getName(), exts)) {
items.add(new FileMeta(file.getPath()));
}
}
return;
}
Aggregations