How could I change this dependency for Android custom shadow view? - java

I was using the following dependency, but I am not going to use it anymore as I have noticed that it is deprecated: dependency I was using
As you can see, the About of this depencency, says the following:
Deprecated because of the performance not fine. Android custom shadow
view, can replace your CardView
I am trying to replace what I was using from that dependency for the Android custom shadow view as the dependency About says, but I don´t know how could I do it.
This is what I was using:
<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="14dp"
android:layout_marginEnd="14dp"
android:layout_weight="1"
android:elevation="#dimen/shel"
app:cornerRadiusTL="#dimen/hol"
app:cornerRadiusTR="#dimen/car"
app:shadowMarginLeft="#dimen/shadow"
app:shadowMarginRight="#dimen/margn"
app:shadowRadius="#dimen/radius">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/sign_stp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="6dp"
android:text="#string/sign"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/red" />
</LinearLayout>
</LinearLayout>
</com.loopeer.shadow.ShadowView>
Also I had made the following function to show card view:
public void showCardView() {
Animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
LinearLayout.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
LinearLayout.startAnimation(Animation);
}
In the main.activity.java the above function is run:
showCardView();

Related

How to implement Android custom shadow view?

I was using one dependency that was working fine, I have seen that it is deprecated, so I am not going to use it more, this was the dependency:dependency I was using
If you see, the About of this depencency, says the following:
Deprecated because of the performance not fine. Android custom shadow
view, can replace your CardView
I am trying to replace what I was using from that dependency for the Android custom shadow view as the dependency About says, but I don´t know how could I do it.
This is what I was using:
<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="14dp"
android:layout_marginEnd="14dp"
android:layout_weight="1"
android:elevation="#dimen/shel"
app:cornerRadiusTL="#dimen/hol"
app:cornerRadiusTR="#dimen/car"
app:shadowMarginLeft="#dimen/shadow"
app:shadowMarginRight="#dimen/margn"
app:shadowRadius="#dimen/radius">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/sign_stp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="6dp"
android:text="#string/sign"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/red" />
</LinearLayout>
</LinearLayout>
</com.loopeer.shadow.ShadowView>
Also I had made the following function to show card view:
public void showCardView() {
Animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
LinearLayout.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
LinearLayout.startAnimation(Animation);
}
In the main.activity.java the above function is run:
showCardView();

How to disable scrolling ViewPager while keyboard is shown?

I'm developing an app and use ViewPager inside it. It scrolls fragments, one of which contains the text input field. So the problem is the following: while the keyboard is showing I still can scroll fragments. have anybody met the same problem?
This is my Main Activity code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/activity_main"
tools:context=".activities.MainActivity">
<androidx.viewpager.widget.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/navigation"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:itemBackground="#color/bgBottomNavigation"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/navigation" />
</RelativeLayout>
And this is the fragment code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.Login">
<ImageView
android:id="#+id/loginLogo"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="#mipmap/logo_foreground"
tools:ignore="ContentDescription" />
<EditText
android:id="#+id/loginUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textPersonName"
android:layout_margin="10dp"
android:layout_below="#+id/loginLogo"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/loginPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textPassword"
android:layout_margin="10dp"
android:layout_below="#+id/loginUsername"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginPassword"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="Войти" />
Well, the problem was solved the next way: I just created a little function to hide the keyboard
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
And then used the listener of ViewPager:
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
hideKeyboard(activity);
}
#Override
public void onPageSelected(int position) {
if (prevMenuItem != null)
prevMenuItem.setChecked(false);
else
navigation.getMenu().getItem(0).setChecked(false);
navigation.getMenu().getItem(position).setChecked(true);
prevMenuItem = navigation.getMenu().getItem(position);
}
#Override
public void onPageScrollStateChanged(int state) {
}
});

Moving a view from a viewgroup to another one

activity_main.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:longClickable="false"
android:orientation="vertical"
android:weightSum="16"
android:animateLayoutChanges="true">
<LinearLayout
android:id="#+id/ly_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="#drawable/item_background"
android:text="Indonesia"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="#drawable/item_background"
android:text="English"/>
</LinearLayout>
<LinearLayout
android:id="#+id/ly_ll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="#drawable/item_background"
android:text="Spain"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="#drawable/item_background"
android:text="Brazil"/>
</LinearLayout>
</LinearLayout>
MainActivity.java:
public class MainActivity extends Activity {
LinearLayout llLayout;
LinearLayout llLayout2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
llLayout = (LinearLayout) findViewById(R.id.ly_ll);
llLayout2 = (LinearLayout) findViewById(R.id.ly_ll2);
for(int i=0;i<llLayout2.getChildCount();i++){
View views = llLayout2.getChildAt(i);
views.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addedViewTarget(v);
}
});
}
}
public void addedViewTarget(View view){
llLayout2.removeView(view);
llLayout.addView(view);
}
}
I have a case where the case is to move the view from viewgroup to another viewgroup. The problem is when I delete a code llLayout.addView(view); it's no problem and the view is successfully erased, but when I want to add a view to llLayout always an error like this "The specified child already has a parent. You must call removeView() on the child's parent first". So, I want to move the view in llLayout2 to llLayout when clicked, are you guys the best solution for this case?
oO yes you are right i tried your code and dose not works
i tried few things and i came up with this weird solution :|
public void addedViewTarget(final View view) {
ViewGroup vg = ((ViewGroup) view.getParent());
vg.removeView(view);
view.postDelayed(new Runnable() {
#Override
public void run() {
llLayout.addView(view);
}
},1000 );
}
i don't know why your code is not working and i dont know why this code is working but I have this hypothesis when you are saying remove View its takes some Time maybe in other thread and when your trying add the view to other ViewGroup instantly it raise error because removing task not complete yet
Try this
if(view.getParent()!=null)
((ViewGroup)view.getParent()).removeView(view);
llLayout.addView(view);

