Advertisement
Crenox

My Weather Android Studio Program

Jun 9th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. package kartik.com.myweather;
  2.  
  3. import android.app.Activity;
  4. import android.location.Location;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.Button;
  11.  
  12. import com.google.android.gms.common.ConnectionResult;
  13. import com.google.android.gms.common.api.GoogleApiClient;
  14. import com.google.android.gms.location.FusedLocationProviderApi;
  15. import com.google.android.gms.location.LocationServices;
  16.  
  17.  
  18. public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
  19. GoogleApiClient.OnConnectionFailedListener {
  20.  
  21. GoogleApiClient mGoogleApiClient;
  22.  
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.activity_main);
  27.  
  28. mGoogleApiClient = new GoogleApiClient.Builder(this)
  29. .addConnectionCallbacks(this)
  30. .addOnConnectionFailedListener(this)
  31. .addApi(LocationServices.API)
  32. .build();
  33.  
  34. /*
  35. final GoogleApiClient.Builder mGoogleApiClient = new GoogleApiClient.Builder(this)
  36. .addConnectionCallbacks(this)
  37. .addOnConnectionFailedListener(this)
  38. .addApi(LocationServices.API);
  39. */
  40. Button button = (Button) findViewById(R.id.button);
  41.  
  42. button.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View v)
  45. {
  46. //mGoogleApiClient.build();
  47. }
  48. });
  49. }
  50.  
  51. @Override
  52. public boolean onCreateOptionsMenu(Menu menu) {
  53. // Inflate the menu; this adds items to the action bar if it is present.
  54. getMenuInflater().inflate(R.menu.menu_main, menu);
  55. return true;
  56. }
  57.  
  58. @Override
  59. public boolean onOptionsItemSelected(MenuItem item) {
  60. // Handle action bar item clicks here. The action bar will
  61. // automatically handle clicks on the Home/Up button, so long
  62. // as you specify a parent activity in AndroidManifest.xml.
  63. int id = item.getItemId();
  64.  
  65. //noinspection SimplifiableIfStatement
  66. if (id == R.id.action_settings) {
  67. return true;
  68. }
  69.  
  70. return super.onOptionsItemSelected(item);
  71. }
  72.  
  73. @Override
  74. public void onConnected(Bundle bundle) {
  75.  
  76. Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
  77. mGoogleApiClient);
  78. Log.e("Location", mLastLocation.toString());
  79. }
  80.  
  81. @Override
  82. public void onConnectionSuspended(int i) {
  83.  
  84. }
  85.  
  86. @Override
  87. public void onConnectionFailed(ConnectionResult connectionResult) {
  88. Log.e("connection failed", connectionResult.toString());
  89. }
  90. }
  91. -------------------------------------------------------------------------------------------------------------------------------
  92. <?xml version="1.0" encoding="utf-8"?>
  93. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  94. package="kartik.com.myweather" >
  95.  
  96. <application
  97. android:allowBackup="true"
  98. android:icon="@mipmap/ic_launcher"
  99. android:label="@string/app_name"
  100. android:theme="@style/AppTheme" >
  101. <activity
  102. android:name=".MainActivity"
  103. android:label="@string/app_name" >
  104. <intent-filter>
  105. <action android:name="android.intent.action.MAIN" />
  106.  
  107. <category android:name="android.intent.category.LAUNCHER" />
  108. </intent-filter>
  109. </activity>
  110. </application>
  111. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  112.  
  113. </manifest>
  114.  
  115. -------------------------------------------------------------------------------------------------------------------------------
  116. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  117. xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  118. android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  119. android:paddingRight="@dimen/activity_horizontal_margin"
  120. android:paddingTop="@dimen/activity_vertical_margin"
  121. android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
  122.  
  123. <Button
  124. android:layout_width="wrap_content"
  125. android:layout_height="wrap_content"
  126. android:text="Click"
  127. android:id="@+id/button"
  128. android:layout_centerVertical="true"
  129. android:layout_centerHorizontal="true" />
  130. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement