|
package am.xtech.nasaspaceapps; |
|
|
|
import android.animation.ObjectAnimator; |
|
import android.app.AlertDialog; |
|
import android.content.Context; |
|
import android.content.DialogInterface; |
|
import android.content.Intent; |
|
import android.content.SharedPreferences; |
|
import android.content.pm.PackageManager; |
|
import android.content.res.Resources; |
|
import android.database.Cursor; |
|
import android.graphics.Bitmap; |
|
import android.graphics.Color; |
|
import android.graphics.Point; |
|
import android.location.Location; |
|
import android.net.Uri; |
|
import android.os.AsyncTask; |
|
import android.os.Handler; |
|
import android.provider.MediaStore; |
|
import android.provider.Settings; |
|
import android.support.v4.app.ActivityCompat; |
|
import android.support.v4.app.FragmentActivity; |
|
import android.support.v4.content.ContextCompat; |
|
import android.support.v4.content.FileProvider; |
|
import android.support.v4.os.ResultReceiver; |
|
import android.support.v7.app.AppCompatActivity; |
|
import android.os.Bundle; |
|
import android.util.Log; |
|
import android.view.Display; |
|
import android.view.MotionEvent; |
|
import android.view.View; |
|
import android.view.ViewGroup; |
|
import android.view.ViewTreeObserver; |
|
import android.view.animation.Animation; |
|
import android.view.animation.AnimationSet; |
|
import android.view.animation.RotateAnimation; |
|
import android.view.animation.TranslateAnimation; |
|
import android.view.inputmethod.InputMethodManager; |
|
import android.widget.Button; |
|
import android.widget.EditText; |
|
import android.widget.ImageButton; |
|
import android.widget.ImageView; |
|
import android.widget.LinearLayout; |
|
import android.widget.RelativeLayout; |
|
import android.widget.TextView; |
|
import android.widget.Toast; |
|
import android.widget.VideoView; |
|
|
|
import am.xtech.nasaspaceapps.Models.FireAddResponse; |
|
import am.xtech.nasaspaceapps.Models.FireModel; |
|
import am.xtech.nasaspaceapps.Models.GetFiresResponse; |
|
import am.xtech.nasaspaceapps.Models.NasaFireModel; |
|
import am.xtech.nasaspaceapps.Services.FetchAddressIntentService; |
|
import am.xtech.nasaspaceapps.Utils.AppUtils; |
|
import am.xtech.nasaspaceapps.Utils.Constants; |
|
import am.xtech.nasaspaceapps.Utils.ImagePickerComment; |
|
import am.xtech.nasaspaceapps.Utils.Methods; |
|
import am.xtech.nasaspaceapps.Utils.VideoPicker; |
|
import am.xtech.nasaspaceapps.Utils.WebServiceClient; |
|
|
|
import com.facebook.CallbackManager; |
|
import com.facebook.FacebookCallback; |
|
import com.facebook.FacebookException; |
|
import com.facebook.share.Sharer; |
|
import com.facebook.share.internal.ShareFeedContent; |
|
import com.facebook.share.model.ShareContent; |
|
import com.facebook.share.model.ShareLinkContent; |
|
import com.facebook.share.model.SharePhoto; |
|
import com.facebook.share.model.SharePhotoContent; |
|
import com.facebook.share.model.ShareVideo; |
|
import com.facebook.share.model.ShareVideoContent; |
|
import com.facebook.share.widget.ShareDialog; |
|
import com.google.android.gms.common.ConnectionResult; |
|
import com.google.android.gms.common.GoogleApiAvailability; |
|
import com.google.android.gms.common.GooglePlayServicesNotAvailableException; |
|
import com.google.android.gms.common.GooglePlayServicesRepairableException; |
|
import com.google.android.gms.common.GooglePlayServicesUtil; |
|
import com.google.android.gms.common.api.GoogleApiClient; |
|
import com.google.android.gms.common.api.Status; |
|
import com.google.android.gms.location.LocationRequest; |
|
import com.google.android.gms.location.LocationServices; |
|
import com.google.android.gms.location.places.Place; |
|
import com.google.android.gms.location.places.ui.PlaceAutocomplete; |
|
import com.google.android.gms.maps.CameraUpdateFactory; |
|
import com.google.android.gms.maps.GoogleMap; |
|
import com.google.android.gms.maps.OnMapReadyCallback; |
|
import com.google.android.gms.maps.SupportMapFragment; |
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory; |
|
import com.google.android.gms.maps.model.CameraPosition; |
|
import com.google.android.gms.maps.model.LatLng; |
|
import com.google.android.gms.maps.model.LatLngBounds; |
|
import com.google.android.gms.maps.model.MapStyleOptions; |
|
import com.google.android.gms.maps.model.Marker; |
|
import com.google.android.gms.maps.model.MarkerOptions; |
|
import com.google.android.gms.maps.model.PolygonOptions; |
|
import com.google.android.gms.maps.model.StreetViewPanoramaCamera; |
|
|
|
import java.io.BufferedOutputStream; |
|
import java.io.BufferedReader; |
|
import java.io.ByteArrayInputStream; |
|
import java.io.ByteArrayOutputStream; |
|
import java.io.File; |
|
import java.io.FileInputStream; |
|
import java.io.FileNotFoundException; |
|
import java.io.FileOutputStream; |
|
import java.io.IOException; |
|
import java.io.InputStream; |
|
import java.io.InputStreamReader; |
|
import java.net.URL; |
|
import java.util.ArrayList; |
|
import java.util.Calendar; |
|
import java.util.Date; |
|
import java.util.GregorianCalendar; |
|
import java.util.HashMap; |
|
import java.util.List; |
|
|
|
import static android.content.ContentValues.TAG; |
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener { |
|
|
|
private SharedPreferences preferences; |
|
private GoogleMap mMap; |
|
private RelativeLayout takePhotoButton; |
|
private RelativeLayout loading_content; |
|
private RelativeLayout videoContentMain; |
|
private int width, height; |
|
private GoogleApiClient mGoogleApiClient; |
|
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000; |
|
private static final int REQUEST_CODE_AUTOCOMPLETE = 1; |
|
|
|
private AddressResultReceiver mResultReceiver; |
|
|
|
private TextView addressTextView; |
|
private LinearLayout shareFireContent; |
|
private LinearLayout logoutButton; |
|
private ImageButton nasaButton; |
|
private boolean nasaIsActive = false; |
|
private ImageButton rocketButton; |
|
private ImageButton weatherButton; |
|
private ImageButton fbShareButton; |
|
private ImageButton playVideoButton; |
|
private ImageButton camerActionButton; |
|
private ImageButton videoActionButton; |
|
private ImageView captureddImageView; |
|
private RelativeLayout closePopUpButton; |
|
private RelativeLayout actionContent; |
|
private RelativeLayout touch_content; |
|
private ImageButton socaialSharingButton; |
|
private EditText descriptionEditText; |
|
private VideoView videoView; |
|
|
|
private SharedPreferences sharedpreferences; |
|
|
|
private Uri sharingFile; |
|
|
|
boolean activeChangeMap = true; |
|
private double mLat, mLong; |
|
private String descriptionForUpload; |
|
private Bitmap shareBitmap; |
|
|
|
private boolean isVideo = false; |
|
private String uploadAddress; |
|
|
|
@Override |
|
protected void onCreate(Bundle savedInstanceState) { |
|
super.onCreate(savedInstanceState); |
|
setContentView(R.layout.activity_main); |
|
sharedpreferences = getSharedPreferences(Constants.My_PREFERENCES, Context.MODE_PRIVATE); |
|
SupportMapFragment fragment; |
|
fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); |
|
fragment.getMapAsync(this); |
|
Display display = getWindowManager().getDefaultDisplay(); |
|
Point size = new Point(); |
|
display.getSize(size); |
|
width = size.x; |
|
height = size.y; |
|
|
|
Methods.checkAndRequestPermissions(MainActivity.this); |
|
|
|
preferences = getSharedPreferences(Constants.APP_NAME, MODE_PRIVATE); |
|
|
|
prepareViews(); |
|
measureViews(); |
|
setClicks(); |
|
setupLocationResultReceiver(); |
|
setupShareDialog(); |
|
} |
|
|
|
private void setupRocketAnimation() |
|
{ |
|
AnimationSet snowMov1 = new AnimationSet(true); |
|
RotateAnimation rotate1 = new RotateAnimation(0,-45, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f ); |
|
rotate1.setDuration(300); |
|
snowMov1.addAnimation(rotate1); |
|
TranslateAnimation trans1 = new TranslateAnimation( |
|
Animation.RELATIVE_TO_PARENT, 0.0f, |
|
Animation.RELATIVE_TO_PARENT, 0.0f, |
|
Animation.RELATIVE_TO_PARENT, 0.0f, |
|
Animation.RELATIVE_TO_PARENT, -1.5f);; |
|
trans1.setFillEnabled(true); |
|
trans1.setFillAfter(true); |
|
trans1.setDuration(700); |
|
snowMov1.addAnimation(trans1); |
|
rocketButton.setAnimation(snowMov1); |
|
new Handler().postDelayed(new Runnable() { |
|
@Override |
|
public void run() { |
|
rocketButton.setVisibility(View.GONE); |
|
loading_content.setVisibility(View.VISIBLE); |
|
descriptionForUpload = descriptionEditText.getText().toString(); |
|
uploadAddress = addressTextView.getText().toString(); |
|
new AsyncAddFire().execute(); |
|
} |
|
}, 800); |
|
} |
|
|
|
@Override |
|
public void onBackPressed() { |
|
if(popIsOpen) |
|
pinPopupCloseAnimation(); |
|
else |
|
super.onBackPressed(); |
|
} |
|
|
|
private void measureViews() { |
|
ViewTreeObserver vto = shareFireContent.getViewTreeObserver(); |
|
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { |
|
public void onGlobalLayout() { |
|
RelativeLayout.LayoutParams rllpPinPopup = (RelativeLayout.LayoutParams) shareFireContent.getLayoutParams(); |
|
rllpPinPopup.bottomMargin = -shareFireContent.getMeasuredHeight(); // use topmargin for the y-property, left margin for the x-property of your view |
|
shareFireContent.setLayoutParams(rllpPinPopup); |
|
} |
|
}); |
|
ViewTreeObserver vto1 = actionContent.getViewTreeObserver(); |
|
vto1.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { |
|
public void onGlobalLayout() { |
|
RelativeLayout.LayoutParams rllpPinPopup = (RelativeLayout.LayoutParams) actionContent.getLayoutParams(); |
|
rllpPinPopup.bottomMargin = -actionContent.getMeasuredHeight(); // use topmargin for the y-property, left margin for the x-property of your view |
|
actionContent.setLayoutParams(rllpPinPopup); |
|
} |
|
}); |
|
} |
|
boolean popIsOpen = false; |
|
public void pinPopupOpenAnimation() { |
|
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(shareFireContent, "translationY", 0, -shareFireContent.getMeasuredHeight()); |
|
objectAnimator.setDuration(500); |
|
objectAnimator.start(); |
|
popIsOpen = true; |
|
rocketButton.setVisibility(View.VISIBLE); |
|
} |
|
|
|
public void pinPopupCloseAnimation() { |
|
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(shareFireContent, "translationY", -shareFireContent.getMeasuredHeight(), 0); |
|
objectAnimator.setDuration(500); |
|
objectAnimator.start(); |
|
popIsOpen = false; |
|
} rocketButton.setVisibility(View.GONE); |
|
descriptionEditText.setText(""); |
|
} |
|
boolean popActionsIsOpen = false; |
|
public void actionsPopupOpenAnimation() { |
|
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(actionContent, "translationY", 0, -actionContent.getMeasuredHeight()); |
|
objectAnimator.setDuration(200); |
|
objectAnimator.start(); |
|
popActionsIsOpen = true; |
|
touch_content.setVisibility(View.VISIBLE); |
|
|
|
} |
|
|
|
public void actionsPopupCloseAnimation() { |
|
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(actionContent, "translationY", -actionContent.getMeasuredHeight(), 0); |
|
objectAnimator.setDuration(200); |
|
objectAnimator.start(); |
|
popActionsIsOpen = false; |
|
touch_content.setVisibility(View.GONE); |
|
} |
|
private void prepareViews() { |
|
takePhotoButton = (RelativeLayout) findViewById(R.id.takePhotoButton); |
|
loading_content = (RelativeLayout) findViewById(R.id.loading_content); |
|
videoContentMain = (RelativeLayout) findViewById(R.id.videoContentMain); |
|
touch_content = (RelativeLayout) findViewById(R.id.touch_content); |
|
actionContent = (RelativeLayout) findViewById(R.id.actionContent); |
|
addressTextView = (TextView) findViewById(R.id.addressTextView); |
|
nasaButton = (ImageButton) findViewById(R.id.nasaButton); |
|
rocketButton = (ImageButton) findViewById(R.id.rocketButton); |
|
weatherButton = (ImageButton) findViewById(R.id.weatherButton); |
|
fbShareButton = (ImageButton) findViewById(R.id.fbShareButton); |
|
camerActionButton = (ImageButton) findViewById(R.id.camerActionButton); |
|
videoActionButton = (ImageButton) findViewById(R.id.videoActionButton); |
|
socaialSharingButton = (ImageButton) findViewById(R.id.socaialSharingButton); |
|
shareFireContent = (LinearLayout) findViewById(R.id.shareFireContent); |
|
logoutButton = (LinearLayout) findViewById(R.id.logoutButton); |
|
captureddImageView = (ImageView) findViewById(R.id.captureddImageView); |
|
closePopUpButton = (RelativeLayout) findViewById(R.id.closePopUpButton); |
|
descriptionEditText = (EditText) findViewById(R.id.descriptionEditText); |
|
videoView = (VideoView) findViewById(R.id.videoView); |
|
playVideoButton = (ImageButton) findViewById(R.id.playVideoButton); |
|
} |