Reputation: 57
Hi I have a question I can get the scanner working perfect and it decodes perfectly but on displaing result it show the image and url but I cant seem to get it so if i click on it or a button to load it btw im 17 so if its an easy fix please dont poke fun just correct me I just want to learn to develop and android was the best way btw i am using an open soure project i found to experiment with
Java File
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jwetherell.quick_response_code;
import android.view.Display;
import android.view.WindowManager;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
/**
* Example Encoder Activity.
*
* @author Justin Wetherell ([email protected])
*/
public final class EncoderActivity extends Activity {
private static final String TAG = EncoderActivity.class.getSimpleName();
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.encoder);
// This assumes the view is full screen, which is a good assumption
WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
int smallerDimension = width < height ? width : height;
smallerDimension = smallerDimension * 7 / 8;
try {
QRCodeEncoder qrCodeEncoder = null;
//qrCodeEncoder = new QRCodeEncoder("AT", null, Contents.Type.TEXT, BarcodeFormat.CODABAR.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("HI", null, Contents.Type.TEXT, BarcodeFormat.CODE_39.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.CODE_128.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("1234567891011", null, Contents.Type.TEXT, BarcodeFormat.EAN_13.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("12345678", null, Contents.Type.TEXT, BarcodeFormat.EAN_8.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("1234", null, Contents.Type.TEXT, BarcodeFormat.ITF.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("2345", null, Contents.Type.TEXT, BarcodeFormat.PDF_417.toString(), smallerDimension);
qrCodeEncoder = new QRCodeEncoder("Hello", null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension);
//qrCodeEncoder = new QRCodeEncoder("12345678910", null, Contents.Type.TEXT, BarcodeFormat.UPC_A.toString(), smallerDimension);`
Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
ImageView view = (ImageView) findViewById(R.id.image_view);
view.setImageBitmap(bitmap);
TextView contents = (TextView) findViewById(R.id.contents_text_view);
contents.setText(qrCodeEncoder.getDisplayContents());
setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle());
} catch (WriterException e) {
Log.e(TAG, "Could not encode barcode", e);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Could not encode barcode", e);
}
} }
Xml File
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2008 ZXing authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/encode_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="@color/encode_view"
android:orientation="vertical"
android:gravity="center">
<ImageView android:id="@+id/image_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="center"/>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center
<TextView android:id="@+id/contents_text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:textColor="@color/contents_text"
android:textSize="18sp"
android:paddingBottom="8dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"/>
</ScrollView>
</LinearLayout>
Thanks
Upvotes: 0
Views: 1472
Reputation: 33545
Call this for your textview.
TextView tv = (TextView) findViewById(R.id.text2);
tv.setMovementMethod(LinkMovementMethod.getInstance());
Learn about Linkify class...
This is make all the links (urls,phone numbers,etc) clickable.
Upvotes: 1