This commit is contained in:
seven332 committed 2015-02-12 20:43:25 +08:00
1 parent ccc1032ecb
commit b63ea27415
34 files changed
+508 -163

No files matched your search

@@ -0,0 +1,80 @@
/*
* 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.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.hippo.ehviewer.R;
import com.hippo.util.ViewUtils;
public class Appbar extends FrameLayout {
private Context mContext;
private ImageView mNavigationIcon;
private TextView mTitle;
private String mTitleString;
public Appbar(Context context) {
super(context);
init(context);
}
public Appbar(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public Appbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Appbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
private void init(Context context) {
mContext = context;
LayoutInflater.from(context).inflate(R.layout.widget_app_bar, this);
mNavigationIcon = (ImageView) findViewById(R.id.ab_navigation_icon);
mTitle = (TextView) findViewById(R.id.ab_title);
ViewUtils.setVisibility(mNavigationIcon, View.GONE);
}
public void setTitle(int resId) {
setTitle(mContext.getString(resId));
}
public void setTitle(String title) {
mTitleString = title;
mTitle.setText(title);
}
}
@@ -18,16 +18,21 @@ package com.hippo.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import org.jetbrains.annotations.NotNull;
public class DrawerFrameLayout extends FrameLayout {
private static final int[] MAX_ATTRS = {android.R.attr.maxWidth};
private int mMaxWidth = -1;
private OnGetPaddingListener mOnGetPaddingListener;
public DrawerFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0, 0);
@@ -50,6 +55,7 @@ public class DrawerFrameLayout extends FrameLayout {
a.recycle();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
@@ -62,4 +68,25 @@ public class DrawerFrameLayout extends FrameLayout {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@SuppressWarnings("deprecation")
@Override
protected boolean fitSystemWindows(@NotNull Rect insets) {
if (mOnGetPaddingListener != null) {
mOnGetPaddingListener.onGetPadding(insets.left, insets.top,
insets.right, insets.bottom);
}
insets.set(0, 0, 0, 0);
return super.fitSystemWindows(insets);
}
public void setOnGetPaddingListener(OnGetPaddingListener listener) {
mOnGetPaddingListener = listener;
}
public interface OnGetPaddingListener {
public void onGetPadding(int l, int t, int r, int b);
}
}
@@ -16,6 +16,8 @@
package com.hippo.widget;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.Editable;
import android.text.Selection;
import android.text.TextWatcher;
@@ -25,6 +27,9 @@ import android.widget.AutoCompleteTextView;
public class PrefixEditText extends AutoCompleteTextView
implements TextWatcher {
private static final String STATE_KEY_SUPER = "super";
private static final String STATE_KEY_PREFIX = "prefix";
private Context mContext;
private String mPrefix;
@@ -95,4 +100,21 @@ public class PrefixEditText extends AutoCompleteTextView
}
}
@Override
public Parcelable onSaveInstanceState() {
final Bundle state = new Bundle();
state.putParcelable(STATE_KEY_SUPER, super.onSaveInstanceState());
state.putString(STATE_KEY_PREFIX, mPrefix);
return state;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
final Bundle savedState = (Bundle) state;
super.onRestoreInstanceState(savedState.getParcelable(STATE_KEY_SUPER));
setPrefix(savedState.getString(STATE_KEY_PREFIX));
}
}
}