use of android.support.v7.widget.helper.ItemTouchHelper.END in project EasyPlayer-RTMP-Android by EasyDSS.
the class PlaylistActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.content_playlist);
// setContentView(R.layout.content_playlist);
setSupportActionBar(mBinding.toolbar);
mCursor = TheApp.sDB.query(VideoSource.TABLE_NAME, null, null, null, null, null, null);
if (!mCursor.moveToFirst()) {
ContentValues cv = new ContentValues();
cv.put(VideoSource.URL, "rtmp://live.hkstv.hk.lxdns.com/live/hks");
TheApp.sDB.insert(VideoSource.TABLE_NAME, null, cv);
mCursor.close();
mCursor = TheApp.sDB.query(VideoSource.TABLE_NAME, null, null, null, null, null, null);
}
mRecyclerView = mBinding.recycler;
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(new RecyclerView.Adapter() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new PlayListViewHolder((VideoSourceItemBinding) DataBindingUtil.inflate(getLayoutInflater(), R.layout.video_source_item, parent, false));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
PlayListViewHolder plvh = (PlayListViewHolder) holder;
mCursor.moveToPosition(position);
String name = mCursor.getString(mCursor.getColumnIndex(VideoSource.NAME));
String url = mCursor.getString(mCursor.getColumnIndex(VideoSource.URL));
if (!TextUtils.isEmpty(name)) {
plvh.mTextView.setText(name);
} else {
plvh.mTextView.setText(url);
}
File file = url2localPosterFile(PlaylistActivity.this, url);
Glide.with(PlaylistActivity.this).load(file).signature(new StringSignature(UUID.randomUUID().toString())).placeholder(R.drawable.placeholder).centerCrop().into(plvh.mImageView);
int audienceNumber = mCursor.getInt(mCursor.getColumnIndex(VideoSource.AUDIENCE_NUMBER));
if (audienceNumber > 0) {
plvh.mAudienceNumber.setText(String.format("当前观看人数:%d", audienceNumber));
plvh.mAudienceNumber.setVisibility(View.VISIBLE);
} else {
plvh.mAudienceNumber.setVisibility(View.GONE);
}
}
@Override
public int getItemCount() {
return mCursor.getCount();
}
});
if (savedInstanceState == null) {
startActivity(new Intent(this, SplashActivity.class));
}
if (!isPro()) {
mBinding.pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
doLoadData(true);
}
});
doLoadData(false);
mBinding.toolbarSetting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(PlaylistActivity.this, SettingsActivity.class));
}
});
} else {
mBinding.toolbarSetting.setVisibility(View.GONE);
mBinding.pullToRefresh.setEnabled(false);
}
mBinding.toolbarAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText edit = new EditText(PlaylistActivity.this);
edit.setHint(isPro() ? "RTSP/RTMP/HTTP/HLS地址" : "RTMP地址(格式为RTMP://...)");
final int hori = (int) getResources().getDimension(R.dimen.activity_horizontal_margin);
final int verti = (int) getResources().getDimension(R.dimen.activity_vertical_margin);
edit.setPadding(hori, verti, hori, verti);
// edit.setFilters(new InputFilter[]{new InputFilter() {
// @Override
// public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
// if (end-start == 0){
// return null;
// }
// Log.d(TAG, String.format("source:%s,start:%d,end:%d;dest:%s,dstart:%d,dend:%d", source, start,end, dest, dstart,dend));
// char[] chs = new char[dest.length()-(dend - dstart) + end-start];
// int i =0;
// int idx = 0;
// for (;i<dstart;i++){
// chs[idx++] = dest.charAt(i);
// }
//
// for (i = start;i<end;i++){
// chs[idx++] = source.charAt(i);
// }
// for (i=dend;i<dest.length();i++){
// chs[idx++] = dest.charAt(i);
// }
//
// String dst = new String(chs);
// dst = dst.toLowerCase();
// if ("rtsp://".indexOf(dst) == 0){
// return null;
// }else if (dst.indexOf("rtsp://") == 0){
// return null;
// }else{
// return "";
// }
// }
// }});
final AlertDialog dlg = new AlertDialog.Builder(PlaylistActivity.this).setView(edit).setTitle("请输入播放地址").setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String mRTSPUrl = String.valueOf(edit.getText());
if (TextUtils.isEmpty(mRTSPUrl)) {
return;
}
// if (!isPro()){
// if (mRTSPUrl.toLowerCase().indexOf("rtsp://")!=0){
// Toast.makeText(PlaylistActivity.this,"不是合法的RTSP地址,请重新添加.",Toast.LENGTH_SHORT).show();
// return;
// }
// }else{
// // if (mRTSPUrl.toLowerCase().indexOf("rtsp://")!=0 && mRTSPUrl.toLowerCase().indexOf("rtmp://")!=0 && mRTSPUrl.toLowerCase().indexOf("http://")!=0 && mRTSPUrl.toLowerCase().indexOf("https://")!=0&& mRTSPUrl.toLowerCase().indexOf("hls://")!=0){
// // Toast.makeText(PlaylistActivity.this,"不是合法的地址,请重新添加.",Toast.LENGTH_SHORT).show();
// // return;
// // }
// }
ContentValues cv = new ContentValues();
cv.put(VideoSource.URL, mRTSPUrl);
TheApp.sDB.insert(VideoSource.TABLE_NAME, null, cv);
mCursor.close();
mCursor = TheApp.sDB.query(VideoSource.TABLE_NAME, null, null, null, null, null, null);
mRecyclerView.getAdapter().notifyItemInserted(mCursor.getCount() - 1);
showOrHideEmptyView();
}
}).setNegativeButton("取消", null).create();
dlg.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edit, InputMethodManager.SHOW_IMPLICIT);
}
});
dlg.show();
}
});
mBinding.toolbarAbout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(PlaylistActivity.this, AboutActivity.class));
}
});
String url = "http://www.easydarwin.org/versions/easyplayer_rtmp/version.txt";
update = new UpdateMgr(this);
update.checkUpdate(url);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project SeniorProject by 5731075221-PM.
the class HospitalNearbyFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_hospital_nearby, container, false);
appBarLayout.setExpanded(true, true);
// searchView = (SearchView) view.findViewById(R.id.searchNearbyHospital);
// searchView.setIconifiedByDefault(false);
// searchView.setIconified(false);
// searchView.clearFocus();
// searchView.setQueryHint("ค้นหา");
// searchView.setOnQueryTextListener(this);
title = getActivity().findViewById(R.id.textTool);
title.setText("ค้นหาโรงพยาบาลใกล้เคียง");
recyclerView = (RecyclerView) view.findViewById(R.id.nearbyHospitalRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
adapter = new RecyclerViewAdapter(hosList);
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
adapter.setOnLoadMoreListener(new LoadMore() {
@Override
public void onLoadMore() {
if (hosList.size() <= hospitalList.size()) {
isLoading = true;
hosList.add(null);
adapter.notifyItemInserted(hosList.size() - 1);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
hosList.remove(hosList.size() - 1);
adapter.notifyItemRemoved(hosList.size());
// Generating more data
int index = hosList.size();
int end = index + 10;
for (int i = index; i < end; i++) {
hosList.add(hospitalList.get(i));
}
if (isGPS && isNetwork)
sortHospital();
adapter.notifyDataSetChanged();
isLoading = false;
// adapter.setLoaded();
}
}, 5000);
} else {
Toast.makeText(getActivity(), "Loading data completed", Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project Zom-Android by zom.
the class ConversationView method initViews.
protected void initViews() {
// mStatusIcon = (ImageView) mActivity.findViewById(R.id.statusIcon);
// mDeliveryIcon = (ImageView) mActivity.findViewById(R.id.deliveryIcon);
// mTitle = (TextView) mActivity.findViewById(R.id.title);
mHistory = (RecyclerView) mActivity.findViewById(R.id.history);
final LinearLayoutManager llm = new LinearLayoutManager(mHistory.getContext());
llm.setStackFromEnd(true);
mHistory.setLayoutManager(llm);
mHistory.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int visibleItemCount = llm.getChildCount();
int totalItemCount = llm.getItemCount();
int pastVisibleItems = llm.findFirstVisibleItemPosition();
if (pastVisibleItems + visibleItemCount >= totalItemCount) {
// End of list
mMessageAdapter.onScrollStateChanged(null, RecyclerView.SCROLL_STATE_IDLE);
} else
mMessageAdapter.onScrollStateChanged(null, RecyclerView.SCROLL_STATE_DRAGGING);
}
});
mComposeMessage = (EditText) mActivity.findViewById(R.id.composeMessage);
mSendButton = (ImageButton) mActivity.findViewById(R.id.btnSend);
mMicButton = (ImageButton) mActivity.findViewById(R.id.btnMic);
mButtonTalk = (TextView) mActivity.findViewById(R.id.buttonHoldToTalk);
mButtonDeleteVoice = (ImageView) mActivity.findViewById(R.id.btnDeleteVoice);
mViewDeleteVoice = mActivity.findViewById(R.id.viewDeleteVoice);
mButtonDeleteVoice.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
int resolvedColor = mHistory.getResources().getColor(android.R.color.holo_red_light);
mButtonDeleteVoice.setBackgroundColor(resolvedColor);
}
return false;
}
});
mButtonAttach = (ImageButton) mActivity.findViewById(R.id.btnAttach);
mViewAttach = mActivity.findViewById(R.id.attachPanel);
mButtonAttach.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleAttachMenu();
}
});
mActivity.findViewById(R.id.btnAttachPicture).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mViewAttach.setVisibility(View.INVISIBLE);
mActivity.startImagePicker();
}
});
mActivity.findViewById(R.id.btnTakePicture).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mViewAttach.setVisibility(View.INVISIBLE);
mActivity.startPhotoTaker();
}
});
mActivity.findViewById(R.id.btnAttachAudio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mViewAttach.setVisibility(View.INVISIBLE);
mActivity.startFilePicker("audio/*");
}
});
/**
* mActivity.findViewById(R.id.btnAttachFile).setOnClickListener(new View.OnClickListener() {
*
* @Override
* public void onClick(View v) {
* mActivity.startFilePicker();
* }
*
* });*
*/
mActivity.findViewById(R.id.btnAttachSticker).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleAttachMenu();
showStickers();
}
});
mMicButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// this is the tap to change to hold to talk mode
if (mMicButton.getVisibility() == View.VISIBLE) {
mComposeMessage.setVisibility(View.GONE);
mMicButton.setVisibility(View.GONE);
// Check if no view has focus:
View view = mActivity.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
mSendButton.setImageResource(R.drawable.ic_keyboard_black_36dp);
mSendButton.setVisibility(View.VISIBLE);
mButtonTalk.setVisibility(View.VISIBLE);
}
}
});
final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
// this is for recording audio directly from one press
mActivity.startAudioRecording();
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
if (mActivity.isAudioRecording()) {
// inViewInBounds(mMicButton, (int) motionEvent.getX(), (int) motionEvent.getY());
boolean send = true;
mActivity.stopAudioRecording(send);
}
return super.onSingleTapUp(e);
}
});
mMicButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}
});
mButtonTalk.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View btnTalk, MotionEvent theMotion) {
switch(theMotion.getAction()) {
case MotionEvent.ACTION_DOWN:
mActivity.startAudioRecording();
mButtonTalk.setText(mActivity.getString(R.string.recording_release));
mViewDeleteVoice.setVisibility(View.VISIBLE);
break;
case MotionEvent.ACTION_MOVE:
boolean inBounds = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
if (!inBounds)
mButtonTalk.setText(mActivity.getString(R.string.recording_delete));
else {
mButtonTalk.setText(mActivity.getString(R.string.recording_release));
mViewDeleteVoice.setVisibility(View.VISIBLE);
}
break;
case MotionEvent.ACTION_UP:
mButtonTalk.setText(mActivity.getString(R.string.push_to_talk));
boolean send = inViewInBounds(btnTalk, (int) theMotion.getX(), (int) theMotion.getY());
mActivity.stopAudioRecording(send);
mViewDeleteVoice.setVisibility(View.GONE);
break;
}
return true;
}
});
/**
* mHistory.setOnItemLongClickListener(new OnItemLongClickListener ()
* {
*
* @TargetApi(Build.VERSION_CODES.HONEYCOMB)
* @Override
* public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
*
* if (arg1 instanceof MessageView)
* {
*
* String textToCopy = ((MessageView)arg1).getLastMessage();
*
* int sdk = android.os.Build.VERSION.SDK_INT;
* if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
* android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
* clipboard.setText(textToCopy); //
* } else {
* android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
* android.content.ClipData clip = android.content.ClipData.newPlainText("chat",textToCopy);
* clipboard.setPrimaryClip(clip); //
* }
*
* Toast.makeText(mActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard), Toast.LENGTH_SHORT).show();
*
* return true;
*
* }
*
* return false;
* }
*
* });*
*/
mComposeMessage.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
sendTypingStatus(true);
return false;
}
});
mComposeMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
sendTypingStatus(hasFocus);
}
});
mComposeMessage.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
sendMessage();
return true;
case KeyEvent.KEYCODE_ENTER:
if (event.isAltPressed()) {
mComposeMessage.append("\n");
return true;
}
}
}
return false;
}
});
mComposeMessage.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null) {
if (event.isAltPressed()) {
return false;
}
}
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && imm.isActive(v)) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
sendMessage();
return true;
}
});
// TODO: this is a hack to implement BUG #1611278, when dispatchKeyEvent() works with
// the soft keyboard, we should remove this hack.
mComposeMessage.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int before, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int after) {
}
public void afterTextChanged(Editable s) {
doWordSearch();
userActionDetected();
}
});
mSendButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mComposeMessage.getVisibility() == View.VISIBLE)
sendMessage();
else {
mSendButton.setImageResource(R.drawable.ic_send_holo_light);
if (mLastSessionStatus == SessionStatus.ENCRYPTED)
mSendButton.setImageResource(R.drawable.ic_send_secure);
mSendButton.setVisibility(View.GONE);
mButtonTalk.setVisibility(View.GONE);
mComposeMessage.setVisibility(View.VISIBLE);
mMicButton.setVisibility(View.VISIBLE);
}
}
});
mMessageAdapter = new ConversationRecyclerViewAdapter(mActivity, null);
mHistory.setAdapter(mMessageAdapter);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project LibreraReader by foobnix.
the class DragingDialogs method preferences.
public static DragingPopup preferences(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
final int cssHash = BookCSS.get().toCssString().hashCode();
final int appHash = Objects.hashCode(AppState.get());
if (ExtUtils.isNotValidFile(controller.getCurrentBook())) {
DragingPopup dialog = new DragingPopup(R.string.preferences, anchor, PREF_WIDTH, PREF_HEIGHT) {
@Override
public View getContentView(final LayoutInflater inflater) {
TextView txt = new TextView(anchor.getContext());
txt.setText(R.string.file_not_found);
return txt;
}
};
return dialog;
}
DragingPopup dialog = new DragingPopup(R.string.preferences, anchor, PREF_WIDTH, PREF_HEIGHT) {
@Override
public View getContentView(final LayoutInflater inflater) {
View inflate = inflater.inflate(R.layout.dialog_prefs, null, false);
// TOP panel start
View topPanelLine = inflate.findViewById(R.id.topPanelLine);
View topPanelLineDiv = inflate.findViewById(R.id.topPanelLineDiv);
// topPanelLine.setVisibility(controller instanceof
// DocumentControllerHorizontalView ? View.VISIBLE : View.GONE);
topPanelLine.setVisibility(View.GONE);
topPanelLineDiv.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
inflate.findViewById(R.id.allBGConfig).setVisibility(Dips.isEInk(inflate.getContext()) ? View.GONE : View.VISIBLE);
View onRecent = inflate.findViewById(R.id.onRecent);
onRecent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
closeDialog();
DragingDialogs.recentBooks(anchor, controller);
}
});
final View onRotate = inflate.findViewById(R.id.onRotate);
onRotate.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT <= 10) {
Toast.makeText(anchor.getContext(), R.string.this_function_will_works_in_modern_android, Toast.LENGTH_SHORT).show();
return;
}
// closeDialog();
MenuBuilderM.addRotateMenu(onRotate, null, updateUIRefresh).show();
}
});
inflate.findViewById(R.id.onPageFlip).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
closeDialog();
DragingDialogs.pageFlippingDialog(anchor, controller, onRefresh);
}
});
ImageView brightness = (ImageView) inflate.findViewById(R.id.onBrightness);
brightness.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isDayNotInvert = !AppState.get().isDayNotInvert;
controller.restartActivity();
}
});
brightness.setImageResource(!AppState.get().isDayNotInvert ? R.drawable.glyphicons_232_sun : R.drawable.glyphicons_2_moon);
final ImageView isCrop = (ImageView) inflate.findViewById(R.id.onCrop);
// isCrop.setVisibility(controller.isTextFormat() ||
// AppState.get().isCut ? View.GONE : View.VISIBLE);
isCrop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isCrop = !AppState.get().isCrop;
SettingsManager.getBookSettings().updateFromAppState();
TintUtil.setTintImageWithAlpha(isCrop, !AppState.get().isCrop ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
updateUIRefresh.run();
}
});
TintUtil.setTintImageWithAlpha(isCrop, !AppState.get().isCrop ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
final ImageView bookCut = (ImageView) inflate.findViewById(R.id.bookCut);
// bookCut.setVisibility(controller.isTextFormat() ? View.GONE :
// View.VISIBLE);
bookCut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
closeDialog();
DragingDialogs.sliceDialog(anchor, controller, updateUIRefresh, new ResultResponse<Integer>() {
@Override
public boolean onResultRecive(Integer result) {
TintUtil.setTintImageWithAlpha(bookCut, !AppState.get().isCut ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
SettingsManager.getBookSettings().updateFromAppState();
EventBus.getDefault().post(new InvalidateMessage());
return false;
}
});
}
});
TintUtil.setTintImageWithAlpha(bookCut, !AppState.get().isCut ? TintUtil.COLOR_TINT_GRAY : Color.LTGRAY);
inflate.findViewById(R.id.onFullScreen).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isFullScreen = !AppState.get().isFullScreen;
DocumentController.chooseFullScreen(controller.getActivity(), AppState.get().isFullScreen);
if (controller.isTextFormat()) {
if (onRefresh != null) {
onRefresh.run();
}
controller.restartActivity();
}
}
});
View tts = inflate.findViewById(R.id.onTTS);
tts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
closeDialog();
DragingDialogs.textToSpeachDialog(anchor, controller);
}
});
final ImageView pin = (ImageView) inflate.findViewById(R.id.onPin);
pin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
AppState.get().isShowToolBar = !AppState.get().isShowToolBar;
pin.setImageResource(AppState.get().isShowToolBar ? R.drawable.glyphicons_336_pushpin : R.drawable.glyphicons_200_ban);
if (onRefresh != null) {
onRefresh.run();
}
}
});
pin.setImageResource(AppState.get().isShowToolBar ? R.drawable.glyphicons_336_pushpin : R.drawable.glyphicons_200_ban);
// TOP panel end
CheckBox isPreText = (CheckBox) inflate.findViewById(R.id.isPreText);
isPreText.setChecked(AppState.get().isPreText);
isPreText.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isPreText = isChecked;
}
});
isPreText.setVisibility(BookType.TXT.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
CheckBox isLineBreaksText = (CheckBox) inflate.findViewById(R.id.isLineBreaksText);
isLineBreaksText.setChecked(AppState.get().isLineBreaksText);
isLineBreaksText.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isLineBreaksText = isChecked;
}
});
isLineBreaksText.setVisibility(BookType.TXT.is(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
//
TextView moreSettings = (TextView) inflate.findViewById(R.id.moreSettings);
moreSettings.setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
inflate.findViewById(R.id.moreSettingsDiv).setVisibility(controller.isTextFormat() ? View.VISIBLE : View.GONE);
// View moreSettingsImage =
// inflate.findViewById(R.id.moreSettingsImage);
// moreSettingsImage.setVisibility(controller.isTextFormat() ?
// View.VISIBLE : View.GONE);
TxtUtils.underlineTextView(moreSettings).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
moreBookSettings(anchor, controller, onRefresh, updateUIRefresh);
}
});
TextView performanceSettings = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.performanceSettigns));
performanceSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
performanceSettings(anchor, controller, onRefresh, updateUIRefresh);
}
});
TextView statusBarSettings = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.statusBarSettings));
statusBarSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
statusBarSettings(anchor, controller, onRefresh, updateUIRefresh);
}
});
final CustomSeek fontSizeSp = (CustomSeek) inflate.findViewById(R.id.fontSizeSp);
fontSizeSp.init(10, 70, AppState.get().fontSizeSp);
fontSizeSp.setOnSeekChanged(new IntegerResponse() {
@Override
public boolean onResultRecive(int result) {
AppState.get().fontSizeSp = result;
return false;
}
});
fontSizeSp.setValueText("" + AppState.get().fontSizeSp);
inflate.findViewById(R.id.fontSizeLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
inflate.findViewById(R.id.fontNameSelectionLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
final TextView textFontName = (TextView) inflate.findViewById(R.id.textFontName);
textFontName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final List<FontPack> fontPacks = BookCSS.get().getAllFontsPacks();
MyPopupMenu popup = new MyPopupMenu(controller.getActivity(), v);
for (final FontPack pack : fontPacks) {
LOG.d("pack.normalFont", pack.normalFont);
popup.getMenu().add(pack.dispalyName, pack.normalFont).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
BookCSS.get().resetAll(pack);
TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
return false;
}
});
}
popup.show();
}
});
TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
final View moreFontSettings = inflate.findViewById(R.id.moreFontSettings);
moreFontSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FontDialog.show(controller.getActivity(), new Runnable() {
@Override
public void run() {
TxtUtils.underline(textFontName, BookCSS.get().displayFontName);
}
});
}
});
final View downloadFonts = inflate.findViewById(R.id.downloadFonts);
downloadFonts.setVisibility(FontExtractor.hasZipFonts() ? View.GONE : View.VISIBLE);
downloadFonts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FontExtractor.showDownloadFontsDialog(controller.getActivity(), downloadFonts, textFontName);
}
});
// crop
CheckBox isCropBorders = (CheckBox) inflate.findViewById(R.id.isCropBorders);
isCropBorders.setChecked(controller.isCropCurrentBook());
isCropBorders.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
controller.onCrop();
}
});
// volume
final CheckBox isReverseKyes = (CheckBox) inflate.findViewById(R.id.isReverseKyes);
isReverseKyes.setChecked(AppState.get().isReverseKeys);
isReverseKyes.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isReverseKeys = isChecked;
}
});
isReverseKyes.setEnabled(AppState.get().isUseVolumeKeys ? true : false);
CheckBox isUseVolumeKeys = (CheckBox) inflate.findViewById(R.id.isUseVolumeKeys);
isUseVolumeKeys.setChecked(AppState.get().isUseVolumeKeys);
isUseVolumeKeys.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
AppState.get().isUseVolumeKeys = isChecked;
isReverseKyes.setEnabled(AppState.get().isUseVolumeKeys ? true : false);
}
});
// orientation begin
final TextView screenOrientation = (TextView) inflate.findViewById(R.id.screenOrientation);
screenOrientation.setText(DocumentController.getRotationText());
TxtUtils.underlineTextView(screenOrientation);
screenOrientation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu menu = new PopupMenu(v.getContext(), v);
for (int i = 0; i < DocumentController.orientationIds.size(); i++) {
final int j = i;
final int name = DocumentController.orientationTexts.get(i);
menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().orientation = DocumentController.orientationIds.get(j);
screenOrientation.setText(DocumentController.orientationTexts.get(j));
TxtUtils.underlineTextView(screenOrientation);
DocumentController.doRotation(controller.getActivity());
return false;
}
});
}
menu.show();
}
});
// orientation end
BrightnessHelper.showBlueLigthDialogAndBrightness(controller.getActivity(), inflate, onRefresh);
// brightness end
// dicts
final TextView selectedDictionaly = (TextView) inflate.findViewById(R.id.selectedDictionaly);
selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
selectedDictionaly.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DialogTranslateFromTo.show(controller.getActivity(), new Runnable() {
@Override
public void run() {
selectedDictionaly.setText(DialogTranslateFromTo.getSelectedDictionaryUnderline());
}
});
}
});
((CheckBox) inflate.findViewById(R.id.isRememberDictionary)).setChecked(AppState.get().isRememberDictionary);
((CheckBox) inflate.findViewById(R.id.isRememberDictionary)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
AppState.get().isRememberDictionary = isChecked;
}
});
// Colors
TextView textCustomizeFontBGColor = (TextView) inflate.findViewById(R.id.textCustomizeFontBGColor);
if (AppState.get().isCustomizeBgAndColors || controller.isTextFormat()) {
textCustomizeFontBGColor.setText(R.string.customize_font_background_colors);
} else {
textCustomizeFontBGColor.setText(R.string.customize_background_color);
}
final ImageView onDayColorImage = (ImageView) inflate.findViewById(R.id.onDayColorImage);
final TextView textDayColor = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDayColor));
textDayColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isSolid = !AppState.get().isUseBGImageDay;
new ColorsDialog((FragmentActivity) controller.getActivity(), true, AppState.get().colorDayText, AppState.get().colorDayBg, false, isSolid, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
textDayColor.setTextColor(colorText);
textDayColor.setBackgroundColor(colorBg);
TintUtil.setTintImageWithAlpha(onDayColorImage, colorText);
AppState.get().colorDayText = colorText;
AppState.get().colorDayBg = colorBg;
ImageLoader.getInstance().clearDiskCache();
ImageLoader.getInstance().clearMemoryCache();
if (AppState.get().isUseBGImageDay) {
textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(true));
}
}
});
}
});
final ImageView onNigthColorImage = (ImageView) inflate.findViewById(R.id.onNigthColorImage);
final TextView textNigthColor = TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onNigthColor));
textNigthColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isSolid = !AppState.get().isUseBGImageNight;
new ColorsDialog((FragmentActivity) controller.getActivity(), false, AppState.get().colorNigthText, AppState.get().colorNigthBg, false, isSolid, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
textNigthColor.setTextColor(colorText);
textNigthColor.setBackgroundColor(colorBg);
TintUtil.setTintImageWithAlpha(onNigthColorImage, colorText);
AppState.get().colorNigthText = colorText;
AppState.get().colorNigthBg = colorBg;
if (AppState.get().isUseBGImageNight) {
textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(true));
}
}
});
}
});
final LinearLayout lc = (LinearLayout) inflate.findViewById(R.id.preColors);
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
textNigthColor.setTextColor(AppState.get().colorNigthText);
textNigthColor.setBackgroundColor(AppState.get().colorNigthBg);
textDayColor.setTextColor(AppState.get().colorDayText);
textDayColor.setBackgroundColor(AppState.get().colorDayBg);
if (AppState.get().isUseBGImageDay) {
textDayColor.setTextColor(Color.BLACK);
textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(true));
}
if (AppState.get().isUseBGImageNight) {
textNigthColor.setTextColor(Color.WHITE);
textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(true));
}
// lc.setVisibility(controller.isTextFormat() ||
// AppState.get().isCustomizeBgAndColors ? View.VISIBLE :
// View.GONE);
final int padding = Dips.dpToPx(3);
final Runnable colorsLine = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
lc.removeAllViews();
for (String line : AppState.get().readColors.split(";")) {
if (TxtUtils.isEmpty(line)) {
continue;
}
String[] split = line.split(",");
LOG.d("Split colors", split[0], split[1], split[2]);
String name = split[0];
final int bg = Color.parseColor(split[1]);
final int text = Color.parseColor(split[2]);
final boolean isDay = split[3].equals("0");
BorderTextView t1 = new BorderTextView(controller.getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
params.setMargins(padding, padding, padding, padding);
t1.setLayoutParams(params);
t1.setGravity(Gravity.CENTER);
t1.setBackgroundColor(bg);
if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
t1.setText(name);
t1.setTextColor(text);
t1.setTypeface(null, Typeface.BOLD);
}
t1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isDay) {
if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
AppState.get().colorDayText = text;
textDayColor.setTextColor(text);
}
AppState.get().colorDayBg = bg;
textDayColor.setBackgroundColor(bg);
AppState.get().isUseBGImageDay = false;
} else {
if (controller.isTextFormat() || AppState.get().isCustomizeBgAndColors) {
AppState.get().colorNigthText = text;
textNigthColor.setTextColor(text);
}
AppState.get().colorNigthBg = bg;
textNigthColor.setBackgroundColor(bg);
AppState.get().isUseBGImageNight = false;
}
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
}
});
lc.addView(t1);
}
// add DayBG
{
ImageView t1 = new ImageView(controller.getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
params.setMargins(padding, padding, padding, padding);
t1.setLayoutParams(params);
t1.setScaleType(ScaleType.FIT_XY);
t1.setImageDrawable(MagicHelper.getBgImageDayDrawable(false));
t1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
textDayColor.setTextColor(Color.BLACK);
textDayColor.setBackgroundDrawable(MagicHelper.getBgImageDayDrawable(false));
AppState.get().isUseBGImageDay = true;
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
}
});
lc.addView(t1, AppState.get().readColors.split(";").length / 2);
}
// add Night
{
ImageView t2 = new ImageView(controller.getActivity());
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(Dips.dpToPx(30), Dips.dpToPx(30));
params2.setMargins(padding, padding, padding, padding);
t2.setLayoutParams(params2);
t2.setScaleType(ScaleType.FIT_XY);
t2.setImageDrawable(MagicHelper.getBgImageNightDrawable(false));
t2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().colorNigthText = AppState.COLOR_WHITE;
AppState.get().colorNigthBg = AppState.COLOR_BLACK;
textNigthColor.setTextColor(Color.WHITE);
textNigthColor.setBackgroundDrawable(MagicHelper.getBgImageNightDrawable(false));
AppState.get().isUseBGImageNight = true;
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
}
});
lc.addView(t2);
}
}
};
colorsLine.run();
TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onDefaultColor)).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() {
AppState.get().readColors = AppState.READ_COLORS_DEAFAUL;
AppState.get().isUseBGImageDay = false;
AppState.get().isUseBGImageNight = false;
AppState.get().bgImageDayTransparency = AppState.DAY_TRANSPARENCY;
AppState.get().bgImageDayPath = MagicHelper.IMAGE_BG_1;
AppState.get().bgImageNightTransparency = AppState.NIGHT_TRANSPARENCY;
AppState.get().bgImageNightPath = MagicHelper.IMAGE_BG_1;
AppState.get().isCustomizeBgAndColors = false;
AppState.get().colorDayText = AppState.COLOR_BLACK;
AppState.get().colorDayBg = AppState.COLOR_WHITE;
textDayColor.setTextColor(AppState.COLOR_BLACK);
textDayColor.setBackgroundColor(AppState.COLOR_WHITE);
AppState.get().colorNigthText = AppState.COLOR_WHITE;
AppState.get().colorNigthBg = AppState.COLOR_BLACK;
textNigthColor.setTextColor(AppState.COLOR_WHITE);
textNigthColor.setBackgroundColor(AppState.COLOR_BLACK);
TintUtil.setTintImageWithAlpha(onDayColorImage, AppState.get().colorDayText);
TintUtil.setTintImageWithAlpha(onNigthColorImage, AppState.get().colorNigthText);
AppState.get().statusBarColorDay = AppState.TEXT_COLOR_DAY;
AppState.get().statusBarColorNight = AppState.TEXT_COLOR_NIGHT;
colorsLine.run();
}
});
}
});
inflate.findViewById(R.id.moreReadColorSettings).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(controller.getActivity());
builder.setTitle(R.string.customize);
final LinearLayout root = new LinearLayout(controller.getActivity());
root.setOrientation(LinearLayout.VERTICAL);
for (String line : AppState.get().readColors.split(";")) {
if (TxtUtils.isEmpty(line)) {
continue;
}
final String[] split = line.split(",");
LOG.d("Split colors", split[0], split[1], split[2]);
final String name = split[0];
final int bg = Color.parseColor(split[1]);
final int text = Color.parseColor(split[2]);
final boolean isDay = split[3].equals("0");
final LinearLayout child = new LinearLayout(controller.getActivity());
child.setOrientation(LinearLayout.HORIZONTAL);
child.setTag(line);
final TextView t1Img = new TextView(controller.getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(60), Dips.dpToPx(30));
params.setMargins(padding, padding, padding, padding);
t1Img.setLayoutParams(params);
t1Img.setGravity(Gravity.CENTER);
t1Img.setBackgroundColor(bg);
t1Img.setText(name);
t1Img.setTextColor(text);
t1Img.setTypeface(null, Typeface.BOLD);
t1Img.setTag(isDay);
TextView t0 = new TextView(controller.getActivity());
t0.setEms(1);
TextView t00 = new TextView(controller.getActivity());
t00.setEms(2);
final TextView t2BG = new TextView(controller.getActivity());
t2BG.setText(TxtUtils.underline(split[1]));
t2BG.setEms(5);
t2BG.setTag(bg);
final TextView t3Text = new TextView(controller.getActivity());
t3Text.setText(TxtUtils.underline(split[2]));
t3Text.setEms(5);
t3Text.setTag(text);
child.addView(t0);
child.addView(t1Img);
child.addView(t00);
child.addView(t2BG);
child.addView(t3Text);
child.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new ColorsDialog((FragmentActivity) controller.getActivity(), (Boolean) t1Img.getTag(), (Integer) t3Text.getTag(), (Integer) t2BG.getTag(), true, true, new ColorsDialogResult() {
@Override
public void onChooseColor(int colorText, int colorBg) {
t1Img.setTextColor(colorText);
t1Img.setBackgroundColor(colorBg);
t2BG.setText(TxtUtils.underline(MagicHelper.colorToString(colorBg)));
t3Text.setText(TxtUtils.underline(MagicHelper.colorToString(colorText)));
t2BG.setTag(colorBg);
t3Text.setTag(colorText);
String line = name + "," + MagicHelper.colorToString(colorBg) + "," + MagicHelper.colorToString(colorText) + "," + split[3];
child.setTag(line);
}
});
}
});
root.addView(child);
}
builder.setView(root);
builder.setNegativeButton(R.string.apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String res = "";
for (int i = 0; i < root.getChildCount(); i++) {
View childAt = root.getChildAt(i);
String line = (String) childAt.getTag();
res = res + line + ";";
}
AppState.get().readColors = res;
LOG.d("SAVE readColors", AppState.get().readColors);
colorsLine.run();
}
});
builder.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.show();
}
});
return inflate;
}
}.show(DragingPopup.PREF + "_preferences").setOnCloseListener(new Runnable() {
@Override
public void run() {
if (//
//
appHash != Objects.hashCode(AppState.get()) || (controller.isTextFormat() && cssHash != BookCSS.get().toCssString().hashCode())) {
if (onRefresh != null) {
onRefresh.run();
}
controller.restartActivity();
}
}
});
return dialog;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END 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;
}
Aggregations