Skip to content

Commit caae995

Browse files
author
mobyiapps
committed
Update
1 parent 6d1a991 commit caae995

File tree

72 files changed

+3241
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3241
-3
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme">
12-
<activity android:name="com.dvinfosys.WidgetsExample.MainActivity">
12+
<activity
13+
android:name="com.dvinfosys.WidgetsExample.MainActivity"
14+
android:configChanges="orientation|screenSize|keyboardHidden"
15+
android:screenOrientation="portrait">
1316
<intent-filter>
1417
<action android:name="android.intent.action.MAIN" />
1518

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
package com.dvinfosys.WidgetsExample;
22

3-
import android.support.v7.app.AppCompatActivity;
3+
import android.net.Uri;
44
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
7+
import com.dvinfosys.widgets.VideoPlayer.VPVideoPlayer;
8+
import com.dvinfosys.widgets.VideoPlayer.VPVideoPlayerStandard;
59

610
public class MainActivity extends AppCompatActivity {
711

812
@Override
913
protected void onCreate(Bundle savedInstanceState) {
1014
super.onCreate(savedInstanceState);
1115
setContentView(R.layout.activity_main);
16+
17+
VPVideoPlayerStandard videoPlayerStandard = findViewById(R.id.vp_videoplayer);
18+
videoPlayerStandard.setUp("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4",VPVideoPlayerStandard.SCREEN_LAYOUT_NORMAL,"Elephant Dream");
19+
videoPlayerStandard.thumbImageView.setImageURI(Uri.parse("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/ElephantsDream.jpg"));
20+
}
21+
22+
@Override
23+
public void onBackPressed() {
24+
if (VPVideoPlayer.backPress()){
25+
return;
26+
}
27+
super.onBackPressed();
28+
}
29+
@Override
30+
protected void onPause() {
31+
super.onPause();
32+
VPVideoPlayer.releaseAllVideos();
1233
}
1334
}

app/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,10 @@
115115
android:text="Custom Button"
116116
app:button_font="Smoothy.otf" />
117117

118+
<com.dvinfosys.widgets.VideoPlayer.VPVideoPlayerStandard
119+
android:layout_width="match_parent"
120+
android:id="@+id/vp_videoplayer"
121+
android:layout_height="200dp"/>
122+
118123
</LinearLayout>
119124
</ScrollView>
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.dvinfosys.widgets" />
2+
package="com.dvinfosys.widgets">
3+
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:supportsRtl="true">
10+
11+
</application>
12+
13+
</manifest>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package com.dvinfosys.widgets.Utils;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.ContextWrapper;
6+
import android.content.SharedPreferences;
7+
import android.net.ConnectivityManager;
8+
import android.net.NetworkInfo;
9+
import android.support.v7.app.AppCompatActivity;
10+
import android.text.TextUtils;
11+
import android.view.ContextThemeWrapper;
12+
13+
import com.dvinfosys.widgets.VideoPlayer.VPVideoPlayer;
14+
15+
import java.util.Formatter;
16+
import java.util.Locale;
17+
18+
public class VPUtils {
19+
public static String stringForTime(int timeMs) {
20+
if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) {
21+
return "00:00";
22+
}
23+
int totalSeconds = timeMs / 1000;
24+
int seconds = totalSeconds % 60;
25+
int minutes = (totalSeconds / 60) % 60;
26+
int hours = totalSeconds / 3600;
27+
StringBuilder stringBuilder = new StringBuilder();
28+
Formatter mFormatter = new Formatter(stringBuilder, Locale.getDefault());
29+
if (hours > 0) {
30+
return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();
31+
} else {
32+
return mFormatter.format("%02d:%02d", minutes, seconds).toString();
33+
}
34+
}
35+
36+
/**
37+
* This method requires the caller to hold the permission ACCESS_NETWORK_STATE.
38+
*
39+
* @param context context
40+
* @return if wifi is connected,return true
41+
*/
42+
public static boolean isWifiConnected(Context context) {
43+
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
44+
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
45+
return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
46+
}
47+
48+
/**
49+
* Get activity from context object
50+
*
51+
* @param context context
52+
* @return object of Activity or null if it is not Activity
53+
*/
54+
public static Activity scanForActivity(Context context) {
55+
if (context == null) return null;
56+
57+
if (context instanceof Activity) {
58+
return (Activity) context;
59+
} else if (context instanceof ContextWrapper) {
60+
return scanForActivity(((ContextWrapper) context).getBaseContext());
61+
}
62+
63+
return null;
64+
}
65+
66+
/**
67+
* Get AppCompatActivity from context
68+
*
69+
* @param context context
70+
* @return AppCompatActivity if it's not null
71+
*/
72+
public static AppCompatActivity getAppCompActivity(Context context) {
73+
if (context == null) return null;
74+
if (context instanceof AppCompatActivity) {
75+
return (AppCompatActivity) context;
76+
} else if (context instanceof ContextThemeWrapper) {
77+
return getAppCompActivity(((ContextThemeWrapper) context).getBaseContext());
78+
}
79+
return null;
80+
}
81+
82+
public static int dip2px(Context context, float dpValue) {
83+
final float scale = context.getResources().getDisplayMetrics().density;
84+
return (int) (dpValue * scale + 0.5f);
85+
}
86+
87+
public static void saveProgress(Context context, String url, int progress) {
88+
if (!VPVideoPlayer.SAVE_PROGRESS) return;
89+
SharedPreferences spn = context.getSharedPreferences("JCVD_PROGRESS",
90+
Context.MODE_PRIVATE);
91+
SharedPreferences.Editor editor = spn.edit();
92+
editor.putInt(url, progress);
93+
editor.apply();
94+
}
95+
96+
public static int getSavedProgress(Context context, String url) {
97+
if (!VPVideoPlayer.SAVE_PROGRESS) return 0;
98+
SharedPreferences spn;
99+
spn = context.getSharedPreferences("JCVD_PROGRESS",
100+
Context.MODE_PRIVATE);
101+
return spn.getInt(url, 0);
102+
}
103+
104+
/**
105+
* if url == null, clear all progress
106+
*
107+
* @param context context
108+
* @param url if url!=null clear this url progress
109+
*/
110+
public static void clearSavedProgress(Context context, String url) {
111+
if (TextUtils.isEmpty(url)) {
112+
SharedPreferences spn = context.getSharedPreferences("JCVD_PROGRESS",
113+
Context.MODE_PRIVATE);
114+
spn.edit().clear().apply();
115+
} else {
116+
SharedPreferences spn = context.getSharedPreferences("JCVD_PROGRESS",
117+
Context.MODE_PRIVATE);
118+
spn.edit().putInt(url, 0).apply();
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)