Skip to content

Commit e430220

Browse files
Getting address With toast
1 parent 7d67e8b commit e430220

4 files changed

Lines changed: 67 additions & 6 deletions

File tree

app/src/main/java/com/sample/MainActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import android.os.Bundle;
2626
import android.preference.PreferenceManager;
2727
import android.support.v7.app.AppCompatActivity;
28+
import android.view.View;
2829

2930
import com.sample.database.CarDBHelper;
3031
import com.sample.database.ContactDBHelper;
32+
import com.sample.utils.Utils;
3133

3234
import java.util.HashSet;
3335
import java.util.Set;
@@ -85,4 +87,8 @@ protected void onCreate(Bundle savedInstanceState) {
8587
}
8688
}
8789
}
90+
91+
public void showDebugDbAddress(View view) {
92+
Utils.showDebugDBAddressLogToast(getApplicationContext());
93+
}
8894
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* * Copyright (C) 2016 Amit Shekhar
4+
* * Copyright (C) 2011 Android Open Source Project
5+
* *
6+
* * Licensed under the Apache License, Version 2.0 (the "License");
7+
* * you may not use this file except in compliance with the License.
8+
* * You may obtain a copy of the License at
9+
* *
10+
* * http://www.apache.org/licenses/LICENSE-2.0
11+
* *
12+
* * Unless required by applicable law or agreed to in writing, software
13+
* * distributed under the License is distributed on an "AS IS" BASIS,
14+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* * See the License for the specific language governing permissions and
16+
* * limitations under the License.
17+
*
18+
*/
19+
20+
package com.sample.utils;
21+
22+
import android.content.Context;
23+
import android.widget.Toast;
24+
25+
import com.sample.BuildConfig;
26+
27+
import java.lang.reflect.Method;
28+
29+
/**
30+
* Created by amitshekhar on 07/02/17.
31+
*/
32+
33+
public class Utils {
34+
35+
private Utils() {
36+
37+
}
38+
39+
public static void showDebugDBAddressLogToast(Context context) {
40+
if (BuildConfig.DEBUG) {
41+
try {
42+
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
43+
Method getAddressLog = debugDB.getMethod("getAddressLog");
44+
Object value = getAddressLog.invoke(null);
45+
Toast.makeText(context, (String) value, Toast.LENGTH_LONG).show();
46+
} catch (Exception ignore) {
47+
48+
}
49+
}
50+
}
51+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
1+
<?xml version="1.0" encoding="utf-8"?><!--
32
~ /*
43
~ * Copyright (C) 2016 Amit Shekhar
54
~ * Copyright (C) 2011 Android Open Source Project
@@ -18,7 +17,7 @@
1817
~ */
1918
-->
2019

21-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
20+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2221
xmlns:tools="http://schemas.android.com/tools"
2322
android:id="@+id/activity_main"
2423
android:layout_width="match_parent"
@@ -29,8 +28,12 @@
2928
android:paddingTop="@dimen/activity_vertical_margin"
3029
tools:context="com.sample.MainActivity">
3130

32-
<TextView
31+
<Button
3332
android:layout_width="wrap_content"
3433
android:layout_height="wrap_content"
35-
android:text="Hello World!" />
36-
</RelativeLayout>
34+
android:textColor="@android:color/black"
35+
android:onClick="showDebugDbAddress"
36+
android:layout_gravity="center"
37+
android:text="@string/show_debug_db_address" />
38+
39+
</FrameLayout>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919

2020
<resources>
2121
<string name="app_name">Android-Debug-Database</string>
22+
<string name="show_debug_db_address">Show Debug Db Address</string>
2223
</resources>

0 commit comments

Comments
 (0)