Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. package com.example.kash.postgresql;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences;
  5. import android.os.Bundle;
  6. import android.support.v7.app.ActionBarActivity;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.Toast;
  13.  
  14.  
  15. public class NewConnection extends ActionBarActivity implements View.OnClickListener
  16. {
  17.     EditText etProf,etURL,etUser,etPass,etDB,etPort;
  18.     Button btnAdd;
  19.     String prof,url,user,pass,DB;
  20.     int port;
  21.     @Override
  22.     protected void onCreate(Bundle savedInstanceState)
  23.     {
  24.         super.onCreate(savedInstanceState);
  25.         setContentView(R.layout.activity_new_connection);
  26.         etProf=(EditText) findViewById(R.id.etProf);
  27.         etURL=(EditText) findViewById(R.id.etURL);
  28.         etUser=(EditText) findViewById(R.id.etUser);
  29.         etPass=(EditText) findViewById(R.id.etPass);
  30.         etDB=(EditText) findViewById(R.id.etDB);
  31.         etPort=(EditText) findViewById(R.id.etPort);
  32.         btnAdd=(Button) findViewById(R.id.btnAdd);
  33.         btnAdd.setOnClickListener(this);
  34.     }
  35.  
  36.     @Override
  37.     public boolean onCreateOptionsMenu(Menu menu)
  38.     {
  39.         // Inflate the menu; this adds items to the action bar if it is present.
  40.         getMenuInflater().inflate(R.menu.menu_new_connection, menu);
  41.         return true;
  42.     }
  43.  
  44.     @Override
  45.     public boolean onOptionsItemSelected(MenuItem item)
  46.     {
  47.         // Handle action bar item clicks here. The action bar will
  48.         // automatically handle clicks on the Home/Up button, so long
  49.         // as you specify a parent activity in AndroidManifest.xml.
  50.         int id = item.getItemId();
  51.  
  52.         //noinspection SimplifiableIfStatement
  53.         if (id == R.id.action_settings)
  54.         {
  55.             return true;
  56.         }
  57.  
  58.         return super.onOptionsItemSelected(item);
  59.     }
  60.  
  61.     @Override
  62.     public void onClick(View v)
  63.     {
  64.         switch(v.getId())
  65.         {
  66.             case R.id.btnAdd:
  67.             {
  68.                 prof=etProf.getText().toString();
  69.                 url=etURL.getText().toString();
  70.                 user=etUser.getText().toString();
  71.                 pass=etPass.getText().toString();
  72.                 DB=etDB.getText().toString();
  73.                 port= Integer.parseInt(etPort.getText().toString());
  74.                 Toast.makeText(this,"Profile Name: "+prof+"\n"+"URL: "+url+"\n"+"Username: "+user+"\n"+"Password: "+pass+"\n"+"Database Name: "+DB+"\n"+"Port Name: "+port,Toast.LENGTH_LONG).show();
  75.                 SharedPreferences prefs=this.getSharedPreferences(prof,Context.MODE_PRIVATE);
  76.                 prefs.edit().putString("Profile",prof).apply();
  77.                 prefs.edit().putString("URL",url).apply();
  78.                 prefs.edit().putString("User",user).apply();
  79.                 prefs.edit().putString("Password",pass).apply();
  80.                 prefs.edit().putString("DB",DB).apply();
  81.                 prefs.edit().putInt("Port", port).apply();
  82.                 finish();
  83.             }
  84.             break;
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement