Android content of ViewGroup disappears when rotationY is animated - android

I created an animation that flips a "card" to its backside.
To achieve this, I used setRotationYBy() and setVisibility() on each, the front, and the back.
The animation itself works fine, but when the animation is running, the content of both cards disappears (and reappears when the animation is finished).
cardFront.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final Runnable moveMapDown = new Runnable() {
public void run() {
map.animate().y(0);
}
};
final Runnable flipCard2 = new Runnable() {
public void run() {
cardBack.setVisibility(View.VISIBLE);
cardFront.setVisibility(View.INVISIBLE);
currentFront = false;
CardBack.animate().rotationYBy(90).setInterpolator
(new DecelerateInterpolator()).withEndAction(moveMapDown).setDuration(300);
cardFront.setRotationY(180);
}
};
Runnable flipCard = new Runnable() {
public void run() {
cardBack.setRotationY(-90);
cardFront.animate().rotationYBy(90).setInterpolator
(new AccelerateInterpolator()).withEndAction(flipCard2).setDuration(300);
}
};
map.animate().y(-200).withEndAction(flipCard);
}
});
XML-Layout of the backside (front almost the same).
<RelativeLayout
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginTop="-18dp"
android:background="#drawable/bgpatch"
android:paddingBottom="16dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="6dp"
android:visibility="invisible" >
<RelativeLayout
android:layout_width="300dp"
android:layout_height="288dp"
android:background="#drawable/dayplan_element_bg" >
<RelativeLayout
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/dayplan_element_bg"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp" >
<TextView
android:id="#+id/backTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="zusätzliche Informationen"
android:textAppearance="?android:textAppearanceLarge"
android:textColor="#android:color/primary_text_dark"
android:textSize="30sp"
android:textStyle="italic" />
</RelativeLayout>
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-1dp"
android:background="#drawable/shadow" />
</RelativeLayout>
</RelativeLayout>

Found the solution:
I had hardware-acceleration set to false due to another part of the app that requires this.
Set it back to true and it works!

Related

Displaying Elements with a delay

How to make a delay on displaying elements in android studio i have 2 ImageView
<ImageView
android:id="#+id/a_letter"
android:background="#00000000"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"
app:srcCompat="#drawable/a_letter"
/>
AND
<ImageView
android:id="#+id/b_letter"
android:background="#00000000"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"
app:srcCompat="#drawable/b_letter"
/>
how to make the ImageView with the ID of a_letter load first when the layout is opened then make a 3 seconds delay before the ImageView with the ID of b_letter displayed?
is this a transition?
First make your image view gone in xml by adding:
<ImageView
android:id="#+id/b_letter"
android:background="#00000000"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"
app:srcCompat="#drawable/b_letter"
android:visibility="gone"/>
and then use a Handler:
ImageView bImageView = (ImageView) findViewById(R.id.b_letter);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
bImageView.setVisibility(View.VISIBLE);
}
}, 3000);

Overlaying youtube Api Videos in View Pager

