public
class
MenuActivity
extends
BaseActivity
implements
View.OnClickListener{
ImageView imgPremium, imgSelf, imgLibrary, imgSay;
LinearLayout menu_detail;
TextView textPremium, textSelf, textLibrary, textSay;
int
mCurrentFragmentIndex;
public
final
static
int
FRAGMENT_ONE =
0
;
public
final
static
int
FRAGMENT_TWO =
1
;
public
final
static
int
FRAGMENT_THREE =
2
;
public
final
static
int
FRAGMENT_FOUR =
3
;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgPremium = (ImageView)findViewById(R.id.img_premium);
imgPremium.setOnClickListener(
this
);
imgSelf = (ImageView)findViewById(R.id.img_self);
imgSelf.setOnClickListener(
this
);
imgLibrary = (ImageView)findViewById(R.id.img_library);
imgLibrary.setOnClickListener(
this
);
imgSay = (ImageView)findViewById(R.id.img_say);
imgSay.setOnClickListener(
this
);
textPremium = (TextView)findViewById(R.id.txt_premium);
textPremium.setOnClickListener(
this
);
textSelf = (TextView)findViewById(R.id.txt_self);
textSelf.setOnClickListener(
this
);
textLibrary = (TextView)findViewById(R.id.txt_library);
textLibrary.setOnClickListener(
this
);
textSay = (TextView)findViewById(R.id.txt_say);
textSay.setOnClickListener(
this
);
}
public
void
fragmentReplace(
int
reqNewFragmentIndex) {
Fragment newFragment =
null
;
newFragment = getFragment(reqNewFragmentIndex);
final
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
transaction.replace(R.id.menu_frame_layout, newFragment);
transaction.commit();
}
private
Fragment getFragment(
int
idx) {
Fragment newFragment =
null
;
switch
(idx) {
case
FRAGMENT_ONE:
newFragment =
new
PremiumFragment();
break
;
case
FRAGMENT_TWO:
newFragment =
new
SelfFragment();
break
;
case
FRAGMENT_THREE:
newFragment =
new
LibraryFragment();
break
;
case
FRAGMENT_FOUR:
newFragment =
new
SayFragment();
break
;
}
return
newFragment;
}
public
void
onClick(View v) {
Intent i;
switch
(v.getId()) {
case
R.id.img_premium:
case
R.id.txt_premium:
mCurrentFragmentIndex = FRAGMENT_ONE;
fragmentReplace(mCurrentFragmentIndex);
getSupportActionBar().show();
break
;
case
R.id.img_self:
case
R.id.txt_self:
mCurrentFragmentIndex = FRAGMENT_TWO;
fragmentReplace(mCurrentFragmentIndex);
getSupportActionBar().show();
break
;
case
R.id.img_library:
case
R.id.txt_library:
mCurrentFragmentIndex = FRAGMENT_THREE;
fragmentReplace(mCurrentFragmentIndex);
getSupportActionBar().show();
break
;
case
R.id.img_say:
case
R.id.txt_say:
mCurrentFragmentIndex = FRAGMENT_FOUR;
fragmentReplace(mCurrentFragmentIndex);
getSupportActionBar().show();
break
;
}