Skip to content

Commit

Permalink
Changed 3 of the fragments to ViewPager as per #116
Browse files Browse the repository at this point in the history
  • Loading branch information
tobykurien committed Oct 4, 2014
1 parent 8826241 commit c97ea8b
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 24 deletions.
28 changes: 17 additions & 11 deletions app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.SecUpwN.AIMSICD.fragments.AtCommandFragment;
import com.SecUpwN.AIMSICD.fragments.CellInfoFragment;
import com.SecUpwN.AIMSICD.fragments.DbViewerFragment;
import com.SecUpwN.AIMSICD.fragments.DetailsContainerFragment;
import com.SecUpwN.AIMSICD.fragments.DeviceFragment;
import com.SecUpwN.AIMSICD.drawer.DrawerMenuItem;
import com.SecUpwN.AIMSICD.drawer.DrawerMenuSection;
Expand Down Expand Up @@ -54,6 +55,7 @@
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.telephony.TelephonyManager;
import android.util.Log;
Expand All @@ -68,7 +70,7 @@
import java.util.ArrayList;
import java.util.List;

public class AIMSICD extends Activity implements AsyncResponse {
public class AIMSICD extends FragmentActivity implements AsyncResponse {

private final String TAG = "AIMSICD";

Expand All @@ -91,6 +93,7 @@ public class AIMSICD extends Activity implements AsyncResponse {
private long mLastPress = 0;

private DrawerMenuActivityConfiguration mNavConf ;
private DetailsContainerFragment mDetailsFrag;

/**
* Called when the activity is first created.
Expand Down Expand Up @@ -145,9 +148,9 @@ public void onDrawerOpened(View drawerView) {
mActionBar.setHomeButtonEnabled(true);

//Display the Device Fragment as the Default View
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, new DeviceFragment())
mDetailsFrag = new DetailsContainerFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, mDetailsFrag)
.commit();

mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
Expand Down Expand Up @@ -233,20 +236,23 @@ void selectItem(int position) {
// Create a new fragment
switch (selectedItem.getId()) {
case 101:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new DeviceFragment()).commit();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, mDetailsFrag).commit();
mDetailsFrag.setCurrentPage(0);
break;
case 102:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new CellInfoFragment()).commit();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, mDetailsFrag).commit();
mDetailsFrag.setCurrentPage(1);
break;
case 103:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new AtCommandFragment()).commit();
break;
case 104:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new DbViewerFragment()).commit();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, mDetailsFrag).commit();
mDetailsFrag.setCurrentPage(2);
break;
case 303:
getFragmentManager().beginTransaction()
Expand Down Expand Up @@ -391,7 +397,7 @@ public void setTitle(CharSequence title) {
mActionBar.setTitle(mTitle);
}

DrawerMenuActivityConfiguration getNavDrawerConfiguration() {
public DrawerMenuActivityConfiguration getNavDrawerConfiguration() {

List<NavDrawerItem> menu = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.SecUpwN.AIMSICD.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.SecUpwN.AIMSICD.fragments.CellInfoFragment;
import com.SecUpwN.AIMSICD.fragments.DbViewerFragment;
import com.SecUpwN.AIMSICD.fragments.DeviceFragment;

/**
* Adapter to allow swiping between various detail fragments
*/
public class DetailsPagerAdapter extends FragmentPagerAdapter {

public DetailsPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0: return new DeviceFragment();
case 1: return new CellInfoFragment();
case 2: return new DbViewerFragment();
}

return new DeviceFragment();
}

@Override
public long getItemId(int position) {
// map position to position in AIMSICD.getNavDrawerConfiguration
switch (position) {
case 0: return 4;
case 1: return 5;
case 2: return 7;
}

return -1;
}

@Override
public int getCount() {
return 3;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
package com.SecUpwN.AIMSICD.fragments;

import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.adapters.BaseInflaterAdapter;
import com.SecUpwN.AIMSICD.adapters.CardItemData;
import com.SecUpwN.AIMSICD.adapters.CellCardInflater;
import com.SecUpwN.AIMSICD.service.AimsicdService;
import com.SecUpwN.AIMSICD.service.CellTracker;
import com.SecUpwN.AIMSICD.utils.Cell;
import com.SecUpwN.AIMSICD.utils.Helpers;
import com.SecUpwN.AIMSICD.rilexecutor.RilExecutor;

import android.app.Activity;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
Expand All @@ -20,6 +9,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -29,6 +19,16 @@
import android.widget.TableRow;
import android.widget.TextView;

import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.adapters.BaseInflaterAdapter;
import com.SecUpwN.AIMSICD.adapters.CardItemData;
import com.SecUpwN.AIMSICD.adapters.CellCardInflater;
import com.SecUpwN.AIMSICD.rilexecutor.RilExecutor;
import com.SecUpwN.AIMSICD.service.AimsicdService;
import com.SecUpwN.AIMSICD.service.CellTracker;
import com.SecUpwN.AIMSICD.utils.Cell;
import com.SecUpwN.AIMSICD.utils.Helpers;

import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import com.SecUpwN.AIMSICD.utils.Helpers;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.SecUpwN.AIMSICD.fragments;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.SecUpwN.AIMSICD.AIMSICD;
import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.adapters.DetailsPagerAdapter;
import com.SecUpwN.AIMSICD.drawer.DrawerMenuActivityConfiguration;
import com.SecUpwN.AIMSICD.drawer.NavDrawerItem;

/**
* This fragment will host child fragments to display device details, cell info, etc.
*/
public class DetailsContainerFragment extends Fragment {
ViewPager vp;
DetailsPagerAdapter adapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_details_container, container, false);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

final DrawerMenuActivityConfiguration mNavConf = ((AIMSICD) getActivity()).getNavDrawerConfiguration();
adapter = new DetailsPagerAdapter(getChildFragmentManager());

vp = (ViewPager) view.findViewById(R.id.details_pager);
vp.setAdapter(adapter);
vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
int navId = (int) adapter.getItemId(position);
NavDrawerItem selectedItem = mNavConf.getNavItems().get(navId);
getActivity().getActionBar().setTitle(selectedItem.getLabel());
}

@Override
public void onPageScrollStateChanged(int state) {

}
});
}

public void setCurrentPage(int page) {
if (page >= 0 && page < adapter.getCount()) {
vp.setCurrentItem(page);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.app.Fragment;
import android.support.v4.app.Fragment;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/fragment_details_container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<FrameLayout
android:id="@+id/details_fragment_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
android:id="@+id/details_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</FrameLayout>

0 comments on commit c97ea8b

Please sign in to comment.