Skip to content

Commit

Permalink
Adds a menu to show license and about information (#39)
Browse files Browse the repository at this point in the history
* Adds a menu to show license and about information

* Add additional information to About section of the menu

* Add auto-generated list of licenses

* Add scrollbar to handle overflow

* Add Github project link

* Add description
  • Loading branch information
dsilhavy authored Sep 12, 2023
1 parent 29672ea commit a9630cd
Show file tree
Hide file tree
Showing 30 changed files with 747 additions and 33 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id("com.google.android.gms.oss-licenses-plugin")
}

android {
Expand All @@ -12,7 +13,7 @@ android {
minSdk 29
targetSdk 33
versionCode 1
versionName "1.0.2"
versionName "1.0.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -21,6 +22,7 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
compileOptions {
Expand All @@ -33,11 +35,11 @@ android {
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation("com.google.android.gms:play-services-oss-licenses:17.0.1")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.5GMSMediaSessionHandler"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".AboutActivity"
android:exported="false" />
<activity
android:name=".LicenseActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
Expand All @@ -29,8 +35,9 @@
android:name="android.app.lib_name"
android:value="" />
</activity>

<service
android:name="com.fivegmag.a5gmsmediasessionhandler.MediaSessionHandlerMessengerService"
android:name=".MediaSessionHandlerMessengerService"
android:exported="true">
<intent-filter>
<action android:name="com.fivegmag.a5gmsmediasessionhandler.Service" />
Expand Down
121 changes: 121 additions & 0 deletions app/src/main/java/com/fivegmag/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.fivegmag

import android.app.AlertDialog
import android.content.Intent
import android.net.Uri
import android.text.Html
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity;
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.fivegmag.a5gmsmediasessionhandler.R


open class BaseActivity : AppCompatActivity() {

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.actionLicense -> {
val dialogView = LayoutInflater.from(this).inflate(R.layout.activity_license, null)
val textView = dialogView.findViewById<TextView>(R.id.licenseTextView)
val formattedText = getString(R.string.license_text)
textView.text = Html.fromHtml(formattedText, Html.FROM_HTML_MODE_LEGACY)
val builder = AlertDialog.Builder(this)
.setView(dialogView)
.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
}
val dialog = builder.create()
dialog.show()
return true
}

R.id.actionAbout -> {
val dialogView = LayoutInflater.from(this).inflate(R.layout.activity_about, null)
addVersionNumber(dialogView)
setClickListeners(dialogView)
formatAboutText(dialogView)
val builder = AlertDialog.Builder(this)
.setView(dialogView)
.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
}
val dialog = builder.create()
dialog.show()
return true
}

R.id.actionAttribution -> {
OssLicensesMenuActivity.setActivityTitle(getString(R.string.action_attribution_notice))
val licensesIntent = Intent(this, OssLicensesMenuActivity::class.java)
startActivity(licensesIntent)
return true
}

}
return super.onOptionsItemSelected(item)
}

private fun addVersionNumber(dialogView: View) {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
val versionName = packageInfo.versionName
val versionTextView = dialogView.findViewById<TextView>(R.id.versionNumberView)
val versionText = getString(R.string.version_text_field, versionName)
versionTextView.text = versionText
}

private fun setClickListeners(dialogView: View) {

val githubTextView = dialogView.findViewById<TextView>(R.id.githubLink)
githubTextView.setOnClickListener {
val url = getString(R.string.github_url)
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}

val twitterTextView = dialogView.findViewById<TextView>(R.id.twitterLink)
twitterTextView.setOnClickListener {
val url = getString(R.string.twitter_url)
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}

val linkedInView = dialogView.findViewById<TextView>(R.id.linkedInLink)
linkedInView.setOnClickListener {
val url = getString(R.string.linked_in_url)
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}

val slackView = dialogView.findViewById<TextView>(R.id.slackLink)
slackView.setOnClickListener {
val url = getString(R.string.slack_url)
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}

val websiteView = dialogView.findViewById<TextView>(R.id.websiteLink)
websiteView.setOnClickListener {
val url = getString(R.string.website_url)
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}
}

private fun formatAboutText(dialogView: View) {
val textView = dialogView.findViewById<TextView>(R.id.descriptionText)
val formattedText = getString(R.string.description_text)
textView.text = Html.fromHtml(formattedText, Html.FROM_HTML_MODE_LEGACY)
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.fivegmag.a5gmsmediasessionhandler

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class AboutActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.fivegmag.a5gmsmediasessionhandler

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class LicenseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_license)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,25 @@ import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import com.fivegmag.BaseActivity

const val TAG_MEDIA_SESSION_HANDLER = "5GMS Media Session Handler"

class MainActivity : AppCompatActivity() {
class MainActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setApplicationVersionNumber()
setSupportActionBar(findViewById(R.id.toolbar))
printDependenciesVersionNumbers()
}

private fun setApplicationVersionNumber() {
try {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
val versionName = packageInfo.versionName
val versionTextView = findViewById<TextView>(R.id.versionNumber)
val versionText = getString(R.string.versionTextField, versionName)
versionTextView.text = versionText
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
}

private fun printDependenciesVersionNumbers() {
Log.d(TAG_MEDIA_SESSION_HANDLER, "5GMS Common Library Version: ${BuildConfig.LIB_VERSION_a5gmscommonlibrary}")
Log.d(
TAG_MEDIA_SESSION_HANDLER,
"5GMS Common Library Version: ${BuildConfig.LIB_VERSION_a5gmscommonlibrary}"
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_action_slack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_action_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_action_slack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_action_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_action_slack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_action_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_action_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/github_mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a9630cd

Please sign in to comment.