mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-06-07 21:17:33 +00:00
Use a button to switch between HTTP requests and Connections
This commit is contained in:
@@ -511,6 +511,26 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
new TabLayoutMediator(findViewById(R.id.tablayout), mPager, (tab, position) ->
|
||||
tab.setText(getString(stateAdapter.getPageTitle(position)))
|
||||
).attach();
|
||||
|
||||
View switchButton = findViewById(R.id.tab_switch_button);
|
||||
if (switchButton != null) {
|
||||
switchButton.setOnClickListener(v -> {
|
||||
if (mPager.getCurrentItem() != POS_CONNECTIONS) {
|
||||
// Switch to Connections tab first, then toggle after fragment is created
|
||||
mPager.setCurrentItem(POS_CONNECTIONS);
|
||||
mPager.post(this::toggleDataView);
|
||||
} else {
|
||||
toggleDataView();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleDataView() {
|
||||
Fragment container = getFragmentAtPos(POS_CONNECTIONS);
|
||||
if (container instanceof DataViewContainerFragment) {
|
||||
((DataViewContainerFragment) container).toggleView();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -625,6 +645,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
public void appStateReady() {
|
||||
mState = AppState.ready;
|
||||
notifyAppState();
|
||||
updateTabSwitchButton();
|
||||
|
||||
if(mPcapLoadDialog != null)
|
||||
checkLoadedPcap();
|
||||
@@ -638,6 +659,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
public void appStateRunning() {
|
||||
mState = AppState.running;
|
||||
notifyAppState();
|
||||
updateTabSwitchButton();
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
checkVpnLockdownNotice();
|
||||
@@ -658,6 +680,14 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
notifyAppState();
|
||||
}
|
||||
|
||||
private void updateTabSwitchButton() {
|
||||
View switchButton = findViewById(R.id.tab_switch_button);
|
||||
if (switchButton != null) {
|
||||
boolean httpLogAvailable = (CaptureService.getHttpLog() != null);
|
||||
switchButton.setVisibility(httpLogAvailable ? android.view.View.VISIBLE : android.view.View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDecryptionRulesNotice() {
|
||||
if(!mDecEmptyRulesNoticeShown && PCAPdroid.getInstance().getDecryptionList().isEmpty()) {
|
||||
new AlertDialog.Builder(this)
|
||||
|
||||
+17
-18
@@ -143,38 +143,24 @@ public class DataViewContainerFragment extends Fragment implements MenuProvider
|
||||
if (mConnectionsFragment instanceof ConnectionsFragment) {
|
||||
((ConnectionsFragment) mConnectionsFragment).onCreateMenu(menu, menuInflater);
|
||||
}
|
||||
|
||||
if (CaptureService.getHttpLog() != null)
|
||||
menu.add(Menu.NONE, R.id.switch_to_http_log, 25, R.string.switch_to_http)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
} else if ((mCurrentView == VIEW_HTTP_LOG) && (mHttpLogFragment != null)) {
|
||||
if (mHttpLogFragment instanceof HttpLogFragment) {
|
||||
((HttpLogFragment) mHttpLogFragment).onCreateMenu(menu, menuInflater);
|
||||
}
|
||||
menu.add(Menu.NONE, R.id.switch_to_connections, 25, R.string.switch_to_connections)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
}
|
||||
|
||||
updateTabTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.switch_to_http_log) {
|
||||
switchToView(VIEW_HTTP_LOG);
|
||||
return true;
|
||||
} else if (id == R.id.switch_to_connections) {
|
||||
switchToView(VIEW_CONNECTIONS);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mCurrentView == VIEW_CONNECTIONS && mConnectionsFragment != null) {
|
||||
if ((mCurrentView == VIEW_CONNECTIONS) && (mConnectionsFragment != null)) {
|
||||
if (mConnectionsFragment instanceof ConnectionsFragment) {
|
||||
if (((ConnectionsFragment) mConnectionsFragment).onMenuItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (mCurrentView == VIEW_HTTP_LOG && mHttpLogFragment != null) {
|
||||
} else if ((mCurrentView == VIEW_HTTP_LOG) && (mHttpLogFragment != null)) {
|
||||
if (mHttpLogFragment instanceof HttpLogFragment) {
|
||||
if (((HttpLogFragment) mHttpLogFragment).onMenuItemSelected(item)) {
|
||||
return true;
|
||||
@@ -185,6 +171,12 @@ public class DataViewContainerFragment extends Fragment implements MenuProvider
|
||||
return false;
|
||||
}
|
||||
|
||||
public void toggleView() {
|
||||
int targetView = (mCurrentView == VIEW_CONNECTIONS) ?
|
||||
VIEW_HTTP_LOG : VIEW_CONNECTIONS;
|
||||
switchToView(targetView);
|
||||
}
|
||||
|
||||
private void switchToView(int targetView) {
|
||||
if (mCurrentView == targetView) {
|
||||
return;
|
||||
@@ -221,6 +213,13 @@ public class DataViewContainerFragment extends Fragment implements MenuProvider
|
||||
tab.setText(getString(titleRes));
|
||||
}
|
||||
}
|
||||
|
||||
View switchButton = activity.findViewById(R.id.tab_switch_button);
|
||||
if (switchButton != null) {
|
||||
int contentDescRes = (mCurrentView == VIEW_CONNECTIONS) ?
|
||||
R.string.switch_to_http : R.string.switch_to_connections;
|
||||
switchButton.setContentDescription(getString(contentDescRes));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onBackPressed() {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="28dp" android:width="28dp"
|
||||
android:viewportHeight="24" android:viewportWidth="24">
|
||||
<path android:fillColor="#FFFFFF" android:pathData="M6.99,10L3,14l3.99,4v-3H14v-2H6.99v-3zM21,8l-3.99,-4v3H10v2h7.01v3L21,8z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@android:color/white" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@@ -25,15 +25,35 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tablayout"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:tabTextColor="@color/colorTabText"
|
||||
app:tabSelectedTextColor="@color/colorTabTextSelected"
|
||||
app:tabIndicatorColor="@color/colorTab"
|
||||
app:tabMaxWidth="0dp"
|
||||
app:tabGravity="fill" />
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tablayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
app:tabTextColor="@color/colorTabText"
|
||||
app:tabSelectedTextColor="@color/colorTabTextSelected"
|
||||
app:tabIndicatorColor="@color/colorTab"
|
||||
app:tabMaxWidth="0dp"
|
||||
app:tabGravity="fill" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/tab_switch_button"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_swap_horiz"
|
||||
android:background="@drawable/tab_switch_button_background"
|
||||
android:contentDescription="@string/switch_to_http"
|
||||
android:visibility="gone"
|
||||
android:focusable="true"
|
||||
android:clickable="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/pager"
|
||||
|
||||
Reference in New Issue
Block a user