Android Open Source - UniTracker Main Activity






From Project

Back to project page UniTracker.

License

The source code is released under:

MIT License

If you think the Android project UniTracker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.connorroberts.unitracker;
//from   ww  w.  j  av  a 2 s . co m
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

import com.connorroberts.unitracker.fragments.LoginFragment;
import com.connorroberts.unitracker.fragments.MainFragment;
import com.connorroberts.unitracker.helpers.SecurePreferences;


public class MainActivity extends Activity {

    public WebView webView;
    public static SecurePreferences preferences;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        preferences = new SecurePreferences(this, "ucas-login", "<-- Add Random String for Encryption -->", true);

        if (savedInstanceState == null) {

            if(preferences.getString("personalId") == null) {

                getFragmentManager().beginTransaction()
                        .add(R.id.container, new LoginFragment())
                        .commit();

            }else {

                getFragmentManager().beginTransaction()
                        .add(R.id.container, new MainFragment())
                        .commit();

            }

        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);

        return true;

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        if(id == R.id.action_logout){

            preferences.clear();

            getFragmentManager().beginTransaction()
                    .replace(R.id.container, new LoginFragment())
                    .commit();

            return true;

        }else if(id == R.id.action_refresh){

            getFragmentManager().beginTransaction()
                    .replace(R.id.container, new MainFragment())
                    .commit();

        }

        return super.onOptionsItemSelected(item);
    }

    public static SecurePreferences getSecurePreferences(){

        return preferences;

    }

}




Java Source Code List

com.connorroberts.unitracker.MainActivity.java
com.connorroberts.unitracker.fragments.LoginFragment.java
com.connorroberts.unitracker.fragments.MainFragment.java
com.connorroberts.unitracker.helpers.JSInterface.java
com.connorroberts.unitracker.helpers.SecurePreferences.java