public class i_dont_even1 : MonoBehaviour
{
public Rigidbody2D rb2D;
public bool bananawel;
void Update()
{
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("work");
}
I tried everything pls help
Related
I have a android project running smoothly, it uses MVVMCross at its core.
The problem came when I was asked manage the app protection policies with Intune.
Now Intune is forcing me to use their managed activity and all other managed namespaces provided by Intune SDK.
In that case, how I can proceed with it?
I tried changing activities base class to Intune's one, in hope to use general things provided by Mvvmcross, such as IOC, dependency injections.
I customised App startup as Intune wants that means there will not be any setup/app.cs class calls involvement.
So I launch Splash activity -> and it launches MainActivity, in MainActivity I am manually injecting all the Dependencies which I require.
Because all these syntaxes are throwing exception under Intune managed activities
example: Mvx.RegisterType<IDeviceInformation, DeviceInformation>();
Above throws exception.
How do I proceed with this migration keeping MVVMcross basic functionality intact?
There is a couple of solutions to that matter that I can think of.
If you only need the DI you can add another DI manager package and handle it from there which will be simpler than configuring Mvx to do that only.
If you need other capabilities of Mvx then you will have to do what Mvx does in its base classes and implement them taking into consideration setting the appropiate interfaces to your base classes.
In Android, in order to get the Setup and Activities working you'll have to:
Register your setup in your android Application file as done here
this.RegisterSetupType<TMvxAndroidSetup>();
Implement your own base activity that takes into consideration the implementation of IMvxEventSourceActivity such as here and also the MvxActivity like here in order to have the events and the data context / viewmodel handling
[Register("mvvmcross.platforms.android.views.base.MvxEventSourceActivity")]
public abstract class MvxEventSourceActivity
: Activity, IMvxEventSourceActivity
{
protected MvxEventSourceActivity()
{
}
protected MvxEventSourceActivity(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
protected override void OnCreate(Bundle bundle)
{
CreateWillBeCalled.Raise(this, bundle);
base.OnCreate(bundle);
CreateCalled.Raise(this, bundle);
}
protected override void OnDestroy()
{
DestroyCalled.Raise(this);
base.OnDestroy();
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
NewIntentCalled.Raise(this, intent);
}
protected override void OnResume()
{
base.OnResume();
ResumeCalled.Raise(this);
}
protected override void OnPause()
{
PauseCalled.Raise(this);
base.OnPause();
}
protected override void OnStart()
{
base.OnStart();
StartCalled.Raise(this);
}
protected override void OnRestart()
{
base.OnRestart();
RestartCalled.Raise(this);
}
protected override void OnStop()
{
StopCalled.Raise(this);
base.OnStop();
}
public override void StartActivityForResult(Intent intent, int requestCode)
{
StartActivityForResultCalled.Raise(this, new MvxStartActivityForResultParameters(intent, requestCode));
base.StartActivityForResult(intent, requestCode);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
ActivityResultCalled.Raise(this, new MvxActivityResultParameters(requestCode, resultCode, data));
base.OnActivityResult(requestCode, resultCode, data);
}
protected override void OnSaveInstanceState(Bundle outState)
{
SaveInstanceStateCalled.Raise(this, outState);
base.OnSaveInstanceState(outState);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
DisposeCalled.Raise(this);
}
base.Dispose(disposing);
}
public event EventHandler DisposeCalled;
public event EventHandler<MvxValueEventArgs<Bundle>> CreateWillBeCalled;
public event EventHandler<MvxValueEventArgs<Bundle>> CreateCalled;
public event EventHandler DestroyCalled;
public event EventHandler<MvxValueEventArgs<Intent>> NewIntentCalled;
public event EventHandler ResumeCalled;
public event EventHandler PauseCalled;
public event EventHandler StartCalled;
public event EventHandler RestartCalled;
public event EventHandler StopCalled;
public event EventHandler<MvxValueEventArgs<Bundle>> SaveInstanceStateCalled;
public event EventHandler<MvxValueEventArgs<MvxStartActivityForResultParameters>> StartActivityForResultCalled;
public event EventHandler<MvxValueEventArgs<MvxActivityResultParameters>> ActivityResultCalled;
}
[Register("mvvmcross.platforms.android.views.MvxActivity")]
public abstract class MvxActivity
: MvxEventSourceActivity
, IMvxAndroidView
{
protected View _view;
protected MvxActivity(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
protected MvxActivity()
{
BindingContext = new MvxAndroidBindingContext(this, this);
this.AddEventListeners();
}
public object DataContext
{
get { return BindingContext.DataContext; }
set { BindingContext.DataContext = value; }
}
public IMvxViewModel ViewModel
{
get
{
return DataContext as IMvxViewModel;
}
set
{
DataContext = value;
OnViewModelSet();
}
}
public void MvxInternalStartActivityForResult(Intent intent, int requestCode)
{
StartActivityForResult(intent, requestCode);
}
public IMvxBindingContext BindingContext { get; set; }
public override void SetContentView(int layoutResId)
{
_view = this.BindingInflate(layoutResId, null);
SetContentView(_view);
}
protected virtual void OnViewModelSet()
{
}
protected override void AttachBaseContext(Context #base)
{
if (this is IMvxSetupMonitor)
{
// Do not attach our inflater to splash screens.
base.AttachBaseContext(#base);
return;
}
base.AttachBaseContext(MvxContextWrapper.Wrap(#base, this));
}
private readonly List<WeakReference<Fragment>> _fragList = new List<WeakReference<Fragment>>();
public override void OnAttachFragment(Fragment fragment)
{
base.OnAttachFragment(fragment);
_fragList.Add(new WeakReference<Fragment>(fragment));
}
public List<Fragment> Fragments
{
get
{
var fragments = new List<Fragment>();
foreach (var weakReference in _fragList)
{
if (weakReference.TryGetTarget(out Fragment f))
{
if (f.IsVisible)
fragments.Add(f);
}
}
return fragments;
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
ViewModel?.ViewCreated();
}
protected override void OnDestroy()
{
base.OnDestroy();
ViewModel?.ViewDestroy(IsFinishing);
}
protected override void OnStart()
{
base.OnStart();
ViewModel?.ViewAppearing();
}
protected override void OnResume()
{
base.OnResume();
ViewModel?.ViewAppeared();
}
protected override void OnPause()
{
base.OnPause();
ViewModel?.ViewDisappearing();
}
protected override void OnStop()
{
base.OnStop();
ViewModel?.ViewDisappeared();
}
}
public abstract class MvxActivity<TViewModel>
: MvxActivity
, IMvxAndroidView<TViewModel> where TViewModel : class, IMvxViewModel
{
public new TViewModel ViewModel
{
get { return (TViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
}
Also you'll have to implement your own splash activity like here which implements the IMvxSetupMonitor and is the one who ends up calling the setup here by calling MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext); and initializing a monitor.
[Register("mvvmcross.platforms.android.views.MvxSplashScreenActivity")]
public abstract class MvxSplashScreenActivity
: MvxActivity, IMvxSetupMonitor
{
protected const int NoContent = 0;
private readonly int _resourceId;
private Bundle _bundle;
public new MvxNullViewModel ViewModel
{
get { return base.ViewModel as MvxNullViewModel; }
set { base.ViewModel = value; }
}
protected MvxSplashScreenActivity(int resourceId = NoContent)
{
RegisterSetup();
_resourceId = resourceId;
}
protected MvxSplashScreenActivity(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
protected virtual void RequestWindowFeatures()
{
RequestWindowFeature(WindowFeatures.NoTitle);
}
protected override void OnCreate(Bundle bundle)
{
RequestWindowFeatures();
_bundle = bundle;
var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);
setup.InitializeAndMonitor(this);
base.OnCreate(bundle);
if (_resourceId != NoContent)
{
// Set our view from the "splash" layout resource
// Be careful to use non-binding inflation
var content = LayoutInflater.Inflate(_resourceId, null);
SetContentView(content);
}
}
private bool _isResumed;
protected override void OnResume()
{
base.OnResume();
_isResumed = true;
var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);
setup.InitializeAndMonitor(this);
}
protected override void OnPause()
{
_isResumed = false;
var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);
setup.CancelMonitor(this);
base.OnPause();
}
public virtual async Task InitializationComplete()
{
if (!_isResumed)
return;
await RunAppStartAsync(_bundle);
}
protected virtual async Task RunAppStartAsync(Bundle bundle)
{
if (Mvx.IoCProvider.TryResolve(out IMvxAppStart startup))
{
if(!startup.IsStarted)
{
await startup.StartAsync(GetAppStartHint(bundle));
}
else
{
Finish();
}
}
}
protected virtual object GetAppStartHint(object hint = null)
{
return hint;
}
protected virtual void RegisterSetup()
{
}
}
public abstract class MvxSplashScreenActivity<TMvxAndroidSetup, TApplication> : MvxSplashScreenActivity
where TMvxAndroidSetup : MvxAndroidSetup<TApplication>, new()
where TApplication : class, IMvxApplication, new()
{
protected MvxSplashScreenActivity(int resourceId = NoContent) : base(resourceId)
{
}
protected override void RegisterSetup()
{
this.RegisterSetupType<TMvxAndroidSetup>();
}
}
This will cover the basics I think.
Hope it helps you to get you to the right direction
my viewpager is different (with multy xml and java file.means page1 java and xml file,page2 java and xml file,page3 java and xml files are seprate).
and want to sate cubeout effect in my viewpager.
**this is my coad **
public class MercuryActivity extends FragmentActivity implements OnPageListener {
List fragments = new Vector();
private ViewPager mPager;
private PagerAdapter mPagerAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.fragments.add(Fragment.instantiate(this, Page1Fragment.class.getName()));
this.fragments.add(Fragment.instantiate(this, Page2Fragment.class.getName()));
this.fragments.add(Fragment.instantiate(this, Page3Fragment.class.getName()));
this.fragments.add(Fragment.instantiate(this, Page4Fragment.class.getName()));
this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), this.fragments);
this.mPager = (ViewPager) super.findViewById(R.id.pager);
this.mPager.setAdapter(this.mPagerAdapter);
}
public void onPage1(String s) {
((Page2Fragment) this.fragments.get(1)).getView();
((Page3Fragment) this.fragments.get(2)).getView();
((Page4Fragment) this.fragments.get(3)).getView();
}
public void onBackPressed() {
new Builder(this).setIcon(17301543).setTitle("Exit").setMessage("Are you sure you want to exit?").setPositiveButton("Yes", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
MercuryActivity.this.moveTaskToBack(true);
MercuryActivity.this.finish();
}
}).setNegativeButton("No", null).show();
}
}
and this is my page adapter
public class PagerAdapter extends FragmentPagerAdapter {
private List fragments;
public PagerAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
public Fragment getItem(int position) {
return (Fragment) this.fragments.get(position);
}
public int getCount() {
return this.fragments.size();
}
}
I have been trying to implement a repository pattern in my project. I am not sure if i am using dispose correctly. I took the pattern from the MVA course on entity framework.
My repository
public static bool IsAwesome { get { return true; } }
public class Repository<T> : IDisposable where T : class
{
private ApplicationDbContext db = null;
protected DbSet<T> DbSet { get; set; }
public Repository()
{
db = new ApplicationDbContext();
DbSet = db.Set<T>();
}
public List<T> GetAll()
{
return DbSet.ToList();
}
public T Get(int id)
{
return DbSet.Find(id);
}
public T GetWithString(string id)
{
return DbSet.Find(id);
}
public void Add(T entity)
{
DbSet.Add(entity);
}
public void Update(T entity)
{
DbSet.Attach(entity);
db.Entry(entity);
}
public void SaveChanges()
{
db.SaveChanges();
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
db.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
Example of imageRepository which inherits from repository
public class ImageRepository : Repository<Image>
{
public Image GetLatest(int vehicleId)
{
return DbSet.FirstOrDefault(p => p.VehicleId == vehicleId);
}
public List<Image> GetImagesByVehicleId(int vehicleId)
{
return DbSet.Where(p => p.VehicleId == vehicleId).ToList();
}
}
Using my repository on top of the controller and disposing in the bottom of my controller
ImageRepository imageRepository = new ImageRepository();
UserRepository userRepository = new UserRepository();
protected override void Dispose(bool disposing)
{
imageRepository.Dispose();
userRepository.Dispose();
base.Dispose(disposing);
}
Will my code handle all unmanaged connections and close them correctly?
Thank you in advance. Im still a bit new to MVC and EF. I am sorry if my question is a bit newbish. My first post in here. So i hope i did not break any rules:)
Add your Dispose code in UnitOfWork,Remove From GenericRepository
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
Context.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
Will my code handle all unmanaged connections and close them
correctly?
Apparently yes.
However, you are not quite following the pattern. You don't have to SuppressFinalize as you don't have a finalizer in your class.Have a read about proper implementation of IDisposable Pattern.
for the life of me I can't figure out what is wrong with this code, please help. I have three classes, GeometricObject, Octagon which extends GeometricObject and TestOctagon which is being used to test the Octagon class. When I run the TestOctagon class I get this error:
The method clone() from the type Object is not visible
Here is my code:
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
protected GeometricObject() {
}
protected GeometricObject(String color, boolean filled) {
this.color = color;
this.filled = filled;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public abstract double getArea();
public abstract double getPerimeter();
}
import java.lang.Comparable;
import java.lang.Cloneable;
public class Octagon extends GeometricObject implements Comparable<Octagon>, Cloneable{
double side;
public Octagon() {
}
public Octagon(double side) {
this.side = side;
}
public Octagon(double side, String color, boolean filled) {
this.side = side;
setColor(color);
setFilled(filled);
}
public double getSide() {
return side;
}
public void setSide(double side) {
this.side = side;
}
public double getArea() {
return (2+4/Math.sqrt(2))*side*side;
}
public double getPerimeter() {
return 8*side;
}
#Override
public int compareTo(Octagon o) {
if (getArea() > o.getArea())
return 1;
else if (getArea() < o.getArea())
return -1;
else
return 0;
}
#Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
public class TestOctagon {
public static void main(String[] args) {
// TODO Auto-generated method stub
GeometricObject oc1 = new Octagon(5);
System.out.println(oc1.getArea());
System.out.println(oc1.getPerimeter());
GeometricObject oc2 = (GeometricObject)oc1.clone();
}
}
Don,
Please note that the access specifier for method Object::clone() is protected. It is not accessible from your TestOctagon class as you are invoking this method on object of type GeometriObject (oc1) where the clone method is still protected as neither it or its super classes have overridden it. Try moving the clone method from Octagon class to GeometriObject class. Please retain the public access specifier. Refer this sample on how to do it http://www.javatpoint.com/object-cloning
I keep getting this error:
Illegal modifier for the local class myWebClient; only abstract or final is permitted.
and this error:
void is an invalid type for the variable backButtonClicked
Heres the code where the error occurs.
public class myWebClient extends WebViewClient
{
}
public void backButtonClicked(View view)
{
if (ourBrow.canGoBack())
ourBrow.goBack();
}
public void forwardButtonClicked(View view)
{
if (ourBrow.canGoForward())
ourBrow.goForward();
}
public void goButtonClicked(View view)
{
String theWebsite = Url.getText().toString();
if(theWebsite != null)
ourBrow.loadUrl(theWebsite);
}
public void refreshButtonClicked(View view)
{
ourBrow.reload();
}
Remove the public modifier of the class and put all methods inside the body of the class:
class myWebClient extends WebViewClient
{
public void backButtonClicked(View view)
{
if (ourBrow.canGoBack())
ourBrow.goBack();
}
public void forwardButtonClicked(View view)
{
if (ourBrow.canGoForward())
ourBrow.goForward();
}
public void goButtonClicked(View view)
{
String theWebsite = Url.getText().toString();
if(theWebsite != null)
ourBrow.loadUrl(theWebsite);
}
public void refreshButtonClicked(View view)
{
ourBrow.reload();
}
}