Skip to content

Commit 651a40a

Browse files
committed
sample update
1 parent d68b49a commit 651a40a

File tree

12 files changed

+449
-32
lines changed

12 files changed

+449
-32
lines changed

sample/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ dependencies {
2525
testCompile 'junit:junit:4.12'
2626
compile project(':cardstackview')
2727
compile 'com.android.support:cardview-v7:24.2.1'
28+
compile 'com.jaeger.statusbaruitl:library:1.3.0'
2829
}

sample/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
android:icon="@mipmap/ic_launcher"
88
android:label="@string/app_name"
99
android:supportsRtl="true"
10-
android:theme="@style/AppTheme">
10+
android:theme="@style/AppTheme.NoTitle">
1111
<activity android:name=".MainActivity">
1212
<intent-filter>
1313
<action android:name="android.intent.action.MAIN"/>
1414

1515
<category android:name="android.intent.category.LAUNCHER"/>
1616
</intent-filter>
1717
</activity>
18+
<activity
19+
android:name=".DetailActivity"
20+
android:theme="@style/AppTheme.NoTitle"/>
1821
</application>
1922

2023
</manifest>

sample/src/main/java/me/brucezz/sample/Card.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.brucezz.sample;
22

3+
import android.os.Parcel;
4+
import android.os.Parcelable;
35
import android.support.annotation.ColorInt;
46
import android.support.annotation.DrawableRes;
57

@@ -9,7 +11,7 @@
911
1012
*/
1113

12-
public class Card {
14+
public class Card implements Parcelable {
1315

1416
@ColorInt int mBgColor;
1517
@DrawableRes int mImage;
@@ -20,4 +22,34 @@ public Card(int bgColor, int image, String title) {
2022
mImage = image;
2123
mTitle = title;
2224
}
25+
26+
@Override
27+
public int describeContents() {
28+
return 0;
29+
}
30+
31+
@Override
32+
public void writeToParcel(Parcel dest, int flags) {
33+
dest.writeInt(this.mBgColor);
34+
dest.writeInt(this.mImage);
35+
dest.writeString(this.mTitle);
36+
}
37+
38+
protected Card(Parcel in) {
39+
this.mBgColor = in.readInt();
40+
this.mImage = in.readInt();
41+
this.mTitle = in.readString();
42+
}
43+
44+
public static final Parcelable.Creator<Card> CREATOR = new Parcelable.Creator<Card>() {
45+
@Override
46+
public Card createFromParcel(Parcel source) {
47+
return new Card(source);
48+
}
49+
50+
@Override
51+
public Card[] newArray(int size) {
52+
return new Card[size];
53+
}
54+
};
2355
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package me.brucezz.sample;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.View;
7+
import android.widget.ImageView;
8+
import android.widget.TextView;
9+
import com.jaeger.library.StatusBarUtil;
10+
11+
/**
12+
* Created by brucezz on 2016-10-28.
13+
* Github: https://github.com/brucezz
14+
15+
*/
16+
17+
public class DetailActivity extends AppCompatActivity {
18+
19+
ImageView mImageView;
20+
TextView mTextView;
21+
View mContent;
22+
23+
@Override
24+
protected void onCreate(@Nullable Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
27+
setContentView(R.layout.activity_detail);
28+
29+
mImageView = (ImageView) findViewById(R.id.detail_bg);
30+
mTextView = (TextView) findViewById(R.id.detail_title);
31+
mContent = findViewById(R.id.detail_content);
32+
33+
Card card = getIntent().getParcelableExtra("card");
34+
mImageView.setImageResource(card.mImage);
35+
StatusBarUtil.setColor(this, card.mBgColor);
36+
mTextView.setText(card.mTitle);
37+
38+
animContent();
39+
}
40+
41+
private void animContent() {
42+
mTextView.animate().alpha(1f).setDuration(500).start();
43+
mContent.animate().alpha(1f).setDuration(500).start();
44+
}
45+
46+
@Override
47+
public void onBackPressed() {
48+
//setResult(RESULT_OK);
49+
finish();
50+
overridePendingTransition(0, 0);
51+
}
52+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package me.brucezz.sample;
2+
3+
import android.content.Context;
4+
import android.content.res.Resources;
5+
import android.util.DisplayMetrics;
6+
import android.util.TypedValue;
7+
8+
/**
9+
* Created by david on 16/5/26.
10+
11+
* GitHub: https://github.com/alighters
12+
*/
13+
public class DisplayUtil {
14+
15+
private static final String TAG = DisplayUtil.class.getSimpleName();
16+
17+
private static Context mContext;
18+
19+
public static void init(Context context) {
20+
mContext = context;
21+
}
22+
23+
/**
24+
* 获取屏幕宽度
25+
*/
26+
public static int getScreenWidthPixel() {
27+
return getDisplayMetrics().widthPixels;
28+
}
29+
30+
/**
31+
* 获取屏幕高度
32+
*/
33+
public static int getScreenHeightPixel() {
34+
return getDisplayMetrics().heightPixels;
35+
}
36+
37+
/**
38+
* 获取 显示信息
39+
*/
40+
public static DisplayMetrics getDisplayMetrics() {
41+
return mContext.getResources().getDisplayMetrics();
42+
}
43+
44+
/**
45+
* px转dp
46+
*/
47+
public static int px2Dp(int px) {
48+
return (int) (px / getDisplayMetrics().density);
49+
}
50+
51+
/**
52+
* px转dp
53+
*/
54+
public static int dp2Px(float dpValue) {
55+
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, getDisplayMetrics());
56+
}
57+
58+
/**
59+
* sx转dp
60+
*/
61+
public static int sp2Px(float spValue) {
62+
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, getDisplayMetrics());
63+
}
64+
65+
/**
66+
* 获取状态栏高度
67+
*/
68+
public static int getStatusBarHeight(Context context) {
69+
int statusBarHeight = 0;
70+
try {
71+
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
72+
if (resourceId > 0) {
73+
statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
74+
}
75+
} catch (Resources.NotFoundException exception) {
76+
}
77+
return statusBarHeight;
78+
}
79+
80+
/**
81+
* 获取导航栏高度
82+
*/
83+
public static int getNavigationBarHeight(Context context) {
84+
Resources resources = context.getResources();
85+
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
86+
if (resourceId > 0) {
87+
return resources.getDimensionPixelSize(resourceId);
88+
}
89+
return 0;
90+
}
91+
}

0 commit comments

Comments
 (0)