Update chart color definition algorithm

Everything comes now from the MoodlUtilBox
This commit is contained in:
Tanguy Herbron 2018-09-01 23:30:19 +02:00
parent 16eafc075a
commit e6d69a01ce
5 changed files with 24 additions and 56 deletions

View File

@ -44,6 +44,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.herbron.moodl.MoodlBox.getColor; import static com.herbron.moodl.MoodlBox.getColor;
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
import static java.lang.Math.abs; import static java.lang.Math.abs;
/** /**
@ -265,10 +266,8 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() {
@Override @Override
public void onBitmapDownloaded(Bitmap bitmapIcon) { public void onBitmapDownloaded(Bitmap bitmapIcon) {
Palette.Builder builder = Palette.from(bitmapIcon);
coinmarketCapAPIManager.getTopCurrencies().get(index).setIcon(bitmapIcon); coinmarketCapAPIManager.getTopCurrencies().get(index).setIcon(bitmapIcon);
coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext()))); coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(getIconDominantColor(getContext(), bitmapIcon));
countIcons(); countIcons();

View File

@ -30,6 +30,7 @@ import com.herbron.moodl.R;
import java.util.List; import java.util.List;
import static com.herbron.moodl.MoodlBox.getDrawable; import static com.herbron.moodl.MoodlBox.getDrawable;
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
/** /**
* Created by Administrator on 27/05/2018. * Created by Administrator on 27/05/2018.
@ -121,20 +122,6 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
currencyLoader.execute(); currencyLoader.execute();
} }
private void updateChartColor(Currency currency)
{
if(currency.getIcon() != null)
{
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(0));
}
else
{
currency.setChartColor(12369084);
}
}
private void loadingIndicatorGenerator() private void loadingIndicatorGenerator()
{ {
loadingFooter = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.listview_loading_indicator, null, false); loadingFooter = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.listview_loading_indicator, null, false);
@ -198,7 +185,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
@Override @Override
public void onBitmapDownloaded(Bitmap bitmap) { public void onBitmapDownloaded(Bitmap bitmap) {
currency.setIcon(bitmap); currency.setIcon(bitmap);
updateChartColor(currency); currency.setChartColor(getIconDominantColor(getContext(), bitmap));
countIcons(currencies[0]); countIcons(currencies[0]);
} }
}); });
@ -216,7 +203,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
icon = Bitmap.createScaledBitmap(icon, 50, 50, false); icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
currency.setIcon(icon); currency.setIcon(icon);
updateChartColor(currency); currency.setChartColor(getIconDominantColor(getContext(), icon));
countIcons(currencies[0]); countIcons(currencies[0]);
} }
} }

View File

@ -708,26 +708,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
super.onProgressUpdate(values); super.onProgressUpdate(values);
} }
private void updateChartColor(Currency currency)
{
if(currency.getIcon() != null)
{
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext())));
}
else
{
currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext()));
}
}
private void loadCurrency(Currency currency)
{
currency.setName(balanceManager.getCurrencyName(currency.getSymbol()));
currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
}
@Override @Override
protected Void doInBackground(Void... params) protected Void doInBackground(Void... params)
{ {
@ -744,7 +724,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
localCurrency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(localCurrency.getSymbol())); localCurrency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(localCurrency.getSymbol()));
updateChartColor(localCurrency); localCurrency.setChartColor(getIconDominantColor(baseContext, localCurrency.getIcon()));
loadCurrency(localCurrency); loadCurrency(localCurrency);

View File

@ -43,6 +43,7 @@ import java.util.List;
import static com.herbron.moodl.MoodlBox.collapseW; import static com.herbron.moodl.MoodlBox.collapseW;
import static com.herbron.moodl.MoodlBox.expandW; import static com.herbron.moodl.MoodlBox.expandW;
import static com.herbron.moodl.MoodlBox.getColor; import static com.herbron.moodl.MoodlBox.getColor;
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
/** /**
* Created by Tiji on 13/04/2018. * Created by Tiji on 13/04/2018.
@ -380,20 +381,6 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac
} }
} }
private void updateChartColor(Currency currency)
{
if(currency.getIcon() != null)
{
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext())));
}
else
{
currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext()));
}
}
public int getCurrencyId(String symbol) public int getCurrencyId(String symbol)
{ {
int id = 0; int id = 0;
@ -454,7 +441,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac
@Override @Override
public void onBitmapDownloaded(Bitmap bitmapIcon) { public void onBitmapDownloaded(Bitmap bitmapIcon) {
currency.setIcon(bitmapIcon); currency.setIcon(bitmapIcon);
updateChartColor(currency); currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon));
countWatchlist(); countWatchlist();
} }
@ -466,7 +453,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac
icon = Bitmap.createScaledBitmap(icon, 50, 50, false); icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
currency.setIcon(icon); currency.setIcon(icon);
updateChartColor(currency); currency.setChartColor(getIconDominantColor(getContext(), icon));
countWatchlist(); countWatchlist();
} }
} }

View File

@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -297,4 +298,18 @@ public class MoodlBox {
return url; return url;
} }
public static int getIconDominantColor(Context context, Bitmap icon)
{
if(icon != null)
{
Palette.Builder builder = Palette.from(icon);
return builder.generate().getDominantColor(getColor(R.color.default_color, context));
}
else
{
return getColor(R.color.default_color, context);
}
}
} }