1
- package fr .free .nrw .commons ;
1
+ package fr .free .nrw .commons . achievements ;
2
2
3
3
import android .content .Intent ;
4
4
import android .graphics .Bitmap ;
20
20
21
21
import java .io .File ;
22
22
import java .io .FileOutputStream ;
23
+ import java .io .IOException ;
23
24
import java .util .Random ;
24
25
26
+ import butterknife .BindView ;
27
+ import butterknife .ButterKnife ;
28
+ import dagger .Binds ;
29
+ import fr .free .nrw .commons .R ;
25
30
import fr .free .nrw .commons .theme .NavigationBaseActivity ;
26
31
27
- public class Achievements extends AppCompatActivity {
32
+ public class AchievementsActivity extends AppCompatActivity {
33
+
34
+ private static final double BADGE_IMAGE_WIDTH_RATIO = 0.4 ;
35
+ private static final double BADGE_IMAGE_HEIGHT_RATIO = 0.36 ;
36
+
37
+ @ BindView (R .id .achievement_badge ) ImageView imageView ;
38
+ @ BindView (R .id .toolbar ) android .support .v7 .widget .Toolbar toolbar ;
28
39
29
- private static final double badge_image_ratio_width = 0.4 ;
30
- private static final double badge_image_ratio_height = 0.36 ;
31
- private ImageView imageView ;
32
40
@ Override
33
41
protected void onCreate (Bundle savedInstanceState ) {
34
42
super .onCreate (savedInstanceState );
35
43
setContentView (R .layout .activity_achievements );
44
+ ButterKnife .bind (this );
36
45
37
46
DisplayMetrics displayMetrics = new DisplayMetrics ();
38
47
getWindowManager ().getDefaultDisplay ().getMetrics (displayMetrics );
39
48
int height = displayMetrics .heightPixels ;
40
49
int width = displayMetrics .widthPixels ;
41
50
42
- imageView = (ImageView )findViewById (R .id .achievement_badge );
43
-
44
51
RelativeLayout .LayoutParams params = (RelativeLayout .LayoutParams )
45
52
imageView .getLayoutParams ();
46
- params .height = (int ) (height *badge_image_ratio_height );
47
- params .width = (int ) (width *badge_image_ratio_width );
53
+ params .height = (int ) (height *BADGE_IMAGE_HEIGHT_RATIO );
54
+ params .width = (int ) (width *BADGE_IMAGE_WIDTH_RATIO );
48
55
imageView .setImageResource (R .drawable .sydney_opera_house );
49
56
imageView .requestLayout ();
50
57
51
- android .support .v7 .widget .Toolbar toolbar = (android .support .v7 .widget .Toolbar ) findViewById (R .id .toolbar );
52
58
setSupportActionBar (toolbar );
53
-
54
59
}
55
60
56
61
@ Override
@@ -73,6 +78,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
73
78
return super .onOptionsItemSelected (item );
74
79
}
75
80
81
+ /**
82
+ * To take screenshot of the screen and return it in Bitmap format
83
+ * @param view
84
+ * @return
85
+ */
76
86
public static Bitmap getScreenShot (View view ) {
77
87
View screenView = view .getRootView ();
78
88
screenView .setDrawingCacheEnabled (true );
@@ -81,6 +91,10 @@ public static Bitmap getScreenShot(View view) {
81
91
return bitmap ;
82
92
}
83
93
94
+ /**
95
+ * To take bitmap and store it temporary storage and share it
96
+ * @param bitmap
97
+ */
84
98
void shareScreen ( Bitmap bitmap ){
85
99
try {
86
100
File file = new File (this .getExternalCacheDir (),"screen.png" );
@@ -94,11 +108,9 @@ void shareScreen ( Bitmap bitmap){
94
108
intent .putExtra (Intent .EXTRA_STREAM , Uri .fromFile (file ));
95
109
intent .setType ("image/png" );
96
110
startActivity (Intent .createChooser (intent , "Share image via" ));
97
- } catch (Exception e ) {
98
- e . printStackTrace ();
111
+ } catch (IOException e ) {
112
+ //Do Nothing
99
113
}
100
114
}
101
115
102
-
103
-
104
116
}
0 commit comments