mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Don't show icon in ActionBar overflow
This commit is contained in:
		
							parent
							
								
									b51f36849e
								
							
						
					
					
						commit
						c81fb02ffc
					
				
					 1 changed files with 0 additions and 55 deletions
				
			
		|  | @ -6,16 +6,11 @@ import android.content.Context; | |||
| import android.content.Intent; | ||||
| import android.content.SharedPreferences; | ||||
| import android.content.pm.PackageManager; | ||||
| import android.content.res.Resources; | ||||
| import android.content.res.TypedArray; | ||||
| import android.os.Build; | ||||
| import android.os.Bundle; | ||||
| import android.support.v4.app.Fragment; | ||||
| import android.support.v4.content.ContextCompat; | ||||
| import android.util.DisplayMetrics; | ||||
| import android.util.Log; | ||||
| import android.util.TypedValue; | ||||
| import android.view.Display; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuInflater; | ||||
|  | @ -28,8 +23,6 @@ import android.widget.ListAdapter; | |||
| import android.widget.TextView; | ||||
| import android.widget.Toast; | ||||
| 
 | ||||
| import java.lang.reflect.Method; | ||||
| 
 | ||||
| import butterknife.BindView; | ||||
| import butterknife.ButterKnife; | ||||
| import fr.free.nrw.commons.AboutActivity; | ||||
|  | @ -39,7 +32,6 @@ import fr.free.nrw.commons.SettingsActivity; | |||
| import fr.free.nrw.commons.nearby.NearbyActivity; | ||||
| 
 | ||||
| import static android.app.Activity.RESULT_OK; | ||||
| import static android.content.Context.LOCATION_SERVICE; | ||||
| 
 | ||||
| public class ContributionsListFragment extends Fragment { | ||||
| 
 | ||||
|  | @ -213,53 +205,6 @@ public class ContributionsListFragment extends Fragment { | |||
|         menu.findItem(R.id.menu_refresh).setVisible(false); | ||||
|     } | ||||
| 
 | ||||
|     /*http://stackoverflow.com/questions/30076392/how-does-this-strange-condition-happens-when-show-menu-item-icon-in-toolbar-over/30337653#30337653 | ||||
|     Overriden to show toggle_layout button on overlay menu | ||||
|     */ | ||||
|     @Override | ||||
|     public void onPrepareOptionsMenu(Menu menu) { | ||||
|         if(menu != null){ | ||||
|             if(menu.getClass().getSimpleName().equals("MenuBuilder")){ | ||||
|                 try{ | ||||
|                     Method m = menu.getClass().getDeclaredMethod( | ||||
|                             "setOptionalIconsVisible", Boolean.TYPE); | ||||
|                     m.setAccessible(true); | ||||
|                     m.invoke(menu, true); | ||||
|                 } | ||||
|                 catch(NoSuchMethodException e){ | ||||
|                     Log.e(TAG, "onMenuOpened", e); | ||||
|                 } | ||||
|                 catch(Exception e){ | ||||
|                     throw new RuntimeException(e); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             MenuItem galleryMenu = menu.findItem(R.id.menu_from_gallery); | ||||
| 
 | ||||
|             // Get background resource id to recognize current themes | ||||
|             TypedArray typedArray = getActivity().getTheme().obtainStyledAttributes(new int[] {R.attr.mainBackground}); | ||||
|             int galleryIconResourceId = typedArray.getResourceId(0, 0); | ||||
|             typedArray.recycle(); | ||||
| 
 | ||||
|             // Get width in dp http://stackoverflow.com/questions/11999260/check-if-menuitem-is-in-actionbar-overflow | ||||
|             DisplayMetrics metrics = new DisplayMetrics(); | ||||
|             Display display = getActivity().getWindowManager().getDefaultDisplay(); | ||||
|             display.getMetrics(metrics); | ||||
|             float logicalDensity = metrics.density; | ||||
|             int dp = (int) (metrics.widthPixels / logicalDensity + 0.5); | ||||
| 
 | ||||
|             if(dp < 360) { // only two icons, there is no room | ||||
|                 if(galleryIconResourceId==getActivity().obtainStyledAttributes(R.style.LightAppTheme, new int[] {R.attr.mainBackground}).getResourceId(0, 0)){ | ||||
|                     galleryMenu.setIcon(R.drawable.ic_photo_black_24dp); //If theme is light, display dark icon on overlay menu | ||||
|                 }else{ | ||||
|                     galleryMenu.setIcon(R.drawable.ic_photo_white_24dp); //If theme is dark, display light icon on overlay menu | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         super.onPrepareOptionsMenu(menu); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 veyndan
						veyndan