Display disabled warning

This commit is contained in:
M66B 2015-10-29 17:33:06 +01:00
parent 2bab68075c
commit fee08efdc8
4 changed files with 24 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.SwitchCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -53,15 +54,20 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
setContentView(R.layout.main);
running = true;
boolean enabled = prefs.getBoolean("enabled", false);
// Action bar
View view = getLayoutInflater().inflate(R.layout.actionbar, null);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(view);
// Disabled warning
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
// On/off switch
SwitchCompat swEnabled = (SwitchCompat) view.findViewById(R.id.swEnabled);
swEnabled.setChecked(prefs.getBoolean("enabled", false));
swEnabled.setChecked(enabled);
swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
@ -168,6 +174,10 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
// Get enabled
boolean enabled = prefs.getBoolean(name, false);
// Display disabled warning
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
// Check switch state
SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
if (swEnabled.isChecked() != enabled)

View File

@ -10,6 +10,17 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ActivityMain">
<TextView
android:id="@+id/tvDisabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:padding="8dp"
android:text="@string/msg_disabled"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textColor="@color/colorAccent"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvApplication"
android:layout_width="match_parent"

View File

@ -16,6 +16,7 @@
<string name="menu_about">À propos</string>
<string name="msg_sure">Etes-vous sûr ?</string>
<string name="msg_disabled">NetGuard is disabled, use the switch above to enable NetGuard</string>
<string name="title_using">Allow when device in use</string>
</resources>

View File

@ -17,6 +17,7 @@
<string name="menu_about">About</string>
<string name="msg_sure">Are you sure?</string>
<string name="msg_disabled">NetGuard is disabled, use the switch above to enable NetGuard</string>
<string name="title_using">Allow when device in use</string>
</resources>