77import  android .content .Context ;
88import  android .content .Intent ;
99import  android .content .SharedPreferences ;
10+ import  android .content .res .TypedArray ;
1011import  android .graphics .Bitmap ;
12+ import  android .graphics .Canvas ;
1113import  android .graphics .Color ;
1214import  android .graphics .DashPathEffect ;
1315import  android .os .Build ;
3133import  java .util .concurrent .ExecutionException ;
3234
3335import  androidx .annotation .NonNull ;
36+ import  androidx .constraintlayout .widget .ConstraintLayout ;
3437import  androidx .core .content .ContextCompat ;
3538import  javinator9889 .bitcoinpools .BitCoinApp ;
3639import  javinator9889 .bitcoinpools .Constants ;
@@ -152,8 +155,12 @@ void putNotification() {
152155                            .setStyle (new  Notification .BigTextStyle ()
153156                                    .bigText (notificationTextLong ));
154157                }
155-                 if  (chartBitmap  != null )
158+                 if  (chartBitmap  != null ) { 
156159                    notification .setLargeIcon (chartBitmap );
160+                     notification .setStyle (new  Notification .BigPictureStyle ()
161+                             .bigPicture (chartBitmap )
162+                             .bigLargeIcon ((Bitmap ) null ));
163+                 }
157164                notification .setContentIntent (clickIntent );
158165                assert  notificationManager  != null ;
159166                notificationManager .notify (Constants .NOTIFICATION_ID , notification .build ());
@@ -175,6 +182,7 @@ private Bitmap generateLineChart(@NonNull final LineChart lineChart) {
175182        pricesMap  = getValuesByDatedURL (url );
176183        if  (pricesMap  == null )
177184            return  null ;
185+ //        lineChart.setDrawingCacheEnabled(true); 
178186        lineChart .setDrawGridBackground (false );
179187        lineChart .getDescription ().setEnabled (false );
180188        CustomMarkerView  markerView  = new  CustomMarkerView (mContext , R .layout .marker_view );
@@ -199,8 +207,7 @@ private Bitmap generateLineChart(@NonNull final LineChart lineChart) {
199207        lineDataSet .setValueTextSize (9f );
200208        lineDataSet .setDrawFilled (true );
201209        lineDataSet .setFormLineWidth (1f );
202-         lineDataSet .setFormLineDashEffect (new  DashPathEffect (new  float []{10f , 5f },
203-                 0f ));
210+         lineDataSet .setFormLineDashEffect (new  DashPathEffect (new  float []{10f , 5f }, 0f ));
204211        lineDataSet .setFormSize (15.f );
205212        lineDataSet .setMode (LineDataSet .Mode .CUBIC_BEZIER );
206213        lineDataSet .setFillDrawable (ContextCompat .getDrawable (mContext , R .drawable .fade_red ));
@@ -210,8 +217,7 @@ private Bitmap generateLineChart(@NonNull final LineChart lineChart) {
210217        LineData  data  = new  LineData (dataSets );
211218        lineChart .setData (data );
212219        lineChart .getAxisLeft ().setValueFormatter (new  LargeValueFormatter ());
213-         lineChart .invalidate ();
214-         return  lineChart .getChartBitmap ();
220+         return  setLayoutParams (lineChart );
215221    }
216222
217223    private  Map <Date , Float > getValuesByDatedURL (@ NonNull  String  url ) {
@@ -226,6 +232,37 @@ private Map<Date, Float> getValuesByDatedURL(@NonNull String url) {
226232        }
227233    }
228234
235+     private  Bitmap  setLayoutParams (@ NonNull  final  LineChart  lineChart ) {
236+         float  dpHeight  = mContext .getResources ().getDisplayMetrics ().heightPixels ;
237+         float  dpWidth  = mContext .getResources ().getDisplayMetrics ().widthPixels ;
238+ 
239+         int [] attrs  = new  int []{R .attr .actionBarSize };
240+         TypedArray  array  = mContext .obtainStyledAttributes (attrs );
241+         int  size  = array .getDimensionPixelSize (0 , 0 );
242+         array .recycle ();
243+ 
244+         int  finalHeightDp  = (int ) ((dpHeight  - size ) * 0.5 );
245+         int  finalWidthDp  = (int ) ((dpWidth  - size ) * 0.9 );
246+ 
247+         System .out .println ("Height: "  + finalHeightDp );
248+         System .out .println ("Width: "  + finalWidthDp );
249+ 
250+         Bitmap  bitmap  = Bitmap .createBitmap (finalWidthDp , finalHeightDp , Bitmap .Config .ARGB_8888 );
251+         Canvas  canvas  = new  Canvas (bitmap );
252+ 
253+         ConstraintLayout .LayoutParams  layoutParams  =
254+                 new  ConstraintLayout .LayoutParams (finalWidthDp , finalHeightDp );
255+         layoutParams .matchConstraintMaxHeight  = (int ) dpHeight ;
256+         layoutParams .matchConstraintMaxWidth  = (int ) dpWidth ;
257+         layoutParams .orientation  = ConstraintLayout .LayoutParams .HORIZONTAL ;
258+         layoutParams .validate ();
259+ 
260+         lineChart .setLayoutParams (layoutParams );
261+         lineChart .invalidate ();
262+         lineChart .draw (canvas );
263+         return  bitmap ;
264+     }
265+ 
229266    @ NonNull 
230267    static  NotificationHandler  newInstance (@ NonNull  Context  context ) {
231268        return  new  NotificationHandler (context );
0 commit comments