Skip to content

Commit 21da5d7

Browse files
committed
Merge branch 'master' of github.com:DingMouRen/PaletteImageView
2 parents 500f769 + 3ef7cb5 commit 21da5d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+28
-80
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
android:supportsRtl="true"
1010
android:theme="@style/AppTheme">
1111
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
1214

15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
1317
</activity>
1418
<activity android:name=".SampleOneActivity"
1519
android:theme="@style/SampleOneStyle"
1620
>
17-
<intent-filter>
18-
<action android:name="android.intent.action.MAIN" />
1921

20-
<category android:name="android.intent.category.LAUNCHER" />
21-
</intent-filter>
2222
</activity>
2323
<activity android:name=".SampleTwoActivity"
2424
android:theme="@style/SampleTwoStyle"

app/src/main/java/com/dingmouren/smaple/paletteimageview/Constant.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ public class Constant {
4040

4141
public static int[] mHeros = new int[]{
4242
R.drawable.p1,
43+
R.drawable.p5,
44+
R.drawable.p6,
45+
R.drawable.p15,
4346
R.drawable.p2,
4447
R.drawable.p3,
4548
R.drawable.p4,
46-
R.drawable.p5,
47-
R.drawable.p6,
4849
R.drawable.p7,
4950
R.drawable.p8,
5051
R.drawable.p9,
@@ -53,7 +54,6 @@ public class Constant {
5354
R.drawable.p12,
5455
R.drawable.p13,
5556
R.drawable.p14,
56-
R.drawable.p15,
5757
R.drawable.p16,
5858
R.drawable.p17,
5959
R.drawable.p18,

app/src/main/java/com/dingmouren/smaple/paletteimageview/SampleOneActivity.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,21 @@
3535
public class SampleOneActivity extends AppCompatActivity {
3636
private ViewPager mViewPager;
3737
private SampleOneAdapter mAdapter;
38-
private RelativeLayout mActionBar;
39-
private Window window;
4038
@Override
4139
protected void onCreate(@Nullable Bundle savedInstanceState) {
4240
super.onCreate(savedInstanceState);
4341
setContentView(R.layout.activity_sample_one);
44-
window = SampleOneActivity.this.getWindow();
45-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
46-
window.setStatusBarColor(getResources().getColor(R.color.md_teal_A400));
47-
}
4842
initView();
4943
initData();
5044
}
5145

5246
private void initView() {
5347
mViewPager = (ViewPager) findViewById(R.id.viewpager);
54-
mActionBar = (RelativeLayout) findViewById(R.id.action_bar);
5548
}
5649

5750
private void initData(){
5851
mAdapter = new SampleOneAdapter(getSupportFragmentManager());
5952
mViewPager.setAdapter(mAdapter);
60-
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
61-
@Override
62-
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
63-
64-
}
65-
66-
@Override
67-
public void onPageSelected(int position) {
68-
int color = mAdapter.getList().get(position).paletteImageView.mMainColor;
69-
mActionBar.setBackgroundColor(color);
70-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
71-
window.setStatusBarColor(color);
72-
}
73-
}
74-
75-
@Override
76-
public void onPageScrollStateChanged(int state) {
77-
78-
}
79-
});
8053

8154
}
8255

app/src/main/java/com/dingmouren/smaple/paletteimageview/SampleOneAdapter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,15 @@
1818
*/
1919

2020
public class SampleOneAdapter extends FragmentStatePagerAdapter {
21-
private Set<SampleOneFragment> mSet = new LinkedHashSet<>();
22-
private List<SampleOneFragment> mList = new ArrayList<>();
2321
public SampleOneAdapter(FragmentManager fm) {
2422
super(fm);
2523
}
2624

2725
@Override
2826
public Fragment getItem(int position) {
2927
SampleOneFragment fragment = SampleOneFragment.newInstance(Constant.mHeros[position]);
30-
mSet.add(fragment);
3128
return fragment;
3229
}
33-
public List<SampleOneFragment> getList(){
34-
mList.clear();
35-
Iterator iterator = mSet.iterator();
36-
while (iterator.hasNext()){
37-
mList.add((SampleOneFragment) iterator.next());
38-
}
39-
return mList;
40-
}
4130
@Override
4231
public int getCount() {
4332
return Constant.mHeros.length;

app/src/main/java/com/dingmouren/smaple/paletteimageview/SampleOneFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.os.Bundle;
77
import android.support.annotation.Nullable;
88
import android.support.v4.app.Fragment;
9+
import android.util.TypedValue;
910
import android.view.LayoutInflater;
1011
import android.view.View;
1112
import android.view.ViewGroup;

app/src/main/res/drawable-hdpi/p1.jpg

-113 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p1.png

71.9 KB
-172 KB
Binary file not shown.
85.9 KB
-102 KB
Binary file not shown.
76 KB
-135 KB
Binary file not shown.
70.3 KB
-104 KB
Binary file not shown.
84.4 KB
-114 KB
Binary file not shown.
73.6 KB
-122 KB
Binary file not shown.
96.8 KB
-4.53 KB
Binary file not shown.
55.7 KB
-8.05 KB
Binary file not shown.
92.6 KB
-143 KB
Binary file not shown.
82.8 KB
-63.7 KB
Binary file not shown.
89.8 KB

app/src/main/res/drawable-hdpi/p2.jpg

-287 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p2.png

95.8 KB
-8.97 KB
Binary file not shown.
91.8 KB

app/src/main/res/drawable-hdpi/p3.jpg

-153 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p3.png

87.7 KB

app/src/main/res/drawable-hdpi/p4.jpg

-121 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p4.png

77.2 KB

app/src/main/res/drawable-hdpi/p5.jpg

-189 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p5.png

84.4 KB

app/src/main/res/drawable-hdpi/p6.jpg

-201 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p6.png

80.2 KB

app/src/main/res/drawable-hdpi/p7.jpg

-121 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p7.png

75.3 KB

app/src/main/res/drawable-hdpi/p8.jpg

-214 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p8.png

93 KB

app/src/main/res/drawable-hdpi/p9.jpg

-164 KB
Binary file not shown.

app/src/main/res/drawable-hdpi/p9.png

69.7 KB

app/src/main/res/layout/activity_main.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525

2626
<com.dingmouren.paletteimageview.PaletteImageView
2727
android:id="@+id/palette"
28-
android:layout_width="match_parent"
29-
android:layout_height="wrap_content"
28+
android:layout_width="300dp"
29+
android:layout_height="300dp"
3030
android:layout_gravity="center_horizontal"
31-
app:palettePadding="20dp"
32-
app:paletteSrc="@mipmap/meigui" />
31+
app:palettePadding="30dp"
32+
app:paletteSrc="@mipmap/test1" />
3333

3434
<LinearLayout
3535
android:layout_width="match_parent"

app/src/main/res/layout/item_sample_one.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
android:id="@+id/palette"
1010
android:layout_width="300dp"
1111
android:layout_height="wrap_content"
12-
app:palettePadding="20dp"
12+
app:palettePadding="30dp"
1313
app:paletteRadius="10dp"
14+
app:paletteOffsetX="20dp"
15+
app:paletteOffsetY="20dp"
16+
app:paletteShadowRadius="10dp"
1417
android:layout_gravity="center_horizontal"
1518
/>
1619
</LinearLayout>
33.4 KB
68.1 KB

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<item name="colorAccent">@color/md_teal_A400</item>
99
</style>
1010
<style name="SampleOneStyle" parent="Theme.AppCompat.Light.NoActionBar">
11+
<item name="android:statusBarColor" tools:ignore="NewApi">@color/md_teal_A400</item>
1112
</style>
1213
<style name="SampleTwoStyle" parent="Theme.AppCompat.Light.NoActionBar">
1314
<item name="android:statusBarColor" tools:ignore="NewApi">@color/md_teal_A400</item>

paletteimageview/src/main/java/com/dingmouren/paletteimageview/PaletteImageView.java

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* Created by dingmouren on 2017/4/25.
32+
*
3233
*/
3334

3435
public class PaletteImageView extends View implements ViewTreeObserver.OnGlobalLayoutListener {
@@ -58,6 +59,9 @@ public class PaletteImageView extends View implements ViewTreeObserver.OnGlobalL
5859
private Handler mHandler = new Handler() {
5960
@Override
6061
public void handleMessage(Message msg) {
62+
if (mOffsetX < DEFAULT_OFFSET) mOffsetX = DEFAULT_OFFSET;
63+
if (mOffsetY < DEFAULT_OFFSET) mOffsetY = DEFAULT_OFFSET;
64+
if (mShadowRadius < DEFAULT_SHADOW_RADIUS) mShadowRadius = DEFAULT_SHADOW_RADIUS;
6165
mPaintShadow.setShadowLayer(mShadowRadius, mOffsetX, mOffsetY, mMainColor);
6266
invalidate();
6367
}
@@ -89,6 +93,9 @@ private void init(Context context, AttributeSet attrs) {
8993
mRadius = a.getDimensionPixelSize(R.styleable.PaletteImageView_paletteRadius, 0);
9094
mImgId = a.getResourceId(R.styleable.PaletteImageView_paletteSrc, 0);
9195
mPadding = a.getDimensionPixelSize(R.styleable.PaletteImageView_palettePadding, DEFAULT_PADDING);
96+
mOffsetX = a.getDimensionPixelSize(R.styleable.PaletteImageView_paletteOffsetX,DEFAULT_OFFSET);
97+
mOffsetY = a.getDimensionPixelSize(R.styleable.PaletteImageView_paletteOffsetY,DEFAULT_OFFSET);
98+
mShadowRadius = a.getDimensionPixelSize(R.styleable.PaletteImageView_paletteShadowRadius,DEFAULT_SHADOW_RADIUS);
9299
a.recycle();
93100

94101
setPadding(mPadding, mPadding, mPadding, mPadding);
@@ -115,15 +122,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
115122
}
116123
if (mBitmap != null) {
117124
height = (int) ((width - mPadding * 2) * (mBitmap.getHeight() * 1.0f / mBitmap.getWidth())) + mPadding * 2;
118-
Log.e(TAG, "bitmap宽高:" + mBitmap.getWidth() + "/" + mBitmap.getHeight() + "--" + (mBitmap.getRowBytes() * mBitmap.getHeight() / 1024 / 1024));
119125
}
120126
setMeasuredDimension(width, height);
121127
}
122128

123129
@Override
124130
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
125131
super.onSizeChanged(w, h, oldw, oldh);
126-
mBitmap = ratio(mBitmap);
127132
zipBitmap(mImgId, mBitmap, mOnMeasureHeightMode);
128133
}
129134

@@ -199,7 +204,6 @@ private void initShadow(Bitmap bitmap) {
199204

200205

201206
private void zipBitmap(int imgId, Bitmap bitmap, int heightNode) {
202-
Log.e(TAG, "zip:" + bitmap.getWidth() + "/" + bitmap.getHeight());
203207
WeakReference<Matrix> weakMatrix = new WeakReference<Matrix>(new Matrix());
204208
if (weakMatrix.get() == null) return;
205209
Matrix matrix = weakMatrix.get();
@@ -244,36 +248,10 @@ private void zipBitmap(int imgId, Bitmap bitmap, int heightNode) {
244248
}
245249
mRealBitmap = Bitmap.createBitmap(bitmap, dx, dy, small, small, matrix, true);
246250
}
247-
if (mRealBitmap != null)
248-
Log.e(TAG, "mRealBitap:" + mRealBitmap.getWidth() + "/" + mRealBitmap.getHeight() + "--"/*(mBitmap.getRowBytes()* mRealBitmap.getHeight() /1024/1024)*/);
249251
initShadow(mRealBitmap);
250252

251253
}
252254

253-
public Bitmap ratio(Bitmap image) {
254-
Bitmap bitmap = null;
255-
ByteArrayOutputStream os = new ByteArrayOutputStream();
256-
image.compress(Bitmap.CompressFormat.JPEG, 100, os);
257-
if (os.toByteArray().length / 1024 > 1024) {//判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出
258-
os.reset();//重置baos即清空baos
259-
image.compress(Bitmap.CompressFormat.JPEG, 50, os);//这里压缩50%,把压缩后的数据存放到baos中
260-
}
261-
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
262-
BitmapFactory.Options newOpts = new BitmapFactory.Options();
263-
//开始读入图片,此时把options.inJustDecodeBounds 设回true了
264-
newOpts.inJustDecodeBounds = true;
265-
newOpts.inPreferredConfig = Bitmap.Config.RGB_565;
266-
bitmap = BitmapFactory.decodeStream(is, null, newOpts);
267-
newOpts.inJustDecodeBounds = false;
268-
int w = newOpts.outWidth;
269-
int h = newOpts.outHeight;
270-
newOpts.inSampleSize = calculateInSampleSize(w, h, getWidth() - mPadding * 2, getHeight() - mPadding * 2);//设置缩放比例
271-
//重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
272-
is = new ByteArrayInputStream(os.toByteArray());
273-
bitmap = BitmapFactory.decodeStream(is, null, newOpts);
274-
return bitmap;
275-
}
276-
277255
/**
278256
* 计算inSampleSize
279257
*
@@ -285,7 +263,7 @@ private int calculateInSampleSize(int rawWidth, int rawHeight, int reqWidth, int
285263
int halfHeight = rawHeight / 2;
286264
int halfWidth = rawWidth / 2;
287265
while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
288-
inSampleSize *= 12;
266+
inSampleSize *= 2;
289267
}
290268
}
291269
return inSampleSize;

paletteimageview/src/main/res/values/attr.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<attr name="paletteRadius" format="dimension" />
66
<attr name="paletteSrc" format="reference" />
77
<attr name="palettePadding" format="dimension" />
8+
<attr name="paletteOffsetX" format="dimension" />
9+
<attr name="paletteOffsetY" format="dimension" />
10+
<attr name="paletteShadowRadius" format="dimension" />
811

912
</declare-styleable>
1013
</resources>

0 commit comments

Comments
 (0)