apps = pm.queryIntentActivities(intent, 0);
258 |
259 | ResolveInfo ri = apps.iterator().next();
260 | if (ri != null) {
261 | String className = ri.activityInfo.name;
262 | intent.setComponent(new ComponentName(packageName, className));
263 | ctx.startActivity(intent);
264 | }
265 | } catch (NameNotFoundException e) {
266 | Logger.e(e);
267 | }
268 | }
269 | }
270 |
--------------------------------------------------------------------------------
/src/com/nmbb/oplayer/util/FractionalTouchDelegate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 YIXIA.COM
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 | package com.nmbb.oplayer.util;
17 |
18 | import android.graphics.Rect;
19 | import android.graphics.RectF;
20 | import android.view.MotionEvent;
21 | import android.view.TouchDelegate;
22 | import android.view.View;
23 |
24 | /**
25 | * {@link TouchDelegate} that gates {@link MotionEvent} instances by comparing
26 | * then against fractional dimensions of the source view.
27 | *
28 | * This is particularly useful when you want to define a rectangle in terms of
29 | * the source dimensions, but when those dimensions might change due to pending
30 | * or future layout passes.
31 | *
32 | * One example is catching touches that occur in the top-right quadrant of
33 | * {@code sourceParent}, and relaying them to {@code targetChild}. This could be
34 | * done with:
35 | * FractionalTouchDelegate.setupDelegate(sourceParent, targetChild, new RectF(0.5f, 0f, 1f, 0.5f));
36 | *
37 | */
38 | public class FractionalTouchDelegate extends TouchDelegate {
39 |
40 | private View mSource;
41 | private View mTarget;
42 |
43 | private RectF mSourceFraction;
44 |
45 | private Rect mScrap = new Rect();
46 |
47 | /** Cached full dimensions of {@link #mSource}. */
48 | private Rect mSourceFull = new Rect();
49 | /** Cached projection of {@link #mSourceFraction} onto {@link #mSource}. */
50 | private Rect mSourcePartial = new Rect();
51 |
52 | private boolean mDelegateTargeted;
53 |
54 | public FractionalTouchDelegate(View source, View target, RectF sourceFraction) {
55 | super(new Rect(0, 0, 0, 0), target);
56 | mSource = source;
57 | mTarget = target;
58 | mSourceFraction = sourceFraction;
59 | }
60 |
61 | /**
62 | * Helper to create and setup a {@link FractionalTouchDelegate} between the
63 | * given {@link View}.
64 | *
65 | * @param source Larger source {@link View}, usually a parent, that will be
66 | * assigned {@link View#setTouchDelegate(TouchDelegate)}.
67 | * @param target Smaller target {@link View} which will receive
68 | * {@link MotionEvent} that land in requested fractional area.
69 | * @param sourceFraction Fractional area projected onto source {@link View}
70 | * which determines when {@link MotionEvent} will be passed to
71 | * target {@link View}.
72 | */
73 | public static void setupDelegate(View source, View target, RectF sourceFraction) {
74 | source.setTouchDelegate(new FractionalTouchDelegate(source, target, sourceFraction));
75 | }
76 |
77 | /**
78 | * Consider updating {@link #mSourcePartial} when {@link #mSource}
79 | * dimensions have changed.
80 | */
81 | private void updateSourcePartial() {
82 | mSource.getHitRect(mScrap);
83 | if (!mScrap.equals(mSourceFull)) {
84 | // Copy over and calculate fractional rectangle
85 | mSourceFull.set(mScrap);
86 |
87 | final int width = mSourceFull.width();
88 | final int height = mSourceFull.height();
89 |
90 | mSourcePartial.left = (int) (mSourceFraction.left * width);
91 | mSourcePartial.top = (int) (mSourceFraction.top * height);
92 | mSourcePartial.right = (int) (mSourceFraction.right * width);
93 | mSourcePartial.bottom = (int) (mSourceFraction.bottom * height);
94 | }
95 | }
96 |
97 | @Override
98 | public boolean onTouchEvent(MotionEvent event) {
99 | updateSourcePartial();
100 |
101 | // The logic below is mostly copied from the parent class, since we
102 | // can't update private mBounds variable.
103 |
104 | // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;
105 | // f=core/java/android/view/TouchDelegate.java;hb=eclair#l98
106 |
107 | final Rect sourcePartial = mSourcePartial;
108 | final View target = mTarget;
109 |
110 | int x = (int)event.getX();
111 | int y = (int)event.getY();
112 |
113 | boolean sendToDelegate = false;
114 | boolean hit = true;
115 | boolean handled = false;
116 |
117 | switch (event.getAction()) {
118 | case MotionEvent.ACTION_DOWN:
119 | if (sourcePartial.contains(x, y)) {
120 | mDelegateTargeted = true;
121 | sendToDelegate = true;
122 | }
123 | break;
124 | case MotionEvent.ACTION_UP:
125 | case MotionEvent.ACTION_MOVE:
126 | sendToDelegate = mDelegateTargeted;
127 | if (sendToDelegate) {
128 | if (!sourcePartial.contains(x, y)) {
129 | hit = false;
130 | }
131 | }
132 | break;
133 | case MotionEvent.ACTION_CANCEL:
134 | sendToDelegate = mDelegateTargeted;
135 | mDelegateTargeted = false;
136 | break;
137 | }
138 |
139 | if (sendToDelegate) {
140 | if (hit) {
141 | event.setLocation(target.getWidth() / 2, target.getHeight() / 2);
142 | } else {
143 | event.setLocation(-1, -1);
144 | }
145 | handled = target.dispatchTouchEvent(event);
146 | }
147 | return handled;
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/com/nmbb/oplayer/util/IntentHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 YIXIA.COM
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 | package com.nmbb.oplayer.util;
17 |
18 | import io.vov.vitamio.utils.Log;
19 |
20 | import java.util.List;
21 | import java.util.regex.Matcher;
22 | import java.util.regex.Pattern;
23 |
24 | import android.content.ComponentName;
25 | import android.content.Context;
26 | import android.content.Intent;
27 | import android.content.pm.PackageInfo;
28 | import android.content.pm.PackageManager;
29 | import android.content.pm.PackageManager.NameNotFoundException;
30 | import android.content.pm.ResolveInfo;
31 | import android.net.Uri;
32 | import android.os.Parcelable;
33 | import android.text.Html;
34 |
35 | public final class IntentHelper {
36 |
37 | public static final String MEDIA_PATTERN = "(http[s]?://)+([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?";
38 | private static final Pattern mMediaPattern;
39 |
40 | static {
41 | mMediaPattern = Pattern.compile(MEDIA_PATTERN);
42 | }
43 |
44 | public static Uri getIntentUri(Intent intent) {
45 | Uri result = null;
46 | if (intent != null) {
47 | result = intent.getData();
48 | if (result == null) {
49 | final String type = intent.getType();
50 | String sharedUrl = intent.getStringExtra(Intent.EXTRA_TEXT);
51 | if (!StringUtils.isEmpty(sharedUrl)) {
52 | if ("text/plain".equals(type) && sharedUrl != null) {
53 | result = getTextUri(sharedUrl);
54 | } else if ("text/html".equals(type) && sharedUrl != null) {
55 | result = getTextUri(Html.fromHtml(sharedUrl).toString());
56 | }
57 | } else {
58 | Parcelable parce = intent.getParcelableExtra(Intent.EXTRA_STREAM);
59 | if (parce != null)
60 | result = (Uri) parce;
61 | }
62 | }
63 | }
64 | return result;
65 | }
66 |
67 | private static Uri getTextUri(String sharedUrl) {
68 | Matcher matcher = mMediaPattern.matcher(sharedUrl);
69 | if (matcher.find()) {
70 | sharedUrl = matcher.group();
71 | if (!StringUtils.isEmpty(sharedUrl)) {
72 | return Uri.parse(sharedUrl);
73 | }
74 | }
75 | return null;
76 | }
77 |
78 | public static boolean existPackage(final Context ctx, String packageName) {
79 | if (!StringUtils.isEmpty(packageName)) {
80 | for (PackageInfo p : ctx.getPackageManager().getInstalledPackages(0)) {
81 | if (packageName.equals(p.packageName))
82 | return true;
83 | }
84 | }
85 | return false;
86 | }
87 |
88 | public static void startApkActivity(final Context ctx, String packageName) {
89 | PackageManager pm = ctx.getPackageManager();
90 | PackageInfo pi;
91 | try {
92 | pi = pm.getPackageInfo(packageName, 0);
93 | Intent intent = new Intent(Intent.ACTION_MAIN, null);
94 | intent.setPackage(pi.packageName);
95 |
96 | List apps = pm.queryIntentActivities(intent, 0);
97 |
98 | ResolveInfo ri = apps.iterator().next();
99 | if (ri != null) {
100 | String className = ri.activityInfo.name;
101 | intent.setComponent(new ComponentName(packageName, className));
102 | ctx.startActivity(intent);
103 | }
104 | } catch (NameNotFoundException e) {
105 | Log.e("startActivity", e);
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/com/nmbb/oplayer/util/MediaUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 YIXIA.COM
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 | package com.nmbb.oplayer.util;
17 |
18 | import java.io.File;
19 | import java.util.regex.Pattern;
20 |
21 | import android.net.Uri;
22 |
23 | public final class MediaUtils {
24 | public static final String[] EXTENSIONS;
25 | // http://www.fileinfo.com/filetypes/video
26 | public static final String[] VIDEO_EXTENSIONS = { "\\.264", "\\.3g2", "\\.3gp", "\\.3gp2", "\\.3gpp", "\\.3gpp2", "\\.3mm", "\\.3p2", "\\.60d", "\\.aep", "\\.ajp", "\\.amv", "\\.amx", "\\.arf", "\\.asf", "\\.asx", "\\.avb", "\\.avd", "\\.avi", "\\.avs", "\\.avs", "\\.axm", "\\.bdm", "\\.bdmv", "\\.bik", "\\.bin", "\\.bix", "\\.bmk", "\\.box", "\\.bs4", "\\.bsf", "\\.byu", "\\.camre", "\\.clpi", "\\.cpi", "\\.cvc", "\\.d2v", "\\.d3v", "\\.dat", "\\.dav", "\\.dce", "\\.dck", "\\.ddat", "\\.dif", "\\.dir", "\\.divx", "\\.dlx", "\\.dmb", "\\.dmsm", "\\.dmss", "\\.dnc", "\\.dpg", "\\.dream", "\\.dsy", "\\.dv", "\\.dv-avi", "\\.dv4", "\\.dvdmedia", "\\.dvr-ms", "\\.dvx", "\\.dxr", "\\.dzm", "\\.dzp", "\\.dzt", "\\.evo", "\\.eye", "\\.f4p", "\\.f4v", "\\.fbr", "\\.fbr", "\\.fbz", "\\.fcp", "\\.flc", "\\.flh", "\\.fli", "\\.flv", "\\.flx", "\\.gl", "\\.grasp", "\\.gts", "\\.gvi", "\\.gvp", "\\.hdmov", "\\.hkm", "\\.ifo", "\\.imovi", "\\.imovi", "\\.iva", "\\.ivf", "\\.ivr", "\\.ivs", "\\.izz", "\\.izzy", "\\.jts", "\\.lsf", "\\.lsx", "\\.m15", "\\.m1pg", "\\.m1v", "\\.m21", "\\.m21", "\\.m2a", "\\.m2p", "\\.m2t", "\\.m2ts", "\\.m2v", "\\.m4e", "\\.m4u", "\\.m4v", "\\.m75", "\\.meta", "\\.mgv", "\\.mj2", "\\.mjp", "\\.mjpg", "\\.mkv", "\\.mmv", "\\.mnv", "\\.mod", "\\.modd", "\\.moff", "\\.moi", "\\.moov", "\\.mov", "\\.movie", "\\.mp21", "\\.mp21", "\\.mp2v", "\\.mp4", "\\.mp4v", "\\.mpe", "\\.mpeg", "\\.mpeg4", "\\.mpf", "\\.mpg", "\\.mpg2", "\\.mpgin", "\\.mpl", "\\.mpls", "\\.mpv", "\\.mpv2", "\\.mqv", "\\.msdvd", "\\.msh", "\\.mswmm", "\\.mts", "\\.mtv", "\\.mvb", "\\.mvc", "\\.mvd", "\\.mve", "\\.mvp", "\\.mxf", "\\.mys", "\\.ncor", "\\.nsv", "\\.nvc", "\\.ogm", "\\.ogv", "\\.ogx", "\\.osp", "\\.par", "\\.pds", "\\.pgi", "\\.piv", "\\.playlist", "\\.pmf", "\\.prel", "\\.pro", "\\.prproj", "\\.psh", "\\.pva", "\\.pvr", "\\.pxv", "\\.qt", "\\.qtch", "\\.qtl", "\\.qtm", "\\.qtz", "\\.rcproject", "\\.rdb", "\\.rec", "\\.rm", "\\.rmd", "\\.rmp", "\\.rms", "\\.rmvb", "\\.roq", "\\.rp", "\\.rts", "\\.rts", "\\.rum", "\\.rv", "\\.sbk", "\\.sbt", "\\.scm", "\\.scm", "\\.scn", "\\.sec", "\\.seq", "\\.sfvidcap", "\\.smil", "\\.smk", "\\.sml", "\\.smv", "\\.spl", "\\.ssm", "\\.str", "\\.stx", "\\.svi", "\\.swf", "\\.swi", "\\.swt", "\\.tda3mt", "\\.tivo", "\\.tix", "\\.tod", "\\.tp", "\\.tp0", "\\.tpd", "\\.tpr", "\\.trp", "\\.ts", "\\.tvs", "\\.vc1", "\\.vcr", "\\.vcv", "\\.vdo", "\\.vdr", "\\.veg", "\\.vem", "\\.vf", "\\.vfw", "\\.vfz", "\\.vgz", "\\.vid", "\\.viewlet", "\\.viv", "\\.vivo", "\\.vlab", "\\.vob", "\\.vp3", "\\.vp6", "\\.vp7", "\\.vpj", "\\.vro", "\\.vsp", "\\.w32", "\\.wcp", "\\.webm", "\\.wm", "\\.wmd", "\\.wmmp", "\\.wmv", "\\.wmx", "\\.wp3", "\\.wpl", "\\.wtv", "\\.wvx", "\\.xfl", "\\.xvid", "\\.yuv", "\\.zm1", "\\.zm2", "\\.zm3", "\\.zmv" };
27 | // http://www.fileinfo.com/filetypes/audio
28 | public static final String[] AUDIO_EXTENSIONS = { "\\.4mp", "\\.669", "\\.6cm", "\\.8cm", "\\.8med", "\\.8svx", "\\.a2m", "\\.aa", "\\.aa3", "\\.aac", "\\.aax", "\\.abc", "\\.abm", "\\.ac3", "\\.acd", "\\.acd-bak", "\\.acd-zip", "\\.acm", "\\.act", "\\.adg", "\\.afc", "\\.agm", "\\.ahx", "\\.aif", "\\.aifc", "\\.aiff", "\\.ais", "\\.akp", "\\.al", "\\.alaw", "\\.all", "\\.amf", "\\.amr", "\\.ams", "\\.ams", "\\.aob", "\\.ape", "\\.apf", "\\.apl", "\\.ase", "\\.at3", "\\.atrac", "\\.au", "\\.aud", "\\.aup", "\\.avr", "\\.awb", "\\.band", "\\.bap", "\\.bdd", "\\.box", "\\.bun", "\\.bwf", "\\.c01", "\\.caf", "\\.cda", "\\.cdda", "\\.cdr", "\\.cel", "\\.cfa", "\\.cidb", "\\.cmf", "\\.copy", "\\.cpr", "\\.cpt", "\\.csh", "\\.cwp", "\\.d00", "\\.d01", "\\.dcf", "\\.dcm", "\\.dct", "\\.ddt", "\\.dewf", "\\.df2", "\\.dfc", "\\.dig", "\\.dig", "\\.dls", "\\.dm", "\\.dmf", "\\.dmsa", "\\.dmse", "\\.drg", "\\.dsf", "\\.dsm", "\\.dsp", "\\.dss", "\\.dtm", "\\.dts", "\\.dtshd", "\\.dvf", "\\.dwd", "\\.ear", "\\.efa", "\\.efe", "\\.efk", "\\.efq", "\\.efs", "\\.efv", "\\.emd", "\\.emp", "\\.emx", "\\.esps", "\\.f2r", "\\.f32", "\\.f3r", "\\.f4a", "\\.f64", "\\.far", "\\.fff", "\\.flac", "\\.flp", "\\.fls", "\\.frg", "\\.fsm", "\\.fzb", "\\.fzf", "\\.fzv", "\\.g721", "\\.g723", "\\.g726", "\\.gig", "\\.gp5", "\\.gpk", "\\.gsm", "\\.gsm", "\\.h0", "\\.hdp", "\\.hma", "\\.hsb", "\\.ics", "\\.iff", "\\.imf", "\\.imp", "\\.ins", "\\.ins", "\\.it", "\\.iti", "\\.its", "\\.jam", "\\.k25", "\\.k26", "\\.kar", "\\.kin", "\\.kit", "\\.kmp", "\\.koz", "\\.koz", "\\.kpl", "\\.krz", "\\.ksc", "\\.ksf", "\\.kt2", "\\.kt3", "\\.ktp", "\\.l", "\\.la", "\\.lqt", "\\.lso", "\\.lvp", "\\.lwv", "\\.m1a", "\\.m3u", "\\.m4a", "\\.m4b", "\\.m4p", "\\.m4r", "\\.ma1", "\\.mdl", "\\.med", "\\.mgv", "\\.mid", "\\.midi", "\\.miniusf", "\\.mka", "\\.mlp", "\\.mmf", "\\.mmm", "\\.mmp", "\\.mo3", "\\.mod", "\\.mp1", "\\.mp2", "\\.mp3", "\\.mpa", "\\.mpc", "\\.mpga", "\\.mpu", "\\.mp_", "\\.mscx", "\\.mscz", "\\.msv", "\\.mt2", "\\.mt9", "\\.mte", "\\.mti", "\\.mtm", "\\.mtp", "\\.mts", "\\.mus", "\\.mws", "\\.mxl", "\\.mzp", "\\.nap", "\\.nki", "\\.nra", "\\.nrt", "\\.nsa", "\\.nsf", "\\.nst", "\\.ntn", "\\.nvf", "\\.nwc", "\\.odm", "\\.oga", "\\.ogg", "\\.okt", "\\.oma", "\\.omf", "\\.omg", "\\.omx", "\\.ots", "\\.ove", "\\.ovw", "\\.pac", "\\.pat", "\\.pbf", "\\.pca", "\\.pcast", "\\.pcg", "\\.pcm", "\\.peak", "\\.phy", "\\.pk", "\\.pla", "\\.pls", "\\.pna", "\\.ppc", "\\.ppcx", "\\.prg", "\\.prg", "\\.psf", "\\.psm", "\\.ptf", "\\.ptm", "\\.pts", "\\.pvc", "\\.qcp", "\\.r", "\\.r1m", "\\.ra", "\\.ram", "\\.raw", "\\.rax", "\\.rbs", "\\.rcy", "\\.rex", "\\.rfl", "\\.rmf", "\\.rmi", "\\.rmj", "\\.rmm", "\\.rmx", "\\.rng", "\\.rns", "\\.rol", "\\.rsn", "\\.rso", "\\.rti", "\\.rtm", "\\.rts", "\\.rvx", "\\.rx2", "\\.s3i", "\\.s3m", "\\.s3z", "\\.saf", "\\.sam", "\\.sb", "\\.sbg", "\\.sbi", "\\.sbk", "\\.sc2", "\\.sd", "\\.sd", "\\.sd2", "\\.sd2f", "\\.sdat", "\\.sdii", "\\.sds", "\\.sdt", "\\.sdx", "\\.seg", "\\.seq", "\\.ses", "\\.sf", "\\.sf2", "\\.sfk", "\\.sfl", "\\.shn", "\\.sib", "\\.sid", "\\.sid", "\\.smf", "\\.smp", "\\.snd", "\\.snd", "\\.snd", "\\.sng", "\\.sng", "\\.sou", "\\.sppack", "\\.sprg", "\\.spx", "\\.sseq", "\\.sseq", "\\.ssnd", "\\.stm", "\\.stx", "\\.sty", "\\.svx", "\\.sw", "\\.swa", "\\.syh", "\\.syw", "\\.syx", "\\.td0", "\\.tfmx", "\\.thx", "\\.toc", "\\.tsp", "\\.txw", "\\.u", "\\.ub", "\\.ulaw", "\\.ult", "\\.ulw", "\\.uni", "\\.usf", "\\.usflib", "\\.uw", "\\.uwf", "\\.vag", "\\.val", "\\.vc3", "\\.vmd", "\\.vmf", "\\.vmf", "\\.voc", "\\.voi", "\\.vox", "\\.vpm", "\\.vqf", "\\.vrf", "\\.vyf", "\\.w01", "\\.wav", "\\.wav", "\\.wave", "\\.wax", "\\.wfb", "\\.wfd", "\\.wfp", "\\.wma", "\\.wow", "\\.wpk", "\\.wproj", "\\.wrk", "\\.wus", "\\.wut", "\\.wv", "\\.wvc", "\\.wve", "\\.wwu", "\\.xa", "\\.xa", "\\.xfs", "\\.xi", "\\.xm", "\\.xmf", "\\.xmi", "\\.xmz", "\\.xp", "\\.xrns", "\\.xsb", "\\.xspf", "\\.xt", "\\.xwb", "\\.ym", "\\.zvd", "\\.zvr" };
29 | public static final String[] SUBTRACK_EXTENSIONS = { ".srt", ".ssa", ".smi", ".txt", ".sub", ".ass" };
30 | public static final Pattern VIDEO_EXTENSIONS_PATTERN;
31 | public static final Pattern AUDIO_EXTENSIONS_PATTERN;
32 | public static final Pattern EXTENSIONS_PATTERN;
33 | public static final Pattern SUBTRACK_EXTENSIONS_PATTERN;
34 | static {
35 | EXTENSIONS = ArrayUtils.concat(VIDEO_EXTENSIONS, AUDIO_EXTENSIONS);
36 | EXTENSIONS_PATTERN = generatePattern(EXTENSIONS);
37 | VIDEO_EXTENSIONS_PATTERN = generatePattern(VIDEO_EXTENSIONS);
38 | AUDIO_EXTENSIONS_PATTERN = generatePattern(AUDIO_EXTENSIONS);
39 | SUBTRACK_EXTENSIONS_PATTERN = generatePattern(SUBTRACK_EXTENSIONS);
40 | }
41 |
42 | public static boolean isVideoOrAudio(String url) {
43 | return EXTENSIONS_PATTERN.matcher(url.trim()).find();
44 | }
45 |
46 | public static boolean isVideoOrAudio(File file) {
47 | return EXTENSIONS_PATTERN.matcher(file.getName().trim()).find();
48 | }
49 |
50 | public static boolean isVideo(String url) {
51 | return VIDEO_EXTENSIONS_PATTERN.matcher(url.trim()).find();
52 | }
53 |
54 | public static boolean isVideo(File file) {
55 | return VIDEO_EXTENSIONS_PATTERN.matcher(file.getName().trim()).find();
56 | }
57 |
58 | public static boolean isAudio(String url) {
59 | return AUDIO_EXTENSIONS_PATTERN.matcher(url.trim()).find();
60 | }
61 |
62 | public static boolean isAudio(File file) {
63 | return AUDIO_EXTENSIONS_PATTERN.matcher(file.getName().trim()).find();
64 | }
65 |
66 | public static boolean isSubTrack(File file) {
67 | return SUBTRACK_EXTENSIONS_PATTERN.matcher(file.getName().trim()).find();
68 | }
69 |
70 | public static boolean isNative(String uri) {
71 | uri = Uri.decode(uri);
72 | return uri != null && (uri.startsWith("/") || uri.startsWith("content:") || uri.startsWith("file:"));
73 | }
74 |
75 | private static Pattern generatePattern(String[] args) {
76 | StringBuffer sb = new StringBuffer();
77 | for (String ext : args) {
78 | if (sb.length() > 0)
79 | sb.append("|");
80 | sb.append(ext);
81 | }
82 | return Pattern.compile("(" + sb.toString() + ")$", Pattern.CASE_INSENSITIVE);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/com/nmbb/oplayer/util/PinyinUtils.java:
--------------------------------------------------------------------------------
1 | package com.nmbb.oplayer.util;
2 |
3 | import net.sourceforge.pinyin4j.PinyinHelper;
4 | import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
5 | import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
6 | import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
7 | import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
8 |
9 | public final class PinyinUtils {
10 |
11 | private static HanyuPinyinOutputFormat spellFormat = new HanyuPinyinOutputFormat();
12 |
13 | static {
14 | spellFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
15 | spellFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
16 | //spellFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
17 | }
18 |
19 | public static String chineneToSpell(String chineseStr) throws BadHanyuPinyinOutputFormatCombination {
20 | StringBuffer result = new StringBuffer();
21 | for (char c : chineseStr.toCharArray()) {
22 | if (c > 128) {
23 | String[] array = PinyinHelper.toHanyuPinyinStringArray(c, spellFormat);
24 | if (array != null && array.length > 0)
25 | result.append(array[0]);
26 | else
27 | result.append(" ");
28 | } else
29 | result.append(c);
30 | }
31 | return result.toString();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/nmbb/oplayer/util/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.nmbb.oplayer.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.view.View;
6 | import android.widget.Toast;
7 |
8 | import com.nmbb.oplayer.OPlayerApplication;
9 | import com.nmbb.oplayer.R;
10 |
11 | public class ToastUtils {
12 |
13 | public static void showToast(int resID) {
14 | showToast(OPlayerApplication.getContext(), Toast.LENGTH_SHORT, resID);
15 | }
16 |
17 | public static void showToast(String text) {
18 | showToast(OPlayerApplication.getContext(), Toast.LENGTH_SHORT, text);
19 | }
20 |
21 | public static void showToast(Context ctx, int resID) {
22 | showToast(ctx, Toast.LENGTH_SHORT, resID);
23 | }
24 |
25 | public static void showToast(Context ctx, String text) {
26 | showToast(ctx, Toast.LENGTH_SHORT, text);
27 | }
28 |
29 | public static void showLongToast(Context ctx, int resID) {
30 | showToast(ctx, Toast.LENGTH_LONG, resID);
31 | }
32 |
33 | public static void showLongToast(int resID) {
34 | showToast(OPlayerApplication.getContext(), Toast.LENGTH_LONG, resID);
35 | }
36 |
37 | public static void showLongToast(Context ctx, String text) {
38 | showToast(ctx, Toast.LENGTH_LONG, text);
39 | }
40 |
41 | public static void showLongToast(String text) {
42 | showToast(OPlayerApplication.getContext(), Toast.LENGTH_LONG, text);
43 | }
44 |
45 | public static void showToast(Context ctx, int duration, int resID) {
46 | showToast(ctx, duration, ctx.getString(resID));
47 | }
48 |
49 | public static void showToast(Context ctx, int duration, String text) {
50 | Toast toast = Toast.makeText(ctx, text, duration);
51 | View mNextView = toast.getView();
52 | if (mNextView != null)
53 | mNextView.setBackgroundResource(R.drawable.toast_frame);
54 | toast.show();
55 | // Toast.makeText(ctx, text, duration).show();
56 | }
57 |
58 | // public static void showToastOnUiThread(final String text) {
59 | // showToastOnUiThread(FSAppliction.getCurrentActivity(), text);
60 | // }
61 |
62 | /** 在UI线程运行弹出 */
63 | public static void showToastOnUiThread(final Activity ctx, final String text) {
64 | if (ctx != null) {
65 | ctx.runOnUiThread(new Runnable() {
66 |
67 | @Override
68 | public void run() {
69 | showToast(ctx, text);
70 | }
71 | });
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/nmbb/oplayer/video/VideoThumbnailUtils.java:
--------------------------------------------------------------------------------
1 | package com.nmbb.oplayer.video;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | public final class VideoThumbnailUtils {
6 |
7 | /** 获取视频的缩略图 */
8 | public static Bitmap createVideoThumbnail() {
9 | return null;
10 | }
11 |
12 | /** 获取视频的时长 */
13 | public int getDuration() {
14 | return 1;
15 | }
16 |
17 | /** 获取视频的高度 */
18 | public int getVideoHeight() {
19 | return 1;
20 | }
21 |
22 | /** 获取视频的宽度 */
23 | public int getVideoWidth() {
24 | return 1;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------