Plugin details stub
This commit is contained in:
parent
d3fef615cf
commit
b32bed6fae
5 changed files with 167 additions and 71 deletions
|
@ -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.FavoritesActivity" android:windowSoftInputMode="adjustPan" />
|
||||
<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" />
|
||||
|
||||
|
||||
|
|
10
OsmAnd/res/layout/plugin.xml
Normal file
10
OsmAnd/res/layout/plugin.xml
Normal 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>
|
51
OsmAnd/src/net/osmand/plus/activities/PluginActivity.java
Normal file
51
OsmAnd/src/net/osmand/plus/activities/PluginActivity.java
Normal 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());
|
||||
}
|
||||
}
|
|
@ -44,13 +44,9 @@ public class PluginsActivity extends OsmandListActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
//TODO: open details
|
||||
togglePluginEnabled(plugin);
|
||||
}
|
||||
|
||||
private void togglePluginEnabled(OsmandPlugin plugin) {
|
||||
boolean isEnabled = OsmandPlugin.getEnabledPlugins().contains(plugin);
|
||||
enableDisablePlugin(plugin, !isEnabled);
|
||||
Intent intent = new Intent(this, PluginActivity.class);
|
||||
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) {
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package net.osmand.plus.dashboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.PluginActivity;
|
||||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -24,87 +23,126 @@ import android.widget.TextView;
|
|||
* Created by Denis on 21.11.2014.
|
||||
*/
|
||||
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";
|
||||
private ArrayList<OsmandPlugin> showedPlugins;
|
||||
private ArrayList<CompoundButton> checks;
|
||||
if (isEnabled == isChecked) {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_plugins_fragment,
|
||||
container, false);
|
||||
view.findViewById(R.id.show_all).setOnClickListener(new View.OnClickListener() {
|
||||
View contentView = inflater.inflate(R.layout.dash_plugins_fragment, container, false);
|
||||
contentView.findViewById(R.id.show_all).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivityForResult(new Intent(getActivity(),
|
||||
getMyApplication().getAppCustomization().getPluginsActivity()), 1);
|
||||
startActivity(new Intent(getActivity(),
|
||||
getMyApplication().getAppCustomization().getPluginsActivity()));
|
||||
}
|
||||
});
|
||||
LinearLayout layout = (LinearLayout) view.findViewById(R.id.plugins);
|
||||
addPlugins(inflater, layout);
|
||||
return view;
|
||||
|
||||
LinearLayout pluginsContainer = (LinearLayout) contentView.findViewById(R.id.plugins);
|
||||
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
|
||||
public void 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) {
|
||||
LinearLayout layout = (LinearLayout) parent;
|
||||
private void inflatePluginView(LayoutInflater inflater, ViewGroup container,
|
||||
OsmandPlugin plugin) {
|
||||
boolean isEnabled = OsmandPlugin.getEnabledPlugins().contains(plugin);
|
||||
boolean hasSettings = (plugin.getSettingsActivity() != null);
|
||||
|
||||
List<OsmandPlugin> availablePlugins = OsmandPlugin.getAvailablePlugins();
|
||||
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins();
|
||||
List<OsmandPlugin> toShow = new ArrayList<OsmandPlugin>();
|
||||
showedPlugins = new ArrayList<OsmandPlugin>();
|
||||
checks = new ArrayList<CompoundButton>();
|
||||
for(OsmandPlugin o : availablePlugins) {
|
||||
if(!(o instanceof OsmandDevelopmentPlugin)) {
|
||||
if(enabledPlugins.contains(o)) {
|
||||
showedPlugins.add(o);
|
||||
} else{
|
||||
toShow.add(o);
|
||||
}
|
||||
}
|
||||
View view = inflater.inflate(R.layout.dash_plugin_item, container, false);
|
||||
view.setTag(plugin);
|
||||
if (isEnabled && hasSettings) {
|
||||
view.setOnClickListener(pluginSettingsListener);
|
||||
} else {
|
||||
view.setOnClickListener(pluginDetailsListener);
|
||||
}
|
||||
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++) {
|
||||
final OsmandPlugin plugin = showedPlugins.get(i);
|
||||
View view = inflater.inflate(R.layout.dash_plugin_item, layout, false);
|
||||
|
||||
((TextView) view.findViewById(R.id.plugin_name)).setText(plugin.getName());
|
||||
((ImageView) view.findViewById(R.id.plugin_logo)).setImageResource(
|
||||
plugin.getLogoResourceId());
|
||||
TextView nameView = (TextView)view.findViewById(R.id.plugin_name);
|
||||
nameView.setText(plugin.getName());
|
||||
|
||||
CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item);
|
||||
checks.add(check);
|
||||
check.setChecked(enabledPlugins.contains(plugin));
|
||||
// int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources()
|
||||
// .getDisplayMetrics());
|
||||
// LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
|
||||
// view.setLayoutParams(lp);
|
||||
layout.addView(view);
|
||||
}
|
||||
ImageView logoView = (ImageView)view.findViewById(R.id.plugin_logo);
|
||||
logoView.setImageResource(plugin.getLogoResourceId());
|
||||
|
||||
CompoundButton enableDisableButton = (CompoundButton)view.findViewById(R.id.check_item);
|
||||
enableDisableButton.setTag(plugin);
|
||||
enableDisableButton.setChecked(isEnabled);
|
||||
enableDisableButton.setOnCheckedChangeListener(enableDisableListener);
|
||||
|
||||
container.addView(view);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue