iterator = sFileTypeMap.keySet().iterator();
128 |
129 | while (iterator.hasNext()) {
130 | if (builder.length() > 0)
131 | builder.append(',');
132 | builder.append(iterator.next());
133 | }
134 | sFileExtensions = builder.toString();
135 | }
136 |
137 | static void addFileType(String extension, int fileType, String mimeType) {
138 | sFileTypeMap.put(extension, new MediaFileType(fileType, mimeType));
139 | sMimeTypeMap.put(mimeType, Integer.valueOf(fileType));
140 | }
141 |
142 | public static boolean isAudioFileType(int fileType) {
143 | return (fileType >= FIRST_AUDIO_FILE_TYPE && fileType <= LAST_AUDIO_FILE_TYPE);
144 | }
145 |
146 | public static boolean isVideoFileType(int fileType) {
147 | return (fileType >= FIRST_VIDEO_FILE_TYPE && fileType <= LAST_VIDEO_FILE_TYPE);
148 | }
149 |
150 | public static MediaFileType getFileType(String path) {
151 | int lastDot = path.lastIndexOf(".");
152 | if (lastDot < 0)
153 | return null;
154 | return sFileTypeMap.get(path.substring(lastDot + 1).toUpperCase());
155 | }
156 |
157 | public static int getFileTypeForMimeType(String mimeType) {
158 | Integer value = sMimeTypeMap.get(mimeType);
159 | return (value == null ? 0 : value.intValue());
160 | }
161 |
162 | protected static class MediaFileType {
163 | int fileType;
164 | String mimeType;
165 |
166 | MediaFileType(int fileType, String mimeType) {
167 | this.fileType = fileType;
168 | this.mimeType = mimeType;
169 | }
170 | }
171 |
172 | }
--------------------------------------------------------------------------------
/vitamio/src/io/vov/vitamio/MediaMetadataRetriever.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | * Copyright (C) 2013 YIXIA.COM
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package io.vov.vitamio;
19 |
20 | import android.content.ContentResolver;
21 | import android.content.Context;
22 | import android.content.res.AssetFileDescriptor;
23 | import android.graphics.Bitmap;
24 | import android.net.Uri;
25 | import android.util.Log;
26 |
27 | import java.io.FileDescriptor;
28 | import java.io.IOException;
29 |
30 | import io.vov.vitamio.utils.FileUtils;
31 |
32 | /**
33 | * MediaMetadataRetriever is used to get meta data from any media file
34 | *
35 | *
36 | * MediaMetadataRetriever mmr = new MediaMetadataRetriever(this);
37 | * mmr.setDataSource(this, mediaUri);
38 | * String title = mmr.extractMetadata(METADATA_KEY_TITLE);
39 | * Bitmap frame = mmr.getFrameAtTime(-1);
40 | *
41 | */
42 | public class MediaMetadataRetriever {
43 | /**
44 | * The metadata key to retrieve the information about the album title
45 | * of the data source.
46 | */
47 | public static final String METADATA_KEY_ALBUM = "album";
48 | /**
49 | * The metadata key to retrieve the information about the artist of
50 | * the data source.
51 | */
52 | public static final String METADATA_KEY_ARTIST = "artist";
53 | /**
54 | * The metadata key to retrieve the information about the author of
55 | * the data source.
56 | */
57 | public static final String METADATA_KEY_AUTHOR = "author";
58 | /**
59 | * The metadata key to retrieve the information about the composer of
60 | * the data source.
61 | */
62 | public static final String METADATA_KEY_COMPOSER = "composer";
63 | /**
64 | * The metadata key to retrieve the content type or genre of the data
65 | * source.
66 | */
67 | public static final String METADATA_KEY_GENRE = "genre";
68 | /**
69 | * The metadata key to retrieve the data source title.
70 | */
71 | public static final String METADATA_KEY_TITLE = "title";
72 | /**
73 | * The metadata key to retrieve the playback duration of the data source.
74 | */
75 | public static final String METADATA_KEY_DURATION = "duration";
76 | /**
77 | * If the media contains video, this key retrieves its width.
78 | */
79 | public static final String METADATA_KEY_VIDEO_WIDTH = "width";
80 | /**
81 | * If the media contains video, this key retrieves its height.
82 | */
83 | public static final String METADATA_KEY_VIDEO_HEIGHT = "height";
84 |
85 | static {
86 | String LIB_ROOT = Vitamio.getLibraryPath();
87 | Log.i("LIB ROOT: %s", LIB_ROOT);
88 | System.load(LIB_ROOT + "libstlport_shared.so");
89 | System.load(LIB_ROOT + "libvscanner.so");
90 | loadFFmpeg_native(LIB_ROOT + "libffmpeg.so");
91 | }
92 |
93 | private Context mContext;
94 | private AssetFileDescriptor mFD = null;
95 |
96 | public MediaMetadataRetriever(Context ctx) {
97 | mContext = ctx;
98 | native_init();
99 | }
100 |
101 | private static native boolean loadFFmpeg_native(String ffmpegPath);
102 |
103 | public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
104 | if (context == null || uri == null)
105 | throw new IllegalArgumentException();
106 | String scheme = uri.getScheme();
107 | if (scheme == null || scheme.equals("file")) {
108 | setDataSource(FileUtils.getPath(uri.toString()));
109 | return;
110 | }
111 |
112 | try {
113 | ContentResolver resolver = context.getContentResolver();
114 | mFD = resolver.openAssetFileDescriptor(uri, "r");
115 | if (mFD == null)
116 | return;
117 | setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
118 | return;
119 | } catch (Exception e) {
120 | closeFD();
121 | }
122 | Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
123 | setDataSource(uri.toString());
124 | return;
125 | }
126 |
127 | public native void setDataSource(String path) throws IOException, IllegalArgumentException, IllegalStateException;
128 |
129 | /*
130 | * Do not change these metadata key values without updating their
131 | * counterparts in c file
132 | */
133 |
134 | public native void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException;
135 |
136 | /**
137 | * Call this method after setDataSource(). This method retrieves the
138 | * meta data value associated with the keyCode.
139 | *
140 | * The keyCode currently supported is listed below as METADATA_XXX
141 | * constants. With any other value, it returns a null pointer.
142 | *
143 | * @param keyCode One of the constants listed below at the end of the class.
144 | * @return The meta data value associate with the given keyCode on success;
145 | * null on failure.
146 | */
147 | public native String extractMetadata(String keyCode) throws IllegalStateException;
148 |
149 | public native Bitmap getFrameAtTime(long timeUs) throws IllegalStateException;
150 |
151 | private native void _release();
152 |
153 | public void release() {
154 | _release();
155 | closeFD();
156 | }
157 |
158 | private native final void native_init();
159 |
160 | private native final void native_finalize();
161 |
162 | @Override
163 | protected void finalize() throws Throwable {
164 | try {
165 | native_finalize();
166 | } finally {
167 | super.finalize();
168 | }
169 | }
170 |
171 | private void closeFD() {
172 | if (mFD != null) {
173 | try {
174 | mFD.close();
175 | } catch (IOException e) {
176 | }
177 | mFD = null;
178 | }
179 | }
180 |
181 | }
--------------------------------------------------------------------------------
/vitamio/src/io/vov/vitamio/MediaScannerClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2006 The Android Open Source Project
3 | * Copyright (C) 2013 YIXIA.COM
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package io.vov.vitamio;
19 |
20 | /**
21 | * DON'T TOUCH THIS FILE IF YOU DON'T KNOW THE MediaScanner PROCEDURE!!!
22 | */
23 | public interface MediaScannerClient {
24 | void scanFile(String path, long lastModified, long fileSize);
25 |
26 | void addNoMediaFolder(String path);
27 |
28 | void handleStringTag(String name, byte[] value, String valueEncoding);
29 |
30 | void setMimeType(String mimeType);
31 | }
--------------------------------------------------------------------------------
/vitamio/src/io/vov/vitamio/Metadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2006 The Android Open Source Project
3 | * Copyright (C) 2013 YIXIA.COM
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package io.vov.vitamio;
19 |
20 | import android.util.SparseArray;
21 |
22 | import java.io.UnsupportedEncodingException;
23 | import java.util.Locale;
24 | import java.util.Map;
25 |
26 | /**
27 | * See {@link io.vov.vitamio.MediaPlayer#getMetadata()}
28 | */
29 | public class Metadata {
30 | public static final int ANY = 0;
31 | public static final int TITLE = 1; // String
32 | public static final int COMMENT = 2; // String
33 | public static final int COPYRIGHT = 3; // String
34 | public static final int ALBUM = 4; // String
35 | public static final int ARTIST = 5; // String
36 | public static final int AUTHOR = 6; // String
37 | public static final int COMPOSER = 7; // String
38 | public static final int GENRE = 8; // String
39 | public static final int DATE = 9; // Date
40 | public static final int DURATION = 10; // Integer(milliseconds)
41 | public static final int CD_TRACK_NUM = 11; // Integer (1-based)
42 | public static final int CD_TRACK_MAX = 12; // Integer
43 | public static final int RATING = 13; // String
44 | public static final int ALBUM_ART = 14; // byte[]
45 | public static final int VIDEO_FRAME = 15; // Bitmap
46 | public static final int LENGTH = 16; // Integer (bytes)
47 | public static final int BIT_RATE = 17; // Integer
48 | public static final int AUDIO_BIT_RATE = 18; // Integer
49 | public static final int VIDEO_BIT_RATE = 19; // Integer
50 | public static final int AUDIO_SAMPLE_RATE = 20; // Integer
51 | public static final int VIDEO_FRAME_RATE = 21; // Float
52 | // See RFC2046 and RFC4281.
53 | public static final int MIME_TYPE = 22; // String
54 | public static final int AUDIO_CODEC = 23; // String
55 | public static final int VIDEO_CODEC = 24; // String
56 | public static final int VIDEO_HEIGHT = 25; // Integer
57 | public static final int VIDEO_WIDTH = 26; // Integer
58 | public static final int NUM_TRACKS = 27; // Integer
59 | public static final int DRM_CRIPPLED = 28; // Boolean
60 | public static final int PAUSE_AVAILABLE = 29; // Boolean
61 | public static final int SEEK_BACKWARD_AVAILABLE = 30; // Boolean
62 | public static final int SEEK_FORWARD_AVAILABLE = 31; // Boolean
63 | public static final int SEEK_AVAILABLE = 32; // Boolean
64 | private static final int LAST_SYSTEM = 32;
65 | private static final int FIRST_CUSTOM = 8192;
66 | private SparseArray mMeta = new SparseArray();
67 | private String mEncoding = "UTF-8";
68 |
69 | public boolean parse(Map meta, String encoding) {
70 | String key = null;
71 | byte[] value = null;
72 | mEncoding = encoding;
73 | for (byte[] keyBytes : meta.keySet()) {
74 | try {
75 | key = new String(keyBytes, mEncoding).trim().toLowerCase(Locale.US);
76 | } catch (UnsupportedEncodingException e) {
77 | key = new String(keyBytes).trim().toLowerCase(Locale.US);
78 | }
79 | value = meta.get(keyBytes);
80 | if (key.equals("title")) {
81 | mMeta.put(TITLE, value);
82 | } else if (key.equals("comment")) {
83 | mMeta.put(COMMENT, value);
84 | } else if (key.equals("copyright")) {
85 | mMeta.put(COPYRIGHT, value);
86 | } else if (key.equals("album")) {
87 | mMeta.put(ALBUM, value);
88 | } else if (key.equals("artist")) {
89 | mMeta.put(ARTIST, value);
90 | } else if (key.equals("author")) {
91 | mMeta.put(AUTHOR, value);
92 | } else if (key.equals("composer")) {
93 | mMeta.put(COMPOSER, value);
94 | } else if (key.equals("genre")) {
95 | mMeta.put(GENRE, value);
96 | } else if (key.equals("creation_time") || key.equals("date")) {
97 | mMeta.put(DATE, value);
98 | } else if (key.equals("duration")) {
99 | mMeta.put(DURATION, value);
100 | } else if (key.equals("length")) {
101 | mMeta.put(LENGTH, value);
102 | } else if (key.equals("bit_rate")) {
103 | mMeta.put(BIT_RATE, value);
104 | } else if (key.equals("audio_bit_rate")) {
105 | mMeta.put(AUDIO_BIT_RATE, value);
106 | } else if (key.equals("video_bit_rate")) {
107 | mMeta.put(VIDEO_BIT_RATE, value);
108 | } else if (key.equals("audio_sample_rate")) {
109 | mMeta.put(AUDIO_SAMPLE_RATE, value);
110 | } else if (key.equals("video_frame_rate")) {
111 | mMeta.put(VIDEO_FRAME_RATE, value);
112 | } else if (key.equals("format")) {
113 | mMeta.put(MIME_TYPE, value);
114 | } else if (key.equals("audio_codec")) {
115 | mMeta.put(AUDIO_CODEC, value);
116 | } else if (key.equals("video_codec")) {
117 | mMeta.put(VIDEO_CODEC, value);
118 | } else if (key.equals("video_height")) {
119 | mMeta.put(VIDEO_HEIGHT, value);
120 | } else if (key.equals("video_width")) {
121 | mMeta.put(VIDEO_WIDTH, value);
122 | } else if (key.equals("num_tracks")) {
123 | mMeta.put(NUM_TRACKS, value);
124 | } else if (key.equals("cap_pause")) {
125 | mMeta.put(PAUSE_AVAILABLE, value);
126 | } else if (key.equals("cap_seek")) {
127 | mMeta.put(SEEK_AVAILABLE, value);
128 | }
129 | }
130 |
131 | if (BuildConfig.DEBUG) {
132 | android.util.Log.i("Vitamio[Metadata]", "title:\t\t" + getString(TITLE));
133 | android.util.Log.i("Vitamio[Metadata]", "comment:\t\t" + getString(COMMENT));
134 | android.util.Log.i("Vitamio[Metadata]", "copyright:\t\t" + getString(COPYRIGHT));
135 | android.util.Log.i("Vitamio[Metadata]", "album:\t\t" + getString(ALBUM));
136 | android.util.Log.i("Vitamio[Metadata]", "artist:\t\t" + getString(ARTIST));
137 | android.util.Log.i("Vitamio[Metadata]", "composer:\t\t" + getString(COMPOSER));
138 | android.util.Log.i("Vitamio[Metadata]", "genre:\t\t" + getString(GENRE));
139 | android.util.Log.i("Vitamio[Metadata]", "date:\t\t" + getString(DATE));
140 | android.util.Log.i("Vitamio[Metadata]", "duration:\t\t" + getLong(DURATION));
141 | android.util.Log.i("Vitamio[Metadata]", "length:\t\t" + getLong(LENGTH));
142 | android.util.Log.i("Vitamio[Metadata]", "bit_rate:\t\t" + getInt(BIT_RATE));
143 | android.util.Log.i("Vitamio[Metadata]", "audio_bit_rate:\t" + getInt(AUDIO_BIT_RATE));
144 | android.util.Log.i("Vitamio[Metadata]", "video_bit_rate:\t" + getInt(VIDEO_BIT_RATE));
145 | android.util.Log.i("Vitamio[Metadata]", "audio_sample_rate:\t" + getInt(AUDIO_SAMPLE_RATE));
146 | android.util.Log.i("Vitamio[Metadata]", "video_frame_rate:\t" + getDouble(VIDEO_FRAME_RATE));
147 | android.util.Log.i("Vitamio[Metadata]", "format:\t\t" + getString(MIME_TYPE));
148 | android.util.Log.i("Vitamio[Metadata]", "audio_codec:\t" + getString(AUDIO_CODEC));
149 | android.util.Log.i("Vitamio[Metadata]", "video_codec:\t" + getString(VIDEO_CODEC));
150 | android.util.Log.i("Vitamio[Metadata]", "video_height:\t" + getInt(VIDEO_HEIGHT));
151 | android.util.Log.i("Vitamio[Metadata]", "video_width:\t" + getInt(VIDEO_WIDTH));
152 | android.util.Log.i("Vitamio[Metadata]", "num_tracks:\t\t" + getInt(NUM_TRACKS));
153 | android.util.Log.i("Vitamio[Metadata]", "cap_pause:\t\t" + getBoolean(PAUSE_AVAILABLE));
154 | android.util.Log.i("Vitamio[Metadata]", "cap_seek:\t\t" + getBoolean(SEEK_AVAILABLE));
155 | }
156 |
157 | return true;
158 | }
159 |
160 | public boolean has(final int metadataId) {
161 | if (!checkMetadataId(metadataId)) {
162 | throw new IllegalArgumentException("Invalid key: " + metadataId);
163 | }
164 | return mMeta.indexOfKey(metadataId) >= 0;
165 | }
166 |
167 | public String getString(final int key) {
168 | byte[] value = mMeta.get(key);
169 | if (value == null) {
170 | return null;
171 | }
172 | try {
173 | return new String(value, mEncoding);
174 | } catch (UnsupportedEncodingException e) {
175 | return new String(value);
176 | }
177 | }
178 |
179 | public int getInt(final int key) {
180 | try {
181 | return Integer.parseInt(getString(key));
182 | } catch (Exception e) {
183 | return -1;
184 | }
185 | }
186 |
187 | public boolean getBoolean(final int key) {
188 | try {
189 | return Boolean.parseBoolean(getString(key));
190 | } catch (Exception e) {
191 | return false;
192 | }
193 | }
194 |
195 | public long getLong(final int key) {
196 | try {
197 | return Long.parseLong(getString(key));
198 | } catch (Exception e) {
199 | return -1;
200 | }
201 | }
202 |
203 | public double getDouble(final int key) {
204 | try {
205 | return Double.parseDouble(getString(key));
206 | } catch (Exception e) {
207 | return -1;
208 | }
209 | }
210 |
211 | public byte[] getByteArray(final int key) {
212 | return mMeta.get(key);
213 | }
214 |
215 | private boolean checkMetadataId(final int val) {
216 | return !(val <= ANY || (LAST_SYSTEM < val && val < FIRST_CUSTOM));
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/vitamio/src/io/vov/vitamio/ThumbnailUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2006 The Android Open Source Project
3 | * Copyright (C) 2013 YIXIA.COM
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package io.vov.vitamio;
19 |
20 | import android.content.Context;
21 | import android.graphics.Bitmap;
22 | import android.graphics.Canvas;
23 | import android.graphics.Matrix;
24 | import android.graphics.Rect;
25 |
26 | import io.vov.vitamio.provider.MediaStore.Video;
27 |
28 | /**
29 | * ThumbnailUtils is a wrapper of MediaMetadataRetriever to retrive a thumbnail
30 | * of video file.
31 | *
32 | *
33 | * Bitmap thumb = ThumbnailUtils.createVideoThumbnail(this, videoPath, MINI_KIND);
34 | *
35 | */
36 | public class ThumbnailUtils {
37 | public static final int OPTIONS_RECYCLE_INPUT = 0x2;
38 | public static final int TARGET_SIZE_MINI_THUMBNAIL_WIDTH = 426;
39 | public static final int TARGET_SIZE_MINI_THUMBNAIL_HEIGHT = 320;
40 | public static final int TARGET_SIZE_MICRO_THUMBNAIL_WIDTH = 212;
41 | public static final int TARGET_SIZE_MICRO_THUMBNAIL_HEIGHT = 160;
42 | private static final int OPTIONS_NONE = 0x0;
43 | private static final int OPTIONS_SCALE_UP = 0x1;
44 |
45 | public static Bitmap createVideoThumbnail(Context ctx, String filePath, int kind) {
46 | if (!Vitamio.isInitialized(ctx)) {
47 | return null;
48 | }
49 | Bitmap bitmap = null;
50 | MediaMetadataRetriever retriever = null;
51 | try {
52 | retriever = new MediaMetadataRetriever(ctx);
53 | retriever.setDataSource(filePath);
54 | bitmap = retriever.getFrameAtTime(-1);
55 | } catch (Exception ex) {
56 | } finally {
57 | try {
58 | retriever.release();
59 | } catch (RuntimeException ex) {
60 | }
61 | }
62 |
63 | if (bitmap != null) {
64 | if (kind == Video.Thumbnails.MICRO_KIND)
65 | bitmap = extractThumbnail(bitmap, TARGET_SIZE_MICRO_THUMBNAIL_WIDTH, TARGET_SIZE_MICRO_THUMBNAIL_HEIGHT, OPTIONS_RECYCLE_INPUT);
66 | else if (kind == Video.Thumbnails.MINI_KIND)
67 | bitmap = extractThumbnail(bitmap, TARGET_SIZE_MINI_THUMBNAIL_WIDTH, TARGET_SIZE_MINI_THUMBNAIL_HEIGHT, OPTIONS_RECYCLE_INPUT);
68 | }
69 | return bitmap;
70 | }
71 |
72 | public static Bitmap extractThumbnail(Bitmap source, int width, int height) {
73 | return extractThumbnail(source, width, height, OPTIONS_NONE);
74 | }
75 |
76 | public static Bitmap extractThumbnail(Bitmap source, int width, int height, int options) {
77 | if (source == null)
78 | return null;
79 |
80 | float scale;
81 | if (source.getWidth() < source.getHeight())
82 | scale = width / (float) source.getWidth();
83 | else
84 | scale = height / (float) source.getHeight();
85 | Matrix matrix = new Matrix();
86 | matrix.setScale(scale, scale);
87 | Bitmap thumbnail = transform(matrix, source, width, height, OPTIONS_SCALE_UP | options);
88 | return thumbnail;
89 | }
90 |
91 | private static Bitmap transform(Matrix scaler, Bitmap source, int targetWidth, int targetHeight, int options) {
92 | boolean scaleUp = (options & OPTIONS_SCALE_UP) != 0;
93 | boolean recycle = (options & OPTIONS_RECYCLE_INPUT) != 0;
94 |
95 | int deltaX = source.getWidth() - targetWidth;
96 | int deltaY = source.getHeight() - targetHeight;
97 | if (!scaleUp && (deltaX < 0 || deltaY < 0)) {
98 | Bitmap b2 = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
99 | Canvas c = new Canvas(b2);
100 |
101 | int deltaXHalf = Math.max(0, deltaX / 2);
102 | int deltaYHalf = Math.max(0, deltaY / 2);
103 | Rect src = new Rect(deltaXHalf, deltaYHalf, deltaXHalf + Math.min(targetWidth, source.getWidth()), deltaYHalf + Math.min(targetHeight, source.getHeight()));
104 | int dstX = (targetWidth - src.width()) / 2;
105 | int dstY = (targetHeight - src.height()) / 2;
106 | Rect dst = new Rect(dstX, dstY, targetWidth - dstX, targetHeight - dstY);
107 | c.drawBitmap(source, src, dst, null);
108 | if (recycle)
109 | source.recycle();
110 | return b2;
111 | }
112 |
113 | float bitmapWidthF = source.getWidth();
114 | float bitmapHeightF = source.getHeight();
115 | float bitmapAspect = bitmapWidthF / bitmapHeightF;
116 | float viewAspect = (float) targetWidth / targetHeight;
117 |
118 | float scale = bitmapAspect > viewAspect ? targetHeight / bitmapHeightF : targetWidth / bitmapWidthF;
119 | if (scale < .9F || scale > 1F)
120 | scaler.setScale(scale, scale);
121 | else
122 | scaler = null;
123 |
124 | Bitmap b1;
125 | if (scaler != null)
126 | b1 = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), scaler, true);
127 | else
128 | b1 = source;
129 |
130 | if (recycle && b1 != source)
131 | source.recycle();
132 |
133 | int dx1 = Math.max(0, b1.getWidth() - targetWidth);
134 | int dy1 = Math.max(0, b1.getHeight() - targetHeight);
135 |
136 | Bitmap b2 = Bitmap.createBitmap(b1, dx1 / 2, dy1 / 2, targetWidth, targetHeight);
137 |
138 | if (b2 != b1 && (recycle || b1 != source))
139 | b1.recycle();
140 |
141 | return b2;
142 | }
143 |
144 | }
--------------------------------------------------------------------------------
/vitamio/src/io/vov/vitamio/VIntent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 |
17 | package io.vov.vitamio;
18 |
19 | /**
20 | * Common intent actions used by Vitamio component.
21 | */
22 | public class VIntent {
23 | public static final String ACTION_MEDIA_SCANNER_SCAN_DIRECTORY = "com.yixia.vitamio.action.MEDIA_SCANNER_SCAN_DIRECTORY";
24 | public static final String ACTION_MEDIA_SCANNER_SCAN_FILE = "com.yixia.vitamio.action.MEDIA_SCANNER_SCAN_FILE";
25 | public static final String ACTION_MEDIA_SCANNER_STARTED = "com.yixia.vitamio.action.MEDIA_SCANNER_STARTED";
26 | public static final String ACTION_MEDIA_SCANNER_FINISHED = "com.yixia.vitamio.action.MEDIA_SCANNER_FINISHED";
27 | }
28 |
--------------------------------------------------------------------------------
/vitamio/src/io/vov/vitamio/VitamioLicense.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 |
17 | package io.vov.vitamio;
18 |
19 | /**
20 | * DON'T MODIFY THIS FILE IF YOU WANT TO USE VITAMIO
21 | */
22 | public class VitamioLicense {
23 | public static final String LICENSE = "Copyright (c) YIXIA (http://yixia.com).\nTHIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)";
24 | }
--------------------------------------------------------------------------------
/vitamio/src/io/vov/vitamio/activity/InitActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 |
17 | package io.vov.vitamio.activity;
18 |
19 | import android.app.Activity;
20 | import android.app.ProgressDialog;
21 | import android.content.Context;
22 | import android.content.Intent;
23 | import android.os.AsyncTask;
24 | import android.os.Bundle;
25 | import android.os.Handler;
26 | import android.os.Message;
27 | import android.view.WindowManager;
28 |
29 | import java.lang.ref.WeakReference;
30 |
31 | import io.vov.vitamio.R;
32 | import io.vov.vitamio.Vitamio;
33 |
34 | public class InitActivity extends Activity {
35 | public static final String FROM_ME = "fromVitamioInitActivity";
36 | private ProgressDialog mPD;
37 | private UIHandler uiHandler;
38 |
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
42 | uiHandler = new UIHandler(this);
43 |
44 | new AsyncTask