Kaidul

Home.java

Jan 16th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.08 KB | None | 0 0
  1. package com.weltintegra;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.location.Location;
  7. import android.location.LocationListener;
  8. import android.location.LocationManager;
  9. import android.net.Uri;
  10. import android.net.wifi.WifiInfo;
  11. import android.net.wifi.WifiManager;
  12. import android.os.Bundle;
  13. import android.telephony.TelephonyManager;
  14. import android.util.Log;
  15. import android.view.View;
  16. import com.google.android.gcm.GCMRegistrar;
  17. import com.google.android.maps.GeoPoint;
  18. import org.apache.http.client.HttpClient;
  19. import org.apache.http.client.methods.HttpPost;
  20. import org.apache.http.impl.client.DefaultHttpClient;
  21.  
  22. import java.security.MessageDigest;
  23. import java.util.UUID;
  24.  
  25. public class home extends Activity {
  26.     private LocationManager locationManager;
  27.     public GeoPoint myLoc;
  28.     public Double lat1;
  29.     public Double lng1;
  30.     protected static String deviceID;
  31.     private String api_token = "b431e1f3aeda13305c155f8d26791f86";
  32.  
  33.     public void onCreate(Bundle savedInstanceState) {
  34.         super.onCreate(savedInstanceState);
  35.         setLocationManager((LocationManager) getSystemService(Context.LOCATION_SERVICE));
  36.         LocationManager locationManager = (LocationManager) this
  37.                 .getSystemService(Context.LOCATION_SERVICE);
  38.         // Define a listener that responds to location updates
  39.         LocationListener locationListener = new LocationListener() {
  40.             public void onLocationChanged(Location location) {
  41.                 // Called when a new location is found by the network location
  42.                 // provider.
  43.                 lng1 = location.getLongitude();
  44.                 lat1 = location.getLatitude();
  45.             }
  46.  
  47.             public void onStatusChanged(String provider, int status,
  48.                     Bundle extras) {
  49.                 Log.i("geo", "ok");
  50.             }
  51.  
  52.             public void onProviderEnabled(String provider) {
  53.             }
  54.  
  55.             public void onProviderDisabled(String provider) {
  56.             }
  57.         };
  58.  
  59.         // Register the listener with the Location Manager to receive location
  60.         // updates
  61.         locationManager.requestLocationUpdates(
  62.                 LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  63.         setContentView(R.layout.home);
  64.  
  65.         try {
  66.             deviceID = getDeviceId(this.getBaseContext());
  67.         } catch (Exception e) {
  68.             e.printStackTrace(); // To change body of catch statement use File |
  69.                                     // Settings | File Templates.
  70.         }
  71.         GCMRegistrar.checkDevice(this);
  72.         GCMRegistrar.checkManifest(this);
  73.         final String regId = GCMRegistrar.getRegistrationId(this);
  74.         if (regId.equals("")) {
  75.             GCMRegistrar.register(this, "181872115906");
  76.         } else {
  77.             HttpClient httpclient = new DefaultHttpClient();
  78.             HttpPost httppost = new HttpPost(
  79.                     "http://apn.weltint.com/userdb/registerandroid/"
  80.                             + api_token + "/" + regId + "/" + deviceID);
  81.             try {
  82.                 httpclient.execute(httppost);
  83.             } catch (Exception ex) {
  84.             }
  85.         }
  86.     }
  87.  
  88.     public void goToQr(View view) {
  89.         Intent intent = new Intent(getParent(), rootqr.class);
  90.         startActivity(intent);
  91.     }
  92.  
  93.     public void shareit(View view) {
  94.         final Intent emailIntent = new Intent(
  95.                 android.content.Intent.ACTION_SEND);
  96.  
  97.         emailIntent.setType("plain/text");
  98.  
  99.         // /emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new
  100.         // String[]{"[email protected]"});
  101.  
  102.         emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Try "
  103.                 + getString(R.string.app_name));
  104.  
  105.         emailIntent
  106.                 .putExtra(
  107.                         android.content.Intent.EXTRA_TEXT,
  108.                         "I love this app and would like to share with you. https://play.google.com/store/search?q="
  109.                                 + getString(R.string.app_name) + "=apps");
  110.  
  111.         home.this.startActivity(Intent.createChooser(emailIntent,
  112.                 "Send mail..."));
  113.     }
  114.  
  115.     public void callUs(View view) {
  116.         Intent sIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
  117.                 + getString(R.string.mainphone)));
  118.         startActivity(sIntent);
  119.     }
  120.  
  121.     public void ourPhisican(View view) {
  122.         Intent intent = new Intent(getParent(), rootWeb.class);
  123.         intent.putExtra("url", "file:///android_asset/our_phisican.html");
  124.         startActivity(intent);
  125.     }
  126.  
  127.     public void goDirection(View view) {
  128.         // Log.i("GEO",lat1.toString());
  129.         String coordinates[] = { getString(R.string.lat),
  130.                 getString(R.string.lon) };
  131.         double lat = Double.parseDouble(coordinates[0]);
  132.         double lng = Double.parseDouble(coordinates[1]);
  133.         String url = "http://maps.google.com/maps?saddr=" + lat1.toString()
  134.                 + "," + lng1.toString() + "&daddr=" + lat + "," + lng;
  135.         Intent i = new Intent(Intent.ACTION_VIEW);
  136.         i.setData(Uri.parse(url));
  137.         startActivity(i);
  138.     }
  139.  
  140.     protected static String getDeviceId(Context context) throws Exception {
  141.         String imei = getImei(context);
  142.         if (imei != null)
  143.             return imei;
  144.         String tid = getWifiMacAddress(context);
  145.         return tid;
  146.     }
  147.  
  148.     protected static String getImei(Context context) {
  149.         TelephonyManager m = (TelephonyManager) context
  150.                 .getSystemService(Context.TELEPHONY_SERVICE);
  151.         String imei = m != null ? m.getDeviceId() : null;
  152.         return imei;
  153.     }
  154.  
  155.     protected static String getWifiMacAddress(Context context) throws Exception {
  156.         WifiManager manager = (WifiManager) context
  157.                 .getSystemService(Context.WIFI_SERVICE);
  158.         WifiInfo wifiInfo = manager.getConnectionInfo();
  159.         if (wifiInfo == null || wifiInfo.getMacAddress() == null)
  160.             return md5(UUID.randomUUID().toString());
  161.         else
  162.             return wifiInfo.getMacAddress().replace(":", "").replace(".", "");
  163.     }
  164.  
  165.     public void goToAppointment(View view) {
  166.         Intent intent = new Intent(getParent(), rootAppointment.class);
  167.         startActivity(intent);
  168.     }
  169.  
  170.     public void goToMb(View view) {
  171.         Intent intent = new Intent(getParent(), rootmb.class);
  172.         startActivity(intent);
  173.     }
  174.  
  175.     protected static String md5(String s) throws Exception {
  176.         MessageDigest md = MessageDigest.getInstance("MD5");
  177.  
  178.         md.update(s.getBytes());
  179.  
  180.         byte digest[] = md.digest();
  181.         StringBuffer result = new StringBuffer();
  182.  
  183.         for (int i = 0; i < digest.length; i++) {
  184.             result.append(Integer.toHexString(0xFF & digest[i]));
  185.         }
  186.         return (result.toString());
  187.     }
  188.  
  189.     public void setLocationManager(LocationManager locationManager) {
  190.         this.locationManager = locationManager;
  191.     }
  192.  
  193.     public LocationManager getLocationManager() {
  194.         return locationManager;
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment