Improve code / xml formatting, closes #54

This commit is contained in:
Emux
2016-07-09 19:45:22 +03:00
parent 7919d0ab9c
commit e793e8851b
458 changed files with 58405 additions and 63062 deletions

View File

@@ -1,7 +1,11 @@
package org.oscim.android.test;
import static org.oscim.utils.ColorUtil.modHsv;
import static org.oscim.utils.ColorUtil.shiftHue;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.ToggleButton;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@@ -20,169 +24,165 @@ import org.oscim.theme.styles.RenderStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.ToggleButton;
import static org.oscim.utils.ColorUtil.modHsv;
import static org.oscim.utils.ColorUtil.shiftHue;
public class ThemeStylerActivity extends BaseMapActivity implements OnSeekBarChangeListener {
final Logger log = LoggerFactory.getLogger(ThemeStylerActivity.class);
final Logger log = LoggerFactory.getLogger(ThemeStylerActivity.class);
public ThemeStylerActivity() {
super(R.layout.activity_map_styler);
}
public ThemeStylerActivity() {
super(R.layout.activity_map_styler);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((SeekBar) findViewById(R.id.seekBarH)).setOnSeekBarChangeListener(this);
((SeekBar) findViewById(R.id.seekBarS)).setOnSeekBarChangeListener(this);
((SeekBar) findViewById(R.id.seekBarV)).setOnSeekBarChangeListener(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((SeekBar) findViewById(R.id.seekBarH)).setOnSeekBarChangeListener(this);
((SeekBar) findViewById(R.id.seekBarS)).setOnSeekBarChangeListener(this);
((SeekBar) findViewById(R.id.seekBarV)).setOnSeekBarChangeListener(this);
Layers layers = mMap.layers();
layers.add(new BuildingLayer(mMap, mBaseLayer));
layers.add(new LabelLayer(mMap, mBaseLayer));
Layers layers = mMap.layers();
layers.add(new BuildingLayer(mMap, mBaseLayer));
layers.add(new LabelLayer(mMap, mBaseLayer));
mMap.setTheme(VtmThemes.DEFAULT);
}
mMap.setTheme(VtmThemes.DEFAULT);
}
class ModStyleVisitor extends RuleVisitor {
private final LineBuilder<?> lineBuilder = LineStyle.builder();
private final AreaBuilder<?> areaBuilder = AreaStyle.builder();
class ModStyleVisitor extends RuleVisitor {
private final LineBuilder<?> lineBuilder = LineStyle.builder();
private final AreaBuilder<?> areaBuilder = AreaStyle.builder();
@Override
public void apply(Rule r) {
for (RenderStyle style : r.styles) {
@Override
public void apply(Rule r) {
for (RenderStyle style : r.styles) {
if (style instanceof LineStyle) {
LineStyle s = (LineStyle) style;
HSV c = lineColor;
if (lineColor.changed && s.outline)
continue;
if (style instanceof LineStyle) {
LineStyle s = (LineStyle) style;
HSV c = lineColor;
if (lineColor.changed && s.outline)
continue;
if (outlineColor.changed) {
if (!s.outline)
continue;
c = outlineColor;
}
if (outlineColor.changed) {
if (!s.outline)
continue;
c = outlineColor;
}
s.set(lineBuilder.set(s)
.color(modColor(s.color, c))
.stippleColor(modColor(s.stippleColor, c))
.build());
continue;
}
s.set(lineBuilder.set(s)
.color(modColor(s.color, c))
.stippleColor(modColor(s.stippleColor, c))
.build());
continue;
}
if (areaColor.changed && style instanceof AreaStyle) {
AreaStyle s = (AreaStyle) style;
if (areaColor.changed && style instanceof AreaStyle) {
AreaStyle s = (AreaStyle) style;
s.set(areaBuilder.set(s)
.color(modColor(s.color, areaColor))
.blendColor(modColor(s.blendColor, areaColor))
.strokeColor(modColor(s.strokeColor, areaColor))
.build());
}
}
super.apply(r);
}
}
s.set(areaBuilder.set(s)
.color(modColor(s.color, areaColor))
.blendColor(modColor(s.blendColor, areaColor))
.strokeColor(modColor(s.strokeColor, areaColor))
.build());
}
}
super.apply(r);
}
}
int modColor(int color, HSV hsv) {
return modHsv(shiftHue(color, hsv.hue), 1, hsv.sat, hsv.val, true);
}
int modColor(int color, HSV hsv) {
return modHsv(shiftHue(color, hsv.hue), 1, hsv.sat, hsv.val, true);
}
public static class HSV {
public double hue = 0;
public double sat = 1;
public double val = 1;
public boolean changed;
}
public static class HSV {
public double hue = 0;
public double sat = 1;
public double val = 1;
public boolean changed;
}
HSV lineColor = new HSV();
HSV outlineColor = new HSV();
HSV areaColor = new HSV();
HSV lineColor = new HSV();
HSV outlineColor = new HSV();
HSV areaColor = new HSV();
ModStyleVisitor mStyleVisitor = new ModStyleVisitor();
ModStyleVisitor mStyleVisitor = new ModStyleVisitor();
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!fromUser)
return;
int id = seekBar.getId();
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!fromUser)
return;
int id = seekBar.getId();
boolean modLine = ((RadioButton) findViewById(R.id.checkBoxLine)).isChecked();
boolean modArea = ((RadioButton) findViewById(R.id.checkBoxArea)).isChecked();
boolean modLine = ((RadioButton) findViewById(R.id.checkBoxLine)).isChecked();
boolean modArea = ((RadioButton) findViewById(R.id.checkBoxArea)).isChecked();
HSV c;
if (modArea)
c = areaColor;
else if (modLine)
c = lineColor;
else
c = outlineColor;
HSV c;
if (modArea)
c = areaColor;
else if (modLine)
c = lineColor;
else
c = outlineColor;
if (id == R.id.seekBarS)
c.sat = progress / 50f;
else if (id == R.id.seekBarV)
c.val = progress / 50f;
else if (id == R.id.seekBarH)
c.hue = progress / 100f;
if (id == R.id.seekBarS)
c.sat = progress / 50f;
else if (id == R.id.seekBarV)
c.val = progress / 50f;
else if (id == R.id.seekBarH)
c.hue = progress / 100f;
log.debug((modArea ? "area" : "line")
+ " h:" + c.hue
+ " s:" + c.sat
+ " v:" + c.val);
log.debug((modArea ? "area" : "line")
+ " h:" + c.hue
+ " s:" + c.sat
+ " v:" + c.val);
VectorTileLayer l = (VectorTileLayer) mMap.layers().get(1);
RenderTheme t = (RenderTheme) l.getTheme();
VectorTileLayer l = (VectorTileLayer) mMap.layers().get(1);
RenderTheme t = (RenderTheme) l.getTheme();
c.changed = true;
t.traverseRules(mStyleVisitor);
t.updateStyles();
c.changed = false;
c.changed = true;
t.traverseRules(mStyleVisitor);
t.updateStyles();
c.changed = false;
if (modArea)
MapRenderer.setBackgroundColor(modColor(t.getMapBackground(), c));
if (modArea)
MapRenderer.setBackgroundColor(modColor(t.getMapBackground(), c));
mMap.render();
}
mMap.render();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onToggleControls(View view) {
findViewById(R.id.controls).setVisibility(((ToggleButton) view).isChecked() ?
View.VISIBLE : View.GONE);
}
public void onToggleControls(View view) {
findViewById(R.id.controls).setVisibility(((ToggleButton) view).isChecked() ?
View.VISIBLE : View.GONE);
}
public void onRadioButtonClicked(View view) {
boolean checked = ((RadioButton) view).isChecked();
if (!checked)
return;
public void onRadioButtonClicked(View view) {
boolean checked = ((RadioButton) view).isChecked();
if (!checked)
return;
HSV c = null;
switch (view.getId()) {
case R.id.checkBoxArea:
c = areaColor;
break;
case R.id.checkBoxLine:
c = lineColor;
break;
case R.id.checkBoxOutline:
c = outlineColor;
break;
}
if (c == null)
return;
((SeekBar) findViewById(R.id.seekBarS)).setProgress((int) (c.sat * 50));
((SeekBar) findViewById(R.id.seekBarV)).setProgress((int) (c.val * 50));
((SeekBar) findViewById(R.id.seekBarH)).setProgress((int) (c.hue * 100));
}
HSV c = null;
switch (view.getId()) {
case R.id.checkBoxArea:
c = areaColor;
break;
case R.id.checkBoxLine:
c = lineColor;
break;
case R.id.checkBoxOutline:
c = outlineColor;
break;
}
if (c == null)
return;
((SeekBar) findViewById(R.id.seekBarS)).setProgress((int) (c.sat * 50));
((SeekBar) findViewById(R.id.seekBarV)).setProgress((int) (c.val * 50));
((SeekBar) findViewById(R.id.seekBarH)).setProgress((int) (c.hue * 100));
}
}