Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-android
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 140778ec
authored
Jul 16, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
c33fea97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
139 additions
and
0 deletions
app/src/main/java/com/whaty/nafmii/activity/TestHomeActivity.java
app/src/main/java/com/whaty/nafmii/activity/TestHomeActivity.java
0 → 100644
View file @
140778e
package
com
.
whaty
.
nafmii
.
activity
;
import
android.annotation.SuppressLint
;
import
android.os.Bundle
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.widget.RadioButton
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentManager
;
import
androidx.fragment.app.FragmentTransaction
;
import
com.polysoft.nafmii.enums.ModulesEnum
;
import
com.polysoft.nafmii.fragment.TestFragment
;
import
com.whaty.nafmii.R
;
import
com.polysoft.nafmii.fragment.home.ModulesFragmentMgr
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
public
class
TestHomeActivity
extends
WebviewActivity
implements
View
.
OnClickListener
,
ModulesFragmentMgr
.
OnChangeModuleListener
{
private
ModulesFragmentMgr
modulesMgr
;
private
HashMap
<
ModulesEnum
,
RadioButton
>
moduleViewsMap
;
private
HashMap
<
ModulesEnum
,
Fragment
>
mFragmentMap
=
new
HashMap
<>();
private
View
footerView
;
private
ModulesEnum
currentModule
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
setContentView
(
R
.
layout
.
activity_home
);
this
.
initView
();
this
.
initHomeModule
();
}
@Override
public
void
onCoreInitFinished
(
boolean
flag
)
{
}
private
void
initView
()
{
this
.
footerView
=
super
.
findViewById
(
R
.
id
.
home_footer_group
);
this
.
footerView
.
setVisibility
(
View
.
VISIBLE
);
HashMap
<
ModulesEnum
,
RadioButton
>
modulesMap
=
new
HashMap
<>();
modulesMap
.
put
(
ModulesEnum
.
HOME
,
super
.
findViewById
(
R
.
id
.
home_btn_home
));
modulesMap
.
put
(
ModulesEnum
.
MEMBER
,
super
.
findViewById
(
R
.
id
.
home_btn_member
));
modulesMap
.
put
(
ModulesEnum
.
LEARN
,
super
.
findViewById
(
R
.
id
.
home_btn_learn
));
modulesMap
.
put
(
ModulesEnum
.
MY
,
super
.
findViewById
(
R
.
id
.
home_btn_my
));
for
(
Map
.
Entry
<
ModulesEnum
,
RadioButton
>
modulesEnumRadioButtonEntry
:
modulesMap
.
entrySet
())
{
modulesEnumRadioButtonEntry
.
getValue
().
setOnClickListener
(
this
);
}
this
.
moduleViewsMap
=
modulesMap
;
}
private
void
initHomeModule
()
{
int
containerId
=
R
.
id
.
home_container_framelayout
;
this
.
mFragmentMap
.
put
(
ModulesEnum
.
HOME
,
TestFragment
.
newInstance
(
"首页"
));
this
.
mFragmentMap
.
put
(
ModulesEnum
.
MEMBER
,
TestFragment
.
newInstance
(
"会员"
));
this
.
mFragmentMap
.
put
(
ModulesEnum
.
LEARN
,
TestFragment
.
newInstance
(
"学习"
));
this
.
mFragmentMap
.
put
(
ModulesEnum
.
MY
,
TestFragment
.
newInstance
(
"我的"
));
FragmentManager
manager
=
getSupportFragmentManager
();
Iterator
<
ModulesEnum
>
iterator
=
this
.
mFragmentMap
.
keySet
().
iterator
();
while
(
iterator
.
hasNext
())
{
ModulesEnum
key
=
iterator
.
next
();
Fragment
fragment
=
this
.
mFragmentMap
.
get
(
key
);
FragmentTransaction
transaction
=
manager
.
beginTransaction
();
transaction
.
add
(
containerId
,
fragment
,
key
.
name
).
hide
(
fragment
).
commitNow
();
}
FragmentTransaction
transaction
=
manager
.
beginTransaction
();
Fragment
fragment
=
this
.
mFragmentMap
.
get
(
ModulesEnum
.
HOME
);
transaction
.
show
(
fragment
).
commitNow
();
this
.
currentModule
=
ModulesEnum
.
HOME
;
}
@SuppressLint
(
"NonConstantResourceId"
)
@Override
public
void
onClick
(
View
v
)
{
switch
(
v
.
getId
())
{
case
R
.
id
.
home_btn_home
:
this
.
changeModule
(
ModulesEnum
.
HOME
,
null
);
break
;
case
R
.
id
.
home_btn_member
:
this
.
changeModule
(
ModulesEnum
.
MEMBER
,
null
);
break
;
case
R
.
id
.
home_btn_learn
:
this
.
changeModule
(
ModulesEnum
.
LEARN
,
null
);
break
;
case
R
.
id
.
home_btn_my
:
this
.
changeModule
(
ModulesEnum
.
MY
,
null
);
break
;
default
:
break
;
}
}
@Override
public
boolean
onKeyDown
(
int
keyCode
,
KeyEvent
event
)
{
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// if (!this.modulesMgr.onBackStack()) {
// return false;
// }
// }
return
super
.
onKeyDown
(
keyCode
,
event
);
}
@Override
public
void
changeModule
(
ModulesEnum
module
,
Fragment
fragment2
)
{
if
(
this
.
currentModule
==
module
)
{
return
;
}
RadioButton
moduleButton
=
this
.
moduleViewsMap
.
get
(
module
);
Fragment
fragment
=
this
.
mFragmentMap
.
get
(
module
);
FragmentManager
manager
=
getSupportFragmentManager
();
FragmentTransaction
transaction
=
manager
.
beginTransaction
();
transaction
.
hide
(
manager
.
findFragmentByTag
(
this
.
currentModule
.
name
));
transaction
.
addToBackStack
(
""
).
show
(
fragment
).
commit
();
if
(
null
!=
moduleButton
)
{
moduleButton
.
setChecked
(
true
);
}
this
.
currentModule
=
module
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment