Android Video Streaming (Video View)

Video 

1.Test.java

package com.sample.test;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class Test extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);

/*Intent move=new Intent(Intent.ACTION_VIEW);
move.setDataAndType(Uri.parse(“android.resource://”+getPackageName()+”/”+R.raw.video), “video/*”);
startActivity(move);*/

VideoView videoView =(VideoView)findViewById(R.id.videoView);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse(“android.resource://”+getPackageName()+”/”+R.raw.video);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();

videoView.start();
}

}

 

2.activity_test.xml

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical” >

<TextView
android:id=”@+id/textView1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/hello_world” />

<VideoView
android:id=”@+id/videoView”
android:layout_width=”match_parent”
android:layout_height=”match_parent” />

</LinearLayout>

 

3.AndroidManifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
package=”com.sample.test”
android:versionCode=”1″
android:versionName=”1.0″ >

<uses-sdk
android:minSdkVersion=”8″
android:targetSdkVersion=”17″ />

<application
android:allowBackup=”true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme” >
<activity
android:name=”com.sample.test.Test”
android:label=”@string/app_name” >
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>

</manifest>

Advertisements

Underling Text View in Android

There are three ways of underling the text in Text View.

  1. SpannableString

  2. setPaintFlags(); of TextView

  3. Html.fromHtml();

Let me explain you all approaches :

1st Approach

For underling the text in TextView you have to use SpannableString

String udata="Underlined Text";
SpannableString content = new SpannableString(udata);
content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
mTextView.setText(content);

2nd Approach

You can make use of setPaintFlags method of TextView to underline the text of TextView.

For eg.

mTextView.setPaintFlags(mTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTextView.setText("This text will be underlined");

You can refer constants of Paint class if you want to strike thru the text.

3rd Approach

Make use of Html.fromHtml(htmlString);

String htmlString="<u>This text will be underlined</u>";
mTextView.setText(Html.fromHtml(htmlString));

Multi Colors for Single Text view in Android

String your1stString=”Welcome”;
String your2ndString=”RAJA”;
String data=”<font COLOR=\”RED\”><b>” + your1stString + “</b></font> TO <font COLOR=#ff0000><b>” + your2ndString + “</b></font>”;

textviewobj.setText(Html.fromHtml(data));

BAR Code Generation in Java

Add the following jar into Class path and Lib folder in project

1.barcode.jar

Source Code:

package javapages4all;

import com.keepdynamic.barcode.generator.BarCode;

public class BARCodeGeneration {

/**
* @param args
*/
public static void main(String[] args)
{
try {
/**
* create BARCODE Class Object
*/
BarCode barcode = new BarCode();

/**
* set barcode properties
*/
barcode.setSymbologyType(BarCode.CODE128);
barcode.setCodeText(“Raja”);
/**
* disable Text displaying below Code
*/
barcode.setDisplayCodeText(false);

/**
* create image object
*/
java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(300,300,java.awt.image.BufferedImage.TYPE_BYTE_INDEXED );

/**
* get graphic context of image
*/
java.awt.Graphics2D imgGraphics = image.createGraphics();

/**
* draw barcode to specified location in Rectangle
*/
barcode.paintBarCode(imgGraphics, new java.awt.Rectangle(0, 0, 300, 300));
barcode.drawBarCode2Image(“/home/raja/Java/barimg.jpg”);
} catch (Exception e)
{
e.printStackTrace();
}

}

}

QR Code Generation in Java

Add the following jar into Class path and Lib folder in project

1.zxing-core-1.7.jar

2.qrgen-1.0.jar

3.zxing-j2se-1.7.jar

Source Code:

package javapages4all;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
public class QRCodeGeneration {

/**
* @param args
*/
public static void main(String[] args)
{
ByteArrayOutputStream out = QRCode.from(“Raja”).to(ImageType.PNG).stream();
try
{
/**
* set the output Image Location
*/
FileOutputStream fout = new FileOutputStream(new File(“/home/raja/Java/QR_Code_raja.JPG”));
fout.write(out.toByteArray());
fout.flush();
fout.close();

} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}

}

 

Install Team-viewer in Ubuntu

open Terminal. When it opens, run the command below to download Team Viewer deb package.

If you have 32-bit version of Ubuntu, run the commands below to download that version:

wget http://www.teamviewer.com/download/teamviewer_linux.deb

After downloading, run the commands below to install it.

sudo dpkg -i teamviewer_linux.deb

If you have 64-bit version of Ubuntu,run the commands below to download that version:


wget http://www.teamviewer.com/download/teamviewer_linux_x64.deb

Then run the commands below to install:

sudo dpkg -i teamviewer_linux_x64.deb

if u Want to Run Team Viewer than type below command on terminal

teamviewer

Show or Hide soft keyboard on opening a dialog or activity in android

For showing the soft keyboard on entering into the activity or to the dialog we can use this coding

Add the following code just before alert.show()

InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
input.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

for hiding keyboard
InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
input.hideSoftInputFromWindow(singleedittext.getWindowToken(),0);
%d bloggers like this: