Skip to content

Commit 29cf6f8

Browse files
authored
Merge pull request #192 from ashqal/dev-m251
Dev m251
2 parents 433c66d + ac708f1 commit 29cf6f8

Some content is hidden

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

41 files changed

+1370
-277
lines changed

app/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 23
5-
buildToolsVersion '25.0.0'
4+
compileSdkVersion 25
5+
buildToolsVersion '25.0.2'
66

77
defaultConfig {
88
applicationId "com.asha.md360player4android"
@@ -23,9 +23,11 @@ android {
2323
dependencies {
2424
compile fileTree(include: ['*.jar'], dir: 'libs')
2525
testCompile 'junit:junit:4.12'
26-
compile 'com.android.support:appcompat-v7:23.2.0'
26+
compile 'com.android.support:appcompat-v7:25.3.1'
2727
compile 'com.squareup.picasso:picasso:2.5.2'
2828
//required, enough for most devices.
29+
compile 'com.android.support:recyclerview-v7:25.3.1'
30+
compile 'com.android.support:cardview-v7:25.3.1'
2931
compile 'tv.danmaku.ijk.media:ijkplayer-java:0.6.0'
3032
compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.6.0'
3133
compile project(path: ':vrlib')

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<activity android:label="IjkPlayerDemoActivity" android:name=".IjkPlayerDemoActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
2222
<activity android:label="VideoPlayerActivity" android:name=".VideoPlayerActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
2323
<activity android:label="BitmapPlayerActivity" android:name=".BitmapPlayerActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
24+
<activity android:label="CubemapPlayerActivity" android:name=".CubemapPlayerActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
25+
<activity android:name=".RecyclerViewActivity" android:screenOrientation="portrait" android:configChanges="screenSize|orientation" />
2426
</application>
2527

2628
</manifest>
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package com.asha.md360player4android;
2+
3+
import android.content.ContentResolver;
4+
import android.content.res.Resources;
5+
import android.graphics.Bitmap;
6+
import android.graphics.drawable.Drawable;
7+
import android.net.Uri;
8+
import android.os.Bundle;
9+
import android.support.annotation.DrawableRes;
10+
import android.util.Log;
11+
import android.view.View;
12+
import android.widget.Toast;
13+
14+
import com.asha.vrlib.MDVRLibrary;
15+
import com.asha.vrlib.model.MDRay;
16+
import com.asha.vrlib.plugins.hotspot.IMDHotspot;
17+
import com.asha.vrlib.texture.MD360BitmapTexture;
18+
import com.asha.vrlib.texture.MD360CubemapTexture;
19+
import com.squareup.picasso.Picasso;
20+
import com.squareup.picasso.Target;
21+
22+
import static com.squareup.picasso.MemoryPolicy.NO_CACHE;
23+
import static com.squareup.picasso.MemoryPolicy.NO_STORE;
24+
25+
/**
26+
* Created by hzqiujiadi on 16/4/5.
27+
* hzqiujiadi [email protected]
28+
*/
29+
public class CubemapPlayerActivity extends MD360PlayerActivity {
30+
31+
private static final String TAG = "BitmapPlayerActivity";
32+
33+
private Uri nextUri = null;
34+
35+
@Override
36+
public void onCreate(Bundle savedInstanceState) {
37+
super.onCreate(savedInstanceState);
38+
39+
findViewById(R.id.control_next).setOnClickListener(new View.OnClickListener() {
40+
@Override
41+
public void onClick(View v) {
42+
busy();
43+
//nextUri = getDrawableUri(R.drawable.texture);
44+
getVRLibrary().notifyPlayerChanged();
45+
}
46+
});
47+
}
48+
49+
private Target mTarget;// keep the reference for picasso.
50+
51+
private void loadImage(Uri uri, final MD360CubemapTexture.Callback callback){
52+
mTarget = new Target() {
53+
@Override
54+
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
55+
Log.d(TAG, "loaded image, size:" + bitmap.getWidth() + "," + bitmap.getHeight());
56+
57+
// notify if size changed
58+
getVRLibrary().onTextureResize(bitmap.getWidth(), bitmap.getHeight());
59+
60+
// texture
61+
callback.texture(bitmap);
62+
//cancelBusy();
63+
}
64+
65+
@Override
66+
public void onBitmapFailed(Drawable errorDrawable) {
67+
68+
}
69+
70+
@Override
71+
public void onPrepareLoad(Drawable placeHolderDrawable) {
72+
73+
}
74+
};
75+
76+
Log.d(TAG, "load image with max texture size:" + callback.getMaxTextureSize());
77+
Picasso.with(getApplicationContext())
78+
.load(uri)
79+
.resize(callback.getMaxTextureSize(),callback.getMaxTextureSize())
80+
.onlyScaleDown()
81+
.centerInside()
82+
.memoryPolicy(NO_CACHE, NO_STORE)
83+
.into(mTarget);
84+
}
85+
86+
private Uri currentUri(){
87+
if (nextUri == null){
88+
return getUri();
89+
} else {
90+
return nextUri;
91+
}
92+
}
93+
94+
@Override
95+
protected MDVRLibrary createVRLibrary() {
96+
return MDVRLibrary.with(this)
97+
.displayMode(MDVRLibrary.DISPLAY_MODE_NORMAL)
98+
.interactiveMode(MDVRLibrary.INTERACTIVE_MODE_TOUCH)
99+
.projectionMode(MDVRLibrary.PROJECTION_MODE_CUBE) // needed
100+
.asCubemap(new MDVRLibrary.ICubemapProvider() {
101+
@Override
102+
public void onProvideCubemap(MD360CubemapTexture.Callback callback, int cubeFace) {
103+
Log.d(TAG, "Load face: " + cubeFace);
104+
105+
switch(cubeFace) {
106+
case MD360CubemapTexture.CUBE_FRONT:
107+
nextUri = getDrawableUri(R.drawable.cube_front);
108+
break;
109+
case MD360CubemapTexture.CUBE_BACK:
110+
nextUri = getDrawableUri(R.drawable.cube_back);
111+
break;
112+
case MD360CubemapTexture.CUBE_TOP:
113+
nextUri = getDrawableUri(R.drawable.cube_top);
114+
break;
115+
case MD360CubemapTexture.CUBE_BOTTOM:
116+
nextUri = getDrawableUri(R.drawable.cube_bottom);
117+
break;
118+
case MD360CubemapTexture.CUBE_LEFT:
119+
nextUri = getDrawableUri(R.drawable.cube_left);
120+
break;
121+
case MD360CubemapTexture.CUBE_RIGHT:
122+
nextUri = getDrawableUri(R.drawable.cube_right);
123+
break;
124+
default:
125+
return;
126+
}
127+
128+
loadImage(currentUri(), callback);
129+
}
130+
131+
@Override
132+
public void onReady() {
133+
// This can be used to hide a loading view and show the library view
134+
Toast.makeText(CubemapPlayerActivity.this, "CubeMap Ready", Toast.LENGTH_SHORT).show();
135+
cancelBusy();
136+
}
137+
})
138+
.listenTouchPick(new MDVRLibrary.ITouchPickListener() {
139+
@Override
140+
public void onHotspotHit(IMDHotspot hitHotspot, MDRay ray) {
141+
Log.d(TAG,"Ray:" + ray + ", hitHotspot:" + hitHotspot);
142+
}
143+
})
144+
.pinchEnabled(true)
145+
.build(findViewById(R.id.gl_view));
146+
}
147+
148+
private Uri getDrawableUri(@DrawableRes int resId){
149+
Resources resources = getResources();
150+
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId) );
151+
}
152+
}

