Advertisement
Kimossab

CP - Teste Exemplo

Jun 4th, 2015
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.19 KB | None | 0 0
  1. /*
  2. NOTAS:
  3. -Ignorei os imports... nao vou tar a decorar aquela merda toda...
  4. -Nao sei até que ponto é isto que é para fazer, mas eu faria assim
  5. -Assumi muita merda que nao sei se era para assumir ou nao... Por exemplo o gestor de base de dados
  6. -Pouco me interessa o XML do layout, se for preciso eu posso fazer mas mais de metade do pessoal nao o vai conseguir fazer num teste... Mas pronto... fuck it...
  7. */
  8. //Parte II
  9. //1
  10. public class P1 extends Activity
  11. {
  12.     EditText TipoMoeda;
  13.     EditText TipoMoedaConv;
  14.     EditText FactorConv;
  15.     EditText Valor;
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState)
  19.     {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.activity_main);
  22.  
  23.         TipoMoeda = (EditText)findViewById(R.id.tipomoeda); //textview para o tipo de moeda a converter
  24.         TipoMoedaConv = (EditText)findViewById(R.id.tipomoedaconv); //textview para o tipo de moeda convertida
  25.         FactorConv = (EditText)findViewById(R.id.factorconv); //textview para o factor de conversao
  26.         Valor = (EditText)findViewById(R.id.valor); //textview com o valor a converter
  27.     }
  28.  
  29.     //Função para o click do butão "Converter"
  30.     public void Converter(View v)
  31.     {
  32.         float vl = Float.parseFloat(Valor.getText().toString());
  33.         float tot = vl * Float.parseFloat(FactorConv.getText().toString());
  34.  
  35.         Toast.makeText(getApplicationContext(), vl + " " + TipoMoeda.getText() + " representam " + tot + " " + TipoMoedaConv.getText(),Toast.LENGTH_LONG).show();
  36.     }
  37. }
  38.  
  39. //2
  40. public class P2 extends Activity
  41. {
  42.     private EditText Email;
  43.     private EditText Name;
  44.  
  45.     @Override
  46.     protected void onCreate(Bundle savedInstanceState)
  47.     {
  48.         super.onCreate(savedInstanceState);
  49.         setContentView(R.layout.activity_p2);
  50.  
  51.         Email = (EditText) findViewById(R.id.email);
  52.         Name = (EditText) findViewById(R.id.nome);
  53.     }
  54.  
  55.     //função para o click do botao Adicionar Contacto
  56.     public void AddContacto(View v)
  57.     {
  58.         Intent intent = new Intent();
  59.         intent.putExtra(ContactsContract.Intents.Insert.EMAIL, Email.getText())
  60.                 .putExtra(ContactsContract.Intents.Insert.EMAIL_TYPE, ContactsContract.CommonDataKinds.Email.TYPE_WORK)
  61.                 .putExtra(ContactsContract.Intents.Insert.NAME, Name.getText())
  62.         startActivity(intent);
  63.     }
  64. }
  65.  
  66. //3
  67. public class P3 extends ActionBarActivity
  68. {
  69.  
  70.     @Override
  71.     protected void onCreate(Bundle savedInstanceState)
  72.     {
  73.         super.onCreate(savedInstanceState);
  74.         setContentView(R.layout.activity_p3);
  75.     }
  76.  
  77.     //public para o click no enviar email
  78.     public void SendEmail(View v)
  79.     {
  80.         Intent email = new Intent(Intent.ACTION_SEND);
  81.         email.setData(Uri.parse("mailto:"));
  82.         email.setType("text/plain");
  83.         email.putExtra(Intent.EXTRA_EMAIL, "pantonio@xx.pt");
  84.         email.putExtra(Intent.EXTRA_SUBJECT, "Reserva efectuada");
  85.         email.putExtra(Intent.EXTRA_TEXT, "A sua reserva foi feita com sucesso. Informamos que a sua reserva tem o código 12345");
  86.  
  87.         try
  88.         {
  89.             startActivity(Intent.createChooser(email, "Send mail..."));
  90.             finish();
  91.         }
  92.         catch(Exception e)
  93.         {
  94.             Toast.makeText(getApplicationContext(), "" + e.getMessage(), Toast.LENGTH_LONG).show();
  95.         }
  96.     }
  97. }
  98.  
  99. //4
  100. public class P4 extends ActionBarActivity
  101. {
  102.     Spinner sp;
  103.     ArrayList<String> al;
  104.     GestorBaseDados bd;
  105.  
  106.     @Override
  107.     protected void onCreate(Bundle savedInstanceState)
  108.     {
  109.         super.onCreate(savedInstanceState);
  110.         setContentView(R.layout.activity_p4);
  111.         bd = new GestorBaseDados(getApplicationContext());
  112.         al = new ArrayList<>();
  113.  
  114.         Cursor c = bd.GetDadosTabela("Spinner");
  115.  
  116.         if (c.moveToFirst())
  117.         {
  118.             do
  119.             {
  120.                 al.add(c.getString(c.getColumn("Texto")));
  121.             }while (c.moveToNext());
  122.         }
  123.  
  124.         sp = (Spinner)findViewById(R.id.spinner);
  125.         ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_spinner_item,al);
  126.         sp.setAdapter(adapter);
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement