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 ;)
Related
I am using Scringo for implementing Group Chat within my Android App. Is there a way in which we can open a particular chatroom through code ? Right now, from the sample applications and API, I found only the below code.
Scringo.openChatRooms(MainActivity.this);
Please let me know how do I
Create a Chatroom programmatically
Open a particular Chatroom programmatically.
Right now Scringo SDK is not providing way to open a chatroom programmatically. They are having their own screens(Activity) to manage the many to many Chat functionality. They are yet to integrate the following features on their Android SDK.
1. Creating Chatrooms programmatically
2. Joining/Opening Chatrooms programmatically
Source: I got a response from their Support Team. They claim that this feature is available for their IOS sdk. I am not sure.
This code solved my problem :
MainActivity.java
public class MainActivity extends Activity {
private Scringo scringo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
scringo = new Scringo(this);
...
findViewById(R.id.openChatRoomButton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Scringo.openChatRooms(MainActivity.this);
}
});
...
}
main.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"
tools:context=".MainActivity" >
...
<Button
android:id="#+id/openChatRoomButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="#string/open_inbox_button_text" />
</RelativeLayout>
Want to develop a QR code reader.. which will customized for my application. after a lot of search i found a link http://www.androidaz.com/development/zxing-qr-reader-direct-integration this tutorial demonstrate what i exactly want. but when i import it and then run this app i notice that its camera is in 90 degree angle when i rotate device. what is the problem i can not realize. my main.xml is
<FrameLayout
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_gravity="center_horizontal">
<include layout="#layout/capture"/>
</FrameLayout>
my mainactivity file is:
public class ScannerActivity extends CaptureActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qrcode);
}
#Override
public void handleDecode(Result rawResult, Bitmap barcode)
{
Toast.makeText(this.getApplicationContext(), "Scanned code " + rawResult.getText(), Toast.LENGTH_LONG).show();
}
}
menifest file with permission :
<uses-permissionandroid:name="android.permission.CAMERA"/>
<uses-permissionandroid:name="android.permission.INTERNET"/>
<uses-permissionandroid:name="android.permission.VIBRATE"/>
<uses-permissionandroid:name="android.permission.FLASHLIGHT"/>
<uses-permissionandroid:name="android.permission.READ_CONTACTS"/>
<uses-permissionandroid:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permissionandroid:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE"/>
it can read QR code fine. only problem camera caused abnormal behavior when rotating..
Thanks in advanced.
Maybe what you would like to do is here:
android-zxinglib
An android library project of zxing BarcodeScanner
https://code.google.com/p/android-zxinglib/
Download the project and look these files:
AndroidManifest.xml
capture.xml
Go into your manifest and change the orientation to landscape. Portrait caused the same problem for me, and landscape looked a lot better.
Recently i have successfully implemented the ActionBarSherlock Demos sample in eclipse. But there is something that i am not able to understand it that how this library automatically creates the header with one icon and a text "ActionBarSharelock Demos" in tab_navigation.xml by using merely a LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dip">
</LinearLayout>
This library is new for me and i am so anxious to know, how this library creates it?
I created a new android project on target api 15 and attach the ActionBarSherlock library to it. then i found that there some of the files are missing from my new android project when i compared it to demos sample project of android. Those files are listed below.
1.pom.xml
2.bin/classes.dex
3.bin/jarlist.cache
4.bin/resources.ap_
Moreover i got a new error in my activity file on eclipse "R cannot be resolved to a variable."
If you know anything about my problem then please share your views.
To use the simplest example:
public class Simple extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
((TextView)findViewById(R.id.text)).setText(R.string.simple_content);
}
}
All you have to do is let your activity inherit one of the Sherlock activites (e.g., SherlockActivity, SherlockFragmentActivity).
You can program the action bar by using the getSupportActionBar() method of the SherlockActivity, e.g. to set the title: getSupportActionBar().setTitle( R.string.my_title );
I am developing an Android Application. In this application, Logo bar is shown on all pages(Activities) or we can say it has header on all pages.
This Logo Bar have few icons like Home, Login, Notification, etc. and on Clicking on these icons corresponding navigation will perform.
for example if user is any where in application and click on home icon, he will navigate to the home page of application.
I am able to inflate logobar.XML into my All Activity by coding. but problem is i have to call onClickListener on all pages for all icons in Logo Bar.
This is not a good programming way.
How can i implement Logo Bar Activity in all other activity without repeating of code?
Is android have any Master Page concept as in .Net or tiles concept as in Struts?
Please guide me.
Edit: ok i got it. may be this answer will help you.
Try using Tab widget with tabactivity check this link for using fragment and tab http://developer.android.com/reference/android/app/TabActivity.html for android. i think for lower versions also we can use this. this si what the link says - "you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT."
you have to create your masterLayout in xml and that you have to include it in your other
layouts in which you have to have it.
The solution was pretty easy.
You need to extends "Activity" Class,in onCreate function SetContentView to your base xml layout and also need to override setContentView in base Activity Class
For Example:
1.Create "base_layout.xml" with the below code
<?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"
android:orientation="vertical"
android:background="#000000"
android:padding="15dp" >
<LinearLayout android:orientation="horizontal" android:background="#000000"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:minHeight="50dp" android:paddingLeft="10dp">
<ImageView android:layout_width="wrap_content" android:id="#+id/ImageView01"
android:adjustViewBounds="true" android:layout_height="wrap_content"
android:scaleType="fitCenter" android:maxHeight="50dp" />
</LinearLayout>
<LinearLayout android:id="#+id/linBase"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
</LinearLayout>
2.Create "BaseActivity.java"
public class BaseActivity extends Activity {
ImageView image;
LinearLayout linBase;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.base_layout);
image = (ImageView)findViewById(R.id.ImageView01);
image.setImageResource(R.drawable.header);
linBase = (LinearLayout)findViewById(R.id.linBase);
}
#Override
public void setContentView(int id) {
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(id, linBase);
}
}
and
public class SomeActivity extends BaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.some_layout);
//rest of code
}
}
The only thing I noticed so far was that when requesting a progress bar (requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) this needs to be done before calling super.onCreate. I think this is because nothing can be drawn yet before calling this function.
This worked great for me and hopefully you will find this useful in your own coding.
There is something like that, but only available on api 11+ (3.2 and Android 4.0.x Ice Cream Sandwich). Its called actionbar ( http://developer.android.com/reference/android/app/ActionBar.html).
I have done this using XML file.
I am just creating runtime view from XML file , and add it to the Activity layout.
I have created method for that
public static void setLoginview(Context ctx, RelativeLayout layout) {
LayoutInflater linflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = linflater.inflate(R.layout.loginheader, null);
layout.addView(myView);
try {
layout.getChildAt(0).setPadding(0, 50, 0, 0);
} catch (Exception e) {
}
}
ctx is the application contetx and layout is the layout in which i want to add that view.
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);