├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── xcode126 │ │ └── kgplayer │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── xcode126 │ │ │ └── kgplayer │ │ │ ├── BaseApplication.java │ │ │ ├── MainActivity.java │ │ │ ├── SplashActivity.java │ │ │ ├── VideoPlayerActivity.java │ │ │ ├── base │ │ │ ├── WrapperActivity.java │ │ │ ├── WrapperFragment.java │ │ │ ├── adapter │ │ │ │ ├── TabAdapter.java │ │ │ │ └── ViewHelper.java │ │ │ ├── autolayout │ │ │ │ ├── AutoFrameLayout.java │ │ │ │ ├── AutoLayoutActivity.java │ │ │ │ ├── AutoLayoutInfo.java │ │ │ │ ├── AutoLinearLayout.java │ │ │ │ ├── AutoRelativeLayout.java │ │ │ │ ├── attr │ │ │ │ │ ├── Attrs.java │ │ │ │ │ ├── AutoAttr.java │ │ │ │ │ ├── HeightAttr.java │ │ │ │ │ ├── MarginAttr.java │ │ │ │ │ ├── MarginBottomAttr.java │ │ │ │ │ ├── MarginLeftAttr.java │ │ │ │ │ ├── MarginRightAttr.java │ │ │ │ │ ├── MarginTopAttr.java │ │ │ │ │ ├── MaxHeightAttr.java │ │ │ │ │ ├── MaxWidthAttr.java │ │ │ │ │ ├── MinHeightAttr.java │ │ │ │ │ ├── MinWidthAttr.java │ │ │ │ │ ├── PaddingAttr.java │ │ │ │ │ ├── PaddingBottomAttr.java │ │ │ │ │ ├── PaddingLeftAttr.java │ │ │ │ │ ├── PaddingRightAttr.java │ │ │ │ │ ├── PaddingTopAttr.java │ │ │ │ │ ├── TextSizeAttr.java │ │ │ │ │ └── WidthAttr.java │ │ │ │ ├── config │ │ │ │ │ ├── AutoLayoutConifg.java │ │ │ │ │ └── UseLandscape.java │ │ │ │ ├── utils │ │ │ │ │ ├── AutoLayoutHelper.java │ │ │ │ │ ├── AutoUtils.java │ │ │ │ │ ├── DimenUtils.java │ │ │ │ │ ├── L.java │ │ │ │ │ └── ScreenUtils.java │ │ │ │ └── widget │ │ │ │ │ ├── AutoCardView.java │ │ │ │ │ ├── AutoRadioGroup.java │ │ │ │ │ ├── AutoTabLayout.java │ │ │ │ │ ├── AutoToolbar.java │ │ │ │ │ └── MetroLayout.java │ │ │ ├── listener │ │ │ │ └── OnViewHelper.java │ │ │ └── widget │ │ │ │ ├── BaseRecyclerHolder.java │ │ │ │ ├── CompatBadgeTitleView.java │ │ │ │ ├── CompatMagicIndicator.java │ │ │ │ ├── IndicatorHelper.java │ │ │ │ ├── OnSimplePagerTitleChangeListener.java │ │ │ │ ├── ScrollableViewPager.java │ │ │ │ └── TitleView.java │ │ │ ├── home │ │ │ └── HomeFragment.java │ │ │ ├── local │ │ │ ├── LocalFragment.java │ │ │ ├── adapter │ │ │ │ └── LocalAdapter.java │ │ │ └── model │ │ │ │ └── MediaItem.java │ │ │ ├── me │ │ │ ├── LoginActivity.java │ │ │ ├── LoginFragment.java │ │ │ └── MeFragment.java │ │ │ ├── net │ │ │ ├── NetFragment.java │ │ │ ├── adapter │ │ │ │ └── NetListAdapter.java │ │ │ └── vo │ │ │ │ └── NetListVo.java │ │ │ └── util │ │ │ ├── DateUtils.java │ │ │ ├── DisplayUtil.java │ │ │ ├── ImageManager.java │ │ │ ├── LogUtils.java │ │ │ └── MyJzvdStd.java │ └── res │ │ ├── color │ │ └── selector_tab_text.xml │ │ ├── drawable-xhdpi │ │ ├── ic_tab_audio.png │ │ ├── ic_tab_audio_press.png │ │ ├── ic_tab_netaudio.png │ │ ├── ic_tab_netaudio_press.png │ │ ├── ic_tab_netvideo.png │ │ ├── ic_tab_netvideo_press.png │ │ ├── ic_tab_video.png │ │ ├── ic_tab_video_press.png │ │ ├── return_white.png │ │ ├── splash_bg.jpeg │ │ └── video_default_icon.png │ │ ├── drawable │ │ ├── main_bottom_text_selector.xml │ │ ├── shape_divider_line.xml │ │ ├── shape_tab_divider.xml │ │ ├── shape_tab_dot.xml │ │ └── shape_tab_msg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_splash.xml │ │ ├── activity_video_player.xml │ │ ├── activity_wrapper.xml │ │ ├── common_empty.xml │ │ ├── common_recycler.xml │ │ ├── fragment_home.xml │ │ ├── fragment_me.xml │ │ ├── item_local.xml │ │ ├── view_normal_tab.xml │ │ └── view_title.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_tab_audio.png │ │ ├── ic_tab_audio_press.png │ │ ├── ic_tab_netaudio.png │ │ ├── ic_tab_netaudio_press.png │ │ ├── ic_tab_netvideo.png │ │ ├── ic_tab_netvideo_press.png │ │ ├── ic_tab_video.png │ │ ├── ic_tab_video_press.png │ │ └── splash_image.jpg │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── xcode126 │ └── kgplayer │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KgPlayer 2 | 3 | KgPlayer简介 4 | 5 |     KgPlayer是android手机上功能最多、性能最好的多媒体播放软件,集视频播放、音频播放和电视直播于一身,支持几乎所有流行的视频、音频格式,它将让您的android手机变成您的掌上享乐中心! 6 | 7 | KgPlayer特点 8 | 1. 大聚合 ,囊括了优酷、土豆、乐视网、PPTV、新浪视频、凤凰视频...国内所有网络视频的站点聚合; 9 | 3. 最牛逼 ,支持mp4、3gp、ts、3gpp、3g2、3gpp2、avi、mkv、flv、divx、f4v、rm、rmvb、rv、wmv、asf、mov、mpg、v8、ram、mpeg、swf、m2v、asx、ra、ram、ndivx、xvid等几乎所有主流的视频格式; 10 | 4. 听音乐, 支持mp3、ogg、wma、mid、m4a、xmf、aac、mpa、midi、ar等几乎所有主流的音频格式; 11 | 5.电视直播 ,支持CCTV-1,CCTV-2....CCTV-13,湖南卫视、浙江卫视、江苏卫视全国30多个电视台; 12 | 6. 最绚丽 ,支持歌词同步,支持内嵌歌词解析、lrc歌词解析文件并同步播放、txt歌词文件解析并同步播放,只需你的歌词文件和音频文件一样名字(例如,伤不起.mp3和伤不起.lrc或者伤不起.mp3和伤不起.txt)就可以超酷的歌词同步。 13 | 7. 最独创 ,智能切换软硬解码、一键切换软硬解码; 14 | 8. 超快速 ,顺畅播放,本地视频拖动瞬间缓冲; 15 | 9. 特高清 ,支持高达720p高清视频播放; 16 | 10. 全功能 ,在线与本地高度结合 17 | 11. 最方便 ,播放同一文件,快速定位到上次播放的位置; 18 | 12. 流媒体 ,支持m3u8、HTTP、RTSP、MMS 等主流流媒体格式,可以配合优酷、土豆、pptv、天天浏览器、海豚浏览器等内容提供商使用; 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion "28.0.3" 6 | defaultConfig { 7 | applicationId "com.xcode126.kgplayer" 8 | minSdkVersion 16 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | multiDexEnabled true 13 | } 14 | 15 | compileOptions { 16 | sourceCompatibility 1.8 17 | targetCompatibility 1.8 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | dexOptions { 27 | javaMaxHeapSize "4g" 28 | } 29 | packagingOptions { 30 | exclude 'META-INF/DEPENDENCIES' 31 | exclude 'META-INF/NOTICE' 32 | exclude 'META-INF/LICENSE' 33 | exclude 'META-INF/LICENSE.txt' 34 | exclude 'META-INF/NOTICE.txt' 35 | } 36 | } 37 | 38 | dependencies { 39 | compile fileTree(include: ['*.jar'], dir: 'libs') 40 | implementation 'com.android.support:multidex:1.0.1' 41 | compile 'cn.jzvd:jiaozivideoplayer:7.0.5' 42 | // compile 'cn.jzvd:jiaozivideoplayer:release' 43 | compile 'me.yokeyword:fragmentation:1.1.1' 44 | compile 'com.jakewharton:butterknife:8.4.0' 45 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' 46 | // compile 'com.lzy.net:okgo:3.0.4' 47 | // compile 'com.alibaba:fastjson:1.2.35' 48 | // compile 'org.greenrobot:eventbus:3.0.0' 49 | compile 'com.android.support:appcompat-v7:28.0.0' 50 | compile 'com.android.support:cardview-v7:28.0.0' 51 | implementation 'com.android.support:design:28.0.0' 52 | compile 'com.github.hackware1993:MagicIndicator:1.5.0' 53 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.35' 54 | // compile 'com.github.LuckSiege.PictureSelector:picture_library:v2.1.0' 55 | compile 'com.github.bumptech.glide:glide:3.7.0' 56 | // compile 'com.github.bumptech.glide:okhttp3-integration:4.0.0-RC1' 57 | } 58 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\AndroidStudioSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | 27 | -keep public class cn.jzvd.JZMediaSystem {*; } 28 | -keep public class cn.jzvd.demo.CustomMedia.CustomMedia {*; } 29 | -keep public class cn.jzvd.demo.CustomMedia.JZMediaIjk {*; } 30 | -keep public class cn.jzvd.demo.CustomMedia.JZMediaSystemAssertFolder {*; } 31 | 32 | -keep class tv.danmaku.ijk.media.player.** {*; } 33 | -dontwarn tv.danmaku.ijk.media.player.* 34 | -keep interface tv.danmaku.ijk.media.player.** { *; } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/xcode126/kgplayer/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.xcode126.kgplayer", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 42 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/BaseApplication.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer; 2 | 3 | import android.support.multidex.MultiDexApplication; 4 | 5 | /** 6 | * Created by sky on 2017/3/30. 7 | * 代表整个APP-全局配置 8 | */ 9 | 10 | public class BaseApplication extends MultiDexApplication { 11 | @Override 12 | public void onCreate() { 13 | super.onCreate(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/SplashActivity.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer; 2 | 3 | 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.os.Handler; 7 | import android.widget.ImageView; 8 | 9 | import com.xcode126.kgplayer.base.WrapperActivity; 10 | import com.xcode126.kgplayer.base.widget.TitleView; 11 | 12 | import butterknife.BindView; 13 | 14 | 15 | /** 16 | * 启动页 17 | */ 18 | public class SplashActivity extends WrapperActivity { 19 | 20 | @BindView(R.id.iv_image) 21 | ImageView imageView; 22 | 23 | @Override 24 | protected int getViewLayout() { 25 | return R.layout.activity_splash; 26 | } 27 | 28 | @Override 29 | protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) { 30 | 31 | // Glide.with(this).load(R.drawable.splash_bg) 32 | // .apply(RequestOptions.bitmapTransform(new GlideScaleBottomTransform(AutoUtils.getScreenHeight() / AutoUtils.getScreenWidth()))) 33 | // .into(imageView); 34 | 35 | } 36 | 37 | @Override 38 | protected void loadData(Bundle savedInstanceState, Intent intent) { 39 | new Handler().postDelayed(() -> { 40 | startActivity(MainActivity.getIntent(mActivity)); 41 | finish(); 42 | }, 3000); 43 | } 44 | 45 | @Override 46 | protected boolean isUseTitle() { 47 | return false; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/VideoPlayerActivity.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | 7 | import com.xcode126.kgplayer.base.WrapperActivity; 8 | import com.xcode126.kgplayer.base.widget.TitleView; 9 | import com.xcode126.kgplayer.util.MyJzvdStd; 10 | 11 | import butterknife.BindView; 12 | import cn.jzvd.Jzvd; 13 | import cn.jzvd.JzvdStd; 14 | 15 | /** 16 | * Author:sky on 2019/4/23 15:35. 17 | * Email:xcode126@126.com 18 | * Desc:视频播放界面 19 | */ 20 | 21 | public class VideoPlayerActivity extends WrapperActivity { 22 | 23 | @BindView(R.id.mJzvdStd) 24 | MyJzvdStd mJzvdStd; 25 | 26 | public static Intent getIntent(Context mContext, String title, String url) { 27 | Intent intent = new Intent(mContext, VideoPlayerActivity.class); 28 | intent.putExtra("title", title); 29 | intent.putExtra("url", url); 30 | return intent; 31 | } 32 | 33 | @Override 34 | protected int getViewLayout() { 35 | return R.layout.activity_video_player; 36 | } 37 | 38 | @Override 39 | protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) { 40 | } 41 | 42 | @Override 43 | protected void loadData(Bundle savedInstanceState, Intent intent) { 44 | startPlay(intent); 45 | } 46 | 47 | @Override 48 | protected boolean isUseTitle() { 49 | return false; 50 | } 51 | 52 | /** 53 | * 开启播放 54 | * @param intent 55 | */ 56 | private void startPlay(Intent intent) { 57 | String url = intent.getStringExtra("url"); 58 | String title = intent.getStringExtra("title"); 59 | // JzvdStd.startFullscreenDirectly(this, JzvdStd.class, url, title); 60 | mJzvdStd.setUp(url, "饺子快长大", JzvdStd.SCREEN_NORMAL); 61 | } 62 | 63 | @Override 64 | protected void onPause() { 65 | super.onPause(); 66 | Jzvd.releaseAllVideos(); 67 | } 68 | 69 | @Override 70 | public void onBackPressedSupport() { 71 | if (Jzvd.backPress()) { 72 | return; 73 | } 74 | super.onBackPressedSupport(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/WrapperFragment.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.view.inputmethod.InputMethodManager; 11 | import android.widget.Toast; 12 | 13 | import com.xcode126.kgplayer.base.adapter.ViewHelper; 14 | import com.xcode126.kgplayer.base.listener.OnViewHelper; 15 | 16 | import butterknife.ButterKnife; 17 | import butterknife.Unbinder; 18 | import me.yokeyword.fragmentation.SupportFragment; 19 | 20 | /** 21 | * Author:sky on 2019/9/20 11:29. 22 | * Email:xcode126@126.com 23 | * Desc: 24 | */ 25 | 26 | public abstract class WrapperFragment extends SupportFragment { 27 | 28 | protected View contentView; 29 | private Unbinder unbinder; 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 33 | contentView = inflater.inflate(getViewLayout(), container, false); 34 | return contentView; 35 | } 36 | 37 | @Override 38 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 39 | unbinder = ButterKnife.bind(this, view); 40 | initView(savedInstanceState); 41 | loadData(savedInstanceState); 42 | } 43 | 44 | @Override 45 | public void onDestroyView() { 46 | super.onDestroyView(); 47 | unbinder.unbind(); 48 | } 49 | 50 | /** 51 | * @return 布局resourceId 52 | */ 53 | public abstract int getViewLayout(); 54 | 55 | /** 56 | * 初始化View。或者其他view级第三方控件的初始化,及相关点击事件的绑定 57 | * 58 | * @param savedInstanceState 59 | */ 60 | protected abstract void initView(Bundle savedInstanceState); 61 | 62 | /** 63 | * 获取请求参数,初始化vo对象,并发送请求 64 | * 65 | * @param savedInstanceState 66 | */ 67 | protected abstract void loadData(Bundle savedInstanceState); 68 | 69 | /** 70 | * 实例化对应layoutId的view同时生成ViewHelper 71 | * 72 | * @param group 可为null 73 | * @param layoutId 74 | * @param listener 75 | * @return 76 | */ 77 | protected View getHelperView(ViewGroup group, int layoutId, OnViewHelper listener) { 78 | ViewHelper helper = new ViewHelper(getActivity().getLayoutInflater().inflate(layoutId, group == null ? null : group instanceof RecyclerView ? (ViewGroup) group.getParent() : group, false)); 79 | if (listener != null) { 80 | listener.help(helper); 81 | } 82 | return helper.getItemView(); 83 | } 84 | 85 | 86 | /** 87 | * 设置键盘显否 88 | * 89 | * @param v 90 | * @param visible 91 | */ 92 | protected void setKeyboardVisible(View v, boolean visible) { 93 | InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 94 | if (imm != null) { 95 | if (visible) { 96 | imm.showSoftInput(v, 0); 97 | } else { 98 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 99 | } 100 | } 101 | } 102 | 103 | protected void showToast(String msg) { 104 | Toast.makeText(_mActivity, msg, Toast.LENGTH_SHORT).show(); 105 | } 106 | 107 | protected void showToast(String msg, int resId) { 108 | Toast.makeText(_mActivity, getString(resId), Toast.LENGTH_SHORT).show(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/adapter/TabAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | import android.support.v4.view.PagerAdapter; 7 | import android.view.ViewGroup; 8 | 9 | import com.xcode126.kgplayer.base.WrapperFragment; 10 | 11 | import java.util.List; 12 | 13 | 14 | /** 15 | * Author:sky on 2019/9/20 10:30. 16 | * Email:xcode126@126.com 17 | * Desc:基本adapter 18 | */ 19 | 20 | public class TabAdapter extends FragmentPagerAdapter { 21 | private int position; 22 | 23 | private List list; 24 | 25 | public TabAdapter(FragmentManager fm, List list) { 26 | super(fm); 27 | this.list = list; 28 | } 29 | 30 | public WrapperFragment getCurrentFragment() { 31 | return list.get(position); 32 | } 33 | 34 | public int getCurrentPosition() { 35 | return position; 36 | } 37 | 38 | @Override 39 | public Fragment getItem(int i) { 40 | return list.get(i); 41 | } 42 | 43 | @Override 44 | public void setPrimaryItem(ViewGroup container, int position, Object object) { 45 | super.setPrimaryItem(container, position, object); 46 | this.position = position; 47 | } 48 | 49 | 50 | @Override 51 | public int getCount() { 52 | return list == null ? 0 : list.size(); 53 | } 54 | 55 | @Override 56 | public int getItemPosition(Object object) { 57 | return PagerAdapter.POSITION_NONE; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/AutoFrameLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xcode126.kgplayer.base.autolayout; 18 | 19 | import android.annotation.TargetApi; 20 | import android.content.Context; 21 | import android.os.Build; 22 | import android.util.AttributeSet; 23 | import android.view.ViewGroup; 24 | import android.widget.FrameLayout; 25 | 26 | import com.xcode126.kgplayer.base.autolayout.utils.AutoLayoutHelper; 27 | 28 | 29 | public class AutoFrameLayout extends FrameLayout 30 | { 31 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 32 | 33 | public AutoFrameLayout(Context context) 34 | { 35 | super(context); 36 | } 37 | 38 | public AutoFrameLayout(Context context, AttributeSet attrs) 39 | { 40 | super(context, attrs); 41 | } 42 | 43 | public AutoFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) 44 | { 45 | super(context, attrs, defStyleAttr); 46 | } 47 | 48 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 49 | public AutoFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 50 | super(context, attrs, defStyleAttr, defStyleRes); 51 | } 52 | 53 | @Override 54 | public LayoutParams generateLayoutParams(AttributeSet attrs) 55 | { 56 | return new LayoutParams(getContext(), attrs); 57 | } 58 | 59 | @Override 60 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 61 | { 62 | if (!isInEditMode()) 63 | { 64 | mHelper.adjustChildren(); 65 | } 66 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 67 | } 68 | 69 | @Override 70 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) 71 | { 72 | super.onLayout(changed, left, top, right, bottom); 73 | } 74 | 75 | public static class LayoutParams extends FrameLayout.LayoutParams 76 | implements AutoLayoutHelper.AutoLayoutParams 77 | { 78 | private AutoLayoutInfo mAutoLayoutInfo; 79 | 80 | public LayoutParams(Context c, AttributeSet attrs) 81 | { 82 | super(c, attrs); 83 | 84 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 85 | } 86 | 87 | public LayoutParams(int width, int height) 88 | { 89 | super(width, height); 90 | } 91 | 92 | public LayoutParams(int width, int height, int gravity) 93 | { 94 | super(width, height, gravity); 95 | } 96 | 97 | public LayoutParams(ViewGroup.LayoutParams source) 98 | { 99 | super(source); 100 | } 101 | 102 | public LayoutParams(MarginLayoutParams source) 103 | { 104 | super(source); 105 | } 106 | 107 | public LayoutParams(FrameLayout.LayoutParams source) 108 | { 109 | super((MarginLayoutParams) source); 110 | gravity = source.gravity; 111 | } 112 | 113 | public LayoutParams(LayoutParams source) 114 | { 115 | this((FrameLayout.LayoutParams) source); 116 | mAutoLayoutInfo = source.mAutoLayoutInfo; 117 | } 118 | 119 | @Override 120 | public AutoLayoutInfo getAutoLayoutInfo() 121 | { 122 | return mAutoLayoutInfo; 123 | } 124 | 125 | 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/AutoLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout; 2 | 3 | import android.content.Context; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | 8 | /** 9 | * Created by zhy on 15/11/19. 10 | */ 11 | public class AutoLayoutActivity extends AppCompatActivity 12 | { 13 | private static final String LAYOUT_LINEARLAYOUT = "LinearLayout"; 14 | private static final String LAYOUT_FRAMELAYOUT = "FrameLayout"; 15 | private static final String LAYOUT_RELATIVELAYOUT = "RelativeLayout"; 16 | 17 | 18 | @Override 19 | public View onCreateView(String name, Context context, AttributeSet attrs) 20 | { 21 | View view = null; 22 | if (name.equals(LAYOUT_FRAMELAYOUT)) 23 | { 24 | view = new AutoFrameLayout(context, attrs); 25 | } 26 | 27 | if (name.equals(LAYOUT_LINEARLAYOUT)) 28 | { 29 | view = new AutoLinearLayout(context, attrs); 30 | } 31 | 32 | if (name.equals(LAYOUT_RELATIVELAYOUT)) 33 | { 34 | view = new AutoRelativeLayout(context, attrs); 35 | } 36 | 37 | if (view != null) return view; 38 | 39 | return super.onCreateView(name, context, attrs); 40 | } 41 | 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/AutoLayoutInfo.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | import android.widget.TextView; 6 | 7 | import com.xcode126.kgplayer.base.autolayout.attr.Attrs; 8 | import com.xcode126.kgplayer.base.autolayout.attr.AutoAttr; 9 | import com.xcode126.kgplayer.base.autolayout.attr.HeightAttr; 10 | import com.xcode126.kgplayer.base.autolayout.attr.MarginBottomAttr; 11 | import com.xcode126.kgplayer.base.autolayout.attr.MarginLeftAttr; 12 | import com.xcode126.kgplayer.base.autolayout.attr.MarginRightAttr; 13 | import com.xcode126.kgplayer.base.autolayout.attr.MarginTopAttr; 14 | import com.xcode126.kgplayer.base.autolayout.attr.MaxHeightAttr; 15 | import com.xcode126.kgplayer.base.autolayout.attr.MaxWidthAttr; 16 | import com.xcode126.kgplayer.base.autolayout.attr.MinHeightAttr; 17 | import com.xcode126.kgplayer.base.autolayout.attr.MinWidthAttr; 18 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingBottomAttr; 19 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingLeftAttr; 20 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingRightAttr; 21 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingTopAttr; 22 | import com.xcode126.kgplayer.base.autolayout.attr.TextSizeAttr; 23 | import com.xcode126.kgplayer.base.autolayout.attr.WidthAttr; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | public class AutoLayoutInfo 29 | { 30 | private List autoAttrs = new ArrayList<>(); 31 | 32 | public void addAttr(AutoAttr autoAttr) 33 | { 34 | autoAttrs.add(autoAttr); 35 | } 36 | 37 | 38 | public void fillAttrs(View view) 39 | { 40 | for (AutoAttr autoAttr : autoAttrs) 41 | { 42 | autoAttr.apply(view); 43 | } 44 | } 45 | 46 | 47 | public static AutoLayoutInfo getAttrFromView(View view, int attrs, int base) 48 | { 49 | ViewGroup.LayoutParams params = view.getLayoutParams(); 50 | if (params == null) return null; 51 | AutoLayoutInfo autoLayoutInfo = new AutoLayoutInfo(); 52 | 53 | // width & height 54 | if ((attrs & Attrs.WIDTH) != 0 && params.width > 0) 55 | { 56 | autoLayoutInfo.addAttr(WidthAttr.generate(params.width, base)); 57 | } 58 | 59 | if ((attrs & Attrs.HEIGHT) != 0 && params.height > 0) 60 | { 61 | autoLayoutInfo.addAttr(HeightAttr.generate(params.height, base)); 62 | } 63 | 64 | //margin 65 | if (params instanceof ViewGroup.MarginLayoutParams) 66 | { 67 | if ((attrs & Attrs.MARGIN) != 0) 68 | { 69 | autoLayoutInfo.addAttr(MarginLeftAttr.generate(((ViewGroup.MarginLayoutParams) params).leftMargin, base)); 70 | autoLayoutInfo.addAttr(MarginTopAttr.generate(((ViewGroup.MarginLayoutParams) params).topMargin, base)); 71 | autoLayoutInfo.addAttr(MarginRightAttr.generate(((ViewGroup.MarginLayoutParams) params).rightMargin, base)); 72 | autoLayoutInfo.addAttr(MarginBottomAttr.generate(((ViewGroup.MarginLayoutParams) params).bottomMargin, base)); 73 | } 74 | if ((attrs & Attrs.MARGIN_LEFT) != 0) 75 | { 76 | autoLayoutInfo.addAttr(MarginLeftAttr.generate(((ViewGroup.MarginLayoutParams) params).leftMargin, base)); 77 | } 78 | if ((attrs & Attrs.MARGIN_TOP) != 0) 79 | { 80 | autoLayoutInfo.addAttr(MarginTopAttr.generate(((ViewGroup.MarginLayoutParams) params).topMargin, base)); 81 | } 82 | if ((attrs & Attrs.MARGIN_RIGHT) != 0) 83 | { 84 | autoLayoutInfo.addAttr(MarginRightAttr.generate(((ViewGroup.MarginLayoutParams) params).rightMargin, base)); 85 | } 86 | if ((attrs & Attrs.MARGIN_BOTTOM) != 0) 87 | { 88 | autoLayoutInfo.addAttr(MarginBottomAttr.generate(((ViewGroup.MarginLayoutParams) params).bottomMargin, base)); 89 | } 90 | } 91 | 92 | //padding 93 | if ((attrs & Attrs.PADDING) != 0) 94 | { 95 | autoLayoutInfo.addAttr(PaddingLeftAttr.generate(view.getPaddingLeft(), base)); 96 | autoLayoutInfo.addAttr(PaddingTopAttr.generate(view.getPaddingTop(), base)); 97 | autoLayoutInfo.addAttr(PaddingRightAttr.generate(view.getPaddingRight(), base)); 98 | autoLayoutInfo.addAttr(PaddingBottomAttr.generate(view.getPaddingBottom(), base)); 99 | } 100 | if ((attrs & Attrs.PADDING_LEFT) != 0) 101 | { 102 | autoLayoutInfo.addAttr(MarginLeftAttr.generate(view.getPaddingLeft(), base)); 103 | } 104 | if ((attrs & Attrs.PADDING_TOP) != 0) 105 | { 106 | autoLayoutInfo.addAttr(MarginTopAttr.generate(view.getPaddingTop(), base)); 107 | } 108 | if ((attrs & Attrs.PADDING_RIGHT) != 0) 109 | { 110 | autoLayoutInfo.addAttr(MarginRightAttr.generate(view.getPaddingRight(), base)); 111 | } 112 | if ((attrs & Attrs.PADDING_BOTTOM) != 0) 113 | { 114 | autoLayoutInfo.addAttr(MarginBottomAttr.generate(view.getPaddingBottom(), base)); 115 | } 116 | 117 | //minWidth ,maxWidth , minHeight , maxHeight 118 | if ((attrs & Attrs.MIN_WIDTH) != 0) 119 | { 120 | autoLayoutInfo.addAttr(MinWidthAttr.generate(MinWidthAttr.getMinWidth(view), base)); 121 | } 122 | if ((attrs & Attrs.MAX_WIDTH) != 0) 123 | { 124 | autoLayoutInfo.addAttr(MaxWidthAttr.generate(MaxWidthAttr.getMaxWidth(view), base)); 125 | } 126 | if ((attrs & Attrs.MIN_HEIGHT) != 0) 127 | { 128 | autoLayoutInfo.addAttr(MinHeightAttr.generate(MinHeightAttr.getMinHeight(view), base)); 129 | } 130 | if ((attrs & Attrs.MAX_HEIGHT) != 0) 131 | { 132 | autoLayoutInfo.addAttr(MaxHeightAttr.generate(MaxHeightAttr.getMaxHeight(view), base)); 133 | } 134 | 135 | //textsize 136 | 137 | if (view instanceof TextView) 138 | { 139 | if ((attrs & Attrs.TEXTSIZE) != 0) 140 | { 141 | autoLayoutInfo.addAttr(TextSizeAttr.generate((int) ((TextView) view).getTextSize(), base)); 142 | } 143 | } 144 | return autoLayoutInfo; 145 | } 146 | 147 | 148 | @Override 149 | public String toString() 150 | { 151 | return "AutoLayoutInfo{" + 152 | "autoAttrs=" + autoAttrs + 153 | '}'; 154 | } 155 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/AutoLinearLayout.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.ViewGroup; 8 | import android.widget.LinearLayout; 9 | 10 | import com.xcode126.kgplayer.base.autolayout.utils.AutoLayoutHelper; 11 | 12 | 13 | /** 14 | * Created by zhy on 15/6/30. 15 | */ 16 | public class AutoLinearLayout extends LinearLayout { 17 | 18 | private AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 19 | 20 | public AutoLinearLayout(Context context) { 21 | super(context); 22 | } 23 | 24 | public AutoLinearLayout(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 29 | public AutoLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { 30 | super(context, attrs, defStyleAttr); 31 | } 32 | 33 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 34 | public AutoLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 35 | super(context, attrs, defStyleAttr, defStyleRes); 36 | } 37 | 38 | @Override 39 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 40 | if (!isInEditMode()) 41 | mHelper.adjustChildren(); 42 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 43 | } 44 | 45 | 46 | @Override 47 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 48 | super.onLayout(changed, l, t, r, b); 49 | } 50 | 51 | 52 | @Override 53 | public LayoutParams generateLayoutParams(AttributeSet attrs) { 54 | return new AutoLinearLayout.LayoutParams(getContext(), attrs); 55 | } 56 | 57 | 58 | public static class LayoutParams extends LinearLayout.LayoutParams 59 | implements AutoLayoutHelper.AutoLayoutParams { 60 | private AutoLayoutInfo mAutoLayoutInfo; 61 | 62 | public LayoutParams(Context c, AttributeSet attrs) { 63 | super(c, attrs); 64 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 65 | } 66 | 67 | @Override 68 | public AutoLayoutInfo getAutoLayoutInfo() { 69 | return mAutoLayoutInfo; 70 | } 71 | 72 | 73 | public LayoutParams(int width, int height) { 74 | super(width, height); 75 | } 76 | 77 | 78 | public LayoutParams(ViewGroup.LayoutParams source) { 79 | super(source); 80 | } 81 | 82 | public LayoutParams(MarginLayoutParams source) { 83 | super(source); 84 | } 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/AutoRelativeLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xcode126.kgplayer.base.autolayout; 18 | 19 | import android.annotation.TargetApi; 20 | import android.content.Context; 21 | import android.os.Build; 22 | import android.util.AttributeSet; 23 | import android.view.ViewGroup; 24 | import android.widget.RelativeLayout; 25 | 26 | import com.xcode126.kgplayer.base.autolayout.utils.AutoLayoutHelper; 27 | 28 | 29 | public class AutoRelativeLayout extends RelativeLayout 30 | { 31 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 32 | 33 | public AutoRelativeLayout(Context context) 34 | { 35 | super(context); 36 | } 37 | 38 | public AutoRelativeLayout(Context context, AttributeSet attrs) 39 | { 40 | super(context, attrs); 41 | } 42 | 43 | public AutoRelativeLayout(Context context, AttributeSet attrs, int defStyle) 44 | { 45 | super(context, attrs, defStyle); 46 | } 47 | 48 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 49 | public AutoRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 50 | super(context, attrs, defStyleAttr, defStyleRes); 51 | } 52 | 53 | @Override 54 | public LayoutParams generateLayoutParams(AttributeSet attrs) 55 | { 56 | return new LayoutParams(getContext(), attrs); 57 | } 58 | 59 | @Override 60 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 61 | { 62 | if (!isInEditMode()) 63 | mHelper.adjustChildren(); 64 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 65 | } 66 | 67 | @Override 68 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) 69 | { 70 | super.onLayout(changed, left, top, right, bottom); 71 | } 72 | 73 | 74 | public static class LayoutParams extends RelativeLayout.LayoutParams 75 | implements AutoLayoutHelper.AutoLayoutParams 76 | { 77 | private AutoLayoutInfo mAutoLayoutInfo; 78 | 79 | public LayoutParams(Context c, AttributeSet attrs) 80 | { 81 | super(c, attrs); 82 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 83 | } 84 | 85 | public LayoutParams(int width, int height) 86 | { 87 | super(width, height); 88 | } 89 | 90 | public LayoutParams(ViewGroup.LayoutParams source) 91 | { 92 | super(source); 93 | } 94 | 95 | public LayoutParams(MarginLayoutParams source) 96 | { 97 | super(source); 98 | } 99 | 100 | @Override 101 | public AutoLayoutInfo getAutoLayoutInfo() 102 | { 103 | return mAutoLayoutInfo; 104 | } 105 | 106 | 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/Attrs.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | /** 4 | * Created by zhy on 15/12/5. 5 | *

6 | * 与attrs.xml中数值对应 7 | */ 8 | public interface Attrs 9 | { 10 | public static final int WIDTH = 1; 11 | public static final int HEIGHT = WIDTH << 1; 12 | public static final int TEXTSIZE = HEIGHT << 1; 13 | public static final int PADDING = TEXTSIZE << 1; 14 | public static final int MARGIN = PADDING << 1; 15 | public static final int MARGIN_LEFT = MARGIN << 1; 16 | public static final int MARGIN_TOP = MARGIN_LEFT << 1; 17 | public static final int MARGIN_RIGHT = MARGIN_TOP << 1; 18 | public static final int MARGIN_BOTTOM = MARGIN_RIGHT << 1; 19 | public static final int PADDING_LEFT = MARGIN_BOTTOM << 1; 20 | public static final int PADDING_TOP = PADDING_LEFT << 1; 21 | public static final int PADDING_RIGHT = PADDING_TOP << 1; 22 | public static final int PADDING_BOTTOM = PADDING_RIGHT << 1; 23 | public static final int MIN_WIDTH = PADDING_BOTTOM << 1; 24 | public static final int MAX_WIDTH = MIN_WIDTH << 1; 25 | public static final int MIN_HEIGHT = MAX_WIDTH << 1; 26 | public static final int MAX_HEIGHT = MIN_HEIGHT << 1; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/AutoAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import com.xcode126.kgplayer.base.autolayout.utils.AutoUtils; 6 | import com.xcode126.kgplayer.base.autolayout.utils.L; 7 | 8 | 9 | /** 10 | * Created by zhy on 15/12/4. 11 | */ 12 | public abstract class AutoAttr 13 | { 14 | public static final int BASE_WIDTH = 1; 15 | public static final int BASE_HEIGHT = 2; 16 | public static final int BASE_DEFAULT = 3; 17 | 18 | protected int pxVal; 19 | protected int baseWidth; 20 | protected int baseHeight; 21 | 22 | /* 23 | protected boolean isBaseWidth; 24 | protected boolean isBaseDefault; 25 | 26 | public AutoAttr(int pxVal) 27 | { 28 | this.pxVal = pxVal; 29 | isBaseDefault = true; 30 | } 31 | 32 | public AutoAttr(int pxVal, boolean isBaseWidth) 33 | { 34 | this.pxVal = pxVal; 35 | this.isBaseWidth = isBaseWidth; 36 | } 37 | */ 38 | 39 | public AutoAttr(int pxVal, int baseWidth, int baseHeight) 40 | { 41 | this.pxVal = pxVal; 42 | this.baseWidth = baseWidth; 43 | this.baseHeight = baseHeight; 44 | } 45 | 46 | public void apply(View view) 47 | { 48 | 49 | boolean log = view.getTag() != null && view.getTag().toString().equals("auto"); 50 | 51 | if (log) 52 | { 53 | L.e(" pxVal = " + pxVal + " ," + this.getClass().getSimpleName()); 54 | } 55 | int val; 56 | if (useDefault()) 57 | { 58 | val = defaultBaseWidth() ? getPercentWidthSize() : getPercentHeightSize(); 59 | if (log) 60 | { 61 | L.e(" useDefault val= " + val); 62 | } 63 | } else if (baseWidth()) 64 | { 65 | val = getPercentWidthSize(); 66 | if (log) 67 | { 68 | L.e(" baseWidth val= " + val); 69 | } 70 | } else 71 | { 72 | val = getPercentHeightSize(); 73 | if (log) 74 | { 75 | L.e(" baseHeight val= " + val); 76 | } 77 | } 78 | 79 | if (val > 0) 80 | val = Math.max(val, 1);//for very thin divider 81 | execute(view, val); 82 | } 83 | 84 | protected int getPercentWidthSize() 85 | { 86 | return AutoUtils.getPercentWidthSizeBigger(pxVal); 87 | } 88 | 89 | protected int getPercentHeightSize() 90 | { 91 | return AutoUtils.getPercentHeightSizeBigger(pxVal); 92 | } 93 | 94 | 95 | protected boolean baseWidth() 96 | { 97 | return contains(baseWidth, attrVal()); 98 | } 99 | 100 | protected boolean useDefault() 101 | { 102 | return !contains(baseHeight, attrVal()) && !contains(baseWidth, attrVal()); 103 | } 104 | 105 | protected boolean contains(int baseVal, int flag) 106 | { 107 | return (baseVal & flag) != 0; 108 | } 109 | 110 | protected abstract int attrVal(); 111 | 112 | protected abstract boolean defaultBaseWidth(); 113 | 114 | protected abstract void execute(View view, int val); 115 | 116 | 117 | @Override 118 | public String toString() 119 | { 120 | return "AutoAttr{" + 121 | "pxVal=" + pxVal + 122 | ", baseWidth=" + baseWidth() + 123 | ", defaultBaseWidth=" + defaultBaseWidth() + 124 | '}'; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/HeightAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class HeightAttr extends AutoAttr 10 | { 11 | public HeightAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.HEIGHT; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 32 | lp.height = val; 33 | } 34 | 35 | public static HeightAttr generate(int val, int baseFlag) 36 | { 37 | HeightAttr heightAttr = null; 38 | switch (baseFlag) 39 | { 40 | case AutoAttr.BASE_WIDTH: 41 | heightAttr = new HeightAttr(val, Attrs.HEIGHT, 0); 42 | break; 43 | case AutoAttr.BASE_HEIGHT: 44 | heightAttr = new HeightAttr(val, 0, Attrs.HEIGHT); 45 | break; 46 | case AutoAttr.BASE_DEFAULT: 47 | heightAttr = new HeightAttr(val, 0, 0); 48 | break; 49 | } 50 | return heightAttr; 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MarginAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginAttr extends AutoAttr 10 | { 11 | public MarginAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | public void apply(View view) 30 | { 31 | if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return; 34 | } 35 | if (useDefault()) 36 | { 37 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 38 | lp.leftMargin = lp.rightMargin = getPercentWidthSize(); 39 | lp.topMargin = lp.bottomMargin = getPercentHeightSize(); 40 | return; 41 | } 42 | super.apply(view); 43 | } 44 | 45 | @Override 46 | protected void execute(View view, int val) 47 | { 48 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 49 | lp.leftMargin = lp.rightMargin = lp.topMargin = lp.bottomMargin = val; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MarginBottomAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginBottomAttr extends AutoAttr 10 | { 11 | public MarginBottomAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_BOTTOM; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if(!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return ; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.bottomMargin = val; 37 | } 38 | 39 | public static MarginBottomAttr generate(int val, int baseFlag) 40 | { 41 | MarginBottomAttr attr = null; 42 | switch (baseFlag) 43 | { 44 | case AutoAttr.BASE_WIDTH: 45 | attr = new MarginBottomAttr(val, Attrs.MARGIN_BOTTOM, 0); 46 | break; 47 | case AutoAttr.BASE_HEIGHT: 48 | attr = new MarginBottomAttr(val, 0, Attrs.MARGIN_BOTTOM); 49 | break; 50 | case AutoAttr.BASE_DEFAULT: 51 | attr = new MarginBottomAttr(val, 0, 0); 52 | break; 53 | } 54 | return attr; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MarginLeftAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginLeftAttr extends AutoAttr 10 | { 11 | public MarginLeftAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_LEFT; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return true; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.leftMargin = val; 37 | } 38 | 39 | public static MarginLeftAttr generate(int val, int baseFlag) 40 | { 41 | MarginLeftAttr attr = null; 42 | switch (baseFlag) 43 | { 44 | case AutoAttr.BASE_WIDTH: 45 | attr = new MarginLeftAttr(val, Attrs.MARGIN_LEFT, 0); 46 | break; 47 | case AutoAttr.BASE_HEIGHT: 48 | attr = new MarginLeftAttr(val, 0, Attrs.MARGIN_LEFT); 49 | break; 50 | case AutoAttr.BASE_DEFAULT: 51 | attr = new MarginLeftAttr(val, 0, 0); 52 | break; 53 | } 54 | return attr; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MarginRightAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginRightAttr extends AutoAttr 10 | { 11 | public MarginRightAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_RIGHT; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return true; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.rightMargin = val; 37 | } 38 | 39 | 40 | public static MarginRightAttr generate(int val, int baseFlag) 41 | { 42 | MarginRightAttr attr = null; 43 | switch (baseFlag) 44 | { 45 | case AutoAttr.BASE_WIDTH: 46 | attr = new MarginRightAttr(val, Attrs.MARGIN_RIGHT, 0); 47 | break; 48 | case AutoAttr.BASE_HEIGHT: 49 | attr = new MarginRightAttr(val, 0, Attrs.MARGIN_RIGHT); 50 | break; 51 | case AutoAttr.BASE_DEFAULT: 52 | attr = new MarginRightAttr(val, 0, 0); 53 | break; 54 | } 55 | return attr; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MarginTopAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class MarginTopAttr extends AutoAttr 10 | { 11 | public MarginTopAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.MARGIN_TOP; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return false; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | if (!(view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) 32 | { 33 | return; 34 | } 35 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 36 | lp.topMargin = val; 37 | 38 | } 39 | 40 | 41 | public static MarginTopAttr generate(int val, int baseFlag) 42 | { 43 | MarginTopAttr attr = null; 44 | switch (baseFlag) 45 | { 46 | case AutoAttr.BASE_WIDTH: 47 | attr = new MarginTopAttr(val, Attrs.MARGIN_TOP, 0); 48 | break; 49 | case AutoAttr.BASE_HEIGHT: 50 | attr = new MarginTopAttr(val, 0, Attrs.MARGIN_TOP); 51 | break; 52 | case AutoAttr.BASE_DEFAULT: 53 | attr = new MarginTopAttr(val, 0, 0); 54 | break; 55 | } 56 | return attr; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MaxHeightAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * Created by zhy on 15/12/24. 9 | */ 10 | public class MaxHeightAttr extends AutoAttr 11 | { 12 | public MaxHeightAttr(int pxVal, int baseWidth, int baseHeight) 13 | { 14 | super(pxVal, baseWidth, baseHeight); 15 | } 16 | 17 | @Override 18 | protected int attrVal() 19 | { 20 | return Attrs.MAX_HEIGHT; 21 | } 22 | 23 | @Override 24 | protected boolean defaultBaseWidth() 25 | { 26 | return false; 27 | } 28 | 29 | @Override 30 | protected void execute(View view, int val) 31 | { 32 | try 33 | { 34 | Method setMaxWidthMethod = view.getClass().getMethod("setMaxHeight", int.class); 35 | setMaxWidthMethod.invoke(view, val); 36 | } catch (Exception ignore) 37 | { 38 | } 39 | } 40 | 41 | public static MaxHeightAttr generate(int val, int baseFlag) 42 | { 43 | MaxHeightAttr attr = null; 44 | switch (baseFlag) 45 | { 46 | case AutoAttr.BASE_WIDTH: 47 | attr = new MaxHeightAttr(val, Attrs.MAX_HEIGHT, 0); 48 | break; 49 | case AutoAttr.BASE_HEIGHT: 50 | attr = new MaxHeightAttr(val, 0, Attrs.MAX_HEIGHT); 51 | break; 52 | case AutoAttr.BASE_DEFAULT: 53 | attr = new MaxHeightAttr(val, 0, 0); 54 | break; 55 | } 56 | return attr; 57 | } 58 | 59 | public static int getMaxHeight(View view) 60 | { 61 | try 62 | { 63 | Method setMaxWidthMethod = view.getClass().getMethod("getMaxHeight"); 64 | return (int) setMaxWidthMethod.invoke(view); 65 | } catch (Exception ignore) 66 | { 67 | } 68 | return 0; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MaxWidthAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * Created by zhy on 15/12/24. 9 | */ 10 | public class MaxWidthAttr extends AutoAttr 11 | { 12 | public MaxWidthAttr(int pxVal, int baseWidth, int baseHeight) 13 | { 14 | super(pxVal, baseWidth, baseHeight); 15 | } 16 | 17 | @Override 18 | protected int attrVal() 19 | { 20 | return Attrs.MAX_WIDTH; 21 | } 22 | 23 | @Override 24 | protected boolean defaultBaseWidth() 25 | { 26 | return true; 27 | } 28 | 29 | @Override 30 | protected void execute(View view, int val) 31 | { 32 | try 33 | { 34 | Method setMaxWidthMethod = view.getClass().getMethod("setMaxWidth", int.class); 35 | setMaxWidthMethod.invoke(view, val); 36 | } catch (Exception ignore) 37 | { 38 | } 39 | } 40 | 41 | public static MaxWidthAttr generate(int val, int baseFlag) 42 | { 43 | MaxWidthAttr attr = null; 44 | switch (baseFlag) 45 | { 46 | case AutoAttr.BASE_WIDTH: 47 | attr = new MaxWidthAttr(val, Attrs.MAX_WIDTH, 0); 48 | break; 49 | case AutoAttr.BASE_HEIGHT: 50 | attr = new MaxWidthAttr(val, 0, Attrs.MAX_WIDTH); 51 | break; 52 | case AutoAttr.BASE_DEFAULT: 53 | attr = new MaxWidthAttr(val, 0, 0); 54 | break; 55 | } 56 | return attr; 57 | } 58 | 59 | public static int getMaxWidth(View view) 60 | { 61 | try 62 | { 63 | Method setMaxWidthMethod = view.getClass().getMethod("getMaxWidth"); 64 | return (int) setMaxWidthMethod.invoke(view); 65 | } catch (Exception ignore) 66 | { 67 | } 68 | return 0; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MinHeightAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.os.Build; 4 | import android.view.View; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | /** 9 | * Created by zhy on 15/12/24. 10 | */ 11 | public class MinHeightAttr extends AutoAttr 12 | { 13 | public MinHeightAttr(int pxVal, int baseWidth, int baseHeight) 14 | { 15 | super(pxVal, baseWidth, baseHeight); 16 | } 17 | 18 | @Override 19 | protected int attrVal() 20 | { 21 | return Attrs.MIN_HEIGHT; 22 | } 23 | 24 | @Override 25 | protected boolean defaultBaseWidth() 26 | { 27 | return false; 28 | } 29 | 30 | @Override 31 | protected void execute(View view, int val) 32 | { 33 | try 34 | { 35 | view.setMinimumHeight(val); 36 | // Method setMaxWidthMethod = view.getClass().getMethod("setMinHeight", int.class); 37 | // setMaxWidthMethod.invoke(view, val); 38 | } catch (Exception ignore) 39 | { 40 | } 41 | } 42 | 43 | public static MinHeightAttr generate(int val, int baseFlag) 44 | { 45 | MinHeightAttr attr = null; 46 | switch (baseFlag) 47 | { 48 | case AutoAttr.BASE_WIDTH: 49 | attr = new MinHeightAttr(val, Attrs.MIN_HEIGHT, 0); 50 | break; 51 | case AutoAttr.BASE_HEIGHT: 52 | attr = new MinHeightAttr(val, 0, Attrs.MIN_HEIGHT); 53 | break; 54 | case AutoAttr.BASE_DEFAULT: 55 | attr = new MinHeightAttr(val, 0, 0); 56 | break; 57 | } 58 | return attr; 59 | } 60 | 61 | public static int getMinHeight(View view) 62 | { 63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) 64 | { 65 | return view.getMinimumHeight(); 66 | } else 67 | { 68 | try 69 | { 70 | Field minHeight = view.getClass().getField("mMinHeight"); 71 | minHeight.setAccessible(true); 72 | return (int) minHeight.get(view); 73 | } catch (Exception e) 74 | { 75 | } 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/MinWidthAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.os.Build; 4 | import android.view.View; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | /** 9 | * Created by zhy on 15/12/24. 10 | */ 11 | public class MinWidthAttr extends AutoAttr 12 | { 13 | public MinWidthAttr(int pxVal, int baseWidth, int baseHeight) 14 | { 15 | super(pxVal, baseWidth, baseHeight); 16 | } 17 | 18 | @Override 19 | protected int attrVal() 20 | { 21 | return Attrs.MIN_WIDTH; 22 | } 23 | 24 | @Override 25 | protected boolean defaultBaseWidth() 26 | { 27 | return true; 28 | } 29 | 30 | @Override 31 | protected void execute(View view, int val) 32 | { 33 | try 34 | { 35 | // Method setMaxWidthMethod = view.getClass().getMethod("setMinWidth", int.class); 36 | // setMaxWidthMethod.invoke(view, val); 37 | } catch (Exception ignore) 38 | { 39 | } 40 | 41 | view.setMinimumWidth(val); 42 | } 43 | 44 | public static int getMinWidth(View view) 45 | { 46 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) 47 | return view.getMinimumWidth(); 48 | try 49 | { 50 | Field minWidth = view.getClass().getField("mMinWidth"); 51 | minWidth.setAccessible(true); 52 | return (int) minWidth.get(view); 53 | } catch (Exception ignore) 54 | { 55 | } 56 | return 0; 57 | } 58 | 59 | 60 | public static MinWidthAttr generate(int val, int baseFlag) 61 | { 62 | MinWidthAttr attr = null; 63 | switch (baseFlag) 64 | { 65 | case AutoAttr.BASE_WIDTH: 66 | attr = new MinWidthAttr(val, Attrs.MIN_WIDTH, 0); 67 | break; 68 | case AutoAttr.BASE_HEIGHT: 69 | attr = new MinWidthAttr(val, 0, Attrs.MIN_WIDTH); 70 | break; 71 | case AutoAttr.BASE_DEFAULT: 72 | attr = new MinWidthAttr(val, 0, 0); 73 | break; 74 | } 75 | return attr; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/PaddingAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingAttr extends AutoAttr 9 | { 10 | public PaddingAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING; 19 | } 20 | 21 | @Override 22 | public void apply(View view) 23 | { 24 | int l, t, r, b; 25 | if (useDefault()) 26 | { 27 | l = r = getPercentWidthSize(); 28 | t = b = getPercentHeightSize(); 29 | view.setPadding(l, t, r, b); 30 | return; 31 | } 32 | super.apply(view); 33 | } 34 | 35 | @Override 36 | protected boolean defaultBaseWidth() 37 | { 38 | return false; 39 | } 40 | 41 | @Override 42 | protected void execute(View view, int val) 43 | { 44 | view.setPadding(val, val, val, val); 45 | } 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/PaddingBottomAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingBottomAttr extends AutoAttr 9 | { 10 | public PaddingBottomAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_BOTTOM; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return false; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = view.getPaddingLeft(); 31 | int t = view.getPaddingTop(); 32 | int r = view.getPaddingRight(); 33 | int b = val; 34 | view.setPadding(l, t, r, b); 35 | 36 | } 37 | 38 | 39 | public static PaddingBottomAttr generate(int val, int baseFlag) 40 | { 41 | PaddingBottomAttr attr = null; 42 | switch (baseFlag) 43 | { 44 | case AutoAttr.BASE_WIDTH: 45 | attr = new PaddingBottomAttr(val, Attrs.PADDING_BOTTOM, 0); 46 | break; 47 | case AutoAttr.BASE_HEIGHT: 48 | attr = new PaddingBottomAttr(val, 0, Attrs.PADDING_BOTTOM); 49 | break; 50 | case AutoAttr.BASE_DEFAULT: 51 | attr = new PaddingBottomAttr(val, 0, 0); 52 | break; 53 | } 54 | return attr; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/PaddingLeftAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingLeftAttr extends AutoAttr 9 | { 10 | public PaddingLeftAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_LEFT; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return true; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = val; 31 | int t = view.getPaddingTop(); 32 | int r = view.getPaddingRight(); 33 | int b = view.getPaddingBottom(); 34 | view.setPadding(l, t, r, b); 35 | 36 | } 37 | 38 | 39 | public static PaddingLeftAttr generate(int val, int baseFlag) 40 | { 41 | PaddingLeftAttr attr = null; 42 | switch (baseFlag) 43 | { 44 | case AutoAttr.BASE_WIDTH: 45 | attr = new PaddingLeftAttr(val, Attrs.PADDING_LEFT, 0); 46 | break; 47 | case AutoAttr.BASE_HEIGHT: 48 | attr = new PaddingLeftAttr(val, 0, Attrs.PADDING_LEFT); 49 | break; 50 | case AutoAttr.BASE_DEFAULT: 51 | attr = new PaddingLeftAttr(val, 0, 0); 52 | break; 53 | } 54 | return attr; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/PaddingRightAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingRightAttr extends AutoAttr 9 | { 10 | public PaddingRightAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_RIGHT; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return true; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = view.getPaddingLeft(); 31 | int t = view.getPaddingTop(); 32 | int r = val; 33 | int b = view.getPaddingBottom(); 34 | view.setPadding(l, t, r, b); 35 | 36 | } 37 | 38 | 39 | public static PaddingRightAttr generate(int val, int baseFlag) 40 | { 41 | PaddingRightAttr attr = null; 42 | switch (baseFlag) 43 | { 44 | case AutoAttr.BASE_WIDTH: 45 | attr = new PaddingRightAttr(val, Attrs.PADDING_RIGHT, 0); 46 | break; 47 | case AutoAttr.BASE_HEIGHT: 48 | attr = new PaddingRightAttr(val, 0, Attrs.PADDING_RIGHT); 49 | break; 50 | case AutoAttr.BASE_DEFAULT: 51 | attr = new PaddingRightAttr(val, 0, 0); 52 | break; 53 | } 54 | return attr; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/PaddingTopAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by zhy on 15/12/5. 7 | */ 8 | public class PaddingTopAttr extends AutoAttr 9 | { 10 | public PaddingTopAttr(int pxVal, int baseWidth, int baseHeight) 11 | { 12 | super(pxVal, baseWidth, baseHeight); 13 | } 14 | 15 | @Override 16 | protected int attrVal() 17 | { 18 | return Attrs.PADDING_TOP; 19 | } 20 | 21 | @Override 22 | protected boolean defaultBaseWidth() 23 | { 24 | return false; 25 | } 26 | 27 | @Override 28 | protected void execute(View view, int val) 29 | { 30 | int l = view.getPaddingLeft(); 31 | int t = val; 32 | int r = view.getPaddingRight(); 33 | int b = view.getPaddingBottom(); 34 | view.setPadding(l, t, r, b); 35 | } 36 | 37 | public static PaddingTopAttr generate(int val, int baseFlag) 38 | { 39 | PaddingTopAttr attr = null; 40 | switch (baseFlag) 41 | { 42 | case AutoAttr.BASE_WIDTH: 43 | attr = new PaddingTopAttr(val, Attrs.PADDING_TOP, 0); 44 | break; 45 | case AutoAttr.BASE_HEIGHT: 46 | attr = new PaddingTopAttr(val, 0, Attrs.PADDING_TOP); 47 | break; 48 | case AutoAttr.BASE_DEFAULT: 49 | attr = new PaddingTopAttr(val, 0, 0); 50 | break; 51 | } 52 | return attr; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/TextSizeAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.util.TypedValue; 4 | import android.view.View; 5 | import android.widget.TextView; 6 | 7 | /** 8 | * Created by zhy on 15/12/4. 9 | */ 10 | public class TextSizeAttr extends AutoAttr 11 | { 12 | 13 | public TextSizeAttr(int pxVal, int baseWidth, int baseHeight) 14 | { 15 | super(pxVal, baseWidth, baseHeight); 16 | } 17 | 18 | @Override 19 | protected int attrVal() 20 | { 21 | return Attrs.TEXTSIZE; 22 | } 23 | 24 | @Override 25 | protected boolean defaultBaseWidth() 26 | { 27 | return false; 28 | } 29 | 30 | @Override 31 | protected void execute(View view, int val) 32 | { 33 | if (!(view instanceof TextView)) 34 | return; 35 | ((TextView) view).setIncludeFontPadding(false); 36 | ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, val); 37 | } 38 | 39 | public static TextSizeAttr generate(int val, int baseFlag) 40 | { 41 | TextSizeAttr attr = null; 42 | switch (baseFlag) 43 | { 44 | case AutoAttr.BASE_WIDTH: 45 | attr = new TextSizeAttr(val, Attrs.TEXTSIZE, 0); 46 | break; 47 | case AutoAttr.BASE_HEIGHT: 48 | attr = new TextSizeAttr(val, 0, Attrs.TEXTSIZE); 49 | break; 50 | case AutoAttr.BASE_DEFAULT: 51 | attr = new TextSizeAttr(val, 0, 0); 52 | break; 53 | } 54 | return attr; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/attr/WidthAttr.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.attr; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | /** 7 | * Created by zhy on 15/12/5. 8 | */ 9 | public class WidthAttr extends AutoAttr 10 | { 11 | public WidthAttr(int pxVal, int baseWidth, int baseHeight) 12 | { 13 | super(pxVal, baseWidth, baseHeight); 14 | } 15 | 16 | @Override 17 | protected int attrVal() 18 | { 19 | return Attrs.WIDTH; 20 | } 21 | 22 | @Override 23 | protected boolean defaultBaseWidth() 24 | { 25 | return true; 26 | } 27 | 28 | @Override 29 | protected void execute(View view, int val) 30 | { 31 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 32 | lp.width = val; 33 | } 34 | 35 | public static WidthAttr generate(int val, int baseFlag) 36 | { 37 | WidthAttr widthAttr = null; 38 | switch (baseFlag) 39 | { 40 | case AutoAttr.BASE_WIDTH: 41 | widthAttr = new WidthAttr(val, Attrs.WIDTH, 0); 42 | break; 43 | case AutoAttr.BASE_HEIGHT: 44 | widthAttr = new WidthAttr(val, 0, Attrs.WIDTH); 45 | break; 46 | case AutoAttr.BASE_DEFAULT: 47 | widthAttr = new WidthAttr(val, 0, 0); 48 | break; 49 | } 50 | return widthAttr; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/config/AutoLayoutConifg.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.config; 2 | 3 | import android.content.Context; 4 | import android.content.pm.ApplicationInfo; 5 | import android.content.pm.PackageManager; 6 | import com.xcode126.kgplayer.base.autolayout.utils.L; 7 | import com.xcode126.kgplayer.base.autolayout.utils.ScreenUtils; 8 | 9 | 10 | /** 11 | * Created by zhy on 15/11/18. 12 | */ 13 | public class AutoLayoutConifg 14 | { 15 | 16 | private static AutoLayoutConifg sIntance = new AutoLayoutConifg(); 17 | 18 | 19 | private static final String KEY_DESIGN_WIDTH = "design_width"; 20 | private static final String KEY_DESIGN_HEIGHT = "design_height"; 21 | 22 | private int mScreenWidth; 23 | private int mScreenHeight; 24 | 25 | private int mDesignWidth; 26 | private int mDesignHeight; 27 | 28 | private boolean useDeviceSize; 29 | 30 | 31 | private AutoLayoutConifg() 32 | { 33 | } 34 | 35 | public void checkParams() 36 | { 37 | if (mDesignHeight <= 0 || mDesignWidth <= 0) 38 | { 39 | throw new RuntimeException( 40 | "you must set " + KEY_DESIGN_WIDTH + " and " + KEY_DESIGN_HEIGHT + " in your manifest file."); 41 | } 42 | } 43 | 44 | public AutoLayoutConifg useDeviceSize() 45 | { 46 | useDeviceSize = true; 47 | return this; 48 | } 49 | 50 | 51 | public static AutoLayoutConifg getInstance() 52 | { 53 | return sIntance; 54 | } 55 | 56 | 57 | public int getScreenWidth() 58 | { 59 | return mScreenWidth; 60 | } 61 | 62 | public int getScreenHeight() 63 | { 64 | return mScreenHeight; 65 | } 66 | 67 | public int getDesignWidth() 68 | { 69 | return mDesignWidth; 70 | } 71 | 72 | public int getDesignHeight() 73 | { 74 | return mDesignHeight; 75 | } 76 | 77 | 78 | public void init(Context context) 79 | { 80 | getMetaData(context); 81 | 82 | int[] screenSize = ScreenUtils.getScreenSize(context, useDeviceSize); 83 | mScreenWidth = screenSize[0]; 84 | mScreenHeight = screenSize[1]; 85 | L.e(" screenWidth =" + mScreenWidth + " ,screenHeight = " + mScreenHeight); 86 | } 87 | 88 | private void getMetaData(Context context) 89 | { 90 | PackageManager packageManager = context.getPackageManager(); 91 | ApplicationInfo applicationInfo; 92 | try 93 | { 94 | applicationInfo = packageManager.getApplicationInfo(context 95 | .getPackageName(), PackageManager.GET_META_DATA); 96 | if (applicationInfo != null && applicationInfo.metaData != null) 97 | { 98 | mDesignWidth = (int) applicationInfo.metaData.get(KEY_DESIGN_WIDTH); 99 | mDesignHeight = (int) applicationInfo.metaData.get(KEY_DESIGN_HEIGHT); 100 | } 101 | } catch (PackageManager.NameNotFoundException e) 102 | { 103 | throw new RuntimeException( 104 | "you must set " + KEY_DESIGN_WIDTH + " and " + KEY_DESIGN_HEIGHT + " in your manifest file.", e); 105 | } 106 | 107 | L.e(" designWidth =" + mDesignWidth + " , designHeight = " + mDesignHeight); 108 | } 109 | 110 | 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/config/UseLandscape.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.config; 2 | 3 | /** 4 | * Created by zhy on 15/12/5. 5 | * 如果Activity设计稿是横屏,继承该接口即可 6 | */ 7 | public interface UseLandscape 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/utils/AutoLayoutHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.xcode126.kgplayer.base.autolayout.utils; 18 | 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.util.AttributeSet; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | 25 | import com.xcode126.kgplayer.R; 26 | import com.xcode126.kgplayer.base.autolayout.AutoLayoutInfo; 27 | import com.xcode126.kgplayer.base.autolayout.attr.HeightAttr; 28 | import com.xcode126.kgplayer.base.autolayout.attr.MarginAttr; 29 | import com.xcode126.kgplayer.base.autolayout.attr.MarginBottomAttr; 30 | import com.xcode126.kgplayer.base.autolayout.attr.MarginLeftAttr; 31 | import com.xcode126.kgplayer.base.autolayout.attr.MarginRightAttr; 32 | import com.xcode126.kgplayer.base.autolayout.attr.MarginTopAttr; 33 | import com.xcode126.kgplayer.base.autolayout.attr.MaxHeightAttr; 34 | import com.xcode126.kgplayer.base.autolayout.attr.MaxWidthAttr; 35 | import com.xcode126.kgplayer.base.autolayout.attr.MinHeightAttr; 36 | import com.xcode126.kgplayer.base.autolayout.attr.MinWidthAttr; 37 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingAttr; 38 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingBottomAttr; 39 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingLeftAttr; 40 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingRightAttr; 41 | import com.xcode126.kgplayer.base.autolayout.attr.PaddingTopAttr; 42 | import com.xcode126.kgplayer.base.autolayout.attr.TextSizeAttr; 43 | import com.xcode126.kgplayer.base.autolayout.attr.WidthAttr; 44 | import com.xcode126.kgplayer.base.autolayout.config.AutoLayoutConifg; 45 | 46 | 47 | public class AutoLayoutHelper 48 | { 49 | private final ViewGroup mHost; 50 | 51 | private static final int[] LL = new int[] 52 | { // 53 | android.R.attr.textSize, 54 | android.R.attr.padding,// 55 | android.R.attr.paddingLeft,// 56 | android.R.attr.paddingTop,// 57 | android.R.attr.paddingRight,// 58 | android.R.attr.paddingBottom,// 59 | android.R.attr.layout_width,// 60 | android.R.attr.layout_height,// 61 | android.R.attr.layout_margin,// 62 | android.R.attr.layout_marginLeft,// 63 | android.R.attr.layout_marginTop,// 64 | android.R.attr.layout_marginRight,// 65 | android.R.attr.layout_marginBottom,// 66 | android.R.attr.maxWidth,// 67 | android.R.attr.maxHeight,// 68 | android.R.attr.minWidth,// 69 | android.R.attr.minHeight,//16843072 70 | 71 | 72 | }; 73 | 74 | private static final int INDEX_TEXT_SIZE = 0; 75 | private static final int INDEX_PADDING = 1; 76 | private static final int INDEX_PADDING_LEFT = 2; 77 | private static final int INDEX_PADDING_TOP = 3; 78 | private static final int INDEX_PADDING_RIGHT = 4; 79 | private static final int INDEX_PADDING_BOTTOM = 5; 80 | private static final int INDEX_WIDTH = 6; 81 | private static final int INDEX_HEIGHT = 7; 82 | private static final int INDEX_MARGIN = 8; 83 | private static final int INDEX_MARGIN_LEFT = 9; 84 | private static final int INDEX_MARGIN_TOP = 10; 85 | private static final int INDEX_MARGIN_RIGHT = 11; 86 | private static final int INDEX_MARGIN_BOTTOM = 12; 87 | private static final int INDEX_MAX_WIDTH = 13; 88 | private static final int INDEX_MAX_HEIGHT = 14; 89 | private static final int INDEX_MIN_WIDTH = 15; 90 | private static final int INDEX_MIN_HEIGHT = 16; 91 | 92 | 93 | /** 94 | * move to other place? 95 | */ 96 | private static AutoLayoutConifg mAutoLayoutConifg; 97 | 98 | public AutoLayoutHelper(ViewGroup host) 99 | { 100 | mHost = host; 101 | 102 | if (mAutoLayoutConifg == null) 103 | { 104 | initAutoLayoutConfig(host); 105 | } 106 | 107 | } 108 | 109 | private void initAutoLayoutConfig(ViewGroup host) 110 | { 111 | mAutoLayoutConifg = AutoLayoutConifg.getInstance(); 112 | mAutoLayoutConifg.init(host.getContext()); 113 | } 114 | 115 | 116 | public void adjustChildren() 117 | { 118 | AutoLayoutConifg.getInstance().checkParams(); 119 | 120 | for (int i = 0, n = mHost.getChildCount(); i < n; i++) 121 | { 122 | View view = mHost.getChildAt(i); 123 | ViewGroup.LayoutParams params = view.getLayoutParams(); 124 | 125 | if (params instanceof AutoLayoutParams) 126 | { 127 | AutoLayoutInfo info = 128 | ((AutoLayoutParams) params).getAutoLayoutInfo(); 129 | if (info != null) 130 | { 131 | info.fillAttrs(view); 132 | } 133 | } 134 | } 135 | 136 | } 137 | 138 | public static AutoLayoutInfo getAutoLayoutInfo(Context context, 139 | AttributeSet attrs) 140 | { 141 | 142 | AutoLayoutInfo info = new AutoLayoutInfo(); 143 | 144 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoLayout_Layout); 145 | int baseWidth = a.getInt(R.styleable.AutoLayout_Layout_layout_auto_basewidth, 0); 146 | int baseHeight = a.getInt(R.styleable.AutoLayout_Layout_layout_auto_baseheight, 0); 147 | a.recycle(); 148 | 149 | TypedArray array = context.obtainStyledAttributes(attrs, LL); 150 | 151 | int n = array.getIndexCount(); 152 | 153 | 154 | for (int i = 0; i < n; i++) 155 | { 156 | int index = array.getIndex(i); 157 | // String val = array.getString(index); 158 | // if (!isPxVal(val)) continue; 159 | 160 | if (!DimenUtils.isPxVal(array.peekValue(index))) continue; 161 | 162 | int pxVal = 0; 163 | try 164 | { 165 | pxVal = array.getDimensionPixelOffset(index, 0); 166 | } catch (Exception ignore)//not dimension 167 | { 168 | continue; 169 | } 170 | switch (index) 171 | { 172 | case INDEX_TEXT_SIZE: 173 | info.addAttr(new TextSizeAttr(pxVal, baseWidth, baseHeight)); 174 | break; 175 | case INDEX_PADDING: 176 | info.addAttr(new PaddingAttr(pxVal, baseWidth, baseHeight)); 177 | break; 178 | case INDEX_PADDING_LEFT: 179 | info.addAttr(new PaddingLeftAttr(pxVal, baseWidth, baseHeight)); 180 | break; 181 | case INDEX_PADDING_TOP: 182 | info.addAttr(new PaddingTopAttr(pxVal, baseWidth, baseHeight)); 183 | break; 184 | case INDEX_PADDING_RIGHT: 185 | info.addAttr(new PaddingRightAttr(pxVal, baseWidth, baseHeight)); 186 | break; 187 | case INDEX_PADDING_BOTTOM: 188 | info.addAttr(new PaddingBottomAttr(pxVal, baseWidth, baseHeight)); 189 | break; 190 | case INDEX_WIDTH: 191 | info.addAttr(new WidthAttr(pxVal, baseWidth, baseHeight)); 192 | break; 193 | case INDEX_HEIGHT: 194 | info.addAttr(new HeightAttr(pxVal, baseWidth, baseHeight)); 195 | break; 196 | case INDEX_MARGIN: 197 | info.addAttr(new MarginAttr(pxVal, baseWidth, baseHeight)); 198 | break; 199 | case INDEX_MARGIN_LEFT: 200 | info.addAttr(new MarginLeftAttr(pxVal, baseWidth, baseHeight)); 201 | break; 202 | case INDEX_MARGIN_TOP: 203 | info.addAttr(new MarginTopAttr(pxVal, baseWidth, baseHeight)); 204 | break; 205 | case INDEX_MARGIN_RIGHT: 206 | info.addAttr(new MarginRightAttr(pxVal, baseWidth, baseHeight)); 207 | break; 208 | case INDEX_MARGIN_BOTTOM: 209 | info.addAttr(new MarginBottomAttr(pxVal, baseWidth, baseHeight)); 210 | break; 211 | case INDEX_MAX_WIDTH: 212 | info.addAttr(new MaxWidthAttr(pxVal, baseWidth, baseHeight)); 213 | break; 214 | case INDEX_MAX_HEIGHT: 215 | info.addAttr(new MaxHeightAttr(pxVal, baseWidth, baseHeight)); 216 | break; 217 | case INDEX_MIN_WIDTH: 218 | info.addAttr(new MinWidthAttr(pxVal, baseWidth, baseHeight)); 219 | break; 220 | case INDEX_MIN_HEIGHT: 221 | info.addAttr(new MinHeightAttr(pxVal, baseWidth, baseHeight)); 222 | break; 223 | } 224 | } 225 | array.recycle(); 226 | L.e(" getAutoLayoutInfo " + info.toString()); 227 | return info; 228 | } 229 | 230 | public interface AutoLayoutParams 231 | { 232 | AutoLayoutInfo getAutoLayoutInfo(); 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/utils/AutoUtils.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.utils; 2 | 3 | import android.view.View; 4 | 5 | import com.xcode126.kgplayer.R; 6 | import com.xcode126.kgplayer.base.autolayout.AutoLayoutInfo; 7 | import com.xcode126.kgplayer.base.autolayout.attr.Attrs; 8 | import com.xcode126.kgplayer.base.autolayout.attr.AutoAttr; 9 | import com.xcode126.kgplayer.base.autolayout.config.AutoLayoutConifg; 10 | 11 | 12 | /** 13 | * Created by zhy on 15/12/4. 14 | */ 15 | public class AutoUtils { 16 | 17 | /** 18 | * 会直接将view的LayoutParams上设置的width,height直接进行百分比处理 19 | * 20 | * @param view 21 | */ 22 | public static void auto(View view) { 23 | autoSize(view); 24 | autoPadding(view); 25 | autoMargin(view); 26 | autoTextSize(view, AutoAttr.BASE_DEFAULT); 27 | } 28 | 29 | /** 30 | * @param view 31 | * @param attrs #Attrs.WIDTH|Attrs.HEIGHT 32 | * @param base AutoAttr.BASE_WIDTH|AutoAttr.BASE_HEIGHT|AutoAttr.BASE_DEFAULT 33 | */ 34 | public static void auto(View view, int attrs, int base) { 35 | AutoLayoutInfo autoLayoutInfo = AutoLayoutInfo.getAttrFromView(view, attrs, base); 36 | if (autoLayoutInfo != null) 37 | autoLayoutInfo.fillAttrs(view); 38 | } 39 | 40 | public static void autoTextSize(View view) { 41 | auto(view, Attrs.TEXTSIZE, AutoAttr.BASE_DEFAULT); 42 | } 43 | 44 | public static void autoTextSize(View view, int base) { 45 | auto(view, Attrs.TEXTSIZE, base); 46 | } 47 | 48 | public static void autoMargin(View view) { 49 | auto(view, Attrs.MARGIN, AutoAttr.BASE_DEFAULT); 50 | } 51 | 52 | public static void autoMargin(View view, int base) { 53 | auto(view, Attrs.MARGIN, base); 54 | } 55 | 56 | public static void autoPadding(View view) { 57 | auto(view, Attrs.PADDING, AutoAttr.BASE_DEFAULT); 58 | } 59 | 60 | public static void autoPadding(View view, int base) { 61 | auto(view, Attrs.PADDING, base); 62 | } 63 | 64 | public static void autoSize(View view) { 65 | auto(view, Attrs.WIDTH | Attrs.HEIGHT, AutoAttr.BASE_DEFAULT); 66 | } 67 | 68 | public static void autoSize(View view, int base) { 69 | auto(view, Attrs.WIDTH | Attrs.HEIGHT, base); 70 | } 71 | 72 | public static boolean autoed(View view) { 73 | Object tag = view.getTag(R.id.id_tag_autolayout_size); 74 | if (tag != null) return true; 75 | view.setTag(R.id.id_tag_autolayout_size, "Just Identify"); 76 | return false; 77 | } 78 | 79 | public static float getPercentWidth1px() { 80 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); 81 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); 82 | return 1.0f * screenWidth / designWidth; 83 | } 84 | 85 | public static float getPercentHeight1px() { 86 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); 87 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); 88 | return 1.0f * screenHeight / designHeight; 89 | } 90 | 91 | 92 | public static int getPercentWidthSize(int val) { 93 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); 94 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); 95 | return (int) (val * 1.0f / designWidth * screenWidth); 96 | } 97 | 98 | 99 | public static int getPercentWidthSizeBigger(int val) { 100 | int screenWidth = AutoLayoutConifg.getInstance().getScreenWidth(); 101 | int designWidth = AutoLayoutConifg.getInstance().getDesignWidth(); 102 | 103 | int res = val * screenWidth; 104 | if (res % designWidth == 0) { 105 | return res / designWidth; 106 | } else { 107 | return res / designWidth + 1; 108 | } 109 | 110 | } 111 | 112 | public static int getPercentHeightSizeBigger(int val) { 113 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); 114 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); 115 | 116 | int res = val * screenHeight; 117 | if (res % designHeight == 0) { 118 | return res / designHeight; 119 | } else { 120 | return res / designHeight + 1; 121 | } 122 | } 123 | 124 | public static int getPercentHeightSize(int val) { 125 | int screenHeight = AutoLayoutConifg.getInstance().getScreenHeight(); 126 | int designHeight = AutoLayoutConifg.getInstance().getDesignHeight(); 127 | 128 | return (int) (val * 1.0f / designHeight * screenHeight); 129 | } 130 | 131 | public static float getScreenHeight() { 132 | return AutoLayoutConifg.getInstance().getScreenHeight(); 133 | } 134 | 135 | public static float getScreenWidth() { 136 | return AutoLayoutConifg.getInstance().getScreenWidth(); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/utils/DimenUtils.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.utils; 2 | 3 | import android.util.TypedValue; 4 | 5 | /** 6 | * Created by zhy on 16/3/3. 7 | */ 8 | public class DimenUtils 9 | { 10 | private static int getComplexUnit(int data) 11 | { 12 | return TypedValue.COMPLEX_UNIT_MASK & (data >> TypedValue.COMPLEX_UNIT_SHIFT); 13 | } 14 | 15 | public static boolean isPxVal(TypedValue val) 16 | { 17 | if (val != null && val.type == TypedValue.TYPE_DIMENSION && 18 | getComplexUnit(val.data) == TypedValue.COMPLEX_UNIT_PX) 19 | { 20 | return true; 21 | } 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/utils/L.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.utils; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by zhy on 15/11/18. 7 | */ 8 | public class L 9 | { 10 | public static boolean debug = false; 11 | private static final String TAG = "AUTO_LAYOUT"; 12 | 13 | public static void e(String msg) 14 | { 15 | if (debug) 16 | { 17 | Log.e(TAG, msg); 18 | } 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/utils/ScreenUtils.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.utils; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Point; 6 | import android.os.Build; 7 | import android.util.DisplayMetrics; 8 | import android.view.Display; 9 | import android.view.WindowManager; 10 | 11 | /** 12 | * Created by zhy on 15/12/4.
13 | * form http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels/15699681#15699681 14 | */ 15 | public class ScreenUtils 16 | { 17 | 18 | public static int getStatusBarHeight(Context context) 19 | { 20 | int result = 0; 21 | try 22 | { 23 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); 24 | if (resourceId > 0) 25 | { 26 | result = context.getResources().getDimensionPixelSize(resourceId); 27 | } 28 | } catch (Resources.NotFoundException e) 29 | { 30 | e.printStackTrace(); 31 | } 32 | return result; 33 | } 34 | 35 | 36 | public static int[] getScreenSize(Context context, boolean useDeviceSize) 37 | { 38 | 39 | int[] size = new int[2]; 40 | 41 | WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 42 | Display d = w.getDefaultDisplay(); 43 | DisplayMetrics metrics = new DisplayMetrics(); 44 | d.getMetrics(metrics); 45 | // since SDK_INT = 1; 46 | int widthPixels = metrics.widthPixels; 47 | int heightPixels = metrics.heightPixels; 48 | 49 | if (!useDeviceSize) 50 | { 51 | size[0] = widthPixels; 52 | size[1] = heightPixels - getStatusBarHeight(context); 53 | 54 | return size; 55 | } 56 | 57 | // includes window decorations (statusbar bar/menu bar) 58 | if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) 59 | try 60 | { 61 | widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d); 62 | heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d); 63 | } catch (Exception ignored) 64 | { 65 | } 66 | // includes window decorations (statusbar bar/menu bar) 67 | if (Build.VERSION.SDK_INT >= 17) 68 | try 69 | { 70 | Point realSize = new Point(); 71 | Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize); 72 | widthPixels = realSize.x; 73 | heightPixels = realSize.y; 74 | } catch (Exception ignored) 75 | { 76 | } 77 | size[0] = widthPixels; 78 | size[1] = heightPixels; 79 | return size; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/widget/AutoCardView.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.CardView; 5 | import android.util.AttributeSet; 6 | import com.xcode126.kgplayer.base.autolayout.AutoFrameLayout; 7 | import com.xcode126.kgplayer.base.autolayout.utils.AutoLayoutHelper; 8 | 9 | 10 | /** 11 | * Created by zhy on 15/12/8. 12 | */ 13 | public class AutoCardView extends CardView { 14 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 15 | 16 | public AutoCardView(Context context) { 17 | super(context); 18 | } 19 | 20 | public AutoCardView(Context context, AttributeSet attrs) { 21 | super(context, attrs); 22 | } 23 | 24 | public AutoCardView(Context context, AttributeSet attrs, int defStyleAttr) { 25 | super(context, attrs, defStyleAttr); 26 | } 27 | 28 | @Override 29 | public AutoFrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) { 30 | return new AutoFrameLayout.LayoutParams(getContext(), attrs); 31 | } 32 | 33 | @Override 34 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 35 | if (!isInEditMode()) { 36 | mHelper.adjustChildren(); 37 | } 38 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/widget/AutoRadioGroup.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.ViewGroup; 6 | import android.widget.RadioGroup; 7 | 8 | import com.xcode126.kgplayer.base.autolayout.AutoLayoutInfo; 9 | import com.xcode126.kgplayer.base.autolayout.utils.AutoLayoutHelper; 10 | 11 | 12 | /** 13 | * Created by hupei on 2016/2/29 9:59. 14 | */ 15 | public class AutoRadioGroup extends RadioGroup 16 | { 17 | private AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 18 | 19 | public AutoRadioGroup(Context context) 20 | { 21 | super(context); 22 | } 23 | 24 | public AutoRadioGroup(Context context, AttributeSet attrs) 25 | { 26 | super(context, attrs); 27 | } 28 | 29 | 30 | @Override 31 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 32 | { 33 | if (!isInEditMode()) 34 | mHelper.adjustChildren(); 35 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 36 | } 37 | 38 | @Override 39 | protected void onLayout(boolean changed, int l, int t, int r, int b) 40 | { 41 | super.onLayout(changed, l, t, r, b); 42 | } 43 | 44 | @Override 45 | public LayoutParams generateLayoutParams(AttributeSet attrs) 46 | { 47 | return new LayoutParams(getContext(), attrs); 48 | } 49 | 50 | public static class LayoutParams extends RadioGroup.LayoutParams 51 | implements AutoLayoutHelper.AutoLayoutParams 52 | { 53 | private AutoLayoutInfo mAutoLayoutInfo; 54 | 55 | public LayoutParams(Context c, AttributeSet attrs) 56 | { 57 | super(c, attrs); 58 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 59 | } 60 | 61 | @Override 62 | public AutoLayoutInfo getAutoLayoutInfo() 63 | { 64 | return mAutoLayoutInfo; 65 | } 66 | 67 | 68 | public LayoutParams(int width, int height) 69 | { 70 | super(width, height); 71 | } 72 | 73 | public LayoutParams(ViewGroup.LayoutParams source) 74 | { 75 | super(source); 76 | } 77 | 78 | public LayoutParams(MarginLayoutParams source) 79 | { 80 | super(source); 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/widget/AutoTabLayout.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.support.design.widget.TabLayout; 6 | import android.util.AttributeSet; 7 | import android.util.TypedValue; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.xcode126.kgplayer.R; 12 | import com.xcode126.kgplayer.base.autolayout.utils.AutoUtils; 13 | import com.xcode126.kgplayer.base.autolayout.utils.DimenUtils; 14 | 15 | 16 | /** 17 | * Created by zhy on 16/3/3. 18 | */ 19 | public class AutoTabLayout extends TabLayout 20 | { 21 | private static final int NO_VALID = -1; 22 | private int mTextSize; 23 | private boolean mTextSizeBaseWidth = false; 24 | 25 | public AutoTabLayout(Context context) 26 | { 27 | this(context, null); 28 | } 29 | 30 | public AutoTabLayout(Context context, AttributeSet attrs) 31 | { 32 | this(context, attrs, 0); 33 | } 34 | 35 | public AutoTabLayout(Context context, AttributeSet attrs, int defStyleAttr) 36 | { 37 | super(context, attrs, defStyleAttr); 38 | 39 | initTextSizeBaseWidth(context, attrs); 40 | 41 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, 42 | defStyleAttr, R.style.Widget_Design_TabLayout); 43 | int tabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance, 44 | R.style.TextAppearance_Design_Tab); 45 | 46 | mTextSize = loadTextSizeFromTextAppearance(tabTextAppearance); 47 | a.recycle(); 48 | } 49 | 50 | private void initTextSizeBaseWidth(Context context, AttributeSet attrs) 51 | { 52 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoTabLayout); 53 | mTextSizeBaseWidth = a.getBoolean(R.styleable.AutoTabLayout_auto_textSize_base_width, false); 54 | a.recycle(); 55 | } 56 | 57 | private int loadTextSizeFromTextAppearance(int textAppearanceResId) 58 | { 59 | TypedArray a = getContext().obtainStyledAttributes(textAppearanceResId, 60 | R.styleable.TextAppearance); 61 | 62 | try 63 | { 64 | if (!DimenUtils.isPxVal(a.peekValue(R.styleable.TextAppearance_android_textSize))) 65 | return NO_VALID; 66 | return a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, NO_VALID); 67 | } finally 68 | { 69 | a.recycle(); 70 | } 71 | } 72 | 73 | @Override 74 | public void addTab(Tab tab, int position, boolean setSelected) 75 | { 76 | super.addTab(tab, position, setSelected); 77 | setUpTabTextSize(tab); 78 | } 79 | 80 | @Override 81 | public void addTab(Tab tab, boolean setSelected) 82 | { 83 | super.addTab(tab, setSelected); 84 | setUpTabTextSize(tab); 85 | } 86 | 87 | private void setUpTabTextSize(Tab tab) 88 | { 89 | if (mTextSize == NO_VALID || tab.getCustomView() != null) return; 90 | 91 | ViewGroup tabGroup = (ViewGroup) getChildAt(0); 92 | ViewGroup tabContainer = (ViewGroup) tabGroup.getChildAt(tab.getPosition()); 93 | TextView textView = (TextView) tabContainer.getChildAt(1); 94 | 95 | 96 | if (AutoUtils.autoed(textView)) 97 | { 98 | return; 99 | } 100 | int autoTextSize = 0 ; 101 | if (mTextSizeBaseWidth) 102 | { 103 | autoTextSize = AutoUtils.getPercentWidthSize(mTextSize); 104 | } else 105 | { 106 | autoTextSize = AutoUtils.getPercentHeightSize(mTextSize); 107 | } 108 | 109 | 110 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, autoTextSize); 111 | } 112 | 113 | 114 | } 115 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/widget/AutoToolbar.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.widget; 2 | 3 | import android.content.Context; 4 | import android.text.TextUtils; 5 | import android.util.AttributeSet; 6 | import android.util.TypedValue; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | import android.widget.Toolbar; 10 | 11 | import com.xcode126.kgplayer.base.autolayout.AutoLayoutInfo; 12 | import com.xcode126.kgplayer.base.autolayout.utils.AutoLayoutHelper; 13 | import com.xcode126.kgplayer.base.autolayout.utils.AutoUtils; 14 | 15 | import java.lang.reflect.Field; 16 | 17 | 18 | /** 19 | * Created by hupei on 2015/12/28 20:33. 20 | */ 21 | public class AutoToolbar extends Toolbar { 22 | private static final int NO_VALID = -1; 23 | private int mTextSize; 24 | private int mSubTextSize; 25 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 26 | 27 | public AutoToolbar(Context context, AttributeSet attrs, int defStyleAttr) { 28 | super(context, attrs, defStyleAttr); 29 | } 30 | 31 | public AutoToolbar(Context context, AttributeSet attrs) { 32 | this(context, attrs, 0); 33 | } 34 | 35 | public AutoToolbar(Context context) { 36 | this(context, null); 37 | } 38 | 39 | 40 | private void setUpTitleTextSize() { 41 | CharSequence title = getTitle(); 42 | if (!TextUtils.isEmpty(title) && mTextSize != NO_VALID) 43 | setUpTitleTextSize("mTitleTextView", mTextSize); 44 | CharSequence subtitle = getSubtitle(); 45 | if (!TextUtils.isEmpty(subtitle) && mSubTextSize != NO_VALID) 46 | setUpTitleTextSize("mSubtitleTextView", mSubTextSize); 47 | } 48 | 49 | private void setUpTitleTextSize(String name, int val) { 50 | try { 51 | //反射 Toolbar 的 TextView 52 | Field f = getClass().getSuperclass().getDeclaredField(name); 53 | f.setAccessible(true); 54 | TextView textView = (TextView) f.get(this); 55 | if (textView != null) { 56 | int autoTextSize = AutoUtils.getPercentHeightSize(val); 57 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, autoTextSize); 58 | } 59 | } catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | 64 | @Override 65 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 66 | if (!this.isInEditMode()) { 67 | setUpTitleTextSize(); 68 | this.mHelper.adjustChildren(); 69 | } 70 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 71 | } 72 | 73 | @Override 74 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 75 | super.onLayout(changed, l, t, r, b); 76 | } 77 | 78 | @Override 79 | public LayoutParams generateLayoutParams(AttributeSet attrs) { 80 | return new LayoutParams(this.getContext(), attrs); 81 | } 82 | 83 | public static class LayoutParams extends Toolbar.LayoutParams implements AutoLayoutHelper.AutoLayoutParams { 84 | private AutoLayoutInfo mDimenLayoutInfo; 85 | 86 | public LayoutParams(Context c, AttributeSet attrs) { 87 | super(c, attrs); 88 | this.mDimenLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 89 | } 90 | 91 | @Override 92 | public AutoLayoutInfo getAutoLayoutInfo() { 93 | return this.mDimenLayoutInfo; 94 | } 95 | 96 | public LayoutParams(int width, int height) { 97 | super(width, height); 98 | } 99 | 100 | public LayoutParams(android.view.ViewGroup.LayoutParams source) { 101 | super(source); 102 | } 103 | 104 | public LayoutParams(ViewGroup.MarginLayoutParams source) { 105 | super(source); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/autolayout/widget/MetroLayout.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.autolayout.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Color; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.xcode126.kgplayer.R; 11 | import com.xcode126.kgplayer.base.autolayout.AutoLayoutInfo; 12 | import com.xcode126.kgplayer.base.autolayout.utils.AutoLayoutHelper; 13 | import com.xcode126.kgplayer.base.autolayout.utils.AutoUtils; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.Random; 18 | 19 | 20 | /** 21 | * Created by zhy on 15/12/10. 22 | * 23 | * //do not use 24 | */ 25 | public class MetroLayout extends ViewGroup 26 | { 27 | 28 | private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); 29 | 30 | private static class MetroBlock 31 | { 32 | int left; 33 | int top; 34 | int width; 35 | } 36 | 37 | private List mAvailablePos = new ArrayList<>(); 38 | private int mDivider; 39 | 40 | public MetroLayout(Context context, AttributeSet attrs) 41 | { 42 | super(context, attrs); 43 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MetroLayout); 44 | mDivider = a.getDimensionPixelOffset(R.styleable.MetroLayout_metro_divider, 0); 45 | mDivider = AutoUtils.getPercentWidthSizeBigger(mDivider); 46 | a.recycle(); 47 | 48 | } 49 | 50 | @Override 51 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 52 | { 53 | 54 | if (true) 55 | randomColor(); 56 | 57 | if (!isInEditMode()) 58 | mHelper.adjustChildren(); 59 | 60 | measureChildren(widthMeasureSpec, heightMeasureSpec); 61 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 62 | 63 | } 64 | 65 | private void randomColor() 66 | { 67 | Random r = new Random(255); 68 | 69 | for (int i = 0, n = getChildCount(); i < n; i++) 70 | { 71 | View v = getChildAt(i); 72 | 73 | v.setBackgroundColor(Color.argb(100, r.nextInt(), r.nextInt(), r.nextInt())); 74 | } 75 | } 76 | 77 | 78 | @Override 79 | protected void onLayout(boolean changed, int l, int t, int r, int b) 80 | { 81 | 82 | initAvailablePosition(); 83 | 84 | int left = 0; 85 | int top = 0; 86 | int divider = mDivider; 87 | 88 | for (int i = 0, n = getChildCount(); i < n; i++) 89 | { 90 | View v = getChildAt(i); 91 | if (v.getVisibility() == View.GONE) continue; 92 | 93 | MetroBlock newPos = findAvailablePos(v); 94 | left = newPos.left; 95 | top = newPos.top; 96 | 97 | int childWidth = v.getMeasuredWidth(); 98 | int childHeight = v.getMeasuredHeight(); 99 | 100 | int right = left + childWidth; 101 | int bottom = top + childHeight; 102 | 103 | v.layout(left, top, right, bottom); 104 | 105 | if (childWidth + divider < newPos.width) 106 | { 107 | newPos.left += childWidth + divider; 108 | newPos.width -= childWidth + divider; 109 | } else 110 | { 111 | mAvailablePos.remove(newPos); 112 | } 113 | 114 | MetroBlock p = new MetroBlock(); 115 | p.left = left; 116 | p.top = bottom + divider; 117 | p.width = childWidth; 118 | mAvailablePos.add(p); 119 | 120 | mergeAvailablePosition(); 121 | 122 | } 123 | } 124 | 125 | private void mergeAvailablePosition() 126 | { 127 | if (mAvailablePos.size() <= 1) return; 128 | 129 | List needRemoveBlocks = new ArrayList<>(); 130 | 131 | MetroBlock one = mAvailablePos.get(0); 132 | MetroBlock two = mAvailablePos.get(1); 133 | 134 | for (int i = 1, n = mAvailablePos.size(); i < n - 1; i++) 135 | { 136 | if (one.top == two.top) 137 | { 138 | one.width = one.width + two.width; 139 | needRemoveBlocks.add(one); 140 | two.left = one.left; 141 | two = mAvailablePos.get(i + 1); 142 | } else 143 | { 144 | one = mAvailablePos.get(i); 145 | two = mAvailablePos.get(i + 1); 146 | } 147 | } 148 | 149 | mAvailablePos.removeAll(needRemoveBlocks); 150 | 151 | } 152 | 153 | private void initAvailablePosition() 154 | { 155 | mAvailablePos.clear(); 156 | MetroBlock first = new MetroBlock(); 157 | first.left = getPaddingLeft(); 158 | first.top = getPaddingTop(); 159 | first.width = getMeasuredWidth(); 160 | mAvailablePos.add(first); 161 | } 162 | 163 | private MetroBlock findAvailablePos(View view) 164 | { 165 | MetroBlock p = new MetroBlock(); 166 | if (mAvailablePos.size() == 0) 167 | { 168 | p.left = getPaddingLeft(); 169 | p.top = getPaddingTop(); 170 | p.width = getMeasuredWidth(); 171 | return p; 172 | } 173 | int min = mAvailablePos.get(0).top; 174 | MetroBlock minHeightPos = mAvailablePos.get(0); 175 | for (MetroBlock _p : mAvailablePos) 176 | { 177 | if (_p.top < min) 178 | { 179 | min = _p.top; 180 | minHeightPos = _p; 181 | } 182 | } 183 | return minHeightPos; 184 | } 185 | 186 | 187 | @Override 188 | public MetroLayout.LayoutParams generateLayoutParams(AttributeSet attrs) 189 | { 190 | return new LayoutParams(getContext(), attrs); 191 | } 192 | 193 | public static class LayoutParams extends MarginLayoutParams 194 | implements AutoLayoutHelper.AutoLayoutParams 195 | { 196 | private AutoLayoutInfo mAutoLayoutInfo; 197 | 198 | public LayoutParams(Context c, AttributeSet attrs) 199 | { 200 | super(c, attrs); 201 | mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs); 202 | } 203 | 204 | public LayoutParams(int width, int height) 205 | { 206 | super(width, height); 207 | } 208 | 209 | public LayoutParams(ViewGroup.LayoutParams source) 210 | { 211 | super(source); 212 | } 213 | 214 | public LayoutParams(MarginLayoutParams source) 215 | { 216 | super(source); 217 | } 218 | 219 | public LayoutParams(LayoutParams source) 220 | { 221 | this((ViewGroup.LayoutParams) source); 222 | mAutoLayoutInfo = source.mAutoLayoutInfo; 223 | } 224 | 225 | @Override 226 | public AutoLayoutInfo getAutoLayoutInfo() 227 | { 228 | return mAutoLayoutInfo; 229 | } 230 | 231 | 232 | } 233 | 234 | } 235 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/listener/OnViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.listener; 2 | 3 | 4 | import com.xcode126.kgplayer.base.adapter.ViewHelper; 5 | 6 | /** 7 | * Auther: winds 8 | * Data: 2017/6/11 9 | * Desc: 10 | */ 11 | 12 | public interface OnViewHelper { 13 | void help(ViewHelper helper); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/widget/BaseRecyclerHolder.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.widget; 2 | 3 | import android.view.View; 4 | import android.widget.TextView; 5 | 6 | import com.chad.library.adapter.base.BaseViewHolder; 7 | import com.xcode126.kgplayer.base.autolayout.utils.AutoUtils; 8 | 9 | 10 | 11 | /** 12 | * Author:sky on 2019/4/23 15:02. 13 | * Email:xcode126@126.com 14 | * Desc:自定义BaseRecyclerHolder 15 | */ 16 | 17 | 18 | public class BaseRecyclerHolder extends BaseViewHolder { 19 | 20 | public BaseRecyclerHolder(View view) { 21 | super(view); 22 | AutoUtils.auto(view); 23 | } 24 | 25 | public BaseRecyclerHolder setVisibleText(int viewId, CharSequence msg) { 26 | TextView view = getView(viewId); 27 | view.setVisibility(View.VISIBLE); 28 | view.setText(msg); 29 | return this; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/widget/CompatBadgeTitleView.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.widget; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.FrameLayout; 7 | 8 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView; 9 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; 10 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgeAnchor; 11 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgeRule; 12 | 13 | /** 14 | * Auther: winds 15 | * Data: 2018/3/3 16 | * Version: 1.0 17 | * Desc: 可适配添加角标 18 | */ 19 | 20 | 21 | public class CompatBadgeTitleView extends FrameLayout implements IMeasurablePagerTitleView { 22 | private IPagerTitleView mInnerPagerTitleView; 23 | private View mBadgeView; 24 | private boolean mAutoCancelBadge = true; 25 | private BadgeRule mXBadgeRule; 26 | private BadgeRule mYBadgeRule; 27 | 28 | public CompatBadgeTitleView(Context context) { 29 | super(context); 30 | } 31 | 32 | public void onSelected(int index, int totalCount) { 33 | if (this.mInnerPagerTitleView != null) { 34 | this.mInnerPagerTitleView.onSelected(index, totalCount); 35 | } 36 | 37 | if (this.mAutoCancelBadge) { 38 | this.setBadgeView((View) null); 39 | } 40 | 41 | } 42 | 43 | public void onDeselected(int index, int totalCount) { 44 | if (this.mInnerPagerTitleView != null) { 45 | this.mInnerPagerTitleView.onDeselected(index, totalCount); 46 | } 47 | 48 | } 49 | 50 | public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) { 51 | if (this.mInnerPagerTitleView != null) { 52 | this.mInnerPagerTitleView.onLeave(index, totalCount, leavePercent, leftToRight); 53 | } 54 | 55 | } 56 | 57 | public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) { 58 | if (this.mInnerPagerTitleView != null) { 59 | this.mInnerPagerTitleView.onEnter(index, totalCount, enterPercent, leftToRight); 60 | } 61 | 62 | } 63 | 64 | public IPagerTitleView getInnerPagerTitleView() { 65 | return this.mInnerPagerTitleView; 66 | } 67 | 68 | public void setInnerPagerTitleView(IPagerTitleView innerPagerTitleView) { 69 | if (this.mInnerPagerTitleView != innerPagerTitleView) { 70 | this.mInnerPagerTitleView = innerPagerTitleView; 71 | this.removeAllViews(); 72 | LayoutParams lp; 73 | if (this.mInnerPagerTitleView instanceof View) { 74 | lp = new LayoutParams(-1, -1); 75 | this.addView((View) this.mInnerPagerTitleView, lp); 76 | } 77 | 78 | if (this.mBadgeView != null) { 79 | if (this.mBadgeView.getLayoutParams() == null) { 80 | lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, -2); 81 | this.addView(this.mBadgeView, lp); 82 | } else { 83 | this.addView(this.mBadgeView); 84 | } 85 | } 86 | 87 | } 88 | } 89 | 90 | public View getBadgeView() { 91 | return this.mBadgeView; 92 | } 93 | 94 | public void setBadgeView(View badgeView) { 95 | if (this.mBadgeView != badgeView) { 96 | this.mBadgeView = badgeView; 97 | this.removeAllViews(); 98 | LayoutParams lp; 99 | if (this.mInnerPagerTitleView instanceof View) { 100 | lp = new LayoutParams(-1, -1); 101 | this.addView((View) this.mInnerPagerTitleView, lp); 102 | } 103 | 104 | if (this.mBadgeView != null) { 105 | if (this.mBadgeView.getLayoutParams() == null) { 106 | lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, -2); 107 | this.addView(this.mBadgeView, lp); 108 | } else { 109 | this.addView(this.mBadgeView); 110 | } 111 | } 112 | 113 | } 114 | } 115 | 116 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 117 | super.onLayout(changed, left, top, right, bottom); 118 | if (this.mInnerPagerTitleView instanceof View && this.mBadgeView != null) { 119 | int[] position = new int[14]; 120 | View v = (View) this.mInnerPagerTitleView; 121 | position[0] = v.getLeft(); 122 | position[1] = v.getTop(); 123 | position[2] = v.getRight(); 124 | position[3] = v.getBottom(); 125 | int y; 126 | if (this.mInnerPagerTitleView instanceof IMeasurablePagerTitleView) { 127 | IMeasurablePagerTitleView view = (IMeasurablePagerTitleView) this.mInnerPagerTitleView; 128 | position[4] = view.getContentLeft(); 129 | position[5] = view.getContentTop(); 130 | position[6] = view.getContentRight(); 131 | position[7] = view.getContentBottom(); 132 | } else { 133 | for (y = 4; y < 8; ++y) { 134 | position[y] = position[y - 4]; 135 | } 136 | } 137 | 138 | position[8] = v.getWidth() / 2; 139 | position[9] = v.getHeight() / 2; 140 | position[10] = position[4] / 2; 141 | position[11] = position[5] / 2; 142 | position[12] = position[6] + (position[2] - position[6]) / 2; 143 | position[13] = position[7] + (position[3] - position[7]) / 2; 144 | int offset; 145 | int newTop; 146 | if (this.mXBadgeRule != null) { 147 | y = position[this.mXBadgeRule.getAnchor().ordinal()]; 148 | offset = this.mXBadgeRule.getOffset(); 149 | newTop = y + offset; 150 | this.mBadgeView.offsetLeftAndRight(newTop - this.mBadgeView.getLeft()); 151 | } 152 | 153 | if (this.mYBadgeRule != null) { 154 | y = position[this.mYBadgeRule.getAnchor().ordinal()]; 155 | offset = this.mYBadgeRule.getOffset(); 156 | newTop = y + offset; 157 | this.mBadgeView.offsetTopAndBottom(newTop - this.mBadgeView.getTop()); 158 | } 159 | } 160 | 161 | } 162 | 163 | public int getContentLeft() { 164 | return this.mInnerPagerTitleView instanceof IMeasurablePagerTitleView ? this.getLeft() + ((IMeasurablePagerTitleView) this.mInnerPagerTitleView).getContentLeft() : this.getLeft(); 165 | } 166 | 167 | public int getContentTop() { 168 | return this.mInnerPagerTitleView instanceof IMeasurablePagerTitleView ? ((IMeasurablePagerTitleView) this.mInnerPagerTitleView).getContentTop() : this.getTop(); 169 | } 170 | 171 | public int getContentRight() { 172 | return this.mInnerPagerTitleView instanceof IMeasurablePagerTitleView ? this.getLeft() + ((IMeasurablePagerTitleView) this.mInnerPagerTitleView).getContentRight() : this.getRight(); 173 | } 174 | 175 | public int getContentBottom() { 176 | return this.mInnerPagerTitleView instanceof IMeasurablePagerTitleView ? ((IMeasurablePagerTitleView) this.mInnerPagerTitleView).getContentBottom() : this.getBottom(); 177 | } 178 | 179 | public BadgeRule getXBadgeRule() { 180 | return this.mXBadgeRule; 181 | } 182 | 183 | public void setXBadgeRule(BadgeRule badgeRule) { 184 | if (badgeRule != null) { 185 | BadgeAnchor anchor = badgeRule.getAnchor(); 186 | if (anchor != BadgeAnchor.LEFT && anchor != BadgeAnchor.RIGHT && anchor != BadgeAnchor.CONTENT_LEFT && anchor != BadgeAnchor.CONTENT_RIGHT && anchor != BadgeAnchor.CENTER_X && anchor != BadgeAnchor.LEFT_EDGE_CENTER_X && anchor != BadgeAnchor.RIGHT_EDGE_CENTER_X) { 187 | throw new IllegalArgumentException("x badge rule is wrong."); 188 | } 189 | } 190 | 191 | this.mXBadgeRule = badgeRule; 192 | } 193 | 194 | public BadgeRule getYBadgeRule() { 195 | return this.mYBadgeRule; 196 | } 197 | 198 | public void setYBadgeRule(BadgeRule badgeRule) { 199 | if (badgeRule != null) { 200 | BadgeAnchor anchor = badgeRule.getAnchor(); 201 | if (anchor != BadgeAnchor.TOP && anchor != BadgeAnchor.BOTTOM && anchor != BadgeAnchor.CONTENT_TOP && anchor != BadgeAnchor.CONTENT_BOTTOM && anchor != BadgeAnchor.CENTER_Y && anchor != BadgeAnchor.TOP_EDGE_CENTER_Y && anchor != BadgeAnchor.BOTTOM_EDGE_CENTER_Y) { 202 | throw new IllegalArgumentException("y badge rule is wrong."); 203 | } 204 | } 205 | 206 | this.mYBadgeRule = badgeRule; 207 | } 208 | 209 | public boolean isAutoCancelBadge() { 210 | return this.mAutoCancelBadge; 211 | } 212 | 213 | public void setAutoCancelBadge(boolean autoCancelBadge) { 214 | this.mAutoCancelBadge = autoCancelBadge; 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/widget/CompatMagicIndicator.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import net.lucode.hackware.magicindicator.MagicIndicator; 7 | import net.lucode.hackware.magicindicator.abs.IPagerNavigator; 8 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator; 9 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; 10 | 11 | /** 12 | * Auther: winds 13 | * Data: 2018/3/3 14 | * Version: 1.0 15 | * Desc: 16 | */ 17 | 18 | 19 | public class CompatMagicIndicator extends MagicIndicator { 20 | 21 | protected IndicatorHelper helper; 22 | 23 | public CompatMagicIndicator(Context context) { 24 | this(context, null); 25 | } 26 | 27 | public CompatMagicIndicator(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | init(); 30 | } 31 | 32 | 33 | void init() { 34 | helper = new IndicatorHelper(this); 35 | } 36 | 37 | public IndicatorHelper getIndicatorHelper() { 38 | return helper; 39 | } 40 | 41 | public CompatBadgeTitleView getCompatBadgeTitleView(int index) { 42 | IPagerNavigator navigator = getNavigator(); 43 | if (navigator != null && navigator instanceof CommonNavigator) { 44 | IPagerTitleView view = ((CommonNavigator) navigator).getPagerTitleView(index); 45 | if (view != null && view instanceof CompatBadgeTitleView) { 46 | return (CompatBadgeTitleView) view; 47 | } 48 | } 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/widget/IndicatorHelper.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.widget; 2 | 3 | import net.lucode.hackware.magicindicator.FragmentContainerHelper; 4 | import net.lucode.hackware.magicindicator.MagicIndicator; 5 | 6 | /** 7 | * Auther: winds 8 | * Data: 2018/3/3 9 | * Version: 1.0 10 | * Desc: 指示器的帮助类 可获得当前指示器的position 11 | */ 12 | 13 | 14 | public class IndicatorHelper extends FragmentContainerHelper { 15 | private int selectedIndex; 16 | 17 | public IndicatorHelper(MagicIndicator magicIndicator) { 18 | super(magicIndicator); 19 | } 20 | 21 | @Override 22 | public void handlePageSelected(int selectedIndex) { 23 | super.handlePageSelected(selectedIndex); 24 | this.selectedIndex = selectedIndex; 25 | } 26 | 27 | public int getSelectedIndex() { 28 | return selectedIndex; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/widget/OnSimplePagerTitleChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.widget; 2 | 3 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView; 4 | 5 | /** 6 | * Author:sky on 2019/4/23 11:58. 7 | * Email:xcode126@126.com 8 | * Desc: 9 | */ 10 | 11 | public class OnSimplePagerTitleChangeListener implements CommonPagerTitleView.OnPagerTitleChangeListener{ 12 | @Override 13 | public void onSelected(int i, int i1) { 14 | 15 | } 16 | 17 | @Override 18 | public void onDeselected(int i, int i1) { 19 | 20 | } 21 | 22 | @Override 23 | public void onLeave(int i, int i1, float v, boolean b) { 24 | 25 | } 26 | 27 | @Override 28 | public void onEnter(int i, int i1, float v, boolean b) { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/widget/ScrollableViewPager.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | 8 | /** 9 | * 可控制是否允许滑动的ViewPager 10 | * 默认false 11 | */ 12 | public class ScrollableViewPager extends ViewPager { 13 | private boolean scrollable = false; 14 | 15 | public ViewPager setScrollable(boolean scrollable) { 16 | this.scrollable = scrollable; 17 | return null; 18 | } 19 | 20 | public ScrollableViewPager(Context context, AttributeSet attrs) { 21 | super(context, attrs); 22 | } 23 | 24 | public ScrollableViewPager(Context context) { 25 | super(context); 26 | } 27 | 28 | @Override 29 | public void scrollTo(int x, int y) { 30 | super.scrollTo(x, y); 31 | } 32 | 33 | @Override 34 | public boolean onTouchEvent(MotionEvent arg0) { 35 | if (!scrollable) 36 | return false; 37 | else 38 | return super.onTouchEvent(arg0); 39 | } 40 | 41 | @Override 42 | public boolean onInterceptTouchEvent(MotionEvent arg0) { 43 | if (!scrollable) 44 | return false; 45 | else 46 | return super.onInterceptTouchEvent(arg0); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/base/widget/TitleView.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.base.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | import android.widget.RelativeLayout; 8 | import android.widget.TextView; 9 | 10 | import com.xcode126.kgplayer.R; 11 | 12 | /** 13 | * Auther: winds 14 | * Data: 2017/4/12 15 | * Desc: 16 | */ 17 | 18 | public class TitleView extends RelativeLayout { 19 | 20 | public TitleView(Context context) { 21 | this(context, null); 22 | } 23 | 24 | public TitleView(Context context, AttributeSet attrs) { 25 | this(context, attrs, 0); 26 | } 27 | 28 | public TitleView(Context context, AttributeSet attrs, int defStyle) { 29 | super(context, attrs, defStyle); 30 | init(context, attrs); 31 | } 32 | 33 | private void init(Context context, AttributeSet attrs) { 34 | View.inflate(context, R.layout.view_title, this); 35 | } 36 | 37 | public void setTitle(String title) { 38 | setText(R.id.tv_title_center, title); 39 | } 40 | 41 | public T getView(int viewId) { 42 | return (T) findViewById(viewId); 43 | } 44 | 45 | public TitleView setText(TextView view, String text) { 46 | view.setVisibility(VISIBLE); 47 | view.setText(text); 48 | return this; 49 | } 50 | 51 | public TitleView setText(int viewId, String text) { 52 | View view = findViewById(viewId); 53 | if (view instanceof TextView) { 54 | return setText((TextView) view, text); 55 | } 56 | return this; 57 | } 58 | 59 | 60 | public TitleView setImageResource(int viewId, int resId) { 61 | View view = findViewById(viewId); 62 | if (view instanceof ImageView) { 63 | return setImageResource((ImageView) view, resId); 64 | } 65 | return this; 66 | } 67 | 68 | public TitleView setImageResource(ImageView view, int resId) { 69 | view.setVisibility(VISIBLE); 70 | view.setImageResource(resId); 71 | return this; 72 | } 73 | 74 | public boolean checkVisible(View view) { 75 | return view == null ? false : view.getVisibility() == VISIBLE ? true : false; 76 | } 77 | 78 | public TitleView setVisible(int viewId, boolean visible) { 79 | return setVisible(findViewById(viewId), visible); 80 | } 81 | 82 | public TitleView setVisible(View view, boolean visible) { 83 | view.setVisibility(visible ? VISIBLE : GONE); 84 | return this; 85 | } 86 | 87 | 88 | public TitleView setChildClickListener(View view, OnClickListener listener) { 89 | if (view != null) { 90 | view.setOnClickListener(listener); 91 | } 92 | return this; 93 | } 94 | 95 | public TitleView setChildClickListener(int viewId, OnClickListener listener) { 96 | return setChildClickListener(findViewById(viewId), listener); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/home/HomeFragment.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.home; 2 | 3 | import android.os.Bundle; 4 | import com.xcode126.kgplayer.R; 5 | import com.xcode126.kgplayer.base.WrapperFragment; 6 | 7 | 8 | /** 9 | * 作者:sky 10 | * 邮箱:xcode126@126.com 11 | * QQ号:1397028339 12 | * 公众号:程序教科书 13 | * desc:首页 14 | */ 15 | 16 | public class HomeFragment extends WrapperFragment { 17 | 18 | public static HomeFragment newInstance() { 19 | return new HomeFragment(); 20 | } 21 | 22 | @Override 23 | public int getViewLayout() { 24 | return R.layout.fragment_home; 25 | } 26 | 27 | @Override 28 | protected void initView(Bundle savedInstanceState) { 29 | 30 | } 31 | @Override 32 | protected void loadData(Bundle savedInstanceState) { 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/local/LocalFragment.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.local; 2 | 3 | import android.content.ContentResolver; 4 | import android.database.Cursor; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | import android.os.Message; 9 | import android.provider.MediaStore; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | 13 | import com.xcode126.kgplayer.R; 14 | import com.xcode126.kgplayer.VideoPlayerActivity; 15 | import com.xcode126.kgplayer.base.WrapperFragment; 16 | import com.xcode126.kgplayer.local.adapter.LocalAdapter; 17 | import com.xcode126.kgplayer.local.model.MediaItem; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import butterknife.BindView; 23 | 24 | /** 25 | * Author:sky on 2019/4/23 11:58. 26 | * Email:xcode126@126.com 27 | * Desc:本地 28 | */ 29 | public class LocalFragment extends WrapperFragment { 30 | 31 | @BindView(R.id.mRecyclerView) 32 | RecyclerView mRecyclerView; 33 | 34 | private LocalAdapter localAdapter; 35 | private List mMediaItems; 36 | 37 | private Handler mHandler = new Handler() { 38 | @Override 39 | public void handleMessage(Message msg) { 40 | super.handleMessage(msg); 41 | if (mMediaItems != null && mMediaItems.size() > 0) { 42 | localAdapter.setNewData(mMediaItems); 43 | } else { 44 | localAdapter.setEmptyView(getHelperView(mRecyclerView, R.layout.common_empty, null)); 45 | localAdapter.notifyDataSetChanged(); 46 | } 47 | } 48 | }; 49 | 50 | public static LocalFragment newInstance() { 51 | return new LocalFragment(); 52 | } 53 | 54 | @Override 55 | public int getViewLayout() { 56 | return R.layout.common_recycler; 57 | } 58 | 59 | @Override 60 | protected void initView(Bundle savedInstanceState) { 61 | mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity)); 62 | localAdapter = new LocalAdapter(); 63 | mRecyclerView.setAdapter(localAdapter); 64 | localAdapter.setOnItemClickListener((adapter, view, position) -> { 65 | MediaItem item = localAdapter.getItem(position); 66 | startActivity(VideoPlayerActivity.getIntent(_mActivity, item.getName(), item.getData())); 67 | }); 68 | } 69 | 70 | @Override 71 | protected void loadData(Bundle savedInstanceState) { 72 | getDataFromLocal(); 73 | } 74 | 75 | /** 76 | * 从本地的sdcard得到数据 77 | * //1.遍历sdcard,后缀名 78 | * //2.从内容提供者里面获取视频 79 | * //3.如果是6.0的系统,动态获取读取sdcard的权限 80 | */ 81 | private void getDataFromLocal() { 82 | new Thread(() -> { 83 | // showLoadingDialog(); 84 | mMediaItems = new ArrayList<>(); 85 | ContentResolver resolver = _mActivity.getContentResolver(); 86 | Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 87 | //具体需要获取的参数 88 | String[] objs = { 89 | MediaStore.Video.Media.DISPLAY_NAME,//视频文件在sdcard的名称 90 | MediaStore.Video.Media.DURATION,//视频总时长 91 | MediaStore.Video.Media.SIZE,//视频的文件大小 92 | MediaStore.Video.Media.DATA,//视频的绝对地址 93 | MediaStore.Video.Media.ARTIST,//歌曲的演唱者 94 | }; 95 | 96 | //访问内部信息 97 | Cursor cursor = resolver.query(uri, objs, null, null, null); 98 | 99 | while (cursor.moveToNext()) { 100 | 101 | MediaItem mediaItem = new MediaItem(); 102 | 103 | String name = cursor.getString(0);//视频的名称 104 | mediaItem.setName(name); 105 | 106 | long duration = cursor.getLong(1);//视频的时长 107 | mediaItem.setDuration(duration); 108 | 109 | long size = cursor.getLong(2);//视频的文件大小 110 | mediaItem.setSize(size); 111 | 112 | String data = cursor.getString(3);//视频的播放地址 113 | mediaItem.setData(data); 114 | 115 | String artist = cursor.getString(4);//艺术家 116 | mediaItem.setArtist(artist); 117 | 118 | mMediaItems.add(mediaItem); 119 | } 120 | cursor.close(); 121 | // onStopLoading(); 122 | mHandler.sendEmptyMessage(0); 123 | }).start(); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/local/adapter/LocalAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.local.adapter; 2 | 3 | import com.chad.library.adapter.base.BaseQuickAdapter; 4 | import com.xcode126.kgplayer.R; 5 | import com.xcode126.kgplayer.base.widget.BaseRecyclerHolder; 6 | import com.xcode126.kgplayer.local.model.MediaItem; 7 | import com.xcode126.kgplayer.util.DateUtils; 8 | 9 | /** 10 | * Author:sky on 2019/4/23 15:02. 11 | * Email:xcode126@126.com 12 | * Desc:本地扫描adapter 13 | */ 14 | 15 | public class LocalAdapter extends BaseQuickAdapter { 16 | 17 | public LocalAdapter() { 18 | super(R.layout.item_local); 19 | } 20 | 21 | @Override 22 | protected void convert(BaseRecyclerHolder helper, MediaItem item) { 23 | // helper.setImageManager(mContext,R.id.iv_image,item.get); 24 | helper.setText(R.id.tv_title,item.getName()); 25 | helper.setText(R.id.tv_time, DateUtils.timeToString(item.getDuration())); 26 | helper.setText(R.id.tv_size,android.text.format.Formatter.formatFileSize(mContext, item.getSize())); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/local/model/MediaItem.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.local.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /* 6 | * @创建者 兰昱 7 | * @创建时间 2016/9/28 16:53 8 | * @描述 9 | */ 10 | //视频信息 11 | public class MediaItem implements Serializable { 12 | private String name; 13 | private String artist; 14 | private String data;//视频绝对地址 15 | private long size; 16 | private long duration; 17 | 18 | public String getData() { 19 | return data; 20 | } 21 | 22 | public void setData(String data) { 23 | this.data = data; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getArtist() { 35 | return artist; 36 | } 37 | 38 | public void setArtist(String artist) { 39 | this.artist = artist; 40 | } 41 | 42 | 43 | public long getSize() { 44 | return size; 45 | } 46 | 47 | public void setSize(long size) { 48 | this.size = size; 49 | } 50 | 51 | public long getDuration() { 52 | return duration; 53 | } 54 | 55 | public void setDuration(long duration) { 56 | this.duration = duration; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "MediaItem{" + 62 | "name='" + name + '\'' + 63 | ", artist='" + artist + '\'' + 64 | ", date='" + data + '\'' + 65 | ", size=" + size + 66 | ", duration=" + duration + 67 | '}'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/me/LoginActivity.java: -------------------------------------------------------------------------------- 1 | //package com.xcode126.kgplayer.me; 2 | // 3 | // 4 | //import android.content.Context; 5 | //import android.content.Intent; 6 | //import android.os.Bundle; 7 | // 8 | //import com.xcode126.kgplayer.R; 9 | //import com.xcode126.kgplayer.base.WrapperActivity; 10 | //import com.xcode126.kgplayer.base.widget.TitleView; 11 | // 12 | // 13 | ///** 14 | // * Auther: winds 15 | // * Data: 2017/6/11 16 | // * Desc: 登录 17 | // */ 18 | // 19 | //public class LoginActivity extends WrapperActivity { 20 | // 21 | // boolean retry; //是否为再次登录 22 | // boolean enable = true; //是否开启选择站点功能 23 | // 24 | // public static Intent getIntent(Context context) { 25 | // return new Intent(context, LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); 26 | // } 27 | // 28 | // /** 29 | // * @param context 30 | // * @param context 31 | // * @param retry 是否是重新登录 32 | // * @return 33 | // */ 34 | // public static Intent getIntent(Context context, boolean retry) { 35 | // return new Intent(context, LoginActivity.class).putExtra("initiative", true).putExtra("retry", retry); 36 | // } 37 | // 38 | // @Override 39 | // public int getViewLayout() { 40 | // return R.layout.activity_login; 41 | // } 42 | // 43 | // @Override 44 | // protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) { 45 | // if (!isTaskRoot()) { 46 | // finish(); 47 | // return; 48 | // } 49 | // retry = intent.getBooleanExtra("retry", false); 50 | // setInterceptable(false); 51 | // loadView(intent.getBooleanExtra("initiative", false)); 52 | // } 53 | // 54 | // 55 | // @Override 56 | // protected void loadData(Bundle savedInstanceState, Intent intent) { 57 | // 58 | // } 59 | // 60 | // @Override 61 | // public void showContentView(String url, BaseVo dataVo) { 62 | // 63 | // } 64 | // 65 | // @Override 66 | // protected boolean isUseTitle() { 67 | // return false; 68 | // } 69 | // 70 | // /** 71 | // * 进入对应页面 请勿改动此逻辑 如无需站点选择功能 请主动设置enable为false或者打正式包 72 | // * 73 | // * @param initiative 74 | // */ 75 | // private void loadView(boolean initiative) { 76 | // if (initiative) { //主动跳转 77 | // loadLoginPage(); 78 | // } else { //自动打开 比如点击icon 安装 79 | // if (enable) { //是否开启站点选择功能 80 | // if (BuildConfig.FLAVOR.equals("beta")) { //是否为测试版 81 | // loadChoosePage(); //仅在主动开启站点选择功能 且为测试版的情况下 加载站点选择页面 82 | // return; 83 | // } 84 | // } 85 | // loadLoginPage(); 86 | // } 87 | // } 88 | // 89 | // private void loadChoosePage() { 90 | // loadRootFragment(R.id.container, TestingFragment.newInstance(), false, false); 91 | // } 92 | // 93 | // public void loadLoginPage() { 94 | // loadRootFragment(R.id.container, LoginFragment.newInstance(), false, false); 95 | // } 96 | //} 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/me/LoginFragment.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.me; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.xcode126.kgplayer.base.WrapperFragment; 6 | 7 | /** 8 | * Author: winds 9 | * Data: 2018/7/26 10 | * Version: 1.0 11 | * Desc: 12 | */ 13 | 14 | 15 | public class LoginFragment extends WrapperFragment { 16 | 17 | public static LoginFragment newInstance() { 18 | return new LoginFragment(); 19 | } 20 | 21 | @Override 22 | public int getViewLayout() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | protected void initView(Bundle savedInstanceState) { 28 | 29 | } 30 | 31 | @Override 32 | protected void loadData(Bundle savedInstanceState) { 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/me/MeFragment.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.me; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.xcode126.kgplayer.R; 6 | import com.xcode126.kgplayer.base.WrapperFragment; 7 | 8 | 9 | /** 10 | * Auther: winds 11 | * Data: 2018/2/27 12 | * Version: 1.0 13 | * Desc: 我的 14 | */ 15 | 16 | 17 | public class MeFragment extends WrapperFragment { 18 | 19 | // @BindView(R.id.mNestedRefreshLayout) 20 | // NestedRefreshLayout mNestedRefreshLayout; 21 | 22 | 23 | public static MeFragment newInstance() { 24 | return new MeFragment(); 25 | } 26 | 27 | @Override 28 | public int getViewLayout() { 29 | return R.layout.fragment_me; 30 | } 31 | 32 | @Override 33 | protected void initView(Bundle savedInstanceState) { 34 | } 35 | 36 | @Override 37 | protected void loadData(Bundle savedInstanceState) { 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/net/NetFragment.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.net; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.xcode126.kgplayer.R; 6 | import com.xcode126.kgplayer.base.WrapperFragment; 7 | 8 | 9 | 10 | /** 11 | * Author:sky on 2019/4/23 15:35. 12 | * Email:xcode126@126.com 13 | * Desc:网络 14 | */ 15 | 16 | public class NetFragment extends WrapperFragment { 17 | 18 | // @BindView(R.id.mNestedRefreshLayout) 19 | // NestedRefreshLayout mNestedRefreshLayout; 20 | // @BindView(R.id.mRecyclerView) 21 | // RecyclerView mRecyclerView; 22 | // 23 | // private NetListAdapter mAdapter; 24 | 25 | public static NetFragment newInstance() { 26 | return new NetFragment(); 27 | } 28 | 29 | @Override 30 | public int getViewLayout() { 31 | return R.layout.fragment_home; 32 | } 33 | 34 | @Override 35 | protected void initView(Bundle savedInstanceState) { 36 | // super.initView(savedInstanceState); 37 | // mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity)); 38 | // mAdapter = new NetListAdapter(); 39 | // mRecyclerView.setAdapter(mAdapter); 40 | // mNestedRefreshLayout.setOnRefreshListener(this); 41 | } 42 | 43 | 44 | @Override 45 | protected void loadData(Bundle savedInstanceState) { 46 | 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/net/adapter/NetListAdapter.java: -------------------------------------------------------------------------------- 1 | //package com.xcode126.kgplayer.net.adapter; 2 | // 3 | // 4 | //import com.xcode126.kgplayer.R; 5 | // 6 | ///** 7 | // * Author:sky on 2019/4/26 14:53. 8 | // * Email:xcode126@126.com 9 | // * Desc: 10 | // */ 11 | // 12 | //public class NetListAdapter extends BaseQuickAdapter{ 13 | // public NetListAdapter() { 14 | // super(R.layout.item_local); 15 | // } 16 | // 17 | // @Override 18 | // protected void convert(BaseRecyclerHolder helper, String item) { 19 | // 20 | // } 21 | //} 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/net/vo/NetListVo.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.net.vo; 2 | 3 | 4 | import java.util.List; 5 | 6 | /** 7 | * Author:sky on 2019/4/26 14:55. 8 | * Email:xcode126@126.com 9 | * Desc: 10 | */ 11 | 12 | public class NetListVo { 13 | 14 | public List trailers; 15 | 16 | public static class TrailersBean { 17 | public int id; 18 | public String movieName; 19 | public String coverImg; 20 | public int movieId; 21 | public String url; 22 | public String hightUrl; 23 | public String videoTitle; 24 | public int videoLength; 25 | public int rating; 26 | public String summary; 27 | public List type; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/util/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.util; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | import java.util.Formatter; 8 | import java.util.Locale; 9 | 10 | /** 11 | * Author:sky on 2019/4/23 15:02. 12 | * Email:xcode126@126.com 13 | * Desc:时间格式工具类 14 | */ 15 | public class DateUtils { 16 | public final static String YEAR_MONTH_DAY_HOUR_MINUTE = "yyyy-MM-dd HH:mm"; 17 | public final static String YEAR_MONTH_DAY = "yyyy-MM-dd"; 18 | public final static String HOUR_MINUTE = "HH:mm"; 19 | 20 | public static String format(long time) { 21 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); 22 | return dateFormat.format(new Date(time)); 23 | } 24 | 25 | public static String format(long time, String pattern) { 26 | SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.CHINA); 27 | return dateFormat.format(new Date(time)); 28 | } 29 | 30 | 31 | public static Date parse(String date) { 32 | if (date == null) { 33 | return null; 34 | } 35 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); 36 | try { 37 | return dateFormat.parse(date); 38 | } catch (ParseException e) { 39 | e.printStackTrace(); 40 | } 41 | return new Date(); 42 | } 43 | 44 | public static Date parse(String date, String pattern) { 45 | if (date == null) { 46 | return null; 47 | } 48 | SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); 49 | try { 50 | return dateFormat.parse(date); 51 | } catch (ParseException e) { 52 | e.printStackTrace(); 53 | } 54 | return null; 55 | } 56 | 57 | public static String formatCurrentDate() { 58 | Date date = new Date(); 59 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 60 | return dateFormat.format(date); 61 | } 62 | 63 | /** 64 | * 格式指定格式的时间戳 65 | * 66 | * @param pattern 67 | * @param time 68 | * @return 69 | */ 70 | public static String getFormatTime(String pattern, Object time) { 71 | SimpleDateFormat sdf = new SimpleDateFormat(); 72 | sdf.applyPattern(pattern); 73 | return sdf.format(Long.parseLong(String.valueOf(time))); 74 | } 75 | 76 | 77 | /** 78 | * 判断是否是当天 79 | * 80 | * @param time 81 | * @return 82 | */ 83 | public static boolean isToday(Object time) { 84 | return getFormatTime(YEAR_MONTH_DAY).equals(getFormatTime(YEAR_MONTH_DAY, time)); 85 | } 86 | 87 | /** 88 | * 指定格式化的当前时间 89 | * 90 | * @param pattern 91 | * @return 92 | */ 93 | public static String getFormatTime(String pattern) { 94 | return getFormatTime(pattern, System.currentTimeMillis()); 95 | } 96 | 97 | /** 98 | * 格式化特定格式的时间戳 99 | * 当天 HOUR_MINUTE 样式 100 | * 非当天 YEAR_MONTH_DAY_HOUR_MINUTE 样式 101 | * 102 | * @param time 103 | * @return 104 | */ 105 | public static String getFormatAppointedTime(String time) { 106 | time = String.format("%1$s%2$s", time, "000"); 107 | return getFormatTime(isToday(time) ? HOUR_MINUTE : YEAR_MONTH_DAY_HOUR_MINUTE, time); 108 | } 109 | 110 | 111 | /** 112 | * 判断是否为今天(效率比较高) 113 | * 114 | * @param day 传入的 时间 "2016-06-28 10:10:30" "2016-06-28" 都可以 115 | * @return true今天 false不是 116 | * @throws ParseException 117 | */ 118 | public static boolean IsToday(String day) throws ParseException { 119 | 120 | Calendar pre = Calendar.getInstance(); 121 | Date predate = new Date(System.currentTimeMillis()); 122 | pre.setTime(predate); 123 | Calendar cal = Calendar.getInstance(); 124 | Date date = getDateFormat().parse(day); 125 | cal.setTime(date); 126 | if (cal.get(Calendar.YEAR) == (pre.get(Calendar.YEAR))) { 127 | int diffDay = cal.get(Calendar.DAY_OF_YEAR) 128 | - pre.get(Calendar.DAY_OF_YEAR); 129 | 130 | if (diffDay == 0) { 131 | return true; 132 | } 133 | } 134 | return false; 135 | } 136 | 137 | public static SimpleDateFormat getDateFormat() { 138 | if (null == DateLocal.get()) { 139 | DateLocal.set(new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA)); 140 | } 141 | return DateLocal.get(); 142 | } 143 | 144 | private static ThreadLocal DateLocal = new ThreadLocal(); 145 | 146 | 147 | /** 148 | * 时间戳格式化成字符串 149 | * 150 | * @param milSecond 151 | * @return 152 | */ 153 | public static String getDateToString(long milSecond) { 154 | Date date = new Date(milSecond); 155 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 156 | return format.format(date); 157 | } 158 | 159 | public static String timeToString(long millions) { 160 | Formatter formatter = new Formatter(); 161 | int totalSeconds = (int) (millions / 1000); 162 | int seconds = totalSeconds % 60; 163 | int minutes = (totalSeconds / 60) % 60; 164 | int hours = totalSeconds / 3600; 165 | if (hours > 0) { 166 | return formatter.format("%d:%02d:%02d", hours, minutes, seconds) 167 | .toString(); 168 | } else { 169 | return formatter.format("%02d:%02d", minutes, seconds).toString(); 170 | } 171 | } 172 | } 173 | 174 | 175 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/util/DisplayUtil.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.util; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.Point; 6 | import android.util.DisplayMetrics; 7 | 8 | /** 9 | * 分辨率转换工具 10 | */ 11 | public class DisplayUtil { 12 | 13 | public static int SYS_SCREEN_WIDTH; 14 | public static int SYS_SCREEN_HEIGHT; 15 | public static int CONTACT_GROUP_LABLE; 16 | 17 | /** 18 | * dip转px 19 | * 20 | * @param context 21 | * @param dipValue 22 | * @return 23 | */ 24 | public static int dip2px(Context context, float dipValue) { 25 | final float scale = context.getResources().getDisplayMetrics().density; 26 | return (int) (dipValue * scale + 0.5f); 27 | } 28 | 29 | /** 30 | * px转dip 31 | * 32 | * @param context 33 | * @param pxValue 34 | * @return 35 | */ 36 | public static int px2dip(Context context, float pxValue) { 37 | final float scale = context.getResources().getDisplayMetrics().density; 38 | return (int) (pxValue / scale + 0.5f); 39 | } 40 | 41 | /** 42 | * 获取屏幕宽度和高度,单位为px 43 | * 44 | * @param context 45 | * @return 46 | */ 47 | public static Point getScreenMetrics(Context context) { 48 | int w_screen = getScreenWidth(context); 49 | int h_screen = getScreenHeight(context); 50 | return new Point(w_screen, h_screen); 51 | 52 | } 53 | 54 | /** 55 | * 获取屏幕长宽比 56 | * 57 | * @param context 58 | * @return 59 | */ 60 | public static float getScreenRate(Context context) { 61 | Point P = getScreenMetrics(context); 62 | float H = P.y; 63 | float W = P.x; 64 | return (H / W); 65 | } 66 | 67 | /** 68 | * 屏幕宽度 69 | * 70 | * @param context 71 | * @return 72 | */ 73 | public static int getScreenWidth(Context context) { 74 | DisplayMetrics dm = context.getResources().getDisplayMetrics(); 75 | int w_screen = dm.widthPixels; 76 | return w_screen; 77 | } 78 | 79 | /** 80 | * 屏幕高度 81 | * 82 | * @param context 83 | * @return 84 | */ 85 | public static int getScreenHeight(Context context) { 86 | DisplayMetrics dm = context.getResources().getDisplayMetrics(); 87 | int h_screen = dm.heightPixels; 88 | return h_screen; 89 | } 90 | 91 | /** 92 | * 获取当前屏幕的尺寸信息 93 | * 94 | * @param activity 95 | */ 96 | public static void getSystemInfo(Activity activity) { 97 | SYS_SCREEN_WIDTH = getScreenWidth(activity); 98 | SYS_SCREEN_HEIGHT = getScreenHeight(activity); 99 | CONTACT_GROUP_LABLE = SYS_SCREEN_WIDTH / 5 * 3; 100 | } 101 | // /** 102 | // * 获取屏幕宽度 103 | // * 104 | // * @param context 105 | // * @return 106 | // */ 107 | // public static int getScreenWidth(Context context) { 108 | // if (width == 0) { 109 | // WindowManager manager = (WindowManager) context 110 | // .getSystemService(Context.WINDOW_SERVICE); 111 | // Display display = manager.getDefaultDisplay(); 112 | // width = display.getWidth(); 113 | // } 114 | // return width; 115 | // } 116 | } 117 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/util/ImageManager.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.util; 2 | 3 | import android.content.Context; 4 | import android.widget.ImageView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; 8 | 9 | /** 10 | * Author:sky on 2019/9/20 14:05. 11 | * Email:xcode126@126.com 12 | * Desc:图片加载工具类 13 | */ 14 | 15 | public class ImageManager { 16 | 17 | private static ImageManager instance; 18 | 19 | private ImageManager() { 20 | } 21 | 22 | public static ImageManager getDefault() { 23 | if (instance == null) { 24 | synchronized (ImageManager.class) { 25 | instance = new ImageManager(); 26 | } 27 | return instance; 28 | } 29 | return instance; 30 | } 31 | 32 | /** 33 | * 加载指定URL的图片并设置到targetView 34 | * 35 | * @param context 36 | * @param obj 37 | * @param targetView 38 | */ 39 | public static void load(Context context, Object obj, final ImageView targetView) { 40 | Glide.with(context).load(obj).into(targetView); 41 | } 42 | 43 | public static void load(Context context, Object obj, int place, final ImageView targetView) { 44 | Glide.with(context).load(obj).placeholder(place).into(targetView); 45 | } 46 | 47 | public static void load(Context context, Object obj, int place, BitmapTransformation transformation, final ImageView targetView) { 48 | Glide.with(context).load(obj).placeholder(place).bitmapTransform(transformation).into(targetView); 49 | } 50 | 51 | public static void load(Context context, Object obj, int place, int error, BitmapTransformation transformation, final ImageView targetView) { 52 | Glide.with(context).load(obj).placeholder(place).error(error).bitmapTransform(transformation).into(targetView); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/util/LogUtils.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.util; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Log工具类 7 | */ 8 | public class LogUtils { 9 | 10 | private LogUtils() { 11 | /* cannot be instantiated */ 12 | throw new UnsupportedOperationException("cannot be instantiated"); 13 | } 14 | 15 | /** 16 | * 是否需要打印bug,可以在application的onCreate函数里面初始化(默认true) 17 | */ 18 | public static boolean isDebug = true; 19 | private static final String TAG = "way"; 20 | 21 | // 下面是默认tag的函数 22 | public static void i(String msg) { 23 | if (isDebug) 24 | Log.i(TAG, msg); 25 | } 26 | 27 | public static void d(String msg) { 28 | if (isDebug) 29 | Log.d(TAG, msg); 30 | } 31 | 32 | public static void e(String msg) { 33 | if (isDebug) 34 | Log.e(TAG, msg); 35 | } 36 | 37 | public static void v(String msg) { 38 | if (isDebug) 39 | Log.v(TAG, msg); 40 | } 41 | 42 | // 下面是传入自定义tag的函数 43 | public static void i(String tag, String msg) { 44 | if (isDebug) 45 | Log.i(tag, msg); 46 | } 47 | 48 | public static void d(String tag, String msg) { 49 | if (isDebug) 50 | Log.d(tag, msg); 51 | } 52 | 53 | public static void e(String tag, String msg) { 54 | if (isDebug) 55 | Log.e(tag, msg); 56 | } 57 | 58 | public static void v(String tag, String msg) { 59 | if (isDebug) 60 | Log.v(tag, msg); 61 | } 62 | 63 | public static void w(String tag, String msg) { 64 | if (isDebug) { 65 | Log.w(tag, msg); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/xcode126/kgplayer/util/MyJzvdStd.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer.util; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.widget.SeekBar; 9 | 10 | import com.xcode126.kgplayer.R; 11 | 12 | import cn.jzvd.JzvdStd; 13 | 14 | /** 15 | * 这里可以监听到视频播放的生命周期和播放状态 16 | * 所有关于视频的逻辑都应该写在这里 17 | * Created by Nathen on 2017/7/2. 18 | */ 19 | public class MyJzvdStd extends JzvdStd { 20 | public MyJzvdStd(Context context) { 21 | super(context); 22 | } 23 | 24 | public MyJzvdStd(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | @Override 29 | public void init(Context context) { 30 | super.init(context); 31 | } 32 | 33 | @Override 34 | public void onClick(View v) { 35 | super.onClick(v); 36 | int i = v.getId(); 37 | if (i == cn.jzvd.R.id.fullscreen) { 38 | Log.i(TAG, "onClick: fullscreen button"); 39 | } else if (i == R.id.start) { 40 | Log.i(TAG, "onClick: start button"); 41 | } 42 | } 43 | 44 | @Override 45 | public boolean onTouch(View v, MotionEvent event) { 46 | super.onTouch(v, event); 47 | int id = v.getId(); 48 | if (id == cn.jzvd.R.id.surface_container) { 49 | switch (event.getAction()) { 50 | case MotionEvent.ACTION_UP: 51 | if (mChangePosition) { 52 | Log.i(TAG, "Touch screen seek position"); 53 | } 54 | if (mChangeVolume) { 55 | Log.i(TAG, "Touch screen change volume"); 56 | } 57 | break; 58 | } 59 | } 60 | 61 | return false; 62 | } 63 | 64 | @Override 65 | public int getLayoutId() { 66 | return R.layout.jz_layout_std; 67 | } 68 | 69 | @Override 70 | public void startVideo() { 71 | super.startVideo(); 72 | Log.i(TAG, "startVideo"); 73 | } 74 | 75 | @Override 76 | public void onStopTrackingTouch(SeekBar seekBar) { 77 | super.onStopTrackingTouch(seekBar); 78 | Log.i(TAG, "Seek position "); 79 | } 80 | 81 | @Override 82 | public void gotoScreenFullscreen() { 83 | super.gotoScreenFullscreen(); 84 | Log.i(TAG, "goto Fullscreen"); 85 | } 86 | 87 | @Override 88 | public void gotoScreenNormal() { 89 | super.gotoScreenNormal(); 90 | Log.i(TAG, "quit Fullscreen"); 91 | } 92 | 93 | @Override 94 | public void autoFullscreen(float x) { 95 | super.autoFullscreen(x); 96 | Log.i(TAG, "auto Fullscreen"); 97 | } 98 | 99 | @Override 100 | public void onClickUiToggle() { 101 | super.onClickUiToggle(); 102 | Log.i(TAG, "click blank"); 103 | } 104 | 105 | //onState 代表了播放器引擎的回调,播放视频各个过程的状态的回调 106 | @Override 107 | public void onStateNormal() { 108 | super.onStateNormal(); 109 | } 110 | 111 | @Override 112 | public void onStatePreparing() { 113 | super.onStatePreparing(); 114 | } 115 | 116 | @Override 117 | public void onStatePlaying() { 118 | super.onStatePlaying(); 119 | } 120 | 121 | @Override 122 | public void onStatePause() { 123 | super.onStatePause(); 124 | } 125 | 126 | @Override 127 | public void onStateError() { 128 | super.onStateError(); 129 | } 130 | 131 | @Override 132 | public void onStateAutoComplete() { 133 | super.onStateAutoComplete(); 134 | Log.i(TAG, "Auto complete"); 135 | } 136 | 137 | //changeUiTo 真能能修改ui的方法 138 | @Override 139 | public void changeUiToNormal() { 140 | super.changeUiToNormal(); 141 | } 142 | 143 | @Override 144 | public void changeUiToPreparing() { 145 | super.changeUiToPreparing(); 146 | } 147 | 148 | @Override 149 | public void changeUiToPlayingShow() { 150 | super.changeUiToPlayingShow(); 151 | } 152 | 153 | @Override 154 | public void changeUiToPlayingClear() { 155 | super.changeUiToPlayingClear(); 156 | } 157 | 158 | @Override 159 | public void changeUiToPauseShow() { 160 | super.changeUiToPauseShow(); 161 | } 162 | 163 | @Override 164 | public void changeUiToPauseClear() { 165 | super.changeUiToPauseClear(); 166 | } 167 | 168 | @Override 169 | public void changeUiToComplete() { 170 | super.changeUiToComplete(); 171 | } 172 | 173 | @Override 174 | public void changeUiToError() { 175 | super.changeUiToError(); 176 | } 177 | 178 | @Override 179 | public void onInfo(int what, int extra) { 180 | super.onInfo(what, extra); 181 | } 182 | 183 | @Override 184 | public void onError(int what, int extra) { 185 | super.onError(what, extra); 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /app/src/main/res/color/selector_tab_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_audio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_audio.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_audio_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_audio_press.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_netaudio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_netaudio.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_netaudio_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_netaudio_press.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_netvideo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_netvideo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_netvideo_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_netvideo_press.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_video.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_tab_video_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/ic_tab_video_press.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/return_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/return_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/splash_bg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/splash_bg.jpeg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/video_default_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/drawable-xhdpi/video_default_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/main_bottom_text_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_divider_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_tab_divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_tab_dot.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_tab_msg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_video_player.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_wrapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 20 | 21 | 22 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/common_empty.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/common_recycler.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_me.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_local.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 15 | 16 | 23 | 24 | 31 | 32 | 40 | 41 | 42 | 53 | 54 | 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_normal_tab.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 22 | 23 | 31 | 32 | 50 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 27 | 28 | 39 | 40 | 47 | 48 | 59 | 60 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_audio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_audio.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_audio_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_audio_press.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_netaudio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_netaudio.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_netaudio_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_netaudio_press.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_netvideo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_netvideo.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_netvideo_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_netvideo_press.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_video.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_tab_video_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/ic_tab_video_press.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/splash_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-hdpi/splash_image.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | 8 | #3097FD 9 | #363636 10 | 11 | #EEEEEE 12 | #FFFFFF 13 | #F5F5F5 14 | #F02B2B 15 | 16 | 17 | #000000 18 | #333333 19 | #666666 20 | #999999 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 7 | 10sp 8 | 3dp 9 | 10 | 10px 11 | 12px 12 | 14px 13 | 16px 14 | 18px 15 | 20px 16 | 22px 17 | 24px 18 | 26px 19 | 28px 20 | 30px 21 | 32px 22 | 34px 23 | 36px 24 | 38px 25 | 40px 26 | 48px 27 | 50px 28 | 52px 29 | 30 | 98px 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | KgPlayer 3 | 4 | 第一個Tab 5 | 第二個Tab 6 | 第三個Tab 7 | 第四個Tab 8 | 9 | 10 | Hello blank fragment 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 19 | 20 | 23 | 24 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/test/java/com/xcode126/kgplayer/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xcode126.kgplayer; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.0.1' 9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 | mavenCentral() 21 | maven { 22 | url "https://jitpack.io" 23 | } 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xcode126/KgPlayer/b8440ad86261f7a18c72e4b24e9b061c8ac56c87/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Mar 30 12:05:37 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------