7bc6bdb3c425fa6998f2263305bb5de2532271f8
[cicn.git] /
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.metis.ccnx.ccnxsdk.metiscontrol;
17
18 import android.os.Bundle;
19 import android.support.design.widget.FloatingActionButton;
20 import android.support.v4.app.Fragment;
21 import android.support.v4.app.FragmentManager;
22 import android.support.v4.app.FragmentPagerAdapter;
23 import android.support.v4.view.ViewPager;
24 import android.support.v7.app.AppCompatActivity;
25 import android.support.v7.widget.Toolbar;
26 import android.util.Log;
27 import android.view.LayoutInflater;
28 import android.view.Menu;
29 import android.view.MenuItem;
30 import android.view.View;
31 import android.view.ViewGroup;
32 import android.widget.TextView;
33
34 public class ForwarderStatusActivity extends AppCompatActivity implements
35         MetisStatusFragment.OnFragmentVisibleListener {
36
37     private static final String TAG = "CCNX FSA";
38
39     private SectionsPagerAdapter mSectionsPagerAdapter;
40
41     private ViewPager mViewPager;
42     private Fragment mVisibleFragment;
43
44
45     @Override
46     protected void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         setContentView(R.layout.activity_forwarder_status);
49
50         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
51         setSupportActionBar(toolbar);
52         mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
53         mViewPager = (ViewPager) findViewById(R.id.container);
54         mViewPager.setAdapter(mSectionsPagerAdapter);
55
56
57         final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
58
59         assert fab != null;
60         fab.setVisibility(View.GONE);
61
62         fab.setOnClickListener(new View.OnClickListener() {
63             @Override
64             public void onClick(View view) {
65                 if (mVisibleFragment != null) {
66                     if (mVisibleFragment instanceof IMetisAddNewItem) {
67                         IMetisAddNewItem fragment = (IMetisAddNewItem) mVisibleFragment;
68                         fragment.showAddNewItemDialog();
69                     }
70                 }
71             }
72         });
73
74     }
75
76
77     @Override
78
79     public boolean onCreateOptionsMenu(Menu menu) {
80         getMenuInflater().inflate(R.menu.menu_forwarder_status, menu);
81         return true;
82     }
83
84     @Override
85     public boolean onOptionsItemSelected(MenuItem item) {
86
87         int id = item.getItemId();
88
89         if (id == R.id.action_settings) {
90             return true;
91         }
92
93         return super.onOptionsItemSelected(item);
94     }
95
96     public static class PlaceholderFragment extends Fragment {
97
98         private static final String ARG_SECTION_NUMBER = "section_number";
99
100         public PlaceholderFragment() {
101         }
102
103         public static PlaceholderFragment newInstance(int sectionNumber) {
104             PlaceholderFragment fragment = new PlaceholderFragment();
105             Bundle args = new Bundle();
106             args.putInt(ARG_SECTION_NUMBER, sectionNumber);
107             fragment.setArguments(args);
108             return fragment;
109         }
110
111         @Override
112         public View onCreateView(LayoutInflater inflater, ViewGroup container,
113                                  Bundle savedInstanceState) {
114             View rootView = inflater.inflate(R.layout.fragment_forwarder_status, container, false);
115             TextView textView = (TextView) rootView.findViewById(R.id.section_label);
116             textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
117             return rootView;
118         }
119     }
120
121     public class SectionsPagerAdapter extends FragmentPagerAdapter {
122
123         public SectionsPagerAdapter(FragmentManager fm) {
124             super(fm);
125         }
126
127         @Override
128         public Fragment getItem(int position) {
129             return MetisStatusFragment.newInstance(position + 1);
130         }
131
132         @Override
133         public int getCount() {
134             return 1;
135         }
136
137         @Override
138         public CharSequence getPageTitle(int position) {
139             return "SECTION 1";
140         }
141
142
143     }
144
145     public void onFragmentVisible(Fragment fragment) {
146         Log.d(TAG, "***** PAGE: " + fragment + " is now showing.");
147         mVisibleFragment = fragment;
148
149         final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
150
151         if (fragment instanceof IMetisAddNewItem) {
152             fab.setVisibility(View.VISIBLE);
153         } else {
154             fab.setVisibility(View.INVISIBLE);
155         }
156
157         String appName = getResources().getString(R.string.app_name);
158
159         if (fragment instanceof IMetisNamedFragment) {
160             appName += " // " + ((IMetisNamedFragment) fragment).getFragmentName();
161         }
162
163         setTitle(appName);
164
165     }
166
167
168
169 }