From 90aa21be1d3113406206cc8261639e388c6870b6 Mon Sep 17 00:00:00 2001 From: Domagalski Date: Sat, 15 Dec 2018 21:35:00 +0100 Subject: [PATCH] Info button on toolbar --- .idea/misc.xml | 2 +- .../findmytutor/activity/BaseActivity.java | 43 +++++++++++++++++++ .../wmi/findmytutor/activity/MapActivity.java | 1 + app/src/main/res/menu/menu_main.xml | 7 +++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index b0c7b20..dc44dda 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java index 5be8ec4..257a4a0 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java @@ -7,6 +7,7 @@ import android.app.FragmentTransaction; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Configuration; +import android.graphics.drawable.ColorDrawable; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; @@ -20,16 +21,20 @@ import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; +import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.PopupWindow; import android.widget.Toast; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; import com.uam.wmi.findmytutor.utils.ActiveFragment; import com.uam.wmi.findmytutor.utils.FeedbackUtils; +import com.uam.wmi.findmytutor.utils.InfoHelperUtils; import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.RxSearchObservable; @@ -76,6 +81,7 @@ public abstract class BaseActivity private ActiveFragment activeFragment = ActiveFragment.NONE; private Fragment activeBottomMenu = null; private SearchView searchView; + public MenuItem infoMenuItem; @SuppressLint("CheckResult") @Override @@ -266,6 +272,8 @@ public abstract class BaseActivity @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); + infoMenuItem = menu.findItem(R.id.action_info); + MenuItem myActionMenuItem = menu.findItem(R.id.action_search); searchView = (SearchView) myActionMenuItem.getActionView(); @@ -313,6 +321,41 @@ public abstract class BaseActivity if (actionBarDrawerToggle.onOptionsItemSelected(item)) { return true; } + + if (item.getItemId()==R.id.action_info){ + + int layoutID; + switch (activeFragment){ + case SHARED_PREFERENCES: + layoutID = R.layout.info_popup_sharing_tab; + break; + case USER_LIST: + layoutID = R.layout.info_popup_userlist; + break; + default: + layoutID = R.layout.info_popup_map; + } + + View popupView = getLayoutInflater().inflate(layoutID,null); + + PopupWindow popupWindow = new PopupWindow(popupView, + LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); + // If the PopupWindow should be focusable + popupWindow.setFocusable(true); + // If you need the PopupWindow to dismiss when when touched outside + popupWindow.setBackgroundDrawable(new ColorDrawable()); + int location[] = new int[2]; + // Get the View's(the one that was clicked in the Fragment) location + View anchorView= getWindow().getDecorView().findViewById(android.R.id.content); + + anchorView.getLocationOnScreen(location); + // Using location, the PopupWindow will be displayed right under anchorView + popupWindow.showAsDropDown(anchorView,0,170,Gravity.RIGHT); +// popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, +// location[0] + anchorView.getWidth() / 2, location[1] + anchorView.getHeight()); + } + + return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index d355d2e..6157e81 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -131,6 +131,7 @@ public class MapActivity extends BaseActivity }; + findViewById(R.id.mapInfoImageButton).setOnClickListener(v-> InfoHelperUtils.infoPopUp(v, R.layout.info_popup_map)); selectLocationButton = findViewById(R.id.select_location_button); removeLocationButton = findViewById(R.id.remove_location_button); diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 9d9f483..96cd955 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -8,4 +8,11 @@ app:showAsAction="always" app:actionViewClass="android.support.v7.widget.SearchView" android:title="@string/search"/> + \ No newline at end of file