Fix some crashes on old devices

This commit is contained in:
2016-09-30 08:10:25 -04:00
parent f876fc50bb
commit 638b3f763c
5 changed files with 17 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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

View File

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