Skip to content

Commit

Permalink
Merge pull request #160 from ashqal/dev-m221
Browse files Browse the repository at this point in the history
Dev m221
  • Loading branch information
ashqal authored Apr 13, 2017
2 parents e0cd48f + 9595b7a commit 04aaa7f
Show file tree
Hide file tree
Showing 52 changed files with 2,070 additions and 977 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import com.asha.vrlib.MDVRLibrary;
import com.asha.vrlib.model.MDRay;
import com.asha.vrlib.plugins.IMDHotspot;
import com.asha.vrlib.plugins.hotspot.IMDHotspot;
import com.asha.vrlib.texture.MD360BitmapTexture;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
Expand All @@ -19,19 +18,22 @@
import android.widget.Toast;

import com.asha.vrlib.MDVRLibrary;
import com.asha.vrlib.common.MDUtil;
import com.asha.vrlib.model.MDHotspotBuilder;
import com.asha.vrlib.model.MDPosition;
import com.asha.vrlib.model.MDRay;
import com.asha.vrlib.plugins.IMDHotspot;
import com.asha.vrlib.model.MDViewBuilder;
import com.asha.vrlib.model.position.MDMutablePosition;
import com.asha.vrlib.plugins.MDAbsPlugin;
import com.asha.vrlib.plugins.MDHotspotPlugin;
import com.asha.vrlib.plugins.MDWidgetPlugin;
import com.asha.vrlib.plugins.hotspot.IMDHotspot;
import com.asha.vrlib.plugins.hotspot.MDAbsHotspot;
import com.asha.vrlib.plugins.hotspot.MDSimpleHotspot;
import com.asha.vrlib.plugins.hotspot.MDAbsView;
import com.asha.vrlib.plugins.hotspot.MDView;
import com.asha.vrlib.texture.MD360BitmapTexture;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -99,13 +101,15 @@ private static void start(Context context, Uri uri, Class<? extends Activity> cl

private MDVRLibrary mVRLibrary;

// load resource from android drawable and remote url.
private MDVRLibrary.IImageLoadProvider mImageLoadProvider = new ImageLoadProvider();

// load resource from android drawable only.
private MDVRLibrary.IImageLoadProvider mAndroidProvider = new AndroidProvider(this);

private List<MDAbsPlugin> plugins = new LinkedList<>();

private MDPosition logoPosition = MDPosition.newInstance().setY(-8.0f).setYaw(-90.0f);
private MDPosition logoPosition = MDMutablePosition.newInstance().setY(-8.0f).setYaw(-90.0f);

private MDPosition[] positions = new MDPosition[]{
MDPosition.newInstance().setZ(-8.0f).setYaw(-45.0f),
Expand Down Expand Up @@ -197,12 +201,12 @@ public void onSpinnerClicked(int index, int key, String value) {
public void onClick(View v) {
final int index = (int) (Math.random() * 100) % positions.length;
MDPosition position = positions[index];
MDHotspotBuilder builder = MDHotspotBuilder.create(mAndroidProvider)
MDHotspotBuilder builder = MDHotspotBuilder.create(mImageLoadProvider)
.size(4f,4f)
.provider(0, MDUtil.getDrawableUri(activity, android.R.drawable.star_off))
.provider(1, MDUtil.getDrawableUri(activity, android.R.drawable.star_on))
.provider(10, MDUtil.getDrawableUri(activity, android.R.drawable.checkbox_off_background))
.provider(11, MDUtil.getDrawableUri(activity, android.R.drawable.checkbox_on_background))
.provider(0, activity, android.R.drawable.star_off)
.provider(1, activity, android.R.drawable.star_on)
.provider(10, activity, android.R.drawable.checkbox_off_background)
.provider(11, activity, android.R.drawable.checkbox_on_background)
.listenClick(new MDVRLibrary.ITouchPickListener() {
@Override
public void onHotspotHit(IMDHotspot hitHotspot, MDRay ray) {
Expand All @@ -228,9 +232,9 @@ public void onHotspotHit(IMDHotspot hitHotspot, MDRay ray) {
findViewById(R.id.button_add_plugin_logo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MDHotspotBuilder builder = MDHotspotBuilder.create(mAndroidProvider)
MDHotspotBuilder builder = MDHotspotBuilder.create(mImageLoadProvider)
.size(4f,4f)
.provider(MDUtil.getDrawableUri(activity, R.drawable.moredoo_logo))
.provider(activity, R.drawable.moredoo_logo)
.title("logo")
.position(logoPosition)
.listenClick(new MDVRLibrary.ITouchPickListener() {
Expand All @@ -239,9 +243,9 @@ public void onHotspotHit(IMDHotspot hitHotspot, MDRay ray) {
Toast.makeText(MD360PlayerActivity.this, "click logo", Toast.LENGTH_SHORT).show();
}
});
MDHotspotPlugin plugin = new MDHotspotPlugin(builder);
plugins.add(plugin);
getVRLibrary().addPlugin(plugin);
MDAbsHotspot hotspot = new MDSimpleHotspot(builder);
plugins.add(hotspot);
getVRLibrary().addPlugin(hotspot);
Toast.makeText(MD360PlayerActivity.this, "add plugin logo" , Toast.LENGTH_SHORT).show();
}
});
Expand All @@ -264,6 +268,66 @@ public void onClick(View v) {
}
});

findViewById(R.id.button_add_hotspot_front).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MDHotspotBuilder builder = MDHotspotBuilder.create(mImageLoadProvider)
.size(4f,4f)
.provider(activity, R.drawable.moredoo_logo)
.title("front logo")
.tag("tag-front")
.position(MDPosition.newInstance().setZ(-12.0f).setY(-1.0f));
MDAbsHotspot hotspot = new MDSimpleHotspot(builder);
hotspot.rotateToCamera();
plugins.add(hotspot);
getVRLibrary().addPlugin(hotspot);
}
});

findViewById(R.id.button_rotate_to_camera_plugin).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IMDHotspot hotspot = getVRLibrary().findHotspotByTag("tag-front");
if (hotspot != null){
hotspot.rotateToCamera();
}
}
});

