-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from csoni111/imageViewer
Image Viewer updates, fixes #61
- Loading branch information
Showing
7 changed files
with
595 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
src/main/java/org/amahi/anywhere/util/FullScreenHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/* | ||
* Copyright (c) 2014 Amahi | ||
* | ||
* This file is part of Amahi. | ||
* | ||
* Amahi is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Amahi is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Amahi. If not, see <http ://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.amahi.anywhere.util; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.ActionBar; | ||
import android.os.Handler; | ||
import android.support.annotation.NonNull; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
|
||
/** | ||
* FullScreenHelper Helper class. | ||
* Shows content as full screen and implements touch listener | ||
* to control the show/hide of controls and ActionBar. | ||
*/ | ||
|
||
public class FullScreenHelper { | ||
|
||
private boolean autoHide = true; | ||
private int autoHideDelayMillis = 3000; | ||
private boolean onClickToggleEnabled = true; | ||
private boolean mVisible; | ||
private static final int UI_ANIMATION_DELAY = 300; | ||
|
||
private View mControlsView; | ||
private View mContentView; | ||
|
||
private ActionBar actionBar; | ||
|
||
public FullScreenHelper(ActionBar actionBar, @NonNull View contentView) { | ||
setActionBar(actionBar); | ||
setmContentView(contentView); | ||
} | ||
|
||
public FullScreenHelper(ActionBar actionBar, @NonNull View contentView, View controlsView) { | ||
setActionBar(actionBar); | ||
setmContentView(contentView); | ||
setmControlsView(controlsView); | ||
} | ||
|
||
public void setmControlsView(View mControlsView) { | ||
this.mControlsView = mControlsView; | ||
} | ||
|
||
public void setmContentView(View mContentView) { | ||
this.mContentView = mContentView; | ||
} | ||
|
||
public void setActionBar(ActionBar actionBar) { | ||
this.actionBar = actionBar; | ||
} | ||
|
||
public void setAutoHide(Boolean autoHide) { | ||
this.autoHide = autoHide; | ||
} | ||
|
||
public void setAutoHideDelayMillis(int millis) { | ||
this.autoHideDelayMillis = millis; | ||
} | ||
|
||
public void enableOnClickToggle(Boolean enable) { | ||
this.onClickToggleEnabled = enable; | ||
} | ||
|
||
public void init() { | ||
mVisible = true; | ||
|
||
// Trigger the initial hide() shortly after the activity has been | ||
// created, to briefly hint to the user that UI controls | ||
// are available. | ||
delayedHide(autoHideDelayMillis); | ||
|
||
if (onClickToggleEnabled) { | ||
// Toggle hide/show on click | ||
mContentView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
toggle(); | ||
} | ||
}); | ||
} | ||
|
||
if (mControlsView != null) { | ||
// Upon interacting with UI controls, delay any scheduled hide() | ||
// operations to prevent the jarring behavior of controls going away | ||
// while interacting with the UI. | ||
mControlsView.setOnTouchListener(new View.OnTouchListener() { | ||
@Override | ||
public boolean onTouch(View view, MotionEvent motionEvent) { | ||
if (autoHide) { | ||
delayedHide(autoHideDelayMillis); | ||
} | ||
return false; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
public void toggle() { | ||
if (mVisible) { | ||
hide(); | ||
} else { | ||
show(); | ||
} | ||
} | ||
|
||
private final Handler mHideHandler = new Handler(); | ||
|
||
private final Runnable mHidePart2Runnable = new Runnable() { | ||
@SuppressLint("InlinedApi") | ||
@Override | ||
public void run() { | ||
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE | ||
| View.SYSTEM_UI_FLAG_FULLSCREEN | ||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | ||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | ||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); | ||
} | ||
}; | ||
|
||
private final Runnable mShowPart2Runnable = new Runnable() { | ||
@Override | ||
public void run() { | ||
if (actionBar != null) | ||
actionBar.show(); | ||
if (mControlsView != null) | ||
mControlsView.setVisibility(View.VISIBLE); | ||
} | ||
}; | ||
|
||
private final Runnable mHideRunnable = new Runnable() { | ||
@Override | ||
public void run() { | ||
hide(); | ||
} | ||
}; | ||
|
||
private void hide() { | ||
if (actionBar != null) | ||
actionBar.hide(); | ||
if (mControlsView != null) | ||
mControlsView.setVisibility(View.GONE); | ||
mVisible = false; | ||
|
||
// Schedule a runnable to remove the status and navigation bar after a delay | ||
mHideHandler.removeCallbacks(mShowPart2Runnable); | ||
mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY); | ||
} | ||
|
||
@SuppressLint("InlinedApi") | ||
private void show() { | ||
// Show the system bar | ||
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | ||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); | ||
mVisible = true; | ||
|
||
// Schedule a runnable to display UI elements after a delay | ||
mHideHandler.removeCallbacks(mHidePart2Runnable); | ||
mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY); | ||
} | ||
|
||
/** | ||
* Schedules a call to hide() in [delay] milliseconds, canceling any | ||
* previously scheduled calls. | ||
*/ | ||
private void delayedHide(int delayMillis) { | ||
mHideHandler.removeCallbacks(mHideRunnable); | ||
mHideHandler.postDelayed(mHideRunnable, delayMillis); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/org/amahi/anywhere/view/ClickableViewPager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2014 Amahi | ||
* | ||
* This file is part of Amahi. | ||
* | ||
* Amahi is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Amahi is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Amahi. If not, see <http ://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
package org.amahi.anywhere.view; | ||
|
||
import android.content.Context; | ||
import android.support.v4.view.ViewPager; | ||
import android.util.AttributeSet; | ||
import android.view.GestureDetector; | ||
import android.view.MotionEvent; | ||
|
||
/** | ||
* Custom ViewPager for implementing click events. | ||
*/ | ||
public class ClickableViewPager extends ViewPager { | ||
|
||
private OnClickListener mOnClickListener; | ||
private GestureDetector tapGestureDetector; | ||
|
||
public ClickableViewPager(Context context) { | ||
super(context); | ||
|
||
setup(); | ||
} | ||
|
||
public ClickableViewPager(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
|
||
setup(); | ||
} | ||
|
||
private void setup() { | ||
tapGestureDetector = new GestureDetector(getContext(), new TapGestureListener()); | ||
} | ||
|
||
@Override | ||
public boolean onInterceptTouchEvent(MotionEvent ev) { | ||
tapGestureDetector.onTouchEvent(ev); | ||
return super.onInterceptTouchEvent(ev); | ||
} | ||
|
||
public void setOnViewPagerClickListener(OnClickListener onClickListener) { | ||
mOnClickListener = onClickListener; | ||
} | ||
|
||
public interface OnClickListener { | ||
void onViewPagerClick(ViewPager viewPager); | ||
} | ||
|
||
private class TapGestureListener extends GestureDetector.SimpleOnGestureListener { | ||
|
||
@Override | ||
public boolean onSingleTapConfirmed(MotionEvent e) { | ||
if (mOnClickListener != null) { | ||
mOnClickListener.onViewPagerClick(ClickableViewPager.this); | ||
} | ||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.