Skip to content

Instantly share code, notes, and snippets.

@takke
Last active September 30, 2020 02:56
Show Gist options
  • Save takke/4282262af2fd10b3f5a8711e8a60a518 to your computer and use it in GitHub Desktop.
Save takke/4282262af2fd10b3f5a8711e8a60a518 to your computer and use it in GitHub Desktop.
Lossless Video Cutter の LicenseActivity の実装
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text"
android:textIsSelectable="true"
android:layout_margin="@dimen/padding_medium"
/>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
...
<application>
...
<activity
android:name=".LicenseActivity"
android:label="@string/open_source_libraries"
/>
...
</manifest>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package jp.takke.videocutter
import android.annotation.SuppressLint
import android.graphics.Typeface
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import androidx.appcompat.app.AppCompatActivity
import jp.takke.videocutter.databinding.ActivityLicenseBinding
import java.io.BufferedReader
import java.io.InputStreamReader
class LicenseActivity : AppCompatActivity() {
private lateinit var binding: ActivityLicenseBinding
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//--------------------------------------------------
// ViewBinding初期化
//--------------------------------------------------
binding = ActivityLicenseBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.text.text = SpannableStringBuilder().apply {
addLicenseItem(this, "Android About Page", "AndroidAboutPage")
addLicenseItem(this, "Java MP4 Parser", "mp4parser")
addLicenseItem(this, "ExoPlayer", "ExoPlayer")
addLicenseItem(this, "Crystal Range Seekbar", "CrystalRangeSeekbar")
addLicenseItem(this, "PermissionsDispatcher", "PermissionsDispatcher")
}
}
private fun addLicenseItem(ssb: SpannableStringBuilder, title: String, licenseFileName: String) {
val start = ssb.length
ssb.append(title)
ssb.setSpan(StyleSpan(Typeface.BOLD), start, ssb.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
ssb.setSpan(RelativeSizeSpan(1.2f), start, ssb.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
ssb.append("\n\n")
ssb.append(readLicenseFile(licenseFileName))
ssb.append("\n\n")
}
private fun readLicenseFile(licenseFileName: String): String {
BufferedReader(InputStreamReader(assets.open("license/$licenseFileName"))).use {
return it.readText()
}
}
}
@takke
Copy link
Author

takke commented Sep 30, 2020

実行結果

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment