Guest User

Untitled

a guest
Feb 12th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. package com.act.weathertasks.activities;
  2.  
  3. import android.app.AlertDialog;
  4. import android.app.Dialog;
  5. import android.app.TabActivity;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.content.SharedPreferences;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.view.View.OnClickListener;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.TabHost;
  15. import android.widget.TabHost.TabSpec;
  16.  
  17. import com.act.weathertasks.R;
  18.  
  19. @SuppressWarnings("deprecation")
  20. public class TabLayoutActivity extends TabActivity {
  21.     Context baseContext = getBaseContext();
  22.     private SharedPreferences prefs = baseContext.getSharedPreferences("prefs", 0);
  23.     private String username = null;
  24.     private String password = null;
  25.    
  26.    
  27.     /**
  28.      * Called when the activity is first created.
  29.      */
  30.     @Override
  31.     public void onCreate(Bundle savedInstanceState) {
  32.         super.onCreate(savedInstanceState);
  33.         setContentView(R.layout.tablayout);
  34.  
  35.         TabHost tabHost = getTabHost();
  36.  
  37.         // Tab for stuff
  38.         TabSpec overzichtSpec = tabHost.newTabSpec("Overzicht");
  39.         // Setting Title and Icon for the Tab
  40.         overzichtSpec.setIndicator("Overzicht");
  41.         Intent overzichtIntent = new Intent(this, OverviewActivity.class);
  42.         overzichtSpec.setContent(overzichtIntent);
  43.  
  44.         // Tab for more stuff
  45.         TabSpec takenSpec = tabHost.newTabSpec("Taken");
  46.         takenSpec.setIndicator("Taken");
  47.         Intent takenIntent = new Intent(this, TasksActivity.class);
  48.         takenSpec.setContent(takenIntent);
  49.        
  50.         // Tab for even more stuff
  51.         TabSpec weerSpec = tabHost.newTabSpec("Weer");
  52.         weerSpec.setIndicator("Weer");
  53.         Intent weerIntent = new Intent(this, WeatherActivity.class);
  54.         weerSpec.setContent(weerIntent);
  55.         /*
  56.         // Tab for even more stuff
  57.         TabSpec ApiSpec = tabHost.newTabSpec("Api");
  58.         ApiSpec.setIndicator("Api");
  59.         Intent ApiIntent = new Intent(this, TaskAPIActivity.class);
  60.         ApiSpec.setContent(ApiIntent);
  61.         */
  62.         tabHost.addTab(overzichtSpec); // Adding first tab
  63.         tabHost.addTab(takenSpec); // Adding second tab
  64.         tabHost.addTab(weerSpec); // Adding third tab
  65.         //tabHost.addTab(ApiSpec);
  66.        
  67.  
  68.  
  69.         if (prefs.getString("USERNAME", null) == null || prefs.getString("PASSWORD", null) == null) {
  70.             final Dialog dialog = new Dialog(TabLayoutActivity.this);
  71.             dialog.setContentView(R.layout.login);
  72.             dialog.setTitle("Login");
  73.             dialog.setCancelable(true);
  74.             Button loginButton = (Button) dialog.findViewById(R.id.loginButton);
  75.             Button cancelButton = (Button) dialog.findViewById(R.id.cancelButton);
  76.             final EditText usernameText = (EditText) dialog.findViewById(R.id.usernameText);
  77.             final EditText passwordText = (EditText) dialog.findViewById(R.id.passwordText);
  78.             loginButton.setOnClickListener(new OnClickListener() {
  79.                 public void onClick(View t) {
  80.                     username = usernameText.getText().toString();
  81.                     password = passwordText.getText().toString();
  82.                     dialog.dismiss();
  83.                 }
  84.             });
  85.             cancelButton.setOnClickListener(new OnClickListener() {
  86.                 public void onClick(View t) {
  87.                     dialog.dismiss();
  88.                 }
  89.             });
  90.             dialog.show();
  91.            
  92.  
  93.             SharedPreferences.Editor editor =  prefs.edit();   
  94.             editor.putString("USERNAME", username);
  95.             editor.putString("PASSWORD", password);
  96.             editor.commit();
  97.         } else {
  98.             username = prefs.getString("USERNAME", null);
  99.             password = prefs.getString("PASSWORD", null);
  100.         }
  101.  
  102.         /*
  103.         try {
  104.             login()
  105.         } catch (Failed login) {
  106.             // give login screen again with toast of incorrect data
  107.         }
  108.         */
  109.     }
  110.    
  111. }
Add Comment
Please, Sign In to add comment