Change source code for video location - android-studio

I recently purchase a source code for a quiz app, doing so with no experience. The app allows video to be played, but requires you to "tap to play", I would like for the video to play on the same screen as the question. How do I change this and can I change this in this line of code? New to this, so if you need any additional info, let me know.
else if(question.questionType == 3) {
mSmallLayout.setVisibility(View.VISIBLE);
mTapText.setText(R.string.tap_to_play);
File file = new File(getExternalCacheDir() + "/delete" + mCurrentQuestion);
if(!file.exists()) {
mSmallImage.setImageURI(Uri.fromFile(file));
} else {
mSmallImage.setImageResource(R.drawable.videooverlay);
}

Then you need to open it using an Android Edition Platform, The code is like:
JAVA:
public void onClickBtn(View v)
{
Toast.makeText(this, "Lets try").show();
}
}
Button[Onclick function]:
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/btn"
android:onClick="onClickBtn" />
</LinearLayout>
And video example:
Playing a video in android
// Additional info: The Android Manifest is a android XML to execute the JAVA code, To work on you need check the Android dev's page and check every function, An function to be ready, Need to be set righty. Thank you!

Related

Unresolved reference by Android Studio 2020.3.1

I've used the Fullscreen Activity to create a project in Android Studio 2020.3.1. On buld of the app, I get "Unresolved reference: LastChange". The 3 lines pointed to (in FullscreenActivity.kt) are:
override fun onConfigurationChanged(newConfig: Configuration) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
LastChange.setText("Landscape")}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
LastChange.setText("Portrait")}
else {
LastChange.setText("Unrecognized")}
super.onConfigurationChanged(newConfig)
}
The TextView (in activity_xml) is coded as:
<TextView
android:id="#+id/LastChange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/LastChangeText"
android:textSize="24sp" />
LastChangeText (in strings.xml) is defined as:
<string name="LastChangeText">N/A</string>
Although your textView has "LastChange" id, that's not the way you call it from activity.
At "onCreate" method, after super.onCreate(), you'll need:
setContentView(R.layout.<YOUR_LAYOUT_NAME>);
val lastChangeTextView = (TextView) findViewById(R.id.LastChange);
And, after that, you can call methods on "lastChangeTextView".
lastChangeTextView.setText("Landscape")
Strongly recommend taking a look at Documentation:
https://developer.android.com/guide/topics/ui/declaring-layout

How to display listItem on emulator on recyclerview?

what I am trying to do is show a custom card in a recyclerview.
I can see it on the design view on android studio, but no when the emulator runs.
I just need to display de listItem.
Is is posible? if so, any help or suggestion would be great, thanks.
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rcvPoolVariables"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="22dp"
android:layout_marginStart="17dp"
android:layout_marginEnd="17dp"
tools:listitem="#layout/row_pool_objectives"
app:layout_constraintTop_toBottomOf="#+id/containerVariableAndWeeks"
app:layout_constraintBottom_toBottomOf="parent"/>
1.xml
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/categoryview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="#layout/innercategorylist">
</androidx.recyclerview.widget.RecyclerView>
2.java file
CategoryModel[] myListData1 = new CategoryModel[]{
new CategoryModel( R.drawable.kiwi,"kiwi"),
new CategoryModel(R.drawable.watermelon,"watermelon" ),
new CategoryModel(R.drawable.strawberry,"strawberry")
};
innerCategoryAdapter = new InnerCategoryAdapter(myListData1, new InnerCategoryAdapter.HomeAdapterInterface() {
#Override
public void onRowClick(int searchText) {
}
});
3.Adapter class id define and assign and model class to variable getter setter set
If the "preliminary version" is shown in the design tab, then there are no errors on the part of xml documents. It's in "regular" code part. I think the error lies in the output of elements on the device - either you do not pass data objects for output in recycler view, or there is an error in the processing of this data. Check the recycler view classes architecture and code of an adapter class. Also read this guide, I hope it'll help you.

Android Xml File Button Hidden

