Moving out camera view in Activity - android

I have an activity with toolbar at the bottom of the screen. Toolbar has a camera button. When user clicks the button, there must appear camera view. It must appear from the bottom of this activity, under the toolbar, fill up to 1/3 of the screen. I created SurfaceView for the camera. But can't set it below the toolbar because of
alignParentBottom="true"
How to do this appearance?
Here are my layouts
<SurfaceView
android:id="#+id/camera_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f4f5f7">
<ImageButton
android:id="#+id/btn_camera"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#f4f5f7"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/camera59" />
...
</RelativeLayout>

Solved it using animated LinearLayout.
Camera_Activity.class
public class Camera_Activity extends AppCompatActivity {
ImageButton btn_camera;
ImageButton btn_mic;
SurfaceView sv;
LinearLayout show_video;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.anim_footer);
show_video = (LinearLayout) findViewById(R.id.show_video);
btn_camera = (ImageButton) findViewById(R.id.btn_camera);
btn_mic = (ImageButton) findViewById(R.id.btn_mic);
sv = (SurfaceView) findViewById(R.id.camera_view);
btn_camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (sv.getVisibility() == View.GONE) {
sv.setVisibility(View.VISIBLE);
final Animation show = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.show_video);
show_video.startAnimation(show);
}
}
});
btn_mic.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (sv.getVisibility() == View.VISIBLE) {
final Animation hide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.hide_video);
hide.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
sv.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
show_video.startAnimation(hide);
}
}
});
}
}
anim_footer.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parent"
android:background="#drawable/gradient"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<LinearLayout
android:id="#+id/show_video"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80000000">
<ImageButton
android:id="#+id/btn_camera"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/btn_mic"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#android:drawable/ic_delete" />
<ImageButton
android:id="#+id/btn_cat"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toLeftOf="#id/btn_mic"
android:layout_toStartOf="#id/btn_mic"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#android:drawable/ic_lock_lock" />
</RelativeLayout>
<SurfaceView
android:visibility="gone"
android:background="#drawable/photo"
android:id="#+id/camera_view"
android:layout_width="match_parent"
android:layout_height="300dp" />
</LinearLayout>
</RelativeLayout>
Animations:
show_video.xml
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:interpolator/accelerate_cubic"
android:startOffset="150"
android:fromYDelta="86%"
android:toYDelta="0"
android:fillAfter="true"
android:duration="2000"/>
hide_video.xml
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:interpolator/bounce"
android:fromYDelta="0"
android:toYDelta="85%"
android:duration="1500"/>

Related

Android click listener on View work in strange manner

I have the following layout.xml containing one ScrollView with some elements(picture and text)
<?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"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/clickable"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:src="#drawable/crown" />
<TextView
android:id="#+id/n1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="some text" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:src="#drawable/medal" />
<TextView
android:id="#+id/n2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="some text" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:src="#drawable/star" />
<TextView
android:id="#+id/n3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="some text" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity{
LayoutInflater inflater;
RelativeLayout MyLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inflater = LayoutInflater.from(this);
MyLayout = (RelativeLayout) inflater.inflate(R.id.layout, null, false);
MyLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("TAG"," I'm clicked! ");
}
});
Click Listener above does not work when I click screen!!!
But if I change code to this - everything is working
MyLayout.findViewById(R.id.clickable).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("TAG"," I'm clicked! ");
}
});
So why should I set click listener to LinearLayout inside ScrollView inside parent RelativeLayout?
Why click listener does not work for root xml element RelativeLayout???
The problem is that your ScrollView is intercepting the touch events and not propagating them to parent layouts (in this case your RelativeLayout).
This thread might have some useful information about this topic.
Just add android:clickable="false" in your ScrollView. Then change your MainActivity like below:
public class MainActivity extends Activity {
LinearLayout myLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myLayout = (LinearLayout) findViewById(R.id.layout);
myLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("TAG"," I'm clicked! ");
}
});
}
}
Note: activity_main.xml is xml file which you are loading.
Now your OnClick will work as expected.

View animation only working second time

