Plugin details stub

This commit is contained in:
Alexey Pelykh 2015-02-03 16:03:29 +02:00
parent d3fef615cf
commit b32bed6fae
5 changed files with 167 additions and 71 deletions

View file

@ -144,6 +144,7 @@
<activity android:name="net.osmand.plus.activities.FavoritesListActivity" android:label="@string/favourites_list_activity" /> <activity android:name="net.osmand.plus.activities.FavoritesListActivity" android:label="@string/favourites_list_activity" />
<activity android:name="net.osmand.plus.activities.FavoritesActivity" android:windowSoftInputMode="adjustPan" /> <activity android:name="net.osmand.plus.activities.FavoritesActivity" android:windowSoftInputMode="adjustPan" />
<activity android:name="net.osmand.plus.activities.PluginsActivity" /> <activity android:name="net.osmand.plus.activities.PluginsActivity" />
<activity android:name="net.osmand.plus.activities.PluginActivity" />
<activity android:name="net.osmand.plus.activities.ContributionVersionActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/contribution_activity" /> <activity android:name="net.osmand.plus.activities.ContributionVersionActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/contribution_activity" />

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.PluginActivity">
</LinearLayout>

View file

@ -0,0 +1,51 @@
package net.osmand.plus.activities;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
/**
* Created by Alexey Pelykh on 02.02.2015.
*/
public class PluginActivity extends OsmandActionBarActivity {
private static final String TAG = "PluginActivity";
public static final String EXTRA_PLUGIN_ID = "plugin_id";
private OsmandPlugin plugin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent == null || !intent.hasExtra(EXTRA_PLUGIN_ID)) {
Log.e(TAG, "Required extra '" + EXTRA_PLUGIN_ID + "' is missing");
finish();
return;
}
String pluginId = intent.getStringExtra(EXTRA_PLUGIN_ID);
if (pluginId == null) {
Log.e(TAG, "Extra '" + EXTRA_PLUGIN_ID + "' is null");
finish();
return;
}
for (OsmandPlugin plugin : OsmandPlugin.getAvailablePlugins()) {
if (!plugin.getId().equals(pluginId))
continue;
this.plugin = plugin;
break;
}
if (plugin == null) {
Log.e(TAG, "Plugin '" + EXTRA_PLUGIN_ID + "' not found");
finish();
return;
}
setContentView(R.layout.plugin);
getSupportActionBar().setTitle(plugin.getName());
}
}

View file

