|
|
@@ -1,8 +1,10 @@
|
|
|
package com.ivalentin.margolariak;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.math.BigInteger;
|
|
|
import java.security.SecureRandom;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Locale;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.app.Fragment;
|
|
|
@@ -15,7 +17,9 @@ import android.content.SharedPreferences;
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
import android.graphics.Typeface;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
+import android.support.v7.app.AppCompatActivity;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.KeyEvent;
|
|
|
@@ -32,22 +36,79 @@ import android.widget.PopupMenu;
|
|
|
import android.widget.ProgressBar;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
+import android.os.Handler;
|
|
|
+
|
|
|
+import com.google.android.gms.appindexing.Action;
|
|
|
+import com.google.android.gms.appindexing.AppIndex;
|
|
|
+import com.google.android.gms.appindexing.Thing;
|
|
|
+import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
|
|
|
/**
|
|
|
* The main Activity of the app. It's actually the only activity, and it loads other fragments.
|
|
|
- *
|
|
|
- * @author Iñigo Valentin
|
|
|
*
|
|
|
+ * @author Iñigo Valentin
|
|
|
*/
|
|
|
-public class MainActivity extends Activity{
|
|
|
+public class MainActivity extends Activity {
|
|
|
|
|
|
//Alarm to get location and notifications.
|
|
|
- private AlarmReceiver alarm;
|
|
|
+ private AlarmReceiver notificationAlarm;
|
|
|
|
|
|
//The menu entries
|
|
|
- RelativeLayout menuItem[];
|
|
|
- TextView menuText[];
|
|
|
- ImageView menuImage[];
|
|
|
+ private RelativeLayout menuItem[];
|
|
|
+ private TextView menuText[];
|
|
|
+ private ImageView menuImage[];
|
|
|
+
|
|
|
+ //Handler to periodically check for location updates
|
|
|
+ private final Handler locationHandler = new Handler();
|
|
|
+ // Code to check for location updates
|
|
|
+ private final Runnable checkForLocation = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+
|
|
|
+ //Get location page and parse it
|
|
|
+ boolean result = false;
|
|
|
+ FetchURL fu = new FetchURL();
|
|
|
+ //TODO: This needs a simple API too
|
|
|
+ fu.Run(GM.SERVER + "/app/location.php");
|
|
|
+ String lat = "", lon = "";
|
|
|
+ String o = fu.getOutput().toString();
|
|
|
+ Log.d("Location", "Fetched location page");
|
|
|
+ if (o.contains("<location>none</location>"))
|
|
|
+ result = false;
|
|
|
+ if (o.contains("<lat>") && o.contains("<lon>")) {
|
|
|
+ lat = o.substring(o.indexOf("<lat>") + 5, o.indexOf("</lat>"));
|
|
|
+ lon = o.substring(o.indexOf("<lon>") + 5, o.indexOf("</lon>"));
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ SharedPreferences settings = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
|
|
|
+ SharedPreferences.Editor editor = settings.edit();
|
|
|
+ if (result) {
|
|
|
+ editor.putLong(GM.PREF_GM_LATITUDE, Double.doubleToLongBits(Double.parseDouble(lat)));
|
|
|
+ editor.putLong(GM.PREF_GM_LONGITUDE, Double.doubleToLongBits(Double.parseDouble(lon)));
|
|
|
+ editor.putString(GM.PREF_GM_LOCATION, new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(Calendar.getInstance().getTime()));
|
|
|
+
|
|
|
+ //Show menu entry
|
|
|
+ if (menuItem[1] != null) {
|
|
|
+ menuItem[1].setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ editor.putString(GM.PREF_GM_LOCATION, GM.DEFAULT_PREF_GM_LOCATION);
|
|
|
+ if (menuItem[1] != null) {
|
|
|
+ menuItem[1].setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ editor.apply();
|
|
|
+
|
|
|
+ //Repeat this the same runnable code block again another th specified interval
|
|
|
+ locationHandler.postDelayed(checkForLocation, GM.INTERVAL_LOCATION);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
+ * See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
+ */
|
|
|
+ private GoogleApiClient client;
|
|
|
|
|
|
//Not referenced in code.
|
|
|
public void showMenu(View v) {
|
|
|
@@ -55,7 +116,7 @@ public class MainActivity extends Activity{
|
|
|
MenuInflater inflater = popup.getMenuInflater();
|
|
|
inflater.inflate(R.menu.menu, popup.getMenu());
|
|
|
|
|
|
- popup.getMenu().getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
|
|
|
+ popup.getMenu().getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
@Override
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
Intent intent = new Intent(MainActivity.this, AboutActivity.class);
|
|
|
@@ -64,7 +125,7 @@ public class MainActivity extends Activity{
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- popup.getMenu().getItem(1).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
|
|
|
+ popup.getMenu().getItem(1).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
@Override
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
Intent intent = new Intent(MainActivity.this, SponsorActivity.class);
|
|
|
@@ -73,7 +134,7 @@ public class MainActivity extends Activity{
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- popup.getMenu().getItem(2).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener(){
|
|
|
+ popup.getMenu().getItem(2).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
@Override
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
|
|
|
@@ -86,14 +147,12 @@ public class MainActivity extends Activity{
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Loads a section in the main screen.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param section Section identifier {@see GM}
|
|
|
- * @param fromSliderMenu Indicates if the call has been made from the slider menu, so it can be closed.
|
|
|
*/
|
|
|
- public void loadSection (byte section, boolean fromSliderMenu){
|
|
|
+ public void loadSection(byte section) {
|
|
|
FragmentManager fm = MainActivity.this.getFragmentManager();
|
|
|
FragmentTransaction ft = fm.beginTransaction();
|
|
|
Fragment fragment = null;
|
|
|
@@ -101,13 +160,13 @@ public class MainActivity extends Activity{
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
|
//Reset all tabs to it's original state
|
|
|
- for (int i = 0; i < 6; i ++){
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
menuText[i].setTypeface(null, Typeface.NORMAL);
|
|
|
menuImage[i].requestLayout();
|
|
|
menuImage[i].getLayoutParams().height = 2;
|
|
|
}
|
|
|
|
|
|
- switch (section){
|
|
|
+ switch (section) {
|
|
|
case GM.SECTION_HOME:
|
|
|
fragment = new HomeLayout();
|
|
|
title = getString(R.string.menu_home);
|
|
|
@@ -125,10 +184,9 @@ public class MainActivity extends Activity{
|
|
|
case GM.SECTION_LABLANCA:
|
|
|
//Get settings
|
|
|
SharedPreferences preferences = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
|
|
|
- if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 1){
|
|
|
+ if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 1) {
|
|
|
fragment = new LablancaLayout();
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
fragment = new LablancaNoFestivalsLayout();
|
|
|
}
|
|
|
title = getString(R.string.menu_lablanca);
|
|
|
@@ -175,7 +233,7 @@ public class MainActivity extends Activity{
|
|
|
menuImage[5].getLayoutParams().height = 8;
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//Replace the fragment.
|
|
|
ft.replace(R.id.activity_main_content_fragment, fragment);
|
|
|
//ft.addToBackStack(title);
|
|
|
@@ -185,29 +243,28 @@ public class MainActivity extends Activity{
|
|
|
|
|
|
/**
|
|
|
* Sets the title of the current section.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param title The title of the current section.
|
|
|
*/
|
|
|
- public void setSectionTitle(String title){
|
|
|
+ public void setSectionTitle(String title) {
|
|
|
TextView tvTitle = (TextView) findViewById(R.id.activity_main_content_title);
|
|
|
tvTitle.setText(title);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Runs when the activity is created.
|
|
|
- *
|
|
|
+ * Runs when the activity is created.
|
|
|
+ *
|
|
|
* @param savedInstanceState Saved state of the activity.
|
|
|
- *
|
|
|
- * @see android.app.Activity#onCreate(android.os.Bundle)
|
|
|
+ * @see Activity#onCreate(Bundle)
|
|
|
*/
|
|
|
- @SuppressWarnings("deprecation")
|
|
|
+ @SuppressWarnings("deprecation, ConstantConditions")
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
- //Get intent extras
|
|
|
- String action = getIntent().getStringExtra(GM.EXTRA_ACTION);
|
|
|
- String actionText = getIntent().getStringExtra(GM.EXTRA_TEXT);
|
|
|
- String actionTitle = getIntent().getStringExtra(GM.EXTRA_TITLE);
|
|
|
+ //Get intent extras
|
|
|
+ String action = getIntent().getStringExtra(GM.EXTRA_ACTION);
|
|
|
+ String actionText = getIntent().getStringExtra(GM.EXTRA_TEXT);
|
|
|
+ String actionTitle = getIntent().getStringExtra(GM.EXTRA_TITLE);
|
|
|
|
|
|
//Set an alarm for notifications..
|
|
|
//Wait a little
|
|
|
@@ -223,9 +280,9 @@ public class MainActivity extends Activity{
|
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- alarm = new AlarmReceiver();
|
|
|
- alarm.setAlarm(context);
|
|
|
- alarm.onReceive(context, intent);
|
|
|
+ notificationAlarm = new AlarmReceiver();
|
|
|
+ notificationAlarm.setAlarm(context);
|
|
|
+ notificationAlarm.onReceive(context, intent);
|
|
|
}
|
|
|
});
|
|
|
} catch (InterruptedException e) {
|
|
|
@@ -237,10 +294,10 @@ public class MainActivity extends Activity{
|
|
|
t.start();
|
|
|
|
|
|
//Remove title bar.
|
|
|
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
|
- //Set layout.
|
|
|
+ //Set layout.
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
//Assign menu items
|
|
|
@@ -266,335 +323,341 @@ public class MainActivity extends Activity{
|
|
|
menuImage[4] = (ImageView) menuItem[4].findViewById(R.id.iv_menu_blog);
|
|
|
menuImage[5] = (ImageView) menuItem[5].findViewById(R.id.iv_menu_gallery);
|
|
|
|
|
|
- //Remove sscrollbars from the sections menu
|
|
|
+ //Remove scrollbars from the sections menu
|
|
|
HorizontalScrollView svMenu = (HorizontalScrollView) findViewById(R.id.sv_menu);
|
|
|
svMenu.setHorizontalScrollBarEnabled(false);
|
|
|
|
|
|
- //Assign buttons for la blanca submenu
|
|
|
- TextView menuLablancaItem[] = new TextView[2];
|
|
|
- //menuLablancaItem[0] = (TextView) findViewById(R.id.menu_lablanca_schedule);
|
|
|
- //menuLablancaItem[1] = (TextView) findViewById(R.id.menu_lablanca_gm_schedule);
|
|
|
-
|
|
|
//Set click listers for menu items
|
|
|
menuItem[0].setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
- public void onClick(View v) { loadSection(GM.SECTION_HOME, true); }
|
|
|
+ public void onClick(View v) {
|
|
|
+ loadSection(GM.SECTION_HOME);
|
|
|
+ }
|
|
|
});
|
|
|
menuItem[1].setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
- public void onClick(View v) { loadSection(GM.SECTION_LOCATION, true); }
|
|
|
+ public void onClick(View v) {
|
|
|
+ loadSection(GM.SECTION_LOCATION);
|
|
|
+ }
|
|
|
});
|
|
|
menuItem[2].setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
- public void onClick(View v) { loadSection(GM.SECTION_LABLANCA, true); }
|
|
|
+ public void onClick(View v) {
|
|
|
+ loadSection(GM.SECTION_LABLANCA);
|
|
|
+ }
|
|
|
});
|
|
|
menuItem[3].setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
- public void onClick(View v) { loadSection(GM.SECTION_ACTIVITIES, true); }
|
|
|
+ public void onClick(View v) {
|
|
|
+ loadSection(GM.SECTION_ACTIVITIES);
|
|
|
+ }
|
|
|
});
|
|
|
menuItem[4].setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
- public void onClick(View v) { loadSection(GM.SECTION_BLOG, true); }
|
|
|
+ public void onClick(View v) {
|
|
|
+ loadSection(GM.SECTION_BLOG);
|
|
|
+ }
|
|
|
});
|
|
|
menuItem[5].setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
- public void onClick(View v) { loadSection(GM.SECTION_GALLERY, true); }
|
|
|
+ public void onClick(View v) {
|
|
|
+ loadSection(GM.SECTION_GALLERY);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
-
|
|
|
+ //Get preferences
|
|
|
SharedPreferences preferences = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
|
|
|
- if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 1) {
|
|
|
- //Show the entries
|
|
|
- //for (int i = 0; i < 2; i ++){
|
|
|
- // menuLablancaItem[i].setVisibility(View.VISIBLE);
|
|
|
- //}
|
|
|
- }
|
|
|
-// menuLablancaItem[0].setOnClickListener(new OnClickListener() {
|
|
|
-// @Override
|
|
|
-// public void onClick(View v) {
|
|
|
-// loadSection(GM.SECTION_LABLANCA_SCHEDULE, true);
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// menuLablancaItem[1].setOnClickListener(new OnClickListener() {
|
|
|
-// @Override
|
|
|
-// public void onClick(View v) {
|
|
|
-// loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE, true);
|
|
|
-// }
|
|
|
-// });
|
|
|
+ SharedPreferences.Editor editor = preferences.edit();
|
|
|
+
|
|
|
+ //TODO: Read preferences. If there is a recent location, show the menu entry
|
|
|
|
|
|
//If the user code is not set, generate one
|
|
|
- if (preferences.getString(GM.USER_CODE, "").length() == 0){
|
|
|
+ if (preferences.getString(GM.USER_CODE, "").length() == 0) {
|
|
|
SecureRandom random = new SecureRandom();
|
|
|
String newCode = new BigInteger(130, random).toString(32).substring(0, 16);
|
|
|
- SharedPreferences.Editor editor = preferences.edit();
|
|
|
editor.putString(GM.USER_CODE, newCode);
|
|
|
editor.apply();
|
|
|
}
|
|
|
-
|
|
|
- //If the database doesn't exist, create it.
|
|
|
- if (!databaseExists()){
|
|
|
- Log.i("DB status", "Database not found. Creating it...");
|
|
|
- createDatabase();
|
|
|
- }
|
|
|
-
|
|
|
- //If its the first time
|
|
|
- if (preferences.getInt(GM.PREF_DB_VERSION, GM.DEFAULT_PREF_DB_VERSION) == GM.DEFAULT_PREF_DB_VERSION){
|
|
|
+
|
|
|
+ //Cerate database if it's not already created
|
|
|
+ createDatabase();
|
|
|
+
|
|
|
+ //If the database has just been updated, recreate the database
|
|
|
+ if (preferences.getInt(GM.PREF_PREVIOUS_VERSION, 0) < BuildConfig.VERSION_CODE) {
|
|
|
+ Log.d("UPDATE", "App updated from version " + preferences.getInt(GM.PREF_PREVIOUS_VERSION, 0) + " to " + BuildConfig.VERSION_CODE + ". Forcing a new sync...");
|
|
|
+ deleteDatabase();
|
|
|
+ editor.putInt(GM.PREF_PREVIOUS_VERSION, BuildConfig.VERSION_CODE);
|
|
|
+ editor.putInt(GM.PREF_DB_VERSION, 0);
|
|
|
+ editor.apply();
|
|
|
+ createDatabase();
|
|
|
initialSync();
|
|
|
}
|
|
|
- //If t's not the first time
|
|
|
- else{
|
|
|
- //Sync db
|
|
|
- sync();
|
|
|
-
|
|
|
- //Load initial section
|
|
|
- loadSection(GM.SECTION_HOME, false);
|
|
|
-
|
|
|
- //If the intent had extras (from notifications), do something
|
|
|
- if (actionText != null){
|
|
|
- TextView tvDialogTitle, tvDialogText;
|
|
|
- Button btDialogClose, btDialogAction;
|
|
|
- Drawable dialogIcon;
|
|
|
- if (actionTitle != null){
|
|
|
-
|
|
|
- //Create a dialog
|
|
|
- final Dialog dialog = new Dialog(this);
|
|
|
-
|
|
|
- //Set up dialog window
|
|
|
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
- dialog.setContentView(R.layout.dialog_notification);
|
|
|
-
|
|
|
- //Set title
|
|
|
- tvDialogTitle = (TextView) dialog.findViewById(R.id.tv_dialog_notification_title);
|
|
|
- tvDialogTitle.setText(actionTitle);
|
|
|
-
|
|
|
- //Set text
|
|
|
- tvDialogText = (TextView) dialog.findViewById(R.id.tv_dialog_notification_text);
|
|
|
- tvDialogText.setText(actionText);
|
|
|
-
|
|
|
- //Set close button
|
|
|
- btDialogClose = (Button) dialog.findViewById(R.id.bt_dialog_notification_close);
|
|
|
- btDialogClose.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- dialog.dismiss();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //Set the icon
|
|
|
- dialogIcon = getResources().getDrawable(R.drawable.ic_launcher);
|
|
|
- if (dialogIcon != null) {
|
|
|
- dialogIcon.setBounds(0, 0, (int) (tvDialogTitle.getTextSize() * 1.4), (int) (tvDialogTitle.getTextSize() * 1.4));
|
|
|
- }
|
|
|
- tvDialogTitle.setCompoundDrawables(dialogIcon, null, null, null);
|
|
|
- tvDialogTitle.setCompoundDrawablePadding(20);
|
|
|
-
|
|
|
- //Get preferences
|
|
|
- int festivals = preferences.getInt(GM.PREF_DB_FESTIVALS, 0);
|
|
|
-
|
|
|
- //Set the action button
|
|
|
- btDialogAction = (Button) dialog.findViewById(R.id.bt_dialog_notification_action);
|
|
|
- if (action != null){
|
|
|
- switch (action) {
|
|
|
-
|
|
|
- case GM.EXTRA_ACTION_LABLANCA:
|
|
|
-
|
|
|
- //Set up the action button
|
|
|
- btDialogAction.setVisibility(View.VISIBLE);
|
|
|
- btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_lablanca));
|
|
|
- btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- dialog.dismiss();
|
|
|
- loadSection(GM.SECTION_LABLANCA, false);
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
+ else {
|
|
|
|
|
|
- case GM.EXTRA_ACTION_LOCATION:
|
|
|
+ //If its the first time
|
|
|
+ if (preferences.getInt(GM.PREF_DB_VERSION, GM.DEFAULT_PREF_DB_VERSION) == GM.DEFAULT_PREF_DB_VERSION) {
|
|
|
+ initialSync();
|
|
|
+ }
|
|
|
+ //If t's not the first time
|
|
|
+ else {
|
|
|
+ //Sync db
|
|
|
+ sync();
|
|
|
+
|
|
|
+ //Load initial section
|
|
|
+ loadSection(GM.SECTION_HOME);
|
|
|
+
|
|
|
+ //If the intent had extras (from notifications), do something
|
|
|
+ if (actionText != null) {
|
|
|
+ TextView tvDialogTitle, tvDialogText;
|
|
|
+ Button btDialogClose, btDialogAction;
|
|
|
+ Drawable dialogIcon;
|
|
|
+ if (actionTitle != null) {
|
|
|
+
|
|
|
+ //Create a dialog
|
|
|
+ final Dialog dialog = new Dialog(this);
|
|
|
+
|
|
|
+ //Set up dialog window
|
|
|
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
+ dialog.setContentView(R.layout.dialog_notification);
|
|
|
+
|
|
|
+ //Set title
|
|
|
+ tvDialogTitle = (TextView) dialog.findViewById(R.id.tv_dialog_notification_title);
|
|
|
+ tvDialogTitle.setText(actionTitle);
|
|
|
+
|
|
|
+ //Set text
|
|
|
+ tvDialogText = (TextView) dialog.findViewById(R.id.tv_dialog_notification_text);
|
|
|
+ tvDialogText.setText(actionText);
|
|
|
+
|
|
|
+ //Set close button
|
|
|
+ btDialogClose = (Button) dialog.findViewById(R.id.bt_dialog_notification_close);
|
|
|
+ btDialogClose.setOnClickListener(new OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //Set the icon
|
|
|
+ dialogIcon = getResources().getDrawable(R.drawable.ic_launcher);
|
|
|
+ if (dialogIcon != null) {
|
|
|
+ dialogIcon.setBounds(0, 0, (int) (tvDialogTitle.getTextSize() * 1.4), (int) (tvDialogTitle.getTextSize() * 1.4));
|
|
|
+ }
|
|
|
+ tvDialogTitle.setCompoundDrawables(dialogIcon, null, null, null);
|
|
|
+ tvDialogTitle.setCompoundDrawablePadding(20);
|
|
|
|
|
|
- if (preferences.getString(GM.PREF_GM_LOCATION, GM.DEFAULT_PREF_GM_LOCATION).equals(GM.DEFAULT_PREF_GM_LOCATION) == false) {
|
|
|
- //Set up the action button if location is reported
|
|
|
+ //Get preferences
|
|
|
+ int festivals = preferences.getInt(GM.PREF_DB_FESTIVALS, 0);
|
|
|
+
|
|
|
+ //Set the action button
|
|
|
+ btDialogAction = (Button) dialog.findViewById(R.id.bt_dialog_notification_action);
|
|
|
+ if (action != null) {
|
|
|
+ switch (action) {
|
|
|
+
|
|
|
+ case GM.EXTRA_ACTION_LABLANCA:
|
|
|
+
|
|
|
+ //Set up the action button
|
|
|
btDialogAction.setVisibility(View.VISIBLE);
|
|
|
- btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_location));
|
|
|
+ btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_lablanca));
|
|
|
btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
dialog.dismiss();
|
|
|
- loadSection(GM.SECTION_LOCATION, false);
|
|
|
+ loadSection(GM.SECTION_LABLANCA);
|
|
|
}
|
|
|
});
|
|
|
+ break;
|
|
|
+
|
|
|
+ case GM.EXTRA_ACTION_LOCATION:
|
|
|
+
|
|
|
+ if (!preferences.getString(GM.PREF_GM_LOCATION, GM.DEFAULT_PREF_GM_LOCATION).equals(GM.DEFAULT_PREF_GM_LOCATION)) {
|
|
|
+ //Set up the action button if location is reported
|
|
|
+ btDialogAction.setVisibility(View.VISIBLE);
|
|
|
+ btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_location));
|
|
|
+ btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ loadSection(GM.SECTION_LOCATION);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case GM.EXTRA_ACTION_BLOG:
|
|
|
-
|
|
|
- //Set up the action button
|
|
|
- btDialogAction.setVisibility(View.VISIBLE);
|
|
|
- btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_blog));
|
|
|
- btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- dialog.dismiss();
|
|
|
- loadSection(GM.SECTION_BLOG, false);
|
|
|
}
|
|
|
- });
|
|
|
- break;
|
|
|
-
|
|
|
- case GM.EXTRA_ACTION_ACTIVITIES:
|
|
|
-
|
|
|
- //Set up the action button
|
|
|
- btDialogAction.setVisibility(View.VISIBLE);
|
|
|
- btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_activities));
|
|
|
- btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- dialog.dismiss();
|
|
|
- loadSection(GM.SECTION_ACTIVITIES, false);
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
-
|
|
|
- case GM.EXTRA_ACTION_GALLERY:
|
|
|
-
|
|
|
- //Set up the action button
|
|
|
- btDialogAction.setVisibility(View.VISIBLE);
|
|
|
- btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gallery));
|
|
|
- btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- dialog.dismiss();
|
|
|
- loadSection(GM.SECTION_GALLERY, false);
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
+ break;
|
|
|
|
|
|
- case GM.EXTRA_ACTION_GMSCHEDULE:
|
|
|
+ case GM.EXTRA_ACTION_BLOG:
|
|
|
|
|
|
- if (festivals == 1) {
|
|
|
//Set up the action button
|
|
|
btDialogAction.setVisibility(View.VISIBLE);
|
|
|
- btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gmschedule));
|
|
|
+ btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_blog));
|
|
|
btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
dialog.dismiss();
|
|
|
- loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE, false);
|
|
|
+ loadSection(GM.SECTION_BLOG);
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
- break;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case GM.EXTRA_ACTION_ACTIVITIES:
|
|
|
|
|
|
- case GM.EXTRA_ACTION_CITYSCHEDULE:
|
|
|
- if (festivals == 1) {
|
|
|
//Set up the action button
|
|
|
btDialogAction.setVisibility(View.VISIBLE);
|
|
|
- btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_cityschedule));
|
|
|
+ btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_activities));
|
|
|
btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
dialog.dismiss();
|
|
|
- loadSection(GM.SECTION_LABLANCA_SCHEDULE, false);
|
|
|
+ loadSection(GM.SECTION_ACTIVITIES);
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
- break;
|
|
|
+ break;
|
|
|
|
|
|
- //If the notification is just text
|
|
|
- default:
|
|
|
- //Hide action button
|
|
|
- btDialogAction.setVisibility(View.GONE);
|
|
|
+ case GM.EXTRA_ACTION_GALLERY:
|
|
|
+
|
|
|
+ //Set up the action button
|
|
|
+ btDialogAction.setVisibility(View.VISIBLE);
|
|
|
+ btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gallery));
|
|
|
+ btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ loadSection(GM.SECTION_GALLERY);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ case GM.EXTRA_ACTION_GMSCHEDULE:
|
|
|
+
|
|
|
+ if (festivals == 1) {
|
|
|
+ //Set up the action button
|
|
|
+ btDialogAction.setVisibility(View.VISIBLE);
|
|
|
+ btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gmschedule));
|
|
|
+ btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case GM.EXTRA_ACTION_CITYSCHEDULE:
|
|
|
+ if (festivals == 1) {
|
|
|
+ //Set up the action button
|
|
|
+ btDialogAction.setVisibility(View.VISIBLE);
|
|
|
+ btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_cityschedule));
|
|
|
+ btDialogAction.setOnClickListener(new OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ loadSection(GM.SECTION_LABLANCA_SCHEDULE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ //If the notification is just text
|
|
|
+ default:
|
|
|
+ //Hide action button
|
|
|
+ btDialogAction.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ btDialogAction.setVisibility(View.GONE);
|
|
|
}
|
|
|
- }
|
|
|
- else{
|
|
|
- btDialogAction.setVisibility(View.GONE);
|
|
|
- }
|
|
|
|
|
|
- //Set dialog parameters
|
|
|
- WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
|
|
- lp.copyFrom(dialog.getWindow().getAttributes());
|
|
|
- lp.width = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
- lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
- lp.gravity = Gravity.CENTER;
|
|
|
- lp.dimAmount = 0.4f;
|
|
|
- dialog.getWindow().setAttributes(lp);
|
|
|
-
|
|
|
- //Show dialog
|
|
|
- dialog.show();
|
|
|
+ //Set dialog parameters
|
|
|
+ WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
|
|
+ lp.copyFrom(dialog.getWindow().getAttributes());
|
|
|
+ lp.width = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
+ lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
+ lp.gravity = Gravity.CENTER;
|
|
|
+ lp.dimAmount = 0.4f;
|
|
|
+ dialog.getWindow().setAttributes(lp);
|
|
|
+
|
|
|
+ //Show dialog
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
+ client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Checks if the app database exists.
|
|
|
- *
|
|
|
- * @return True if the database exists, false otherwise.
|
|
|
+ * Creates the app database and fills it with the hard coded, default data.
|
|
|
*/
|
|
|
- private boolean databaseExists(){
|
|
|
- File database = getApplicationContext().getDatabasePath(GM.DB_NAME);
|
|
|
- return database.exists();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Creates the app database and fills it with the hard coded, default data.
|
|
|
- */
|
|
|
- private void createDatabase(){
|
|
|
- SQLiteDatabase db;
|
|
|
- try {
|
|
|
- //Create database
|
|
|
- db = openOrCreateDatabase(GM.DB_NAME, Activity.MODE_PRIVATE, null);
|
|
|
-
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS activity (id INT, permalink VARCHAR, date DATETIME, city VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, after_es VARCHAR, after_en VARCHAR, after_eu VARCHAR, price INT, inscription INT, max_people INT, album INT, dtime DATETIME, comments INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS activity_comment (id INT, activity INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS activity_image (id INT, activity INT, image VARCHAR, idx INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS activity_itinerary (id INT, activity INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, start DATETIME, end DATETIME, place INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS activity_tag (activity INT, tag VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS album (id INT, permalink VARCHAR, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, open INT, time DATETIME);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS festival (id INT, year INT, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, img VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS festival_day (id INT, date DATETIME, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, price INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS festival_event (id INT, gm INT, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, host INT, place INT, start DATETIME, end DATETIME);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS festival_event_image (id INT, event INT, image VARCHAR, idx INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS festival_offer (id INT, year INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, days INT, price INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS location (id INT, dtime DATETIME, lat FLOAT, lon FLOAT, manual INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS notification (id INT, dtime DATETIME, duration INT, action VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, internal INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS people (id INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, link VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS photo (id INT, file VARCHAR, permalink VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, dtime DATETIME, uploaded DATETIME, place INT, width INT, height INT, size INT, username VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS photo_album (photo INT, album INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS photo_comment (id INT, photo INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS place (id INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, address_es VARCHAR, address_en VARCHAR, address_eu VARCHAR, cp VARCHAR, lat FLOAT, lon FLOAT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS post (id INT, permalink VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, dtime DATETIME, comments INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS post_comment (id INT, post INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS post_image (id INT, post INT, image VARCHAR, idx INT);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS post_tag (post INT, tag VARCHAR);");
|
|
|
- db.execSQL("CREATE TABLE IF NOT EXISTS settings (name VARCHAR, value VARCHAR);");
|
|
|
+ private void createDatabase() {
|
|
|
+ SQLiteDatabase db;
|
|
|
+ try {
|
|
|
+ //Create database
|
|
|
+ db = openOrCreateDatabase(GM.DB_NAME, Activity.MODE_PRIVATE, null);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.ACTIVITY);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.ACTIVITY_COMMENT);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.ACTIVITY_IMAGE);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.ACTIVITY_ITINERARY);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.ACTIVITY_TAG);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.ALBUM);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.FESTIVAL);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.FESTIVAL_DAY);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.FESTIVAL_EVENT);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.FESTIVAL_EVENT_IMAGE);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.FESTIVAL_OFFER);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.LOCATION);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.NOTIFICATION);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.PEOPLE);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.PHOTO);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.PHOTO_ALBUM);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.PHOTO_COMMENT);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.PLACE);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.POST);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.POST_COMMENT);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.POST_IMAGE);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.POST_TAG);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.SETTINGS);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.SPONSOR);
|
|
|
+ db.execSQL(GM.DB.QUERY.CREATE.VERSION);
|
|
|
db.close();
|
|
|
- }
|
|
|
- catch (Exception ex){
|
|
|
- Log.e("Error creating database", ex.toString());
|
|
|
- }
|
|
|
- }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ Log.e("Error creating database", ex.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates the app database and fills it with the hard coded, default data.
|
|
|
+ */
|
|
|
+ private void deleteDatabase() {
|
|
|
+ SQLiteDatabase db;
|
|
|
+ try {
|
|
|
+ deleteDatabase(GM.DB_NAME);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ Log.e("Error deleting database", ex.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Performs a full sync against the remote database.
|
|
|
*/
|
|
|
- private void sync(){
|
|
|
+ private void sync() {
|
|
|
ProgressBar pbSync = (ProgressBar) findViewById(R.id.pb_sync);
|
|
|
ImageView ivSync = (ImageView) findViewById(R.id.iv_logo);
|
|
|
new Sync(this, pbSync, ivSync).execute();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Perform an initial sync before the app can be used.
|
|
|
- * A dialog will block the UI.
|
|
|
+ * Perform an initial sync before the app can be used.
|
|
|
+ * A dialog will block the UI.
|
|
|
* It is intended to be used only when the database is empty.
|
|
|
*/
|
|
|
- private void initialSync(){
|
|
|
+ @SuppressWarnings("ConstantConditions")
|
|
|
+ private void initialSync() {
|
|
|
//Create a dialog
|
|
|
Dialog dialog = new Dialog(this);
|
|
|
dialog.setCancelable(false);
|
|
|
-
|
|
|
+
|
|
|
//Set up the window
|
|
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
dialog.setContentView(R.layout.dialog_sync);
|
|
|
@@ -607,21 +670,21 @@ public class MainActivity extends Activity{
|
|
|
lp.gravity = Gravity.CENTER;
|
|
|
lp.dimAmount = 0.4f;
|
|
|
dialog.getWindow().setAttributes(lp);
|
|
|
-
|
|
|
+
|
|
|
//Sync
|
|
|
ProgressBar pbSync = (ProgressBar) findViewById(R.id.pb_sync);
|
|
|
ImageView ivSync = (ImageView) findViewById(R.id.iv_logo);
|
|
|
new Sync(this, pbSync, ivSync, dialog, this).execute();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Overrides onBackPressed().
|
|
|
+ * Overrides onBackPressed().
|
|
|
* Used to show the previous fragment instead of finishing the app.
|
|
|
- *
|
|
|
- * @see android.support.v7.app.AppCompatActivity#onBackPressed()
|
|
|
+ *
|
|
|
+ * @see AppCompatActivity#onBackPressed()
|
|
|
*/
|
|
|
@Override
|
|
|
- public void onBackPressed(){
|
|
|
+ public void onBackPressed() {
|
|
|
try {
|
|
|
FragmentManager fm = getFragmentManager();
|
|
|
if (fm.getBackStackEntryCount() > 1) {
|
|
|
@@ -630,20 +693,21 @@ public class MainActivity extends Activity{
|
|
|
finish();
|
|
|
super.onBackPressed();
|
|
|
}
|
|
|
- }
|
|
|
- catch (Exception ex){
|
|
|
+ } catch (Exception ex) {
|
|
|
Log.e("Error going back", "Finishing activity: " + ex.toString());
|
|
|
+ Log.e("RUNNABLE", "Finishing callback for location");
|
|
|
+ locationHandler.removeCallbacks(checkForLocation);
|
|
|
finish();
|
|
|
//super.onBackPressed();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Overrides onKeyUp().
|
|
|
* Used to toggle the menu whent the key is pressed.
|
|
|
*
|
|
|
- * @see android.app.Activity#onKeyUp(int, KeyEvent)
|
|
|
+ * @see Activity#onKeyUp(int, KeyEvent)
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
@@ -653,5 +717,58 @@ public class MainActivity extends Activity{
|
|
|
}
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ locationHandler.post(checkForLocation);
|
|
|
+ super.onResume();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPause() {
|
|
|
+ locationHandler.removeCallbacks(checkForLocation);
|
|
|
+ super.onPause();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ locationHandler.removeCallbacks(checkForLocation);
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
+ * See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
+ */
|
|
|
+ public Action getIndexApiAction() {
|
|
|
+ Thing object = new Thing.Builder()
|
|
|
+ .setName("Main Page") // TODO: Define a title for the content shown.
|
|
|
+ // TODO: Make sure this auto-generated URL is correct.
|
|
|
+ .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
|
|
|
+ .build();
|
|
|
+ return new Action.Builder(Action.TYPE_VIEW)
|
|
|
+ .setObject(object)
|
|
|
+ .setActionStatus(Action.STATUS_TYPE_COMPLETED)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStart() {
|
|
|
+ super.onStart();
|
|
|
+
|
|
|
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
+ client.connect();
|
|
|
+ AppIndex.AppIndexApi.start(client, getIndexApiAction());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStop() {
|
|
|
+ super.onStop();
|
|
|
+
|
|
|
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
|
|
|
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
|
|
|
+ AppIndex.AppIndexApi.end(client, getIndexApiAction());
|
|
|
+ client.disconnect();
|
|
|
+ }
|
|
|
}
|