In this tutorial, we will create an app that will showcase a few of the Adobe CC apps.
As in many objects that are created, we will:
In this version, we will simple drag and drop components that are needed for the app onto the screen. These components are XML elements that get compiled to their appropriate Java objects type when the app is built.
While you could have done this at the SAME time you create each component above, we wanted to do it in a systematic approach. However, in real production it would be best to create the components and give them names at the same time they are created.
IMPORTANT CONCEPT TO REMEMBER: It is important to name every component that will be used by Java code with an id. The id is used to store a reference of the element in a Java object as you will see later.
Again, you could have written some code as you created the components like adding an onClick handler to the button. However, we wanted to do this step in a a logical manner.
public void buttonEventHandler(View view) {
Log.i("Info", "A button was clicked.");
}
private static final String TAG = "MainActivity"; // OR
private static final String TAG = MainActivity.class.getSimpleName();
public void buttonEventHandler(View view) {
//Log.i("Info", "A button was clicked.");
switch (view.getId()){
case R.id.dw_buttonID:
Log.i("Info", "The Dreamweaver button clicked.");
break;
case R.id.ps_buttonID:
Log.i("Info", "The Photoshop button clicked.");
break; case R.id.ai_buttonID:
Log.i("Info", "The Illustrator button clicked.");
break;
case R.id.id_buttonID:
Log.i("Info", "The InDesign button clicked.");
break;
}
}
Now that we have all of the buttons created and working within the same activity (page), we will now create MULTIPLE activities (pages) that corresponds to each button. In the next version of this app, we will see how to create a SINGLE page that can be used for all buttons.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
<activity
android:name=".DWActivity"
android:label="@string/title_activity_dw"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.adobeccapps.MainActivity" />
</activity>
Now that we have created new activities, we need to write the code to navigate to those activities.
public void buttonEventHandler(View view) {
// Log.i("Info", "A button was clicked.");
switch (view.getId()){
case R.id.dw_buttonID:
// Log.i("Info", "The Dreamweaver button clicked.");
Intent dwPage = new Intent(MainActivity.this, DWActivity.class);
startActivity(dwPage);
break;
case R.id.ps_buttonID:
// Log.i("Info", "The Photoshop button clicked.");
Intent psPage = new Intent(MainActivity.this, PSActivity.class);
startActivity(psPage);
break;
case R.id.ai_buttonID:
// Log.i("Info", "The Illustrator button clicked.");
Intent aiPage = new Intent(MainActivity.this, AIActivity.class);
startActivity(aiPage);
break;
case R.id.id_buttonID:
// Log.i("Info", "The InDesign button clicked.");
Intent idPage = new Intent(MainActivity.this, IDActivity.class);
startActivity(idPage);
break;
}
}
}
While the default button works fine, we will customize them by using a selector to get it two custom states (normal and pressed).
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<item android:drawable="@drawable/button_background_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/button_background_default" />
</selector>
android:background="@drawable/custom_button_states"