I'm trying to make an ImageButton slide up and out and then have another set of buttons slide in it's place, my problem is that the second buttons don't "slide" in the first time, only from the second and onward. I tried setting the button containers Visibility to invisible instead of gone, but it had no effect of the animation and just split the buttons to the top and bottom of the parent view.
xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:id="#+id/user_email_show"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:background="#ffffff"
android:onClick="showEmail"
app:srcCompat="#drawable/logo_email" />+
<LinearLayout
android:id="#+id/user_email_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageButton
android:id="#+id/user_email_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFF"
android:onClick="addEmail"
android:visibility="gone"
app:srcCompat="#drawable/ic_add" />
<TextView
android:id="#+id/user_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<LinearLayout
android:id="#+id/user_email_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
<ImageButton
android:id="#+id/user_email_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFF"
android:onClick="editEmail"
app:srcCompat="#drawable/ic_edit" />
<ImageButton
android:id="#+id/user_email_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFF"
android:tint="#a7a7a7"
app:srcCompat="#drawable/ic_delete" />
</LinearLayout>
<ImageButton
android:id="#+id/user_email_hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:onClick="hideEmail"
android:tint="#a7a7a7"
android:padding="15dp"
android:visibility="gone"
app:srcCompat="#drawable/ic_cancel" />
</LinearLayout>
</LinearLayout>
Show animation method
public void showEmail(View view) {
findViewById(R.id.user_email_hide).setVisibility(View.VISIBLE);
if (emailCheck == true) {
emailTextView.setVisibility(View.VISIBLE);
emailInput.setVisibility(View.VISIBLE);
} else {
addEmail.setVisibility(View.VISIBLE);
}
final Animation slide_up_in = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up_in);
Animation slide_up_out = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up_out);
showEmail.startAnimation(slide_up);
slide_up_out.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
showEmail.setVisibility(View.GONE);
emailContainer.setVisibility(View.VISIBLE);
emailContainer.setAnimation(slide_up_in);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
}
animation file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="1000"
android:fromYDelta="150%"
android:toYDelta="0" />
</set>

Android Animation disabled EditText

i add the Bounce effect to Linear layout.This linear layout contain 2 EditTexts and one button.but when animation complete Edittexts and Button are Disabled.I cant use them.how can i enable Edittexts and Button.
XML
<LinearLayout android:background="#drawable/login_grd" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="50dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:textSize="55sp"
android:gravity="center"
android:layout_gravity="center"
android:textColor="#fff"
android:id="#+id/_title"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AFF"/>
<Button
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="200dp"
android:textColor="#000"
android:background="#fff"
android:id="#+id/animloginButton"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Login"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="480dp"
android:background="#color/white"
android:id="#+id/lnr_do_login"
android:layout_marginTop="280dp">
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel2"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:id="#+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:textSize="16sp"
android:textColor="#color/black"
android:id="#+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel2"
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<EditText
android:textSize="16sp"
android:textColor="#color/black"
android:inputType="textPassword"
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password" />
</android.support.design.widget.TextInputLayout>
<Button
android:textColor="#000"
android:background="#fff"
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Sign In"/>
</LinearLayout>
<TextView
android:textColor="#color/white"
android:layout_gravity="bottom|right"
android:gravity="bottom|center"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="#string/app_name"
android:layout_marginBottom="10dp" />
</LinearLayout>
</LinearLayout>
LoginActivity.class
private LinearLayout lnrLoginView;
#Override
public void onCreate(Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(R.layout.before_login_screen);
animloginButton = (Button) findViewById(R.id.animloginButton);
lnrLoginView = (LinearLayout) findViewById(R.id.lnr_do_login);
TextView title = (TextView) findViewById(R.id._title);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/title_font.ttf");
title.setTypeface(type);
animloginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
lnrLoginView.clearAnimation();
TranslateAnimation translation;
translation = new TranslateAnimation(0f, 0F, 0f, -getDisplayHeight());
translation.setStartOffset(10);
translation.setDuration(1000);
translation.setFillAfter(true);
translation.setInterpolator(new BounceInterpolator());
lnrLoginView.startAnimation(translation);
animloginButton.setVisibility(View.INVISIBLE);
}
private int getDisplayHeight() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics.widthPixels;
}
});
}
Try to use ObjectAnimator.onFloat instead.
animloginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(lnrLoginView.getTag() instanceof Animator){
((Animator)lnrLoginView.getTag()).cancel();
}
ObjectAnimator translateY = ObjectAnimator
.ofFloat(target, "translationY", -transY)
.setDuration(1000)
;
translateY.setStartDelay(10);
translateY.setTarget(lnrLoginView);
translateY.setInterpolator(new BounceInterpolator());
translateY.start();
animloginButton.setVisibility(View.INVISIBLE);
}
private int getDisplayHeight() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics.widthPixels;
}
});
Use a animation listener to malipulate your views before and after the animation.
translation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
//Disable the views.
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
//Enable the views
}
});

