This commit is contained in:
mwang 2019-04-14 23:17:31 +08:00
parent 3c4082162f
commit 06b5ae50fa
46 changed files with 485 additions and 1083 deletions

View File

@ -132,6 +132,8 @@ public class BookActivity extends Activity_base {
TextView tvTonglei;
@BindView(R.id.txtLatestUpdate)
TextView tvLastUpdate;
public Intent getSvrIntent(){
if(serviceIntent ==null){
serviceIntent= new Intent(this, ServiceDownload.class);
@ -155,15 +157,15 @@ public class BookActivity extends Activity_base {
@Override
protected void setupToolbar() {
super.setupToolbar();
toolbar.setTitleMarginBottom(1);
toolbar.setTitleTextAppearance(this,R.style.TitleText);
// toolbar.setTitleMarginBottom(1);
// toolbar.setTitleTextAppearance(this,R.style.TitleText);
toolbar.inflateMenu(R.menu.menu_book);//设置右上角的填充菜单
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int menuItemId = item.getItemId();
if (menuItemId == R.id.menuShelf) {
Toast.makeText(BookActivity.this,"show book shelf",Toast.LENGTH_LONG);
}
return true;
@ -189,8 +191,9 @@ public class BookActivity extends Activity_base {
checkPermission(BookActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE, EXTERNAL_STORAGE_REQ_CODE, "添加图书需要此权限,请允许");
}
pageFactory = PageFactory.getInstance();
// pageFactory.clear();
setBookInfo();//set title ,data from novel list
NetUtil.cancelRequest(mNovel.getNovelId());
getBookInfo();
}
@ -244,7 +247,7 @@ public class BookActivity extends Activity_base {
this.txtTitle.setText(mNovel.getName());
this.txtDesc2.setFullString(mNovel.getDesc ());
txtDesc2.setCollapsedLines(2);
// txtDesc2.setCollapsedLines(2);
// txtDesc2.setSuffixColor(R.color.colorPrimary);
// txtDesc2.setExpanded(false);
@ -266,7 +269,7 @@ public class BookActivity extends Activity_base {
Glide.with(BookActivity.this)
.load( Uri.decode(NetUtil.getCoverUrl(mNovel.getCover())))
.dontAnimate()
.error(R.mipmap.side_bg2)
// .error(R.mipmap.side_bg2)
.transform(new GaoSiTransForm(this, 50, 3)) // "14":模糊度"3":图片缩放3倍后再进行模糊
.into(imageViewHead);
@ -282,10 +285,14 @@ public class BookActivity extends Activity_base {
btnShelf.setText(title);
}
@OnClick({R.id.btnRead, R.id.btnCacheBook, R.id.btnShelf,R.id.llCate})
@OnClick({R.id.btnRead, R.id.btnCacheBook, R.id.btnShelf,R.id.llCate,R.id.btnFistPage})
void submitButton(View view) {
Intent intent;
switch (view.getId()) {
case R.id.btnFistPage:
intent = new Intent(BookActivity.this, Main2Activity.class);
startActivity(intent);;
break;
case R.id.btnRead:
readBook();
//testBook();
@ -300,7 +307,10 @@ public class BookActivity extends Activity_base {
shelfBook();
break;
case R.id.llCate:
Intent intent = new Intent(BookActivity.this, MarkActivity.class);
Log.d(TAG, String .format("prepareBook: current book %s, start to open book cate of %s" , mNovel.getName() , pageFactory.getNovle().getName()));
intent = new Intent(BookActivity.this, MarkActivity.class);
startActivity(intent);;
break;
}
@ -660,6 +670,13 @@ void onResponseProcess( String content ,String url){
protected void onResume() {
super.onResume();
registerReceiver(receiver,filter);
if(mNovel!=null && mNovel.getId()>0) {
mNovel = LitePal.find(Novel.class, mNovel.getId()); //更新最新进度
if((pageFactory.getNovle()==null || mNovel.getId() !=pageFactory.getNovle().getId())){
pageFactory.prepareBook(mNovel);
}
}
// View v =findViewById(R.id.head_img);
// v.measure(0,0);
// BlurKit.getInstance().blur(v, 20);

View File

@ -326,5 +326,7 @@ public abstract class BasicFragment extends Fragment {
}
public void reload() {
initViews();
}
}

View File

@ -3,6 +3,7 @@ package com.novelbook.android.Fragments;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
@ -48,7 +49,7 @@ public class BookMarkFragment extends BasicFragment {
}
bookMarksList = new ArrayList<>();
bookMarksList = LitePal.where("novelId = ?", novelId+"").find(BookMarks.class);
Log.d(TAG, "initData: bookmark size " +bookMarksList.size());
}
@Override
protected void fillData() {

View File

@ -13,6 +13,7 @@ import com.novelbook.android.R;
import com.novelbook.android.ReadActivity;
import com.novelbook.android.adapter.CatalogueAdapter;
import com.novelbook.android.db.Chapter;
import com.novelbook.android.db.DownloadTask;
import com.novelbook.android.db.Novel;
import com.novelbook.android.utils.PageFactory;
@ -33,13 +34,7 @@ public class CatalogFragment extends BasicFragment {
@BindView(R.id.lv_catalogue)
ListView lv_catalogue;
private ProgressDialog progressDialog;
private void showProgressDialog() {
if ( null == progressDialog) {
progressDialog =new ProgressDialog(getActivity());
}
progressDialog.show();
}
protected void processArguments(){
if (getArguments() != null) {
Bundle bundle = getArguments() ;
@ -50,13 +45,16 @@ public class CatalogFragment extends BasicFragment {
}
@Override
protected void fillData() {
catalogueList.addAll(pageFactory.getChapters());
CatalogueAdapter catalogueAdapter = new CatalogueAdapter(getContext(), catalogueList);
catalogueAdapter.setCharter(pageFactory.getCurrentChapter());
lv_catalogue.setAdapter(catalogueAdapter);
catalogueAdapter.notifyDataSetChanged();
}
private void dismissProgressDialog() {
if ( null != progressDialog) {
progressDialog.dismiss();
}
}
@Override
protected int getLayoutRes() {
return R.layout.fragment_catalog;
@ -64,8 +62,37 @@ public class CatalogFragment extends BasicFragment {
@Override
protected void initData() {
showProgressDialog(true,"请稍等");
pageFactory = PageFactory.getInstance();
catalogueList.addAll(pageFactory.getChapters());
Log.d(TAG, String .format("prepareBook: start to open book cate of %s" , pageFactory.getNovle().getName()));
new Thread() {
@Override
public void run() {
int slepttime = 0;
while (slepttime < 100 && pageFactory.isReadingCatalogs() && pageFactory.getChapters().size() == 0) {
try {
sleep(50);
slepttime++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if ( !pageFactory.isReadingCatalogs() && pageFactory.getChapters().size() == 0) {
handler.sendEmptyMessage(2);
}else{
handler.sendEmptyMessage(1);
}
// Toast.makeText(BookActivity.this,"已加入下载队列2",Toast.LENGTH_LONG).show();
}
}.start();
}
@ -76,7 +103,7 @@ public class CatalogFragment extends BasicFragment {
lv_catalogue.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
showProgressDialog();
showProgressDialog(true,"请稍等");
if(pageFactory.getPageWidget()==null){
Novel novel = pageFactory.getNovle();
if(novel!=null){
@ -87,7 +114,7 @@ public class CatalogFragment extends BasicFragment {
}else
pageFactory.changeChapter(position+1);
dismissProgressDialog();
hideProgress();
getActivity().finish();
}
});
@ -95,10 +122,7 @@ public class CatalogFragment extends BasicFragment {
@Override
protected void initViews() {
CatalogueAdapter catalogueAdapter = new CatalogueAdapter(getContext(), catalogueList);
catalogueAdapter.setCharter(pageFactory.getCurrentChapter());
lv_catalogue.setAdapter(catalogueAdapter);
catalogueAdapter.notifyDataSetChanged();
}
@Override

View File

@ -170,6 +170,14 @@ public class Fragment_Shelf extends BasicFragment {
// startActivity(intent);
}
});
Button btnCancel = bottomSheetDialog.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bottomSheetDialog.dismiss();
}
});
bottomSheetDialog.show();

View File

@ -3,24 +3,20 @@ package com.novelbook.android.Fragments;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.novelbook.android.R;
import com.novelbook.android.adapter.BandanAdapterNew;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netsubscribe.BookSubscribe;
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
import com.novelbook.android.utils.BandanAdapter;
import com.novelbook.android.adapter.BandanAdapter;
import com.novelbook.android.utils.Constants;
import com.novelbook.android.utils.GsonUtil;
import com.novelbook.android.utils.OnItemClickListener;
import org.json.JSONObject;
import java.util.List;
import butterknife.BindView;
@ -31,7 +27,7 @@ public class Fragment_bangdan extends BasicFragment {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private BandanAdapter mAdapter;
private BandanAdapterNew mAdapter;
private List<NovelBlock> mBlocks;
// private List<Novel> mData;
@BindView(R.id.rvBangdan)
@ -51,14 +47,14 @@ public class Fragment_bangdan extends BasicFragment {
if(mBlocks==null){
return;
}
mAdapter = new BandanAdapter(activity ,mBlocks,R.layout.recycle_list_item_bangdan,new OnItemClickListener()
mAdapter = new BandanAdapterNew(activity ,mBlocks,R.layout.recycle_list_item_bangdannew,new OnItemClickListener()
{
@Override
public void onItemClick(View view, int position)
{
showPaihangbang(mBlocks.get(position));
// showBookDetail(mBlocks.get(blockId).getNs().get(novelIndex));
// showPaihangbang(mBlocks.get(position));
// Toast.makeText(getActivity(),"待。。。。。做",Toast.LENGTH_LONG).show();
}
@ -71,7 +67,8 @@ public class Fragment_bangdan extends BasicFragment {
@Override
public void onLinearOutClick(View view, int blockId,int novelIndex) {
// Toast.makeText(activity, "book "+ bookId + " clicked", Toast.LENGTH_SHORT).show();
showBookDetail(mBlocks.get(blockId).getNs().get(novelIndex));
showPaihangbang(mBlocks.get(blockId));
// showBookDetail(mBlocks.get(blockId).getNs().get(novelIndex));
//showPaihangbang("分类名称" +position);
Log.d(TAG,String.format("clicked: position %s,lineId %s",novelIndex,blockId));

View File

@ -22,17 +22,24 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.novelbook.android.Fragments.BasicFragment;
import com.novelbook.android.Fragments.Fragment_Shelf;
import com.novelbook.android.Fragments.Fragment_bookStore;
import com.novelbook.android.Fragments.Fragment_paihang;
import com.novelbook.android.utils.Constants;
import org.litepal.util.Const;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
public class Main2Activity extends Activity_base
implements NavigationView.OnNavigationItemSelectedListener{//} , BasicFragment.OnFragmentInteractionListener {
public MyApp app ;
@ -45,6 +52,8 @@ public class Main2Activity extends Activity_base
NavigationView navigationView;
@BindView(R.id.navigation )
BottomNavigationView botoomNavigation;
@BindView(R.id.rgSex)
RadioGroup rgSex;
@Override
public int getLayoutRes() {
@ -285,8 +294,8 @@ private int bottomSelectedIndex;
// toggle.setDrawerIndicatorEnabled(showToggle);
// toggle.syncState();
spinner.setVisibility( showSpinner?View.VISIBLE:View.GONE);
//spinner.setVisibility( showSpinner?View.VISIBLE:View.GONE);
rgSex.setVisibility( showSpinner?View.VISIBLE:View.GONE);
supportInvalidateOptionsMenu();
//invalidateOptionsMenu();
@ -410,6 +419,37 @@ private int bottomSelectedIndex;
}
@OnClick({R.id.radioButtonBoy,R.id.radioButtonGirl})
void Onclick(View view){
int s;
switch (view.getId()) {
case R.id.radioButtonBoy:
s = rgSex.getCheckedRadioButtonId() == R.id.radioButtonBoy ?1:0;
if(s!= Constants.SEX){
Constants.SEX=s;
Fragment current = getSupportFragmentManager().findFragmentById(R.id.realtabcontent);
if (current != null && current instanceof BasicFragment){
((BasicFragment)current).reload();
}
}
break;
case R.id.radioButtonGirl:
s = rgSex.getCheckedRadioButtonId() == R.id.radioButtonBoy ?1:0;
if(s!= Constants.SEX){
Constants.SEX=s;
Fragment current = getSupportFragmentManager().findFragmentById(R.id.realtabcontent);
if (current != null && current instanceof BasicFragment){
((BasicFragment)current).reload();
}
}
break;
}
}
public void hideBottomNavi(){
botoomNavigation.setVisibility(View.GONE);
}

View File

@ -1,17 +1,21 @@
package com.novelbook.android;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.design.widget.AppBarLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import com.astuetz.PagerSlidingTabStrip;
import com.flyco.tablayout.SlidingTabLayout;
import com.novelbook.android.adapter.MyPagerAdapter;
import com.novelbook.android.db.Chapter;
import com.novelbook.android.db.Novel;
import com.novelbook.android.utils.FileUtils;
import com.novelbook.android.utils.PageFactory;
@ -22,15 +26,17 @@ import butterknife.BindView;
public class MarkActivity extends Activity_base {
private static final String TAG = MarkActivity.class.getSimpleName();
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.appbar)
AppBarLayout appbar;
@BindView(R.id.tabs)
PagerSlidingTabStrip tabs;
@BindView(R.id.pager)
ViewPager pager;
@BindView(R.id.tab_layout)
SlidingTabLayout tabLayout;
// @Bind(R.id.lv_catalogue)
// ListView lv_catalogue;
@ -40,6 +46,7 @@ public class MarkActivity extends Activity_base {
private ArrayList<Chapter> catalogueList = new ArrayList<>();
private DisplayMetrics dm;
private String EXTR_BOOK ="book";
@Override
public int getLayoutRes() {
return R.layout.zactivity_mark;
@ -58,6 +65,8 @@ public class MarkActivity extends Activity_base {
@Override
protected void initData() {
pageFactory = PageFactory.getInstance();
Log.d(TAG, "prepareBook: pagefactory.mbook is ?" + (pageFactory.getNovle() .getName()) );
config = Config.getInstance();
dm = getResources().getDisplayMetrics();
typeface = config.getTypeface();
@ -72,37 +81,15 @@ public class MarkActivity extends Activity_base {
}
});
if (getSupportActionBar() != null) {
// getSupportActionBar().setTitle(pageFactory.getBookName());
getSupportActionBar().setTitle(pageFactory.getBookName());
}
setTabsValue();
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(),0));
tabs.setViewPager(pager);
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(),pageFactory.getNovle().getId()));
tabLayout.setViewPager(pager);
}
private void setTabsValue() {
// 设置Tab是自动填充满屏幕的
tabs.setShouldExpand(true);//所有初始化要在setViewPager方法之前
// 设置Tab的分割线是透明的
tabs.setDividerColor(Color.TRANSPARENT);
// 设置Tab底部线的高度
tabs.setUnderlineHeight((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 1, dm));
// 设置Tab Indicator的高度
tabs.setIndicatorHeight((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 2, dm));
// 设置Tab标题文字的大小
tabs.setTextSize((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 16, dm));
//设置Tab标题文字的字体
tabs.setTypeface(typeface,0);
// 设置Tab Indicator的颜色
tabs.setIndicatorColor(getResources().getColor(R.color.colorAccent));
// 取消点击Tab时的背景色
tabs.setTabBackground(0);
// pagerSlidingTabStrip.setDividerPadding(18);
}
protected void initListener() {

View File

@ -521,13 +521,14 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
bookMarks.setText(word);
bookMarks.setNovelId(pageFactory.getNovle().getId());
bookMarks.setChapt(pageFactory.getCurrentChapter());
bookMarks.setChaptName(((pageFactory.getChapters().get(bookMarks.getChapt()).getChapterName())));
bookMarks.setChaptName(((pageFactory.getChapters().get(bookMarks.getChapt()-1).getChapterName())));
bookMarks.save();
Toast.makeText(ReadActivity.this, "书签添加成功", Toast.LENGTH_SHORT).show();
} catch (SQLException e) {
Toast.makeText(ReadActivity.this, "该书签已存在", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(ReadActivity.this, "添加书签失败", Toast.LENGTH_SHORT).show();
}
}

View File

@ -1,4 +1,4 @@
package com.novelbook.android.utils;
package com.novelbook.android.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
@ -12,6 +12,8 @@ import android.widget.TextView;
import com.novelbook.android.R;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.utils.ImageUtil;
import com.novelbook.android.utils.OnItemClickListener;
import java.util.ArrayList;
import java.util.List;

View File

@ -0,0 +1,175 @@
package com.novelbook.android.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.novelbook.android.R;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.utils.ImageUtil;
import com.novelbook.android.utils.OnItemClickListener;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class BandanAdapterNew extends RecyclerView.Adapter<BandanAdapterNew.MyViewHolder> {
private final int EMPTY_VIEW = 1;
private final int PROGRESS_VIEW = 2;
private final int IMAGE_VIEW = 3;
private Context context;
private List<NovelBlock> mDatas = new ArrayList<NovelBlock>();
private OnItemClickListener mOnItemClickLitener;
private int listItemID;
public BandanAdapterNew(Context context, List<NovelBlock> mDatas, int listItemID, OnItemClickListener clickLitener) {
this.context = context;
this.mDatas = mDatas;
this.mOnItemClickLitener = clickLitener;
this.listItemID = listItemID;
}
public BandanAdapterNew(Context context, OnItemClickListener clickLitener) {
this.context = context;
this.mOnItemClickLitener = clickLitener;
}
@Override
public int getItemViewType(int position) {
if(mDatas.size() == 0){
return EMPTY_VIEW;
} else if(mDatas.get(position) == null){
return PROGRESS_VIEW;
} else {
return super.getItemViewType(position);
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
context).inflate(listItemID, parent,
false));
return holder;
}
public void setParameters(List<NovelBlock> mDatas,int listItemID ) {
this.mDatas = mDatas;
this.listItemID = listItemID;
}
public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener)
{
this.mOnItemClickLitener = mOnItemClickLitener;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position)
{
NovelBlock nb = mDatas.get(position);
holder.tvCateName.setText(nb.getName());
if(nb==null){return;}
String nvs = "";
String pic ="";
for(Novel nv : nb.getNs()) {
if (nv != null) {
nvs +=TextUtils.isEmpty(nvs)?nv.getName() : " " + nv.getName();
if(TextUtils.isEmpty(pic)) {
pic = nv.getCover();
}
}
}
holder.tvNoves.setText(nvs);
ImageUtil.loadImage(context,pic,holder.imageView);
// 如果设置了回调则设置点击事件
if (mOnItemClickLitener != null)
{
holder.itemView.setOnClickListener(new View.OnClickListener() //show more cate paihang
{
@Override
public void onClick(View v)
{
int pos = holder.getLayoutPosition();
mOnItemClickLitener.onItemClick(holder.itemView, pos);
}
});
holder.itemView.setOnLongClickListener(new View.OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
int pos = holder.getLayoutPosition();
mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
return false;
}
});
holder.ll1.setOnClickListener(new View.OnClickListener() { //show bookdetail
@Override
public void onClick(View v)
{
int pos = position;
mOnItemClickLitener.onLinearOutClick(holder.itemView, pos,0);
}
});
}
}
@Override
public int getItemCount()
{
return mDatas.size();
}
public void addData(int position) {
// mDatas.add(position, "Insert One");
notifyItemInserted(position);
}
public void removeData(int position) {
mDatas.remove(position);
notifyItemRemoved(position);
}
class MyViewHolder extends RecyclerView.ViewHolder
{
@BindView(R.id.ll1)
LinearLayout ll1;
@BindView(R.id.tvCateName)
TextView tvCateName;
@BindView(R.id.imageView)
ImageView imageView;
@BindView(R.id.tvNovels)
TextView tvNoves;
public MyViewHolder(View view)
{
super(view);
ButterKnife.bind(this, view);
//tvTitle = (TextView) view.findViewById(R.id.title);
// tvAuthor = (TextView) view.findViewById(R.id.author);
}
}
}

View File

@ -1,286 +0,0 @@
package com.novelbook.android.adapter;
import android.content.Context;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import com.novelbook.android.Config;
import com.novelbook.android.R;
import com.novelbook.android.db.Novel;
import com.novelbook.android.view.DragGridListener;
import com.novelbook.android.view.DragGridView;
import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;
import org.litepal.exceptions.DataSupportException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ShelfAdapter extends BaseAdapter implements DragGridListener {
private Context mContex;
private List<Novel> bilist;
private static LayoutInflater inflater = null;
private int mHidePosition = -1;
private Typeface typeface;
protected List<AsyncTask<Void, Void, Boolean>> myAsyncTasks = new ArrayList<>();
private int[] firstLocation;
private Config config;
public ShelfAdapter(Context context, List<Novel> bilist){
this.mContex = context;
this.bilist = bilist;
config = Config.getInstance();
typeface = config.getTypeface();
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
//背景书架的draw需要用到item的高度
if(bilist.size() < 10){
return 10;
}else{
return bilist.size();
}
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return bilist.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View contentView, ViewGroup arg2) {
// TODO Auto-generated method stub
final ViewHolder viewHolder;
if (contentView == null) {
contentView = inflater.inflate(R.layout.zshelfitem, null);
viewHolder = new ViewHolder(contentView);
viewHolder.name.setTypeface(typeface);
contentView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) contentView.getTag();
}
if(bilist.size() > position){
//DragGridView 解决复用问题
if(position == mHidePosition){
contentView.setVisibility(View.INVISIBLE);
}else {
contentView.setVisibility(View.VISIBLE);
}
if (DragGridView.getShowDeleteButton()) {
viewHolder.deleteItem_IB.setVisibility(View.VISIBLE);
}else {
viewHolder.deleteItem_IB.setVisibility(View.INVISIBLE);
}
viewHolder.name.setVisibility(View.VISIBLE);
String fileName = bilist.get(position).getName();
viewHolder.name.setText(fileName);
}else {
contentView.setVisibility(View.INVISIBLE);
}
return contentView;
}
static class ViewHolder {
@BindView(R.id.ib_close)
ImageButton deleteItem_IB;
@BindView(R.id.tv_name)
TextView name;
public ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
/**
* Drag移动时item交换数据,并在数据库中更新交换后的位置数据
* @param oldPosition
* @param newPosition
*/
@Override
public void reorderItems(int oldPosition, int newPosition) {
Novel temp = bilist.get(oldPosition);
List<Novel> bookLists1 = new ArrayList<>();
bookLists1 = LitePal.findAll(Novel.class);
int tempId = bookLists1.get(newPosition).getId();
// Log.d("oldposotion is",oldPosition+"");
// Log.d("newposotion is", newPosition + "");
if(oldPosition < newPosition){
for(int i=oldPosition; i<newPosition; i++){
//获得交换前的ID,必须是数据库的真正的ID如果使用bilist获取id是错误的因为bilist交换后id是跟着交换的
List<Novel> bookLists = new ArrayList<>();
bookLists = LitePal.findAll(Novel.class);
int dataBasesId = bookLists.get(i).getId();
Collections.swap(bilist, i, i + 1);
updateBookPosition(i,dataBasesId, bilist);
}
}else if(oldPosition > newPosition){
for(int i=oldPosition; i>newPosition; i--) {
List<Novel> bookLists = new ArrayList<>();
bookLists = LitePal.findAll(Novel.class);
int dataBasesId = bookLists.get(i).getId();
Collections.swap(bilist, i, i - 1);
updateBookPosition(i,dataBasesId,bilist);
}
}
bilist.set(newPosition, temp);
updateBookPosition(newPosition, tempId, bilist);
}
/**
* 两个item数据交换结束后把不需要再交换的item更新到数据库中
* @param position
* @param bookLists
*/
public void updateBookPosition (int position,int databaseId,List<Novel> bookLists) {
Novel book = new Novel();
String bookpath = bookLists.get(position).getNovelPath();
String bookname = bookLists.get(position).getName();
book.setNovelPath(bookpath);
book.setName(bookname);
book.setLastReadPos(bookLists.get(position).getLastReadPos());
book.setLastReadChapt(bookLists.get(position).getLastReadChapt());
book.setCharset(bookLists.get(position).getCharset());
//开线程保存改动的数据到数据库
//使用litepal数据库框架update时每次只能update一个id中的一条信息如果相同则不更新
upDateBookToSqlite3(databaseId , book);
}
/**
* 隐藏item
* @param hidePosition
*/
@Override
public void setHideItem(int hidePosition) {
this.mHidePosition = hidePosition;
notifyDataSetChanged();
}
/**
* 删除书本
* @param deletePosition
*/
@Override
public void removeItem(int deletePosition) {
String bookpath = bilist.get(deletePosition).getNovelPath();
LitePal.deleteAll(Novel.class, "bookpath = ?", bookpath);
bilist.remove(deletePosition);
// Log.d("删除的书本是", bookpath);
notifyDataSetChanged();
}
public void setBookList(List<Novel> bookLists){
this.bilist = bookLists;
notifyDataSetChanged();
}
/**
* Book打开后位置移动到第一位
* @param openPosition
*/
@Override
public void setItemToFirst(int openPosition) {
List<Novel> bookLists1 = new ArrayList<>();
bookLists1 = LitePal.findAll(Novel.class);
int tempId = bookLists1.get(0).getId();
Novel temp = bookLists1.get(openPosition);
// Log.d("setitem adapter ",""+openPosition);
if(openPosition!=0) {
for (int i = openPosition; i > 0 ; i--) {
List<Novel> bookListsList = new ArrayList<>();
bookListsList = LitePal.findAll(Novel.class);
int dataBasesId = bookListsList.get(i).getId();
Collections.swap(bookLists1, i, i - 1);
updateBookPosition(i, dataBasesId, bookLists1);
}
bookLists1.set(0, temp);
updateBookPosition(0, tempId, bookLists1);
for (int j = 0 ;j<bookLists1.size();j++) {
String bookpath = bookLists1.get(j).getNovelPath();
// Log.d("移动到第一位",bookpath);
}
}
notifyDataSetChanged();
}
@Override
public void nitifyDataRefresh() {
notifyDataSetChanged();
}
public void putAsyncTask(AsyncTask<Void, Void, Boolean> asyncTask) {
myAsyncTasks.add(asyncTask.execute());
}
/**
* 数据库书本信息更新
* @param databaseId 要更新的数据库的书本ID
* @param bookList
*/
public void upDateBookToSqlite3(final int databaseId,final Novel bookList) {
putAsyncTask(new AsyncTask<Void, Void, Boolean>() {
@Override
protected void onPreExecute() {
}
@Override
protected Boolean doInBackground(Void... params) {
try {
bookList.update(databaseId);
} catch (DataSupportException e) {
return false;
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
} else {
Log.d("保存到数据库结果-->", "失败");
}
}
});
}
}

View File

@ -174,6 +174,7 @@ public class HttpMethods {
// .addHeader("Content-Type", "application/json; charset=utf-8")
.addHeader("Device", "Android")
.removeHeader("User-Agent").addHeader("User-Agent",NetUtil.getUserAgent()) // 随机agent
.tag(NetUtil.currentRequestTag)
.method(originalRequest.method(), originalRequest.body());
// requestBuilder.addHeader("Authorization", "Bearer" + BaseConstant.TOKEN);//添加请求头信息服务器进行token有效性验证

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import com.novelbook.android.MyApp;
@ -19,6 +20,8 @@ import okhttp3.Call;
*/
public class NetUtil {
private static final String TAG= NetUtil.class.getSimpleName();
public static int currentRequestTag =0;
/**
* 判断是否有网络连接
*
@ -90,16 +93,21 @@ public class NetUtil {
return -1;
}
public static void cancelRequest(String tag) {
public static void cancelRequest(int tag) {
currentRequestTag =tag;
for (Call call : HttpMethods.getOkClient().dispatcher().queuedCalls()) {
if (call.request().tag().equals(tag))
Log.d(TAG, String.format("cancelRequest: queuedCalls ,request url %s, request TAG %s ,current Tag ",call.request().url(), call.request().tag(),tag));
if (!call.request().tag().equals(tag))
call.cancel();
}
//B) go through the running calls and cancel if the tag matches:
for (Call call : HttpMethods.getOkClient().dispatcher().runningCalls()) {
if (call.request().tag().equals(tag))
Log.d(TAG, String.format("cancelRequest: request url %s, request TAG %s ,current Tag %s",call.request().url(), call.request().tag(),tag));
if (call.request().tag()!=null && !call.request().tag().equals(tag)) {
call.cancel();
Log.d(TAG, String.format("cancelRequest: request url %s, request TAG %s ,current Tag %s, canceled.",call.request().url(), call.request().tag(),tag));
}
}
}

View File

@ -66,6 +66,10 @@ public class BookUtil {
this.mContext = context;
}
public boolean isReadingCatalogs() {
return mMuluStatus == MuluStatus.isDownloading;
}
//存储的字符数
public static final int cachedSize = 30000;
// protected final ArrayList<WeakReference<char[]>> myArray = new ArrayList<>();
@ -102,7 +106,9 @@ public class BookUtil {
public void setNovel(Novel novel) {
this.mNovel = novel;
}
public Novel getNovel( ) {
return mNovel ;
}
//当前目录网站列表
private NovelSites mNovelSites;
//当前目录网站

View File

@ -555,8 +555,15 @@ public class PageFactory {
public void prepareBook(Novel book){
if(mBook!=null &&mBook.getNovelId() !=book.getNovelId()){ //取消未上本书完成的web请求待验证效果
NetUtil.cancelRequest(mBook.getNovelId()+"" );
try {
NetUtil.cancelRequest(mBook.getNovelId() );
}catch (Exception e)
{
Log.e(TAG, "prepareBook: error on canceling request "+e.getMessage());
e.printStackTrace();
}
}
Log.d(TAG, "prepareBook: .start prepare book " + book.getName());
this.mBook = book ;
mBookUtil = new BookUtil();
//this.mBookUtil.setContext(context);
@ -580,7 +587,7 @@ public class PageFactory {
initBg(config.getDayOrNight());
if(mBook!=null &&mBook.getNovelId() !=book.getNovelId()){ //取消未上本书完成的web请求
NetUtil.cancelRequest(mBook.getNovelId()+"" );
NetUtil.cancelRequest(mBook.getNovelId() );
}
this.mBook = book ;
@ -1091,6 +1098,8 @@ public class PageFactory {
}
public void clear(){
Log.d(TAG, String .format("prepareBook: clearing book info %s" , getNovle().getName()));
//mBookUtil=null;
currentChapter = 0;
bookPath = "";
bookName = "";
@ -1122,15 +1131,17 @@ public class PageFactory {
public List<Chapter> getChapters(){
return mBookUtil.getChapters();
}
public boolean isReadingCatalogs(){
return mBookUtil.isReadingCatalogs();
}
public String getBookPath(){
return bookPath;
}
public String getBookName(){
return mBook.getName();
return getNovle().getName();
}
public Novel getNovle(){
return mBook;
return mBookUtil.getNovel();
}
//是否是第一页
public boolean isfirstPage() {

View File

@ -1,678 +0,0 @@
package com.novelbook.android.view;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import com.novelbook.android.R;
import com.novelbook.android.utils.CommonUtil;
import java.util.LinkedList;
import java.util.List;
public class DragGridView extends GridView implements View.OnClickListener{
/**
* DragGridView的item长按响应的时间 默认是1000毫秒也可以自行设置
*/
private long dragResponseMS = 1000;
/**
* 是否可以拖拽默认不可以
*/
private boolean isDrag = false;
private int mDownX;
private int mDownY;
private int moveX;
private int moveY;
/**
* 正在拖拽的position
*/
private int mDragPosition;
/**
* 刚开始拖拽的item对应的View
*/
private View mStartDragItemView = null;
/**
* 用于拖拽的镜像这里直接用一个ImageView
*/
private ImageView mDragImageView;
/**
* 震动器
*/
private Vibrator mVibrator;
private WindowManager mWindowManager;
/**
* item镜像的布局参数
*/
private WindowManager.LayoutParams mWindowLayoutParams;
/**
* 我们拖拽的item对应的Bitmap
*/
private Bitmap mDragBitmap;
/**
* 按下的点到所在item的上边缘的距离
*/
private int mPoint2ItemTop ;
/**
* 按下的点到所在item的左边缘的距离
*/
private int mPoint2ItemLeft;
/**
* DragGridView距离屏幕顶部的偏移量
*/
private int mOffset2Top;
/**
* DragGridView距离屏幕左边的偏移量
*/
private int mOffset2Left;
/**
* 状态栏的高度
*/
private int mStatusHeight;
/**
* DragGridView自动向下滚动的边界值
*/
private int mDownScrollBorder;
/**
* DragGridView自动向上滚动的边界值
*/
private int mUpScrollBorder;
/**
* DragGridView自动滚动的速度
*/
private static final int speed = 20;
private boolean mAnimationEnd = true;
private DragGridListener mDragAdapter;
private int mNumColumns;
private int mColumnWidth;
private boolean mNumColumnsSet;
private int mHorizontalSpacing;
private Bitmap background;
private Bitmap bookshelf_dock;
private boolean touchable = true;
private ImageButton mDeleteButton;
private static boolean isShowDeleteButton = false;
private static boolean isMove = false;
private Context mcontext;
private View firtView;
private TextView firstItemTextView;
private final int[] firstLocation = new int[2];
private int i = 0;
public DragGridView(Context context) {
this(context, null);
}
public DragGridView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public DragGridView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mStatusHeight = getStatusHeight(context);
background = BitmapFactory.decodeResource(getResources(),
R.mipmap.bookshelf_layer_center);
bookshelf_dock = BitmapFactory.decodeResource(getResources(),R.mipmap.bookshelf_dock);
if(!mNumColumnsSet){
mNumColumns = AUTO_FIT;
}
mcontext = context;
}
private Handler mHandler = new Handler();
//用来处理是否为长按的Runnable
private Runnable mLongClickRunnable = new Runnable() {
@Override
public void run() {
isDrag = true; //设置可以拖拽
mVibrator.vibrate(50); //震动一下
mStartDragItemView.setVisibility(View.INVISIBLE);//隐藏该item
//根据我们按下的点显示item镜像
createDragImage(mDragBitmap, mDownX, mDownY);
setIsShowDeleteButton(true);
for (int i = 0;i < getChildCount();i++) {
final View mGridItemView = getChildAt(i);
mDeleteButton = (ImageButton) mGridItemView.findViewById(R.id.ib_close);
mDeleteButton.setOnClickListener(DragGridView.this);
if(mDeleteButton.getVisibility()!=VISIBLE) {
// mDeleteButton.setVisibility(VISIBLE);
}
}
}
};
@Override
public void setAdapter(ListAdapter adapter) {
super.setAdapter(adapter);
if(adapter instanceof DragGridListener){
mDragAdapter = (DragGridListener) adapter;//回调方法的关键,拿到了该接口被实现后的实例
}else{
throw new IllegalStateException("the adapter must be implements DragGridListener");
}
}
@Override
public void setNumColumns(int numColumns) {
super.setNumColumns(numColumns);
mNumColumnsSet = true;
this.mNumColumns = numColumns;
}
@Override
public void setColumnWidth(int columnWidth) {
super.setColumnWidth(columnWidth);
mColumnWidth = columnWidth;
}
@Override
public void setHorizontalSpacing(int horizontalSpacing) {
super.setHorizontalSpacing(horizontalSpacing);
this.mHorizontalSpacing = horizontalSpacing;
}
/**
* 若设置为AUTO_FIT计算有多少列
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mNumColumns == AUTO_FIT) {
int numFittedColumns;
if (mColumnWidth > 0) {
int gridWidth = Math.max(MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft()
- getPaddingRight(), 0);
numFittedColumns = gridWidth / mColumnWidth;
if (numFittedColumns > 0) {
while (numFittedColumns != 1) {
if (numFittedColumns * mColumnWidth + (numFittedColumns - 1)
* mHorizontalSpacing > gridWidth) {
numFittedColumns--;
} else {
break;
}
}
} else {
numFittedColumns = 1;
}
} else {
numFittedColumns = 2;
}
mNumColumns = numFittedColumns;
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
/**
* 设置响应拖拽的毫秒数默认是1000毫秒
* @param dragResponseMS
*/
public void setDragResponseMS(long dragResponseMS) {
this.dragResponseMS = dragResponseMS;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch(ev.getAction()){
case MotionEvent.ACTION_DOWN:
mDownX = (int) ev.getX();
mDownY = (int) ev.getY();
//根据按下的X,Y坐标获取所点击item的position
mDragPosition = pointToPosition(mDownX, mDownY);
// Log.d("mDagPosition is", "" + mDragPosition);
if(mDragPosition == AdapterView.INVALID_POSITION){
return super.dispatchTouchEvent(ev);
}
//使用Handler延迟dragResponseMS执行mLongClickRunnable,
// 大于20dp才执行mLongClickRunnable避免与Drawlayout发生冲突
int panding = (int) CommonUtil.convertDpToPixel(mcontext,20);
if(mDownX > panding) {
mHandler.postDelayed(mLongClickRunnable, dragResponseMS);
}
//根据position获取该item所对应的View
mStartDragItemView = getChildAt(mDragPosition - getFirstVisiblePosition());
//
mPoint2ItemTop = mDownY - mStartDragItemView.getTop();
mPoint2ItemLeft = mDownX - mStartDragItemView.getLeft();
mOffset2Top = (int) (ev.getRawY() - mDownY);
mOffset2Left = (int) (ev.getRawX() - mDownX);
//获取DragGridView自动向上滚动的偏移量小于这个值DragGridView向下滚动
mDownScrollBorder = getHeight() / 5;
//获取DragGridView自动向下滚动的偏移量大于这个值DragGridView向上滚动
mUpScrollBorder = getHeight() * 4/5;
//开启mDragItemView绘图缓存
mStartDragItemView.setDrawingCacheEnabled(true);
//获取mDragItemView在缓存中的Bitmap对象
mDragBitmap = Bitmap.createBitmap(mStartDragItemView.getDrawingCache());
//这一步很关键释放绘图缓存避免出现重复的镜像
mStartDragItemView.destroyDrawingCache();
break;
case MotionEvent.ACTION_MOVE:
int moveX = (int)ev.getX();
int moveY = (int) ev.getY();
//如果我们在按下的item上面移动只要不超过item的边界我们就不移除mRunnable
if(!isTouchInItem(mStartDragItemView, moveX, moveY)){
mHandler.removeCallbacks(mLongClickRunnable);
}
break;
case MotionEvent.ACTION_UP:
mHandler.removeCallbacks(mLongClickRunnable);
mHandler.removeCallbacks(mScrollRunnable);
break;
}
return super.dispatchTouchEvent(ev);
}
/**
* 是否点击在GridView的item上面
* @param dragView
* @param x
* @param y
* @return
*/
private boolean isTouchInItem(View dragView, int x, int y){
if(dragView == null){
return false;
}
int leftOffset = dragView.getLeft();
int topOffset = dragView.getTop();
if(x < leftOffset || x > leftOffset + dragView.getWidth()){
return false;
}
if(y < topOffset || y > topOffset + dragView.getHeight()){
return false;
}
return true;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(isDrag && mDragImageView != null){
switch(ev.getAction()){
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
moveX = (int) ev.getX();
moveY = (int) ev.getY();
//拖动item
onDragItem(moveX, moveY);
break;
case MotionEvent.ACTION_UP:
onStopDrag();
isDrag = false;
break;
}
return true;
}
return super.onTouchEvent(ev);
}
/**
* 创建拖动的镜像
* @param bitmap
* @param downX
* 按下的点相对父控件的X坐标
* @param downY
* 按下的点相对父控件的X坐标
*/
private void createDragImage(Bitmap bitmap, int downX , int downY){
mWindowLayoutParams = new WindowManager.LayoutParams();
mWindowLayoutParams.format = PixelFormat.TRANSLUCENT; //图片之外的其他地方透明
mWindowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
mWindowLayoutParams.x = downX - mPoint2ItemLeft + mOffset2Left;
mWindowLayoutParams.y = downY - mPoint2ItemTop + mOffset2Top - mStatusHeight;
mWindowLayoutParams.alpha = 1.0f; //透明度
// mWindowLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
// mWindowLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowLayoutParams.width = (int)(1.05*mStartDragItemView.getWidth());
mWindowLayoutParams.height = (int)(1.05*mStartDragItemView.getHeight());
mWindowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE ;
mDragImageView = new ImageView(getContext());
mDragImageView.setImageBitmap(bitmap);
mWindowManager.addView(mDragImageView, mWindowLayoutParams);
}
/**
* 从界面上面移动拖动镜像
*/
private void removeDragImage(){
if(mDragImageView != null){
mWindowManager.removeView(mDragImageView);
mDragImageView = null;
}
}
/**
* 拖动item在里面实现了item镜像的位置更新item的相互交换以及GridView的自行滚动
* @param moveX
* @param moveY
*/
private void onDragItem(int moveX, int moveY){
mWindowLayoutParams.x = moveX - mPoint2ItemLeft + mOffset2Left;
mWindowLayoutParams.y = moveY - mPoint2ItemTop + mOffset2Top - mStatusHeight;
mWindowManager.updateViewLayout(mDragImageView, mWindowLayoutParams); //更新镜像的位置
onSwapItem(moveX, moveY);
//GridView自动滚动 //已知bug当上下滚动过快时item的相互交换速度跟不上会crash
mHandler.post(mScrollRunnable);
}
/**
* 当moveY的值大于向上滚动的边界值触发GridView自动向上滚动
* 当moveY的值小于向下滚动的边界值触发GridView自动向下滚动
* 否则不进行滚动
*/
private Runnable mScrollRunnable = new Runnable() {
@Override
public void run() {
int scrollY;
if(getFirstVisiblePosition() == 0 || getLastVisiblePosition() == getCount() - 1){
mHandler.removeCallbacks(mScrollRunnable);
}
if(moveY > mUpScrollBorder){
scrollY = speed;
mHandler.postDelayed(mScrollRunnable, 25);
}else if(moveY < mDownScrollBorder){
scrollY = -speed;
mHandler.postDelayed(mScrollRunnable, 25);
}else{
scrollY = 0;
mHandler.removeCallbacks(mScrollRunnable);
}
smoothScrollBy(scrollY, 10);
}
};
/**
* 交换item,并且控制item之间的显示与隐藏效果
* @param moveX
* @param moveY
*/
private void onSwapItem(int moveX, int moveY){
//获取我们手指移动到的那个item的position
final int tempPosition = pointToPosition(moveX, moveY);
//假如tempPosition 改变了并且tempPosition不等于-1,则进行交换
if(tempPosition != mDragPosition && tempPosition != AdapterView.INVALID_POSITION && mAnimationEnd ){
mDragAdapter.setHideItem(tempPosition);
mDragAdapter.reorderItems(mDragPosition, tempPosition);
final ViewTreeObserver observer = getViewTreeObserver();
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
observer.removeOnPreDrawListener(this);
animateReorder(mDragPosition, tempPosition);
mDragPosition = tempPosition; //交换结束更新mDragPosition
return true;
}
} );
}
}
/**
* 创建移动动画
* @param view
* @param startX
* @param endX
* @param startY
* @param endY
* @return
*/
private AnimatorSet createTranslationAnimations(View view, float startX,
float endX, float startY, float endY) {
ObjectAnimator animX = ObjectAnimator.ofFloat(view, "translationX",
startX, endX);
ObjectAnimator animY = ObjectAnimator.ofFloat(view, "translationY",
startY, endY);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
return animSetXY;
}
/**
* item的交换动画效果
* @param oldPosition
* @param newPosition
*/
private void animateReorder(final int oldPosition, final int newPosition) {
boolean isForward = newPosition > oldPosition;
List<Animator> resultList = new LinkedList<Animator>();
if (isForward) {
for (int pos = oldPosition; pos < newPosition; pos++) {
View view = getChildAt(pos - getFirstVisiblePosition());
// Log.d("oldPosition",""+ pos);
//双数
if ((pos + 1) % mNumColumns == 0) {
resultList.add(createTranslationAnimations(view,
- view.getWidth() * (mNumColumns - 1), 0,
view.getHeight(), 0));
} else {
resultList.add(createTranslationAnimations(view,
view.getWidth(), 0, 0, 0));
}
}
} else {
for (int pos = oldPosition; pos > newPosition; pos--) {
View view = getChildAt(pos - getFirstVisiblePosition());
if ((pos + mNumColumns) % mNumColumns == 0) {
resultList.add(createTranslationAnimations(view,
view.getWidth() * (mNumColumns - 1), 0,
-view.getHeight(), 0));
} else {
resultList.add(createTranslationAnimations(view,
-view.getWidth(), 0, 0, 0));
}
}
}
AnimatorSet resultSet = new AnimatorSet();
resultSet.playTogether(resultList);
resultSet.setDuration(300);
resultSet.setInterpolator(new AccelerateDecelerateInterpolator());
resultSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mAnimationEnd = false;
}
@Override
public void onAnimationEnd(Animator animation) {
mAnimationEnd = true;
}
});
resultSet.start();
}
/**
* 停止拖拽我们将之前隐藏的item显示出来并将镜像移除
*/
private void onStopDrag(){
View view = getChildAt(mDragPosition - getFirstVisiblePosition());
if(view != null){
view.setVisibility(View.VISIBLE);
}
mDragAdapter.setHideItem(-1);
removeDragImage();
}
/**
* 获得状态栏的高度
*
* @param context
* @return
*/
public static int getStatusHeight(Context context)
{
int statusHeight = -1;
try
{
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height")
.get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e)
{
e.printStackTrace();
}
return statusHeight;
}
@Override
protected void dispatchDraw(Canvas canvas) {
i++;
int backgroundHeightPanding = (int) CommonUtil.convertDpToPixel(mcontext,4);
int dockHightPanding = (int) CommonUtil.convertDpToPixel(mcontext,3);
int count = getChildCount();
int top = count > 0 ? getChildAt(0).getTop() : 0;
int bottom = getChildAt(0).getBottom();
int backgroundWidth = background.getWidth();
int backgroundHeight = background.getHeight()-backgroundHeightPanding;
int dockWith = bookshelf_dock.getWidth();
int dockHight = bookshelf_dock.getHeight();
int width = getWidth();
int height = getHeight();
for (int y = top; y < height; y += backgroundHeight) {
for (int x = 0; x < width; x += backgroundWidth) {
canvas.drawBitmap(background, x, y, null);
}
if(y > top) {
canvas.drawBitmap(bookshelf_dock, 0 , y-dockHightPanding, null);
}
}
if(i == 1) {
firtView = getChildAt(0);
firstItemTextView = (TextView) firtView.findViewById(R.id.tv_name);
firstItemTextView.getLocationInWindow(firstLocation);
}
super.dispatchDraw(canvas);
}
@Override
public void onClick(View v) {
// Log.d("deleteImageButton","ok");
mDragAdapter.removeItem(mDragPosition);
}
public static boolean getShowDeleteButton () {
return isShowDeleteButton;
}
public static void setIsShowDeleteButton (boolean a) {
isShowDeleteButton = a;
}
public void setTouchable(boolean isable) {
this.touchable = isable;
}
public boolean getTouchable () {
return touchable;
}
public static void setNoMove (boolean ismove) {
isMove = ismove;
}
private ImageView getmDragImageView() {
return mDragImageView;
}
public int[] getFirstLocation() {
return firstLocation;
}
}

View File

@ -104,12 +104,12 @@
<TextView
android:id="@+id/category"
style="@style/TextViewNovelType"
android:text="aaa"
android:text=""
/>
<TextView
android:id="@+id/author"
style="@style/TextViewNovelAuthor"
android:text="aaa"
android:text=""
/>
@ -135,13 +135,13 @@
app:popupTheme="@style/ToolBarTheme.PopupOverlay" >
<Button android:id="@+id/mTextMessage"
<Button android:id="@+id/btnFistPage"
style="@style/buttonCates"
android:layout_width="wrap_content"
android:textColor="@color/white"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="10dp"
android:text="书架" />
android:text="首页" />
</android.support.v7.widget.Toolbar>
@ -152,7 +152,7 @@
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="@dimen/botoomNavi"
android:orientation="horizontal"
android:layout_weight="0"
android:layout_gravity="bottom"

View File

@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@mipmap/side_bg" />
/>
<io.alterac.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
android:id="@+id/blurLayout"

View File

@ -52,7 +52,27 @@
android:layout_weight="0"
android:visibility="gone"
/>
<RadioGroup
android:id="@+id/rgSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:outlineAmbientShadowColor="@color/colorPrimaryDark"
android:outlineSpotShadowColor="@color/lightgray"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/radioButtonBoy"
android:text="男生 "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
/>
<RadioButton
android:id="@+id/radioButtonGirl"
android:text="女生"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>

View File

@ -46,7 +46,7 @@
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@mipmap/side_bg"
/>
</LinearLayout>

View File

@ -103,10 +103,10 @@
style="@style/TextViewDesc"
android:padding="5dp"
android:layout_marginLeft="20dp"
app:collapsedLines="2"
app:collapsedLines="3"
app:collapsedText=" 》》》"
app:expandedText=" 《《《"
app:suffixColor="#0000ff"
app:suffixColor="@color/colorPrimary"
app:suffixTrigger="true"
/>
@ -133,7 +133,7 @@
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@mipmap/side_bg"
/>
</LinearLayout>

View File

@ -7,12 +7,6 @@
android:layout_marginRight="@dimen/marginRight"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
@ -55,7 +49,7 @@
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.TextInputEditText

View File

@ -25,7 +25,7 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@mipmap/side_bg"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar

View File

@ -17,7 +17,7 @@
style="@style/buttonCates"
android:text="本地导入"
/>
<LinearLayout style="@style/llGraySplit.2dp"/>
<!--
<Button
style="@style/buttonCates"
@ -26,11 +26,13 @@
-->
<LinearLayout style="@style/llGraySplit.2dp"/>
<Button
android:id="@+id/btnUploadProgress"
style="@style/buttonCates"
android:text="上传进度"
/>
<LinearLayout style="@style/llGraySplit.2dp"/>
<Button
android:id="@+id/btnDownloadProgress"
style="@style/buttonCates"
android:text="下载进度"
/>
@ -48,8 +50,9 @@
/>
-->
<LinearLayout style="@style/llGraySplit"/>
<Button
android:id="@+id/btnCancel"
style="@style/buttonCates"
android:text="取消"
android:textColor="@color/colorAccent"

View File

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@mipmap/side_bg"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"

View File

@ -31,7 +31,7 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior"
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="@dimen/botoomNavi"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:layout_behavior="@string/appbar_scrolling_view_behavior"

View File

@ -96,6 +96,7 @@
android:background="@drawable/item_selector"
android:clickable="true"
android:gravity="center"
android:visibility="gone"
android:orientation="vertical">
<LinearLayout
@ -156,7 +157,8 @@
android:background="@drawable/item_selector"
android:clickable="false"
android:gravity="center"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/llOutside"
>
<LinearLayout
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_weight="1"
android:background="@drawable/item_selector"
android:clickable="true"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView"
style="@style/NovelImage.horizon"
android:layout_width="40dp"
android:layout_height="60dp"
android:gravity="center_horizontal"
android:src="@drawable/googleg_standard_color_18" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="15dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvCateName"
style="@style/NovelBlockTitle"
android:layout_height="15dp"
android:gravity="center_vertical"
android:text="完本精选"
android:textSize="18sp" />
<TextView
android:id="@+id/tvNovels"
android:text="圣诞老人 奇遇记 风马牛大战 当夏洛克遇到马洛特 圣诞老人 奇遇记 风马牛大战 当夏洛克遇到马洛特"
style="@style/TextViewNovelDesc"/>
</LinearLayout>
</LinearLayout>
<LinearLayout style="@style/llGraySplit.2dp.gray" />
</LinearLayout>
</LinearLayout>

View File

@ -28,19 +28,25 @@
<!--app:layout_behavior="@string/appbar_scrolling_view_behavior"/>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/llOutside"
android:orientation="vertical"
android:layout_marginTop="-20dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="48dip"
android:layout_height="40dp"
android:background="@color/white"
app:tl_indicator_color="@color/crimson"
app:tl_indicator_corner_radius="1.5dp"
app:tl_indicator_height="2dp"
app:tl_indicator_width="45dp"
app:tl_textSelectColor="@color/crimson"
app:tl_textUnselectColor="@color/grey"
app:tl_tab_space_equal ="true"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"

View File

@ -29,7 +29,7 @@
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@mipmap/side_bg"
/>
</LinearLayout>

View File

@ -16,8 +16,7 @@
android:layout_height="120dp"
android:layout_width="90dp"
android:layout_marginTop="46dp"
android:background="@mipmap/cover_default_new"
android:drawableBottom="@mipmap/cover_type_txt"
android:text=""
android:padding="10dp"
android:textColor="@color/read_textColor"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

View File

@ -43,7 +43,8 @@
<dimen name="marginLeft">10dp</dimen>
<!-- 屏幕底部侧空出 -->
<dimen name="marginBottom">5dp</dimen>
<!-- 底部导航栏高度 -->
<dimen name="botoomNavi">42dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->

View File

@ -125,7 +125,10 @@
<item name="android:layout_height">2dp</item>
</style>
<style name="llGraySplit.2dp.gray">
<item name="android:background">@color/lightgray</item>
</style>
<style name="TextViewTitle">
<item name="android:paddingLeft">5dp</item>
<item name="android:textColor">@color/darkcyan</item>
@ -317,7 +320,7 @@
<item name="android:textSize">12sp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:lines">2</item>
<item name="android:lines">1</item>
<item name="android:gravity">center</item>
<item name="android:ellipsize">end</item>
</style>