fullscrren mode by click on activity_media

This commit is contained in:
Len Chan 2019-03-31 17:48:47 +08:00
parent 749f63f1d4
commit e06a3bad73
7 changed files with 185 additions and 111 deletions

View File

@ -55,7 +55,7 @@ ext.conscryptLibraryVersion = '2.0.0'
ext.evernoteLibraryVersion = '1.2.6'
ext.gsonLibraryVersion = '2.8.2'
ext.guavaLibraryVersion = '24.1-android'
ext.photoViewLibraryVersion = '2.0.0'
ext.photoViewLibraryVersion = '2.1.3'
ext.swipebackLibraryVersion = '1.0.3'
ext.ratethisappLibraryVersion = '1.2.0'
ext.uploadServiceVersion = "3.4.2"

View File

@ -19,6 +19,7 @@ import android.Manifest;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.net.Uri;
import android.os.Build;
@ -28,6 +29,7 @@ import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -67,6 +69,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.HttpsConnection;
import fr.gouv.etalab.mastodon.client.TLSSocketFactory;
import fr.gouv.etalab.mastodon.helper.CustomPhotoView;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnDownloadInterface;
import fr.gouv.etalab.mastodon.webview.MastalabWebChromeClient;
@ -74,6 +77,8 @@ import fr.gouv.etalab.mastodon.webview.MastalabWebViewClient;
import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
@ -87,7 +92,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
private RelativeLayout loader;
private ArrayList<Attachment> attachments;
private PhotoView imageView;
private CustomPhotoView imageView;
private SimpleExoPlayerView videoView;
private float downX;
private int mediaPosition;
@ -96,7 +101,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
private String finalUrlDownload;
private String preview_url;
private ImageView prev, next;
private boolean isHiding;
private boolean isControlElementShown;
private Bitmap downloadedImage;
private File fileVideo;
private TextView progress;
@ -106,6 +111,8 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
private TextView media_description;
private Attachment attachment;
SwipeBackLayout mSwipeBackLayout;
private float imageScale = 0;
private RelativeLayout action_bar_container;
private enum actionSwipe{
RIGHT_TO_LEFT,
LEFT_TO_RIGHT,
@ -125,6 +132,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
setTheme(R.style.TransparentBlack);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_media);
action_bar_container = (RelativeLayout) findViewById(R.id.action_bar_container);
mSwipeBackLayout = new SwipeBackLayout(MediaActivity.this);
mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_BOTTOM);
mSwipeBackLayout.setMaskAlpha(125);
@ -162,13 +170,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
}
media_description = findViewById(R.id.media_description);
message_ready = findViewById(R.id.message_ready);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
media_save = findViewById(R.id.media_save);
media_share = findViewById(R.id.media_share);
media_close = findViewById(R.id.media_close);
progress = findViewById(R.id.loader_progress);
webview_video = findViewById(R.id.webview_video);
media_save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -221,28 +228,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
finish();
}
});
Handler h = new Handler();
scheduleHidden = scheduleHiddenDescription = true;
h.postDelayed(new Runnable() {
@Override
public void run() {
// DO DELAYED STUFF
media_close.setVisibility(View.GONE);
media_save.setVisibility(View.GONE);
media_share.setVisibility(View.GONE);
scheduleHidden = false;
}
}, 2000);
h.postDelayed(new Runnable() {
@Override
public void run() {
// DO DELAYED STUFF
media_description.setVisibility(View.GONE);
scheduleHiddenDescription = false;
}
}, 6000);
canSwipe = true;
loader = findViewById(R.id.loader);
imageView = findViewById(R.id.media_picture);
@ -252,9 +237,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
if( theme == THEME_BLACK){
changeDrawableColor(getApplicationContext(), prev, R.color.dark_icon);
changeDrawableColor(getApplicationContext(), next, R.color.dark_icon);
}else {
}else if(theme == THEME_LIGHT) {
changeDrawableColor(getApplicationContext(), prev, R.color.mastodonC4);
changeDrawableColor(getApplicationContext(), next, R.color.mastodonC4);
}else{
changeDrawableColor(getApplicationContext(), prev, R.color.white);
changeDrawableColor(getApplicationContext(), next, R.color.white);
}
prev.setOnClickListener(new View.OnClickListener() {
@Override
@ -275,18 +263,29 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
imageView.setOnMatrixChangeListener(new OnMatrixChangedListener() {
@Override
public void onMatrixChanged(RectF rect) {
imageScale = imageView.getScale();
Log.v("imageScale", String.valueOf(imageScale));
canSwipe = (imageView.getScale() == 1 );
mSwipeBackLayout.isDisabled(imageView.getScale() != 1 );
}
});
if( attachments != null && attachments.size() > 1){
prev.setVisibility(View.VISIBLE);
next.setVisibility(View.VISIBLE);
}
pbar_inf = findViewById(R.id.pbar_inf);
setTitle("");
isHiding = false;
//isHiding = false;
setTitle("");
displayMediaAtPosition(actionSwipe.POP);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putFloat("scale", imageScale);
super.onSaveInstanceState(outState);
}
/**
@ -297,26 +296,27 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
*/
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
Boolean thisControllShown = isControlElementShown;
if( event.getAction() == MotionEvent.ACTION_DOWN){
isControlElementShown = !isControlElementShown;
FullScreencall(thisControllShown);
if(thisControllShown){
action_bar_container.setVisibility(View.GONE);
media_close.setVisibility(View.GONE);
media_save.setVisibility(View.GONE);
media_share.setVisibility(View.GONE);
}else{
media_close.setVisibility(View.VISIBLE);
media_close.setVisibility(View.VISIBLE);
media_save.setVisibility(View.VISIBLE);
media_share.setVisibility(View.VISIBLE);
}
if( event.getAction() == MotionEvent.ACTION_DOWN && !scheduleHidden){
scheduleHidden = true;
media_close.setVisibility(View.VISIBLE);
media_save.setVisibility(View.VISIBLE);
media_share.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
media_close.setVisibility(View.GONE);
media_save.setVisibility(View.GONE);
media_share.setVisibility(View.GONE);
scheduleHidden = false;
}
}, 2000);
}
if( event.getAction() == MotionEvent.ACTION_DOWN && !scheduleHiddenDescription){
scheduleHiddenDescription = true;
if( attachment != null && attachment.getDescription() != null && !attachment.getDescription().equals("null")){
if( event.getAction() == MotionEvent.ACTION_DOWN){
if(media_description.getVisibility() == View.VISIBLE && thisControllShown){
media_description.setVisibility(View.GONE);
}else if(!thisControllShown && attachment != null && attachment.getDescription() != null && !attachment.getDescription().equals("null")){
media_description.setText(attachment.getDescription());
media_description.setVisibility(View.VISIBLE);
imageView.setContentDescription(attachment.getDescription());
@ -324,14 +324,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
media_description.setText("");
media_description.setVisibility(View.GONE);
}
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
media_description.setVisibility(View.GONE);
scheduleHiddenDescription = false;
}
}, 6000);
}
if( !canSwipe || mediaPosition > attachments.size() || mediaPosition < 1 || attachments.size() <= 1)
return super.dispatchTouchEvent(event);
@ -339,17 +331,14 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
case MotionEvent.ACTION_DOWN: {
downX = event.getX();
//Displays navigation left/right buttons
if( attachments != null && attachments.size() > 1 && !isHiding){
prev.setVisibility(View.VISIBLE);
next.setVisibility(View.VISIBLE);
isHiding = true;
new Handler().postDelayed(new Runnable(){
public void run() {
prev.setVisibility(View.GONE);
next.setVisibility(View.GONE);
isHiding = false;
}
}, 2000);
if( attachments != null && attachments.size() > 1){
if(thisControllShown){
prev.setVisibility(View.GONE);
next.setVisibility(View.GONE);
}else{
prev.setVisibility(View.VISIBLE);
next.setVisibility(View.VISIBLE);
}
}
return super.dispatchTouchEvent(event);
}
@ -366,6 +355,8 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
}
}
}
return super.dispatchTouchEvent(event);
}
@ -561,20 +552,40 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
@Override
public void onResume(){
super.onResume();
FullScreencall();
FullScreencall(isControlElementShown);
if( player != null) {
player.setPlayWhenReady(true);
}
}
public void FullScreencall() {
public void FullScreencall(Boolean shouldFullscreen) {
if(Build.VERSION.SDK_INT < 19) {
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
if(shouldFullscreen){
v.setSystemUiVisibility(View.VISIBLE);
}else {
v.setSystemUiVisibility(View.GONE);
}
} else {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
if(shouldFullscreen){
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}else{
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
}

View File

@ -0,0 +1,34 @@
package fr.gouv.etalab.mastodon.helper;
import android.content.Context;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
import com.github.chrisbanes.photoview.PhotoView;
import com.github.chrisbanes.photoview.PhotoViewAttacher;
public class CustomPhotoView extends PhotoView {
private PhotoViewAttacher mAttacher;
public CustomPhotoView(Context context) {
super(context);
}
public CustomPhotoView(Context context, AttributeSet attr) {
super(context, attr);
}
public CustomPhotoView(Context context, AttributeSet attr, int defStyle) {
super(context, attr, defStyle);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
Log.v("layoutchanged","yes!" );
}
}

View File

@ -24,7 +24,6 @@
app:isSwipeFromEdge="true"
app:maskAlpha="125"
app:swipeBackFactor="0.5">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -32,7 +31,6 @@
android:id="@+id/main_container_media">
<!-- Main Loader -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loader"
@ -77,11 +75,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Description is set dynamically -->
<com.github.chrisbanes.photoview.PhotoView
<fr.gouv.etalab.mastodon.helper.CustomPhotoView
android:visibility="gone"
android:id="@+id/media_picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
/>
<TextView
android:visibility="gone"
@ -89,7 +88,7 @@
android:id="@+id/media_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_marginBottom="62dp"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dp"
android:background="#AA000000"
@ -104,44 +103,12 @@
android:layout_height="match_parent"
/>
<ImageView
android:id="@+id/media_prev"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:contentDescription="@string/previous"
android:src="@drawable/ic_first_page"
android:visibility="gone" />
<ImageView
android:id="@+id/media_next"
android:layout_width="20dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:contentDescription="@string/next"
android:src="@drawable/ic_last_page"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent_grey">
android:background="@color/transparent_grey"
android:id="@+id/action_bar_container"
android:paddingTop="16dp">
<ImageButton
android:id="@+id/media_close"
android:layout_width="35dp"
@ -202,6 +169,43 @@
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="@+id/media_prev"
android:layout_width="30dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:background="@color/transparent_grey"
android:tint="@color/white"
android:contentDescription="@string/previous"
android:src="@drawable/ic_first_page"
android:visibility="gone" />
<ImageView
android:id="@+id/media_next"
android:layout_width="30dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:background="@color/transparent_grey"
android:contentDescription="@string/next"
android:src="@drawable/ic_last_page"
android:visibility="gone" />
<TextView
android:visibility="gone"
@ -211,6 +215,7 @@
android:text="@string/media_ready"
android:gravity="center"
android:textSize="14sp"
android:layout_alignBottom="@+id/media_picture_container"
android:layout_marginBottom="40dp"
android:layout_width="match_parent"

View File

@ -0,0 +1,21 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- "Mark Favorite", should appear as action button if possible -->
<item
android:id="@+id/media_save"
android:icon="@drawable/ic_save_white"
android:title="@string/download"
app:showAsAction="ifRoom"/>
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/media_share"
android:title="@string/share"
app:showAsAction="never"/>
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/media_close"
android:title="@string/share"
app:showAsAction="never"/>
</menu>

View File

@ -392,4 +392,8 @@
<style name="Shape.Dark" parent="AppThemeDark">
<item name="android:background">@drawable/shape_border_bottom_settings_dark</item>
</style>
<style name="activity_media_toolbar_theme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
</style>
</resources>

View File

@ -10,7 +10,6 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects