Indicate connection is metered in the action bar

This commit is contained in:
M66B 2016-02-18 09:44:12 +01:00
parent 5ae59064ab
commit 7800251ebf
8 changed files with 41 additions and 5 deletions

View File

@ -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);
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 819 B

View File

@ -4,12 +4,28 @@
android:background="?attr/colorPrimary"
android:orientation="horizontal">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_security_white_24dp" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/swEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:saveEnabled="false" />
<ImageView
android:id="@+id/ivMetered"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_attach_money_white_24dp"
android:visibility="gone" />
</LinearLayout>

View File

@ -162,6 +162,7 @@ Your internet traffic is not being sent to a remote VPN server.</string>
<string name="msg_download_last">Last download: %s</string>
<string name="msg_start_forward" formatted="false">Start forwarding from %1$s port %2$d to %3$s:%4$d of \'%5$s\'?</string>
<string name="msg_stop_forward">Stop forwarding of %1$s port %2$d?</string>
<string name="msg_metered">Network is metered</string>
<string name="title_conditions">Conditions</string>
<string name="title_screen_wifi">Allow Wi-Fi when screen is on</string>