Update
This commit is contained in:
1 parent
b9f0a6c70c
commit
69330a2fec
20 files changed
+411
-342
No files matched your search
@@ -71,7 +71,7 @@ public final class EhClient {
|
||||
ThreadFactory threadFactory = new PriorityThreadFactory(TAG,
|
||||
Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mRequestThreadPool = new ThreadPoolExecutor(poolSize, poolSize,
|
||||
1, TimeUnit.SECONDS, requestWorkQueue, threadFactory);
|
||||
1L, TimeUnit.SECONDS, requestWorkQueue, threadFactory);
|
||||
}
|
||||
|
||||
public static String getUrlHeader(int mode) {
|
||||
@@ -86,8 +86,8 @@ public final class EhClient {
|
||||
}
|
||||
}
|
||||
|
||||
public static interface EhClientListener {
|
||||
public void onFailure(Exception e);
|
||||
public interface EhClientListener {
|
||||
void onFailure(Exception e);
|
||||
}
|
||||
|
||||
public abstract static class OnGetGalleryListListener implements EhClientListener {
|
||||
@@ -111,9 +111,9 @@ public final class EhClient {
|
||||
}
|
||||
|
||||
private interface BgJobHelper {
|
||||
public void doInBackground();
|
||||
void doInBackground();
|
||||
|
||||
public void onPostExecute();
|
||||
void onPostExecute();
|
||||
}
|
||||
|
||||
private abstract class SimpleBgJobHelper implements BgJobHelper {
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.support.v4.widget.DrawerLayout;
|
||||
import com.hippo.content.VectorContext;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene;
|
||||
import com.hippo.ehviewer.widget.ContentLayout;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.scene.StageLayout;
|
||||
|
||||
@@ -33,7 +32,7 @@ public class ContentActivity extends StageActivity {
|
||||
private Resources mResources;
|
||||
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private ContentLayout mContentLayout;
|
||||
private StageLayout mContentLayout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -43,21 +42,15 @@ public class ContentActivity extends StageActivity {
|
||||
mResources = getResources();
|
||||
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
|
||||
mContentLayout = (ContentLayout) mDrawerLayout.findViewById(R.id.stage);
|
||||
mContentLayout = (StageLayout) mDrawerLayout.findViewById(R.id.stage);
|
||||
|
||||
mDrawerLayout.setStatusBarBackground(R.color.theme_primary_dark);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
startScene(GalleryListScene.class, null);
|
||||
}
|
||||
}
|
||||
|
||||
public int getFitPaddingBottom() {
|
||||
return mContentLayout.getFitPaddingBottom();
|
||||
}
|
||||
|
||||
public void setOnGetFitPaddingListener(ContentLayout.OnGetFitPaddingListener listener) {
|
||||
mContentLayout.setOnGetFitPaddingListener(listener);
|
||||
onCreateStageLayout(mContentLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,35 +16,16 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
import com.hippo.ehviewer.widget.ContentLayout;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.TransitionCurtain;
|
||||
import com.hippo.widget.Appbar;
|
||||
|
||||
public class GalleryListScene extends Scene implements SearchLayout.SearhLayoutHelper,
|
||||
Scene.ActivityResultListener, ContentLayout.OnGetFitPaddingListener {
|
||||
public class GalleryListScene extends Scene {
|
||||
|
||||
private final static int PAGE_INDEX_SEARCH = 0;
|
||||
private final static int PAGE_INDEX_LIST = 1;
|
||||
@@ -53,145 +34,23 @@ public class GalleryListScene extends Scene implements SearchLayout.SearhLayoutH
|
||||
private ContentActivity mActivity;
|
||||
private Resources mResources;
|
||||
|
||||
private View mSearchView;
|
||||
private SearchLayout mSearchLayout;
|
||||
|
||||
private View mListView;
|
||||
|
||||
private Appbar mAppbar;
|
||||
private ViewPager mViewPager;
|
||||
|
||||
private PagerAdapter mPagerAdapter;
|
||||
private ContentLayout mContentLayout;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.scene_gallery_list);
|
||||
|
||||
mActivity = (ContentActivity) getStageActivity();
|
||||
mResources = mActivity.getResources();
|
||||
|
||||
LayoutInflater inflater = mActivity.getLayoutInflater();
|
||||
mContentLayout = (ContentLayout) findViewById(R.id.content_layout);
|
||||
|
||||
// Search View
|
||||
mSearchView = inflater.inflate(R.layout.fragment_search, null);
|
||||
mSearchLayout = (SearchLayout) mSearchView.findViewById(R.id.search_layout);
|
||||
mContentLayout.showText("无法连接网络");
|
||||
}
|
||||
|
||||
mSearchLayout.setHelper(this);
|
||||
|
||||
// List View
|
||||
protected void onGetFitPaddingBottom(int b) {
|
||||
// TODO
|
||||
mListView = inflater.inflate(R.layout.fragment_list, null);
|
||||
|
||||
Button bb = (Button) mListView.findViewById(R.id.test_button);
|
||||
bb.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startScene(TestScene.class, null, new TransitionCurtain(new TransitionCurtain.ViewPair[] {
|
||||
new TransitionCurtain.ViewPair(R.id.haha, R.id.haha),
|
||||
new TransitionCurtain.ViewPair(R.id.bbbbbb, R.id.bbbbbb)
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
// Main View
|
||||
setContentView(R.layout.scene_gallery_list);
|
||||
mAppbar = (Appbar) findViewById(R.id.appbar);
|
||||
mViewPager = (ViewPager) findViewById(R.id.viewPager);
|
||||
|
||||
mAppbar.setTitle(mResources.getString(R.string.app_name));
|
||||
|
||||
mPagerAdapter = new SimplePagerAdapter();
|
||||
mViewPager.setAdapter(mPagerAdapter);
|
||||
mViewPager.setCurrentItem(PAGE_INDEX_LIST);
|
||||
|
||||
// Fit Padding Bottom
|
||||
mActivity.setOnGetFitPaddingListener(this);
|
||||
int fitPaddingBottom = mActivity.getFitPaddingBottom();
|
||||
if (fitPaddingBottom != -1) {
|
||||
setFitPaddingBottom(fitPaddingBottom);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFitPaddingBottom(int fitPaddingBottom) {
|
||||
mSearchLayout.setFitPaddingBottom(fitPaddingBottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(@NonNull SparseArray<Parcelable> savedStates) {
|
||||
super.onRestoreInstanceState(savedStates);
|
||||
|
||||
// mSearchView and mListView may not in hierarchy
|
||||
mSearchView.restoreHierarchyState(savedStates);
|
||||
mListView.restoreHierarchyState(savedStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSearch(ListUrlBuilder lub) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSelectImage() {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetResult(int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
Uri selectedImage = data.getData();
|
||||
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
||||
|
||||
Cursor cursor = mActivity.getContentResolver().query(selectedImage,
|
||||
filePathColumn, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String imagePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
if (imagePath != null) {
|
||||
mSearchLayout.onSelectImage(imagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetFitPadding(int l, int t, int r, int b) {
|
||||
setFitPaddingBottom(b);
|
||||
}
|
||||
|
||||
private class SimplePagerAdapter extends PagerAdapter {
|
||||
@Override
|
||||
public int getCount() {
|
||||
return PAGE_NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup view, int position) {
|
||||
View v;
|
||||
switch (position) {
|
||||
default:
|
||||
case PAGE_INDEX_SEARCH:
|
||||
v = mSearchView;
|
||||
break;
|
||||
case PAGE_INDEX_LIST:
|
||||
v = mListView;
|
||||
break;
|
||||
}
|
||||
view.addView(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup view, int position, Object object) {
|
||||
view.removeView((View) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.scene.Scene;
|
||||
|
||||
public class SearchScene extends Scene implements SearchLayout.SearhLayoutHelper,
|
||||
Scene.ActivityResultListener{
|
||||
|
||||
private ContentActivity mActivity;
|
||||
private Resources mResources;
|
||||
|
||||
private SearchLayout mSearchLayout;
|
||||
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.scene_search);
|
||||
|
||||
mActivity = (ContentActivity) getStageActivity();
|
||||
mResources = mActivity.getResources();
|
||||
|
||||
mSearchLayout = (SearchLayout) findViewById(R.id.search_layout);
|
||||
|
||||
mSearchLayout.setHelper(this);
|
||||
}
|
||||
|
||||
protected void onGetFitPaddingBottom(int b) {
|
||||
mSearchLayout.setFitPaddingBottom(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSearch(ListUrlBuilder lub) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSelectImage() {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetResult(int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
Uri selectedImage = data.getData();
|
||||
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
||||
|
||||
Cursor cursor = mActivity.getContentResolver().query(selectedImage,
|
||||
filePathColumn, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String imagePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
if (imagePath != null) {
|
||||
mSearchLayout.onSelectImage(imagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,75 +16,177 @@
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.scene.StageLayout;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.IntIdGenerator;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
import com.hippo.widget.refreshlayout.RefreshLayout;
|
||||
|
||||
public class ContentLayout extends StageLayout {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
private OnGetFitPaddingListener mOnGetFitPaddingListener;
|
||||
public class ContentLayout extends FrameLayout {
|
||||
|
||||
private int mFitPaddingLeft = -1;
|
||||
private int mFitPaddingTop = -1;
|
||||
private int mFitPaddingRight = -1;
|
||||
private int mFitPaddingBottom = -1;
|
||||
private ProgressBar mProgressBar;
|
||||
private ViewGroup mItView;
|
||||
private RefreshLayout mRefreshLayout;
|
||||
private View mImageView;
|
||||
private TextView mTextView;
|
||||
|
||||
public ContentLayout(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ContentLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ContentLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ContentLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
private void init(Context context) {
|
||||
LayoutInflater.from(context).inflate(R.layout.widget_content_layout, this);
|
||||
|
||||
mProgressBar = (ProgressBar) getChildAt(0);
|
||||
mItView = (ViewGroup) getChildAt(1);
|
||||
mRefreshLayout = (RefreshLayout) getChildAt(2);
|
||||
mImageView = mItView.getChildAt(0);
|
||||
mTextView = (TextView) mItView.getChildAt(1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected boolean fitSystemWindows(@NonNull Rect insets) {
|
||||
mFitPaddingLeft = 0;
|
||||
mFitPaddingTop = 0;
|
||||
mFitPaddingRight = 0;
|
||||
mFitPaddingBottom = insets.bottom;
|
||||
if (mOnGetFitPaddingListener != null) {
|
||||
mOnGetFitPaddingListener.onGetFitPadding(mFitPaddingLeft, mFitPaddingTop,
|
||||
mFitPaddingRight, mFitPaddingBottom);
|
||||
public void showProgressBar() {
|
||||
ViewUtils.setVisibility(mProgressBar, View.VISIBLE);
|
||||
ViewUtils.setVisibility(mItView, View.GONE);
|
||||
ViewUtils.setVisibility(mRefreshLayout, View.GONE);
|
||||
}
|
||||
|
||||
public void showText(CharSequence text) {
|
||||
ViewUtils.setVisibility(mProgressBar, View.GONE);
|
||||
ViewUtils.setVisibility(mItView, View.VISIBLE);
|
||||
ViewUtils.setVisibility(mRefreshLayout, View.GONE);
|
||||
|
||||
mTextView.setText(text);
|
||||
}
|
||||
|
||||
private abstract static class ContentHelper<E, VH extends RecyclerView.ViewHolder>
|
||||
extends EasyRecyclerView.Adapter<VH>
|
||||
implements RefreshLayout.OnHeaderRefreshListener,
|
||||
RefreshLayout.OnFooterRefreshListener {
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
private StaggeredGridLayoutManager mLayoutManager;
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*/
|
||||
private List<E> mList;
|
||||
|
||||
private IntIdGenerator mIdGenerator;
|
||||
|
||||
/**
|
||||
* First index index of current page
|
||||
*/
|
||||
private int mFirstIndex;
|
||||
/**
|
||||
* Last index index of current page
|
||||
*/
|
||||
private int mLastIndex;
|
||||
/**
|
||||
* Current page index
|
||||
*/
|
||||
private int mCurrentPage;
|
||||
/**
|
||||
* First shown page index
|
||||
*/
|
||||
private int mFirstPage;
|
||||
/**
|
||||
* Last shown page index
|
||||
*/
|
||||
private int mLastPage;
|
||||
/**
|
||||
* The number of page in sum
|
||||
*/
|
||||
private int mPageNum;
|
||||
|
||||
private int mCurrentTaskId;
|
||||
private int mCurrentTaskType;
|
||||
|
||||
private ContentHelper(RecyclerView recyclerView,
|
||||
StaggeredGridLayoutManager layoutManager) {
|
||||
mRecyclerView = recyclerView;
|
||||
mLayoutManager = layoutManager;
|
||||
|
||||
mList = new ArrayList<>();
|
||||
mIdGenerator = IntIdGenerator.create();
|
||||
}
|
||||
|
||||
insets.set(insets.left, insets.top, insets.right, 0);
|
||||
/**
|
||||
*
|
||||
* @param location
|
||||
* @return
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code location < 0 || location >= size()}
|
||||
*/
|
||||
public E getDataAt(int location) {
|
||||
return mList.get(location);
|
||||
}
|
||||
|
||||
return super.fitSystemWindows(insets);
|
||||
}
|
||||
public abstract E[] getPageData(int page);
|
||||
|
||||
public void setOnGetFitPaddingListener(OnGetFitPaddingListener listener) {
|
||||
mOnGetFitPaddingListener = listener;
|
||||
}
|
||||
public void onGetPageData(int mTaskId, int page, E[] data) {
|
||||
|
||||
public int getFitPaddingLeft() {
|
||||
return mFitPaddingLeft;
|
||||
}
|
||||
}
|
||||
|
||||
public int getFitPaddingTop() {
|
||||
return mFitPaddingTop;
|
||||
}
|
||||
@Override
|
||||
public boolean onFooterRefresh() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getFitPaddingRight() {
|
||||
return mFitPaddingRight;
|
||||
}
|
||||
@Override
|
||||
public void onHeaderRefresh() {
|
||||
|
||||
public int getFitPaddingBottom() {
|
||||
return mFitPaddingBottom;
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnGetFitPaddingListener {
|
||||
public void onGetFitPadding(int l, int t, int r, int b);
|
||||
public void refresh() {
|
||||
|
||||
}
|
||||
|
||||
public void goTo(int page) {
|
||||
if (page < 0 || page >= mPageNum) {
|
||||
throw new IndexOutOfBoundsException("Page number is " + mPageNum + ", page is " + page);
|
||||
}
|
||||
|
||||
if (page > mFirstIndex) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
abstract public void onScrollStateChanged(RecyclerView recyclerView, int newState);
|
||||
|
||||
public class OnScrollListener extends RecyclerView.OnScrollListener {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
ContentHelper.this.onScrollStateChanged(recyclerView, newState);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,8 @@ public abstract class Scene {
|
||||
|
||||
private static SceneManager sSceneManager;
|
||||
|
||||
private int mFitPaddingBottom = -1;
|
||||
|
||||
static void setSceneManager(SceneManager sceneManager) {
|
||||
sSceneManager = sceneManager;
|
||||
}
|
||||
@@ -156,6 +158,13 @@ public abstract class Scene {
|
||||
onOut();
|
||||
}
|
||||
|
||||
void getFitPaddingBottom(int b) {
|
||||
if (mFitPaddingBottom != b) {
|
||||
mFitPaddingBottom = b;
|
||||
onGetFitPaddingBottom(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBackgroundColor(int bgColor) {
|
||||
if (mBackgroundColor != bgColor) {
|
||||
mBackgroundColor = bgColor;
|
||||
@@ -211,6 +220,10 @@ public abstract class Scene {
|
||||
protected void onOut() {
|
||||
}
|
||||
|
||||
protected void onGetFitPaddingBottom(int b) {
|
||||
}
|
||||
|
||||
|
||||
public View onCreateStageBar() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.hippo.scene;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.util.Log;
|
||||
|
||||
@@ -33,6 +32,8 @@ class SceneManager {
|
||||
|
||||
private Scene mLegacyScene;
|
||||
|
||||
private int[] mTemp = new int[2];
|
||||
|
||||
// Should only be called by SceneApplication
|
||||
SceneManager() {
|
||||
}
|
||||
@@ -76,6 +77,12 @@ class SceneManager {
|
||||
scene.setState(Scene.SCENE_STATE_CREATE);
|
||||
scene.create(null);
|
||||
|
||||
// Update fit padding
|
||||
int fitPaddingBottom = getStageActivity().getStageLayout().getFitPaddingBottom();
|
||||
if (fitPaddingBottom != -1) {
|
||||
scene.getFitPaddingBottom(fitPaddingBottom);
|
||||
}
|
||||
|
||||
if (curtain != null && previousState != null) {
|
||||
scene.setState(Scene.SCENE_STATE_OPEN);
|
||||
curtain.open(scene, previousState);
|
||||
@@ -138,9 +145,11 @@ class SceneManager {
|
||||
scene.detachFromeStage();
|
||||
}
|
||||
|
||||
/*
|
||||
// Switch stage bar
|
||||
View stageBarContent = scene.onCreateStageBar();
|
||||
getStageActivity().getStageBar().updateContent(stageBarContent);
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "The scene is not in stage");
|
||||
@@ -182,6 +191,10 @@ class SceneManager {
|
||||
}
|
||||
}
|
||||
|
||||
Stack<Scene> getSceneStack() {
|
||||
return mSceneStack;
|
||||
}
|
||||
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
for (Scene scene : mSceneStack) {
|
||||
scene.saveInstanceState(outState);
|
||||
|
||||
@@ -24,9 +24,9 @@ import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.ui.AbsActionBarActivity;
|
||||
import com.hippo.util.IntIdGenerator;
|
||||
import com.hippo.widget.StageBar;
|
||||
|
||||
public abstract class StageActivity extends AbsActionBarActivity {
|
||||
public abstract class StageActivity extends AbsActionBarActivity
|
||||
implements StageLayout.OnGetFitPaddingBottomListener {
|
||||
|
||||
private IntIdGenerator mActivityResultIdGenerator = IntIdGenerator.create();
|
||||
private SparseArray<Scene.ActivityResultListener> mActivityResultListenerMap =
|
||||
@@ -40,7 +40,7 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
|
||||
public abstract @NonNull StageLayout getStageLayout();
|
||||
|
||||
public abstract @NonNull StageBar getStageBar();
|
||||
// public abstract @NonNull StageBar getStageBar();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -49,6 +49,10 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
((SceneApplication) getApplication()).getSceneManager().setStageActivity(this);
|
||||
}
|
||||
|
||||
protected void onCreateStageLayout(StageLayout stageLayout) {
|
||||
stageLayout.setOnGetFitPaddingListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@@ -56,6 +60,13 @@ public abstract class StageActivity extends AbsActionBarActivity {
|
||||
((SceneApplication) getApplication()).getSceneManager().setStageActivity(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetFitPaddingBottom(int b) {
|
||||
for (Scene scene : sSceneManager.getSceneStack()) {
|
||||
scene.getFitPaddingBottom(b);
|
||||
}
|
||||
}
|
||||
|
||||
void attachSceneToStage(Scene scene) {
|
||||
View sceneView = scene.getSceneView();
|
||||
if (sceneView != null) {
|
||||
|
||||
+1
-4
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.widget;
|
||||
package com.hippo.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.CardView;
|
||||
@@ -58,7 +58,4 @@ public class StageBar extends CardView {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package com.hippo.scene;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -26,6 +27,10 @@ import android.widget.FrameLayout;
|
||||
|
||||
public class StageLayout extends FrameLayout {
|
||||
|
||||
private OnGetFitPaddingBottomListener mOnGetFitPaddingBottomListener;
|
||||
|
||||
private int mFitPaddingBottom = -1;
|
||||
|
||||
public StageLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -52,4 +57,29 @@ public class StageLayout extends FrameLayout {
|
||||
protected void dispatchRestoreInstanceState(@NonNull SparseArray<Parcelable> container) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public void setOnGetFitPaddingListener(OnGetFitPaddingBottomListener listener) {
|
||||
mOnGetFitPaddingBottomListener = listener;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected boolean fitSystemWindows(@NonNull Rect insets) {
|
||||
mFitPaddingBottom = insets.bottom;
|
||||
if (mOnGetFitPaddingBottomListener != null) {
|
||||
mOnGetFitPaddingBottomListener.onGetFitPaddingBottom(mFitPaddingBottom);
|
||||
}
|
||||
|
||||
insets.set(insets.left, insets.top, insets.right, 0);
|
||||
|
||||
return super.fitSystemWindows(insets);
|
||||
}
|
||||
|
||||
public int getFitPaddingBottom() {
|
||||
return mFitPaddingBottom;
|
||||
}
|
||||
|
||||
public interface OnGetFitPaddingBottomListener {
|
||||
void onGetFitPaddingBottom(int b);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,6 @@ public class TransitionCurtain extends Curtain {
|
||||
|
||||
colorAnim.start();
|
||||
|
||||
|
||||
mAnimList.add(colorAnim);
|
||||
|
||||
// Handle transit part
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.hippo.util;
|
||||
|
||||
|
||||
import android.os.Process;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
@@ -45,5 +44,4 @@ public class PriorityThreadFactory implements ThreadFactory {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -350,4 +350,25 @@ public final class ViewUtils {
|
||||
vto.removeOnGlobalLayoutListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get index in parent
|
||||
*
|
||||
* @param view The view
|
||||
* @return The index
|
||||
*/
|
||||
public static int getIndexInParent(View view) {
|
||||
ViewParent parent = view.getParent();
|
||||
if (parent instanceof ViewGroup) {
|
||||
ViewGroup viewParent = (ViewGroup) parent;
|
||||
int count = viewParent.getChildCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
View v = viewParent.getChildAt(i);
|
||||
if (v == view) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user