Skip to content

Commit a72475e

Browse files
committed
pty效果完成
1 parent bcbaf17 commit a72475e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6767
-5866
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
*auto-save*
1111
credentials/*
1212
secring.gpg
13-
*/build
13+
*/build
14+
/*_dir

LottieTest/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="cn.cong.lottietest">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7+
58
<application
69
android:allowBackup="true"
710
android:icon="@mipmap/ic_launcher"
811
android:label="@string/app_name"
12+
android:networkSecurityConfig="@xml/network_security_config"
913
android:roundIcon="@mipmap/ic_launcher_round"
1014
android:supportsRtl="true"
1115
android:theme="@style/AppTheme">
@@ -15,6 +19,23 @@
1519

1620
<category android:name="android.intent.category.LAUNCHER" />
1721
</intent-filter>
22+
<intent-filter>
23+
<action android:name="android.intent.action.VIEW" />
24+
25+
<category android:name="android.intent.category.DEFAULT" />
26+
<category android:name="android.intent.category.BROWSABLE" />
27+
28+
<data
29+
android:host="*"
30+
android:mimeType="application/*"
31+
android:pathPattern=".*\\.json"
32+
android:scheme="content" />
33+
<data
34+
android:host="*"
35+
android:mimeType="application/*"
36+
android:pathPattern=".*\\.json"
37+
android:scheme="file" />
38+
</intent-filter>
1839
</activity>
1940
</application>
2041

LottieTest/src/main/assets/狐狸气泡左.json

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,99 @@
11
package cn.cong.lottietest
22

3-
import android.support.v7.app.AppCompatActivity
3+
import android.Manifest
4+
import android.content.Intent
5+
import android.net.Uri
46
import android.os.Bundle
7+
import android.provider.MediaStore
8+
import android.provider.OpenableColumns
9+
import android.support.v7.app.AppCompatActivity
10+
import android.widget.SeekBar
11+
import android.widget.TextView
12+
import android.widget.Toast
13+
import com.airbnb.lottie.LottieAnimationView
14+
import kotlinx.android.synthetic.main.activity_main.*
15+
import java.io.File
16+
import java.io.FileInputStream
17+
import java.io.FileOutputStream
18+
519

620
class MainActivity : AppCompatActivity() {
721

22+
private var file: File? = null
23+
824
override fun onCreate(savedInstanceState: Bundle?) {
925
super.onCreate(savedInstanceState)
1026
setContentView(R.layout.activity_main)
27+
28+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
29+
requestPermissions(arrayOf(Manifest.permission_group.STORAGE), 1)
30+
}
31+
32+
intent?.data?.let { dealFileFrom(it) }
33+
34+
seek.setOnSeekBarChangeListener(SeekListener(tv, lov))
35+
seek.max = 20
36+
lov.setBackgroundResource(android.R.color.holo_green_light)
37+
seek.progress = 0
38+
lov.setSizeChangeListener { dealLoadAnim() }
39+
tv.minEms = 4 // 最小宽度
40+
bt.setOnClickListener {
41+
val intent = Intent(Intent.ACTION_GET_CONTENT)
42+
intent.type = "*/*" //设置类型,我这里是任意类型,任意后缀的可以这样写。
43+
intent.addCategory(Intent.CATEGORY_OPENABLE)
44+
startActivityForResult(intent, 1)
45+
}
46+
}
47+
48+
private fun dealLoadAnim() {
49+
if (file == null) lov.setAnimation("狐狸气泡左.json") else lov.setAnimation(FileInputStream(file), null)
50+
lov.playAnimation()
51+
}
52+
53+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
54+
super.onActivityResult(requestCode, resultCode, data)
55+
if (requestCode == 1 && resultCode == RESULT_OK) { //是否选择,没选择就不会继续
56+
val uri = data?.data ?: return //得到uri,后面就是将uri转化成file的过程。
57+
// Log.d("TAG", "onActivityResult: $uri")
58+
dealFileFrom(uri)
59+
}
60+
61+
}
62+
63+
private fun dealFileFrom(uri: Uri) {
64+
// Log.d("TAG", "dealFileFrom: $uri")
65+
contentResolver.query(uri, arrayOf(MediaStore.Images.Media.DATA, OpenableColumns.DISPLAY_NAME), null, null, null)?.use { cs ->
66+
if (cs.moveToNext()) {
67+
val path = cs.getString(cs.getColumnIndexOrThrow(MediaStore.Images.Media.DATA))
68+
val name = cs.getString(cs.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
69+
// Log.d("TAG", "dealFileFrom: $name : $path")
70+
if (path == null) contentResolver.openInputStream(uri)?.use { fis ->
71+
val f = File(cacheDir, name ?: "${System.currentTimeMillis()}")
72+
FileOutputStream(f).use { fos ->
73+
fos.write(fis.readBytes())
74+
file = f
75+
dealLoadAnim()
76+
}
77+
}
78+
else {
79+
file = File(path)
80+
Toast.makeText(this@MainActivity, "文件:${file?.name}", Toast.LENGTH_SHORT).show()
81+
dealLoadAnim()
82+
}
83+
}
84+
}
85+
}
86+
87+
class SeekListener(private val tv: TextView, private val lov: LottieAnimationView) : SeekBar.OnSeekBarChangeListener {
88+
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
89+
// if (!fromUser) return
90+
tv.text = StringBuilder().apply { for (i in 0 until progress) append("这是一段测试文字\t").append(i).append("\t") }
91+
}
92+
93+
override fun onStartTrackingTouch(seekBar: SeekBar?) {
94+
}
95+
96+
override fun onStopTrackingTouch(seekBar: SeekBar?) {
97+
}
1198
}
1299
}

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