increase the height of view while animating to the top

I have three views 1)Toolbar 2)Edittext and Recyclerview. Now on click on edittext i want to animate the toolbar to the top(out of screen generally) up along with edittext and recyclerview .The animation works fine but the problems is that the recycler view is not taking the full height.The recycler view is moved to the top but also recyclerview is not taking the full height
XMl
<?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="#fff">
<include
android:id="#+id/tb_explore"
layout="#layout/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></include>
<LinearLayout
android:id="#+id/ll_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tb_explore"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:layout_marginTop="07dp"
android:focusable="false"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/et_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imageView11"
android:layout_toStartOf="#+id/imageView11"
android:background="#android:color/transparent"
android:hint="Search by vendor name or keyword"
android:padding="10dp"
android:imeOptions="actionGo"
android:singleLine="true"
android:textSize="#dimen/regular" />
<TextView
android:id="#+id/tv_cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="center"
android:text="Cancel"
android:visibility="gone" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_explore_search"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_below="#+id/ll_search"
android:layout_marginTop="10dp"
android:background="#efd3d3"
android:visibility="visible" />
Code
rlHeader.animate()
.translationY(-rlHeader.getHeight());
llSearch.animate()
.translationY(-rlHeader.getHeight())
.setListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
rvExplore.getLayoutParams().height = rvExplore.getHeight() + rlHeader.getHeight(); //here i am increasing the height but no use
rvExplore.animate().translationY(-rlHeader.getHeight());
}
#Override
public void onAnimationEnd(Animator animation) {
etSearch.requestFocus();
tvCancel.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationCancel(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
}
});

Changing views with ViewFlipper Android

I need a little help.I'm using a ViewFlipper to change views in TabActivity but not really sure how to do it.Here is my code :
MainActivity.class
public class Collections extends Activity implements OnClickListener {
ViewFlipper vFlip;
Button genre, recommended, soon;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.collections_layout);
vFlip = (ViewFlipper) findViewById(R.id.tags_flipper);
genre = (Button) findViewById(R.id.genre_btn);
genre.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
recommended = (Button) findViewById(R.id.recom_btn);
recommended.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
soon = (Button) findViewById(R.id.soon_btn);
soon.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
}
}
I have three different xml, which I want to load with clicking the buttons.Here is the collection_layout.xml
Collection_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/actionbar"
android:layout_width="fill_parent"
android:layout_height="65px"
android:background="#drawable/pink_bar"
android:tileMode="repeat"
android:orientation="vertical">
<ImageView
android:src="#drawable/stampii_logo"
android:id="#+id/stampii_logo_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20px"/>
</LinearLayout>
<LinearLayout
android:id="#+id/first_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:background="#d229ce">
<Button
android:id="#+id/genre_btn"
android:text="By Genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/recom_btn"
android:text="Recommended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/soon_btn"
android:text="Expect Soon!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/flip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<ViewFlipper
android:id="#+id/tags_flipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include android:id="#+id/genre" layout="#layout/by_genre" />
<include android:id="#+id/recom" layout="#layout/recommended" />
<include android:id="#+id/soon" layout="#layout/expect_soon" />
</ViewFlipper>
</LinearLayout>
</LinearLayout>
So how can i do that?Thanks a lot!
Use ViewFlipper.setDisplayedChild

Categories

Resources