Skip to content

Commit

Permalink
v1.1.2新增转gif和GIF分享到微信QQ功能
Browse files Browse the repository at this point in the history
  • Loading branch information
honglei92 committed Oct 15, 2018
1 parent 1d2370d commit 0614cc5
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 13 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
Expand All @@ -25,14 +26,16 @@ android {
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
api 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
// androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
api 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'
api 'io.reactivex.rxjava2:rxandroid:2.0.2'
api 'com.wuhenzhizao:titlebar:1.0.7'
api 'com.androidkun:XTabLayout:1.1.4'
implementation 'com.github.tyhjh:FFmpeg:-SNAPSHOT'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.bumptech.glide:glide:3.7.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IndexActivity : BaseActivity() {

override fun initView() {
setContentView(R.layout.activity_index)
val titles = arrayOf("录制", "本地视频", "转gif")
val titles = arrayOf("录制", "本地视频", "已转Gif")
mViewPagerCom.adapter = object : FragmentPagerAdapter(supportFragmentManager) {
override fun getItem(position: Int): Fragment? {
when (position) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.a83661.screenrecorder.ui.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.RecyclerView.Adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.example.a83661.screenrecorder.R
import java.io.File

/**
* @author:honglei92
* @time:2018/7/9
*/

class LocalGifAdapter(var context: Context, var gifPaths: ArrayList<String>) : Adapter<LocalGifAdapter.ViewHolder>() {
lateinit var mOnItemClickListener: OnItemClickListener
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_local_gif, p0, false))
}

override fun getItemCount(): Int {
return gifPaths.size
}

override fun onBindViewHolder(p0: ViewHolder, p1: Int) {
Glide.with(context).load(File(gifPaths[p1])).asGif().into(p0.mGifIv)
p0.mShareGifiv.setOnClickListener {
mOnItemClickListener.onItemClick(it, p1)
}
}

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var mGifIv: ImageView = itemView.findViewById(R.id.gifIv)
var mShareGifiv: ImageView = itemView.findViewById(R.id.ivShareGif)
}

fun setOnItemClickListener(onItemClickListener: OnItemClickListener) {
this.mOnItemClickListener = onItemClickListener
}

interface OnItemClickListener {
fun onItemClick(view: View, position: Int)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.a83661.screenrecorder.ui.adapter

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.support.v4.app.FragmentActivity
import android.util.Log
import android.view.View
import android.view.ViewGroup
Expand All @@ -12,9 +12,11 @@ import android.widget.TextView
import com.example.a83661.screenrecorder.R
import com.example.a83661.screenrecorder.bean.Video
import com.example.a83661.screenrecorder.ui.VideoPlayActivity
import com.yorhp.tyhjffmpeg.Mv2Gif
import com.yorhp.tyhjffmpeg.Setting
import java.io.File

class LocalVideoAdapter(val context: Context, var list: ArrayList<Video>) : BaseAdapter() {
class LocalVideoAdapter(val context: FragmentActivity, var list: ArrayList<Video>) : BaseAdapter() {
override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
Log.d("honglei92", "execute:" + p0)
val viewHolder: ViewHolder
Expand All @@ -27,6 +29,7 @@ class LocalVideoAdapter(val context: Context, var list: ArrayList<Video>) : Base
viewHolder.tvDurationTime = view.findViewById(R.id.tvDurationTime)
viewHolder.ivVideo = view.findViewById(R.id.ivImage)
viewHolder.ivShare = view.findViewById(R.id.ivShare)
viewHolder.ivGif = view.findViewById(R.id.ivGif)
view.tag = viewHolder
} else {
view = p1
Expand All @@ -52,6 +55,21 @@ class LocalVideoAdapter(val context: Context, var list: ArrayList<Video>) : Base
context.startActivity(Intent.createChooser(shareIntent, "分享"))

}
viewHolder.ivGif.setOnClickListener {
Thread(Runnable {
val pathFrom = list[p0].path
val pathTo = list[p0].path!!.replace("mp4", "gif")
val setting = Setting(
true,
1080,
1920,
20,
0,
20
)
Mv2Gif.convert(pathFrom, pathTo, setting)
}).start()
}
return view
}

Expand All @@ -73,5 +91,6 @@ class LocalVideoAdapter(val context: Context, var list: ArrayList<Video>) : Base
lateinit var tvDurationTime: TextView
lateinit var ivVideo: ImageView
lateinit var ivShare: ImageView
lateinit var ivGif: ImageView
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,85 @@
package com.example.a83661.screenrecorder.ui.fragment

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.a83661.screenrecorder.R
import com.example.a83661.screenrecorder.base.Constants
import com.example.a83661.screenrecorder.bean.Video
import com.example.a83661.screenrecorder.ui.adapter.LocalGifAdapter
import java.io.File
import java.io.FileFilter

/**
* 转gif
*
* @author: https://github.com/honglei92
* @time: 2018/9/9
*/
class GifFragment : Fragment() {
class GifFragment : Fragment(), LocalGifAdapter.OnItemClickListener {
var mAdapter: LocalGifAdapter? = null
override fun onItemClick(view: View, position: Int) {
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = "image/*"
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(File(mGifList[position])))
activity!!.startActivity(Intent.createChooser(shareIntent, "分享"))
}

var mGifList = arrayListOf<String>()
var mRefreshLayout: SwipeRefreshLayout? = null
var mRecycleView: RecyclerView? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_local_gif, null)
mRefreshLayout = view.findViewById(R.id.swipeRefresh)
mRecycleView = view.findViewById(R.id.localGifRv)
initView()
return view
}

private fun initView() {
mRefreshLayout!!.setOnRefreshListener {
initGifRv()
}
initGifRv()
}

private fun initGifRv() {
val file = File(Constants.directory)
mGifList = getGifList(file)
mAdapter = LocalGifAdapter(activity!!, mGifList)
mAdapter!!.setOnItemClickListener(this)
mRecycleView!!.adapter = mAdapter
mRecycleView!!.layoutManager = object : GridLayoutManager(activity, 3) {}
mRecycleView!!.itemAnimator = DefaultItemAnimator()
mRefreshLayout!!.isRefreshing = false
}

private fun getGifList(file: File): ArrayList<String> {
val mList = arrayListOf<String>()
file.listFiles(FileFilter { file ->
var name = file!!.name
val i = name.indexOf(".")
if (i != -1) {
name = name.substring(i)
if (name.equals(".gif", true)) {
val video = Video()
file.usableSpace
mList.add(file.absolutePath)
return@FileFilter true
}
}
false
})
return mList
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LocalFragment : Fragment() {
private fun initVideoLv() {
val file = File(Constants.directory)
mVideoList = getVideoList(file)
val adapter = LocalVideoAdapter(activity, mVideoList)
val adapter = LocalVideoAdapter(activity!!, mVideoList)
mLocalVideoLv!!.adapter = adapter
mSwipeRefreshLayout!!.isRefreshing = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ class RecordFragment : Fragment() {
}
val mOpenLocalBtn = view.findViewById<Button>(R.id.openLocalBtn)
mOpenLocalBtn.setOnClickListener {
FileUT.openAssignFolder(activity, StringUT.getDirectory())
FileUT.openAssignFolder(activity!!, StringUT.getDirectory())
}
val mClearLocalBtn = view.findViewById<Button>(R.id.clearLocalBtn)
mClearLocalBtn.setOnClickListener {
FileUT.clearAssignFolder(activity, StringUT.getDirectory())
FileUT.clearAssignFolder(activity!!, StringUT.getDirectory())
Toast.makeText(activity, "清理完成", Toast.LENGTH_SHORT).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.support.v4.app.FragmentActivity
import java.io.File

/**
Expand All @@ -12,7 +13,7 @@ import java.io.File
*/
class FileUT {
companion object {
fun openAssignFolder(activity: Activity, path: String) {
fun openAssignFolder(activity: FragmentActivity, path: String) {
val file = File(path)
if (null == file || !file.exists()) {
return
Expand All @@ -32,7 +33,7 @@ class FileUT {

}

fun clearAssignFolder(mainActivity: Activity, directory: String) {
fun clearAssignFolder(mainActivity: FragmentActivity, directory: String) {
val file = File(directory)
if (null == file || !file.exists()) {
return
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_local_gif.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/localVideoRv"
android:id="@+id/localGifRv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/item_local_gif.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:id="@+id/gifIv"
android:layout_width="120dp"
android:layout_height="120dp" />

<ImageView
android:id="@+id/ivShareGif"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:src="@mipmap/icon_share" />
</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/item_local_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:src="@mipmap/icon_share" />

<ImageView
android:id="@+id/ivGif"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:src="@mipmap/icon_gif" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Expand Down
Binary file added app/src/main/res/mipmap-xxhdpi/icon_gif.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down

0 comments on commit 0614cc5

Please sign in to comment.