Back to project page piwik_android_sdk.
The source code is released under:
MIT License
If you think the Android project piwik_android_sdk 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.anupcowkur.piwiksample; // w ww .j a v a 2 s. c om import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.anupcowkur.piwiksdk.PiwikClient; import java.util.HashMap; public class LayoutChangesActivity extends Activity { /** * A static list of country names. */ private static final String[] COUNTRIES = new String[]{"Belgium", "France", "Italy", "Germany", "Spain", "Austria", "Russia", "Poland", "Croatia", "Greece", "Ukraine",}; /** * The container view which has layout change animations turned on. In this sample, this view * is a {@link android.widget.LinearLayout}. */ private ViewGroup mContainerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_layout_changes); mContainerView = (ViewGroup) findViewById(R.id.container); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.activity_layout_changes, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // Navigate "up" the demo structure to the launchpad activity. // See http://developer.android.com/design/patterns/navigation.html for more. NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); return true; case R.id.action_add_item: // Hide the "empty" view since there is now at least one item in the list. findViewById(android.R.id.empty).setVisibility(View.GONE); addItem(); return true; case R.id.action_sync: PiwikClient.syncImmediately(); return true; } return super.onOptionsItemSelected(item); } private void addItem() { // Instantiate a new "row" view. final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, mContainerView, false); String country = COUNTRIES[(int) (Math.random() * COUNTRIES.length)]; // Set the text in the new row to a random country. ((TextView) newView.findViewById(android.R.id.text1)).setText(country); PiwikClient.trackEvent(this, "List/Add"); // Set a click listener for the "X" button in the row that will remove the row. newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Remove the row from its parent (the container view). // Because mContainerView has android:animateLayoutChanges set to true, // this removal is automatically animated. mContainerView.removeView(newView); PiwikClient.trackEvent(LayoutChangesActivity.this, "List/Remove"); // If there are no rows remaining, show the empty view. if (mContainerView.getChildCount() == 0) { findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } } }); // Because mContainerView has android:animateLayoutChanges set to true, // adding this view is automatically animated. mContainerView.addView(newView, 0); } }