mirror of
https://github.com/M66B/NetGuard.git
synced 2025-03-10 06:03:10 +00:00
Added copy challenge
This commit is contained in:
parent
b2fa5a69ac
commit
c915d770f2
3 changed files with 83 additions and 13 deletions
|
@ -20,6 +20,9 @@ package eu.faircode.netguard;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -37,12 +40,16 @@ import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.NavUtils;
|
import androidx.core.app.NavUtils;
|
||||||
|
|
||||||
|
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
|
||||||
|
|
||||||
public class ActivityPro extends AppCompatActivity {
|
public class ActivityPro extends AppCompatActivity {
|
||||||
private static final String TAG = "NetGuard.Pro";
|
private static final String TAG = "NetGuard.Pro";
|
||||||
|
|
||||||
|
@ -288,17 +295,28 @@ public class ActivityPro extends AppCompatActivity {
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||||
String challenge = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? Build.SERIAL : "O3" + android_id);
|
final String challenge = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? Build.SERIAL : "O3" + android_id);
|
||||||
String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "NetGuard2" : "NetGuard3");
|
String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "NetGuard2" : "NetGuard3");
|
||||||
|
|
||||||
// Challenge
|
// Challenge
|
||||||
TextView tvChallenge = view.findViewById(R.id.tvChallenge);
|
TextView tvChallenge = view.findViewById(R.id.tvChallenge);
|
||||||
tvChallenge.setText(challenge);
|
tvChallenge.setText(challenge);
|
||||||
|
|
||||||
|
ImageButton ibCopy = view.findViewById(R.id.ibCopy);
|
||||||
|
ibCopy.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = ClipData.newPlainText(getString(R.string.title_pro_challenge), challenge);
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
Toast.makeText(ActivityPro.this, android.R.string.copy, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Response
|
// Response
|
||||||
|
final EditText etResponse = view.findViewById(R.id.etResponse);
|
||||||
try {
|
try {
|
||||||
final String response = Util.md5(challenge, seed);
|
final String response = Util.md5(challenge, seed);
|
||||||
EditText etResponse = view.findViewById(R.id.etResponse);
|
|
||||||
etResponse.addTextChangedListener(new TextWatcher() {
|
etResponse.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
@ -324,6 +342,20 @@ public class ActivityPro extends AppCompatActivity {
|
||||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageButton ibPaste = view.findViewById(R.id.ibPaste);
|
||||||
|
ibPaste.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
if (clipboard != null &&
|
||||||
|
clipboard.hasPrimaryClip() &&
|
||||||
|
clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
|
||||||
|
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
|
||||||
|
etResponse.setText(item.getText().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
app/src/main/res/drawable/baseline_file_copy_24.xml
Normal file
10
app/src/main/res/drawable/baseline_file_copy_24.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM15,5l6,6v10c0,1.1 -0.9,2 -2,2L7.99,23C6.89,23 6,22.1 6,21l0.01,-14c0,-1.1 0.89,-2 1.99,-2h7zM14,12h5.5L14,6.5L14,12z"/>
|
||||||
|
</vector>
|
|
@ -20,15 +20,29 @@
|
||||||
android:text="@string/title_pro_challenge"
|
android:text="@string/title_pro_challenge"
|
||||||
android:textAppearance="@style/TextMedium" />
|
android:textAppearance="@style/TextMedium" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvChallenge"
|
android:id="@+id/tvChallenge"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
android:text="@string/title_pro_challenge"
|
android:text="@string/title_pro_challenge"
|
||||||
android:textAppearance="@style/TextMedium"
|
android:textAppearance="@style/TextMedium"
|
||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/ibCopy"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:src="@drawable/baseline_file_copy_24" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -36,11 +50,25 @@
|
||||||
android:text="@string/title_pro_reponse"
|
android:text="@string/title_pro_reponse"
|
||||||
android:textAppearance="@style/TextMedium" />
|
android:textAppearance="@style/TextMedium" />
|
||||||
|
|
||||||
<EditText
|
<LinearLayout
|
||||||
android:id="@+id/etResponse"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etResponse"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
android:importantForAccessibility="no"
|
android:importantForAccessibility="no"
|
||||||
android:inputType="text" />
|
android:inputType="text" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/ibPaste"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:src="@drawable/baseline_file_copy_24" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
Loading…
Add table
Reference in a new issue