This is an old revision of the document!
Colocviu 1
Model de Subiect
Observații Generale
Pentru rezolvarea subiectelor propuse în cadrul colocviului 1, sunt necesare:
- un cont Github personal, pe care să existe drepturi de citire și de scriere;
- SDK-ul de Android (cu o imagine pentru nivelul de API 16 - Jelly Bean 4.1);
- mediul de dezvoltare integrat Eclipse, împreună cu plugin-ul Android Developer Tools;
- un dispozitiv mobil:
- fizic (bring your own device);
- virtual: Genymotion, AVD.
În situația în care lucrați pe calculatoarele din laboratorul Ixia (EG106) este recomandat să folosiți:
- fluxbox ca utilitar pentru gestiunea ferestrelor (se alege din interfața de autentificare);
- epiphany pentru navigare Internet.
Este de preferat să nu se depășească memoria disponibilă, întrucât comportamentul acestor mașini este imprevizibil în momentul în care se folosește swap-ul (se blochează, fără posibilitatea de recuperare din eroare).
Rezolvări
1. Se urmăresc indicațiile disponibile în secțiunea Crearea unui cont Github, subpunctele 3-4.
2.
student@pdsd2015:~$ git clone https://www.github.com/perfectstudent/PracticalTest01
3. Se urmăresc indicațiile disponibile în secțiunea Crearea unei aplicații Android în Eclipse Luna SR1a (4.4.1).
4.
- activity_practical_test01_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" tools:context="ro.pub.cs.systems.pdsd.practicaltest01.PracticalTest01MainActivity" > <Button android:id="@+id/navigate_to_secondary_activity_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/navigate_to_secondary_activity" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/left_edit_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:saveEnabled="false" android:enabled="false" android:inputType="number" android:gravity="center" /> <EditText android:id="@+id/right_edit_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:saveEnabled="false" android:enabled="false" android:inputType="number" android:gravity="center" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="false" > <ScrollView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <Button android:id="@+id/left_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/press_me" /> </ScrollView> <ScrollView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <Button android:id="@+id/right_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/press_me_too" /> </ScrollView> </LinearLayout> </LinearLayout>
5.
private ButtonClickListener buttonClickListener = new ButtonClickListener(); private class ButtonClickListener implements Button.OnClickListener { @Override public void onClick(View view) { EditText leftEditText = (EditText)PracticalTest01MainActivity.this.findViewById(R.id.left_edit_text); EditText rightEditText = (EditText)PracticalTest01MainActivity.this.findViewById(R.id.right_edit_text); int leftButtonClickedNumber = Integer.parseInt(leftEditText.getText().toString()); int rightButtonClickedNumber = Integer.parseInt(rightEditText.getText().toString()); switch(view.getId()) { case R.id.left_button: leftButtonClickedNumber++; leftEditText.setText(String.valueOf(leftButtonClickedNumber)); break; case R.id.right_button: rightButtonClickedNumber++; rightEditText.setText(String.valueOf(rightButtonClickedNumber)); break; } } } @Override protected void onCreate(Bundle savedInstanceState) { // ... Button leftButton = (Button)findViewById(R.id.left_button); leftButton.setOnClickListener(buttonClickListener); Button rightButton = (Button)findViewById(R.id.right_button); rightButton.setOnClickListener(buttonClickListener); }
6.
a)
b)
c)
d)
7.
- PracticalTest01SecondaryActivity.java
package ro.pub.cs.systems.pdsd.practicaltest01; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView; public class PracticalTest01SecondaryActivity extends Activity { private ButtonClickListener buttonClickListener = new ButtonClickListener(); private class ButtonClickListener implements Button.OnClickListener { @Override public void onClick(View view) { switch(view.getId()) { case R.id.ok_button: setResult(RESULT_OK, new Intent()); finish(); break; case R.id.cancel_button: setResult(RESULT_CANCELED, new Intent()); finish(); break; } } } }
8.
9.
student@pdsd2015:~/PracticalTest01$ git add * student@pdsd2015:~/PracticalTest01$ git commit -m "finished tasks for PracticalTest01" student@pdsd2015:~/PracticalTest01$ git push origin master
