Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit b3bd88a

Browse files
authored
Merge pull request #2525 from dkanada/pieview
add PieFractionview to android client
2 parents 21fbd8f + cc72dcd commit b3bd88a

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Improvements:
99

1010
Other changes:
1111
- Upgrade olm-sdk.aar from version 2.2.2 to version 2.3.0
12+
- move PieFractionView from the SDK to the client (#2525)
1213

1314
Bugfix:
1415
-

vector/src/main/java/im/vector/adapters/VectorMediasViewerAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.matrix.androidsdk.util.ImageUtils;
5252
import org.matrix.androidsdk.util.JsonUtils;
5353
import org.matrix.androidsdk.util.Log;
54-
import org.matrix.androidsdk.view.PieFractionView;
5554

5655
import java.io.File;
5756
import java.io.FileInputStream;
@@ -62,6 +61,7 @@
6261
import im.vector.R;
6362
import im.vector.activity.CommonActivityUtils;
6463
import im.vector.util.SlidableMediaInfo;
64+
import im.vector.view.PieFractionView;
6565

6666
/**
6767
* An images slider
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2014 OpenMarket Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package im.vector.view;
17+
18+
import android.content.Context;
19+
import android.content.res.TypedArray;
20+
import android.graphics.Canvas;
21+
import android.graphics.Paint;
22+
import android.graphics.RectF;
23+
import android.util.AttributeSet;
24+
import android.view.View;
25+
26+
import im.vector.R;
27+
28+
/**
29+
* View that displays a disc representing a percentage.
30+
*/
31+
public class PieFractionView extends View {
32+
33+
private static final int START_ANGLE = -90;
34+
35+
// fraction between 0 and 100
36+
private int fraction = 0;
37+
38+
private final RectF rectF;
39+
private final Paint paint;
40+
41+
private int fillColor;
42+
private int restColor;
43+
44+
public int getFillColor() {
45+
return getResources().getColor(R.color.vector_green_color);
46+
}
47+
48+
public int getRestColor() {
49+
return getResources().getColor(R.color.vector_dark_grey_color);
50+
}
51+
52+
@SuppressWarnings("ResourceType")
53+
public PieFractionView(Context context, AttributeSet attrs) {
54+
super(context, attrs);
55+
56+
int[] attrArray = new int[] {android.R.attr.layout_width, android.R.attr.layout_height};
57+
TypedArray typedArray = context.obtainStyledAttributes(attrs, attrArray);
58+
int width = typedArray.getDimensionPixelSize(0, 0);
59+
int height = typedArray.getDimensionPixelSize(1, 0);
60+
typedArray.recycle();
61+
62+
rectF = new RectF(0, 0, width, height);
63+
paint = new Paint();
64+
65+
fillColor = getFillColor();
66+
restColor = getRestColor();
67+
}
68+
69+
public void setFraction(int fraction) {
70+
// check bounds and avoid useless refresh
71+
if ((0 <= fraction) && (fraction <= 100) && (this.fraction != fraction)) {
72+
this.fraction = fraction;
73+
invalidate();
74+
}
75+
}
76+
77+
@Override
78+
protected void onDraw(Canvas canvas) {
79+
int angle = fraction * 360 / 100;
80+
81+
// draw the fill section
82+
paint.setColor(fillColor);
83+
canvas.drawArc(rectF, START_ANGLE, angle, true, paint);
84+
85+
// draw the rest of the circle
86+
paint.setColor(restColor);
87+
canvas.drawArc(rectF, START_ANGLE + angle, 360 - angle, true, paint);
88+
}
89+
}

vector/src/main/res/layout/adapter_vector_medias_viewer.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
</RelativeLayout>
3636

3737

38-
<org.matrix.androidsdk.view.PieFractionView
38+
<im.vector.view.PieFractionView
3939
android:id="@+id/media_slider_piechart"
4040
android:layout_centerHorizontal="true"
4141
android:layout_centerVertical="true"
42-
android:alpha="0.2"
42+
android:alpha="0.4"
4343
android:layout_width="160dp"
4444
android:layout_height="160dp"/>
4545

0 commit comments

Comments
 (0)