In My Android Application, i have to hide button based on some condition,if condition is true than button is hide,otherwise it appear as it is, so for hide facility i'm using button's buttonID.setVisibility(View.INVISIBLE),so that button is hidden but it take space in xml file,so please suggest me to button is hidden and don't take space in xml file
visible - This means visible and it takes space.
invisible- This means invisible and it takes space.
gone- This means invisible and it DOESN'T takes space.
Use it as follows:
Visible tag in XML
android:visibility="visible"
Visible code in java
view.setVisibility(View.VISIBLE);
Invisible tag in XML
android:visibility="invisible"
Invisible code in java
view.setVisibility(View.INVISIBLE);
Gone tag in XML
android:visibility="gone"
Gone tag in java
view.setVisibility(View.GONE);
you should use View.GONE instead of View.INVISIBLE
As what #Tim suggested,you can always change the layout parameters for the elements not just set it's visibility to VISIBLE or GONE
Here the sample. Assume checkBox is clicked
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
buttonID.setVisibility(View.GONE);
}
else{
buttonID.setVisibility(View.VISIBLE);
// now settings the new parameters
AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) buttonID.getLayoutParams());
params.x = 100; // the new value
params.y = 100; // the new value
buttonID.setLayoutParams(params);
}
});
Source : Android: how to change layout_x, layout_y in an AbsoluteLayout dynamically?

Android ViewFlipper with translation animation - not working properly

I want to display banner(images moving in x direction) in my application. For that i am using ViewFlipper with Translation animation. Please find my below code..
my layout: banner.xml
<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" >
<ViewFlipper
android:id="#+id/banner_image"
android:layout_width="match_parent"
android:layout_height="258dp" />
</RelativeLayout>
In animation: in_from_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="3000"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
Out Animation: out_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="3000"/>
</set>
My Java Code
public class BannerView extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.banner);
ViewFlipper myViewFlipper = (ViewFlipper) findViewById(R.id.banner_image);
//Setting first image in viewFlipper
ImageView imageView1 = new ImageView(HomeView.this);
imageView1.setImageDrawable(getResources().getDrawable(R.drawable.img1));
myViewFlipper.addView(imageView1);
//Setting second image in viewFlipper
ImageView imageView2 = new ImageView(HomeView.this);
imageView2.setImageDrawable(getResources().getDrawable(R.drawable.img2));
myViewFlipper.addView(imageView2);
myViewFlipper.setAutoStart(true);
//Setting in and out animation
myViewFlipper.setInAnimation(HomeView.this,R.anim.in_from_right);
myViewFlipper.setOutAnimation(HomeView.this,R.anim.out_to_left);
//Starting the view filpper to rotate
myViewFlipper.startFlipping();
}
}
Here my problem is,
When i set the duration for in and out animation as "5000", ViewFilpper's behavior is changing like the below,
Image start to move slowly and ending quickly.
I dont know where i am missing. I want to slow down the speed. Please help me resolve the issue.
Update: I whipped up some sample code and there is a big stutter halfway through as if the 2nd view is forcibly moved to catch up to the 1st view. After much trial and error I found that setting android:flipInterval="5000" in the viewflipper xml properties fixed it. I can only assume that the default flipInterval is shorter than 5000 and hence the issue.
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="match_parent"
android:layout_height="258dp"
android:flipInterval="5000" >
If you still find the animation not smooth enough:
Put this in your xml for the translate animation:
android:interpolator="#android:anim/linear_interpolator"
And then
android:startOffset="1000"
to slide_out_to_left so it waits a bit before continuing.
Thanks for your reply. I found the solution for my problem. Please find my answer below.
I have changed my interpolator in xml as below:
android:interpolator="#android:anim/decelerate_interpolator"
And then i used android:flipInterval="5000" in my viewflipper solved my problem.

Playing audio in a safari web app in iOS 8.1

Bevour you mark this as "old", I've searched the whole www for a solution, but I can't find one.
I am making a WebApp that plays sound-effects. I've created a var audio = new Audio() element, and changed his src to the URL of the sound-effect. When I call the audio.play() function, it starts playing the sound effect. In normal safari it works, but when I set apple-mobile-web-app-capable to true in a meta-tag, the WebApp crashes. I tried also to use a hard coded audio tag, to create a audio tag using javascript and to populate a div with a audio-element and it didn't work.
var audio = new Audio;
function set(src){ audio.src = src; }
function play() { audio.play(); }
function pause() { audio.pause(); }
<button onClick="set('https://incompetech.com/music/royalty-free/mp3-royaltyfree/Thief%20in%20the%20Night.mp3')">Set sound</button>
<button onClick="play()">Play sound</button>
<button onClick="pause()">Pause sound</button><br /><br />
<b>Music:</b> "Thief in the Night" Kevin MacLeod (incompetech.com) Licensed under Creative Commons: By Attribution 3.0 License http://creativecommons.org/licenses/by/3.0/
Tnx in advance, Stephan

Resources