Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.act.weathertasks.activities;
- import android.app.AlertDialog;
- import android.app.Dialog;
- import android.app.TabActivity;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TabHost;
- import android.widget.TabHost.TabSpec;
- import com.act.weathertasks.R;
- @SuppressWarnings("deprecation")
- public class TabLayoutActivity extends TabActivity {
- Context baseContext = getBaseContext();
- private SharedPreferences prefs = baseContext.getSharedPreferences("prefs", 0);
- private String username = null;
- private String password = null;
- /**
- * Called when the activity is first created.
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.tablayout);
- TabHost tabHost = getTabHost();
- // Tab for stuff
- TabSpec overzichtSpec = tabHost.newTabSpec("Overzicht");
- // Setting Title and Icon for the Tab
- overzichtSpec.setIndicator("Overzicht");
- Intent overzichtIntent = new Intent(this, OverviewActivity.class);
- overzichtSpec.setContent(overzichtIntent);
- // Tab for more stuff
- TabSpec takenSpec = tabHost.newTabSpec("Taken");
- takenSpec.setIndicator("Taken");
- Intent takenIntent = new Intent(this, TasksActivity.class);
- takenSpec.setContent(takenIntent);
- // Tab for even more stuff
- TabSpec weerSpec = tabHost.newTabSpec("Weer");
- weerSpec.setIndicator("Weer");
- Intent weerIntent = new Intent(this, WeatherActivity.class);
- weerSpec.setContent(weerIntent);
- /*
- // Tab for even more stuff
- TabSpec ApiSpec = tabHost.newTabSpec("Api");
- ApiSpec.setIndicator("Api");
- Intent ApiIntent = new Intent(this, TaskAPIActivity.class);
- ApiSpec.setContent(ApiIntent);
- */
- tabHost.addTab(overzichtSpec); // Adding first tab
- tabHost.addTab(takenSpec); // Adding second tab
- tabHost.addTab(weerSpec); // Adding third tab
- //tabHost.addTab(ApiSpec);
- if (prefs.getString("USERNAME", null) == null || prefs.getString("PASSWORD", null) == null) {
- final Dialog dialog = new Dialog(TabLayoutActivity.this);
- dialog.setContentView(R.layout.login);
- dialog.setTitle("Login");
- dialog.setCancelable(true);
- Button loginButton = (Button) dialog.findViewById(R.id.loginButton);
- Button cancelButton = (Button) dialog.findViewById(R.id.cancelButton);
- final EditText usernameText = (EditText) dialog.findViewById(R.id.usernameText);
- final EditText passwordText = (EditText) dialog.findViewById(R.id.passwordText);
- loginButton.setOnClickListener(new OnClickListener() {
- public void onClick(View t) {
- username = usernameText.getText().toString();
- password = passwordText.getText().toString();
- dialog.dismiss();
- }
- });
- cancelButton.setOnClickListener(new OnClickListener() {
- public void onClick(View t) {
- dialog.dismiss();
- }
- });
- dialog.show();
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString("USERNAME", username);
- editor.putString("PASSWORD", password);
- editor.commit();
- } else {
- username = prefs.getString("USERNAME", null);
- password = prefs.getString("PASSWORD", null);
- }
- /*
- try {
- login()
- } catch (Failed login) {
- // give login screen again with toast of incorrect data
- }
- */
- }
- }
Add Comment
Please, Sign In to add comment