Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timber to sample #628

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions stetho-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ android {
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
// release target excludes Stetho for illustration purposes.
// See dependencies for instructions on how Stetho developers
Expand All @@ -29,6 +34,8 @@ android {

dependencies {
implementation project(':stetho')
implementation project(':stetho-timber')
implementation 'com.jakewharton.timber:timber:4.1.2'
implementation project(':stetho-urlconnection')

// Uncomment if you wish to play with the Console evaluation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import com.facebook.stetho.inspector.database.ContentProviderSchema;
import com.facebook.stetho.inspector.database.ContentProviderSchema.Table;
import com.facebook.stetho.inspector.protocol.ChromeDevtoolsDomain;
import com.facebook.stetho.timber.StethoTree;

import timber.log.Timber;

public class SampleDebugApplication extends SampleApplication {
private static final String TAG = "SampleDebugApplication";
Expand All @@ -31,6 +34,7 @@ public class SampleDebugApplication extends SampleApplication {
public void onCreate() {
super.onCreate();

Timber.plant(new StethoTree());
long startTime = SystemClock.elapsedRealtime();
initializeStetho(this);
long elapsed = SystemClock.elapsedRealtime() - startTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import android.view.View;
import android.widget.Toast;

import timber.log.Timber;

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -33,10 +35,25 @@ protected void onCreate(Bundle savedInstanceState) {
.show();
}

findViewById(R.id.settings_btn).setOnClickListener(mMainButtonClicked);
findViewById(R.id.apod_btn).setOnClickListener(mMainButtonClicked);
findViewById(R.id.irc_btn).setOnClickListener(mMainButtonClicked);
findViewById(R.id.about).setOnClickListener(mMainButtonClicked);
findViewById(R.id.log_btn).setOnClickListener(v -> {
Timber.i("log button clicked");
});
findViewById(R.id.settings_btn).setOnClickListener(v -> {
SettingsActivity.show(MainActivity.this);
});
findViewById(R.id.apod_btn).setOnClickListener(v -> {
APODActivity.show(MainActivity.this);
});
findViewById(R.id.irc_btn).setOnClickListener(v -> {
IRCConnectActivity.show(MainActivity.this);
});
findViewById(R.id.about).setOnClickListener(v -> {
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_layout, null);
Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(view);
dialog.setTitle(getString(R.string.app_name));
dialog.show();
});
}

private static boolean isStethoPresent() {
Expand Down Expand Up @@ -64,26 +81,6 @@ private SharedPreferences getPrefs() {
return PreferenceManager.getDefaultSharedPreferences(this /* context */);
}

private final View.OnClickListener mMainButtonClicked = new View.OnClickListener() {
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.settings_btn) {
SettingsActivity.show(MainActivity.this);
} else if (id == R.id.apod_btn) {
APODActivity.show(MainActivity.this);
} else if (id == R.id.irc_btn) {
IRCConnectActivity.show(MainActivity.this);
} else if (id == R.id.about) {
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_layout, null);
Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(view);
dialog.setTitle(getString(R.string.app_name));
dialog.show();
}
}
};

private final SharedPreferences.OnSharedPreferenceChangeListener mToastingPrefListener =
new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
Expand Down
8 changes: 8 additions & 0 deletions stetho-sample/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
android:gravity="center_horizontal"
android:padding="15dp">

<Button
android:id="@+id/log_btn"
android:text="@string/log_btn"
android:layout_width="@dimen/main_button_width"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
/>

<Button
android:id="@+id/settings_btn"
android:text="@string/settings_btn"
Expand Down
1 change: 1 addition & 0 deletions stetho-sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<resources>
<string name="app_name">Stetho Sample</string>
<string name="log_btn">Log</string>
<string name="settings_btn">Settings</string>
<string name="apod_btn">APOD RSS Feed</string>
<string name="irc_btn">IRC Client</string>
Expand Down