Update chart color definition algorithm
Everything comes now from the MoodlUtilBox
This commit is contained in:
parent
16eafc075a
commit
e6d69a01ce
@ -44,6 +44,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.herbron.moodl.MoodlBox.getColor;
|
||||
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
|
||||
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() {
|
||||
@Override
|
||||
public void onBitmapDownloaded(Bitmap bitmapIcon) {
|
||||
Palette.Builder builder = Palette.from(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();
|
||||
|
||||
|
@ -30,6 +30,7 @@ import com.herbron.moodl.R;
|
||||
import java.util.List;
|
||||
|
||||
import static com.herbron.moodl.MoodlBox.getDrawable;
|
||||
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 27/05/2018.
|
||||
@ -121,20 +122,6 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
|
||||
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()
|
||||
{
|
||||
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
|
||||
public void onBitmapDownloaded(Bitmap bitmap) {
|
||||
currency.setIcon(bitmap);
|
||||
updateChartColor(currency);
|
||||
currency.setChartColor(getIconDominantColor(getContext(), bitmap));
|
||||
countIcons(currencies[0]);
|
||||
}
|
||||
});
|
||||
@ -216,7 +203,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface
|
||||
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
|
||||
|
||||
currency.setIcon(icon);
|
||||
updateChartColor(currency);
|
||||
currency.setChartColor(getIconDominantColor(getContext(), icon));
|
||||
countIcons(currencies[0]);
|
||||
}
|
||||
}
|
||||
|
@ -708,26 +708,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
||||
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
|
||||
protected Void doInBackground(Void... params)
|
||||
{
|
||||
@ -744,7 +724,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
||||
|
||||
localCurrency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(localCurrency.getSymbol()));
|
||||
|
||||
updateChartColor(localCurrency);
|
||||
localCurrency.setChartColor(getIconDominantColor(baseContext, localCurrency.getIcon()));
|
||||
|
||||
loadCurrency(localCurrency);
|
||||
|
||||
|
@ -43,6 +43,7 @@ import java.util.List;
|
||||
import static com.herbron.moodl.MoodlBox.collapseW;
|
||||
import static com.herbron.moodl.MoodlBox.expandW;
|
||||
import static com.herbron.moodl.MoodlBox.getColor;
|
||||
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
int id = 0;
|
||||
@ -454,7 +441,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac
|
||||
@Override
|
||||
public void onBitmapDownloaded(Bitmap bitmapIcon) {
|
||||
currency.setIcon(bitmapIcon);
|
||||
updateChartColor(currency);
|
||||
currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon));
|
||||
countWatchlist();
|
||||
|
||||
}
|
||||
@ -466,7 +453,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac
|
||||
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
|
||||
|
||||
currency.setIcon(icon);
|
||||
updateChartColor(currency);
|
||||
currency.setChartColor(getIconDominantColor(getContext(), icon));
|
||||
countWatchlist();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.v7.graphics.Palette;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@ -297,4 +298,18 @@ public class MoodlBox {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user