mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-06-16 21:10:57 +08:00
Add inspector link into the status view
This commit is contained in:
parent
e5a774847b
commit
3e08121edc
@ -25,6 +25,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
@ -39,6 +41,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.emanuelef.remote_capture.activities.InspectorActivity;
|
||||
import com.emanuelef.remote_capture.model.AppState;
|
||||
import com.emanuelef.remote_capture.CaptureService;
|
||||
import com.emanuelef.remote_capture.model.Prefs;
|
||||
@ -48,9 +51,12 @@ import com.emanuelef.remote_capture.activities.MainActivity;
|
||||
import com.emanuelef.remote_capture.activities.StatsActivity;
|
||||
import com.emanuelef.remote_capture.interfaces.AppStateListener;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
public class StatusFragment extends Fragment implements AppStateListener {
|
||||
private TextView mCollectorInfo;
|
||||
private TextView mCaptureStatus;
|
||||
private TextView mInspectorLink;
|
||||
private MainActivity mActivity;
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
@ -79,6 +85,7 @@ public class StatusFragment extends Fragment implements AppStateListener {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
mCollectorInfo = view.findViewById(R.id.collector_info);
|
||||
mCaptureStatus = view.findViewById(R.id.status_view);
|
||||
mInspectorLink = view.findViewById(R.id.inspector_link);
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(mActivity);
|
||||
|
||||
mCaptureStatus.setOnClickListener(v -> {
|
||||
@ -91,6 +98,8 @@ public class StatusFragment extends Fragment implements AppStateListener {
|
||||
// Make URLs clickable
|
||||
mCollectorInfo.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
setupInspectorLinK();
|
||||
|
||||
mPrefs.registerOnSharedPreferenceChangeListener((sharedPreferences, s) -> {
|
||||
if((mActivity != null) && (mActivity.getState() == AppState.ready))
|
||||
refreshPcapDumpInfo();
|
||||
@ -110,6 +119,19 @@ public class StatusFragment extends Fragment implements AppStateListener {
|
||||
mActivity.setAppStateListener(this);
|
||||
}
|
||||
|
||||
private void setupInspectorLinK() {
|
||||
int color = getResources().getColor(android.R.color.tab_indicator_text);
|
||||
|
||||
mInspectorLink.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_search, 0, 0, 0);
|
||||
Drawable drawables[] = mInspectorLink.getCompoundDrawables();
|
||||
drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
|
||||
mInspectorLink.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(getActivity(), InspectorActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
private void processStatsUpdateIntent(Intent intent) {
|
||||
long bytes_sent = intent.getLongExtra(CaptureService.TRAFFIC_STATS_UPDATE_SENT_BYTES, 0);
|
||||
long bytes_rcvd = intent.getLongExtra(CaptureService.TRAFFIC_STATS_UPDATE_RCVD_BYTES, 0);
|
||||
@ -160,10 +182,12 @@ public class StatusFragment extends Fragment implements AppStateListener {
|
||||
switch(state) {
|
||||
case ready:
|
||||
mCaptureStatus.setText(R.string.ready);
|
||||
mInspectorLink.setVisibility(View.GONE);
|
||||
refreshPcapDumpInfo();
|
||||
break;
|
||||
case running:
|
||||
mCaptureStatus.setText(Utils.formatBytes(CaptureService.getBytes()));
|
||||
mInspectorLink.setVisibility(View.VISIBLE);
|
||||
refreshPcapDumpInfo();
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
android:id="@+id/collector_info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="82dp"
|
||||
android:layout_marginTop="60dp"
|
||||
android:gravity="center"
|
||||
android:autoLink="web"
|
||||
android:drawablePadding="5dp"
|
||||
@ -20,6 +20,20 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/status_view" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/inspector_link"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/inspector"
|
||||
android:drawablePadding="5dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/collector_info" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/status_view"
|
||||
android:layout_width="240dp"
|
||||
@ -28,7 +42,7 @@
|
||||
android:background="@drawable/rounded_bg"
|
||||
android:gravity="center"
|
||||
android:text="@string/ready"
|
||||
android:textSize="30dp"
|
||||
android:textSize="30sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user