My multiple youtube videos in viewPager overlaying itself and youtubePlayer stops after one second recording. My first video works fine, but whenever I slide to another or back to previous one and try to record it I give an overlaying error. I try to set the videoContainer to gone, release the youtube player, bringToFront() current videoContainer, hide/show detach/attach videoFragment and the problem still remains.The detach/attach fragment solution works but not every time.
My warn message: YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.widget.LinearLayout{54f27e3 V.E...... ........ 0,0-1080,1584 #7f1000ec app:id/globalViewLinearLayout}. Right edge 50 px right of YouTubePlayerView's left edge.
My FragmentViewPagerItemXML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/globalViewLinearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundContent">
<com.app.CustomScrollView
android:id="#+id/customScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollViewLinearLayout">
<FrameLayout
android:id="#+id/mediaContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_marginBottom="80dp"
android:visibility="gone"
android:id="#+id/videoContainerLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/videoContainer"
android:orientation="vertical" />
</LinearLayout>
<RelativeLayout
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="#dimen/imageHeight"
android:id="#+id/galleryContainer"
android:layout_marginBottom="55dp">
<ProgressBar
android:id="#+id/progress"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:id="#+id/photoWithButtonsContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#color/black">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/themePhoto"
android:clickable="true"
android:adjustViewBounds="true"
android:padding="10dp"
android:background="#android:color/white"
android:layout_centerInParent="true"
android:visibility="gone" />
<ImageButton
android:layout_alignRight="#+id/themePhoto"
android:layout_alignTop="#+id/themePhoto"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_margin="8dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#drawable/expand"
android:id="#+id/zoomMe"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_gravity="bottom|right"
android:id="#+id/buttonLinearLayout">
<android.support.design.widget.FloatingActionButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/playButton"
android:src="#drawable/ic_play_arrow_black_48dp"
app:backgroundTint="#color/white"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:visibility="gone" />
<android.support.design.widget.FloatingActionButton
app:backgroundTint="#color/white"
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/videoButton"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:src="#drawable/ic_ondemand_video_black_48dp"
android:visibility="gone" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_height="85dp"
android:background="#drawable/ribbon"
android:id="#+id/artWorkCounter"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
</FrameLayout>
Code:
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
videoContainer = (LinearLayout) view.findViewById(R.id.videoContainerLayout);
mYouTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
return view;
}
viewHolder.videoButton = (FloatingActionButton) view.findViewById(R.id.videoButton);
viewHolder.videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view1) {
if (view.findViewById(R.id.videoContainer).isShown()) {
animateFab(false);
videoContainer.setVisibility(View.GONE);
} else {
if (context instanceof TestActivity)
((TestActivity) context).setAutoOrientationEnabled(true);
youTubeVideoInit(artWork.getVideo_uri(), view);
animateFab(true);
}
}
});
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (viewHolder != null) {
if (!isVisibleToUser ) {
isVisible = false;
if (videoContainer != null)
if (videoContainer.isShown()) {
viewHolder.videoButton.performClick();
}
if(mYouTubePlayerFragment!=null)
getChildFragmentManager().beginTransaction().detach(mYouTubePlayerFragment).commitAllowingStateLoss();
} else {
if(mYouTubePlayerFragment!=null)
getChildFragmentManager().beginTransaction().attach(mYouTubePlayerFragment).commitAllowingStateLoss();
isVisible = true;
}
}
}
YouTubePlayer mPlayer;
YouTubePlayerSupportFragment mYouTubePlayerFragment;
String youtubeID;
LinearLayout videoContainer;
public void youTubeVideoInit(String youtubeUrl, final View view) {
final String API_KEY = getString(R.string.develop_key);
Uri uri = Uri.parse(youtubeUrl);
try {
youtubeID = URLDecoder.decode(uri.getQueryParameter("v"), "UTF-8");
} catch (UnsupportedEncodingException exception) {
exception.printStackTrace();
}
mYouTubePlayerFragment.initialize(API_KEY, new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean isRejected) {
if (!isRejected) {
mPlayer = youTubePlayer;
mPlayer.cueVideo(youtubeID);
mPlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
#Override
public void onFullscreen(boolean b) {
if (!b && context instanceof TestActivity){
((TestActivity) context).setPortraitOrientation();
((TestActivity) context).setAutoOrientationEnabled(true);
}
}
});
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
getChildFragmentManager().beginTransaction().replace(R.id.videoContainer, mYouTubePlayerFragment, YouTubePlayerFragment.class.getSimpleName()).commit();
videoContainer.setVisibility(View.VISIBLE);
}
EDIT: I found what is the problem: The Zoom-out page transformer overlays the videos.

Animating when re-positioning a view

As you can see in the attached code, linearLayoutLogo contains a ProgressBar and TextView and linearLayoutReading contains an ImageView and TextView. When linearLayoutReading is made visible the the two layouts reposition themselves around the center point due to android:layout_centerInParent="true".
How can I animate linearLayoutLogo so it shifts upwards to its new position prior to linearLayoutReading becoming visible? Please see the attached video for an example.
activity_main.xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:gravity="center">
<LinearLayout
android:id="#+id/linearLayoutLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/imageViewRLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_accessibility_black_24dp"
android:padding="8dp"/>
<TextView
android:id="#+id/textViewAppTitle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="34sp"
android:textColor="#CCFFFFFF"
android:text="AppName"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutReading"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Base.TextAppearance.AppCompat.Large"
android:text="Reading from device"
android:textColor="#BF000000" />
<ProgressBar
android:id="#+id/progressBarSplash"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
style="#style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:paddingBottom="8dp"/>
</LinearLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
public ProgressBar progressBarSplash;
public LinearLayout linearLayoutReading;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayoutReading = (LinearLayout)findViewById(R.id.linearLayoutReading);
linearLayoutReading.setVisibility(View.GONE);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
linearLayoutReading.setVisibility(View.VISIBLE);
progressBarSplash = (ProgressBar)findViewById(R.id.progressBarSplash);
progressBarSplash.setEnabled(true);
progressBarSplash.setIndeterminate(true);
}
}.start();
}
}
Tested it out on Android Studio. Just include android:animateLayoutChanges="true" in the top most LinearLayout (the one with centerInParent element).

Android allow multi-touch on an activity

