initial commit
This commit is contained in:
105
app/src/main/java/ch/pizzapp/android/view/AppToolbar.java
Normal file
105
app/src/main/java/ch/pizzapp/android/view/AppToolbar.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package ch.pizzapp.android.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import ch.pizzapp.android.R;
|
||||
import ch.pizzapp.android.activity.BaseActivity;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 18/09/2017.
|
||||
*/
|
||||
|
||||
public class AppToolbar extends Toolbar {
|
||||
|
||||
private View rootView;
|
||||
private TextView toolbarTitleTextView;
|
||||
private ImageView hamburgerIcon, backIcon;
|
||||
private boolean showHamburgerIcon, showBackIcon;
|
||||
private String title;
|
||||
private int toolbarBackgroundColor, titleTextColor;
|
||||
|
||||
/*
|
||||
public PizzalinkToolbar(Toolbar toolbar){
|
||||
this.toolbar = toolbar;
|
||||
initViews();
|
||||
toolbar.setBackgroundColor(ContextCompat.getColor(BaseActivity.currentActivity, android.R.color.transparent));
|
||||
}
|
||||
*/
|
||||
|
||||
public AppToolbar(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public AppToolbar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AppToolbar, 0, 0);
|
||||
try {
|
||||
showHamburgerIcon = a.getBoolean(R.styleable.AppToolbar_showHamburgerMenuIcon, false);
|
||||
showBackIcon = a.getBoolean(R.styleable.AppToolbar_showBackIcon, false);
|
||||
title = a.getString(R.styleable.AppToolbar_title);
|
||||
/*
|
||||
toolbarBackgroundColor = a.getColor(R.styleable.PizzalinkToolbar_toolbarBackgroundColor,
|
||||
ContextCompat.getColor(BaseActivity.currentActivity, R.color.colorPrimary));
|
||||
titleTextColor = a.getColor(R.styleable.PizzalinkToolbar_toolbarTitleTextColor,
|
||||
ContextCompat.getColor(BaseActivity.currentActivity, R.color.white));
|
||||
*/
|
||||
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context){
|
||||
rootView = inflate(context, R.layout.layout_pizzalink_toolbar, this);
|
||||
this.setPadding(0, 0, 0, 0);
|
||||
this.setContentInsetsAbsolute(0, 0);
|
||||
toolbarTitleTextView = (TextView) rootView.findViewById(R.id.toolbarTitleTextView);
|
||||
//this.setBackgroundResource(toolbarBackgroundColor);
|
||||
//toolbarTitleTextView.setTextColor(titleTextColor);
|
||||
hamburgerIcon = (ImageView) rootView.findViewById(R.id.hamburgerIcon);
|
||||
backIcon = (ImageView) rootView.findViewById(R.id.backIcon);
|
||||
if(showHamburgerIcon)
|
||||
hamburgerIcon.setVisibility(VISIBLE);
|
||||
if(showBackIcon)
|
||||
backIcon.setVisibility(VISIBLE);
|
||||
backIcon.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BaseActivity.currentActivity.onBackPressed();
|
||||
}
|
||||
});
|
||||
if(title != null) {
|
||||
toolbarTitleTextView.setText(title);
|
||||
toolbarTitleTextView.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public Toolbar getToolbar() {
|
||||
return (Toolbar) rootView;
|
||||
}
|
||||
|
||||
public void setTitle(String title){
|
||||
rootView.setVisibility(View.VISIBLE);
|
||||
toolbarTitleTextView.setVisibility(View.VISIBLE);
|
||||
toolbarTitleTextView.setText(title);
|
||||
}
|
||||
|
||||
public void setHamburgerIconVisibility(boolean show) {
|
||||
if(show)
|
||||
hamburgerIcon.setVisibility(VISIBLE);
|
||||
else
|
||||
hamburgerIcon.setVisibility(GONE);
|
||||
}
|
||||
|
||||
public ImageView getHamburgerIcon() {
|
||||
return hamburgerIcon;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user