findViewById(R.id.button_add_md_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView textView = new TextView(activity);
textView.setBackgroundColor(0x55FFCC11);
textView.setText("Hello world.");

MDViewBuilder builder = MDViewBuilder.create()
.provider(textView, 400/*view width*/, 100/*view height*/)
.size(4, 1)
.position(MDPosition.newInstance().setZ(-12.0f))
.title("md view")
.tag("tag-md-text-view")
;

MDAbsView mdView = new MDView(builder);
plugins.add(mdView);
getVRLibrary().addPlugin(mdView);
}
});

findViewById(R.id.button_update_md_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MDAbsView mdView = getVRLibrary().findViewByTag("tag-md-text-view");
if (mdView != null){
TextView textView = mdView.castAttachedView(TextView.class);
textView.setText("Cheer up!");
textView.setBackgroundColor(0x8800FF00);
mdView.invalidate();
}
}
});

final TextView hotspotText = (TextView) findViewById(R.id.hotspot_text);
getVRLibrary().setEyePickChangedListener(new MDVRLibrary.IEyePickListener() {
@Override
Expand Down Expand Up @@ -324,6 +388,7 @@ public void busy(){
findViewById(R.id.progress).setVisibility(View.VISIBLE);
}

// android impl
private class AndroidProvider implements MDVRLibrary.IImageLoadProvider {

Activity activity;
Expand All @@ -334,8 +399,6 @@ public AndroidProvider(Activity activity) {

@Override
public void onProvideBitmap(Uri uri, MD360BitmapTexture.Callback callback) {
//BitmapFactory.decodeStream()

try {
Bitmap bitmap = BitmapFactory.decodeStream(activity.getContentResolver().openInputStream(uri));
callback.texture(bitmap);
Expand All @@ -346,13 +409,16 @@ public void onProvideBitmap(Uri uri, MD360BitmapTexture.Callback callback) {
}
}

// picasso impl
private class ImageLoadProvider implements MDVRLibrary.IImageLoadProvider{

private SimpleArrayMap<Uri,Target> targetMap = new SimpleArrayMap<>();

@Override
public void onProvideBitmap(final Uri uri, final MD360BitmapTexture.Callback callback) {

final Target target = new Target() {

@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// texture
Expand All @@ -371,8 +437,7 @@ public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
targetMap.put(uri, target);
Picasso.with(getApplicationContext()).load(uri).resize(3072,2048).centerInside().memoryPolicy(NO_CACHE, NO_STORE).into(target);

Picasso.with(getApplicationContext()).load(uri).resize(callback.getMaxTextureSize(),callback.getMaxTextureSize()).onlyScaleDown().centerInside().memoryPolicy(NO_CACHE, NO_STORE).into(target);
}
}
}
61 changes: 61 additions & 0 deletions app/src/main/res/layout/activity_md_using_surface_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,75 @@
android:background="@drawable/selector_button_background"
android:layout_width="wrap_content"
android:layout_height="42dp" />

</LinearLayout>

<LinearLayout
android:id="@+id/plugin_layout2"
android:layout_below="@id/plugin_layout"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button_add_hotspot_front"
android:textSize="13sp"
android:textColor="@android:color/white"
android:text="AddHotspotFront"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:includeFontPadding="false"
android:background="@drawable/selector_button_background"
android:layout_width="wrap_content"
android:layout_height="42dp" />

<Button
android:id="@+id/button_rotate_to_camera_plugin"
android:textSize="13sp"
android:textColor="@android:color/white"
android:layout_marginLeft="8dp"
android:text="RotateToCamera"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:includeFontPadding="false"
android:background="@drawable/selector_button_background"
android:layout_width="wrap_content"
android:layout_height="42dp" />

<Button
android:id="@+id/button_add_md_view"
android:textSize="13sp"
android:textColor="@android:color/white"
android:layout_marginLeft="8dp"
android:text="add MDView"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:includeFontPadding="false"
android:background="@drawable/selector_button_background"
android:layout_width="wrap_content"
android:layout_height="42dp" />

<Button
android:id="@+id/button_update_md_view"
android:textSize="13sp"
android:textColor="@android:color/white"
android:layout_marginLeft="8dp"
android:text="update MDView"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:includeFontPadding="false"
android:background="@drawable/selector_button_background"
android:layout_width="wrap_content"
android:layout_height="42dp" />

</LinearLayout>

<LinearLayout
android:layout_below="@id/plugin_layout2"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/control_next"
android:text="next"
Expand Down
Loading

0 comments on commit 04aaa7f

Please sign in to comment.