Add AppbarScene
This commit is contained in:
1 parent
f334b250ef
commit
0e4ded4231
10 files changed
+288
-2
No files matched your search
@@ -26,12 +26,12 @@ import android.widget.TextView;
|
||||
|
||||
import com.hippo.effect.ripple.RippleSalon;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.AppbarScene;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
|
||||
public final class SettingsHeaderScene extends Scene implements EasyRecyclerView.OnItemClickListener {
|
||||
public final class SettingsHeaderScene extends AppbarScene implements EasyRecyclerView.OnItemClickListener {
|
||||
|
||||
private static final int[] HEADER_ICON_ARRAY = {
|
||||
R.drawable.ic_cellphone_android_theme_primary,
|
||||
@@ -52,6 +52,8 @@ public final class SettingsHeaderScene extends Scene implements EasyRecyclerView
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mActivity = getStageActivity();
|
||||
setTitle(R.string.signout);
|
||||
setIcon(R.drawable.ic_arrow_left_dark);
|
||||
|
||||
mRecyclerView = new EasyRecyclerView(mActivity);
|
||||
setContentView(mRecyclerView);
|
||||
@@ -70,6 +72,11 @@ public final class SettingsHeaderScene extends Scene implements EasyRecyclerView
|
||||
mRecyclerView.getPaddingRight(), b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIconClick() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.scene;
|
||||
|
||||
import android.annotation.DrawableRes;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StringRes;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.effect.ripple.RippleSalon;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.SimpleImageView;
|
||||
|
||||
public class AppbarScene extends Scene {
|
||||
|
||||
private SimpleImageView mIcon;
|
||||
private TextView mTitle;
|
||||
private FrameLayout mContent;
|
||||
|
||||
@Override
|
||||
protected void setContentView(int resId) {
|
||||
getStageActivity().getLayoutInflater().inflate(resId, mContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setContentView(View view) {
|
||||
mContent.addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public View findViewById(int resId) {
|
||||
return mContent.findViewById(resId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.setContentView(R.layout.scene_appbar);
|
||||
|
||||
mIcon = (SimpleImageView) super.findViewById(R.id.appbar_icon);
|
||||
mTitle = (TextView) super.findViewById(R.id.appbar_title);
|
||||
mContent = (FrameLayout) super.findViewById(R.id.appbar_content);
|
||||
|
||||
RippleSalon.addRipple(mIcon, true);
|
||||
mIcon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onIconClick();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onIconClick() {
|
||||
}
|
||||
|
||||
public void setIcon(@DrawableRes int resId) {
|
||||
mIcon.setDrawable(resId);
|
||||
ViewUtils.setVisibility(mIcon, resId == -1 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
public void setIcon(Drawable icon) {
|
||||
mIcon.setDrawable(icon);
|
||||
ViewUtils.setVisibility(mIcon, icon == null ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
public void setTitle(@StringRes int resId) {
|
||||
mTitle.setText(resId);
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
mTitle.setText(title);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
package com.hippo.widget;
|
||||
|
||||
import android.annotation.DrawableRes;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
@@ -47,6 +48,10 @@ public class SimpleImageView extends View implements Drawable.Callback {
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setDrawable(@DrawableRes int resId) {
|
||||
setDrawable(getContext().getResources().getDrawable(resId));
|
||||
}
|
||||
|
||||
public void setDrawable(Drawable drawable) {
|
||||
if (mDrawable != null) {
|
||||
mDrawable.setCallback(null);
|
||||
|
||||
Reference in new issue
Block a user