use of com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences in project Pokemap by omkarmoghe.
the class MainActivity method onCreate.
//region Lifecycle Methods
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sharedPref = this.getSharedPreferences(getString(R.string.pref_file_key), Context.MODE_PRIVATE);
themeId = sharedPref.getInt(getString(R.string.pref_theme_no_action_bar), R.style.AppTheme_NoActionBar);
setTheme(themeId);
setContentView(R.layout.activity_main);
pref = new PokemapSharedPreferences(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FragmentManager fragmentManager = getSupportFragmentManager();
MapWrapperFragment mapWrapperFragment = (MapWrapperFragment) fragmentManager.findFragmentByTag(MAP_FRAGMENT_TAG);
if (mapWrapperFragment == null) {
mapWrapperFragment = MapWrapperFragment.newInstance();
}
fragmentManager.beginTransaction().replace(R.id.main_container, mapWrapperFragment, MAP_FRAGMENT_TAG).commit();
if (pref.isServiceEnabled()) {
startNotificationService();
}
}
use of com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences in project Pokemap by omkarmoghe.
the class MapWrapperFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
mPref = new PokemapSharedPreferences(getContext());
showablePokemonIDs = mPref.getShowablePokemonIDs();
}
use of com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences in project Pokemap by omkarmoghe.
the class PokemonToShowPreference method init.
private void init(Context context) {
List<CharSequence> entries = new ArrayList<>();
List<CharSequence> entriesValues = new ArrayList<>();
Set<String> defaultValues = new HashSet<>();
PokemonIdOuterClass.PokemonId[] ids = PokemonIdOuterClass.PokemonId.values();
for (PokemonIdOuterClass.PokemonId pokemonId : ids) {
if ((pokemonId != PokemonIdOuterClass.PokemonId.MISSINGNO) && (pokemonId != PokemonIdOuterClass.PokemonId.UNRECOGNIZED)) {
entries.add(PokemonIdUtils.getLocalePokemonName(context, pokemonId.name()));
entriesValues.add(String.valueOf(pokemonId.getNumber()));
defaultValues.add(String.valueOf(pokemonId.getNumber()));
}
}
setEntries(entries.toArray(new CharSequence[] {}));
setEntryValues(entriesValues.toArray(new CharSequence[] {}));
// all pokemons are shown by default
setDefaultValue(defaultValues);
mPref = new PokemapSharedPreferences(context);
}
use of com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences in project Pokemap by omkarmoghe.
the class PokemonNotificationService method onCreate.
@Override
public void onCreate() {
EventBus.getDefault().register(this);
createNotification();
preffs = new PokemapSharedPreferences(this);
locationManager = LocationManager.getInstance(this);
nianticManager = NianticManager.getInstance();
updateRunnable = new UpdateRunnable(preffs.getServiceRefreshRate() * 1000);
workThread = new Thread(updateRunnable);
initBroadcastReciever();
workThread.start();
locationManager.onResume();
isRunning = true;
}
use of com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences in project Pokemap by omkarmoghe.
the class LoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNianticManager = NianticManager.getInstance();
mGoogleManager = GoogleManager.getInstance();
mPref = new PokemapSharedPreferences(this);
setContentView(R.layout.activity_login);
mNianticAuthListener = new NianticManager.AuthListener() {
@Override
public void authSuccessful() {
finishLogin();
}
@Override
public void authFailed(String message, String provider) {
switch(provider) {
case LoginInfo.PROVIDER_PTC:
showPTCLoginFailed();
break;
case LoginInfo.PROVIDER_GOOGLE:
showGoogleLoginFailed();
break;
}
Log.d(TAG, "authFailed() called with: message = [" + message + "]");
}
};
mNianticLoginListener = new NianticManager.LoginListener() {
@Override
public void authSuccessful(String authToken) {
Log.d(TAG, "authSuccessful() called with: authToken = [" + authToken + "]");
PtcLoginInfo info = new PtcLoginInfo(authToken, mUsernameView.getText().toString(), mPasswordView.getText().toString());
mPref.setLoginInfo(info);
mNianticManager.setLoginInfo(LoginActivity.this, info, mNianticAuthListener);
}
@Override
public void authFailed(String message) {
Log.e(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
showPTCLoginFailed();
}
};
mGoogleLoginListener = new GoogleManager.LoginListener() {
@Override
public void authSuccessful(String authToken, String refreshToken) {
GoogleLoginInfo info = new GoogleLoginInfo(authToken, refreshToken);
Log.d(TAG, "authSuccessful() called with: authToken = [" + authToken + "]");
mPref.setLoginInfo(info);
mNianticManager.setLoginInfo(LoginActivity.this, info, mNianticAuthListener);
}
@Override
public void authFailed(String message) {
Log.d(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
showGoogleLoginFailed();
}
@Override
public void authRequested(GoogleService.AuthRequest body) {
//Do nothing
}
};
findViewById(R.id.txtDisclaimer).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
new AlertDialog.Builder(LoginActivity.this).setTitle(getString(R.string.login_warning_title)).setMessage(Html.fromHtml(getString(R.string.login_warning))).setPositiveButton(android.R.string.ok, null).show();
}
});
// Set up the triggerAutoLogin form.
mUsernameView = (AutoCompleteTextView) findViewById(R.id.username);
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.login || id == EditorInfo.IME_NULL) {
validatePTCLoginForm();
return true;
}
return false;
}
});
LoginInfo loginInfo = mPref.getLoginInfo();
if (loginInfo != null && loginInfo instanceof PtcLoginInfo) {
mUsernameView.setText(((PtcLoginInfo) loginInfo).getUsername());
mPasswordView.setText(((PtcLoginInfo) loginInfo).getPassword());
}
Button signInButton = (Button) findViewById(R.id.email_sign_in_button);
signInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
validatePTCLoginForm();
}
});
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
SignInButton signInButtonGoogle = (SignInButton) findViewById(R.id.sign_in_button);
signInButtonGoogle.setSize(SignInButton.SIZE_WIDE);
signInButtonGoogle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
GoogleAuthActivity.startForResult(LoginActivity.this, REQUEST_USER_AUTH);
}
});
triggerAutoLogin();
}
Aggregations