I am trying to allow the user to put a ring on the circle on the screen and then press the larger button so that the circle goes to the next ring size.
Everything work fines when no ring is on the screen.
However when a ring it on the screen no other touches are called and the buttons and the seekbar does not work.
I'm new in android and i haven't came across this requirement before. Is there a way I can allow multi-touch gestures on the activity or a way to ignore touches on that specific layout?
XML File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:splitMotionEvents="false"
>
<TextView
android:id="#+id/us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<TextView
android:id="#+id/uklbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="UK Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<TextView
android:id="#+id/uk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/uklbl"
android:layout_alignBottom="#+id/uklbl"
android:layout_toRightOf="#+id/uklbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<ImageView
android:id="#+id/ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/uslbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/uk"
android:gravity="left"
android:padding="#dimen/standard_margin"
android:text="US Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<SeekBar
android:id="#+id/seekbar"
android:progressDrawable="#drawable/red_scrubber_progress"
android:thumb="#drawable/red_scrubber_control"
android:max="8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/divider" />
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uklbl"
android:layout_marginTop="18dp"
android:background="#color/pressed_gemporia" />
<TextView
android:id="#+id/sizes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="#dimen/standard_margin"
android:layout_below="#+id/seekbar"
android:text="TextView" android:textColor="#color/pressed_gemporia" />
<Button
android:id="#+id/right"
android:layout_width="100dp"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:background="#color/White"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/left"
android:text="Larger" />
<Button
android:id="#+id/left"
android:layout_width="100dp"
android:background="#color/White"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Smaller" />
<ImageView
android:id="#+id/ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ci"
android:layout_centerHorizontal="true"
android:src="#drawable/j" />
Java Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ring_sizes);
left = (Button)findViewById(R.id.left);
right = (Button)findViewById(R.id.right);
us = (TextView) findViewById(R.id.us);
uk = (TextView) findViewById(R.id.uk);
ci = (ImageView)findViewById(R.id.ci);
ring = (ImageView)findViewById(R.id.ring);
sizes.add(R.drawable.j);
sizes.add(R.drawable.l);
sizes.add(R.drawable.n);
sizes.add(R.drawable.p);
sizes.add(R.drawable.r);
sizes.add(R.drawable.t);
sizes.add(R.drawable.v);
sizes.add(R.drawable.x);
sizes.add(R.drawable.z);
USsizes.add("5");
USsizes.add("6");
USsizes.add("7");
USsizes.add("8");
USsizes.add("9");
USsizes.add("10");
USsizes.add("11");
USsizes.add("12");
USsizes.add("13");
UKsizes.add("J-K");
UKsizes.add("L-M");
UKsizes.add("N-O");
UKsizes.add("P-Q");
UKsizes.add("R-S");
UKsizes.add("T-U");
UKsizes.add("V-W");
UKsizes.add("X-Y");
UKsizes.add("Z+");
color = (getBaseContext().getResources().getColor(R.color.pressed_gemporia));
value = (TextView) findViewById(R.id.sizes);
seekbar = (SeekBar) findViewById(R.id.seekbar);
seekbar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
value.setText("UK Size : "+UKsizes.get(0) + " - US Size: " + USsizes.get(0));
setUpViews();
seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
ring.setImageResource(sizes.get(progress));
us.setText(USsizes.get(progress));
uk.setText(UKsizes.get(progress));
counter=progress;
value.setText("UK Size : "+UKsizes.get(progress) + " - US Size: " + USsizes.get(progress));
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
}
public void setUpViews(){
ring.setImageResource(sizes.get(counter));
us.setText(USsizes.get(counter));
uk.setText(UKsizes.get(counter));
right.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(UKsizes.size()>counter+1){
ring.setImageResource(sizes.get(counter+1));
seekbar.setProgress(counter+1);
}
}
});
left.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(counter!=0){
ring.setImageResource(sizes.get(counter));
seekbar.setProgress(counter-1);
} }
});
}
}
There is a way to ignore touches in particular layout,for that you should add
android:splitMotionEvents="false"
in your layout . You can refer answers from thie following link
https://stackoverflow.com/questions/12777435/disable-multi-finger-touch-in-my-app

How to create a Button in the camera view in vuforia?

I am using Vuforia AR sdk and want to create a button on the camera preview on the screen.
I cannot figure out where and how to add the button.
I have edit the camera_overlay_udt.xml like this.. In my layout design i have placed back button and listview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:src="#drawable/back" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Swipart"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/arcstarButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"
android:src="#drawable/star_button" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/favListingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:gravity="top"
android:orientation="horizontal"
android:visibility="visible" >
<ListView
android:id="#+id/favlist"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:layout_marginLeft="7dp"
android:cacheColorHint="#00000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#color/overlay_bottom_bar_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1" >
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/overlay_bottom_bar_separators" />
<ImageButton
android:id="#+id/camera_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:contentDescription="#string/content_desc_camera_button"
android:onClick="onCameraClick"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/camera_button_background" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/bottom_bar"
android:background="#color/overlay_bottom_bar_separators" />
</RelativeLayout>
after that please Edit that ImageTargets.java class
private void addOverlayView(boolean initLayout) {
// Inflates the Overlay Layout to be displayed above the Camera View
LayoutInflater inflater = LayoutInflater.from(this);
mUILayouts = (RelativeLayout) inflater.inflate(
R.layout.camera_overlay_udt, null, false);
mUILayouts.setVisibility(View.VISIBLE);
// If this is the first time that the application runs then the
// uiLayout background is set to BLACK color, will be set to
// transparent once the SDK is initialized and camera ready to draw
if (initLayout) {
mUILayouts.setBackgroundColor(Color.TRANSPARENT);
}
// Adds the inflated layout to the view
addContentView(mUILayouts, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Gets a reference to the bottom navigation bar
mBottomBar = mUILayouts.findViewById(R.id.bottom_bar);
// Gets a reference to the Camera button
mCameraButton = mUILayouts.findViewById(R.id.camera_button);
mCameraButton.setVisibility(View.GONE);
favButton = (ImageButton) mUILayouts.findViewById(R.id.arcstarButton);
listview = (ListView) mUILayouts.findViewById(R.id.favlist);
backButton = (ImageButton) mUILayouts.findViewById(R.id.backButton);
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
finish();
}
});
listview.setVisibility(View.GONE);
galleryList = SendFile.getFavourites();
if (galleryList != null) {
gridviewAdapter = new GridviewAdapter(ImageTargets.this);
listview.setAdapter(gridviewAdapter);
}
favButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (galleryList != null && galleryList.size() > 0) {
if (listview.getVisibility() == View.GONE) {
listview.setVisibility(View.VISIBLE);
} else {
listview.setVisibility(View.GONE);
}
} else {
Toast.makeText(ImageTargets.this, "Favourites not fond",
Toast.LENGTH_LONG).show();
}
}
});
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paramAdapterView,
View paramView, int positon, long paramLong) {
SendFile.setFavourite(galleryList.get(positon));
Intent intent = new Intent(ImageTargets.this,
LoadingScreen.class);
Bundle bundle = new Bundle();
bundle.putInt("x", x_Axis);
bundle.putInt("y", y_Axis);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
});
showDialogHandler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Server Response: " + aResponse, Toast.LENGTH_SHORT)
.show();
showAlertDialog(aResponse);
} else {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Not Got Response From Server.", Toast.LENGTH_SHORT)
.show();
}
};
};
loadingDialogHandler.captureButtonContainer = mUILayouts
.findViewById(R.id.camera_button);
mUILayouts.bringToFront();
}
They showing there layouts using handlers
Start you camera preview in a normal way. Place a layout on top of it with transparent background like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ff000000"
android:layout_height="match_parent">
<ImageView
android:id="#+id/start_image_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:src="#drawable/scan_image"/>
</RelativeLayout>
In java file, you can add this layout like this:
private View mStartupView;
mStartupView = getLayoutInflater().inflate(
R.layout.startup_screen, null);
// Add it to the content view:
addContentView(mStartupView, new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
This way you will get to see your button on top of camera preview. Hope it helps
You can add buttons in cameraoverlay layout which is in layout folder and you can initialize buttons in initAR function which is in mainactivity.
Step 1: Add the button in the camera_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
style="#android:style/Widget.ProgressBar"
android:id="#+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="51dp"
android:text="Button" />
</RelativeLayout>
Step 2: Edit the ImageTargets.java class
private static final String LOGTAG = "ImageTargets";
private Button b1;
Step 3: Modify the initApplicationAR() function of ImageTargets.java class
private void initApplicationAR()
{
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = Vuforia.requiresAlpha();
mGlView = new SampleApplicationGLView(this);
mGlView.init(translucent, depthSize, stencilSize);
mRenderer = new ImageTargetRenderer(this, vuforiaAppSession);
mRenderer.setTextures(mTextures);
mGlView.setRenderer(mRenderer);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
b1.setVisibility(View.GONE);
}
});
}
Now lay back and watch your button disappear on a click!
Although it's a long time since the post.. yet I found one article.. wherein you can have the desired thing..
Ref: https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82
Solution:
Step1: Make a custom layout XML file (vuforia_widget_screen.xml). For example, button has been added.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<FrameLayout
android:id="#+id/unity_player_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:text="#string/welcome" />
</FrameLayout>
Step 2: Make following changes in the UnityPlayerActivity.java
Replace "setContentView(mUnityPlayer);" with
setContentView(R.layout.vuforia_widget_screen);
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.addView(mUnityPlayer.getView());
-> For anyone, who will face the issue in future. :)

Categories

Resources