This commit is contained in:
Alexey Pelykh 2015-02-05 18:26:42 +02:00
parent f3979fef89
commit b4ce36cf92
7 changed files with 76 additions and 33 deletions

View file

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<item
android:top="6dp"
android:right="2dp">
<bitmap
android:src="@drawable/ic_overflow_menu_dark"
android:gravity="center" />
android:gravity="top|end" />
</item>
</layer-list>

View file

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<item
android:top="6dp"
android:right="2dp">
<bitmap
android:src="@drawable/ic_overflow_menu_light"
android:gravity="center" />
android:gravity="top|end" />
</item>
</layer-list>

View file

@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dash_plugin_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -17,7 +18,7 @@
android:layout_height="54dp"
android:orientation="horizontal">
<ImageView
<ImageButton
android:id="@+id/plugin_logo"
android:layout_width="32dp"
android:layout_height="32dp"
@ -43,7 +44,7 @@
<net.osmand.plus.widgets.SwitchEx
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="6dp"
@ -54,7 +55,6 @@
android:layout_marginEnd="16dp"
android:background="?attr/switch_ex_background"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="9.5dp"

View file

@ -62,17 +62,16 @@
</LinearLayout>
</LinearLayout>
<LinearLayout
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:orientation="vertical">
android:layout_height="match_parent"
android:layout_gravity="top|end">
<ImageView
android:id="@+id/plugin_is_enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="6dp"
android:src="?attr/ic_action_check"
android:visibility="invisible"
@ -83,6 +82,7 @@
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="6dp"
android:layout_gravity="center_horizontal|bottom"
android:background="?attr/ic_plugin_options"/>
</LinearLayout>
</FrameLayout>
</FrameLayout>

View file

@ -7,6 +7,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.text.format.DateFormat;
import android.view.View;
import android.view.ViewParent;
import android.view.inputmethod.InputMethodManager;
public class AndroidUtils {
@ -49,4 +50,18 @@ public class AndroidUtils {
public static String formatTime(Context ctx, long time) {
return DateFormat.getTimeFormat(ctx).format(new Date(time));
}
public static View findParentViewById(View view, int id) {
ViewParent viewParent = view.getParent();
while (viewParent != null && viewParent instanceof View) {
View parentView = (View)viewParent;
if (parentView.getId() == id)
return parentView;
viewParent = parentView.getParent();
}
return null;
}
}

View file

@ -86,7 +86,7 @@ public class PluginsActivity extends OsmandListActivity {
if (plugin.isActive()) {
pluginLogo.setBackgroundResource(R.drawable.bg_plugin_logo_enabled);
} else {
TypedArray attributes = getTheme().obtainStyledAttributes(
TypedArray attributes = getTheme().obtainStyledAttributes(
new int[] {R.attr.bg_plugin_logo_disabled});
pluginLogo.setBackgroundDrawable(attributes.getDrawable(0));
attributes.recycle();

View file

@ -2,18 +2,20 @@ package net.osmand.plus.dashboard;
import java.util.List;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -25,11 +27,25 @@ public class DashPluginsFragment extends DashBaseFragment {
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
OsmandPlugin plugin = (OsmandPlugin)buttonView.getTag();
View pluginView = AndroidUtils.findParentViewById(buttonView, R.id.dash_plugin_item);
OsmandPlugin plugin = (OsmandPlugin)pluginView.getTag();
if (plugin.isActive() == isChecked) {
return;
}
OsmandPlugin.enablePlugin(getMyApplication(), plugin, isChecked);
if (OsmandPlugin.enablePlugin(getMyApplication(), plugin, isChecked)) {
updatePluginState(pluginView);
}
}
};
private final View.OnClickListener toggleEnableDisableListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
View pluginView = AndroidUtils.findParentViewById(view, R.id.dash_plugin_item);
OsmandPlugin plugin = (OsmandPlugin)pluginView.getTag();
if (OsmandPlugin.enablePlugin(getMyApplication(), plugin, !plugin.isActive())) {
updatePluginState(pluginView);
}
}
};
@ -94,41 +110,49 @@ public class DashPluginsFragment extends DashBaseFragment {
for (int pluginIndex = 0; pluginIndex < pluginsContainer.getChildCount(); pluginIndex++) {
View pluginView = pluginsContainer.getChildAt(pluginIndex);
OsmandPlugin plugin = (OsmandPlugin)pluginView.getTag();
boolean isEnabled = plugin.isActive();
CompoundButton enableDisableButton = (CompoundButton) pluginView.findViewById(
R.id.check_item);
enableDisableButton.setChecked(isEnabled);
updatePluginState(pluginView);
}
}
private void updatePluginState(View pluginView) {
OsmandPlugin plugin = (OsmandPlugin)pluginView.getTag();
boolean isEnabled = plugin.isActive();
CompoundButton enableDisableButton = (CompoundButton)pluginView.findViewById(
R.id.check_item);
enableDisableButton.setChecked(isEnabled);
ImageButton logoView = (ImageButton)pluginView.findViewById(R.id.plugin_logo);
if (plugin.isActive()) {
logoView.setBackgroundResource(R.drawable.bg_plugin_logo_enabled);
} else {
TypedArray attributes = getActivity().getTheme().obtainStyledAttributes(
new int[] {R.attr.bg_plugin_logo_disabled});
logoView.setBackgroundDrawable(attributes.getDrawable(0));
attributes.recycle();
}
}
private void inflatePluginView(LayoutInflater inflater, ViewGroup container,
OsmandPlugin plugin) {
View view = inflater.inflate(R.layout.dash_plugin_item, container, false);
view.setTag(plugin);
// To discuss: too much confusing and not consistent
// boolean hasSettings = (plugin.getSettingsActivity() != null);
// if (isEnabled && hasSettings) {
// view.setOnClickListener(pluginSettingsListener);
// } else {
// view.setOnClickListener(pluginDetailsListener);
// }
view.setOnClickListener(pluginDetailsListener);
TextView nameView = (TextView)view.findViewById(R.id.plugin_name);
nameView.setText(plugin.getName());
ImageView logoView = (ImageView)view.findViewById(R.id.plugin_logo);
ImageButton logoView = (ImageButton)view.findViewById(R.id.plugin_logo);
logoView.setOnClickListener(toggleEnableDisableListener);
logoView.setImageResource(plugin.getLogoResourceId());
CompoundButton enableDisableButton = (CompoundButton)view.findViewById(R.id.check_item);
enableDisableButton.setTag(plugin);
enableDisableButton.setChecked(plugin.isActive());
enableDisableButton.setOnCheckedChangeListener(enableDisableListener);
updatePluginState(view);
container.addView(view);
}
}