app/src/main/java/com/asha/md360player4android/DemoActivity.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ public void onClick(View v) {
105105
}
106106
}
107107
});
108+
109+
findViewById(R.id.cubemap_button).setOnClickListener(new View.OnClickListener() {
110+
@Override
111+
public void onClick(View v) {
112+
String url = et.getText().toString();
113+
114+
MD360PlayerActivity.startCubemap(DemoActivity.this, null);
115+
}
116+
});
117+
118+
findViewById(R.id.recycler_view_button).setOnClickListener(new View.OnClickListener() {
119+
@Override
120+
public void onClick(View v) {
121+
RecyclerViewActivity.start(DemoActivity.this);
122+
}
123+
});
108124
}
109125

110126
private Uri getDrawableUri(@DrawableRes int resId){

app/src/main/java/com/asha/md360player4android/MD360PlayerActivity.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.asha.vrlib.MDDirectorCamUpdate;
2323
import com.asha.vrlib.MDVRLibrary;
24+
import com.asha.vrlib.model.MDHitEvent;
2425
import com.asha.vrlib.model.MDHotspotBuilder;
2526
import com.asha.vrlib.model.MDPosition;
2627
import com.asha.vrlib.model.MDRay;
@@ -105,6 +106,10 @@ public static void startBitmap(Context context, Uri uri){
105106
start(context, uri, BitmapPlayerActivity.class);
106107
}
107108

109+
public static void startCubemap(Context context, Uri uri){
110+
start(context, uri, CubemapPlayerActivity.class);
111+
}
112+
108113
private static void start(Context context, Uri uri, Class<? extends Activity> clz){
109114
Intent i = new Intent(context,clz);
110115
i.setData(uri);
@@ -363,9 +368,11 @@ public void onClick(View v) {
363368

364369
final TextView hotspotText = (TextView) findViewById(R.id.hotspot_text);
365370
final TextView directorBriefText = (TextView) findViewById(R.id.director_brief_text);
366-
getVRLibrary().setEyePickChangedListener(new MDVRLibrary.IEyePickListener() {
371+
getVRLibrary().setEyePickChangedListener(new MDVRLibrary.IEyePickListener2() {
367372
@Override
368-
public void onHotspotHit(IMDHotspot hotspot, long hitTimestamp) {
373+
public void onHotspotHit(MDHitEvent hitEvent) {
374+
IMDHotspot hotspot = hitEvent.getHotspot();
375+
long hitTimestamp = hitEvent.getTimestamp();
369376
String text = hotspot == null ? "nop" : String.format(Locale.CHINESE, "%s %fs", hotspot.getTitle(), (System.currentTimeMillis() - hitTimestamp) / 1000.0f );
370377
hotspotText.setText(text);
371378

0 commit comments

Comments
 (0)