Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added drawable on MenuItem and possibility to load images from url #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ disable a swipe direction
resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_RIGHT);
```

use icons from iconify:
```java
IconDrawable drawable = new IconDrawable(context, FontAwesomeIcons.fa_home)
.colorRes(R.color.ab_icon)
.actionBarSize();
itemHome = new ResideMenuItem(this, drawable, "Home");
```

load background from URL:
```java
//Use this block on your Application class
ResideMenu.imageLoader = new ResideMenu.ImageLoader() {
@Override
public void loadFromUrl(String url, ImageView imageView) {
//Exemple of loading from URL with picasso
Picasso.with(imageView.getContext()).load(url).into(imageView);
}
};

//and load from a url
resideMenu.setBackground("some url here");
```

## Custom Usage

Do your reside menu configurations, by creating an instance of ResideMenu with your custom layout's resource Ids. If you want to use default layout, just pass that variable as -1.
Expand Down
13 changes: 13 additions & 0 deletions ResideMenu/src/com/special/ResideMenu/ResideMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Rect;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.*;
import android.view.animation.AnimationUtils;
import android.widget.*;
Expand Down Expand Up @@ -74,6 +75,7 @@ public class ResideMenu extends FrameLayout {

private boolean mUse3D;
private static final int ROTATE_Y_ANGLE = 10;
public static ImageLoader imageLoader;

public ResideMenu(Context context) {
super(context);
Expand Down Expand Up @@ -216,6 +218,13 @@ private void setShadowAdjustScaleXByOrientation() {
public void setBackground(int imageResource) {
imageViewBackground.setImageResource(imageResource);
}
public void setBackground(String imageUrl) {
if (imageLoader != null) {
imageLoader.loadFromUrl(imageUrl, imageViewBackground);
} else {
Log.e(ResideMenu.class.getName(), "ImageLoader not defined.");
}
}

/**
* The visibility of the shadow under the activity;
Expand Down Expand Up @@ -696,6 +705,10 @@ public interface OnMenuListener {
public void closeMenu();
}

public interface ImageLoader{
void loadFromUrl(String url, ImageView imageView);
}

private void showScrollViewMenu(View scrollViewMenu) {
if (scrollViewMenu != null && scrollViewMenu.getParent() == null) {
addView(scrollViewMenu);
Expand Down
64 changes: 63 additions & 1 deletion ResideMenu/src/com/special/ResideMenu/ResideMenuItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.special.ResideMenu;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -39,6 +41,44 @@ public ResideMenuItem(Context context, int icon, String title) {
tv_title.setText(title);
}

public ResideMenuItem(Context context, Drawable icon, int title) {
super(context);
initViews(context);
iv_icon.setImageDrawable(icon);
tv_title.setText(title);
}

public ResideMenuItem(Context context, Drawable icon, String title) {
super(context);
initViews(context);
iv_icon.setImageDrawable(icon);
tv_title.setText(title);
}

public ResideMenuItem(Context context, String icon, int title) {
super(context);
initViews(context);

tv_title.setText(title);
if (ResideMenu.imageLoader != null) {
ResideMenu.imageLoader.loadFromUrl(icon, iv_icon);
} else {
Log.e(ResideMenu.class.getName(), "ImageLoader not defined.");
}
}

public ResideMenuItem(Context context, String icon, String title) {
super(context);
initViews(context);

tv_title.setText(title);
if (ResideMenu.imageLoader != null) {
ResideMenu.imageLoader.loadFromUrl(icon, iv_icon);
} else {
Log.e(ResideMenu.class.getName(), "ImageLoader not defined.");
}
}

private void initViews(Context context){
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.residemenu_item, this);
Expand All @@ -47,14 +87,36 @@ private void initViews(Context context){
}

/**
* set the icon color;
* set the icon resource;
*
* @param icon
*/
public void setIcon(int icon){
iv_icon.setImageResource(icon);
}

/**
* set the icon drawable;
*
* @param icon
*/
public void setIcon(Drawable icon){
iv_icon.setImageDrawable(icon);
}

/**
* set the icon url;
*
* @param icon
*/
public void setIcon(String icon){
if (ResideMenu.imageLoader != null) {
ResideMenu.imageLoader.loadFromUrl(icon, iv_icon);
} else {
Log.e(ResideMenu.class.getName(), "ImageLoader not defined.");
}
}

/**
* set the title with resource
* ;
Expand Down
28 changes: 17 additions & 11 deletions ResideMenuDemo/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.special.ResideMenuDemo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="17"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MenuActivity"
android:theme="@android:style/Theme.Light.NoTitleBar"
android:label="@string/app_name">
package="com.special.ResideMenuDemo"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".App">
<activity
android:name="MenuActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
24 changes: 24 additions & 0 deletions ResideMenuDemo/src/com/special/ResideMenuDemo/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.special.ResideMenuDemo;

import android.app.Application;
import android.widget.ImageView;

import com.special.ResideMenu.ResideMenu;

/**
* Created by gusta on 28/11/2016.
*/

public class App extends Application {

@Override
public void onCreate() {
super.onCreate();
ResideMenu.imageLoader = new ResideMenu.ImageLoader() {
@Override
public void loadFromUrl(String url, ImageView imageView) {
// Picasso.with(imageView.getContext()).load(url).into(imageView);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ private void setUpMenu() {
// attach to current activity;
resideMenu = new ResideMenu(this);
resideMenu.setUse3D(true);
resideMenu.setBackground(R.drawable.menu_background);
// resideMenu.setBackground(R.drawable.menu_background);
resideMenu.setBackground("some url here");
resideMenu.attachToActivity(this);
resideMenu.setMenuListener(menuListener);
//valid scale factor is between 0.0f and 1.0f. leftmenu'width is 150dip.
Expand Down