This commit is contained in:
seven332 committed 2015-02-17 15:26:24 +08:00
1 parent 940d135057
commit a5d9c2fd4a
18 files changed
+461 -137

No files matched your search

@@ -15,5 +15,7 @@
package com.hippo.ehviewer.ui.fragment;
public class GalleryListFragment extends SceneFragment {
import android.support.v4.app.Fragment;
public class GalleryListFragment extends Fragment {
}
@@ -1,33 +0,0 @@
/*
* 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.fragment;
import android.support.v4.app.Fragment;
import com.hippo.scene.Scene;
public class SceneFragment extends Fragment {
private Scene mScene;
public Scene getScene() {
return mScene;
}
public void setScene(Scene scene) {
mScene = scene;
}
}
@@ -22,6 +22,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
@@ -32,20 +33,22 @@ import com.hippo.ehviewer.data.GalleryListUrlBuilder;
import com.hippo.ehviewer.widget.SearchLayout;
import com.hippo.scene.Scene;
public class SearchFragment extends SceneFragment implements SearchLayout.SearhLayoutHelper,
public class SearchFragment extends Fragment implements SearchLayout.SearhLayoutHelper,
Scene.ActivityResultListener {
private static final String VIEW_STATE_TAG = "android:view_state";
private Activity mActivity;
private OnSearchListener mOnSearchListener;
private View mRootView;
private SearchLayout mSearchLayout;
public void setOnSearchListener(OnSearchListener listener) {
mOnSearchListener = listener;
private static Scene sScene;
private static OnSearchListener sOnSearchListener;
public static void setScene(Scene scene) {
sScene = scene;
}
@Override
@@ -80,9 +83,9 @@ public class SearchFragment extends SceneFragment implements SearchLayout.SearhL
}
@Override
public void requestSelectImage() {
public void onRequestSelectImage() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
getScene().startActivityForResult(intent, this);
sScene.startActivityForResult(intent, this);
}
@Override
@@ -15,6 +15,7 @@
package com.hippo.ehviewer.ui.scene;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@@ -30,6 +31,8 @@ import com.hippo.widget.Appbar;
public class GalleryListScene extends Scene implements SearchFragment.OnSearchListener {
private Resources mResources;
private Appbar mAppbar;
private ViewPager mViewPager;
@@ -39,13 +42,17 @@ public class GalleryListScene extends Scene implements SearchFragment.OnSearchLi
public void onCreate() {
setContentView(R.layout.scene_gallery_list);
mResources = getStageActivity().getResources();
mAppbar = (Appbar) findViewById(R.id.appbar);
mViewPager = (ViewPager) findViewById(R.id.viewPager);
mAdapter = new GalleryListPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mAdapter);
mAppbar.setTitle("EhViewer");
mAppbar.setTitle(mResources.getString(R.string.app_name));
SearchFragment.setScene(this);
}
@Override
@@ -61,6 +68,8 @@ public class GalleryListScene extends Scene implements SearchFragment.OnSearchLi
@Override
public void onDestroy() {
dispatchRemove();
SearchFragment.setScene(null);
}
@Override
@@ -93,12 +102,9 @@ public class GalleryListScene extends Scene implements SearchFragment.OnSearchLi
public Fragment getItem(int i) {
if (i == 0) {
SearchFragment fragment = new SearchFragment();
fragment.setScene(GalleryListScene.this);
fragment.setOnSearchListener(GalleryListScene.this);
return fragment;
} else {
GalleryListFragment fragment = new GalleryListFragment();
fragment.setScene(GalleryListScene.this);
return fragment;
}
}
@@ -18,7 +18,6 @@ package com.hippo.ehviewer.widget;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.widget.LinearLayoutManager;
@@ -32,7 +31,6 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.hippo.effect.ripple.RippleSalon;
@@ -46,7 +44,7 @@ import com.hippo.widget.recyclerview.EasyRecyclerView;
import org.jetbrains.annotations.NotNull;
public class SearchLayout extends FrameLayout implements CompoundButton.OnCheckedChangeListener,
View.OnClickListener {
View.OnClickListener, SelectSearchImageLayout.SelectSearchImageLayoutHelper {
private static final String STATE_KEY_SUPER = "super";
private static final String STATE_KEY_SEARCH_MODE = "search_mode";
@@ -92,10 +90,7 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
private FloatLabelEditText mEditTextTag;
private View mImageView;
private TextView mTextSelectImage;
private TextView mTextImagePath;
private ImageView mImagePreview;
private SelectSearchImageLayout mImageView;
private View mActionView;
private TextView mAction1;
@@ -218,24 +213,18 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
// TODO add quick search
} else if (v == mAction2) {
taggleSearchMode();
} else if (v == mTextSelectImage) {
if (mHelper != null) {
mHelper.requestSelectImage();
}
}
}
public void onSelectImage(@NotNull String imagePath) {
mTextImagePath.setText(imagePath);
mImageView.onSelectImage(imagePath);
}
if (mSearchImage != null && !mSearchImage.isRecycled()) {
mSearchImage.isRecycled();
@Override
public void onRequstSelectImage() {
if (mHelper != null) {
mHelper.onRequestSelectImage();
}
mSearchImage = BitmapFactory.decodeFile(imagePath);
mImagePreview.setImageBitmap(mSearchImage);
ViewUtils.setVisibility(mTextImagePath, View.VISIBLE);
ViewUtils.setVisibility(mImagePreview, View.VISIBLE);
}
private class SearchHolder extends RecyclerView.ViewHolder {
@@ -393,19 +382,14 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
if (mImageView == null) {
mInflater.inflate(R.layout.search_image, holder.content);
mImageView = holder.content.getChildAt(0);
mTextSelectImage = (TextView) mImageView.findViewById(R.id.search_select_image_action);
mTextImagePath = (TextView) mImageView.findViewById(R.id.search_select_image_path);
mImagePreview = (ImageView) mImageView.findViewById(R.id.search_select_image_image);
mImageView = (SelectSearchImageLayout) holder.content.getChildAt(0);
// Restore state
if (mSavedInstanceState != null) {
holder.content.restoreHierarchyState(mSavedInstanceState);
}
RippleSalon.addRipple(mTextSelectImage, false);
mTextSelectImage.setOnClickListener(SearchLayout.this);
mImageView.setHelper(SearchLayout.this);
} else {
ViewUtils.removeFromParent(mImageView);
holder.content.addView(mImageView);
@@ -433,6 +417,6 @@ public class SearchLayout extends FrameLayout implements CompoundButton.OnChecke
}
public interface SearhLayoutHelper {
public void requestSelectImage();
public void onRequestSelectImage();
}
}
@@ -0,0 +1,177 @@
/*
* 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.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hippo.effect.ripple.RippleSalon;
import com.hippo.ehviewer.R;
import com.hippo.util.ViewUtils;
import com.larvalabs.svgandroid.SVG;
import com.larvalabs.svgandroid.SVGBuilder;
import org.jetbrains.annotations.NotNull;
public class SelectSearchImageLayout extends LinearLayout implements View.OnClickListener{
private static final String STATE_KEY_SUPER = "super";
private static final String STATE_KEY_PATH = "path";
private TextView mButtonSelect;
private TextView mTextPath;
private ImageView mImagePreview;
private String mSelectedPath;
private Bitmap mSelectedImage;
private SelectSearchImageLayoutHelper mHelper;
public SelectSearchImageLayout(Context context) {
super(context);
init(context);
}
public SelectSearchImageLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public SelectSearchImageLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SelectSearchImageLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.widget_select_search_image_layout, this);
// TODO It is a bad idea.
int childCount = getChildCount();
if (childCount == 3) {
setOrientation(LinearLayout.VERTICAL);
} else if (childCount == 2) {
setOrientation(LinearLayout.HORIZONTAL);
} else {
throw new IllegalStateException("Can't guess orientation, did you changed the layout res ?");
}
mButtonSelect = (TextView) findViewById(R.id.search_select_image_action);
mTextPath = (TextView) findViewById(R.id.search_select_image_path);
mImagePreview = (ImageView) findViewById(R.id.search_select_image_image);
RippleSalon.addRipple(mButtonSelect, false);
mButtonSelect.setOnClickListener(this);
ViewUtils.removeHardwareAccelerationSupport(mImagePreview);
SVG svg = new SVGBuilder().readFromResource(getResources(), R.raw.file_image).build();
mImagePreview.setImageDrawable(svg.getDrawable());
}
public void setHelper(SelectSearchImageLayoutHelper helper) {
mHelper = helper;
}
private void setImagePreview(String imagePath) {
if (mSelectedImage != null && !mSelectedImage.isRecycled()) {
mSelectedImage.isRecycled();
}
mSelectedImage = BitmapFactory.decodeFile(imagePath);
if (mSelectedImage != null) {
mImagePreview.setImageBitmap(mSelectedImage);
} else {
SVG svg = new SVGBuilder().readFromResource(getResources(), R.raw.file_image_off).build();
mImagePreview.setImageDrawable(svg.getDrawable());
}
}
public void onSelectImage(@NotNull String selectPath) {
mSelectedPath = selectPath;
mTextPath.setText(selectPath);
setImagePreview(selectPath);
ViewUtils.setVisibility(mTextPath, View.VISIBLE);
ViewUtils.setVisibility(mImagePreview, View.VISIBLE);
super.onDetachedFromWindow();
super.onAttachedToWindow();
}
@Override
protected void onAttachedToWindow() {
if (mSelectedPath != null) {
setImagePreview(mSelectedPath);
}
}
@Override
protected void onDetachedFromWindow() {
if (mSelectedImage != null && !mSelectedImage.isRecycled()) {
mSelectedImage.isRecycled();
}
mSelectedImage = null;
}
@Override
public Parcelable onSaveInstanceState() {
final Bundle state = new Bundle();
state.putParcelable(STATE_KEY_SUPER, super.onSaveInstanceState());
state.putString(STATE_KEY_PATH, mSelectedPath);
return state;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
final Bundle savedState = (Bundle) state;
super.onRestoreInstanceState(savedState.getParcelable(STATE_KEY_SUPER));
String path = savedState.getString(STATE_KEY_PATH);
if (path != null) {
onSelectImage(path);
}
}
}
@Override
public void onClick(View v) {
if (mHelper != null) {
mHelper.onRequstSelectImage();
}
}
public interface SelectSearchImageLayoutHelper {
public void onRequstSelectImage();
}
}
@@ -62,6 +62,10 @@ public abstract class Scene {
return mRootView;
}
public StageActivity getStageActivity() {
return mStageActivity;
}
public void startScene(Class sceneClass) {
mStageActivity.startScene(this, sceneClass);
}
@@ -156,6 +156,15 @@ public final class ViewUtils {
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void addHardwareAccelerationSupport(View v) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
if (v.getLayerType() != View.LAYER_TYPE_HARDWARE) {
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
}
}
public static void measureView(View v, int width, int height) {
int widthMeasureSpec;
int heightMeasureSpec;