Android Open Source - AndroidWeatherBuoyDemo Compass View Activity






From Project

Back to project page AndroidWeatherBuoyDemo.

License

The source code is released under:

Apache License

If you think the Android project AndroidWeatherBuoyDemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kevinrschultz.weatherbuoy.sandbox;
//w w  w .  j  a  v  a2 s  .c  o  m
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

import com.kevinrschultz.weatherbuoy.customviews.compass.CompassView;

import butterknife.ButterKnife;
import butterknife.InjectView;


public class CompassViewActivity extends Activity {

    @InjectView(R.id.compass_compass)
    CompassView compass;

    @InjectView(R.id.compass_wave_seekbar)
    SeekBar waveSeekBar;

    @InjectView(R.id.compass_wind_seekbar)
    SeekBar windSeekBar;

    @InjectView(R.id.compass_wave_label)
    TextView waveLabel;

    @InjectView(R.id.compass_wind_label)
    TextView windLabel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_compass_view);
        ButterKnife.inject(this);

        waveSeekBar.setOnSeekBarChangeListener(makeWaveSeekBarListener());
        windSeekBar.setOnSeekBarChangeListener(makeWindSeekBarListener());

    }

    private SeekBar.OnSeekBarChangeListener makeWaveSeekBarListener() {
        return new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                double direction = getDirectionFromProgress(progress);
                waveLabel.setText(String.format("%.1f", direction));
                compass.setWaveDirection(direction);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {}

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {}
        };
    }

    private SeekBar.OnSeekBarChangeListener makeWindSeekBarListener() {
        return new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                double direction = getDirectionFromProgress(progress);
                windLabel.setText(String.format("%.1f", direction));
                compass.setWindDirection(direction);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {}

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {}
        };
    }

    private double getDirectionFromProgress(int progress) {
        return (360.0 * (double) progress) / 100.0;
    }

}




Java Source Code List

com.kevinrschultz.weatherbuoy.Constants.java
com.kevinrschultz.weatherbuoy.customviews.compass.CompassViewTest.java
com.kevinrschultz.weatherbuoy.customviews.compass.CompassView.java
com.kevinrschultz.weatherbuoy.customviews.compass.Compass.java
com.kevinrschultz.weatherbuoy.data.FakeBuoyListingGenerator.java
com.kevinrschultz.weatherbuoy.json.GsonSingleton.java
com.kevinrschultz.weatherbuoy.model.Advisory.java
com.kevinrschultz.weatherbuoy.model.BuoyDescription.java
com.kevinrschultz.weatherbuoy.model.Region.java
com.kevinrschultz.weatherbuoy.model.UnitSystem.java
com.kevinrschultz.weatherbuoy.model.WaveCondition.java
com.kevinrschultz.weatherbuoy.model.WindCondition.java
com.kevinrschultz.weatherbuoy.preferences.WeatherBuoyPreferences.java
com.kevinrschultz.weatherbuoy.sandbox.ActivityLaunchingListItem.java
com.kevinrschultz.weatherbuoy.sandbox.CompassViewActivity.java
com.kevinrschultz.weatherbuoy.sandbox.MainActivity.java
com.kevinrschultz.weatherbuoy.ui.BaseActivity.java
com.kevinrschultz.weatherbuoy.ui.BaseArrayAdapter.java
com.kevinrschultz.weatherbuoy.ui.BuoyDescriptionAdapter.java
com.kevinrschultz.weatherbuoy.ui.BuoyDetailActivity.java
com.kevinrschultz.weatherbuoy.ui.BuoyDetailFragment.java
com.kevinrschultz.weatherbuoy.ui.BuoyDetailViewModel.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingActivity.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingFragment.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingPresenter.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingView.java
com.kevinrschultz.weatherbuoy.ui.SettingsActivity.java
com.kevinrschultz.weatherbuoy.ui.SettingsFragment.java
com.kevinrschultz.weatherbuoy.util.UnitConverter.java
com.kevinrschultz.weatherbuoy.views.AdvisoryBannerView.java
com.kevinrschultz.weatherbuoy.views.InstrumentView.java
com.kevinrschultz.weatherbuoy.views.Instrument.java
com.kevinrschultz.weatherbuoy.views.OptionalTextView.java