diff options
Diffstat (limited to 'app')
35 files changed, 151 insertions, 35 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java b/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java index 01b10575..89aeb4be 100644 --- a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java +++ b/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java @@ -16,6 +16,9 @@ */ package se.leap.bitmaskclient; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.v7.widget.SwitchCompat; import android.view.LayoutInflater; @@ -23,6 +26,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CompoundButton; +import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; @@ -52,21 +56,27 @@ public class DrawerSettingsAdapter extends BaseAdapter { private boolean isChecked = false; private int itemType = NONE; private CompoundButton.OnCheckedChangeListener callback; + private Drawable iconResource; - private DrawerSettingsItem(String description, int viewType, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) { + private DrawerSettingsItem(Context context, String description, @DrawableRes int iconResource, int viewType, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) { this.description = description; this.viewType = viewType; this.isChecked = isChecked; this.itemType = itemType; this.callback = callback; + try { + this.iconResource = context.getResources().getDrawable(iconResource); + } catch (RuntimeException e) { + e.printStackTrace(); + } } - public static DrawerSettingsItem getSimpleTextInstance(String description, int itemType) { - return new DrawerSettingsItem(description, VIEW_SIMPLE_TEXT, false, itemType, null); + public static DrawerSettingsItem getSimpleTextInstance(Context context, String description, @DrawableRes int iconResource, int itemType) { + return new DrawerSettingsItem(context, description, iconResource, VIEW_SIMPLE_TEXT, false, itemType, null); } - public static DrawerSettingsItem getSwitchInstance(String description, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) { - return new DrawerSettingsItem(description, VIEW_SWITCH, isChecked, itemType, callback); + public static DrawerSettingsItem getSwitchInstance(Context context, String description, @DrawableRes int iconResource, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) { + return new DrawerSettingsItem(context, description, iconResource, VIEW_SWITCH, isChecked, itemType, callback); } public int getItemType() { @@ -138,7 +148,7 @@ public class DrawerSettingsAdapter extends BaseAdapter { switch(type) { case VIEW_SIMPLE_TEXT: convertView = initTextViewBinding(holder); - holder.textView.setText(drawerSettingsItem.description); + bindSimpleText(drawerSettingsItem, holder); break; case VIEW_SWITCH: convertView = initSwitchBinding(holder); @@ -154,7 +164,7 @@ public class DrawerSettingsAdapter extends BaseAdapter { holder.resetSwitchView(); convertView = initTextViewBinding(holder); } - holder.textView.setText(drawerSettingsItem.description); + bindSimpleText(drawerSettingsItem, holder); break; case VIEW_SWITCH: if (!holder.isSwitchViewHolder()) { @@ -169,23 +179,36 @@ public class DrawerSettingsAdapter extends BaseAdapter { return convertView; } + private void bindSimpleText(DrawerSettingsItem drawerSettingsItem, ViewHolder holder) { + holder.textView.setText(drawerSettingsItem.description); + if (drawerSettingsItem.iconResource != null) { + holder.iconView.setImageDrawable(drawerSettingsItem.iconResource); + } + } + private void bindSwitch(DrawerSettingsItem drawerSettingsItem, ViewHolder holder) { holder.switchView.setChecked(drawerSettingsItem.isChecked); - holder.switchView.setText(drawerSettingsItem.description); + holder.textView.setText(drawerSettingsItem.description); holder.switchView.setOnCheckedChangeListener(drawerSettingsItem.callback); + if (drawerSettingsItem.iconResource != null) { + holder.iconView.setImageDrawable(drawerSettingsItem.iconResource); + } } @NonNull private View initSwitchBinding(ViewHolder holder) { View convertView = mInflater.inflate(R.layout.v_switch_list_item, null); - holder.switchView = convertView.findViewById(android.R.id.text1); + holder.switchView = convertView.findViewById(R.id.option_switch); + holder.textView = convertView.findViewById(android.R.id.text1); + holder.iconView = convertView.findViewById(R.id.material_icon); return convertView; } @NonNull private View initTextViewBinding(ViewHolder holder) { - View convertView = mInflater.inflate(R.layout.v_single_list_item, null); + View convertView = mInflater.inflate(R.layout.v_icon_text_list_item, null); holder.textView = convertView.findViewById(android.R.id.text1); + holder.iconView = convertView.findViewById(R.id.material_icon); return convertView; } @@ -200,6 +223,7 @@ public class DrawerSettingsAdapter extends BaseAdapter { static class ViewHolder { TextView textView; + ImageView iconView; SwitchCompat switchView; boolean isSwitchViewHolder() { diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index 21d061d1..635238f2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -244,12 +244,7 @@ public class NavigationDrawerFragment extends Fragment { private void setupAccountsListView() { drawerAccountsListView = drawerView.findViewById(R.id.accountList); drawerAccountsListView.setAdapter(accountListAdapter); - drawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - selectItem(parent, position); - } - }); + drawerAccountsListView.setOnItemClickListener((parent, view, position, id) -> selectItem(parent, position)); } private void setupSettingsListView() { @@ -261,22 +256,24 @@ public class NavigationDrawerFragment extends Fragment { private void setupSettingsListAdapter() { settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater()); if (getContext() != null) { - settingsListAdapter.addItem(getSwitchInstance(getString(R.string.save_battery), + settingsListAdapter.addItem(getSwitchInstance(getContext(), + getString(R.string.save_battery), + R.drawable.ic_battery_36, getSaveBattery(getContext()), BATTERY_SAVER, (buttonView, newStateIsChecked) -> onSwitchItemSelected(BATTERY_SAVER, newStateIsChecked))); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - settingsListAdapter.addItem(getSimpleTextInstance(getString(R.string.always_on_vpn), ALWAYS_ON)); + settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(R.string.always_on_vpn), R.drawable.ic_always_on_36, ALWAYS_ON)); } if (isDefaultBitmask()) { - settingsListAdapter.addItem(getSimpleTextInstance(getString(switch_provider_menu_option), SWITCH_PROVIDER)); + settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(switch_provider_menu_option), R.drawable.ic_switch_provider_36, SWITCH_PROVIDER)); } - settingsListAdapter.addItem(getSimpleTextInstance(getString(log_fragment_title), LOG)); + settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(log_fragment_title), R.drawable.ic_log_36, LOG)); if (ENABLE_DONATION) { - settingsListAdapter.addItem(getSimpleTextInstance(getString(donate_title), DONATE)); + settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(donate_title), R.drawable.ic_donate_36, DONATE)); } - settingsListAdapter.addItem(getSimpleTextInstance(getString(about_fragment_title), ABOUT)); + settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(about_fragment_title), R.drawable.ic_about_36, ABOUT)); } private ActionBar setupActionBar() { diff --git a/app/src/main/res/drawable-hdpi/ic_about_36.png b/app/src/main/res/drawable-hdpi/ic_about_36.png Binary files differnew file mode 100644 index 00000000..52f4e395 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/ic_about_36.png diff --git a/app/src/main/res/drawable-hdpi/ic_always_on_36.png b/app/src/main/res/drawable-hdpi/ic_always_on_36.png Binary files differnew file mode 100644 index 00000000..8547b61d --- /dev/null +++ b/app/src/main/res/drawable-hdpi/ic_always_on_36.png diff --git a/app/src/main/res/drawable-hdpi/ic_battery_36.png b/app/src/main/res/drawable-hdpi/ic_battery_36.png Binary files differnew file mode 100644 index 00000000..7d4cd60b --- /dev/null +++ b/app/src/main/res/drawable-hdpi/ic_battery_36.png diff --git a/app/src/main/res/drawable-hdpi/ic_donate_36.png b/app/src/main/res/drawable-hdpi/ic_donate_36.png Binary files differnew file mode 100644 index 00000000..f269af8c --- /dev/null +++ b/app/src/main/res/drawable-hdpi/ic_donate_36.png diff --git a/app/src/main/res/drawable-hdpi/ic_log_36.png b/app/src/main/res/drawable-hdpi/ic_log_36.png Binary files differnew file mode 100644 index 00000000..3ed90a08 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/ic_log_36.png diff --git a/app/src/main/res/drawable-hdpi/ic_switch_provider_36.png b/app/src/main/res/drawable-hdpi/ic_switch_provider_36.png Binary files differnew file mode 100644 index 00000000..0bace0ce --- /dev/null +++ b/app/src/main/res/drawable-hdpi/ic_switch_provider_36.png diff --git a/app/src/main/res/drawable-mdpi/ic_about_36.png b/app/src/main/res/drawable-mdpi/ic_about_36.png Binary files differnew file mode 100644 index 00000000..110e8f2e --- /dev/null +++ b/app/src/main/res/drawable-mdpi/ic_about_36.png diff --git a/app/src/main/res/drawable-mdpi/ic_always_on_36.png b/app/src/main/res/drawable-mdpi/ic_always_on_36.png Binary files differnew file mode 100644 index 00000000..ea15a067 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/ic_always_on_36.png diff --git a/app/src/main/res/drawable-mdpi/ic_battery_36.png b/app/src/main/res/drawable-mdpi/ic_battery_36.png Binary files differnew file mode 100644 index 00000000..0490996a --- /dev/null +++ b/app/src/main/res/drawable-mdpi/ic_battery_36.png diff --git a/app/src/main/res/drawable-mdpi/ic_donate_36.png b/app/src/main/res/drawable-mdpi/ic_donate_36.png Binary files differnew file mode 100644 index 00000000..b47fecaf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/ic_donate_36.png diff --git a/app/src/main/res/drawable-mdpi/ic_log_36.png b/app/src/main/res/drawable-mdpi/ic_log_36.png Binary files differnew file mode 100644 index 00000000..85a5210c --- /dev/null +++ b/app/src/main/res/drawable-mdpi/ic_log_36.png diff --git a/app/src/main/res/drawable-mdpi/ic_switch_provider_36.png b/app/src/main/res/drawable-mdpi/ic_switch_provider_36.png Binary files differnew file mode 100644 index 00000000..a830e782 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/ic_switch_provider_36.png diff --git a/app/src/main/res/drawable-xhdpi/ic_about_36.png b/app/src/main/res/drawable-xhdpi/ic_about_36.png Binary files differnew file mode 100644 index 00000000..7a15dacc --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/ic_about_36.png diff --git a/app/src/main/res/drawable-xhdpi/ic_always_on_36.png b/app/src/main/res/drawable-xhdpi/ic_always_on_36.png Binary files differnew file mode 100644 index 00000000..811d64d7 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/ic_always_on_36.png diff --git a/app/src/main/res/drawable-xhdpi/ic_battery_36.png b/app/src/main/res/drawable-xhdpi/ic_battery_36.png Binary files differnew file mode 100644 index 00000000..4bed162d --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/ic_battery_36.png diff --git a/app/src/main/res/drawable-xhdpi/ic_donate_36.png b/app/src/main/res/drawable-xhdpi/ic_donate_36.png Binary files differnew file mode 100644 index 00000000..fe680f0e --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/ic_donate_36.png diff --git a/app/src/main/res/drawable-xhdpi/ic_log_36.png b/app/src/main/res/drawable-xhdpi/ic_log_36.png Binary files differnew file mode 100644 index 00000000..571e09ae --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/ic_log_36.png diff --git a/app/src/main/res/drawable-xhdpi/ic_switch_provider_36.png b/app/src/main/res/drawable-xhdpi/ic_switch_provider_36.png Binary files differnew file mode 100644 index 00000000..be31da48 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/ic_switch_provider_36.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_about_36.png b/app/src/main/res/drawable-xxhdpi/ic_about_36.png Binary files differnew file mode 100644 index 00000000..b2c8cfcc --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/ic_about_36.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_always_on_36.png b/app/src/main/res/drawable-xxhdpi/ic_always_on_36.png Binary files differnew file mode 100644 index 00000000..bfb87c49 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/ic_always_on_36.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_battery_36.png b/app/src/main/res/drawable-xxhdpi/ic_battery_36.png Binary files differnew file mode 100644 index 00000000..7a311741 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/ic_battery_36.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_donate_36.png b/app/src/main/res/drawable-xxhdpi/ic_donate_36.png Binary files differnew file mode 100644 index 00000000..08bff222 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/ic_donate_36.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_log_36.png b/app/src/main/res/drawable-xxhdpi/ic_log_36.png Binary files differnew file mode 100644 index 00000000..b0396a89 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/ic_log_36.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_switch_provider_36.png b/app/src/main/res/drawable-xxhdpi/ic_switch_provider_36.png Binary files differnew file mode 100644 index 00000000..229e3147 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/ic_switch_provider_36.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_about_36.png b/app/src/main/res/drawable-xxxhdpi/ic_about_36.png Binary files differnew file mode 100644 index 00000000..bbbd987f --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/ic_about_36.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_always_on_36.png b/app/src/main/res/drawable-xxxhdpi/ic_always_on_36.png Binary files differnew file mode 100644 index 00000000..f8e2a790 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/ic_always_on_36.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_battery_36.png b/app/src/main/res/drawable-xxxhdpi/ic_battery_36.png Binary files differnew file mode 100644 index 00000000..70087a20 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/ic_battery_36.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_donate_36.png b/app/src/main/res/drawable-xxxhdpi/ic_donate_36.png Binary files differnew file mode 100644 index 00000000..cf04212d --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/ic_donate_36.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_log_36.png b/app/src/main/res/drawable-xxxhdpi/ic_log_36.png Binary files differnew file mode 100644 index 00000000..30f5e866 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/ic_log_36.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_switch_provider_36.png b/app/src/main/res/drawable-xxxhdpi/ic_switch_provider_36.png Binary files differnew file mode 100644 index 00000000..56a9bd29 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/ic_switch_provider_36.png diff --git a/app/src/main/res/layout-xlarge/v_icon_text_list_item.xml b/app/src/main/res/layout-xlarge/v_icon_text_list_item.xml new file mode 100644 index 00000000..100016a6 --- /dev/null +++ b/app/src/main/res/layout-xlarge/v_icon_text_list_item.xml @@ -0,0 +1,31 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/item_container" + android:layout_height="wrap_content" + android:layout_width="match_parent" + android:orientation="horizontal" + xmlns:tools="http://schemas.android.com/tools"> + + <ImageView + android:id="@+id/material_icon" + android:layout_width="?android:attr/listPreferredItemHeightSmall" + android:layout_height="?android:attr/listPreferredItemHeightSmall" + android:layout_gravity="center" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" + tools:src="@drawable/ic_add_circle_outline_grey600_24dp" + /> + <TextView + android:id="@android:id/text1" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceLarge" + android:gravity="center_vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" + android:paddingRight="?android:attr/listPreferredItemPaddingRight" + android:minHeight="?android:attr/listPreferredItemHeightSmall" + tools:text="TEST" + /> + +</LinearLayout> diff --git a/app/src/main/res/layout/v_icon_text_list_item.xml b/app/src/main/res/layout/v_icon_text_list_item.xml new file mode 100644 index 00000000..0631b2fc --- /dev/null +++ b/app/src/main/res/layout/v_icon_text_list_item.xml @@ -0,0 +1,31 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/item_container" + android:layout_height="wrap_content" + android:layout_width="match_parent" + android:orientation="horizontal" + xmlns:tools="http://schemas.android.com/tools"> + + <ImageView + android:id="@+id/material_icon" + android:layout_width="?android:attr/listPreferredItemHeightSmall" + android:layout_height="?android:attr/listPreferredItemHeightSmall" + android:layout_gravity="center" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" + tools:src="@drawable/ic_add_circle_outline_grey600_24dp" + /> + <TextView + android:id="@android:id/text1" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceListItemSmall" + android:gravity="center_vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" + android:paddingRight="?android:attr/listPreferredItemPaddingRight" + android:minHeight="?android:attr/listPreferredItemHeightSmall" + tools:text="TEST" + /> + +</LinearLayout> diff --git a/app/src/main/res/layout/v_switch_list_item.xml b/app/src/main/res/layout/v_switch_list_item.xml index bdb9a74c..26060a73 100644 --- a/app/src/main/res/layout/v_switch_list_item.xml +++ b/app/src/main/res/layout/v_switch_list_item.xml @@ -1,15 +1,48 @@ -<android.support.v7.widget.SwitchCompat xmlns:android="http://schemas.android.com/apk/res/android" +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - android:id="@android:id/text1" + android:id="@+id/item_container" + android:layout_height="?android:attr/listPreferredItemHeightSmall" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceListItemSmall" - android:gravity="center_vertical" - android:paddingStart="?android:attr/listPreferredItemPaddingStart" - android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" - android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" - android:paddingRight="?android:attr/listPreferredItemPaddingRight" - android:background="?android:attr/activatedBackgroundIndicator" - android:minHeight="?android:attr/listPreferredItemHeightSmall" - android:checked="false" - tools:text="someOption" />
\ No newline at end of file + > + + <ImageView + android:id="@+id/material_icon" + android:layout_width="?android:attr/listPreferredItemHeightSmall" + android:layout_height="?android:attr/listPreferredItemHeightSmall" + android:layout_gravity="center" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" + tools:src="@drawable/ic_add_circle_outline_grey600_24dp" + /> + + <TextView + android:id="@android:id/text1" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:textAppearance="?android:attr/textAppearanceListItemSmall" + android:gravity="center_vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" + android:paddingRight="?android:attr/listPreferredItemPaddingRight" + android:minHeight="?android:attr/listPreferredItemHeightSmall" + tools:text="TEST" + android:layout_toEndOf="@id/material_icon" + android:layout_toRightOf="@+id/material_icon" + /> + + <android.support.v7.widget.SwitchCompat + android:id="@+id/option_switch" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceListItemSmall" + android:gravity="center_vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" + android:paddingRight="?android:attr/listPreferredItemPaddingRight" + android:background="?android:attr/activatedBackgroundIndicator" + android:minHeight="?android:attr/listPreferredItemHeightSmall" + android:checked="false" + tools:text="" /> +</RelativeLayout>
\ No newline at end of file |