Makes the profile picture icon in toolbar clickable to open menu
This commit is contained in:
parent
dea2993005
commit
45b6478b20
|
@ -40,6 +40,7 @@ import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -107,7 +108,6 @@ import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeHamburgerIcon;
|
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
|
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
|
||||||
|
@ -353,7 +353,6 @@ public class MainActivity extends AppCompatActivity
|
||||||
toolbarTitle.setOnClickListener(new View.OnClickListener() {
|
toolbarTitle.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
if( navigationView.getMenu().findItem(R.id.nav_favorites) != null && navigationView.getMenu().findItem(R.id.nav_favorites).isChecked()){
|
if( navigationView.getMenu().findItem(R.id.nav_favorites) != null && navigationView.getMenu().findItem(R.id.nav_favorites).isChecked()){
|
||||||
DisplayStatusFragment faveFrag = (DisplayStatusFragment) fragmentManager.findFragmentByTag("FAVOURITES");
|
DisplayStatusFragment faveFrag = (DisplayStatusFragment) fragmentManager.findFragmentByTag("FAVOURITES");
|
||||||
if (faveFrag != null && faveFrag.isVisible()) {
|
if (faveFrag != null && faveFrag.isVisible()) {
|
||||||
|
@ -502,10 +501,15 @@ public class MainActivity extends AppCompatActivity
|
||||||
registerForContextMenu(drawer);
|
registerForContextMenu(drawer);
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||||
drawer.addDrawerListener(toggle);
|
|
||||||
toggle.setDrawerIndicatorEnabled(false);
|
toggle.setDrawerIndicatorEnabled(false);
|
||||||
changeHamburgerIcon(MainActivity.this, account.getAvatar());
|
ImageView iconbar = (ImageView) toolbar.findViewById(R.id.iconbar);
|
||||||
toggle.syncState();
|
iconbar.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
drawer.openDrawer(Gravity.START);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Helper.loadPictureIcon(MainActivity.this, account.getAvatar(),iconbar);
|
||||||
headerLayout = navigationView.getHeaderView(0);
|
headerLayout = navigationView.getHeaderView(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -980,7 +980,7 @@ public class Helper {
|
||||||
* @param activity Activity The current activity
|
* @param activity Activity The current activity
|
||||||
* @param url String the url of the profile picture
|
* @param url String the url of the profile picture
|
||||||
*/
|
*/
|
||||||
public static void changeHamburgerIcon(final Activity activity, String url){
|
public static void loadPictureIcon(final Activity activity, String url, final ImageView imageView){
|
||||||
ImageLoader imageLoader;
|
ImageLoader imageLoader;
|
||||||
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
||||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||||
|
@ -989,14 +989,13 @@ public class Helper {
|
||||||
url = "https://" + Helper.getLiveInstance(activity) + url;
|
url = "https://" + Helper.getLiveInstance(activity) + url;
|
||||||
}
|
}
|
||||||
imageLoader.loadImage(url, options, new SimpleImageLoadingListener(){
|
imageLoader.loadImage(url, options, new SimpleImageLoadingListener(){
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
super.onLoadingComplete(imageUri, view, loadedImage);
|
||||||
Resources res = activity.getResources();
|
Resources res = activity.getResources();
|
||||||
Bitmap loadedImageResized = Bitmap.createScaledBitmap(loadedImage, (int)convertDpToPixel(40, activity), (int)convertDpToPixel(40, activity), true);
|
BitmapDrawable icon = new BitmapDrawable(res, getRoundedCornerBitmap(loadedImage, 150));
|
||||||
BitmapDrawable icon = new BitmapDrawable(res, getRoundedCornerBitmap(loadedImageResized, 90));
|
imageView.setImageDrawable(icon);
|
||||||
if( ((MainActivity)activity).getSupportActionBar() != null)
|
|
||||||
((MainActivity)activity).getSupportActionBar().setIcon(icon);
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){
|
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){
|
||||||
|
@ -1004,44 +1003,6 @@ public class Helper {
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the profile picture in the current action bar
|
|
||||||
* @param activity Activity The current activity
|
|
||||||
* @param url String the url of the profile picture
|
|
||||||
*/
|
|
||||||
public static void loadPPInActionBar(final Activity activity, String url){
|
|
||||||
ImageLoader imageLoader;
|
|
||||||
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
|
||||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
|
||||||
imageLoader = ImageLoader.getInstance();
|
|
||||||
if( url.startsWith("/") ){
|
|
||||||
url = "https://" + Helper.getLiveInstance(activity) + url;
|
|
||||||
}
|
|
||||||
imageLoader.loadImage(url, options, new SimpleImageLoadingListener(){
|
|
||||||
@Override
|
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
|
||||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
|
||||||
|
|
||||||
Drawable ppDrawable;
|
|
||||||
Toolbar toolBar = (Toolbar) activity.findViewById(R.id.toolbar);
|
|
||||||
if( toolBar != null){
|
|
||||||
ppDrawable = new BitmapDrawable(activity.getResources(), Bitmap.createScaledBitmap(loadedImage, (int) convertDpToPixel(25, activity), (int) convertDpToPixel(25, activity), true));
|
|
||||||
toolBar.findViewById(R.id.pp_actionBar).setBackgroundDrawable(ppDrawable);
|
|
||||||
}else{
|
|
||||||
ActionBar supportActionBar = ((TootActivity) activity).getSupportActionBar();
|
|
||||||
if( supportActionBar != null){
|
|
||||||
ppDrawable = new BitmapDrawable(activity.getResources(), Bitmap.createScaledBitmap(loadedImage, (int) convertDpToPixel(20, activity), (int) convertDpToPixel(20, activity), true));
|
|
||||||
supportActionBar.setIcon(ppDrawable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){
|
|
||||||
|
|
||||||
}});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the header with the new selected account
|
* Update the header with the new selected account
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
tools:context="mastodon.etalab.gouv.fr.mastodon.fr.etalab.gouv.fr.mastodon.activities.MainActivity">
|
tools:context="mastodon.etalab.gouv.fr.mastodon.fr.etalab.gouv.fr.mastodon.activities.MainActivity">
|
||||||
|
|
||||||
<android.support.design.widget.AppBarLayout
|
<android.support.design.widget.AppBarLayout
|
||||||
|
android:id="@+id/appBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:theme="@style/AppTheme.AppBarOverlay"
|
android:theme="@style/AppTheme.AppBarOverlay"
|
||||||
|
@ -42,6 +43,11 @@
|
||||||
android:background="?attr/colorPrimary"
|
android:background="?attr/colorPrimary"
|
||||||
android:theme="@style/AppThemeDark_NoActionBar"
|
android:theme="@style/AppThemeDark_NoActionBar"
|
||||||
app:popupTheme="?attr/popupOverlay">
|
app:popupTheme="?attr/popupOverlay">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iconbar"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/toolbar_search_container"
|
android:id="@+id/toolbar_search_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -110,7 +110,6 @@ import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeHamburgerIcon;
|
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
|
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
|
||||||
|
@ -358,7 +357,6 @@ public class MainActivity extends AppCompatActivity
|
||||||
toolbarTitle.setOnClickListener(new View.OnClickListener() {
|
toolbarTitle.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
if( navigationView.getMenu().findItem(R.id.nav_favorites) != null && navigationView.getMenu().findItem(R.id.nav_favorites).isChecked()){
|
if( navigationView.getMenu().findItem(R.id.nav_favorites) != null && navigationView.getMenu().findItem(R.id.nav_favorites).isChecked()){
|
||||||
DisplayStatusFragment faveFrag = (DisplayStatusFragment) fragmentManager.findFragmentByTag("FAVOURITES");
|
DisplayStatusFragment faveFrag = (DisplayStatusFragment) fragmentManager.findFragmentByTag("FAVOURITES");
|
||||||
if (faveFrag != null && faveFrag.isVisible()) {
|
if (faveFrag != null && faveFrag.isVisible()) {
|
||||||
|
@ -486,8 +484,6 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||||
|
|
||||||
|
@ -509,10 +505,15 @@ public class MainActivity extends AppCompatActivity
|
||||||
registerForContextMenu(drawer);
|
registerForContextMenu(drawer);
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||||
drawer.addDrawerListener(toggle);
|
|
||||||
toggle.setDrawerIndicatorEnabled(false);
|
toggle.setDrawerIndicatorEnabled(false);
|
||||||
changeHamburgerIcon(MainActivity.this, account.getAvatar());
|
ImageView iconbar = (ImageView) toolbar.findViewById(R.id.iconbar);
|
||||||
toggle.syncState();
|
iconbar.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
drawer.openDrawer(Gravity.START);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Helper.loadPictureIcon(MainActivity.this, account.getAvatar(),iconbar);
|
||||||
headerLayout = navigationView.getHeaderView(0);
|
headerLayout = navigationView.getHeaderView(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue