Search in sources :

Example 1 with GPSTracker

use of com.a5corp.weather.permissions.GPSTracker in project Weather by Sparker0i.

the class WeatherFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_weather, container, false);
    ButterKnife.bind(this, rootView);
    MaterialDialog.Builder builder = new MaterialDialog.Builder(this.getActivity()).title(getString(R.string.please_wait)).content(getString(R.string.loading)).cancelable(false).progress(true, 0);
    pd = builder.build();
    setHasOptionsMenu(true);
    preferences = new Prefs(getContext());
    weatherFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/weather.ttf");
    Bundle bundle = getArguments();
    int mode;
    if (bundle != null)
        mode = bundle.getInt(Constants.MODE, 0);
    else
        mode = 0;
    if (mode == 0)
        updateWeatherData(preferences.getCity(), null, null);
    else
        updateWeatherData(null, Float.toString(preferences.getLatitude()), Float.toString(preferences.getLongitude()));
    gps = new GPSTracker(getContext());
    cityField.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    updatedField.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    humidityView.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    sunriseIcon.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    sunriseIcon.setTypeface(weatherFont);
    sunriseIcon.setText(getActivity().getString(R.string.sunrise_icon));
    sunsetIcon.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    sunsetIcon.setTypeface(weatherFont);
    sunsetIcon.setText(getActivity().getString(R.string.sunset_icon));
    windIcon.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    windIcon.setTypeface(weatherFont);
    windIcon.setText(getActivity().getString(R.string.speed_icon));
    humidityIcon.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    humidityIcon.setTypeface(weatherFont);
    humidityIcon.setText(getActivity().getString(R.string.humidity_icon));
    windView.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    swipeView.setColorSchemeResources(R.color.red, R.color.green, R.color.blue, R.color.yellow, R.color.orange);
    swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            swipeView.setRefreshing(true);
            handler.post(new Runnable() {

                @Override
                public void run() {
                    changeCity(preferences.getCity());
                }
            });
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    swipeView.setRefreshing(false);
                }
            }, 10000);
        }
    });
    directionView.setTypeface(weatherFont);
    directionView.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    dailyView.setText(getString(R.string.daily));
    dailyView.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    sunriseView.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    sunsetView.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    button.setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    pd.show();
    for (int i = 0; i < 11; ++i) {
        String f = "details_view" + (i + 1), g = "weather_icon" + (i + 1);
        if (i != 10) {
            int resID = getResources().getIdentifier(f, "id", getContext().getPackageName());
            detailsField[i] = (TextView) rootView.findViewById(resID);
            detailsField[i].setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
        }
        int resIDI = getResources().getIdentifier(g, "id", getContext().getPackageName());
        weatherIcon[i] = (TextView) rootView.findViewById(resIDI);
        weatherIcon[i].setTypeface(weatherFont);
        weatherIcon[i].setTextColor(ContextCompat.getColor(getContext(), R.color.textColor));
    }
    return rootView;
}
Also used : GPSTracker(com.a5corp.weather.permissions.GPSTracker) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Bundle(android.os.Bundle) SpannableString(android.text.SpannableString) Prefs(com.a5corp.weather.preferences.Prefs) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 2 with GPSTracker

use of com.a5corp.weather.permissions.GPSTracker in project Weather by Sparker0i.

the class WeatherFragment method showCity.

private void showCity() {
    gps = new GPSTracker(getContext());
    if (!gps.canGetLocation())
        gps.showSettingsAlert();
    else {
        String lat = gps.getLatitude();
        String lon = gps.getLongitude();
        changeCity(lat, lon);
    }
}
Also used : GPSTracker(com.a5corp.weather.permissions.GPSTracker) SpannableString(android.text.SpannableString)

Aggregations

SpannableString (android.text.SpannableString)2 GPSTracker (com.a5corp.weather.permissions.GPSTracker)2 Bundle (android.os.Bundle)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 Prefs (com.a5corp.weather.preferences.Prefs)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1