Skip to content

Commit

Permalink
add lib usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aabolfazl committed Mar 6, 2022
1 parent 9c6e9a0 commit 87148cc
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation project(path: ':filelogger')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="abbasi.android.filelogger.sample">

<uses-permission android:name="android.permission.WRITE_PROFILE" />
<uses-permission android:name="android.permission.READ_PROFILE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/abbasi/android/filelogger/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
package abbasi.android.filelogger.sample

import abbasi.android.filelogger.FileLogger
import abbasi.android.filelogger.config.Config
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

findViewById<Button>(R.id.init).setOnClickListener {
applicationContext.getExternalFilesDir(null)?.let {
val config = Config.Builder(it.path)
.setDefaultTag("TAG")
.setLogcatEnable(true)
.build()

FileLogger.init(config)
}
}

findViewById<Button>(R.id.writeNormalLog).setOnClickListener {
FileLogger.i("Custom", "This is normal Log with custom TAG")
FileLogger.i(msg = "This is normal Info Log")
FileLogger.d(msg = "This is normal Debug Log")
FileLogger.w(msg = "This is normal Warning Log")
FileLogger.e(msg = "This is normal Error Log")
}

findViewById<Button>(R.id.writeExceptionLog).setOnClickListener {
try {
findViewById<ImageView>(R.id.writeNormalLog).imageAlpha // just for happening exception
} catch (e: Exception) {
FileLogger.e(msg = "This is normal Log with custom TAG", throwable = e)
}
}

findViewById<Button>(R.id.deleteLogs).setOnClickListener {
FileLogger.deleteFiles()
}

}
}
66 changes: 60 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,67 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
<Button
android:id="@+id/init"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="Init"
android:textAllCaps="false"
app:layout_constraintBottom_toTopOf="@+id/writeNormalLog"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed" />

<Button
android:id="@+id/writeNormalLog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="Write Log"
android:textAllCaps="false"
app:layout_constraintBottom_toTopOf="@+id/writeExceptionLog"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/init" />

<Button
android:id="@+id/writeExceptionLog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="Write exception log"
android:textAllCaps="false"
app:layout_constraintBottom_toTopOf="@+id/deleteLogs"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/writeNormalLog" />

<Button
android:id="@+id/deleteLogs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="Delete Logs"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/writeExceptionLog" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 87148cc

Please sign in to comment.