mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Improved the quality of PR
This commit is contained in:
parent
53d274ba3b
commit
3cf7080d40
4 changed files with 62 additions and 46 deletions
|
|
@ -250,7 +250,6 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
|||
achievements.setFeaturedImages
|
||||
(featuredImages.getInt("Quality_images") +
|
||||
featuredImages.getInt("Featured_pictures_on_Wikimedia_Commons"));
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -275,8 +274,8 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
|||
levelNumber.setText(levelUpInfoString);
|
||||
final ContextThemeWrapper wrapper = new ContextThemeWrapper(this, levelInfo.getLevelStyle());
|
||||
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.badge, wrapper.getTheme());
|
||||
Bitmap bitmap = drawableToBitmap(drawable);
|
||||
BitmapDrawable bitmapImage = writeOnDrawable(bitmap, Integer.toString(levelInfo.getLevel()));
|
||||
Bitmap bitmap = BitmapUtils.drawableToBitmap(drawable);
|
||||
BitmapDrawable bitmapImage = BitmapUtils.writeOnDrawable(bitmap, Integer.toString(levelInfo.getLevel()),this);
|
||||
imageView.setImageDrawable(bitmapImage);
|
||||
}
|
||||
|
||||
|
|
@ -322,48 +321,6 @@ public class AchievementsActivity extends NavigationBaseActivity {
|
|||
levelNumber.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* write level Number on the badge
|
||||
* @param bm
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
public BitmapDrawable writeOnDrawable(Bitmap bm, String text){
|
||||
Bitmap.Config config = bm.getConfig();
|
||||
if(config == null){
|
||||
config = Bitmap.Config.ARGB_8888;
|
||||
}
|
||||
Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(),bm.getHeight(),config);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(bm, 0, 0, null);
|
||||
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setColor(Color.WHITE);
|
||||
paint.setTextSize(Math.round(canvas.getHeight()/2));
|
||||
paint.setTextAlign(Paint.Align.CENTER);
|
||||
Rect rectText = new Rect();
|
||||
paint.getTextBounds(text,0, text.length(),rectText);
|
||||
canvas.drawText(text, Math.round(canvas.getWidth()/2),Math.round(canvas.getHeight()/1.35), paint);
|
||||
return new BitmapDrawable(getResources(), bitmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Drawable to bitmap
|
||||
* @param drawable
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap drawableToBitmap (Drawable drawable) {
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable)drawable).getBitmap();
|
||||
}
|
||||
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* It display the alertDialog with Image of screenshot
|
||||
* @param screenshot
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
package fr.free.nrw.commons.achievements;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class BitmapUtils {
|
||||
|
||||
/**
|
||||
* write level Number on the badge
|
||||
* @param bm
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
public static BitmapDrawable writeOnDrawable(Bitmap bm, String text, Context context){
|
||||
Bitmap.Config config = bm.getConfig();
|
||||
if(config == null){
|
||||
config = Bitmap.Config.ARGB_8888;
|
||||
}
|
||||
Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(),bm.getHeight(),config);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(bm, 0, 0, null);
|
||||
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setColor(Color.WHITE);
|
||||
paint.setTextSize(Math.round(canvas.getHeight()/2));
|
||||
paint.setTextAlign(Paint.Align.CENTER);
|
||||
Rect rectText = new Rect();
|
||||
paint.getTextBounds(text,0, text.length(),rectText);
|
||||
canvas.drawText(text, Math.round(canvas.getWidth()/2),Math.round(canvas.getHeight()/1.35), paint);
|
||||
return new BitmapDrawable(context.getResources(), bitmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Drawable to bitmap
|
||||
* @param drawable
|
||||
* @return
|
||||
*/
|
||||
public static Bitmap drawableToBitmap (Drawable drawable) {
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable)drawable).getBitmap();
|
||||
}
|
||||
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ public class LevelController {
|
|||
level.setMaximumUniqueImagesUsed(5);
|
||||
if(achievements.getImagesUploaded() >= 100 && achievements.getUniqueUsedImages() >= 45){
|
||||
level.setLevel(10);
|
||||
level.setMaximumUniqueImagesUsed(50);
|
||||
level.setMaximumUploadCount(110);
|
||||
level.setLevelStyle(R.style.LevelFive);
|
||||
} else if (achievements.getImagesUploaded() >= 90 && achievements.getUniqueUsedImages() >= 40){
|
||||
level.setLevel(9);
|
||||
|
|
|
|||
|
|
@ -81,10 +81,11 @@
|
|||
android:layout_marginRight="32dp"
|
||||
android:id="@+id/images_uploaded_progressbar"
|
||||
android:progress="50"
|
||||
app:progress_text_size="9dp"
|
||||
app:progress_end_color="#8C8B98"
|
||||
app:progress_start_color="#3A3381"
|
||||
app:progress_stroke_width="3dp"
|
||||
app:progress_text_format_pattern="12/24"
|
||||
app:progress_text_format_pattern="573/110"
|
||||
app:progress_text_color="@color/secondaryColor"
|
||||
app:style="solid_line" />
|
||||
|
||||
|
|
@ -119,6 +120,7 @@
|
|||
android:id="@+id/image_reverts_progressbar"
|
||||
app:progress_end_color="#8C8B98"
|
||||
app:progress_start_color="#3A3381"
|
||||
app:progress_text_size="9dp"
|
||||
app:progress_stroke_width="3dp"
|
||||
app:progress_text_format_pattern="12/24"
|
||||
app:progress_text_color="@color/secondaryColor"
|
||||
|
|
@ -153,6 +155,7 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_marginRight="32dp"
|
||||
android:progress="50"
|
||||
app:progress_text_size="9dp"
|
||||
android:id="@+id/images_used_by_wiki_progressbar"
|
||||
app:progress_end_color="#8C8B98"
|
||||
app:progress_start_color="#3A3381"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue