Fix some crashes on old devices

pull/201/head
Alinson S. Xavier 9 years ago
parent f876fc50bb
commit 638b3f763c

@ -21,6 +21,7 @@ package org.isoron.uhabits.activities;
import android.content.*; import android.content.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.support.v4.content.res.*;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.*; import android.view.*;
import android.widget.*; import android.widget.*;
@ -67,9 +68,8 @@ public abstract class BaseRootView extends FrameLayout
{ {
if (SDK_INT < LOLLIPOP && !themeSwitcher.isNightMode()) if (SDK_INT < LOLLIPOP && !themeSwitcher.isNightMode())
{ {
return context return ResourcesCompat.getColor(context.getResources(),
.getResources() R.color.grey_900, context.getTheme());
.getColor(R.color.grey_900, context.getTheme());
} }
StyledResources res = new StyledResources(context); StyledResources res = new StyledResources(context);

@ -26,6 +26,7 @@ import android.net.*;
import android.os.*; import android.os.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.support.design.widget.*; import android.support.design.widget.*;
import android.support.v4.content.res.*;
import android.support.v7.app.*; import android.support.v7.app.*;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -103,9 +104,8 @@ public class BaseScreen
{ {
if (SDK_INT < LOLLIPOP) if (SDK_INT < LOLLIPOP)
{ {
return context return ResourcesCompat.getColor(context.getResources(),
.getResources() R.color.grey_900, context.getTheme());
.getColor(R.color.grey_900, context.getTheme());
} }
else else
{ {

@ -163,6 +163,9 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
@Override @Override
public void onPostExecute() public void onPostExecute()
{ {
if (getContext() == null || habit == null || historyChart == null)
return;
int color = ColorUtils.getColor(getContext(), habit.getColor()); int color = ColorUtils.getColor(getContext(), habit.getColor());
historyChart.setColor(color); historyChart.setColor(color);
historyChart.setCheckmarks(checkmarks); historyChart.setCheckmarks(checkmarks);

@ -239,7 +239,7 @@ public class HabitCardView extends FrameLayout
background = res.getDrawable(R.attr.selectedBackground); background = res.getDrawable(R.attr.selectedBackground);
else background = res.getDrawable(R.attr.cardBackground); else background = res.getDrawable(R.attr.cardBackground);
innerFrame.setBackground(background); innerFrame.setBackgroundDrawable(background);
} }
} }

@ -144,12 +144,18 @@ public abstract class BaseWidget
return new int[]{ w, h, w, h }; return new int[]{ w, h, w, h };
} }
@NonNull
private Bitmap getBitmapFromView(View view) private Bitmap getBitmapFromView(View view)
{ {
view.invalidate(); view.invalidate();
view.setDrawingCacheEnabled(true); view.setDrawingCacheEnabled(true);
view.buildDrawingCache(true); view.buildDrawingCache(true);
return view.getDrawingCache(); Bitmap drawingCache = view.getDrawingCache();
if(drawingCache == null)
throw new IllegalStateException("bitmap is null");
return drawingCache;
} }
@NonNull @NonNull

Loading…
Cancel
Save