Update Piechart colors
This commit is contained in:
parent
a306f48c02
commit
511d239f16
@ -57,9 +57,15 @@ import com.nauk.coinfolio.R;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.DecimalFormatSymbols;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
//Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart
|
//Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart
|
||||||
|
|
||||||
@ -94,6 +100,8 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
private Runnable updateRunnable;
|
private Runnable updateRunnable;
|
||||||
private ViewFlipper viewFlipper;
|
private ViewFlipper viewFlipper;
|
||||||
|
|
||||||
|
private HashMap<String, Integer> dominantCurrenciesColors;
|
||||||
|
|
||||||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
||||||
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||||
|
|
||||||
@ -246,6 +254,29 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
lastTimestamp = 0;
|
lastTimestamp = 0;
|
||||||
|
|
||||||
setupNavBar(savedInstanceState);
|
setupNavBar(savedInstanceState);
|
||||||
|
|
||||||
|
setupDominantCurrenciesColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupDominantCurrenciesColors()
|
||||||
|
{
|
||||||
|
dominantCurrenciesColors = new HashMap<>();
|
||||||
|
|
||||||
|
dominantCurrenciesColors.put("BTC", -489456);
|
||||||
|
dominantCurrenciesColors.put("ETH", -13619152);
|
||||||
|
dominantCurrenciesColors.put("XRP", -16744256);
|
||||||
|
dominantCurrenciesColors.put("BCH", -1011696);
|
||||||
|
dominantCurrenciesColors.put("LTC", -4671304);
|
||||||
|
dominantCurrenciesColors.put("ADA", -16773080);
|
||||||
|
dominantCurrenciesColors.put("NEO", -9390048);
|
||||||
|
dominantCurrenciesColors.put("XLM", -11509656);
|
||||||
|
dominantCurrenciesColors.put("XMR", -499712);
|
||||||
|
dominantCurrenciesColors.put("EOS", -1513240);
|
||||||
|
dominantCurrenciesColors.put("IOT", -1513240);
|
||||||
|
dominantCurrenciesColors.put("DASH", -15175496);
|
||||||
|
dominantCurrenciesColors.put("XEM", -7829368);
|
||||||
|
dominantCurrenciesColors.put("TRX", -7829360);
|
||||||
|
dominantCurrenciesColors.put("ETC", -10448784);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupNavBar(Bundle savedInstanceState)
|
private void setupNavBar(Bundle savedInstanceState)
|
||||||
@ -269,6 +300,7 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
nav.changeCurrentItem(-1);
|
nav.changeCurrentItem(-1);
|
||||||
|
|
||||||
|
findViewById(R.id.toolbar_layout).setFocusable(true);
|
||||||
findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true);
|
findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true);
|
||||||
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true);
|
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true);
|
||||||
|
|
||||||
@ -284,6 +316,7 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
//0 : Unknown
|
//0 : Unknown
|
||||||
//1 : Market cap
|
//1 : Market cap
|
||||||
|
findViewById(R.id.toolbar_layout).setFocusable(false);
|
||||||
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
|
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
|
||||||
findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false);
|
findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false);
|
||||||
|
|
||||||
@ -421,8 +454,6 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
private void getBitmapFromURL(String src, IconCallBack callBack) {
|
private void getBitmapFromURL(String src, IconCallBack callBack) {
|
||||||
Bitmap result;
|
Bitmap result;
|
||||||
|
|
||||||
Log.d("coinfolio", "Downloading bitmap");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
java.net.URL url = new java.net.URL(src);
|
java.net.URL url = new java.net.URL(src);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url
|
HttpURLConnection connection = (HttpURLConnection) url
|
||||||
@ -523,10 +554,15 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if(marketCapCounter == 2)
|
if(marketCapCounter == 2)
|
||||||
{
|
{
|
||||||
|
setupTextViewMarketCap();
|
||||||
|
|
||||||
findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE);
|
findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE);
|
||||||
|
findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
List<PieEntry> entries = new ArrayList<>();
|
List<PieEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
|
ArrayList<Integer> colors = new ArrayList<>();
|
||||||
|
|
||||||
PieChart pieChart = findViewById(R.id.marketCapPieChart);
|
PieChart pieChart = findViewById(R.id.marketCapPieChart);
|
||||||
|
|
||||||
float otherCurrenciesDominance = 0;
|
float otherCurrenciesDominance = 0;
|
||||||
@ -534,14 +570,16 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); )
|
for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
String key = (String) i.next();
|
String key = (String) i.next();
|
||||||
Log.d(getResources().getString(R.string.debug), "Sym : " + key + " " + marketCapManager.getDominance().get(key));
|
|
||||||
entries.add(new PieEntry(marketCapManager.getDominance().get(key), key));
|
entries.add(new PieEntry(marketCapManager.getDominance().get(key), key));
|
||||||
otherCurrenciesDominance += marketCapManager.getDominance().get(key);
|
otherCurrenciesDominance += marketCapManager.getDominance().get(key);
|
||||||
|
colors.add(dominantCurrenciesColors.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
entries.add(new PieEntry(100-otherCurrenciesDominance, "Others"));
|
entries.add(new PieEntry(100-otherCurrenciesDominance, "Others"));
|
||||||
|
colors.add(-12369084);
|
||||||
|
|
||||||
PieDataSet set = new PieDataSet(entries, "Market Cap Dominance");
|
PieDataSet set = new PieDataSet(entries, "Market Cap Dominance");
|
||||||
|
set.setColors(colors);
|
||||||
|
set.setSliceSpace(1);
|
||||||
PieData data = new PieData(set);
|
PieData data = new PieData(set);
|
||||||
pieChart.setData(data);
|
pieChart.setData(data);
|
||||||
|
|
||||||
@ -550,21 +588,28 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
pieChart.setTouchEnabled(false);
|
pieChart.setTouchEnabled(false);
|
||||||
|
|
||||||
pieChart.getDescription().setEnabled(false);
|
pieChart.getDescription().setEnabled(false);
|
||||||
|
pieChart.getLegend().setEnabled(false);
|
||||||
pieChart.setCenterText(generateCenterSpannableText());
|
pieChart.setCenterText(generateCenterSpannableText());
|
||||||
pieChart.setVisibility(View.VISIBLE);
|
|
||||||
pieChart.invalidate(); // refresh
|
pieChart.invalidate(); // refresh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupTextViewMarketCap()
|
||||||
|
{
|
||||||
|
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK);
|
||||||
|
DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
|
||||||
|
|
||||||
|
symbols.setGroupingSeparator(' ');
|
||||||
|
formatter.setDecimalFormatSymbols(symbols);
|
||||||
|
|
||||||
|
((TextView) findViewById(R.id.marketCapTextView)).setText(getResources().getString(R.string.market_cap_textview, formatter.format(marketCapManager.getMarketCap())));
|
||||||
|
|
||||||
|
((TextView) findViewById(R.id.dayVolumeTotalMarketCap)).setText(getResources().getString(R.string.volume_market_cap_textview, formatter.format(marketCapManager.getDayVolume())));
|
||||||
|
}
|
||||||
|
|
||||||
private SpannableString generateCenterSpannableText() {
|
private SpannableString generateCenterSpannableText() {
|
||||||
|
|
||||||
SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
|
SpannableString s = new SpannableString("Market Capitalization Dominance");
|
||||||
s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
|
|
||||||
s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
|
|
||||||
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
|
|
||||||
s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
|
|
||||||
s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
|
|
||||||
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,6 +773,7 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
Palette.Builder builder = Palette.from(localCurrency.getIcon());
|
Palette.Builder builder = Palette.from(localCurrency.getIcon());
|
||||||
|
|
||||||
localCurrency.setChartColor(builder.generate().getDominantColor(0));
|
localCurrency.setChartColor(builder.generate().getDominantColor(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -238,6 +238,8 @@ public class BalanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void mergeBalanceTotal(List<Currency> balance)
|
private void mergeBalanceTotal(List<Currency> balance)
|
||||||
|
{
|
||||||
|
if(balance != null)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < balance.size(); i++)
|
for(int i = 0; i < balance.size(); i++)
|
||||||
{
|
{
|
||||||
@ -259,6 +261,7 @@ public class BalanceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface VolleyCallBack {
|
public interface VolleyCallBack {
|
||||||
void onSuccess();
|
void onSuccess();
|
||||||
|
@ -28,6 +28,7 @@ public class MarketCapManager {
|
|||||||
private RequestQueue requestQueue;
|
private RequestQueue requestQueue;
|
||||||
private String topRequestResult[];
|
private String topRequestResult[];
|
||||||
private long marketCap;
|
private long marketCap;
|
||||||
|
private long dayVolume;
|
||||||
|
|
||||||
public MarketCapManager(android.content.Context context)
|
public MarketCapManager(android.content.Context context)
|
||||||
{
|
{
|
||||||
@ -88,6 +89,8 @@ public class MarketCapManager {
|
|||||||
JSONObject jsonObject = new JSONObject(response);
|
JSONObject jsonObject = new JSONObject(response);
|
||||||
|
|
||||||
marketCap = new BigDecimal(jsonObject.getString("total_market_cap_usd")).longValue();
|
marketCap = new BigDecimal(jsonObject.getString("total_market_cap_usd")).longValue();
|
||||||
|
|
||||||
|
dayVolume = new BigDecimal(jsonObject.getString("total_24h_volume_usd")).longValue();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -111,6 +114,11 @@ public class MarketCapManager {
|
|||||||
return dominance;
|
return dominance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getDayVolume()
|
||||||
|
{
|
||||||
|
return dayVolume;
|
||||||
|
}
|
||||||
|
|
||||||
private void processTopCurrencies(String response)
|
private void processTopCurrencies(String response)
|
||||||
{
|
{
|
||||||
response = response.substring(response.indexOf('[')+1, response.lastIndexOf(']'));
|
response = response.substring(response.indexOf('[')+1, response.lastIndexOf(']'));
|
||||||
@ -124,7 +132,7 @@ public class MarketCapManager {
|
|||||||
|
|
||||||
JSONObject jsonObject = new JSONObject(topRequestResult[i]);
|
JSONObject jsonObject = new JSONObject(topRequestResult[i]);
|
||||||
|
|
||||||
Log.d("coinfolio", "Symbol : " + jsonObject.getString("symbol") + " " + jsonObject.getString("rank"));
|
//Log.d("coinfolio", "Symbol : " + jsonObject.getString("symbol") + " " + jsonObject.getString("rank"));
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -132,6 +140,11 @@ public class MarketCapManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getMarketCap()
|
||||||
|
{
|
||||||
|
return marketCap;
|
||||||
|
}
|
||||||
|
|
||||||
public interface VolleyCallBack
|
public interface VolleyCallBack
|
||||||
{
|
{
|
||||||
void onSuccess();
|
void onSuccess();
|
||||||
|
@ -66,7 +66,8 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/layoutMarketCap"
|
android:id="@+id/layoutMarketCap"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<!--<TextView
|
<!--<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -75,13 +76,6 @@
|
|||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:gravity="center_horizontal"/>-->
|
android:gravity="center_horizontal"/>-->
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/layoutProgressMarketCap"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:visibility="visible"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBarMarketCap"
|
android:id="@+id/progressBarMarketCap"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -89,11 +83,40 @@
|
|||||||
style="?android:attr/progressBarStyleLarge"
|
style="?android:attr/progressBarStyleLarge"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:background="@drawable/circular_progress_bar" />
|
android:background="@drawable/circular_progress_bar" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/layoutProgressMarketCap"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/marketCapTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:textSize="20dp"
|
||||||
|
android:gravity="center_horizontal"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dayVolumeTotalMarketCap"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:textSize="18dp"
|
||||||
|
android:gravity="center_horizontal"/>
|
||||||
|
|
||||||
<com.github.mikephil.charting.charts.PieChart
|
<com.github.mikephil.charting.charts.PieChart
|
||||||
android:id="@+id/marketCapPieChart"
|
android:id="@+id/marketCapPieChart"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="350dp"/>
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -149,4 +149,8 @@
|
|||||||
<string name="fingerprint_dialog_cancel">Cancel</string>
|
<string name="fingerprint_dialog_cancel">Cancel</string>
|
||||||
<string name="fingerprint_dialog_title">Verify your fingerprint to continue</string>
|
<string name="fingerprint_dialog_title">Verify your fingerprint to continue</string>
|
||||||
|
|
||||||
|
|
||||||
|
<string name="market_cap_textview">Total Market Capitalization :\nUS$%1$s</string>
|
||||||
|
<string name="volume_market_cap_textview">24h volume :\nUS$%1$s</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user