I am having trouble trying to create an adapter for a TwoWayView from lucasar.
https://github.com/lucasr/twoway-view
What I want is a facebook-style display for images. Sort of like this.
facebook style image structure
I am currently trying to convert the LayoutAdapter.java file in the github repo under the sample folder into an Adapter that I can use in my project, but I think I need some more information on what exactly this adapter is doing.
Here is the xml for the TwoWayView grid.
<org.lucasr.twowayview.widget.TwoWayView
android:id="#+id/twvGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
app:twowayview_layoutManager="SpannableGridLayoutManager"
app:twowayview_numColumns="3"
app:twowayview_numRows="3"
android:layout_below="#+id/youtubeVidImage"
android:layout_gravity="center"
android:fitsSystemWindows="true"
android:layout_marginTop="35dp"/>
Each Item in the layout (GalleryItem) is essentially just a url of an image to be displayed. And I want to be able to add these images to the layout in the Activity that set up the TwoWayView. Something like this for the code in the Activity that initializes the mPhotos array.
private void initImagesRecyclerView(){
Log.d(TAG, "initImagesRecyclerView: init Recyclerview");
imagesRecyclerView = findViewById(R.id.twvGrid);
mPhotos = new ArrayList<GalleryItem>();
//mImagePostsAdapter = new ImagePostsAdapter(this,mPhotos);
//imagesRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL));
mImagePostsAdapter = new TwoWayViewAdapter(this,imagesRecyclerView,R.layout.layout_staggered_grid);
imagesRecyclerView.setAdapter(mImagePostsAdapter);
}
Can anyone give me some advice on how to implement the TwoWayView? Anything on how to make the adapter and how to set it to the TwoWayView reference in the Activity would be great.
Thanks
Related
I am designing an cross-platform app for iOS aswell Android with a shared logic using MVVMCross (5.1.1).
Throughout my app I have a fixed toolbar at the top displaying the current view's title aswell a button. Below the bar the interface is changing from view to view
The Android part:
On Android I created a reuseable layout which I embed in my current layout using include.
In my portable project I have a BaseViewModel which has the properties the reuseable toolbar layout binds to. Every other ViewModel derives from this base class. This way I can have all bindable properties of a displayed screen in one ViewModel without the need of nesting but see for yourself:
activity_login.xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_login" />
<RelativeLayout
android:id="#+id/parentLoginLayout"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
app:MvxBind="Text Pin"
/>
</RelativeLayout>
</RelativeLayout>
toolbar_login.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_login"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="0dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:minWidth="25px"
android:minHeight="25px">
<TextView
app:MvxBind="Click ToolbarMenuCommand"
/>
<!-- some other -->
</android.support.v7.widget.Toolbar>
ViewModels.cs
using System.Threading.Tasks;
using Mobile.Helpers;
using ViewModels.Base;
using MvvmCross.Core.Navigation;
using MvvmCross.Core.ViewModels;
using Plugin.MessageBox;
namespace Mobile.ViewModels
{
public abstract class BaseViewModel : MvxViewModel
{
protected void NavigateToMainView()
{
NavigateTo<MainViewModel>();
}
private readonly IMvxNavigationService _navigationService;
protected BaseViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
}
public IMvxCommand ToolbarMenuCommand => new MvxCommand(OnMenuButtonClick);
protected abstract void OnMenuButtonClick();
}
public class LoginViewModel : BaseViewModel
{
private bool _menuVisibility;
private string _pin;
public LoginViewModel(IMvxNavigationService navigationService) : base(navigationService)
{
}
public bool MenuVisibility
{
get => _menuVisibility;
set => SetProperty(ref _menuVisibility, value);
}
public string Pin
{
get => _pin;
set => SetProperty(ref _pin, value);
}
protected override void OnMenuButtonClick()
{
MenuVisibility = !MenuVisibility;
}
}
}
The iOS part:
I am not entirely sure how to realise above behavior on iOS. I hope someone has a good idea or a good example project for me which I can take a look at. In general it is no problem to refactorise the ViewModels incase my idea is just not possible at iOS.
A few facts about the iOS project:
I am not using storyboards but single .xib's being independent
from each other
In my .xib's files I use autolayout constraints for positioning and
sizing entirely
A few ideas I already had (cant test them right now):
1. idea:
Create a base .xib with the above bar, the constraints aswell the
outlets
Create each new xib Design based on the previously created file
This would mean I need to adjust every view incase I decide to change something about the toolbar but so far I found no other way to embed a .xib in another .xib without having two different ViewControllers. Also I read that inheritance cause problems with outlets.
2. idea
Each .xib has an empty view at the top which acts as a container for
the toolbar
Have a Base ViewController which constructs the toolbar from code and
adds it as a child to the container view, and binds the properties
from the BaseViewModel
In a previous iOS project I noticed that adding views to the layout can cause problems with autolayout. Probably also a not that good solution?
3. idea
Create a xib with the toolbar and a container below and use it as a master page which would probably mean having a MasterViewModel with the toolbar properties and a nested ChildViewModel.
This is probably the way to go but I have to admit that I have no clue what is the best way to approach it (stil pretty new to iOS and MVVMCross).
Does someone have a few useful hints for me? Thanks a lot!
From what I understood I think you should try to use ScrollView for iOS part and try to imitate the ViewPager's behavior from Android, an example.
I am new to android development and I am working on an android project where I have to integrate QR scanner. So I thought I would integrate Zxing QR scanner and came across this library https://github.com/dm77/barcodescanner, Following the instructions provided I have successfully integrated and scanned a QR as well.
Now I want to customise the camera view. The problem is there is no documentation on how to get access to the camera layout. Since I am new I might be missing something.
I have read through many Zxing related threads but I din find any solution.
Any help will be greatly appreciated either by letting me know on how I can get access to the camera view or pointing me out to some articles. Once I know how then I can complete the rest.
I would be happy to provide any further information.
Thanks in advance.
Update:
public class QrScanActivity extends BaseActivity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_scan);
// Programmatically initialize the scanner view
mScannerView = new ZXingScannerView(this);
// Set the scanner view as the content view
setContentView(mScannerView);
}
mScannerView is the view from the library. I want to get access to that view. I have a view called as activity_my_scan. I can add custom layout to that and use that but I don't know how to bypass the layout being used by the library.
Instead of just adding this lib as a jar using gradle's
compile 'me.dm7.barcodescanner:zxing:1.6.3'
you could clone the project from github or download a zip and uzip it and integrate to your project as a lib project. And then make any desired changes in its sources and its layouts.
ZXingScannerView extends BarcodeScannerView. You can access this by going to the declaration of ZXingScannerView (in Android Studio Ctrl+B).
public class ZXingScannerView extends BarcodeScannerView {
private MultiFormatReader mMultiFormatReader;
public static final List<BarcodeFormat> ALL_FORMATS = new ArrayList();
private List<BarcodeFormat> mFormats;
private ZXingScannerView.ResultHandler mResultHandler;
If you go the declaration of BarcodeScannerView, you'll notice a method called setupLayout() which formats the layout:
public void setupLayout() {
this.mPreview = new CameraPreview(this.getContext());
this.mViewFinderView = new ViewFinderView(this.getContext());
RelativeLayout relativeLayout = new RelativeLayout(this.getContext());
relativeLayout.setGravity(17);
relativeLayout.setBackgroundColor(-16777216);
relativeLayout.addView(this.mPreview);
this.addView(relativeLayout);
this.addView(this.mViewFinderView);
}
By going to the declaration of "CameraPreview" you'll be able to get more info for how the camera is laid out and you could maybe extend ZXingScannerView to edit the layout.
Hope this helps!
Cheers!
Well in your case i would try to include the layout into another layout, maybe it helps:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
<TextView android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:text="#string/hello"
android:padding="10dp" />
...
</LinearLayout>
And of course there is information about that here ;)
I am currently trying to draw a graph within an Android application. The library I found is called GraphView (http://www.jjoe64.com/p/graphview-library.html). I am currently using version 2, which is available on GitHub.
Drawing graphs works really nicely. The code necessary to get a graph is the following:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Map<String,List<GraphEntry>> graphData = (...)
if (graphData != null) {
List<GraphEntry> entries = graphData.get("temperature");
GraphView.GraphViewData[] data = new GraphView.GraphViewData[entries.size()];
int i = 0;
for (GraphEntry entry : entries) {
data[i++] = new GraphView.GraphViewData(entry.getDate().getTime(), entry.getValue());
}
GraphView.GraphViewSeries graphViewSeries = new GraphView.GraphViewSeries("temperature", 0xffff0000, data);
LineGraphView graphView = new LineGraphView(this, "temperature");
graphView.addSeries(graphViewSeries);
graphView.setShowLegend(true);
LinearLayout graphLayout = (LinearLayout) findViewById(R.id.layout);
graphLayout.addView(graphView);
}
}
This will produce a normal graph. Unfortunately, all kinds of labels are missing. The documentation tells that for the normal use case, one does not have to care about labels, as the library does this automatically. What am I doing wrong? I only get the plain graph, without any labels.
For the completeness, I am adding the graph to a linear layout. The appropriate layout file has the following contents:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:id="#+id/layout"
android:orientation="vertical"
></LinearLayout>
The GraphEntry class is only a container with a java.util.Date attribute and a double value attribute.
Thank you very much for any help,
Matthias
I switched to another charting engine: AChartEngine. This one works out of the box.
I had the same problem. This can be solved by removing the following line from the manifest file.
android:theme="#style/AppTheme"
I know this is quite vague, but worked for me. I don't the exact reason why this happens. If u guys come across the better solution please do share it.
You should use the latest version from github and include that in your project. This will allow you to set various colours using
graphView.getGraphViewStyle().setGridColor(Color.GREEN);
graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.YELLOW);
graphView.getGraphViewStyle().setVerticalLabelsColor(Color.RED);
I'm trying to implement activity with ListView among other widgets. So if I understand correctly I can't use ListActivity (because it shows only one big ListView that ist ok for me).
I found a lot different examples of doing this in java from SO like this
or
this
or great example.
I've tried to do in same way but it doesn't work correctly. I'm curious is this functionality exists in mono android at all?
I found only one example of using ListView in mono android which is
this
and this example describe using ListActivity only.
So, my layout:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:id="#+id/widget36"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</TableLayout>
My OnCreate:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.CreateUser);
JavaList<string> somadata = new JavaList<string> { "111", "222", "333" };
ListView view = FindViewById<ListView>(Resource.Id.list);
view.Adapter = new ArrayAdapter<string>(this, Resource.Layout.CreateUser, somadata);
view.TextFilterEnabled = true;
}
I've just found solution. I had error in this line:
view.Adapter = new ArrayAdapter<string>(this, Resource.Layout.CreateUser, somadata);
This topic helps me a lot.
Here is a further list of layouts that
you can use.
Sources of predefined layouts are here.
So, there is two options how to fix error and make ListView work without ListActivity in Mono Android.
First:
Just copy/paste layout of standard resource named simple_list_item_1:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
/>
Second (I'm sure it's a best way):
Just use standard resource. In Mono Android it named Android.Resource.Layout.SimpleListItem1
So my updated version of OnCreate which works perfect:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.CreateUser);
JavaList<string> somadata = new JavaList<string> { "111", "222", "333" };
ListView view = FindViewById<ListView>(Resource.Id.list);
view.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, somadata);
}
I created a custom SurfaceView called CaptureView and tried to add it into main.xml file:
<dev.recorder.client.CaptureView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/capturePreview"/>
The application seems to work fine but if I switch from main.xml tab to Layout in Eclipse the text NullPointerException appears instead of layout preview.
In the Activity I binded the controls the following way:
setContentView(R.layout.main);
bindControls();
private void bindControls()
{
videoPreview = (CaptureView)findViewById(R.id.capturePreview);
txtstatus = (TextView)findViewById(R.id.txtMode);
txtTimer = (TextView)findViewById(R.id.txtTime);
}
Does anyone know how this issue could be solved?
make sure that you are initializing the view in onFinishInflate and not in the constructor.
the layout preview code might initialize your control through a different code path.