Skip to content

Commit 537b870

Browse files
author
Your Name
committed
1. 增加x86支持
1 parent e1b3f68 commit 537b870

Some content is hidden

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

50 files changed

+1293
-150
lines changed

app/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 29
4+
compileSdkVersion 21
55
buildToolsVersion '27.0.3'
66
defaultConfig {
77
applicationId "com.coorchice.supertextview"
88
minSdkVersion 19
9-
targetSdkVersion 29
9+
targetSdkVersion 21
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -30,6 +30,7 @@ dependencies {
3030
implementation 'com.android.support:recyclerview-v7:21.0.3'
3131
implementation 'com.github.bumptech.glide:glide:3.7.0'
3232
implementation 'com.squareup.picasso:picasso:2.5.2'
33+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
3334
testImplementation 'junit:junit:4.12'
3435
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
3536
configurations.all {

app/src/main/AndroidManifest.xml

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.coorchice.supertextview">
2+
<manifest package="com.coorchice.supertextview"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
44

5-
<uses-permission android:name="android.permission.INTERNET" />
6-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
8-
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
9-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
10-
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
11-
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
12-
<uses-permission android:name="android.permission.READ_LOGS" />
5+
<application
6+
android:name=".STVApplication"
7+
android:allowBackup="true"
8+
android:icon="@drawable/app_icon2"
9+
android:label="@string/app_name"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".GifListActivity"></activity>
13+
<activity android:name=".GifActivity" />
14+
<activity android:name=".TestActivity" />
15+
<activity android:name=".MainActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
1318

14-
<application
15-
android:name=".STVApplication"
16-
android:allowBackup="true"
17-
android:icon="@drawable/app_icon2"
18-
android:label="@string/app_name"
19-
android:supportsRtl="true"
20-
android:theme="@style/AppTheme">
21-
<activity android:name=".TestActivity"></activity>
22-
<activity android:name=".MainActivity">
23-
<intent-filter>
24-
<action android:name="android.intent.action.MAIN" />
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
<activity android:name=".SecondActivity" />
23+
<activity
24+
android:name=".ThirdActivity"
25+
android:label="@string/title_activity_third"
26+
android:theme="@style/AppTheme.NoActionBar" />
27+
<activity android:name=".ListActivity" />
28+
</application>
29+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
30+
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
31+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
32+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
33+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
34+
<uses-permission android:name="android.permission.READ_LOGS" />
35+
<uses-permission android:name="android.permission.INTERNET" />
2536

26-
<category android:name="android.intent.category.LAUNCHER" />
27-
</intent-filter>
28-
</activity>
29-
<activity android:name=".SecondActivity"></activity>
30-
<activity
31-
android:name=".ThirdActivity"
32-
android:label="@string/title_activity_third"
33-
android:theme="@style/AppTheme.NoActionBar"></activity>
34-
<activity android:name=".ListActivity"></activity>
35-
</application>
37+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
3638

3739
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
package com.coorchice.supertextview;
2+
3+
import android.app.Activity;
4+
import android.graphics.Bitmap;
5+
import android.graphics.Canvas;
6+
import android.os.Bundle;
7+
import android.text.TextUtils;
8+
import android.view.View;
9+
import android.widget.EditText;
10+
import android.widget.Toast;
11+
12+
import com.coorchice.library.SuperTextView;
13+
import com.coorchice.library.gifdecoder.GifDrawable;
14+
import com.coorchice.library.utils.STVUtils;
15+
import com.coorchice.library.utils.ThreadPool;
16+
17+
public class GifActivity extends Activity {
18+
19+
private SuperTextView stvGifScreen;
20+
private SuperTextView stvPre;
21+
private SuperTextView stvPlay;
22+
private SuperTextView stvNext;
23+
private SuperTextView stvStrict;
24+
private SuperTextView stvScaleType;
25+
private EditText etFrameDuration;
26+
private SuperTextView stvFrameDuration;
27+
private EditText etGotoFrame;
28+
private SuperTextView stvGotoFrame;
29+
private EditText etGetFrame;
30+
private SuperTextView stvGetFrame;
31+
private SuperTextView stvShowFrame;
32+
private SuperTextView tvInfo;
33+
34+
private long gifMemory = 0;
35+
private long lastDrawTime = System.currentTimeMillis();
36+
37+
@Override
38+
protected void onCreate(Bundle savedInstanceState) {
39+
super.onCreate(savedInstanceState);
40+
setContentView(R.layout.activity_gif);
41+
initView();
42+
addListener();
43+
44+
}
45+
46+
private void initView() {
47+
stvGifScreen = (SuperTextView) findViewById(R.id.stv_gif_screen);
48+
stvPre = (SuperTextView) findViewById(R.id.stv_pre);
49+
stvPlay = (SuperTextView) findViewById(R.id.stv_play);
50+
stvNext = (SuperTextView) findViewById(R.id.stv_next);
51+
stvStrict = (SuperTextView) findViewById(R.id.stv_strict);
52+
stvScaleType = (SuperTextView) findViewById(R.id.stv_scale_type);
53+
etFrameDuration = (EditText) findViewById(R.id.et_frame_duration);
54+
stvFrameDuration = (SuperTextView) findViewById(R.id.stv_frame_duration);
55+
etGotoFrame = (EditText) findViewById(R.id.et_goto_frame);
56+
stvGotoFrame = (SuperTextView) findViewById(R.id.stv_goto_frame);
57+
etGetFrame = (EditText) findViewById(R.id.et_get_frame);
58+
stvGetFrame = (SuperTextView) findViewById(R.id.stv_get_frame);
59+
stvShowFrame = (SuperTextView) findViewById(R.id.stv_show_frame);
60+
tvInfo = (SuperTextView) findViewById(R.id.tv_info);
61+
62+
stvPlay.setSelected(true);
63+
ThreadPool.run(new Runnable() {
64+
@Override
65+
public void run() {
66+
byte[] resBytes = STVUtils.getResBytes(GifActivity.this, R.drawable.gif_m_7);
67+
gifMemory = resBytes.length / 1024;
68+
final GifDrawable drawable = GifDrawable.createDrawable(resBytes);
69+
runOnUiThread(new Runnable() {
70+
@Override
71+
public void run() {
72+
stvGifScreen.setDrawable(drawable);
73+
}
74+
});
75+
}
76+
});
77+
}
78+
79+
private void addListener() {
80+
stvGifScreen.setAutoAdjust(true);
81+
stvGifScreen.addAdjuster(new SuperTextView.Adjuster() {
82+
@Override
83+
protected void adjust(SuperTextView v, Canvas canvas) {
84+
if (stvGifScreen.getDrawable() instanceof GifDrawable) {
85+
GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
86+
StringBuilder sb = new StringBuilder()
87+
.append("gif memory : ").append(gifMemory / 1000).append("MB").append(gifMemory % 1000).append("KB\n")
88+
.append("ptr : ").append(gifDrawable.getPtr()).append("\n")
89+
.append("width : ").append(gifDrawable.getWidth()).append("\n")
90+
.append("height : ").append(gifDrawable.getHeight()).append("\n")
91+
.append("frame count : ").append(gifDrawable.getFrameCount()).append("\n")
92+
.append("frame duration : ").append(gifDrawable.getFrameDuration()).append("ms\n")
93+
// .append("rel frame duration : ").append(System.currentTimeMillis() - lastDrawTime).append("ms\n")
94+
.append("enable strict : ").append(gifDrawable.isStrict()).append("\n")
95+
.append("current frame : ").append(gifDrawable.getCurrentFrame());
96+
if (!(tvInfo.getText() != null && tvInfo.getText().toString().equals(sb.toString()))) {
97+
tvInfo.setText(sb);
98+
}
99+
lastDrawTime = System.currentTimeMillis();
100+
}
101+
}
102+
}.setOpportunity(SuperTextView.Adjuster.Opportunity.AT_LAST));
103+
104+
stvScaleType.setOnClickListener(new View.OnClickListener() {
105+
@Override
106+
public void onClick(View v) {
107+
switch (stvGifScreen.getScaleType()) {
108+
case FIT_XY:
109+
stvGifScreen.setScaleType(SuperTextView.ScaleType.FIT_CENTER);
110+
Toast.makeText(GifActivity.this, "ScaleType:FIT_CENTER", Toast.LENGTH_SHORT).show();
111+
break;
112+
case FIT_CENTER:
113+
stvGifScreen.setScaleType(SuperTextView.ScaleType.CENTER);
114+
Toast.makeText(GifActivity.this, "ScaleType:CENTER", Toast.LENGTH_SHORT).show();
115+
break;
116+
case CENTER:
117+
stvGifScreen.setScaleType(SuperTextView.ScaleType.FIT_XY);
118+
Toast.makeText(GifActivity.this, "ScaleType:FIT_XY", Toast.LENGTH_SHORT).show();
119+
break;
120+
}
121+
}
122+
});
123+
124+
stvPlay.setOnClickListener(new View.OnClickListener() {
125+
@Override
126+
public void onClick(View v) {
127+
stvPlay.setSelected(!stvPlay.isSelected());
128+
stvPlay.setDrawable(stvPlay.isSelected() ? R.drawable.icon_stop : R.drawable.icon_play);
129+
if (stvGifScreen.getDrawable() instanceof GifDrawable) {
130+
GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
131+
if (stvPlay.isSelected()) {
132+
gifDrawable.play();
133+
} else {
134+
gifDrawable.stop();
135+
}
136+
}
137+
}
138+
});
139+
140+
stvPre.setOnClickListener(new View.OnClickListener() {
141+
@Override
142+
public void onClick(View v) {
143+
if (stvGifScreen.getDrawable() instanceof GifDrawable) {
144+
GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
145+
int pre = gifDrawable.getCurrentFrame() - 1;
146+
if (pre < 0) {
147+
pre = 0;
148+
}
149+
gifDrawable.gotoFrame(pre);
150+
}
151+
}
152+
});
153+
154+
stvNext.setOnClickListener(new View.OnClickListener() {
155+
@Override
156+
public void onClick(View v) {
157+
if (stvGifScreen.getDrawable() instanceof GifDrawable) {
158+
GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
159+
int frameCount = gifDrawable.getFrameCount();
160+
int next = gifDrawable.getCurrentFrame() + 1;
161+
if (next >= frameCount) {
162+
next = frameCount - 1;
163+
}
164+
gifDrawable.gotoFrame(next);
165+
}
166+
}
167+
});
168+
169+
stvStrict.setOnClickListener(new View.OnClickListener() {
170+
@Override
171+
public void onClick(View v) {
172+
if (stvGifScreen.getDrawable() instanceof GifDrawable) {
173+
GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
174+
boolean strict = !gifDrawable.isStrict();
175+
stvStrict.setDrawable(strict ? R.drawable.icon_selected : R.drawable.icon_unselected);
176+
gifDrawable.setStrict(strict);
177+
}
178+
}
179+
});
180+
181+
stvFrameDuration.setOnClickListener(new View.OnClickListener() {
182+
@Override
183+
public void onClick(View v) {
184+
String num = etFrameDuration.getText().toString();
185+
if (!TextUtils.isEmpty(num) && stvGifScreen.getDrawable() instanceof GifDrawable) {
186+
int i = Integer.valueOf(num);
187+
GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
188+
gifDrawable.setFrameDuration(i);
189+
}
190+
}
191+
});
192+
193+
stvGotoFrame.setOnClickListener(new View.OnClickListener() {
194+
@Override
195+
public void onClick(View v) {
196+
String num = etGotoFrame.getText().toString();
197+
if (!TextUtils.isEmpty(num) && stvGifScreen.getDrawable() instanceof GifDrawable) {
198+
int i = Integer.valueOf(num);
199+
GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
200+
int frameCount = gifDrawable.getFrameCount();
201+
if (i >= frameCount) {
202+
i = frameCount - 1;
203+
} else if (i < 0) {
204+
i = 0;
205+
}
206+
gifDrawable.gotoFrame(i);
207+
}
208+
}
209+
});
210+
211+
stvGetFrame.setOnClickListener(new View.OnClickListener() {
212+
@Override
213+
public void onClick(View v) {
214+
String num = etGetFrame.getText().toString();
215+
if (!TextUtils.isEmpty(num) && stvGifScreen.getDrawable() instanceof GifDrawable) {
216+
int i = Integer.valueOf(num);
217+
final GifDrawable gifDrawable = (GifDrawable) stvGifScreen.getDrawable();
218+
int frameCount = gifDrawable.getFrameCount();
219+
if (i >= frameCount) {
220+
i = frameCount - 1;
221+
} else if (i < 0) {
222+
i = 0;
223+
}
224+
if (gifDrawable.isStrict()) {
225+
final int finalPosition = i;
226+
ThreadPool.run(new Runnable() {
227+
@Override
228+
public void run() {
229+
final Bitmap frame = gifDrawable.getFrame(finalPosition);
230+
runOnUiThread(new Runnable() {
231+
@Override
232+
public void run() {
233+
stvShowFrame.setDrawable(frame);
234+
stvShowFrame.setVisibility(View.VISIBLE);
235+
}
236+
});
237+
238+
}
239+
});
240+
} else {
241+
Bitmap frame = gifDrawable.getFrame(i);
242+
stvShowFrame.setDrawable(frame);
243+
stvShowFrame.setVisibility(View.VISIBLE);
244+
}
245+
}
246+
}
247+
});
248+
249+
stvShowFrame.setOnClickListener(new View.OnClickListener() {
250+
@Override
251+
public void onClick(View v) {
252+
stvShowFrame.setVisibility(View.GONE);
253+
}
254+
});
255+
}
256+
}

0 commit comments

Comments
 (0)