+40-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,49 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:orientation="vertical"
78
tools:context=".MainActivity">
89

9-
<TextView
10+
<android.support.constraint.ConstraintLayout
1011
android:layout_width="wrap_content"
1112
android:layout_height="wrap_content"
12-
android:text="Hello World!"
13-
app:layout_constraintBottom_toBottomOf="parent"
14-
app:layout_constraintLeft_toLeftOf="parent"
15-
app:layout_constraintRight_toRightOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
13+
app:layout_constraintBottom_toTopOf="@id/seek"
14+
app:layout_constraintEnd_toEndOf="parent"
15+
app:layout_constraintStart_toStartOf="parent"
16+
app:layout_constraintTop_toTopOf="parent">
17+
18+
<com.airbnb.lottie.LottieAnimationView
19+
android:id="@+id/lov"
20+
android:layout_width="0dp"
21+
android:layout_height="0dp"
22+
app:layout_constraintBottom_toBottomOf="@id/tv"
23+
app:layout_constraintEnd_toEndOf="@id/tv"
24+
app:layout_constraintStart_toStartOf="@id/tv"
25+
app:layout_constraintTop_toTopOf="@id/tv"
26+
app:lottie_loop="true" />
27+
28+
<TextView
29+
android:id="@+id/tv"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:padding="20dp"
33+
android:textColor="@android:color/tertiary_text_light"
34+
android:textSize="20sp"
35+
tools:text="测试文字" />
36+
37+
</android.support.constraint.ConstraintLayout>
38+
39+
<Button
40+
android:id="@+id/bt"
41+
android:layout_width="wrap_content"
42+
android:layout_height="wrap_content"
43+
android:text="选择文件" />
44+
45+
<SeekBar
46+
android:id="@+id/seek"
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:padding="16dp"
50+
app:layout_constraintBottom_toBottomOf="parent" />
1751

1852
</android.support.constraint.ConstraintLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<base-config cleartextTrafficPermitted="true" />
4+
</network-security-config>

0 commit comments

Comments
 (0)