XML CODE
Extra header File
Extra header File
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimaryDark" android:elevation="6dp" android:gravity="center_vertical" android:orientation="horizontal" android:padding="10dp"> <ImageView android:id="@+id/img_menu" android:layout_width="30dp" android:layout_height="wrap_content" android:src="@drawable/menu" /> <TextView android:id="@+id/txttool" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:gravity="center" android:text="@string/neworder" android:textColor="@color/white" android:textSize="16dp" /> </LinearLayout>Navigation Xml<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white"> <LinearLayout android:id="@+id/linear_main_view" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include android:id="@+id/header" layout="@layout/extra_header" /> <FrameLayout android:id="@+id/frame_layout" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <LinearLayout android:id="@+id/linear_navigation" android:layout_width="280dp" android:layout_height="wrap_content" android:orientation="vertical"> <!-- android:layout_gravity="start" --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#1C4556" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="24sp" android:padding="7dp" android:orientation="horizontal"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/ivImage" android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="start" android:src="@drawable/dummy_user" /> <TextView android:id="@+id/txtusername" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="20dp" android:gravity="center" android:text="JOHN CARTER" android:textColor="@color/white" android:textSize="16sp" /> </LinearLayout> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/login_bg" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="24sp" android:orientation="vertical"> <TextView android:id="@+id/txtneworders" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/logout" android:drawablePadding="20dp" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="@string/neworder" android:textColor="@color/white" android:textSize="16sp" /> <View android:layout_width="match_parent" android:layout_height="1px" android:background="#848486" /> <TextView android:id="@+id/txtpickorders" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/logout" android:drawablePadding="20dp" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="@string/pickorder" android:textColor="@color/white" android:textSize="16sp" /> <View android:layout_width="match_parent" android:layout_height="1px" android:background="#848486" /> <TextView android:id="@+id/droporder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/logout" android:drawablePadding="20dp" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="@string/droporder" android:textColor="@color/white" android:textSize="16sp" /> <View android:layout_width="match_parent" android:layout_height="1px" android:background="#848486" /> <TextView android:id="@+id/deliverorder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/logout" android:drawablePadding="40dp" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="@string/deliverorder" android:textColor="@color/white" android:textSize="16sp" /> <View android:layout_width="wrap_content" android:layout_height="1px" android:background="#848486" /> <TextView android:id="@+id/txtcompliteorders" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/logout" android:drawablePadding="20dp" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="@string/complete" android:textColor="@color/white" android:textSize="16sp" /> <View android:layout_width="match_parent" android:layout_height="1px" android:background="#848486" /> <TextView android:id="@+id/txtlogout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/logout" android:drawablePadding="20dp" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="@string/logout" android:textColor="@color/white" android:textSize="16sp" /> <View android:layout_width="match_parent" android:layout_height="1px" android:background="#848486" /> </LinearLayout> </LinearLayout> </ScrollView> </LinearLayout> </LinearLayout> </android.support.v4.widget.DrawerLayout>Java.classpublic class MainActivity extends AppCompatActivity implements View.OnClickListener { public static ImageView imgMenu; private DrawerLayout drawerLayout; private FragmentManager fragmentManager; public static TextView txttool; TextView txtneworders, txtpickorders, txtcompliteorders, txtlogout, droporder, deliverorder, txtusername; SessionManager manager; SharedPreferences preferences; private static final String PREFRENCES_NAME = "myprefrences"; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); preferences = getSharedPreferences(PREFRENCES_NAME, Context.MODE_PRIVATE); manager = new SessionManager(); imgMenu = (ImageView) findViewById(R.id.img_menu); txttool = (TextView) findViewById(R.id.txttool); txttool.setGravity(Gravity.CENTER); txtusername = (TextView) findViewById(R.id.txtusername); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); txtneworders = (TextView) findViewById(R.id.txtneworders); txtpickorders = (TextView) findViewById(R.id.txtpickorders); droporder = (TextView) findViewById(R.id.droporder); deliverorder = (TextView) findViewById(R.id.deliverorder); txtcompliteorders = (TextView) findViewById(R.id.txtcompliteorders); txtlogout = (TextView) findViewById(R.id.txtlogout); imgMenu.setOnClickListener(this); txtneworders.setOnClickListener(this); txtpickorders.setOnClickListener(this); droporder.setOnClickListener(this); deliverorder.setOnClickListener(this); txtcompliteorders.setOnClickListener(this); txtlogout.setOnClickListener(this); txtusername.setText(preferences.getString("username", "")); fragmentManager = getSupportFragmentManager(); One one = new One (); fragmentManager.beginTransaction().replace(R.id.frame_layout, one ).commit(); } @Override public void onClick(View v) { drawerLayout.closeDrawer(Gravity.LEFT); hideKeyboard(); switch (v.getId()) { case R.id.img_menu: drawerLayout.openDrawer(Gravity.LEFT); break; case R.id.txt: One one= new One(); txttool.setText("One"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, one).commit(); hideKeyboard(); break; case R.id.txt:One one= new One(); txttool.setText("One"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, one).commit(); hideKeyboard(); break;case R.id.txt:case R.id.txt:One one= new One(); txttool.setText("One"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, one).commit(); hideKeyboard(); break;case R.id.txt:One one= new One(); txttool.setText("One"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, one).commit(); hideKeyboard(); break;case R.id.txtlogout: AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogTheme)); alert.setTitle("Logout"); alert.setMessage("Do you want to logout?"); alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent intent = new Intent(MainActivity.this, LoginActivity.class); manager.setPreferences(MainActivity.this, "statuslogin", "0"); preferences = getSharedPreferences(PREFRENCES_NAME, Context.MODE_PRIVATE); preferences.edit().clear().commit(); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert.show(); break; default: one= new OneFragment(); break; } } private void hideKeyboard() { View view = this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } public interface ClickListener { void onClick(View view, int position); void onLongClick(View view, int position); } public static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener { private GestureDetector gestureDetector; private ClickListener clickListener; public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) { this.clickListener = clickListener; gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } @Override public void onLongPress(MotionEvent e) { View child = recyclerView.findChildViewUnder(e.getX(), e.getY()); if (child != null && clickListener != null) { clickListener.onLongClick(child, recyclerView.getChildPosition(child)); } } }); } @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { View child = rv.findChildViewUnder(e.getX(), e.getY()); if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) { clickListener.onClick(child, rv.getChildPosition(child)); } return false; } @Override public void onTouchEvent(RecyclerView rv, MotionEvent e) { } @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { } } }One one= new One(); txttool.setText("One"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, one).commit(); hideKeyboard(); break;Font Classpublic class LatoBlaFontTextView extends TextView { public LatoBlaFontTextView(Context context) { super(context); init(); } public LatoBlaFontTextView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public LatoBlaFontTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "Lato-Bla.ttf"); super.setTypeface(tf); } }<com.example.admin.employeeapp.fonts.LatoBolItaFontTextViewSecond Navigation<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white"> <LinearLayout android:id="@+id/linear_main_view" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include android:id="@+id/header" layout="@layout/extra_header" /> <FrameLayout android:id="@+id/frame_layout" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </LinearLayout> <ScrollView android:id="@+id/linear_navigation" android:layout_width="280dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@android:color/white"> <!-- android:layout_gravity="start" --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/img" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/txtusername" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:text="Virat" android:textColor="@android:color/white" android:textSize="20sp" /> <TextView android:id="@+id/txtuseremail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:text="insideplay@gmail.com" android:textColor="@android:color/white" android:textSize="16sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/txt_home" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableTop="@drawable/home_selector" android:gravity="center_horizontal" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="Home" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> <TextView android:id="@+id/txt_profile" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableTop="@drawable/profile_seloctor" android:gravity="center_horizontal" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="My Profile" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="3px" android:background="#eef1f3" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/txt_inscalculator" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableTop="@drawable/calculator_selector" android:gravity="center_horizontal" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="Instagram Calculator" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> <TextView android:id="@+id/txt_request" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableTop="@drawable/requesr_selector" android:gravity="center_horizontal" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="Request for Appearance" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="3px" android:background="#eef1f3" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/txt_feedback" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableTop="@drawable/feedback_selector" android:gravity="center_horizontal" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="Feedback" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> <TextView android:id="@+id/txt_changepass" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableTop="@drawable/changepass_selector" android:gravity="center_horizontal" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="Change Password" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="3px" android:background="#eef1f3" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/txt_logout" android:layout_width="150dp" android:layout_height="wrap_content" android:drawableTop="@drawable/logout_selector" android:gravity="center_horizontal" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="Logout" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="3px" android:background="#eef1f3" /> <!-- <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/txt_faq" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_weight="1" android:drawableTop="@drawable/faq_selector" android:paddingBottom="20dp" android:paddingTop="20dp" android:text="FAQ" android:textAlignment="center" android:textColor="@drawable/home_selector_color" android:textSize="16sp" /> </LinearLayout> --> </LinearLayout> </LinearLayout> </ScrollView></android.support.v4.widget.DrawerLayout>Java.classpublic class MainActivity extends AppCompatActivity implements View.OnClickListener { public static ImageView imgMenu; private DrawerLayout drawerLayout; private FragmentManager fragmentManager; private TextView txtProfile, txt_home, txt_inscalculator, txt_changepass, txt_request, txt_logout, txt_feedback, txtusername, txtuseremail; public static TextView txttool; SessionManager manager; SharedPreferences preferences; private static final String PREFRENCES_NAME = "myprefrences"; static boolean isLoginIn; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imgMenu = (ImageView) findViewById(R.id.img_menu); txttool = (TextView) findViewById(R.id.txttool); txttool.setGravity(Gravity.CENTER); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); txtProfile = (TextView) findViewById(R.id.txt_profile); txt_home = (TextView) findViewById(R.id.txt_home); txt_inscalculator = (TextView) findViewById(R.id.txt_inscalculator); txt_request = (TextView) findViewById(R.id.txt_request); txt_logout = (TextView) findViewById(R.id.txt_logout); txt_feedback = (TextView) findViewById(R.id.txt_feedback); txt_changepass = (TextView) findViewById(R.id.txt_changepass); txtusername = (TextView) findViewById(R.id.txtusername); txtuseremail = (TextView) findViewById(R.id.txtuseremail); imgMenu.setOnClickListener(this); txtProfile.setOnClickListener(this); txt_home.setOnClickListener(this); txt_inscalculator.setOnClickListener(this); // txt_become.setOnClickListener(this); txt_request.setOnClickListener(this); txt_logout.setOnClickListener(this); txt_feedback.setOnClickListener(this); txt_changepass.setOnClickListener(this); fragmentManager = getSupportFragmentManager(); HomeFragment homeFragment = new HomeFragment(); fragmentManager.beginTransaction().replace(R.id.frame_layout, homeFragment).commit(); } @SuppressLint("NewApi") @Override public void onClick(View v) { hideKeyboard(); switch (v.getId()) { case R.id.img_menu: if (HomeFragment.count == 1) { HomeFragment homeFragment = new HomeFragment(); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, homeFragment).commit(); imgMenu.setImageResource(R.drawable.menu); HomeFragment.count = 0; } else { drawerLayout.openDrawer(Gravity.LEFT); } break; case R.id.txt_home: drawerLayout.closeDrawer(Gravity.LEFT); HomeFragment homeFragment = new HomeFragment(); txttool.setText("Welcome"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, homeFragment).commit(); hideKeyboard(); break; case R.id.txt_profile: drawerLayout.closeDrawer(Gravity.LEFT); // InfluencerFragment influencerFragment = new InfluencerFragment(); Influencer influencer = new Influencer(); txttool.setText("My Profile"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, influencer).commit(); hideKeyboard(); break; case R.id.txt_request: drawerLayout.closeDrawer(Gravity.LEFT); AppearanceFragment appearanceFragment = new AppearanceFragment(); txttool.setText("Appearance"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, appearanceFragment).commit(); hideKeyboard(); break; case R.id.txt_feedback: drawerLayout.closeDrawer(Gravity.LEFT); FeedBackFragment feedBackFragment = new FeedBackFragment(); txttool.setText("FeedBack"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, feedBackFragment).commit(); hideKeyboard(); break; case R.id.txt_changepass: drawerLayout.closeDrawer(Gravity.LEFT); ChangePasswordFragment changePasswordFragment = new ChangePasswordFragment(); txttool.setText("Change Password"); txttool.setGravity(Gravity.CENTER); fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.frame_layout, changePasswordFragment).commit(); hideKeyboard(); break; case R.id.txt_logout: drawerLayout.closeDrawer(Gravity.LEFT); AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogTheme)); alert.setTitle("Logout"); alert.setMessage("Do you want to logout?"); alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // trimCache(); Intent intent = new Intent(MainActivity.this, LoginActivity.class); manager.setPreferences(MainActivity.this, "status", "0"); manager.setPreferences(MainActivity.this, "loginuser", "0"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert.show(); break; default: homeFragment = new HomeFragment(); break; } } public void onBackPressed() { super.onBackPressed(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); System.exit(0); }}Image Selector<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/logout_actwell" android:state_selected="true" android:text="SECOND"> </item> <item android:drawable="@mipmap/logout_actwell" android:state_pressed="true" android:text="SECOND"> </item> <item android:drawable="@mipmap/logoutwell"> </item> </selector>text Color Selector<selectorxmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="@color/signuptext" /> <item android:state_pressed="false" android:color="@color/iron" /> </selector>
No comments:
Post a Comment