Skip to content

Commit

Permalink
Fix sliders problem
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocipriani01 committed Apr 9, 2021
1 parent ad003fe commit 009f069
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .idea/modules/app/Telescope.Touch.app.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "io.github.marcocipriani01.telescopetouch"
minSdkVersion 21
targetSdkVersion 30
versionCode 31
versionName "1.8.1"
versionCode 32
versionName "1.8.2"
multiDexEnabled true
if (file('api.properties').exists()) {
Properties properties = new Properties()
Expand Down Expand Up @@ -40,7 +40,7 @@ dependencies {
implementation project(path: ':datamodel')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.activity:activity:1.3.0-alpha05'
implementation 'androidx.activity:activity:1.3.0-alpha06'
implementation 'androidx.fragment:fragment:1.3.2'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.hardware.SensorManager;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.util.Log;

import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
Expand Down Expand Up @@ -64,7 +63,6 @@ public class ApplicationModule {
private final TelescopeTouchApp app;

public ApplicationModule(TelescopeTouchApp app) {
Log.d(TAG, "Creating application module for " + app);
this.app = app;
}

Expand All @@ -82,7 +80,6 @@ Context provideContext() {
@Provides
@Singleton
SharedPreferences provideSharedPreferences() {
Log.d(TAG, "Providing shared preferences");
return PreferenceManager.getDefaultSharedPreferences(app);
}

Expand Down Expand Up @@ -147,7 +144,6 @@ ConnectivityManager provideConnectivityManager() {
@Singleton
LayerManager provideLayerManager(AssetManager assetManager, Resources resources,
AstronomerModel model, SharedPreferences preferences) {
Log.i(TAG, "Initializing LayerManager");
LayerManager layerManager = new LayerManager(preferences);
layerManager.addLayer(new StarsLayer(assetManager, resources));
layerManager.addLayer(new MessierLayer(assetManager, resources));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import io.github.marcocipriani01.telescopetouch.activities.util.SimpleAdapter;
import io.github.marcocipriani01.telescopetouch.indi.ConnectionManager;
import io.github.marcocipriani01.telescopetouch.indi.INDICamera;
import io.github.marcocipriani01.telescopetouch.indi.NumberPropPref;

import static io.github.marcocipriani01.telescopetouch.ApplicationConstants.CCD_LOOP_DELAY_PREF;
import static io.github.marcocipriani01.telescopetouch.TelescopeTouchApp.connectionManager;
Expand Down Expand Up @@ -738,12 +739,7 @@ public void onCameraFunctionsChange() {
if (gainSlider != null) {
boolean hasGain = camera.hasGain();
gainSlider.setEnabled(hasGain);
if (hasGain) {
gainSlider.setValueFrom((float) camera.gainE.getMin());
gainSlider.setValueTo((float) camera.gainE.getMax());
gainSlider.setStepSize((float) camera.gainE.getStep());
gainSlider.setValue((float) (double) camera.gainE.getValue());
}
if (hasGain) NumberPropPref.setSliderValues(gainSlider, camera.gainE);
}
if (isoSpinner != null) {
boolean hasISO = camera.hasISO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.github.marcocipriani01.telescopetouch.activities.util.SimpleAdapter;
import io.github.marcocipriani01.telescopetouch.indi.ConnectionManager;
import io.github.marcocipriani01.telescopetouch.indi.INDIFocuser;
import io.github.marcocipriani01.telescopetouch.indi.NumberPropPref;

import static io.github.marcocipriani01.telescopetouch.TelescopeTouchApp.connectionManager;

Expand Down Expand Up @@ -373,11 +374,7 @@ public void onFocuserFunctionsChange() {
if (speedSlider != null) {
boolean hasSpeed = focuser.hasSpeed();
speedSlider.setEnabled(hasSpeed);
if (hasSpeed) {
speedSlider.setValueFrom((float) focuser.speedE.getMin());
speedSlider.setValueTo((float) focuser.speedE.getMax());
speedSlider.setValue((float) (double) focuser.speedE.getValue());
}
if (hasSpeed) NumberPropPref.setSliderValues(speedSlider, focuser.speedE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.github.marcocipriani01.telescopetouch.R;

/**
* Created by johntaylor on 4/24/16.
* @author johntaylor
*/
public class SensorAccuracyDecoder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ protected Spannable createSummary() {
}
}

public static void setSliderValues(Slider slider, float min, float max, float step, float value) {
float diff = max - min;
if (step > diff) step = diff;
float mod = diff % step;
if (mod > .0001) max -= mod;
mod = (value - min) % step;
if (mod > .0001) value -= mod;
if (value > max)
value = max;
else if (value < min)
value = min;
slider.setValueFrom(min);
slider.setValueTo(max);
slider.setStepSize(step);
slider.setValue(value);
}

public static void setSliderValues(Slider slider, INDINumberElement element) {
setSliderValues(slider, (float) element.getMin(),
(float) element.getMax(), (float) element.getStep(),
(float) (double) element.getValue());
}

@Override
protected void onClick() {
Context context = getContext();
Expand All @@ -92,22 +115,23 @@ protected void onClick() {
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
int padding = resources.getDimensionPixelSize(R.dimen.padding_medium);
layoutParams.setMargins(padding, 0, padding, 0);
boolean notReadOnly = prop.getPermission() != Constants.PropertyPermissions.RO;

for (INDINumberElement element : elements) {
TextInputLayout inputLayout = new TextInputLayout(context);
inputLayout.setPadding(padding, padding, padding, 0);
inputLayout.setHint(element.getLabel());
TextInputEditText editText = new TextInputEditText(context);
editText.setText(element.getValueAsString().trim());
editText.setEnabled(prop.getPermission() != Constants.PropertyPermissions.RO);
editText.setEnabled(notReadOnly);
editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
editTextViews.add(editText);
inputLayout.addView(editText);
layout.addView(inputLayout, layoutParams);

float min = (float) element.getMin(),
max = (float) element.getMax();
if ((max - min) <= 1000f) {
if (notReadOnly && ((max - min) <= 2000f)) {
Slider slider = new Slider(context);
slider.setThumbStrokeColorResource(R.color.colorAccent);
ColorStateList colorStateList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent));
Expand All @@ -118,10 +142,7 @@ protected void onClick() {
slider.setTickVisible(false);
slider.setTrackHeight(resources.getDimensionPixelSize(R.dimen.slider_track_height));
slider.setPadding(padding * 2, 0, padding * 2, padding);
slider.setValueFrom(min);
slider.setValueTo(max);
slider.setStepSize(((float) element.getStep()));
slider.setValue((float) (double) element.getValue());
setSliderValues(slider, min, max, (float) element.getStep(), (float) (double) element.getValue());
slider.addOnChangeListener((slider1, value, fromUser) -> {
if (fromUser)
editText.setText(String.valueOf(value));
Expand Down Expand Up @@ -154,7 +175,7 @@ public void afterTextChanged(Editable s) {
scrollView.addView(layout);
builder.setView(scrollView);

if (prop.getPermission() != Constants.PropertyPermissions.RO) {
if (notReadOnly) {
builder.setPositiveButton(R.string.send_request, (dialog, id) -> {
try {
for (int i = 0; i < elements.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ public class GridLayer extends AbstractLayer {

public static final int DEPTH_ORDER = 30;
public static final String PREFERENCE_ID = "source_provider.4";
private final int numRightAscentionLines;
private final int numDeclinationLines;
private final int raLinesCount;
private final int decLinesCount;

/**
* @param numDeclinationLines The number of declination lines to show including the poles
* on each side of the equator. 9 is a good number for 10 degree
* intervals.
* @param decLinesCount The number of declination lines to show including the poles
* on each side of the equator. 9 is a good number for 10 degree
* intervals.
*/
public GridLayer(Resources resources, int numRightAscentionLines, int numDeclinationLines) {
public GridLayer(Resources resources, int raLinesCount, int decLinesCount) {
super(resources, false);
this.numRightAscentionLines = numRightAscentionLines;
this.numDeclinationLines = numDeclinationLines;
this.raLinesCount = raLinesCount;
this.decLinesCount = decLinesCount;
}

@Override
protected void initializeAstroSources(List<AstronomicalSource> sources) {
sources.add(new GridSource(getResources(), numRightAscentionLines, numDeclinationLines));
sources.add(new GridSource(getResources(), raLinesCount, decLinesCount));
}

@Override
Expand Down

0 comments on commit 009f069

Please sign in to comment.