Java tutorial
package townley.stuart.app.android.trekkinly; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.AlphaAnimation; import android.widget.ImageButton; import android.widget.TextView; /** * Copyright 2015 Stuart Lachlan Townley Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ public class DisplayGPS extends Fragment { GPS_Data gps_data; DataBaseHelper db; public static DisplayGPS newInstance() { DisplayGPS displayWeather = new DisplayGPS(); return displayWeather; } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.gps_layout, container, false); gps_data = new GPS_Data(getActivity()); db = new DataBaseHelper(getActivity()); db.getWritableDatabase(); db.getGPS(gps_data); db.upDateDataBaseGPS(gps_data); final TextView textView_lat = (TextView) rootView.findViewById(R.id.gps_latitude_data); final TextView textView_long = (TextView) rootView.findViewById(R.id.gps_longitude_data); String latitude = db.rowone; String longitude = db.rowtwo; if (latitude == null && longitude == null) { textView_lat.setText("No information is present"); textView_long.setText("No information is present"); } else { textView_lat.setText("" + latitude); textView_long.setText("" + longitude); } final ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.refresh_gps); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f); animation1.setDuration(500); imageButton.startAnimation(animation1); if (gps_data.locationObtainable()) { db.addGPS(gps_data); db.getGPS(gps_data); db.upDateDataBaseGPS(gps_data); textView_lat.setText("" + db.rowone); textView_long.setText("" + db.rowtwo); Log.w("GPS DATA Latitude is", "" + gps_data.lat); Log.w("GPS DATA Longitude is", "" + gps_data.longi); gps_data.stopUsingGPS(); } else { gps_data.SettingsAlertDialog(); } } }); return rootView; } @Override public void onAttach(Activity activity) { super.onAttach(activity); ((MainActivityTrekkly) activity).onSectionAttached(10); MainActivityTrekkly mA = ((MainActivityTrekkly) getActivity()); mA.restoreActionBar(Color.parseColor("#68228B")); } }