I created a new class for my toolbars edittext. I have it for expansion animation but it crashes when you click the edittext. Heres the code used
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.EditText;
/**
* Created by on 2018-01-07.
*/
public class Toolbar extends AppCompatActivity {
EditText search;
public void onEdit(){
Animation scaleAnimation = new ScaleAnimation(0, -500, 1, 1);
scaleAnimation.setDuration(750);
scaleAnimation.setFillAfter(true);
search.startAnimation(scaleAnimation);
}
}
personally ive never used other class rather one large class so any helpfull tips is greatly appreciated. The code in the MainActivity currently is blank which i was going to fill with webview once i got there or possibly in another class....
Here the crash data:
01-07 05:09:41.007 943-1130/? E/OMX-VDEC-1080P: Does not handle dataspace request
01-07 05:09:41.007 943-1130/? E/OMXNodeInstance: getConfig(3af0069:qcom.decoder.avc, ??(0x7f000062)) ERROR: UnsupportedSetting(0x80001019)
01-07 05:09:41.009 943-2332/? E/OMX-VDEC-1080P: Does not handle dataspace request
01-07 05:09:41.009 943-2332/? E/OMXNodeInstance: getConfig(3af0069:qcom.decoder.avc, ??(0x7f000062)) ERROR: UnsupportedSetting(0x80001019)
You can not find edittext because you have not set a view for this class, i guess you will be using this class from another activity which has ContentView and that is associated with an XML file. To be able to findviewbyids of that activity from this class. You will need to do something like this.
public class testclass {
public void onEdit(Context context, Activity activity){
EditText search;
search = activity.findViewById(R.id.search_edt);
Animation scaleAnimation = new ScaleAnimation(0, -500, 1, 1);
scaleAnimation.setDuration(750);
scaleAnimation.setFillAfter(true);
search.startAnimation(scaleAnimation);
}
}
and from your main class call this class passing parameters of context and activity like this
a.onEdit(this,this);
now you will be able to retrieve the widgets of the UI of that activity from this class.
I hope i helped this explanation helped you.
Related
I followed a tutorial online to create an AR app that could show my 3D models in AR.
I put my .obj and .gltf 3d model files in my assets folder,
when the I tap on a plane, the method placeObject() should run and put my model (selectObject) on the place.
but when I test it on my phone,after the plane was detected and I tapped the screen, nothing happened, I checked my logcat and it shows the error when I tapped:
2021-11-04 01:55:46.629 11172-12363/com.example.arcoretest E/ModelRenderable: Unable to load Renderable registryId='testscene.obj'
java.util.concurrent.CompletionException: java.lang.AssertionError: No RCB file at uri: testscene.obj
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:278)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:284)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1629)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.lang.AssertionError: No RCB file at uri: testscene.obj
at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.byteBufferToSfb(LoadRenderableFromSfbTask.java:191)
at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.lambda$downloadAndProcessRenderable$0$com-google-ar-sceneform-rendering-LoadRenderableFromSfbTask(LoadRenderableFromSfbTask.java:121)
I'm not sure where the problem is, is it my uri is wrong or I should use other 3d model format?
(I tried .obj/.fbx/.gltf but none of them worked)
(I can't use .sfb or .sfa ,I can no longer use sceneform plugin to convert files into sfa/sfb because it was deprecated)
here is my grade dependencies:
{
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.15.0'
implementation 'com.google.ar:core:1.15.0'
implementation 'com.google.ar.sceneform:assets:1.15.0'
...
}
My mainActivity.java:
package com.example.arcoretest;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import com.google.ar.core.Anchor;
import com.google.ar.core.HitResult;
import com.google.ar.core.Plane;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.rendering.Renderable;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.TransformableNode;
public class MainActivity extends AppCompatActivity {
private ArFragment fragment;
private Uri selectObject;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
selectObject = Uri.parse("testscene.obj");
fragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.sceneFormFragment);
//when tapped on a plane, code below will run
fragment.setOnTapArPlaneListener(
(HitResult hitResult, Plane plane, MotionEvent motionEvent)->{
Anchor anchor = hitResult.createAnchor();
placeObject(fragment,anchor,selectObject);
}
);
}
//this method put 3d model in scene
private void placeObject(ArFragment fragment, Anchor anchor,Uri model){
ModelRenderable.builder()
.setSource(fragment.getContext(),model)
.build()
.thenAccept( renderable -> addNodeToScene(fragment,anchor,renderable))
.exceptionally((throwable -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(throwable.getMessage())
.setTitle("Error!");
AlertDialog dialog = builder.create();
dialog.show();
return null;
}));
}
private void addNodeToScene(ArFragment fragment, Anchor anchor, Renderable renderable){
AnchorNode anchorNode = new AnchorNode(anchor);
TransformableNode node = new TransformableNode(fragment.getTransformationSystem());
node.setRenderable(renderable);
node.setParent(anchorNode);
fragment.getArSceneView().getScene().addChild(anchorNode);
node.select();
}
}
and I put my 3d model files in assets folder like this:
I would recommend to update to the latest version of SceneForm. This is a community maintained version, with the latest dependencies of ArCore, Filament and Android. For your usecase the 3d-model-viewer sample might be interesting.
I tried a lot of things but I can't get it to work... I try to pass this String Variable (when i click Item in RecyclerView) to my MainActivity.
What works bad is calling the function (OnRecyclerViewItemClick) and changing the variable(GetUrlFromItem). My version of Android Studio is 2.3.3
I really need do this:
My RecyclerView:
public class viewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
TextView titulo;
Button playbtn01;
List<Fuente> ListaObjeto;
public viewHolder(View itemView,List<Fuente> datos) {
super(itemView);
ListaObjeto = datos;
titulo = (TextView) itemView.findViewById(R.id.texto);
playbtn01 = (Button) itemView.findViewById(R.id.playbtn00);
playbtn01.setOnClickListener(this);
}
#Override
public void onClick(View view) {
int position = getAdapterPosition();
Fuente objeto = ListaObjeto.get(position);
if (view.getId() == playbtn01.getId()) {
MainActivity mainActivity = new MainActivity:
mainActivity.OnRecyclerViewItemClick(); /// initiate Void in Main
mainActivity.GetUrlFromItem = objeto.GetUrl; //Change Variable of Main
}
}
}
MainActivity
public class MainActivity extends AppCompatActivity {
public String GetUrlFromItem;
public void OnRecyclerViewItemClick() {
if (GetUrlFromItem == "..."){
doSomething...
}
}
}
There are two big problems that I see.
The first is how you get a MainActivity instance to work with. In your question, you have this line of code:
MainActivity mainActivity = new MainActivity:
Calling new is going to do exactly what it sounds like: create a new instance of the MainActivity class. You do not want a new instance! You want your alive and running instance.
There are a handful of ways to get ahold of your alive and running MainActivity, but probably the simplest one for now is going to be casting your ViewHolder's itemView's Context. So instead of the above, write something like this:
MainActivity mainActivity = (MainActivity) itemView.getContext();
The second big problem is in the next two lines:
mainActivity.OnRecyclerViewItemClick();
mainActivity.GetUrlFromItem = objeto.GetUrl;
The problem here is the order of these two statements. Because you invoke mainActivity.OnRecyclerViewItemClick() before setting the value of mainActivity.GetUrlFromItem, the value will not be updated when OnRecyclerViewItemClick() is executed.
Simply swap the order of these two lines.
I am using MaterialCalendarView Library and i added in my application for customization and I require Left and right button controll and controll left to right or right to left scroll in MainActivity but did not resoved please give me any suggestion if you know about it.
here is my code my java code.
mcv.state().edit()
.setFirstDayOfWeek(day_name)
.setMinimumDate(CalendarDay.from(2016, 1, 3))
.setMaximumDate(CalendarDay.from(2017, 12, 25))
.setCalendarDisplayMode(CalendarMode.WEEKS)
.commit();
here is my XML code
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/calendarView"
android:layout_width="368dp"
android:layout_height="wrap_content"
app:mcv_showOtherDates="all"
app:mcv_selectionColor="#android:color/holo_orange_dark"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
here is Library Link where i get this MaterialCalendarView
I created a callBackinterface in library and added method in that interface and and implement in MaterialCalendarView class that class is in library and other in main app respected class and pass controll to that app class when position chnage on scroll base and its work for me here is final code for more understanding
CallBackInterface
public interface CallBackInterface {
void sendResponse(int position,CalendarDay calendarDay);
}
Respected class where you want scroll controll access
mcv.setCallBackInterfacecustom(new CallBackInterface() {
#Override
public void sendResponse(int position, CalendarDay calendarDay) {
Toast.makeText(mActivity, calendarDay.getDate()+"" + position, Toast.LENGTH_LONG).show();
}
});
MaterialCalendarView class that is basically library class I added that library as a module in application code and here is code and link of that class MaterialcalendarView
here is code
added a method in that class that is...
public void setCallBackInterfacecustom(CallBackInterface _callBackInterfacecustom) {
callBackInterfacecustom = _callBackInterfacecustom;
}
I set setResponse method in viewpager that is ...
#Override
public void onPageSelected(int position) {
titleChanger.setPreviousMonth(currentMonth);
currentMonth = adapter.getItem(position);
Log.e("page scrolled",""+position+"month"+currentMonth);
CallBackInterface _CallBackInterface = callBackInterfacecustom;
if (_CallBackInterface != null) {
_CallBackInterface.sendResponse(position,currentMonth);
}
}
Hope so it will others who want.
I am having a difficult time figuring out how to reference a view's ID in a custom class. The goal is to create a class that can change the text inside a button and change the visibility of a textView from gone to visible. The code works fine as a stand alone, but I'd like to not repeat it a bunch of times for all the drop down sections being created.
In the code below, when initiating in my main class, nothing happens when this is attached to an onclick listener
How do I reference what would otherwise be R.id.btn1 and R.id.text1 so I can use this as a class?
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class toggleSection {
private Button button;
private TextView textView;
private boolean isOpen = false;
public toggleSection(Button button, TextView textView) {
this.button = button;
this.textView = textView;
}
public void toggleSection(Button button, TextView textView, String title) {
if (!isOpen) {
button.setText(title + " ►");
textView.setVisibility(View.VISIBLE);
isOpen = true;
} else {
button.setText(title + " ▼");
textView.setVisibility(View.GONE);
isOpen = false;
}
}
}
Thanks
In your toggleSection(), you are providing references to your button and textview again and using those references only. However, you should be using instance variables here that you must have initialized in the constructor.
I have been trying to make my first android app. I am stuck with this strange problem. There are lot of people who had faced same problem (like here, here, here and lots of other places) in past but none of the solutions seems to work for me.
My problem is if I set layout file like setContentView(R.layout.MainActivity) application crashes on this function but if I directly set GLSurfaceView as content view application works just fine. I want to have a ListView and GLSurfaceView on same screen thats why I am trying to add it in XML.
Here is my layout file
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.camerafilters.CameraGLSurfaceView
android:id="#+id/CameraGLSurfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<!-- <ListView
android:id="#+id/ShaderList"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
-->
</LinearLayout>
Here is relevant portion from main activity. Note that CameraGLSurfaceView is an inner class.
public class CameraMainActivity extends Activity implements
SurfaceTexture.OnFrameAvailableListener
{
private CameraGLSurfaceView _cameraGLView;
/**
* Captures frames from an image stream as an OpenGL ES texture. The image stream may come from either camera preview or video decode.
* A SurfaceTexture may be used in place of a SurfaceHolder when specifying the output destination of a Camera or MediaPlayer object
*/
private SurfaceTexture _surface;
CameraGLRenderer _renderer;
private Camera _camera;
private ListView _shaderListView;
class CameraGLSurfaceView extends GLSurfaceView
{
CameraGLRenderer renderer;
public CameraGLSurfaceView(Context context, AttributeSet attrs)
{
super(context, attrs);
// Create an OpenGL ES 2.0 context
setEGLContextClientVersion(2);
// Set the Renderer for drawing on the GLSurfaceView
renderer = new CameraGLRenderer((CameraMainActivity)context);
setRenderer(renderer);
// Render the view only when there is a change in the drawing data
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
public CameraGLRenderer getRenderer()
{
return renderer;
}
}
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
_cameraGLView = new CameraGLSurfaceView(this, null);
// Create a GLSurfaceView instance and set it
// as the ContentView for this Activity.
setContentView(R.layout.activity_main);
_cameraGLView = (CameraGLSurfaceView) findViewById(R.id.CameraGLSurfaceView);
_renderer = _cameraGLView.getRenderer();
}
Any pointers where i am wrong ?
First, have a look at the exception stacktrace in logcat to find the exact problem.
Then, guessing the problem is that the view specified in your XML cannot be instantiated: your inner class needs to be public static and you need to refer to it correctly in XML, like
com.example.camerafilters.CameraMainActivity$CameraGLSurfaceView
though it's cleaner to have it as a separate class instead of an inner class.
Why u calling it before onCreate ? You don't need to call it since you defined it in your xml layout.
You dont need to call it all. Just delete the line before setContentView.
You should call GLSurfaceView.setRenderer() in your Activity.onCreate()