- 内蔵ビューアで短いGIFVを表示するとバッファ中表示が頻出する問題の対策

- 内蔵ビューアの左下に静止画の倍率表示を追加
- 内蔵ビューアで静止画のズームをx4以上にすると補間アルゴリズムをpixel peeper向けに変更する
This commit is contained in:
tateisu 2017-12-29 18:23:10 +09:00
parent 92bb6223cd
commit c775088d5f
7 changed files with 114 additions and 53 deletions

View File

@ -10,8 +10,8 @@ android {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 26
versionCode 193
versionName "1.9.3"
versionCode 194
versionName "1.9.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -61,7 +61,6 @@ import jp.juggler.subwaytooter.util.Utils;
import jp.juggler.subwaytooter.view.PinchBitmapView;
import okhttp3.Call;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class ActMediaViewer extends AppCompatActivity implements View.OnClickListener {
@ -139,6 +138,7 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
SimpleExoPlayerView exoView;
View svDescription;
TextView tvDescription;
TextView tvStatus;
void initUI(){
setContentView( R.layout.act_media_viewer );
@ -149,6 +149,7 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
tvError = findViewById( R.id.tvError );
svDescription = findViewById( R.id.svDescription );
tvDescription = findViewById( R.id.tvDescription );
tvStatus = findViewById( R.id.tvStatus );
boolean enablePaging = media_list.size() > 1;
btnPrevious.setEnabled( enablePaging );
@ -170,6 +171,17 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
if( isDestroyed() ) return;
loadDelta( delta );
}
@Override public void onMove( final float tx, final float ty, final float scale ){
App1.app_state.handler.post( new Runnable() {
@Override public void run(){
if( isDestroyed() ) return;
if( tvStatus.getVisibility() == View.VISIBLE ){
tvStatus.setText( getString(R.string.zooming_of,scale ));
}
}
} );
}
} );
exoPlayer = ExoPlayerFactory.newSimpleInstance( this, new DefaultTrackSelector() );
@ -177,7 +189,7 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
exoView.setPlayer( exoPlayer );
}
void loadDelta( int delta ){
if( media_list.size() < 2 ) return;
int size = media_list.size();
@ -192,6 +204,7 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
exoView.setVisibility( View.GONE );
tvError.setVisibility( View.GONE );
svDescription.setVisibility( View.GONE );
tvStatus.setVisibility( View.GONE );
if( media_list == null
|| media_list.isEmpty()
@ -275,6 +288,9 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
return;
}
tvStatus.setVisibility( View.VISIBLE );
tvStatus.setText(null);
pbvImage.setVisibility( View.VISIBLE );
pbvImage.setBitmap( null );
@ -587,6 +603,9 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
} );
}
long buffering_last_shown;
static final long short_limit = 5000L;
private final Player.EventListener player_listener = new Player.EventListener() {
@Override public void onTimelineChanged( Timeline timeline, Object manifest ){
log.d( "exoPlayer onTimelineChanged" );
@ -607,7 +626,14 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
// かなり頻繁に呼ばれる
// log.d( "exoPlayer onPlayerStateChanged %s %s", playWhenReady, playbackState );
if( playWhenReady && playbackState == Player.STATE_BUFFERING ){
Utils.showToast( ActMediaViewer.this, false, R.string.video_buffering );
long now = SystemClock.elapsedRealtime();
if( now - buffering_last_shown >= short_limit && exoPlayer.getDuration() >= short_limit ){
buffering_last_shown = now;
Utils.showToast( ActMediaViewer.this, false, R.string.video_buffering );
}
/*
exoPlayer.getDuration() may returns negative value (TIME_UNSET ,same as Long.MIN_VALUE + 1).
*/
}
}

View File

@ -1,5 +1,6 @@
package jp.juggler.subwaytooter.view;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@ -36,8 +37,6 @@ public class PinchBitmapView extends View {
void init( Context context ){
paint.setFilterBitmap( true );
// 定数をdpからpxに変換
float density = context.getResources().getDisplayMetrics().density;
swipe_velocity = 1000f * density;
@ -48,6 +47,7 @@ public class PinchBitmapView extends View {
// ページめくり操作のコールバック
public interface Callback {
void onSwipe( int delta );
void onMove(float tx,float ty,float scale);
}
@Nullable Callback callback;
@ -83,9 +83,12 @@ public class PinchBitmapView extends View {
super.onDraw( canvas );
if( bitmap != null && ! bitmap.isRecycled() ){
matrix.reset();
matrix.postScale( current_scale, current_scale );
matrix.postTranslate( current_trans_x, current_trans_y );
paint.setFilterBitmap( current_scale < 4f );
canvas.drawBitmap( bitmap, matrix, paint );
}
}
@ -126,8 +129,15 @@ public class PinchBitmapView extends View {
current_trans_x = ( view_w - draw_w ) / 2f;
current_trans_y = ( view_h - draw_h ) / 2f;
}else{
current_trans_x = current_trans_y = 0f;
current_scale = 1f;
}
if( callback != null ) callback.onMove( current_trans_x,current_trans_y,current_scale );
// 画像がnullに変化した時も再描画が必要
invalidate();
}
@ -148,6 +158,7 @@ public class PinchBitmapView extends View {
// フリック操作の検出に使う
@Nullable VelocityTracker velocityTracker;
@SuppressLint("ClickableViewAccessibility")
@Override public boolean onTouchEvent( MotionEvent ev ){
if( bitmap == null
@ -167,7 +178,7 @@ public class PinchBitmapView extends View {
velocityTracker.addMovement( ev );
bDrag = bPointerCountChanged = false;
startTracking( ev );
trackStart( ev );
return true;
}
@ -180,15 +191,15 @@ public class PinchBitmapView extends View {
case MotionEvent.ACTION_POINTER_UP:
// タッチ操作中に指の数を変えた
bDrag = bPointerCountChanged = true;
startTracking( ev );
trackStart( ev );
break;
case MotionEvent.ACTION_MOVE:
nextTracking( ev );
trackNext( ev );
break;
case MotionEvent.ACTION_UP:
nextTracking( ev );
trackNext( ev );
checkClickOrPaging();
@ -313,7 +324,7 @@ public class PinchBitmapView extends View {
float view_h;
float view_aspect;
void startTracking( MotionEvent ev ){
void trackStart( MotionEvent ev ){
// 追跡開始時の指の位置
start_pos.update( ev );
@ -347,14 +358,14 @@ public class PinchBitmapView extends View {
tracking_matrix_inv.mapPoints( dst, src );
}
void nextTracking( MotionEvent ev ){
void trackNext( MotionEvent ev ){
pos.update( ev );
if( pos.count != start_pos.count ){
// タッチ操作中に指の数が変わった
log.d( "nextTracking: pointer count changed" );
bDrag = bPointerCountChanged = true;
startTracking( ev );
trackStart( ev );
return;
}
@ -394,6 +405,8 @@ public class PinchBitmapView extends View {
current_trans_y = clipTranslate( view_h, bitmap_h, current_scale, start_image_trans_y + move_y );
}
if( callback != null ) callback.onMove( current_trans_x,current_trans_y,current_scale );
invalidate();
}

View File

@ -53,51 +53,70 @@
/>
</FrameLayout>
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/flFooter"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexWrap="wrap"
app:alignItems="center"
app:justifyContent="center"
>
<ImageButton
android:id="@+id/btnPrevious"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/previous"
android:minWidth="48dp"
android:src="?attr/ic_left"
/>
<com.google.android.flexbox.FlexboxLayout
<ImageButton
android:id="@+id/btnNext"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/next"
android:minWidth="48dp"
android:src="?attr/ic_right"
/>
android:id="@+id/flFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:alignItems="center"
app:flexWrap="wrap"
app:justifyContent="center"
>
<ImageButton
android:id="@+id/btnDownload"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/download"
android:minWidth="48dp"
android:src="?attr/ic_download"
/>
<ImageButton
android:id="@+id/btnPrevious"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/previous"
android:minWidth="48dp"
android:src="?attr/ic_left"
/>
<ImageButton
android:id="@+id/btnMore"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/more"
android:minWidth="48dp"
android:src="?attr/btn_more"
/>
<ImageButton
android:id="@+id/btnNext"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/next"
android:minWidth="48dp"
android:src="?attr/ic_right"
/>
</com.google.android.flexbox.FlexboxLayout>
<ImageButton
android:id="@+id/btnDownload"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/download"
android:minWidth="48dp"
android:src="?attr/ic_download"
/>
<ImageButton
android:id="@+id/btnMore"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/more"
android:minWidth="48dp"
android:src="?attr/btn_more"
/>
</com.google.android.flexbox.FlexboxLayout>
<TextView
android:id="@+id/tvStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom"
android:layout_marginBottom="6dp"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:gravity="start|bottom"
android:textSize="12sp"
android:alpha="0.5"
/>
</FrameLayout>
</LinearLayout>

View File

@ -585,6 +585,7 @@
<string name="media_attachment_type_error">The type of media attachment is \"%1$s\". ST can\'t handle it, but you can try open in browser.</string>
<string name="video_buffering">Buffering…</string>
<string name="dont_repeat_download_to_same_url">Can\'t repeat downloading same URL in a short time.</string>
<string name="zooming_of">×%1$,.1f</string>
<!--<string name="abc_action_bar_home_description">Revenir à l\'accueil</string>-->
<!--<string name="abc_action_bar_home_description_format">%1$s, %2$s</string>-->

View File

@ -872,5 +872,6 @@
<string name="media_attachment_type_error">添付メディアの種類\"%1$s\"はこのアプリでは開けません。下の「…」にある「ブラウザで開く」を試すことができます</string>
<string name="video_buffering">バッファ中…</string>
<string name="dont_repeat_download_to_same_url">同じURLを数秒以内に繰り返しダウンロードすることはできません</string>
<string name="zooming_of">×%1$,.1f</string>
</resources>

View File

@ -575,4 +575,5 @@
<string name="media_attachment_type_error">The type of media attachment is \"%1$s\". ST can\'t handle it, but you can try open in browser.</string>
<string name="video_buffering">Buffering…</string>
<string name="dont_repeat_download_to_same_url">Can\'t repeat downloading same URL in a few second.</string>
<string name="zooming_of">×%1$,.1f</string>
</resources>