Skip to content

Commit

Permalink
Merge pull request #192 from ashqal/dev-m251
Browse files Browse the repository at this point in the history
Dev m251
  • Loading branch information
ashqal authored Sep 13, 2017
2 parents 433c66d + ac708f1 commit 29cf6f8
Show file tree
Hide file tree
Showing 41 changed files with 1,370 additions and 277 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
compileSdkVersion 25
buildToolsVersion '25.0.2'

defaultConfig {
applicationId "com.asha.md360player4android"
Expand All @@ -23,9 +23,11 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
//required, enough for most devices.
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'tv.danmaku.ijk.media:ijkplayer-java:0.6.0'
compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.6.0'
compile project(path: ':vrlib')
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<activity android:label="IjkPlayerDemoActivity" android:name=".IjkPlayerDemoActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
<activity android:label="VideoPlayerActivity" android:name=".VideoPlayerActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
<activity android:label="BitmapPlayerActivity" android:name=".BitmapPlayerActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
<activity android:label="CubemapPlayerActivity" android:name=".CubemapPlayerActivity" android:screenOrientation="landscape" android:configChanges="screenSize|orientation" />
<activity android:name=".RecyclerViewActivity" android:screenOrientation="portrait" android:configChanges="screenSize|orientation" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.asha.md360player4android;

import android.content.ContentResolver;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.asha.vrlib.MDVRLibrary;
import com.asha.vrlib.model.MDRay;
import com.asha.vrlib.plugins.hotspot.IMDHotspot;
import com.asha.vrlib.texture.MD360BitmapTexture;
import com.asha.vrlib.texture.MD360CubemapTexture;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

import static com.squareup.picasso.MemoryPolicy.NO_CACHE;
import static com.squareup.picasso.MemoryPolicy.NO_STORE;

/**
* Created by hzqiujiadi on 16/4/5.
* hzqiujiadi [email protected]
*/
public class CubemapPlayerActivity extends MD360PlayerActivity {

private static final String TAG = "BitmapPlayerActivity";

private Uri nextUri = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

findViewById(R.id.control_next).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
busy();
//nextUri = getDrawableUri(R.drawable.texture);
getVRLibrary().notifyPlayerChanged();
}
});
}

private Target mTarget;// keep the reference for picasso.

private void loadImage(Uri uri, final MD360CubemapTexture.Callback callback){
mTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d(TAG, "loaded image, size:" + bitmap.getWidth() + "," + bitmap.getHeight());

// notify if size changed
getVRLibrary().onTextureResize(bitmap.getWidth(), bitmap.getHeight());

// texture
callback.texture(bitmap);
//cancelBusy();
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {

}

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {

}
};

Log.d(TAG, "load image with max texture size:" + callback.getMaxTextureSize());
Picasso.with(getApplicationContext())
.load(uri)
.resize(callback.getMaxTextureSize(),callback.getMaxTextureSize())
.onlyScaleDown()
.centerInside()
.memoryPolicy(NO_CACHE, NO_STORE)
.into(mTarget);
}

private Uri currentUri(){
if (nextUri == null){
return getUri();
} else {
return nextUri;
}
}

@Override
protected MDVRLibrary createVRLibrary() {
return MDVRLibrary.with(this)
.displayMode(MDVRLibrary.DISPLAY_MODE_NORMAL)
.interactiveMode(MDVRLibrary.INTERACTIVE_MODE_TOUCH)
.projectionMode(MDVRLibrary.PROJECTION_MODE_CUBE) // needed
.asCubemap(new MDVRLibrary.ICubemapProvider() {
@Override
public void onProvideCubemap(MD360CubemapTexture.Callback callback, int cubeFace) {
Log.d(TAG, "Load face: " + cubeFace);

switch(cubeFace) {
case MD360CubemapTexture.CUBE_FRONT:
nextUri = getDrawableUri(R.drawable.cube_front);
break;
case MD360CubemapTexture.CUBE_BACK:
nextUri = getDrawableUri(R.drawable.cube_back);
break;
case MD360CubemapTexture.CUBE_TOP:
nextUri = getDrawableUri(R.drawable.cube_top);
break;
case MD360CubemapTexture.CUBE_BOTTOM:
nextUri = getDrawableUri(R.drawable.cube_bottom);
break;
case MD360CubemapTexture.CUBE_LEFT:
nextUri = getDrawableUri(R.drawable.cube_left);
break;
case MD360CubemapTexture.CUBE_RIGHT:
nextUri = getDrawableUri(R.drawable.cube_right);
break;
default:
return;
}

loadImage(currentUri(), callback);
}

@Override
public void onReady() {
// This can be used to hide a loading view and show the library view
Toast.makeText(CubemapPlayerActivity.this, "CubeMap Ready", Toast.LENGTH_SHORT).show();
cancelBusy();
}
})
.listenTouchPick(new MDVRLibrary.ITouchPickListener() {
@Override
public void onHotspotHit(IMDHotspot hitHotspot, MDRay ray) {
Log.d(TAG,"Ray:" + ray + ", hitHotspot:" + hitHotspot);
}
})
.pinchEnabled(true)
.build(findViewById(R.id.gl_view));
}

private Uri getDrawableUri(@DrawableRes int resId){
Resources resources = getResources();
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId) );
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/asha/md360player4android/DemoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ public void onClick(View v) {
}
}
});

findViewById(R.id.cubemap_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = et.getText().toString();

MD360PlayerActivity.startCubemap(DemoActivity.this, null);
}
});

findViewById(R.id.recycler_view_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RecyclerViewActivity.start(DemoActivity.this);
}
});
}

private Uri getDrawableUri(@DrawableRes int resId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.asha.vrlib.MDDirectorCamUpdate;
import com.asha.vrlib.MDVRLibrary;
import com.asha.vrlib.model.MDHitEvent;
import com.asha.vrlib.model.MDHotspotBuilder;
import com.asha.vrlib.model.MDPosition;
import com.asha.vrlib.model.MDRay;
Expand Down Expand Up @@ -105,6 +106,10 @@ public static void startBitmap(Context context, Uri uri){
start(context, uri, BitmapPlayerActivity.class);
}

public static void startCubemap(Context context, Uri uri){
start(context, uri, CubemapPlayerActivity.class);
}

private static void start(Context context, Uri uri, Class<? extends Activity> clz){
Intent i = new Intent(context,clz);
i.setData(uri);
Expand Down Expand Up @@ -363,9 +368,11 @@ public void onClick(View v) {

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

Expand Down
Loading

0 comments on commit 29cf6f8

Please sign in to comment.