mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	Added news number on navigation bar elements
This commit is contained in:
		@@ -69,7 +69,7 @@ public class NavigationBar extends BaseFrameLayoutView implements NavigationBarI
 | 
			
		||||
    private void init(){
 | 
			
		||||
 | 
			
		||||
        //Inflate main view
 | 
			
		||||
        View view = inflate(getContext(), R.layout.navigation_bar, this);
 | 
			
		||||
        View view = inflate(getContext(), R.layout.view_navigation_bar, this);
 | 
			
		||||
        mLinearLayout = view.findViewById(R.id.container);
 | 
			
		||||
 | 
			
		||||
        //Inflate menu
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,13 @@
 | 
			
		||||
package org.communiquons.android.comunic.client.ui.views;
 | 
			
		||||
 | 
			
		||||
import android.annotation.SuppressLint;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.graphics.PorterDuff;
 | 
			
		||||
import android.graphics.drawable.Drawable;
 | 
			
		||||
import android.support.annotation.NonNull;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.widget.ImageView;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
 | 
			
		||||
import org.communiquons.android.comunic.client.R;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.utils.DrawableUtils;
 | 
			
		||||
@@ -16,13 +18,18 @@ import org.communiquons.android.comunic.client.ui.utils.UiUtils;
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
class NavigationBarItem extends BaseFrameLayoutView implements View.OnClickListener {
 | 
			
		||||
public class NavigationBarItem extends BaseFrameLayoutView implements View.OnClickListener {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Debug tag
 | 
			
		||||
     */
 | 
			
		||||
    private static final String TAG = NavigationBarItem.class.getCanonicalName();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * News number icon
 | 
			
		||||
     */
 | 
			
		||||
    private TextView mNumberNews;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Image icon
 | 
			
		||||
     */
 | 
			
		||||
@@ -48,13 +55,27 @@ class NavigationBarItem extends BaseFrameLayoutView implements View.OnClickListe
 | 
			
		||||
     */
 | 
			
		||||
    private boolean mSelected;
 | 
			
		||||
 | 
			
		||||
    public NavigationBarItem(@NonNull Context context) {
 | 
			
		||||
    NavigationBarItem(@NonNull Context context) {
 | 
			
		||||
        super(context);
 | 
			
		||||
 | 
			
		||||
        //Inflate view
 | 
			
		||||
        View view = inflate(getContext(), R.layout.navigation_bar_item, this);
 | 
			
		||||
        View view = inflate(getContext(), R.layout.view_navigation_bar_item, this);
 | 
			
		||||
        mIcon = view.findViewById(R.id.icon);
 | 
			
		||||
        mNumberNews = view.findViewById(R.id.numberNews);
 | 
			
		||||
        view.setOnClickListener(this);
 | 
			
		||||
 | 
			
		||||
        setNumberNews(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set the number of news
 | 
			
		||||
     *
 | 
			
		||||
     * @param number The number of news to display
 | 
			
		||||
     */
 | 
			
		||||
    @SuppressLint("SetTextI18n")
 | 
			
		||||
    public void setNumberNews(Integer number){
 | 
			
		||||
        mNumberNews.setText(""+number);
 | 
			
		||||
        mNumberNews.setVisibility(number == 0 ? View.GONE : View.VISIBLE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								app/src/main/res/drawable/ic_circle.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								app/src/main/res/drawable/ic_circle.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    android:shape="oval"
 | 
			
		||||
    android:width="2dp"
 | 
			
		||||
    android:height="2dp">
 | 
			
		||||
 | 
			
		||||
    <solid android:color="@color/default_drawable_color"/>
 | 
			
		||||
 | 
			
		||||
    <size
 | 
			
		||||
        android:width="10dp"
 | 
			
		||||
        android:height="10dp"/>
 | 
			
		||||
 | 
			
		||||
</shape>
 | 
			
		||||
@@ -20,4 +20,19 @@
 | 
			
		||||
        app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/numberNews"
 | 
			
		||||
        android:layout_width="14dp"
 | 
			
		||||
        android:layout_height="14dp"
 | 
			
		||||
        android:background="@drawable/ic_circle"
 | 
			
		||||
        android:backgroundTint="@android:color/holo_red_dark"
 | 
			
		||||
        android:paddingTop="1dp"
 | 
			
		||||
        android:textAlignment="center"
 | 
			
		||||
        android:textColor="@android:color/white"
 | 
			
		||||
        android:textSize="8sp"
 | 
			
		||||
        android:textStyle="bold"
 | 
			
		||||
        app:layout_constraintEnd_toEndOf="@+id/icon"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="@+id/icon"
 | 
			
		||||
        tools:text="10" />
 | 
			
		||||
 | 
			
		||||
</android.support.constraint.ConstraintLayout>
 | 
			
		||||
		Reference in New Issue
	
	Block a user