use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class MyApplication method onCreate.
@Override
public void onCreate() {
super.onCreate();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getBaseContext().getResources().getConfiguration();
String lang = preferences.getString(getString(R.string.pref_language), "en");
locale = new Locale(lang);
config.setLocale(locale);
Log.i("Locale", lang);
Locale.setDefault(locale);
updateConfiguration(config);
setSystemLocale(config, locale);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
LanguageUtil.setLanguage(this, new Prefs(this).getLanguage());
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class NotificationService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
CheckConnection checkNetwork = new CheckConnection(this);
if (!checkNetwork.isNetworkAvailable()) {
return;
}
Log.i("In", "Notification Service Alarm");
intent = NotificationService.newIntent(this);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
prefs = new Prefs(this);
long intervalMillis = Long.parseLong(prefs.getTime());
if (alarmManager != null)
if (new Prefs(this).getNotifs()) {
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), intervalMillis, pendingIntent);
} else {
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();
}
String city = prefs.getCity();
String units = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.PREF_TEMPERATURE_UNITS, Constants.METRIC);
try {
WeatherInfo weather;
weather = new Request(this).getItems(city, units);
if (new Prefs(this).getNotifs())
weatherNotification(weather);
} catch (IOException e) {
Log.e(TAG, "Error get weather", e);
}
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class AlarmReceiver method setRecurringAlarm.
public static void setRecurringAlarm(Context context) {
Intent refresh = new Intent(context, AlarmReceiver.class);
PendingIntent recurringRefresh = PendingIntent.getBroadcast(context, 0, refresh, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long intervalMillis = Long.parseLong(new Prefs(context).getTime());
if (intervalMillis == 0) {
// Cancel previous alarm
alarms.cancel(recurringRefresh);
} else {
alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + intervalMillis, intervalMillis, recurringRefresh);
}
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class FirstLaunchFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_first_launch, container, false);
preferences = new Prefs(getContext());
cityInput = rootView.findViewById(R.id.city_input);
textField = rootView.findViewById(R.id.materialTextField);
ImageView img = textField.findViewById(R.id.mtf_image);
img.setImageAlpha(R.drawable.logo);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
permission = new Permissions(getContext());
requestPermissions(new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, Constants.READ_COARSE_LOCATION);
}
});
message = rootView.findViewById(R.id.intro_text);
if (GlobalActivity.i == 0) {
message.setText(getString(R.string.pick_city));
} else {
message.setText(getString(R.string.uh_oh));
}
Button goButton = rootView.findViewById(R.id.go_button);
goButton.setText(getString(android.R.string.ok));
goButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!new CheckConnection(getContext()).isNetworkAvailable()) {
Snackbar.make(rootView, getString(R.string.check_internet), Snackbar.LENGTH_SHORT).show();
} else if (cityInput.getText().length() > 0) {
launchActivity(0);
} else {
Snackbar.make(rootView, getString(R.string.enter_city_first), Snackbar.LENGTH_SHORT).show();
}
}
});
cityInput.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
launchActivity(0);
return true;
}
return false;
}
});
return rootView;
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class Request method gsonWeather.
private WeatherInfo gsonWeather(URL url) throws IOException {
HttpURLConnection connection1 = (HttpURLConnection) url.openConnection();
connection1.addRequestProperty("x-api-key", new Prefs(context).getWeatherKey());
InputStream content = connection1.getInputStream();
try {
// Read the server response and attempt to parse it as JSON
Reader reader = new InputStreamReader(content);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
Gson gson = gsonBuilder.create();
WeatherInfo posts = gson.fromJson(reader, WeatherInfo.class);
System.out.println(gson.toJson(posts));
content.close();
return posts;
} catch (Exception ex) {
Log.e("FetchWeather", "Failed to parse JSON due to: " + ex);
}
return null;
}
Aggregations