From 7800251ebf9df75ff1ce4f23550f41f822fa5c12 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 18 Feb 2016 09:44:12 +0100 Subject: [PATCH] Indicate connection is metered in the action bar --- .../eu/faircode/netguard/ActivityMain.java | 25 +++++++++++++++--- .../ic_attach_money_white_24dp.png | Bin 0 -> 397 bytes .../ic_attach_money_white_24dp.png | Bin 0 -> 256 bytes .../ic_attach_money_white_24dp.png | Bin 0 -> 448 bytes .../ic_attach_money_white_24dp.png | Bin 0 -> 640 bytes .../ic_attach_money_white_24dp.png | Bin 0 -> 819 bytes app/src/main/res/layout/action.xml | 20 ++++++++++++-- app/src/main/res/values/strings.xml | 1 + 8 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_attach_money_white_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_attach_money_white_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_attach_money_white_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_attach_money_white_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_attach_money_white_24dp.png diff --git a/app/src/main/java/eu/faircode/netguard/ActivityMain.java b/app/src/main/java/eu/faircode/netguard/ActivityMain.java index 5667439f..7188337f 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityMain.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityMain.java @@ -46,6 +46,7 @@ import android.support.v7.widget.SwitchCompat; import android.text.method.LinkMovementMethod; import android.util.Log; import android.util.TypedValue; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -53,6 +54,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.CompoundButton; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -63,6 +65,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences private boolean running = false; private SwitchCompat swEnabled; + private ImageView ivMetered; private SwipeRefreshLayout swipeRefresh; private AdapterRule adapter = null; private MenuItem menuSearch = null; @@ -116,9 +119,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences SinkholeService.stop("UI", this); } + getSupportActionBar().setTitle(null); + // Action bar - View actionView = getLayoutInflater().inflate(R.layout.action, null, false); + final View actionView = getLayoutInflater().inflate(R.layout.action, null, false); swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); + ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); @@ -180,6 +186,17 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences } }); + // Network is metered + ivMetered.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG); + toast.setGravity(Gravity.TOP, actionView.getLeft(), actionView.getBottom()); + toast.show(); + return true; + } + }); + // Disabled warning TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE); @@ -465,7 +482,9 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences Util.logExtras(intent); if (adapter != null) - if (intent.hasExtra("connected") && intent.hasExtra("metered")) + if (intent.hasExtra("connected") && intent.hasExtra("metered")) { + ivMetered.setVisibility(Util.isMeteredNetwork(ActivityMain.this) ? View.VISIBLE : View.GONE); + if (intent.getBooleanExtra("connected", false)) if (intent.getBooleanExtra("metered", false)) adapter.setMobileActive(); @@ -473,7 +492,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences adapter.setWifiActive(); else adapter.setDisconnected(); - else + } else updateApplicationList(null); } }; diff --git a/app/src/main/res/drawable-hdpi/ic_attach_money_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_attach_money_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..ee833c667ac49d6204cbc7ee1a5939809d98d341 GIT binary patch literal 397 zcmV;80doF{P)~!wssdc#O3D@w zxL&AM9;%5DAuL-YFb=3!5X8u0q}ZU3O8LbE8NR%dz@bcj(8e+OZkeWBe$dG(FMM}K zll-BQezr)G^GJjIqlOutG4>P;t-NB?%La`&I5;$^04o?hvcV+Af(j7F7?lk=Fz%^R z9+olsWP?(!F?I;)6H(r9WvP=L2FbZ(igscQut*AHP4 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_attach_money_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_attach_money_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..707d167616765fe8f34d8e637cb2a2a1ba681389 GIT binary patch literal 256 zcmV+b0ssDqP)1)?crW`5VcO3 z7IMJ1scz{azh_gqUL1M+vBGUim#xw1EZ%)WJ}X2kJiav6MJ_(VR4FP~EUIoj=b^Ow z+fRLtb8-TnasC#`HEf&Ad+u}3eUY^nw6!hrKFl$F^(1tsPIQUkF{z7IsX(0?^&Dum`b85=kfHKF6dK{HEPibm;W}aMg z!aH%T&QjH4v-9V!-~DF)|MRx1mGl0e{ruBoqKAr*rie|>zL-OYpPg34V8~9p)RQ}> zDv3+_smzk;Ic=HCqaG%T-#?MwBGx5pbLvIPs&|6H8#EqsUj8^ih_zFDiT8(TdG9Ve z+yCFNRm&phNZIt= z-M+(j)qImcwepB#8rvMtZFX8$Fy)M0!Nj*`LVjc@?`FAcV&wnukwE>))E?_Anm#(u zHGl3&n0x4m+AhyY-jn!}xP(pTESw(`XBeKCY}i|3=#rMdVgk3w#x^rHk8nHs zzmfG+$Z*}HSB)`?nJ;ThE$WtNo?&*{^p>IN$_pCD(l3=hJ(%dTJhY-F@ly5EgPcC< zp%r%yg{+=a(ULiztN-qdUn>H_auhl6Ch;s?DG_#2`cAs=VIDX+pjW zrdZ_}`K?N0ZPmNfd%=Cq@gtS)O(p9;iio5Mq*t*;EKvybQxCrG-rIEC&u(&j6Za7j zKCjFNmY$n_p0ZpeVkWjhK6;Y!nnfOY4-!8=6_PWH*L#T00LSr`|I&|yH{Eth)CHz2 N22WQ%mvv4FO#qM@Am0E0 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_attach_money_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_attach_money_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..f3c568542d1a733c45204f1ed5c6b9bf6a926d2d GIT binary patch literal 819 zcmV-31I+x1P)(jc!6FGXE_?3M6S`p_sHP)J+%&hSjD`6m1NG(g?$nAdMEu zNUZ{6k`f{bQG!CsM0BFtWHQ8=@u~HD&Wx{)&F>7npYL{liw7K>TZ&;AhG7_nv0BK$ zS(uc6vlLc$Ccp%k025#W;#f9SQ3DFy9pIq>A0c8HrHyX>19 zW~g>cz<>0x5)sb1A;62DmAfb%kcFT4G|L8b65Sj_+^75R`tb7&XCX@D0xEGfK`TYd zV^b;TIw9$Ou%JSiyY9n+ry%AXR%fy zz>jKB^YSsOdWnF~s7`2JHlpf~2neJ4U-PmQ)u2Q`1XYFh3%{_kml6R#H2#G2ClD}- z>S=NX+{W%?G6mFOXVH{A0UiQ4dBj%P0R6S&%%YcyWC+M&oan~6K&ecC{z?cE+Xrq@ zOP)Z0<|b*xJi1x?a)38usLP^- zN%RG%kq=OpP7OXRbajv>A7Ebr&G=YAM?dKT0b28LkW0M4BDQXs0R4HXr;i1qYmy7l zUv7-2_;=Pz2Iwz?(*$vHRXRX_MT}t=Bu6?xfBC${?x=i#{&o>T)#>g4bpxpU$raFq zYC6#YgQ$w*`exy0q62QCs@1<{AF5EI15Tm3tAEXLRDnbX>_io!Q2V+M)kxx>#P3o0 zNY%P5!$Q@S_<*z6b!oi5-^e@cY7!sd%WXvRr|0gkcG_UO$t zGK{k`QZMEPi0%_ZJm3z!JjBl|(T$NQ6_Cqo;uU1ONfC(@Ge*n6{IDmJ|3g!R+002ovPDHLkV1fXzd(Z#? literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/action.xml b/app/src/main/res/layout/action.xml index 474fa39c..b3425ff5 100644 --- a/app/src/main/res/layout/action.xml +++ b/app/src/main/res/layout/action.xml @@ -4,12 +4,28 @@ android:background="?attr/colorPrimary" android:orientation="horizontal"> + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a3e83f60..aba1fda6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -162,6 +162,7 @@ Your internet traffic is not being sent to a remote VPN server. Last download: %s Start forwarding from %1$s port %2$d to %3$s:%4$d of \'%5$s\'? Stop forwarding of %1$s port %2$d? + Network is metered Conditions Allow Wi-Fi when screen is on