Skip to content

Commit 28d7355

Browse files
committed
add example
1 parent a042087 commit 28d7355

28 files changed

+730
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
.DS_Store
55
/build
66
/debugger/build
7-
/example
87
/captures
98
.externalNativeBuild
109
local.properties

example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

example/build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 30
5+
defaultConfig {
6+
applicationId "zerobranch.example"
7+
minSdkVersion 19
8+
targetSdkVersion 30
9+
versionCode 1
10+
versionName "1.0"
11+
}
12+
buildTypes {
13+
release {
14+
minifyEnabled true
15+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16+
}
17+
}
18+
19+
compileOptions {
20+
sourceCompatibility JavaVersion.VERSION_1_8
21+
targetCompatibility JavaVersion.VERSION_1_8
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
implementation 'androidx.appcompat:appcompat:1.2.0'
28+
implementation project(":debugger")
29+
implementation "com.squareup.okhttp3:okhttp:4.9.0"
30+
implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
31+
}

example/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="zerobranch.example">
4+
5+
<application
6+
android:name="zerobranch.example.App"
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:networkSecurityConfig="@xml/network_security_config"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name="zerobranch.example.MainActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN"/>
17+
18+
<category android:name="android.intent.category.LAUNCHER"/>
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package zerobranch.example;
2+
3+
import android.app.Application;
4+
5+
public class App extends Application {
6+
7+
@Override
8+
public void onCreate() {
9+
super.onCreate();
10+
}
11+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package zerobranch.example;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
import android.os.Bundle;
6+
import android.preference.PreferenceManager;
7+
import androidx.appcompat.app.AppCompatActivity;
8+
9+
import zerobranch.example.db.DBHelper;
10+
import zerobranch.androidremotedebugger.AndroidRemoteDebugger;
11+
import zerobranch.androidremotedebugger.logging.NetLoggingInterceptor;
12+
13+
import java.io.IOException;
14+
import java.util.HashSet;
15+
import java.util.Set;
16+
17+
import okhttp3.MediaType;
18+
import okhttp3.OkHttpClient;
19+
import okhttp3.Request;
20+
import okhttp3.RequestBody;
21+
import okhttp3.Response;
22+
23+
public class MainActivity extends AppCompatActivity {
24+
DBHelper dbHelper;
25+
26+
@Override
27+
protected void onCreate(Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
dbHelper = new DBHelper(getApplicationContext());
30+
31+
setContentView(R.layout.activity_main);
32+
AndroidRemoteDebugger.init(
33+
new AndroidRemoteDebugger.Builder(this)
34+
.enabled(true)
35+
.enableDuplicateLogging()
36+
.build()
37+
);
38+
39+
findViewById(R.id.verbose).setOnClickListener(v -> {
40+
AndroidRemoteDebugger.Log.v("tag", "This is a simple message.");
41+
});
42+
43+
findViewById(R.id.info).setOnClickListener(v -> {
44+
AndroidRemoteDebugger.Log.i("tag", "This is an info message.");
45+
});
46+
47+
findViewById(R.id.debug).setOnClickListener(v -> {
48+
AndroidRemoteDebugger.Log.d("tag", "This is a debug message.");
49+
});
50+
51+
findViewById(R.id.warn).setOnClickListener(v -> {
52+
AndroidRemoteDebugger.Log.w("tag", "This is a warning message.");
53+
});
54+
55+
findViewById(R.id.error).setOnClickListener(v -> {
56+
AndroidRemoteDebugger.Log.e("tag", "This error message");
57+
});
58+
59+
findViewById(R.id.fatal).setOnClickListener(v -> {
60+
AndroidRemoteDebugger.Log.wtf("tag", "This is a fatal message.");
61+
int a = 1 / 0;
62+
});
63+
64+
65+
findViewById(R.id.flavor).setOnClickListener(v -> {
66+
// dbHelper.insertFlavor();
67+
// AndroidRemoteDebugger.stop();
68+
// dbHelper.insertFlavor();
69+
70+
Set<String> integers = new HashSet<>();
71+
integers.add("100");
72+
integers.add("1001");
73+
integers.add("10032");
74+
integers.add("910024");
75+
76+
SharedPreferences sharedPref = getSharedPreferences("test_preference", Context.MODE_PRIVATE);
77+
sharedPref.edit().putInt("key_2", 123).apply();
78+
sharedPref.edit().putBoolean("key_3", false).apply();
79+
sharedPref.edit().putFloat("key_4", 4.2f).apply();
80+
sharedPref.edit().putLong("key_5", 123L).apply();
81+
sharedPref.edit().putStringSet("key_5", integers).apply();
82+
83+
SharedPreferences sharedPref1 = getSharedPreferences("QWE_PREF_2", Context.MODE_PRIVATE);
84+
sharedPref1.edit().putString("key_21", "value_21").apply();
85+
86+
SharedPreferences sharedPref2 = getSharedPreferences("QWE_PREF_3", Context.MODE_PRIVATE);
87+
sharedPref2.edit().putString("key_31", "value_31").apply();
88+
89+
SharedPreferences sharedPref3 = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
90+
sharedPref3.edit().putString("key_31", "value_31").apply();
91+
});
92+
93+
findViewById(R.id.network1).setOnClickListener(v -> {
94+
send("http://www.mocky.io/v2/5dfa87362f00006700ff9a18"); // link and query
95+
});
96+
97+
findViewById(R.id.network2).setOnClickListener(v -> {
98+
send("http://www.mocky.io/v2/5dfa884b2f00007200ff9a22"); // difficult link
99+
});
100+
101+
// findViewById(R.id.network3).setOnClickListener(v -> {
102+
// send("http://www.mocky.io/v2/5d79ff7a320000749834ec26"); // empty
103+
// });
104+
//
105+
// findViewById(R.id.network4).setOnClickListener(v -> {
106+
// send("http://www.mocky.io/v2/5d7bcf0a350000a96f3cadea"); // just link
107+
// });
108+
//
109+
// findViewById(R.id.network5).setOnClickListener(v -> {
110+
// send("http://www.mocky.io/v2/5d90d3f63000002b00cacfe2"); // error
111+
// });
112+
}
113+
114+
private void send(String url) {
115+
new Thread(() -> {
116+
OkHttpClient client = new OkHttpClient.Builder()
117+
.addInterceptor(new NetLoggingInterceptor())
118+
.build();
119+
120+
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"name\": \"Mercury\", \"radius\": 2439.7}");
121+
Request request = new Request.Builder()
122+
.url(url)
123+
.post(body)
124+
.addHeader("Api-key", "jfp74mvnWRQWRQWRf83Tls3j")
125+
.addHeader("Token", "hdsjJ7f3Hkd7EWTHSDV32hfGJSAj72l")
126+
.addHeader("DeviceId", "whs67DFSWE2gjfDADSUg4")
127+
.build();
128+
129+
try {
130+
Response response = client
131+
.newCall(request)
132+
.execute();
133+
System.out.println(response.body().string());
134+
} catch (IOException e) {
135+
// e.printStackTrace();
136+
}
137+
}).start();
138+
}
139+
}
140+
141+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package zerobranch.example.db;
2+
3+
import android.content.ContentValues;
4+
import android.content.Context;
5+
import android.database.sqlite.SQLiteDatabase;
6+
import android.database.sqlite.SQLiteOpenHelper;
7+
8+
import java.util.Random;
9+
10+
public class DBHelper extends SQLiteOpenHelper {
11+
private final static int THIRD_VERSION = 20127;
12+
SQLiteDatabase db;
13+
14+
public DBHelper(Context context) {
15+
super(context, "test.db", null, THIRD_VERSION);
16+
}
17+
18+
@Override
19+
public void onCreate(SQLiteDatabase db) {
20+
this.db = db;
21+
// String user = "CREATE TABLE User (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, address TEXT);";
22+
// String flavors = "CREATE TABLE Flavor (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, description TEXT, age INTEGER);";
23+
// db.execSQL(user);
24+
// db.execSQL(flavors);
25+
// insertFlavor();
26+
}
27+
28+
@Override
29+
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
30+
System.out.println();
31+
}
32+
33+
public void insertUser() {
34+
SQLiteDatabase database = getWritableDatabase();
35+
36+
String user = "CREATE TABLE User (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, address INTEGER, sun real);";
37+
getWritableDatabase().execSQL(user);
38+
Random rnd = new Random();
39+
int rdnNumber = rnd.nextInt(10000);
40+
ContentValues cv = new ContentValues();
41+
cv.put("name", "name_" + rdnNumber);
42+
cv.put("address", rdnNumber);
43+
database.insert("User", null, cv);
44+
// database.close();
45+
}
46+
47+
public void insertFlavor() {
48+
SQLiteDatabase database = getWritableDatabase();
49+
String flavors = "CREATE TABLE Flavor (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, description TEXT, age INTEGER);";
50+
database.execSQL(flavors);
51+
52+
Random rnd = new Random();
53+
int rdnNumber = rnd.nextInt(10000);
54+
ContentValues cv = new ContentValues();
55+
cv.put("name", "name_" + rdnNumber);
56+
cv.put("description", "description_" + rdnNumber);
57+
cv.put("age", rdnNumber);
58+
database.insert("Flavor", null, cv);
59+
// database.close();
60+
}
61+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillType="evenOdd"
9+
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
10+
android:strokeColor="#00000000"
11+
android:strokeWidth="1">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="78.5885"
15+
android:endY="90.9159"
16+
android:startX="48.7653"
17+
android:startY="61.0927"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0"/>
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0"/>
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
32+
android:strokeColor="#00000000"
33+
android:strokeWidth="1"/>
34+
</vector>

0 commit comments

Comments
 (0)