Permalink
Browse files

Add another view to the sample app. Extract demo constants.

  • Loading branch information...
1 parent 9a8aea2 commit 29559d909c9b294cf326addb35dc07524efe62ab @daggerrz daggerrz committed Mar 20, 2012
View
1 sample-app/AndroidManifest.xml
@@ -13,5 +13,6 @@
</intent-filter>
</activity>
<activity android:name=".AdViewActivity" android:label="Ad with managed view"/>
+ <activity android:name=".ManualMarkupActivity" android:label="Manual markup management"/>
</application>
</manifest>
View
2 sample-app/res/layout/main.xml
@@ -17,7 +17,7 @@
/>
<Button android:id="@+id/pull_ad_markup"
- android:text="Get ad markup"
+ android:text="Show manual markup view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
View
22 sample-app/res/layout/manual_ad_markup.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+
+ <Button android:id="@+id/pull_ad_markup"
+ android:text="Get ad markup"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ />
+
+ <TextView
+ android:id="@+id/markup"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="No markup loaded"
+ />
+
+</LinearLayout>
+
View
18 sample-app/src/main/java/com/tapad/sample/MainActivity.java
@@ -18,9 +18,9 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- // Or use Tracking.init(this) to use the application package id
- Tracking.init(this, "AndroidEventSDK_testapp");
- AdServing.init(this, "18", null);
+ AdServing.init(this, SampleConstants.PUBLISHER_ID, SampleConstants.PROPERTY_ID);
+ // AdServing.init calls the Tracking init code. If you are just using the Tracking API,
+ // just call Tracking.init(this) instead of the above.
Button custom = (Button) findViewById(R.id.custom_event);
custom.setOnClickListener(new View.OnClickListener() {
@@ -33,17 +33,7 @@ public void onClick(View view) {
adMarkup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
- AdServing.get().requestAd(new AdRequest("110", AdSize.S320x50) {
- @Override
- protected void onResponse(final AdResponse response) {
- view.post(new Runnable() {
- @Override
- public void run() {
- Logging.info("ADS", response.getMarkup());
- }
- });
- }
- });
+ startActivity(new Intent(MainActivity.this, ManualMarkupActivity.class));
}
});
View
58 sample-app/src/main/java/com/tapad/sample/ManualMarkupActivity.java
@@ -0,0 +1,58 @@
+package com.tapad.sample;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import com.tapad.adserving.AdRequest;
+import com.tapad.adserving.AdResponse;
+import com.tapad.adserving.AdServing;
+import com.tapad.adserving.AdSize;
+
+public class ManualMarkupActivity extends Activity {
+ private TextView markupView;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.manual_ad_markup);
+
+ markupView = (TextView) findViewById(R.id.markup);
+
+ Button adMarkup = (Button) findViewById(R.id.pull_ad_markup);
+ adMarkup.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(final View view) {
+ loadMarkup();
+ }
+ });
+ }
+
+ private void loadMarkup() {
+ AdServing.get().requestAd(new AdRequest(SampleConstants.PLACEMENT_ID, AdSize.S320x50, false) {
+ @Override
+ protected void onResponse(final AdResponse response) {
+ markupView.post(new Runnable() {
+ @Override
+ public void run() {
+ handleResponse(response);
+ }
+ });
+ }
+ });
+ }
+
+ private void handleResponse(AdResponse response) {
+ switch (response.getResponseCode()) {
+ case AdResponse.OK:
+ markupView.setText(response.getMarkup());
+ break;
+ case AdResponse.NO_AD_AVAILABLE:
+ markupView.setText("No markup available for this publisher, placement and / or size.");
+ break;
+ case AdResponse.ERROR:
+ markupView.setText("Unable to load markup: " + response.getMessage());
+ }
+ }
+}
View
7 sample-app/src/main/java/com/tapad/sample/SampleConstants.java
@@ -0,0 +1,7 @@
+package com.tapad.sample;
+
+public class SampleConstants {
+ public static final String PUBLISHER_ID = "18";
+ public static final String PROPERTY_ID = "38";
+ public static final String PLACEMENT_ID = "110";
+}

0 comments on commit 29559d9

Please sign in to comment.