@ -44,13 +44,9 @@ public class PluginsActivity extends OsmandListActivity {
return; return;
} }
//TODO: open details Intent intent = new Intent(this, PluginActivity.class);
togglePluginEnabled(plugin); intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
} startActivity(intent);
private void togglePluginEnabled(OsmandPlugin plugin) {
boolean isEnabled = OsmandPlugin.getEnabledPlugins().contains(plugin);
enableDisablePlugin(plugin, !isEnabled);
} }
private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) { private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) {

View file

@ -1,14 +1,13 @@
package net.osmand.plus.dashboard; package net.osmand.plus.dashboard;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.development.OsmandDevelopmentPlugin;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -24,87 +23,126 @@ import android.widget.TextView;
* Created by Denis on 21.11.2014. * Created by Denis on 21.11.2014.
*/ */
public class DashPluginsFragment extends DashBaseFragment { public class DashPluginsFragment extends DashBaseFragment {
private final CompoundButton.OnCheckedChangeListener enableDisableListener =
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
OsmandPlugin plugin = (OsmandPlugin)buttonView.getTag();
boolean isEnabled = OsmandPlugin.getEnabledPlugins().contains(plugin);
public static final String TAG = "DASH_PLUGINS_FRAGMENT"; if (isEnabled == isChecked) {
private ArrayList<OsmandPlugin> showedPlugins; return;
private ArrayList<CompoundButton> checks; }
OsmandPlugin.enablePlugin(getMyApplication(), plugin, isChecked);
}
};
private final View.OnClickListener pluginSettingsListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
OsmandPlugin plugin = (OsmandPlugin)view.getTag();
Class<? extends Activity> settingsActivity = plugin.getSettingsActivity();
startActivity(new Intent(getActivity(), settingsActivity));
}
};
private final View.OnClickListener pluginDetailsListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
OsmandPlugin plugin = (OsmandPlugin)view.getTag();
Intent intent = new Intent(getActivity(), PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
startActivity(intent);
}
};
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_plugins_fragment, View contentView = inflater.inflate(R.layout.dash_plugins_fragment, container, false);
container, false); contentView.findViewById(R.id.show_all).setOnClickListener(new View.OnClickListener() {
view.findViewById(R.id.show_all).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
startActivityForResult(new Intent(getActivity(), startActivity(new Intent(getActivity(),
getMyApplication().getAppCustomization().getPluginsActivity()), 1); getMyApplication().getAppCustomization().getPluginsActivity()));
} }
}); });
LinearLayout layout = (LinearLayout) view.findViewById(R.id.plugins);
addPlugins(inflater, layout); LinearLayout pluginsContainer = (LinearLayout) contentView.findViewById(R.id.plugins);
return view; List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins();
for(OsmandPlugin plugin : enabledPlugins) {
if (plugin instanceof OsmandDevelopmentPlugin) {
continue;
}
inflatePluginView(inflater, pluginsContainer, plugin);
}
for(OsmandPlugin plugin : OsmandPlugin.getAvailablePlugins()) {
if (pluginsContainer.getChildCount() > 2) {
break;
}
if (plugin instanceof OsmandDevelopmentPlugin) {
continue;
}
if (enabledPlugins.contains(plugin)) {
continue;
}
inflatePluginView(inflater, pluginsContainer, plugin);
}
return contentView;
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
for (int i = 0; i < checks.size(); i++) {
final CompoundButton ch = checks.get(i);
final OsmandPlugin o = showedPlugins.get(i);
ch.setOnCheckedChangeListener(null);
ch.setChecked(OsmandPlugin.getEnabledPlugins().contains(o));
ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
OsmandPlugin.enablePlugin(getMyApplication(), o, b);
}
});
}
View contentView = getView();
if (contentView == null) {
return;
}
LinearLayout pluginsContainer = (LinearLayout) contentView.findViewById(R.id.plugins);
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins();
for (int pluginIndex = 0; pluginIndex < pluginsContainer.getChildCount(); pluginIndex++) {
View pluginView = pluginsContainer.getChildAt(pluginIndex);
OsmandPlugin plugin = (OsmandPlugin)pluginView.getTag();
boolean isEnabled = enabledPlugins.contains(plugin);
CompoundButton enableDisableButton = (CompoundButton) pluginView.findViewById(
R.id.check_item);
enableDisableButton.setChecked(isEnabled);
}
} }
private void addPlugins(LayoutInflater inflater, View parent) { private void inflatePluginView(LayoutInflater inflater, ViewGroup container,
LinearLayout layout = (LinearLayout) parent; OsmandPlugin plugin) {
boolean isEnabled = OsmandPlugin.getEnabledPlugins().contains(plugin);
boolean hasSettings = (plugin.getSettingsActivity() != null);
List<OsmandPlugin> availablePlugins = OsmandPlugin.getAvailablePlugins(); View view = inflater.inflate(R.layout.dash_plugin_item, container, false);
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins(); view.setTag(plugin);
List<OsmandPlugin> toShow = new ArrayList<OsmandPlugin>(); if (isEnabled && hasSettings) {
showedPlugins = new ArrayList<OsmandPlugin>(); view.setOnClickListener(pluginSettingsListener);
checks = new ArrayList<CompoundButton>(); } else {
for(OsmandPlugin o : availablePlugins) { view.setOnClickListener(pluginDetailsListener);
if(!(o instanceof OsmandDevelopmentPlugin)) {
if(enabledPlugins.contains(o)) {
showedPlugins.add(o);
} else{
toShow.add(o);
}
}
}
Collections.shuffle(toShow, new Random(System.currentTimeMillis()));
while (!toShow.isEmpty()) {
showedPlugins.add(toShow.remove(0));
if (showedPlugins.size() > 2) {
break;
}
} }
for (int i = 0; i < showedPlugins.size(); i++) { TextView nameView = (TextView)view.findViewById(R.id.plugin_name);
final OsmandPlugin plugin = showedPlugins.get(i); nameView.setText(plugin.getName());
View view = inflater.inflate(R.layout.dash_plugin_item, layout, false);
((TextView) view.findViewById(R.id.plugin_name)).setText(plugin.getName()); ImageView logoView = (ImageView)view.findViewById(R.id.plugin_logo);
((ImageView) view.findViewById(R.id.plugin_logo)).setImageResource( logoView.setImageResource(plugin.getLogoResourceId());
plugin.getLogoResourceId());
CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item); CompoundButton enableDisableButton = (CompoundButton)view.findViewById(R.id.check_item);
checks.add(check); enableDisableButton.setTag(plugin);
check.setChecked(enabledPlugins.contains(plugin)); enableDisableButton.setChecked(isEnabled);
// int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources() enableDisableButton.setOnCheckedChangeListener(enableDisableListener);
// .getDisplayMetrics());
// LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height); container.addView(view);
// view.setLayoutParams(lp);
layout.addView(view);
}
} }
} }