use of com.foobnix.sys.ClickUtils in project LibreraReader by foobnix.
the class HorizontalViewActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
intetrstialTimeoutSec = ADS.FULL_SCREEN_TIMEOUT_SEC;
LOG.d("getRequestedOrientation", AppState.get().orientation, getRequestedOrientation());
handler = new Handler();
handlerTimer = new Handler();
flippingHandler = new Handler();
flippingTimer = 0;
long crateBegin = System.currentTimeMillis();
requestWindowFeature(Window.FEATURE_NO_TITLE);
BrightnessHelper.applyBrigtness(this);
if (AppState.get().isDayNotInvert) {
setTheme(R.style.StyledIndicatorsWhite);
} else {
setTheme(R.style.StyledIndicatorsBlack);
}
DocumentController.doRotation(this);
clickUtils = new ClickUtils();
super.onCreate(savedInstanceState);
if (PasswordDialog.isNeedPasswordDialog(this)) {
return;
}
boolean isTextFomat = ExtUtils.isTextFomat(getIntent());
AppState.get().load(this);
// AppState.get().isCut = false;
PageImageState.get().isShowCuttingLine = false;
PageImageState.get().cleanSelectedWords();
setContentView(R.layout.activity_horiziontal_view);
Android6.checkPermissions(this);
viewPager = (VerticalViewPager) findViewById(R.id.pager);
overlay = findViewById(R.id.overlay);
overlay.setVisibility(View.VISIBLE);
progressDraw = (ProgressDraw) findViewById(R.id.progressDraw);
actionBar = (LinearLayout) findViewById(R.id.actionBar);
bottomBar = findViewById(R.id.bottomBar);
bottomIndicators = findViewById(R.id.bottomIndicators);
adFrame = findViewById(R.id.adFrame);
anchor = (FrameLayout) findViewById(R.id.anchor);
moveCenter = findViewById(R.id.moveCenter);
currentSeek = (TextView) findViewById(R.id.currentSeek);
maxSeek = (TextView) findViewById(R.id.maxSeek);
toastBrightnessText = (TextView) findViewById(R.id.toastBrightnessText);
toastBrightnessText.setVisibility(View.GONE);
TintUtil.setDrawableTint(toastBrightnessText.getCompoundDrawables()[0], Color.WHITE);
modeName = (TextView) findViewById(R.id.modeName);
modeName.setText(AppState.get().nameHorizontalMode);
pagesCountIndicator = (TextView) findViewById(R.id.pagesCountIndicator);
flippingIntervalView = (TextView) findViewById(R.id.flippingIntervalView);
pagesTime = (TextView) findViewById(R.id.pagesTime);
pagesPower = (TextView) findViewById(R.id.pagesPower);
linkHistory = (ImageView) findViewById(R.id.linkHistory);
onMove = (ImageView) findViewById(R.id.onMove);
onMove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DragingDialogs.onMoveDialog(anchor, dc, onRefresh, reloadDoc);
}
});
currentSeek.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Dialogs.showDeltaPage(anchor, dc, dc.getCurentPageFirst1(), onRefresh);
return true;
}
});
maxSeek.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Dialogs.showDeltaPage(anchor, dc, dc.getCurentPageFirst1(), onRefresh);
return true;
}
});
updateSeekBarColorAndSize();
titleTxt = (TextView) findViewById(R.id.title);
chapterView = (TextView) findViewById(R.id.chapter);
linkHistory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dc.onLinkHistory();
showHideHistory();
}
});
linkHistory.setVisibility(View.GONE);
seekBar = (SeekBar) findViewById(R.id.seekBar);
if (AppState.get().isRTL) {
if (Build.VERSION.SDK_INT >= 11) {
seekBar.setRotation(180);
}
}
onPageFlip1 = findViewById(R.id.autoScroll);
onPageFlip1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DragingDialogs.pageFlippingDialog(anchor, dc, onRefresh);
}
});
final ImageView onFullScreen = (ImageView) findViewById(R.id.onFullScreen);
onFullScreen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().isFullScreen = !AppState.get().isFullScreen;
onFullScreen.setImageResource(AppState.get().isFullScreen ? R.drawable.glyphicons_487_fit_frame_to_image : R.drawable.glyphicons_488_fit_image_to_frame);
DocumentController.chooseFullScreen(HorizontalViewActivity.this, AppState.get().isFullScreen);
if (dc.isTextFormat()) {
if (onRefresh != null) {
onRefresh.run();
}
nullAdapter();
dc.restartActivity();
}
}
});
onFullScreen.setImageResource(AppState.get().isFullScreen ? R.drawable.glyphicons_487_fit_frame_to_image : R.drawable.glyphicons_488_fit_image_to_frame);
ImageView dayNightButton = (ImageView) findViewById(R.id.bookNight);
dayNightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
v.setEnabled(false);
AppState.get().isDayNotInvert = !AppState.get().isDayNotInvert;
nullAdapter();
dc.restartActivity();
}
});
if (Dips.isEInk(this)) {
dayNightButton.setVisibility(View.GONE);
AppState.get().isDayNotInvert = true;
}
onBC = (UnderlineImageView) findViewById(R.id.onBC);
onBC.underline(AppState.get().isEnableBC);
onBC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.contrastAndBrigtness(anchor, dc, reloadDocBrigntness, reloadDoc);
}
});
dayNightButton.setImageResource(!AppState.get().isDayNotInvert ? R.drawable.glyphicons_232_sun : R.drawable.glyphicons_2_moon);
moveCenter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
authoFit();
}
});
onBC.setVisibility(isTextFomat ? View.GONE : View.VISIBLE);
if (DocumentController.isEinkOrMode(this)) {
onBC.setVisibility(View.VISIBLE);
}
onMove.setVisibility(DocumentController.isEinkOrMode(this) && !isTextFomat ? View.VISIBLE : View.GONE);
findViewById(R.id.thumbnail).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.thumbnailDialog(anchor, dc);
}
});
findViewById(R.id.onShowSearch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
showSearchDialog();
}
});
outline = (ImageView) findViewById(R.id.onDocDontext);
outline.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.showContent(anchor, dc);
}
});
findViewById(R.id.onBookmarks).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.addBookmarks(anchor, dc, new Runnable() {
@Override
public void run() {
showHideHistory();
}
});
}
});
findViewById(R.id.onBookmarks).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(final View arg0) {
DragingDialogs.addBookmarksLong(anchor, dc);
return true;
}
});
findViewById(R.id.onRecent).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.recentBooks(anchor, dc);
}
});
textToSpeach = (ImageView) findViewById(R.id.textToSpeach);
textToSpeach.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
LOG.d("bookTTS", AppState.get().isDoubleCoverAlone, AppState.get().isDouble, AppState.get().isCut);
if (AppState.get().isDouble || AppState.get().isCut) {
modeOnePage();
return;
}
DragingDialogs.textToSpeachDialog(anchor, dc);
}
});
ttsActive = (ImageView) findViewById(R.id.ttsActive);
onTTSStatus(null);
ttsActive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.textToSpeachDialog(anchor, dc);
}
});
ttsActive.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Vibro.vibrate();
TTSEngine.get().stop();
ttsActive.setVisibility(View.GONE);
return true;
}
});
onModeChange = (ImageView) findViewById(R.id.onModeChange);
onModeChange.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MyPopupMenu p = new MyPopupMenu(v.getContext(), v);
p.getMenu().add(R.string.one_page).setIcon(R.drawable.glyphicons_two_page_one).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_two_page_one);
AppState.get().isDouble = false;
AppState.get().isDoubleCoverAlone = false;
AppState.get().isCut = false;
SettingsManager.getBookSettings().updateFromAppState();
if (dc.isTextFormat()) {
nullAdapter();
dc.restartActivity();
dc.cleanImageMatrix();
} else {
TTSEngine.get().stop();
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
}
return false;
}
});
p.getMenu().add(R.string.two_pages).setIcon(R.drawable.glyphicons_two_pages_12).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_two_pages_12);
AppState.get().isDouble = true;
AppState.get().isCut = false;
AppState.get().isDoubleCoverAlone = false;
SettingsManager.getBookSettings().updateFromAppState();
if (dc.isTextFormat()) {
nullAdapter();
dc.restartActivity();
dc.cleanImageMatrix();
} else {
TTSEngine.get().stop();
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
}
return false;
}
});
if (!dc.isTextFormat()) {
p.getMenu().add(R.string.two_pages_cover).setIcon(R.drawable.glyphicons_two_pages_23).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_two_pages_23);
AppState.get().isDouble = true;
AppState.get().isCut = false;
AppState.get().isDoubleCoverAlone = true;
SettingsManager.getBookSettings().updateFromAppState();
if (dc.isTextFormat()) {
nullAdapter();
dc.restartActivity();
dc.cleanImageMatrix();
} else {
TTSEngine.get().stop();
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
}
return false;
}
});
}
if (!dc.isTextFormat()) {
p.getMenu().add(R.string.half_page).setIcon(R.drawable.glyphicons_page_split).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_page_split);
AppState.get().isDouble = false;
AppState.get().isCut = true;
// AppState.get().isCrop = false;
SettingsManager.getBookSettings().updateFromAppState();
TTSEngine.get().stop();
// onCrop.underline(AppState.get().isCrop);
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
return false;
}
});
}
p.show();
Keyboards.hideNavigation(HorizontalViewActivity.this);
}
});
onCrop = (UnderlineImageView) findViewById(R.id.onCrop);
onCrop.setVisibility(isTextFomat ? View.GONE : View.VISIBLE);
onCrop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().isCrop = !AppState.get().isCrop;
SettingsManager.getBookSettings().cropPages = AppState.get().isCrop;
reloadDoc.run();
onCrop.underline(AppState.get().isCrop);
PageImageState.get().isAutoFit = true;
EventBus.getDefault().post(new MessageAutoFit(viewPager.getCurrentItem()));
}
});
final View bookMenu = findViewById(R.id.bookMenu);
bookMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
ShareDialog.show(HorizontalViewActivity.this, dc.getCurrentBook(), new Runnable() {
@Override
public void run() {
if (dc.getCurrentBook().delete()) {
TempHolder.listHash++;
AppDB.get().deleteBy(dc.getCurrentBook().getPath());
dc.getActivity().finish();
}
}
}, dc.getCurentPage(), null, dc);
Keyboards.hideNavigation(HorizontalViewActivity.this);
}
});
modeName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
bookMenu.performClick();
}
});
modeName.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
dc.onChangeTextSelection();
AppState.get().isEditMode = false;
hideShow();
return true;
}
});
findViewById(R.id.bookPref).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.preferences(anchor, dc, onRefresh, reloadDoc);
}
});
onClose = findViewById(R.id.bookClose);
onClose.setVisibility(View.INVISIBLE);
onClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
nullAdapter();
closeDialogs();
showInterstial();
}
});
onClose.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(final View v) {
Vibro.vibrate();
CloseAppDialog.showOnLongClickDialog(HorizontalViewActivity.this, v, dc);
return true;
}
});
findViewById(R.id.editTop2).setVisibility(View.GONE);
findViewById(R.id.nextTypeBootom).setVisibility(View.GONE);
lockModelImage = (ImageView) findViewById(R.id.lockUnlock);
lockModelImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().isLocked = !AppState.get().isLocked;
updateLockMode();
}
});
updateLockMode();
Keyboards.hideNavigationOnCreate(HorizontalViewActivity.this);
currentSeek.setVisibility(View.GONE);
maxSeek.setVisibility(View.GONE);
seekBar.setVisibility(View.INVISIBLE);
bottomIndicators.setVisibility(View.GONE);
titleTxt.setText(HorizontalModeController.getTempTitle(this));
loadinAsyncTask = new CopyAsyncTask() {
AlertDialog dialog;
private boolean isCancelled = false;
long start = 0;
@Override
protected void onPreExecute() {
start = System.currentTimeMillis();
TempHolder.get().loadingCancelled = false;
dialog = Dialogs.loadingBook(HorizontalViewActivity.this, new Runnable() {
@Override
public void run() {
isCancelled = true;
TempHolder.get().loadingCancelled = true;
CacheZipUtils.removeFiles(CacheZipUtils.CACHE_BOOK_DIR.listFiles());
finish();
}
});
}
@Override
protected Object doInBackground(Object... params) {
try {
LOG.d("doRotation(this)", AppState.get().orientation, HorizontalViewActivity.this.getRequestedOrientation());
try {
while (viewPager.getHeight() == 0) {
Thread.sleep(250);
}
int count = 0;
if (AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
while (viewPager.getHeight() > viewPager.getWidth() && count < 20) {
Thread.sleep(250);
count++;
}
} else if (AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
while (viewPager.getWidth() > viewPager.getHeight() && count < 20) {
Thread.sleep(250);
count++;
}
}
} catch (InterruptedException e) {
}
LOG.d("viewPager", viewPager.getHeight() + "x" + viewPager.getWidth());
initAsync(viewPager.getWidth(), viewPager.getHeight());
} catch (MuPdfPasswordException e) {
return -1;
} catch (RuntimeException e) {
LOG.e(e);
return -2;
}
return 0;
}
@Override
protected void onCancelled() {
try {
if (dialog != null) {
dialog.dismiss();
}
} catch (Exception e) {
}
isCancelled = true;
}
@Override
protected void onPostExecute(Object result) {
if (LOG.isEnable) {
long time = System.currentTimeMillis() - start;
// modeName.setText("" + time / 1000);
}
try {
// onClose.setVisibility(View.VISIBLE);
LOG.d("RESULT", result);
if (dialog != null) {
dialog.dismiss();
}
} catch (Exception e) {
}
if (isCancelled) {
LOG.d("Cancelled");
finish();
return;
}
if ((Integer) result == -2) {
Toast.makeText(HorizontalViewActivity.this, R.string.msg_unexpected_error, Toast.LENGTH_SHORT).show();
AppState.get().isEditMode = true;
hideShow();
return;
}
if ((Integer) result == -1) {
final EditText input = new EditText(HorizontalViewActivity.this);
input.setSingleLine(true);
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
AlertDialog.Builder dialog = new AlertDialog.Builder(HorizontalViewActivity.this);
dialog.setTitle(R.string.enter_password);
dialog.setView(input);
dialog.setCancelable(false);
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
dc.onCloseActivityFinal(null);
}
});
dialog.setPositiveButton(R.string.open_file, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final String txt = input.getText().toString();
if (TxtUtils.isNotEmpty(txt)) {
dialog.dismiss();
dc.onCloseActivityFinal(new Runnable() {
@Override
public void run() {
getIntent().putExtra(HorizontalModeController.EXTRA_PASSWORD, txt);
startActivity(getIntent());
}
});
} else {
dc.onCloseActivityFinal(null);
}
}
});
AlertDialog show = dialog.show();
} else {
currentSeek.setVisibility(View.VISIBLE);
maxSeek.setVisibility(View.VISIBLE);
seekBar.setVisibility(View.VISIBLE);
bottomIndicators.setVisibility(View.VISIBLE);
onModeChange.setVisibility(View.VISIBLE);
dc.initHandler();
AppState.get().lastClosedActivity = HorizontalViewActivity.class.getSimpleName();
AppState.get().lastMode = HorizontalViewActivity.class.getSimpleName();
LOG.d("lasta save", AppState.get().lastClosedActivity);
PageImageState.get().isAutoFit = PageImageState.get().needAutoFit;
if (ExtUtils.isTextFomat(getIntent())) {
PageImageState.get().isAutoFit = true;
// moveCenter.setVisibility(View.GONE);
} else if (AppState.get().isLockPDF) {
// moveCenter.setVisibility(View.VISIBLE);
AppState.get().isLocked = true;
}
if (ExtUtils.isNoTextLayerForamt(dc.getCurrentBook().getPath())) {
TintUtil.setTintImageWithAlpha(textToSpeach, Color.LTGRAY);
}
if (dc.isTextFormat()) {
// TintUtil.setTintImage(lockModelImage, Color.LTGRAY);
}
loadUI();
// AppState.get().isEditMode = false; //remember last
updateUI(dc.getPageFromUri());
hideShow();
EventBus.getDefault().post(new MessageAutoFit(dc.getPageFromUri()));
seekBar.setOnSeekBarChangeListener(onSeek);
showHideInfoToolBar();
testScreenshots();
isInitPosistion = Dips.screenHeight() > Dips.screenWidth();
isInitOrientation = AppState.get().orientation;
updateIconMode();
onCrop.setVisibility(dc.isTextFormat() ? View.GONE : View.VISIBLE);
onMove.setVisibility(DocumentController.isEinkOrMode(HorizontalViewActivity.this) && !dc.isTextFormat() ? View.VISIBLE : View.GONE);
onBC.setVisibility(dc.isTextFormat() ? View.GONE : View.VISIBLE);
if (Dips.isEInk(dc.getActivity()) || AppState.get().isInkMode) {
onBC.setVisibility(View.VISIBLE);
}
onCrop.underline(AppState.get().isCrop);
onCrop.invalidate();
// RecentUpates.updateAll(HorizontalViewActivity.this);
}
}
};
loadinAsyncTask.executeOnExecutor(Executors.newSingleThreadExecutor());
updateIconMode();
BrightnessHelper.updateOverlay(overlay);
//
tinUI();
LOG.d("INIT end", (float) (System.currentTimeMillis() - crateBegin) / 1000);
anchor.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onGlobalLayout() {
if (anchor.getVisibility() == View.VISIBLE) {
adFrame.setVisibility(View.GONE);
adFrame.setClickable(false);
} else {
if (AppState.get().isEditMode) {
adFrame.setVisibility(View.VISIBLE);
adFrame.setClickable(true);
} else {
adFrame.setVisibility(View.GONE);
adFrame.setClickable(false);
}
}
if (Build.VERSION.SDK_INT >= 11) {
if (anchor.getX() < 0) {
anchor.setX(0);
}
if (anchor.getY() < 0) {
anchor.setY(0);
}
}
}
});
}
Aggregations