Java tutorial
package com.canappi.connector.yp.yhere; /**************************************************************************************************** Disclaimer: IMPORTANT: This artifact is supplied to you by Convergence Modeling LLC. in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this acceptance constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Convergence Modeling LLC artifact. In consideration of your agreement to abide by the following terms, and subject to these terms, Convergence Modeling LLC grants you a personal, non-exclusive license, to use, reproduce, modify and redistribute this artifact, with or without modifications, in source and/or binary forms. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Convergence Modeling LLC herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Convergence Modeling artifact may be incorporated. This artifact is provided by Convergence Modeling LLC on an "AS IS" basis. CONVERGENCE MODELING LLC MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE CONVERGENCE MODELING LLC artifact OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL CONVERGENCE MODELING LLC BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF CONVERGENCE MODELING LLC artifact, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF CONVERGENCE MODELING LLC HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ****************************************************************************************************/ import java.util.HashMap; import java.util.Iterator; import java.util.ArrayList; import java.util.Calendar; import java.util.Set; import java.lang.reflect.Field; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import android.net.Uri; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.app.Activity; import android.content.Intent; import android.content.Context; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.KeyEvent; import android.webkit.WebView; import android.widget.*; import android.util.Log; import android.app.Dialog; import android.widget.ImageView; import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.view.LayoutInflater; import android.view.ViewGroup; import org.apache.http.impl.client.DefaultHttpClient; import java.net.HttpURLConnection; import java.io.DataOutputStream; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import org.xml.sax.InputSource; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import com.canappi.connector.yp.yhere.R; public class CouponView extends Activity { Activity parentController; HashMap couponViewIds; HashMap couponViewValues; // Connection ypCoupons // Operation : getCouponsByZip private ArrayList<HashMap> getCouponsByZipResultSet; private HashMap getCouponsByZipRow; private Boolean isRoot; private Boolean isRow; private Boolean isColumn; private String currentProperty; private String currentElement; String searchlocQueryParameter; public String getSearchlocQueryParameter() { return this.searchlocQueryParameter; } public void setSearchlocQueryParameter(String s) { this.searchlocQueryParameter = s; } String getCouponsByZipURLString; // Layout : couponsLayout private ListView resultsListView; ResultsEfficientAdapter resultsAdapter; private static ArrayList<String> businessNameArray; private static ArrayList<String> couponDescriptionArray; private static ArrayList<String> couponIdArray; private static ArrayList<String> phoneNumberArray; private static ArrayList<String> callArray; private static ArrayList<String> streetArray; private static ArrayList<String> cityArray; Boolean isUserDefault; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.couponview); resultsListView = (ListView) findViewById(R.id.resultsTable); viewDidLoad(); Log.i("couponView", "onCreate() callback method"); } public void setParentController(Activity a) { parentController = a; } public Activity getParentController() { return parentController; } public ArrayList<Element> getCouponsByZip(HashMap<String, String> requestParameters) { ArrayList<Element> data = new ArrayList<Element>(); System.setProperty("http.keepAlive", "false"); System.setProperty("javax.net.debug", "all"); // _FakeX509TrustManager.allowAllSSL(); //Protocol::: HTTP GET StringBuffer query = new StringBuffer(); HttpURLConnection connection = null; try { URL url; if (requestParameters != null) { String key; query.append( "http://api2.yp.com/listings/v1/coupons?format=xml&key=5d0b448ba491c2dff5a36040a125df0a"); query.append("&"); key = "searchloc"; String searchlocValue = requestParameters.get(key); String searchlocDefaultValue = retrieveFromUserDefaultsFor(key); if (searchlocValue.length() > 0) { query.append("" + key + "=" + requestParameters.get(key)); } else { //try to find the value in the user defaults if (searchlocDefaultValue != null) { query.append("" + key + "=" + retrieveFromUserDefaultsFor(key)); } } url = new URL(query.toString()); } else { url = new URL( "http://api2.yp.com/listings/v1/coupons?format=xml&key=5d0b448ba491c2dff5a36040a125df0a"); } connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); connection.setUseCaches(false); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); int rc = connection.getResponseCode(); Log.i("Response code", String.valueOf(rc)); InputStream is; if (rc <= 400) { is = connection.getInputStream(); } else { /* error from server */ is = connection.getErrorStream(); } //XML ResultSet try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource isrc = new InputSource(); isrc.setByteStream(is); Document doc = db.parse(isrc); NodeList nodes = doc.getElementsByTagName("searchListings"); if (nodes.getLength() > 0) { Element list = (Element) nodes.item(0); NodeList l = list.getChildNodes(); for (int i = 0; i < l.getLength(); i++) { Node n = l.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element row = (Element) l.item(i); data.add(row); } } } } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } finally { connection.disconnect(); } return data; } public void fetchDataFromypCoupons(Object orows) { HashMap<String, String> map = new HashMap<String, String>(); map.put("couponDescription", "coupons.couponDescription"); map.put("businessName", "businessName"); map.put("couponId", "couponId"); map.put("phoneNumber", "phone"); map.put("street", "street"); map.put("city", "city"); map.put("call", "call"); ArrayList<Element> rows = (ArrayList<Element>) orows; if (rows != null) { if (rows.size() > 0) { String key = ""; String subkey = ""; //Init from Web API Data // couponsLayout //Initializing results //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@6dc57a92 (name: businessName, text: name, font: Helvetica-Bold, size: 14, alignment: Left, lines: null) //if (rows.size()>0) { for (int i = 0; i < rows.size(); i++) { Element row = (Element) rows.get(i); Object object = null; key = map.get("businessName"); int r = key.indexOf("."); if (r < 0) { NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element e = (Element) nodes.item(0); object = e.getTextContent(); } else { object = ""; } } else { String[] elementNames; elementNames = key.split("\\."); key = elementNames[0]; subkey = elementNames[elementNames.length - 1]; NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element rootElement = (Element) nodes.item(0); NodeList subnodes = rootElement.getElementsByTagName(subkey); if (subnodes.getLength() > 0) { Element e = (Element) subnodes.item(0); object = e.getTextContent(); } else { //We need to look one level deeper (but not more) subnodes = rootElement.getChildNodes(); object = ""; for (int k = 0; k < subnodes.getLength(); k++) { Element e = (Element) subnodes.item(k); NodeList otherNodes = e.getElementsByTagName(subkey); if (otherNodes.getLength() > 0) { Element sube = (Element) otherNodes.item(0); object = sube.getTextContent(); } } } } else { object = ""; } } if (object != null) { businessNameArray.add((String) object); } else { businessNameArray.add(""); } } //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@7d206f0 (name: couponDescription, text: coupon, font: null, size: null, alignment: Left, lines: 3) //if (rows.size()>0) { for (int i = 0; i < rows.size(); i++) { Element row = (Element) rows.get(i); Object object = null; key = map.get("couponDescription"); int r = key.indexOf("."); if (r < 0) { NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element e = (Element) nodes.item(0); object = e.getTextContent(); } else { object = ""; } } else { String[] elementNames; elementNames = key.split("\\."); key = elementNames[0]; subkey = elementNames[elementNames.length - 1]; NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element rootElement = (Element) nodes.item(0); NodeList subnodes = rootElement.getElementsByTagName(subkey); if (subnodes.getLength() > 0) { Element e = (Element) subnodes.item(0); object = e.getTextContent(); } else { //We need to look one level deeper (but not more) subnodes = rootElement.getChildNodes(); object = ""; for (int k = 0; k < subnodes.getLength(); k++) { Element e = (Element) subnodes.item(k); NodeList otherNodes = e.getElementsByTagName(subkey); if (otherNodes.getLength() > 0) { Element sube = (Element) otherNodes.item(0); object = sube.getTextContent(); } } } } else { object = ""; } } if (object != null) { couponDescriptionArray.add((String) object); } else { couponDescriptionArray.add(""); } } //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@51d92803 (name: couponId, text: id, font: null, size: null, alignment: Left, lines: null) //if (rows.size()>0) { for (int i = 0; i < rows.size(); i++) { Element row = (Element) rows.get(i); Object object = null; key = map.get("couponId"); int r = key.indexOf("."); if (r < 0) { NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element e = (Element) nodes.item(0); object = e.getTextContent(); } else { object = ""; } } else { String[] elementNames; elementNames = key.split("\\."); key = elementNames[0]; subkey = elementNames[elementNames.length - 1]; NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element rootElement = (Element) nodes.item(0); NodeList subnodes = rootElement.getElementsByTagName(subkey); if (subnodes.getLength() > 0) { Element e = (Element) subnodes.item(0); object = e.getTextContent(); } else { //We need to look one level deeper (but not more) subnodes = rootElement.getChildNodes(); object = ""; for (int k = 0; k < subnodes.getLength(); k++) { Element e = (Element) subnodes.item(k); NodeList otherNodes = e.getElementsByTagName(subkey); if (otherNodes.getLength() > 0) { Element sube = (Element) otherNodes.item(0); object = sube.getTextContent(); } } } } else { object = ""; } } if (object != null) { couponIdArray.add((String) object); } else { couponIdArray.add(""); } } //Processing com.canappi.metamodels.mdsl.mDsl.impl.TextImpl@744957c7 (name: phoneNumber, defaultText: null, font: null, size: null, alignment: Left, readOnly: false, hasClearButton: false, clearButtonMode: Never, isSecure: false, textEntry: textEntry, isAutocomplete: false, lines: null, placeHolder: null, orientation: right, buttonMode: Never, border: none) //if (rows.size()>0) { for (int i = 0; i < rows.size(); i++) { Element row = (Element) rows.get(i); Object object = null; key = map.get("phoneNumber"); int r = key.indexOf("."); if (r < 0) { NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element e = (Element) nodes.item(0); object = e.getTextContent(); } else { object = ""; } } else { String[] elementNames; elementNames = key.split("\\."); key = elementNames[0]; subkey = elementNames[elementNames.length - 1]; NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element rootElement = (Element) nodes.item(0); NodeList subnodes = rootElement.getElementsByTagName(subkey); if (subnodes.getLength() > 0) { Element e = (Element) subnodes.item(0); object = e.getTextContent(); } else { //We need to look one level deeper (but not more) subnodes = rootElement.getChildNodes(); object = ""; for (int k = 0; k < subnodes.getLength(); k++) { Element e = (Element) subnodes.item(k); NodeList otherNodes = e.getElementsByTagName(subkey); if (otherNodes.getLength() > 0) { Element sube = (Element) otherNodes.item(0); object = sube.getTextContent(); } } } } else { object = ""; } } if (object != null) { phoneNumberArray.add((String) object); } else { phoneNumberArray.add(""); } } //Processing com.canappi.metamodels.mdsl.mDsl.impl.ButtonImpl@24065c4 (name: call, title: , titleSelected: null, style: Bordered, gradientStyle: Alert, image: phone.png, selectedImage: null, font: null, size: null, isStandard: None) //if (rows.size()>0) { for (int i = 0; i < rows.size(); i++) { Element row = (Element) rows.get(i); Object object = null; key = map.get("call"); int r = key.indexOf("."); if (r < 0) { NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element e = (Element) nodes.item(0); object = e.getTextContent(); } else { object = ""; } } else { String[] elementNames; elementNames = key.split("\\."); key = elementNames[0]; subkey = elementNames[elementNames.length - 1]; NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element rootElement = (Element) nodes.item(0); NodeList subnodes = rootElement.getElementsByTagName(subkey); if (subnodes.getLength() > 0) { Element e = (Element) subnodes.item(0); object = e.getTextContent(); } else { //We need to look one level deeper (but not more) subnodes = rootElement.getChildNodes(); object = ""; for (int k = 0; k < subnodes.getLength(); k++) { Element e = (Element) subnodes.item(k); NodeList otherNodes = e.getElementsByTagName(subkey); if (otherNodes.getLength() > 0) { Element sube = (Element) otherNodes.item(0); object = sube.getTextContent(); } } } } else { object = ""; } } if (object != null) { callArray.add((String) object); } else { callArray.add(""); } } //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@30c3bb57 (name: street, text: id, font: null, size: null, alignment: Left, lines: null) //if (rows.size()>0) { for (int i = 0; i < rows.size(); i++) { Element row = (Element) rows.get(i); Object object = null; key = map.get("street"); int r = key.indexOf("."); if (r < 0) { NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element e = (Element) nodes.item(0); object = e.getTextContent(); } else { object = ""; } } else { String[] elementNames; elementNames = key.split("\\."); key = elementNames[0]; subkey = elementNames[elementNames.length - 1]; NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element rootElement = (Element) nodes.item(0); NodeList subnodes = rootElement.getElementsByTagName(subkey); if (subnodes.getLength() > 0) { Element e = (Element) subnodes.item(0); object = e.getTextContent(); } else { //We need to look one level deeper (but not more) subnodes = rootElement.getChildNodes(); object = ""; for (int k = 0; k < subnodes.getLength(); k++) { Element e = (Element) subnodes.item(k); NodeList otherNodes = e.getElementsByTagName(subkey); if (otherNodes.getLength() > 0) { Element sube = (Element) otherNodes.item(0); object = sube.getTextContent(); } } } } else { object = ""; } } if (object != null) { streetArray.add((String) object); } else { streetArray.add(""); } } //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@40f186b8 (name: city, text: id, font: Helvetica-Oblique, size: 10, alignment: Left, lines: null) //if (rows.size()>0) { for (int i = 0; i < rows.size(); i++) { Element row = (Element) rows.get(i); Object object = null; key = map.get("city"); int r = key.indexOf("."); if (r < 0) { NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element e = (Element) nodes.item(0); object = e.getTextContent(); } else { object = ""; } } else { String[] elementNames; elementNames = key.split("\\."); key = elementNames[0]; subkey = elementNames[elementNames.length - 1]; NodeList nodes = row.getElementsByTagName(key); if (nodes.getLength() > 0) { Element rootElement = (Element) nodes.item(0); NodeList subnodes = rootElement.getElementsByTagName(subkey); if (subnodes.getLength() > 0) { Element e = (Element) subnodes.item(0); object = e.getTextContent(); } else { //We need to look one level deeper (but not more) subnodes = rootElement.getChildNodes(); object = ""; for (int k = 0; k < subnodes.getLength(); k++) { Element e = (Element) subnodes.item(k); NodeList otherNodes = e.getElementsByTagName(subkey); if (otherNodes.getLength() > 0) { Element sube = (Element) otherNodes.item(0); object = sube.getTextContent(); } } } } else { object = ""; } } if (object != null) { cityArray.add((String) object); } else { cityArray.add(""); } } } } } public HashMap identities() { return couponViewIds; } public HashMap values() { return couponViewValues; } public String textValueForControl(String name) { return (String) couponViewValues.get(name); } public String idForControl(String name) { return (String) couponViewIds.get(name); } public void setId(String id, String name) { couponViewIds.put(name, id); } public String retrieveFromUserDefaultsFor(String key) { SharedPreferences settings = getSharedPreferences("yherePreferences", MODE_PRIVATE); return settings.getString(key, null); } public void didSelectViewController() { if (this.searchlocQueryParameter == null) this.searchlocQueryParameter = ""; HashMap<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("searchloc", this.searchlocQueryParameter); ArrayList<Element> getCouponsByZipResultSet = this.getCouponsByZip(requestParameters); fetchDataFromypCoupons(getCouponsByZipResultSet); } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. public void viewDidLoad() { Bundle extras = getIntent().getExtras(); if (extras != null) { Set<String> keys = extras.keySet(); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = iter.next(); Class c = SearchView.class; try { Field f = c.getDeclaredField(key); Object extra = extras.get(key); String value = extra.toString(); f.set(this, extras.getString(value)); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else { } couponViewIds = new HashMap(); couponViewValues = new HashMap(); isUserDefault = false; resultsListView = (ListView) findViewById(R.id.resultsTable); resultsAdapter = new ResultsEfficientAdapter(this); businessNameArray = new ArrayList<String>(); couponDescriptionArray = new ArrayList<String>(); couponIdArray = new ArrayList<String>(); phoneNumberArray = new ArrayList<String>(); callArray = new ArrayList<String>(); streetArray = new ArrayList<String>(); cityArray = new ArrayList<String>(); resultsListView.setAdapter(resultsAdapter); didSelectViewController(); } private static String pad(int c) { if (c >= 10) return String.valueOf(c); else return "0" + String.valueOf(c); } // Control Actions public void call(View view) { if (view.getId() == R.id.callButton) { //Open URL in a browser Object o = view.getTag(); int p = (Integer) o; String callPhone = phoneNumberArray.get(p); if (callPhone != null) { String phone = "tel:" + callPhone; Intent call = new Intent(Intent.ACTION_CALL, Uri.parse(phone)); startActivity(call); } //TODO Implement Action //End of Action Implementation //TODO implement call action } } private static class ResultsEfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public ResultsEfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { //Log.v("Count :",String.valueOf(vehicleitems.size())); return businessNameArray.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.coupon, null); holder = new ViewHolder(); holder.businessNameTextView = (TextView) convertView.findViewById(R.id.businessNameTextView); holder.businessNameTextView.setTag(new Integer(position)); holder.couponDescriptionTextView = (TextView) convertView .findViewById(R.id.couponDescriptionTextView); holder.couponDescriptionTextView.setTag(new Integer(position)); holder.couponIdTextView = (TextView) convertView.findViewById(R.id.couponIdTextView); holder.couponIdTextView.setTag(new Integer(position)); holder.phoneNumberEditText = (TextView) convertView.findViewById(R.id.phoneNumberEditText); holder.phoneNumberEditText.setTag(new Integer(position)); holder.callButton = (Button) convertView.findViewById(R.id.callButton); holder.callButton.setTag(new Integer(position)); holder.streetTextView = (TextView) convertView.findViewById(R.id.streetTextView); holder.streetTextView.setTag(new Integer(position)); holder.cityTextView = (TextView) convertView.findViewById(R.id.cityTextView); holder.cityTextView.setTag(new Integer(position)); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.businessNameTextView.setText(businessNameArray.get(position)); holder.couponDescriptionTextView.setText(couponDescriptionArray.get(position)); holder.couponIdTextView.setText(couponIdArray.get(position)); holder.phoneNumberEditText.setText(phoneNumberArray.get(position)); holder.streetTextView.setText(streetArray.get(position)); holder.cityTextView.setText(cityArray.get(position)); return convertView; } static class ViewHolder { TextView businessNameTextView; TextView couponDescriptionTextView; TextView couponIdTextView; TextView phoneNumberEditText; Button callButton; TextView streetTextView; TextView cityTextView; } } @Override protected Dialog onCreateDialog(int id) { switch (id) { } return null; } @Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { } } public void viewDidUnload() { resultsListView = (ListView) findViewById(R.id.resultsTable); resultsAdapter = new ResultsEfficientAdapter(this); businessNameArray = new ArrayList<String>(); couponDescriptionArray = new ArrayList<String>(); couponIdArray = new ArrayList<String>(); phoneNumberArray = new ArrayList<String>(); callArray = new ArrayList<String>(); streetArray = new ArrayList<String>(); cityArray = new ArrayList<String>(); resultsListView.setAdapter(resultsAdapter); } @Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; switch (item.getItemId()) { case R.layout.searchview: // app icon in Action Bar clicked; go home intent = new Intent(this, SearchView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.restaurantview: // app icon in Action Bar clicked; go home intent = new Intent(this, RestaurantView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.groceryview: // app icon in Action Bar clicked; go home intent = new Intent(this, GroceryView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.gasstationview: // app icon in Action Bar clicked; go home intent = new Intent(this, GasStationView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.theaterview: // app icon in Action Bar clicked; go home intent = new Intent(this, TheaterView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.couponview: // app icon in Action Bar clicked; go home intent = new Intent(this, CouponView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.lubeview: // app icon in Action Bar clicked; go home intent = new Intent(this, LubeView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.gameview: // app icon in Action Bar clicked; go home intent = new Intent(this, GameView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.bakeryview: // app icon in Action Bar clicked; go home intent = new Intent(this, BakeryView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.repairview: // app icon in Action Bar clicked; go home intent = new Intent(this, RepairView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.homeview: // app icon in Action Bar clicked; go home intent = new Intent(this, HomeView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; case R.layout.settingsview: // app icon in Action Bar clicked; go home intent = new Intent(this, SettingsView.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } } @Override public boolean onCreateOptionsMenu(Menu menu) { //getMenuInflater().inflate(R.menu.menu, menu); //SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); // Set appropriate listeners for searchView //... return super.onCreateOptionsMenu(menu); } @Override protected void onStart() { super.onStart(); //Toast.makeText(this, "onStart", Toast.LENGTH_SHORT).show(); } @Override protected void onResume() { super.onResume(); //Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show(); } @Override protected void onRestart() { super.onRestart(); //Toast.makeText(this, "onRestart", Toast.LENGTH_SHORT).show(); } @Override protected void onPause() { super.onPause(); //Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show(); super.onPause(); } @Override protected void onStop() { super.onStop(); //Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show(); super.onStop(); } @Override protected void onDestroy() { super.onDestroy(); //Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } }