Search in sources :

Example 6 with Prefs

use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.

the class SmallWidgetProvider method scheduleNextUpdate.

private static void scheduleNextUpdate(Context context) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    long now = new Date().getTime();
    long nextUpdate = now + Long.parseLong(new Prefs(context).getTime());
    if (BuildConfig.DEBUG) {
        Log.i(TAG, "Next widget update: " + android.text.format.DateFormat.getTimeFormat(context).format(new Date(nextUpdate)));
    }
    if (Build.VERSION.SDK_INT >= 19) {
        alarmManager.setExact(AlarmManager.RTC, nextUpdate, getTimeIntent(context));
    } else {
        alarmManager.set(AlarmManager.RTC, nextUpdate, getTimeIntent(context));
    }
}
Also used : AlarmManager(android.app.AlarmManager) Prefs(com.a5corp.weather.preferences.Prefs) Date(java.util.Date)

Example 7 with Prefs

use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.

the class WeatherFragment method onCreateView.

@Override
public View onCreateView(@NonNull 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.activity()).title(getString(R.string.please_wait)).content(getString(R.string.loading)).cancelable(false).progress(true, 0);
    pd = builder.build();
    setHasOptionsMenu(true);
    preferences = new Prefs(context());
    weatherFont = Typeface.createFromAsset(activity().getAssets(), "fonts/weather-icons-v2.0.10.ttf");
    fab = ((WeatherActivity) activity()).findViewById(R.id.fab);
    Bundle bundle = getArguments();
    fabProgressCircle = ((WeatherActivity) activity()).findViewById(R.id.fabProgressCircle);
    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(context());
    cityField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    updatedField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    humidityView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseIcon.setTypeface(weatherFont);
    sunriseIcon.setText(activity().getString(R.string.sunrise_icon));
    sunsetIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunsetIcon.setTypeface(weatherFont);
    sunsetIcon.setText(activity().getString(R.string.sunset_icon));
    humidityIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    humidityIcon.setTypeface(weatherFont);
    humidityIcon.setText(activity().getString(R.string.humidity_icon));
    windView.setTextColor(ContextCompat.getColor(context(), 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() {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    changeCity(preferences.getCity());
                    swipeView.setRefreshing(false);
                }
            });
        }
    });
    horizontalLayoutManager = new LinearLayoutManager(context(), LinearLayoutManager.HORIZONTAL, false);
    horizontalRecyclerView.setLayoutManager(horizontalLayoutManager);
    horizontalRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (horizontalLayoutManager.findLastVisibleItemPosition() == 9 || citys != null)
                fab.hide();
            else
                fab.show();
        }
    });
    directionView.setTypeface(weatherFont);
    directionView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    dailyView.setText(getString(R.string.daily));
    dailyView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunsetView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    button.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    pd.show();
    horizontalRecyclerView.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    weatherIcon.setTypeface(weatherFont);
    weatherIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    if (citys == null)
        ((WeatherActivity) activity()).showFab();
    else
        ((WeatherActivity) activity()).hideFab();
    return rootView;
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Bundle(android.os.Bundle) Prefs(com.a5corp.weather.preferences.Prefs) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) GPSTracker(com.a5corp.weather.permissions.GPSTracker) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 8 with Prefs

use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.

the class WeatherActivity method changeCity.

public void changeCity(String city) {
    WeatherFragment wf = (WeatherFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
    wf.changeCity(city);
    new Prefs(this).setCity(city);
}
Also used : WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) Prefs(com.a5corp.weather.preferences.Prefs)

Example 9 with Prefs

use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.

the class MapsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    rootView = inflater.inflate(R.layout.fragment_maps, container, false);
    webView = (WebView) rootView.findViewById(R.id.webView);
    prefs = new Prefs(getContext());
    ((WeatherActivity) getActivity()).hideFab();
    loadMap();
    return rootView;
}
Also used : WeatherActivity(com.a5corp.weather.activity.WeatherActivity) Prefs(com.a5corp.weather.preferences.Prefs)

Example 10 with Prefs

use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.

the class LicenseActivity method attachBaseContext.

@Override
protected void attachBaseContext(Context newBase) {
    Context context = MyContextWrapper.wrap(newBase, new Prefs(newBase).getLanguage());
    super.attachBaseContext(context);
}
Also used : Context(android.content.Context) Prefs(com.a5corp.weather.preferences.Prefs)

Aggregations

Prefs (com.a5corp.weather.preferences.Prefs)25 AlarmManager (android.app.AlarmManager)6 Intent (android.content.Intent)6 PendingIntent (android.app.PendingIntent)5 Context (android.content.Context)5 WeatherInfo (com.a5corp.weather.model.WeatherInfo)3 Date (java.util.Date)3 Bundle (android.os.Bundle)2 View (android.view.View)2 WeatherActivity (com.a5corp.weather.activity.WeatherActivity)2 WeatherFragment (com.a5corp.weather.fragment.WeatherFragment)2 CheckConnection (com.a5corp.weather.internet.CheckConnection)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 Locale (java.util.Locale)2 SharedPreferences (android.content.SharedPreferences)1 Configuration (android.content.res.Configuration)1 Handler (android.os.Handler)1 KeyEvent (android.view.KeyEvent)1 Button (android.widget.Button)1