Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.project.test;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.net.ConnectivityManager;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.preference.PreferenceManager;
- import android.telephony.TelephonyManager;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import android.widget.Toast;
- import edu.bellevue.android.blackboard.BlackboardHelper;
- public class MainActivity extends Activity implements Runnable{
- /** Called when the activity is first created. */
- private ProgressDialog pd;
- private Handler handler = new Handler(){
- public void handleMessage(Message m)
- {
- pd.setMessage("Success!");
- if(BlackboardHelper.isLoggedIn()){
- Intent i = new Intent(MainActivity.this,CourseViewer.class);
- startActivity(i);
- }
- pd.dismiss();
- }
- };
- public boolean onCreateOptionsMenu(Menu m)
- {
- m.add("Settings");
- return super.onCreateOptionsMenu(m);
- }
- public boolean onOptionsItemSelected(MenuItem mi)
- {
- if (mi.getTitle().equals("Settings"))
- {
- Intent i = new Intent(this,PrefActivity.class);
- startActivity(i);
- }
- return true;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button loginButton = (Button)findViewById(R.id.btnLogIn);
- loginButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Thread t = new Thread(MainActivity.this);
- pd = ProgressDialog.show(MainActivity.this, "Please Wait", "Logging In...");
- t.start();
- }
- });
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- if (prefs.getBoolean("autologin", false)){
- ((TextView)findViewById(R.id.txtUserName)).setText(prefs.getString("username","n/a"));
- ((TextView)findViewById(R.id.txtPassword)).setText(prefs.getString("password","n/a"));
- Thread t = new Thread(MainActivity.this);
- pd = ProgressDialog.show(MainActivity.this, "Please Wait", "Logging In...");
- t.start();
- return;
- }
- }
- public void run()
- {
- // TODO Auto-generated method stub
- String userName = (((TextView)findViewById(R.id.txtUserName)).getText()).toString();
- String password = (((TextView)findViewById(R.id.txtPassword)).getText()).toString();
- BlackboardHelper.logIn(userName, password);
- handler.sendEmptyMessage(0);
- }
- public static boolean shouldConnect(SharedPreferences prefs, Context ctx)
- {
- ConnectivityManager connMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
- int netType = connMan.getActiveNetworkInfo().getType();
- int netSubType = connMan.getActiveNetworkInfo().getSubtype();
- if (netType == ConnectivityManager.TYPE_WIFI)
- {
- return prefs.getBoolean("wifi", false);
- } else if (netType == ConnectivityManager.TYPE_MOBILE)
- {
- if (prefs.getBoolean("mobile",false))
- {
- TelephonyManager tm = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
- if (tm.isNetworkRoaming())
- {
- return (prefs.getBoolean("roaming",false));
- }else
- {
- return true;
- }
- }else
- {
- return false;
- }
- }else
- {return false;}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement