Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds-android
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
云深项目组
beyond-clouds-android
Commits
8306f07b
Commit
8306f07b
authored
Mar 25, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片浏览器完成
parent
21d72c4f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
9 deletions
+69
-9
app/src/main/java/cn/yunliyunwai/beyondclouds/ui/common/PhotoViewerActivity.java
+25
-2
app/src/main/java/cn/yunliyunwai/beyondclouds/ui/handler/NavHandlers.java
+3
-2
app/src/main/java/cn/yunliyunwai/beyondclouds/view/DynamicGridLayout.java
+2
-1
app/src/main/res/layout/activity_photoviewer.xml
+39
-4
No files found.
app/src/main/java/cn/yunliyunwai/beyondclouds/ui/common/PhotoViewerActivity.java
View file @
8306f07b
...
...
@@ -12,6 +12,7 @@ import androidx.appcompat.app.AppCompatActivity;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentManager
;
import
androidx.fragment.app.FragmentPagerAdapter
;
import
androidx.viewpager.widget.ViewPager
;
import
com.bumptech.glide.Glide
;
...
...
@@ -20,11 +21,13 @@ import cn.yunliyunwai.beyondclouds.databinding.FragmentPhotoBinding;
public
class
PhotoViewerActivity
extends
AppCompatActivity
{
public
static
final
String
ARGS_PHOTO_LINKS
=
"PHOTO_LINKS"
;
public
static
final
String
ARG_PHOTO_LINKS
=
"PHOTO_LINKS"
;
public
static
final
String
ARG_CURRENT_INDEX
=
"CURRENT_INDEX"
;
ActivityPhotoviewerBinding
binding
;
private
String
[]
mPhotos
;
private
int
mCurrentIndex
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
...
...
@@ -33,10 +36,30 @@ public class PhotoViewerActivity extends AppCompatActivity {
setContentView
(
binding
.
getRoot
());
Intent
intent
=
getIntent
();
mPhotos
=
intent
.
getStringArrayExtra
(
ARGS_PHOTO_LINKS
);
mPhotos
=
intent
.
getStringArrayExtra
(
ARG_PHOTO_LINKS
);
mCurrentIndex
=
intent
.
getIntExtra
(
ARG_CURRENT_INDEX
,
0
);
binding
.
txtCurrentIndex
.
setText
((
mCurrentIndex
+
1
)
+
""
);
binding
.
txtImgCount
.
setText
(
mPhotos
.
length
+
""
);
PhotosPagerAdapter
adapter
=
new
PhotosPagerAdapter
(
getSupportFragmentManager
(),
mPhotos
);
binding
.
viewPager
.
setAdapter
(
adapter
);
binding
.
viewPager
.
setCurrentItem
(
mCurrentIndex
);
binding
.
viewPager
.
addOnPageChangeListener
(
new
ViewPager
.
OnPageChangeListener
()
{
@Override
public
void
onPageScrolled
(
int
position
,
float
positionOffset
,
int
positionOffsetPixels
)
{
}
@Override
public
void
onPageSelected
(
int
position
)
{
binding
.
txtCurrentIndex
.
setText
((
position
+
1
)
+
""
);
}
@Override
public
void
onPageScrollStateChanged
(
int
state
)
{
}
});
}
public
static
class
PhotosPagerAdapter
extends
FragmentPagerAdapter
{
...
...
app/src/main/java/cn/yunliyunwai/beyondclouds/ui/handler/NavHandlers.java
View file @
8306f07b
...
...
@@ -207,9 +207,10 @@ public class NavHandlers {
view
.
getContext
().
startActivity
(
intent
);
}
public
static
void
toPhotoViewer
(
View
view
,
String
[]
photoLinks
)
{
public
static
void
toPhotoViewer
(
View
view
,
String
[]
photoLinks
,
int
currentIndex
)
{
Intent
intent
=
new
Intent
(
view
.
getContext
(),
PhotoViewerActivity
.
class
);
intent
.
putExtra
(
PhotoViewerActivity
.
ARGS_PHOTO_LINKS
,
photoLinks
);
intent
.
putExtra
(
PhotoViewerActivity
.
ARG_PHOTO_LINKS
,
photoLinks
);
intent
.
putExtra
(
PhotoViewerActivity
.
ARG_CURRENT_INDEX
,
currentIndex
);
view
.
getContext
().
startActivity
(
intent
);
}
}
app/src/main/java/cn/yunliyunwai/beyondclouds/view/DynamicGridLayout.java
View file @
8306f07b
...
...
@@ -128,10 +128,11 @@ public class DynamicGridLayout extends ViewGroup {
int
left
=
computePosition
(
currentCol
,
imageSize
)
+
getPaddingLeft
();
int
top
=
computePosition
(
currentRow
,
imageSize
)
+
getPaddingTop
();
imageView
.
layout
(
left
,
top
,
left
+
imageSize
,
top
+
imageSize
);
final
int
currentIndex
=
i
;
imageView
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
NavHandlers
.
toPhotoViewer
(
v
,
mImgUrls
.
toArray
(
new
String
[
0
]));
NavHandlers
.
toPhotoViewer
(
v
,
mImgUrls
.
toArray
(
new
String
[
0
])
,
currentIndex
);
}
});
}
...
...
app/src/main/res/layout/activity_photoviewer.xml
View file @
8306f07b
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:background=
"#000000"
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:background=
"#000000"
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<androidx.viewpager.widget.ViewPager
android:id=
"@+id/view_pager"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
<LinearLayout
android:id=
"@+id/img_indicator"
app:layout_constraintStart_toStartOf=
"@id/view_pager"
app:layout_constraintEnd_toEndOf=
"@id/view_pager"
app:layout_constraintBottom_toBottomOf=
"@id/view_pager"
android:layout_marginBottom=
"10dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/txt_current_index"
android:text=
"1"
android:textSize=
"24dp"
android:typeface=
"serif"
android:textColor=
"@color/colorWhite"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:text=
"/"
android:textColor=
"#f2f2f2"
android:typeface=
"serif"
android:textSize=
"16dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/txt_img_count"
android:text=
"9"
android:typeface=
"serif"
android:textColor=
"#f2f2f2"
android:textSize=
"14dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment