small changes within the plugins activity

This commit is contained in:
Pavol Zibrita 2012-07-08 13:43:08 +02:00
parent 5c392ec83f
commit 53a3a415c3
2 changed files with 24 additions and 15 deletions

View file

@ -10,13 +10,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawablePadding="10dp" android:drawablePadding="10dp"
android:textStyle="bold" android:textStyle="bold"
android:textSize="18sp" android:drawableRight="@drawable/list_activities_dot_marker1_pressed" android:drawableLeft="@drawable/list_activities_plugin_menu_symbol" android:text="@string/extra_settings" android:gravity="center_vertical" android:paddingLeft="10dp" android:paddingRight="10dp" android:background="@drawable/ic_background_plugin_listitem"> android:textSize="20sp" android:drawableRight="@drawable/list_activities_dot_marker1_pressed" android:drawableLeft="@drawable/list_activities_plugin_menu_symbol" android:text="@string/extra_settings" android:gravity="center_vertical" android:paddingLeft="10dp" android:paddingRight="10dp" android:background="@drawable/ic_background_plugin_listitem">
</TextView> </TextView>
<TextView <TextView
android:id="@+id/plugin_descr" android:id="@+id/plugin_descr"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"
android:maxLines="7" android:maxLines="7"
android:text="@string/osmand_extra_settings_description" android:text="@string/osmand_extra_settings_description"
android:textColor="@color/color_light_gray" android:textColor="@color/color_light_gray"

View file

@ -7,6 +7,7 @@ import java.util.Set;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -18,8 +19,9 @@ import android.widget.TextView;
public class PluginsActivity extends OsmandListActivity { public class PluginsActivity extends OsmandListActivity {
private List<OsmandPlugin> availablePlugins; private List<OsmandPlugin> availablePlugins;
private Set<String> enabledPlugins = new LinkedHashSet<String>(); private Set<String> clickedPlugins = new LinkedHashSet<String>();
private Set<String> restartPlugins = new LinkedHashSet<String>(); private Set<String> restartPlugins = new LinkedHashSet<String>();
private static int colorGreen = 0xff23CC6C;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -31,7 +33,6 @@ public class PluginsActivity extends OsmandListActivity {
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins(); List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins();
for(OsmandPlugin p : enabledPlugins) { for(OsmandPlugin p : enabledPlugins) {
restartPlugins.add(p.getId()); restartPlugins.add(p.getId());
this.enabledPlugins.add(p.getId());
} }
titleBar.afterSetContentView(); titleBar.afterSetContentView();
@ -41,9 +42,10 @@ public class PluginsActivity extends OsmandListActivity {
@Override @Override
protected void onListItemClick(ListView l, View v, int position, long id) { protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id); super.onListItemClick(l, v, position, id);
OsmandPlugin item = getListAdapter().getItem(position); OsmandPlugin item = getListAdapter().getItem(position);
boolean enable = !restartPlugins.contains(item.getId()); boolean enable = !restartPlugins.contains(item.getId());
if (!enable || clickedPlugins.contains(item.getId())) {
boolean ok = OsmandPlugin.enablePlugin(((OsmandApplication) getApplication()), item, enable); boolean ok = OsmandPlugin.enablePlugin(((OsmandApplication) getApplication()), item, enable);
if (ok) { if (ok) {
if (!enable) { if (!enable) {
@ -52,6 +54,9 @@ public class PluginsActivity extends OsmandListActivity {
restartPlugins.add(item.getId()); restartPlugins.add(item.getId());
} }
} }
} else {
clickedPlugins.add(item.getId());
}
getListAdapter().notifyDataSetChanged(); getListAdapter().notifyDataSetChanged();
} }
@ -73,16 +78,19 @@ public class PluginsActivity extends OsmandListActivity {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
v = inflater.inflate(net.osmand.plus.R.layout.plugins_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.plugins_list_item, parent, false);
} }
final View row = v;
OsmandPlugin plugin = getItem(position); OsmandPlugin plugin = getItem(position);
boolean toBeEnabled = restartPlugins.contains(plugin.getId());
int resourceId = toBeEnabled ? R.drawable.list_activities_dot_marker2_pressed : R.drawable.list_activities_dot_marker1_pressed;
final View row = v;
TextView nameView = (TextView) row.findViewById(R.id.plugin_name); TextView nameView = (TextView) row.findViewById(R.id.plugin_name);
nameView.setText(plugin.getName()); nameView.setText(plugin.getName());
nameView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.list_activities_plugin_menu_symbol), null, getResources().getDrawable(resourceId), null);
TextView description = (TextView) row.findViewById(R.id.plugin_descr); TextView description = (TextView) row.findViewById(R.id.plugin_descr);
description.setText(plugin.getDescription()); description.setText(plugin.getDescription());
boolean toBeEnabled = restartPlugins.contains(plugin.getId()); description.setVisibility(clickedPlugins.contains(plugin.getId()) ? View.VISIBLE : View.GONE);
int right = toBeEnabled ? R.drawable.list_activities_dot_marker2_pressed : R.drawable.list_activities_dot_marker1_pressed; description.setTextColor(toBeEnabled? colorGreen : Color.LTGRAY);
nameView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.list_activities_plugin_menu_symbol), null, getResources().getDrawable(right), null);
return row; return row;
} }