Back to project page GADemo.
The source code is released under:
GNU General Public License
If you think the Android project GADemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.pdro.gademo; /*from ww w . j a v a2 s . c o m*/ import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.Toast; import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Logger; import com.google.android.gms.analytics.Tracker; public class MainActivity extends Activity { private final String PROPERTY_ID = getString(R.string.gaProperty); // for GA private final int DISPATCH_PERIOD = 5; private Tracker tracker; private ColorWheel mColorWheel = new ColorWheel(); private final String screenName = "Main Screen"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Enabling Up / Back navigation ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); // tracker code tracker = GoogleAnalytics.getInstance(this).newTracker(PROPERTY_ID); tracker.setScreenName(screenName); GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(DISPATCH_PERIOD); GoogleAnalytics.getInstance(this).getLogger().setLogLevel(Logger.LogLevel.VERBOSE); tracker.send(new HitBuilders.AppViewBuilder().build()); // variables dealing with layout final RelativeLayout mainScreenLayout = (RelativeLayout) findViewById(R.id.mainScreenLayout); final Button eventButton = (Button) findViewById(R.id.trackEvent_Button); final Button exceptionButton = (Button) findViewById(R.id.trackCrash_Button); final Button secondScreenButton = (Button) findViewById(R.id.launchSecondScreen_Button); // Button Listener for EVENT eventButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { tracker.send(new HitBuilders.EventBuilder() .setCategory("Event Button") .setAction("Pressed the Event Button") .setLabel("trackEvent") .build()); Toast.makeText(getApplicationContext(), "Event sent to GA", Toast.LENGTH_SHORT).show(); int color = mColorWheel.getColor(); mainScreenLayout.setBackgroundColor(color); eventButton.setTextColor(color); exceptionButton.setTextColor(color); secondScreenButton.setTextColor(color); } }); // Button Listener for EXCEPTION exceptionButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { // Build and send exception. tracker.send(new HitBuilders.ExceptionBuilder() .setDescription(null) .setFatal(false) .build()); Toast.makeText(getApplicationContext(), "Exception thrown", Toast.LENGTH_SHORT).show(); int color = mColorWheel.getColor(); mainScreenLayout.setBackgroundColor(color); eventButton.setTextColor(color); exceptionButton.setTextColor(color); secondScreenButton.setTextColor(color); } }); secondScreenButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, MessagesActivity.class); startActivity(intent); } }); } }