Search in sources :

Example 1 with PokemapSharedPreferences

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();
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) MapWrapperFragment(com.omkarmoghe.pokemap.views.map.MapWrapperFragment) PokemapSharedPreferences(com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with PokemapSharedPreferences

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();
}
Also used : PokemapSharedPreferences(com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences)

Example 3 with PokemapSharedPreferences

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);
}
Also used : ArrayList(java.util.ArrayList) PokemonIdOuterClass(POGOProtos.Enums.PokemonIdOuterClass) PokemapSharedPreferences(com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences) HashSet(java.util.HashSet)

Example 4 with PokemapSharedPreferences

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;
}
Also used : PokemapSharedPreferences(com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences)

Example 5 with PokemapSharedPreferences

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LoginInfo(com.omkarmoghe.pokemap.models.login.LoginInfo) PtcLoginInfo(com.omkarmoghe.pokemap.models.login.PtcLoginInfo) GoogleLoginInfo(com.omkarmoghe.pokemap.models.login.GoogleLoginInfo) PtcLoginInfo(com.omkarmoghe.pokemap.models.login.PtcLoginInfo) GoogleLoginInfo(com.omkarmoghe.pokemap.models.login.GoogleLoginInfo) PokemapSharedPreferences(com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) SignInButton(com.google.android.gms.common.SignInButton) NianticManager(com.omkarmoghe.pokemap.controllers.net.NianticManager) Button(android.widget.Button) SignInButton(com.google.android.gms.common.SignInButton) GoogleService(com.omkarmoghe.pokemap.controllers.net.GoogleService) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) GoogleManager(com.omkarmoghe.pokemap.controllers.net.GoogleManager)

Aggregations

PokemapSharedPreferences (com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences)5 PokemonIdOuterClass (POGOProtos.Enums.PokemonIdOuterClass)1 FragmentManager (android.support.v4.app.FragmentManager)1 AlertDialog (android.support.v7.app.AlertDialog)1 Toolbar (android.support.v7.widget.Toolbar)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 SignInButton (com.google.android.gms.common.SignInButton)1 GoogleManager (com.omkarmoghe.pokemap.controllers.net.GoogleManager)1 GoogleService (com.omkarmoghe.pokemap.controllers.net.GoogleService)1 NianticManager (com.omkarmoghe.pokemap.controllers.net.NianticManager)1 GoogleLoginInfo (com.omkarmoghe.pokemap.models.login.GoogleLoginInfo)1 LoginInfo (com.omkarmoghe.pokemap.models.login.LoginInfo)1 PtcLoginInfo (com.omkarmoghe.pokemap.models.login.PtcLoginInfo)1 MapWrapperFragment (com.omkarmoghe.pokemap.views.map.MapWrapperFragment)1 ArrayList (java.util.ArrayList)1