Automatic scrolling a text view after appending text in Android

I'm trying to make the content of a textview to automatically scroll to the bottom at the most recent text appended. I tried many ways from many post but seems there's no way to make it work. I trie also different layout_wheight and width parameters and so on. The silly thing is that I already made it in the past and it worked, but now using the same set up it is not.
Here's my latest xml code:
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.5"
android:weightSum="2">
<ScrollView
android:id="#+id/askScv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<TextView
android:id="#+id/askTxv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:maxLines="99999"
android:scrollbars="vertical"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</ScrollView>
<ScrollView
android:id="#+id/answerScv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<TextView
android:id="#+id/answerTxv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:maxLines="99999"
android:scrollbars="vertical"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</ScrollView>
</TableRow>
and the Java one:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mQuestionEdt = (EditText) findViewById(R.id.questionEdt);
mAnswerTxv = (TextView) findViewById(R.id.answerTxv);
mAnswerTxv.setMovementMethod(new ScrollingMovementMethod());
mAnswerScv=(ScrollView)findViewById(R.id.answerScv);
mAnswerScv.fullScroll(View.FOCUS_DOWN);
mAskTxv=(TextView) findViewById(R.id.askTxv);
mAskTxv.setMovementMethod(new ScrollingMovementMethod());
mAskScv=(ScrollView)findViewById(R.id.askScv);
mAskScv.fullScroll(View.FOCUS_DOWN);
mAskBtn = (ImageButton) findViewById(R.id.askBtn);
mAskBtn.setOnClickListener(this);
mStartBtn = (ImageButton) findViewById(R.id.startBtn);
mStartBtn.setOnClickListener(this);
}
#Override
public void onClick(View view) {
Bundle result;
if (view.equals(mAskBtn)) {
result=mAnsweringMachine.answer(mQuestionEdt.getText().toString());
mAskTxv.append("\n" + mQuestionEdt.getText().toString());
mAskScv.smoothScrollTo(0,mAskTxv.getBottom());
mAnswerTxv.append("\n" + result.getString(AnsweringMachine.DIALOGUE_RESULT));
mAnswerScv.smoothScrollTo(0,mAnswerTxv.getBottom());
} else if (view.equals(mStartBtn)) {
result = mAnsweringMachine.runStartingPrompt();
mAnswerTxv.append(result.getString(AnsweringMachine.DIALOGUE_RESULT));
//mAnswerScv.fullScroll(View.FOCUS_DOWN);
}
}
And here's my old working code, xml:
<ScrollView
android:id="#+id/terminalScv"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/terminalTxv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge" />
</ScrollView>
and Java one:
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_terminal);
terminalTxv=(TextView) findViewById(R.id.terminalTxv);
terminalScv=(ScrollView) findViewById(R.id.terminalScv);
terminalScv.fullScroll(View.FOCUS_DOWN);
}
#Override
protected void onBtDataReceived(int[] data) {
super.onBtDataReceived(data);
String out=String.valueOf(terminalTxv.getLineCount())+" - ";
for (int x=0;x<data.length-1;x++){
out+=data[x];
out+=" ";
}
out+="\n";
terminalTxv.append(out);
terminalScv.smoothScrollTo(0, terminalTxv.getBottom());
}
Hope somebody can make me understand this enigma....
Thanks!
In the XML for the textView element I would try to add:
android:gravity="bottom"
Also are you sure you need to specify android:scrollbars="vertical" in both scrollview and textview? In addition, I noticed the difference between old working version is that it doesn't uses setMovementMethod() - personally I would use this method without scrollview, but since you already have scroollview I don't see a reason why would you need it...

Difficulties fading out and hiding Relative Layout

I'm trying to do a simple fade-out animation for my "custom" media controller.
The problem I'm having is that the layout does not fade-out, it just disappears after a second (as if I would set the Visibility to GONE with a 1 second delay).
This is my function:
private void fadeOut(final View view) {
final AlphaAnimation fadeOutAnimation = new AlphaAnimation(1.0F, 0.0F);
fadeOutAnimation.setDuration(1000);
fadeOutAnimation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.GONE);
}
});
view.startAnimation(fadeOutAnimation);
}
And the layout that I'm trying to hide:
<RelativeLayout
android:id="#+id/videoControllerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="0dp"
android:alpha="50"
android:background="#color/DarkGrey" >
<ImageButton
android:id="#+id/playVideoButton"
android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:background="#null"
android:contentDescription="#string/playButton"
android:scaleType="fitCenter"
android:src="#drawable/play" />
<ImageButton
android:id="#+id/fullScreenVideoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:background="#null"
android:contentDescription="#string/fullscreen"
android:src="#drawable/fullscreen" />
</RelativeLayout>
It's worth mentioning that all this is being used inside a fragment.
I'm hoping that someone with a bit more experience will take the time and let me know what I'm doing wrong.
I think you should have this in an anim xml file where you would want this:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1000"/>
</set>
I think your problem is that the interpolator isn't defined. So try to put this line's equivalent in your code:
android:interpolator="#android:anim/accelerate_interpolator"
Hope it helps
EDIT: did a little research, it looks like you want to say
fadeOutAnimation.setInterpolator(new AccelerateInterpolator());

Categories