Skip to content

Commit

Permalink
Changed
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuhaibNC committed Aug 21, 2024
1 parent a0f73fe commit 115af14
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 30 deletions.
71 changes: 43 additions & 28 deletions app/src/main/java/com/shuhaib/ipf/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,68 @@
import android.widget.Button;
import android.view.View;
import android.view.WindowManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.widget.Toast;

public class MainActivity extends Activity {

public static TextView warnt;
TextView ipaddress;
Button restart;
public static TextView ipaddress;
public static Button restart;
public static String err;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);

ipaddress = findViewById(R.id.ipaddress);
warnt = findViewById(R.id.warntext);
restart = findViewById(R.id.restart);

NetworkUtils nu = new NetworkUtils();
String ipaddr = nu.getLocalIpAddress();
try{
if (ipaddr == null){
ipaddress.setText("127.0.0.1");
warnt.setText("Please turn on mobile hotspot and press restart");
}
else{
ipaddress.setText(ipaddr);
}
}
catch(Exception e){
warnt.setText(e.getMessage());
}
refreshIP();
restart.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
restartApp(MainActivity.this);
refreshIP();
}
});


}

public static void restartApp(Activity activity) {
Intent intent = activity.getPackageManager()
.getLaunchIntentForPackage(activity.getPackageName());


public void refreshIP() {
NetworkUtils nu = new NetworkUtils();
final String ipaddr = nu.getLocalIpAddress();

ipaddress.setOnClickListener(new View.OnClickListener() {

if (intent != null) {
activity.finish();
activity.startActivity(intent);
}
@Override
public void onClick(View view) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (ipaddr != null){
ClipData clip = ClipData.newPlainText("Copied Text", ipaddr);
clipboard.setPrimaryClip(clip);}
else{
ClipData clip = ClipData.newPlainText("Copied Text", "127.0.0.1");
clipboard.setPrimaryClip(clip);
}
}
});

if (ipaddr == null){
ipaddress.setText("127.0.0.1");
warnt.setText("Turn on mobile hotspot and press refresh");
}
else{
ipaddress.setText(ipaddr);
warnt.setText("");
}

}

}
Expand All @@ -85,8 +99,9 @@ public static String getLocalIpAddress() {
}
}
}
} catch (Exception e) {
MainActivity.warnt.setText(e.getMessage());
}
catch (Exception e) {
return null;
}

return null;
Expand Down
Binary file added app/src/main/res/drawable/ic_launcher_back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:id="@+id/ipaddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="127.0.0.1"
android:text=""
android:textIsSelectable="true"
android:fontFamily="monospace" />

Expand All @@ -63,7 +63,7 @@
android:layout_marginLeft="10.0dip"
android:layout_marginRight="10.0dip"
android:layout_marginBottom="10.0dip"
android:text="Restart" />
android:text="@string/refresh" />

<TextView
android:layout_width="fill_parent"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<foreground android:drawable="@drawable/ic_launcher"/>
<background android:drawable="@drawable/ic_launcher_back"/>
<monochrome android:drawable="@mipmap/ic_launcher_monet"/>
</adaptive-icon>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<string name="app_name">IP Finder</string>
<string name="credit">Developed by ShuhaibNC</string>
<string name="refresh">Refresh</string>
</resources>

0 comments on commit 115af14

Please sign in to comment.