http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Thursday, 29 August 2013
Thursday, 15 August 2013
Create buttons using shape
//create xml button_big_normal.xml
android:shape="rectangle"
android:useLevel="false">
android:color="#adadac"/>
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
android:shape="rectangle"
android:useLevel="false">
android:color="#000000"/>
android:color="#adadac"/>
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
Wednesday, 14 August 2013
create button using shape in android
http://stackoverflow.com/questions/2122199/how-do-i-set-the-rounded-corner-radius-of-a-color-drawable-using-xml
android:shape="rectangle">
android:startColor="#679a00"
android:endColor="#98cb00"
android:angle="90"/>
android:top="6dp"
android:right="6dp"
android:bottom="6dp" />
android:endColor="#98cb00"
android:angle="90"/>
android:right="6dp"
android:bottom="6dp" />
Sunday, 11 August 2013
shared preference android
SharedPreferences sp_Detail = getSharedPreferences(Constant.
SHAREDPREFERENCES
SharedPreferences.Editor spEdit_Event = sp_Detail.edit();
spEdit_.putString(Constant.
_ID, alst_Id.get(position));
spEdit_.putString(Constant.
_NAME, alst_Title.get(position));spEdit_.commit();
SharedPreferences ShareEvent = getSharedPreferences(Constant.
SHAREDPREFERENCES, MODE_WORLD_READABLE);strEventID = ShareEvent.getString(Constant.EVENT_ID,null);
SVN Use
// open eclips click hep => Install software =>
In Work with textview add
http://subclipse.tigris.org/update_1.6.x
Then click on select All => Next
After installing SVN right click on project=>Team=>Share project
and give path to svn(eg:http://192.168.2.201:8080/svn/asteroid_android/)
Click on file which you want to edit lock this file
After updating unlock this file
In Work with textview add
http://subclipse.tigris.org/update_1.6.x
Then click on select All => Next
After installing SVN right click on project=>Team=>Share project
and give path to svn(eg:http://192.168.2.201:8080/svn/asteroid_android/)
Click on file which you want to edit lock this file
After updating unlock this file
tab implementation in android
//create xml tab.xml
****************
xml version="1.0"
encoding="utf-8"?>****************
<
TabHost xmlns:android="http://schemas.android.com/apk/res/android"//Create java file HomeActivity.java
****************************
package com.mrs.abd;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
public class HomeActivity extends android.app.TabActivity implements OnTabChangeListener {
private TabHost tabHost = null;
private TextView txtHome = null,txtDoneer = null,txtDelen= null,txtOver = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tabs);
tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, ViewGroupOrganizer.class);
txtHome = new TextView(this);
txtHome.setTypeface(CommanClass.SetCustomFont(getResources()));
txtHome.setText(Constant.HOME_TAB_TEXT);
txtHome.setTextColor(getResources().getColor(R.color.White));
txtHome.setBackgroundResource(R.drawable.img_tab_home_selected);
txtHome.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
txtHome.setGravity(Gravity.CENTER);
spec = tabHost.newTabSpec(Constant.1_TAB_TEXT).setIndicator(txtHome).setContent(intent);
tabHost.addTab(spec);
txtDe = new TextView(this);
txtDe.setTypeface(CommanClass.SetCustomFont(getResources()));
txtDe.setText(Constant.2_TAB_TEXT);
txtDe.setTextColor(getResources().getColor(R.color.Black));
txtDe.setBackgroundResource(R.drawable.img_tab_doneer);
txtDe.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
txtDe.setGravity(Gravity.CENTER);
spec = tabHost.newTabSpec(Constant.3_TAB_TEXT).setIndicator(txtDelen).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Do.class);
txtDo = new TextView(this);
txtDo.setText(Constant.DO_TAB_TEXT);
txtDo.setTypeface(CommanClass.SetCustomFont(getResources()));
txtDo.setTextColor(getResources().getColor(R.color.Black));
txtDo.setBackgroundResource(R.drawable.img_tab_doneer);
txtDo.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
txtDo.setGravity(Gravity.CENTER);
spec = tabHost.newTabSpec(Constant.DOTAB_TEXT).setIndicator(txtDoneer).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Over.class);
txtO = new TextView(this);
txtO.setTypeface(CommanClass.SetCustomFont(getResources()));
txtO.setText(Constant.3_TAB_TEXT);
txtO.setTextColor(getResources().getColor(R.color.Black));
txtO.setBackgroundResource(R.drawable.img_tab_over);
txtO.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
txtO.setGravity(Gravity.CENTER);
spec = tabHost.newTabSpec(Constant.3_TAB_TEXT).setIndicator(txtOver).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(tabHost.getCurrentTab()==0)
{
while(true)
{
if (ViewGroupOrganizer.history.size() > 1)
{
ViewGroupOrganizer.history.remove(ViewGroupOrganizer.history.size() - 1);
ViewGroupOrganizer.group.setContentView(ViewGroupOrganizer.history.get(ViewGroupOrganizer.history.size() - 1));
}
else
{
break;
}
}
}
else
{
tabHost.setCurrentTab(0);
}
}
});
tabHost.getTabWidget().getChildAt(1).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
ShareAlertdialog();
}
});
tabHost.setOnTabChangedListener(this);
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This Dialog is used for show share dialog
*/
public void ShareAlertdialog() {
final CharSequence[] items = { Constant.FACEBOOK, Constant.TWITTER};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(Constant.SHARE_ALERT_DIALOG_TITLE);
builder.setNegativeButton(Constant.SHARE_CANCEL_BUTTON, null);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item == 0) {
if(CommanClass.CheckNetwork(HomeActivity.this)){
Intent mIntent = new Intent(HomeActivity.this,Share_On_Facebook.class);
mIntent.setAction(Constant.FACEBOOK_ACTION);
startActivity(mIntent);
}
} else if(item == 1) {
if(CommanClass.CheckNetwork(HomeActivity.this)){
Intent mIntent = new Intent(HomeActivity.this,Share_On_Twitter.class);
mIntent.setAction("");
startActivity(mIntent);
}
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onTabChanged(String tabId) {
if(tabId.equals(Constant.HOME_TAB_TEXT)){
txtHome.setBackgroundResource(R.drawable.img_tab_home_selected);
txtHome.setTypeface(CommanClass.SetCustomFont(getResources()));
txtHome.setTextColor(getResources().getColor(R.color.White));
}
else{
txtHome.setBackgroundResource(R.drawable.img_tab_home);
txtHome.setTypeface(CommanClass.SetCustomFont(getResources()));
txtHome.setTextColor(getResources().getColor(R.color.Black));
}
if(tabId.equals(Constant.DONEER_TAB_TEXT)){
txtDo.setBackgroundResource(R.drawable.img_tab_doneer_selected);
txtDo.setTypeface(CommanClass.SetCustomFont(getResources()));
txtDo.setTextColor(getResources().getColor(R.color.White));
}
else{
txtDo.setBackgroundResource(R.drawable.img_tab_doneer);
txtDo.setTypeface(CommanClass.SetCustomFont(getResources()));
txtDo.setTextColor(getResources().getColor(R.color.Black));
}
if(tabId.equals(Constant.4TAB_TEXT)){
txt4.setBackgroundResource(R.drawable.img_tab_doneer_selected);
txt4.setTypeface(CommanClass.SetCustomFont(getResources()));
txt4.setTextColor(getResources().getColor(R.color.White));
}
else{
txt4setBackgroundResource(R.drawable.img_tab_doneer);
txt4setTypeface(CommanClass.SetCustomFont(getResources()));
txt4setTextColor(getResources().getColor(R.color.Black));
}
if(tabId.equals(Constant.4TAB_TEXT)){
txt4setBackgroundResource(R.drawable.img_tab_4selected);
txt.setTypeface(CommanClass.SetCustomFont(getResources()));
txt4setTextColor(getResources().getColor(R.color.White));
}
else{
txt4setBackgroundResource(R.drawable.img_4over);
txt4setTypeface(CommanClass.SetCustomFont(getResources()));
txt4setTextColor(getResources().getColor(R.color.Black));
}
}
}
//code for Give space in tab
TabWidget widget = getTabWidget();
final int tabChildrenCount = widget.getChildCount();
LinearLayout.LayoutParams currentLayout;
for (int i_tab = 0; i_tab < tabChildrenCount; i_tab++) {
currentLayout = (LinearLayout.LayoutParams) widget
.getChildAt(i_tab).getLayoutParams();
if (i_tab == 0) {
currentLayout.setMargins(10, 0, 5, 0);
} else if (i_tab == (tabChildrenCount - 1)) {
currentLayout.setMargins(5, 0, 10, 0);
} else {
currentLayout.setMargins(5, 0, 5, 0);
}
currentLayout.height = 40;
}
widget.requestLayout();
Friday, 9 August 2013
image loader
package com.app.v3;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Debug;
import android.util.Log;
import android.widget.ImageView;
public class ImageLoader {
//the simplest in-memory cache implementation. This should be replaced with something like SoftReference or BitmapOptions.inPurgeable(since 1.6)
private HashMap
private File cacheDir;
private int defaultimage_id;
private Context mContext=null;
private boolean Strach=false;
private int Scale_Width=0;
private int Scale_Height=0;
public ImageLoader(Context context,int Defaultimage_id,int intidentifie,boolean strach,int Scale_Width,int Scale_Height){
this.mContext=context;
this.defaultimage_id=Defaultimage_id;
this.Strach=strach;
this.Scale_Width=Scale_Width;
this.Scale_Height=Scale_Height;
//Make the background thead low priority. This way it will not affect the UI performance
photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);
//Find the dir to save cached images
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
// Toast.makeText(context, "Mounted", Toast.LENGTH_SHORT).show();
if(intidentifie==1)
{ cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"SmallImageBuffer"); }
// else if(intidentifie==2)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"EventBigImageBuffer"); }
// else if(intidentifie==3)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Institute"); }
// else if(intidentifie==4)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Advertise"); }
}
else
{cacheDir=context.getCacheDir();}
if(!cacheDir.exists())
{cacheDir.mkdirs();}
}
public void DisplayImage(String strImagePath, ImageView imgImageView)
{
if(cache.containsKey(strImagePath))
{
if(Strach){
imgImageView.setBackgroundDrawable(new BitmapDrawable(cache.get(strImagePath)));
}
else{
imgImageView.setImageBitmap(cache.get(strImagePath));
}
}
else
{
queuePhoto(strImagePath, imgImageView);
if(Strach){
imgImageView.setBackgroundResource(defaultimage_id);
}
else{
imgImageView.setImageResource(defaultimage_id);
}
}
}
private void queuePhoto(String strImagePath, ImageView imgImageView)
{
//This ImageView may be used for other images before. So there may be some old tasks in the queue. We need to discard them.
photosQueue.Clean(imgImageView);
PhotoToLoad p=new PhotoToLoad(strImagePath, imgImageView);
synchronized(photosQueue.photosToLoad){
photosQueue.photosToLoad.push(p);
photosQueue.photosToLoad.notifyAll();
}
//start thread if it's not started yet
if(photoLoaderThread.getState()==Thread.State.NEW)
photoLoaderThread.start();
}
private Bitmap getBitmap(String strImagePath)
{
//I identify images by hashcode. Not a perfect solution, good for the demo.
String strFilename=String.valueOf(strImagePath.hashCode());
File mFile=new File(cacheDir, strFilename);
//from SD cache
Bitmap mBmp = CommanClass.DecodeFileGetBitmap(mContext, mFile.getAbsolutePath(),Scale_Width, Scale_Height);
if(mBmp!=null){
return mBmp;
}else{
//from web
try{
if(CommanClass.CheckNetwork(mContext))
{
InputStream mFileInputStream=new URL(strImagePath).openStream();
OutputStream mOutputStream = new FileOutputStream(mFile);
Utility.CopyStream(mFileInputStream, mOutputStream);
mOutputStream.close();
// mBitmap = DecodeFile(mFile);
return CommanClass.DecodeFileGetBitmap(mContext, mFile.getAbsolutePath(),Scale_Width, Scale_Height);
}
else
{
return null;
}
} catch (Exception e){
e.printStackTrace();
return null;
}
}
}
// //decodes image and scales it to reduce memory consumption
// private Bitmap DecodeFile(File mFile){
// try {
// // Get the dimensions of the bitmap
// BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
// bmpFactoryOptions.inJustDecodeBounds=true;
// BitmapFactory.decodeStream(new FileInputStream(mFile),null,bmpFactoryOptions);
//
// if ( checkBitmapFitsInMemory(bmpFactoryOptions.outWidth, bmpFactoryOptions.outHeight, 2)){
//// Log.w("Image Loader","Aborting bitmap load for avoiding memory crash");
//
// // Decode the image file into a Bitmap sized to fill the View
// bmpFactoryOptions.inJustDecodeBounds = false;
// bmpFactoryOptions.inPurgeable = true;
//
// Bitmap bitmapPostScale=ImageShrink(BitmapFactory.decodeStream(new FileInputStream(mFile),null,bmpFactoryOptions));
// return bitmapPostScale;
// }
// else{
// Log.w("Bitmap Load","Memory Crash");
// Runtime.getRuntime().gc();
// return null;
// }
// }
// catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// }
// //this function use for image large to small make
// private Bitmap ImageShrink(Bitmap bitmapPreScale){
// if(bitmapPreScale!=null){
// int oldWidth = bitmapPreScale.getWidth();
// int oldHeight = bitmapPreScale.getHeight();
// int newWidth = Scale_Width; // whatever your desired width and height are
// int newHeight = Scale_Height;
//
// // calculate the scale
// float scaleWidth = ((float) newWidth) / oldWidth;
// float scaleHeight = ((float) newHeight) / oldHeight;
//
// // create a matrix for the manipulation
// Matrix matrix = new Matrix();
// // resize the bit map
// matrix.postScale(scaleWidth, scaleHeight);
//
// // recreate the new Bitmap
// return Bitmap.createBitmap(bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true);
// }
// else{
// return null;
// }
//
// }
private boolean checkBitmapFitsInMemory(long bmpwidth,long bmpheight, int bmpdensity ){
long reqsize=bmpwidth*bmpheight*bmpdensity;
long allocNativeHeap = Debug.getNativeHeapAllocatedSize();
final long heapPad=(long) Math.max(4*1024*1024,Runtime.getRuntime().maxMemory()*0.1);
if ((reqsize + allocNativeHeap + heapPad) >= Runtime.getRuntime().maxMemory())
{
return false;
}
return true;
}
//Task for the queue
private class PhotoToLoad
{
public String strImagePath;
public ImageView mImageView;
public PhotoToLoad(String strImagePath, ImageView mImageView){
this.strImagePath=strImagePath;
this.mImageView=mImageView;
}
}
PhotosQueue photosQueue=new PhotosQueue();
public void stopThread()
{
photoLoaderThread.interrupt();
try {
photoLoaderThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//stores list of photos to download
class PhotosQueue
{
private Stack
//removes all instances of this ImageView
public void Clean(ImageView mImageV)
{
for(int j=0 ;j
if(photosToLoad.get(j).mImageView==mImageV)
photosToLoad.remove(j);
else
++j;
}
}
}
class PhotosLoader extends Thread {
public void run() {
try {
while(true)
{
//thread waits until there are any images to load in the queue
if(photosQueue.photosToLoad.size()==0)
synchronized(photosQueue.photosToLoad){
photosQueue.photosToLoad.wait();
}
if(photosQueue.photosToLoad.size()!=0)
{
PhotoToLoad photoToLoad;
synchronized(photosQueue.photosToLoad){
photoToLoad=photosQueue.photosToLoad.pop();
}
Bitmap bmp=getBitmap(photoToLoad.strImagePath);
cache.put(photoToLoad.strImagePath, bmp);
Object tag=photoToLoad.mImageView.getTag();
if(tag!=null && ((String)tag).equals(photoToLoad.strImagePath)){
BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad.mImageView);
Activity a=(Activity)photoToLoad.mImageView.getContext();
a.runOnUiThread(bd);
}
}
if(Thread.interrupted())
break;
}
} catch (InterruptedException e) {
//allow thread to exit
}
}
}
PhotosLoader photoLoaderThread=new PhotosLoader();
//Used to display bitmap in the UI thread
class BitmapDisplayer implements Runnable
{
Bitmap mBitmap;
ImageView mImageView;
public BitmapDisplayer(Bitmap mBmp, ImageView mImg)
{
this.mBitmap=mBmp;
this.mImageView=mImg;
}
public void run()
{
if(mBitmap!=null)
{
if(Strach){
mImageView.setBackgroundDrawable(new BitmapDrawable(mBitmap));
}
else{
mImageView.setImageBitmap(mBitmap);
}
}
else
{
if(Strach){
mImageView.setBackgroundResource(defaultimage_id);
}
else{
mImageView.setImageResource(defaultimage_id);
}
}
}
}
// public void clearCache() {
// //clear memory cache
//// Iterator it = cache.entrySet().iterator();
//// while (it.hasNext()) {
//// Map.Entry pairs = (Map.Entry)it.next();
//// if(cache.get(pairs.getKey())!=null){
//// cache.get(pairs.getKey()).recycle();
//// Bitmap mBitmap=null;
//// cache.put(pairs.getKey().toString(), mBitmap);
//// }
////// System.out.println(pairs.getKey() + " = " + pairs.getValue());
////// it.remove(); // avoids a ConcurrentModificationException
//// }
//
// cache.clear();
// //clear SD cache
// File[] mFilesArray = cacheDir.listFiles();
// for(File mFile:mFilesArray)
// mFile.delete();
// }
//
public void clearCache() {
try{
if(!cache.isEmpty()){
for (Map.Entry
try{
// Log.i(TAG,"Image Key = " + entry.getKey());
if(entry.getValue()!=null){
if(!entry.getValue().isRecycled()){
entry.getValue().recycle();
// entry.setValue(null);
System.gc();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
finally{
//clear memory cache
cache.clear();
//clear SD cache
DeleteCache();
}
}
private void DeleteCache(){
try{
File[] mFilesArray=cacheDir.listFiles();
for(File mFile:mFilesArray)
mFile.delete();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
package com.app.v3;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Debug;
import android.util.Log;
import android.widget.ImageView;
public class ImageLoader {
//the simplest in-memory cache implementation. This should be replaced with something like SoftReference or BitmapOptions.inPurgeable(since 1.6)
private HashMap
private File cacheDir;
private int defaultimage_id;
private Context mContext=null;
private boolean Strach=false;
private int Scale_Width=0;
private int Scale_Height=0;
public ImageLoader(Context context,int Defaultimage_id,int intidentifie,boolean strach,int Scale_Width,int Scale_Height){
this.mContext=context;
this.defaultimage_id=Defaultimage_id;
this.Strach=strach;
this.Scale_Width=Scale_Width;
this.Scale_Height=Scale_Height;
//Make the background thead low priority. This way it will not affect the UI performance
photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);
//Find the dir to save cached images
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
// Toast.makeText(context, "Mounted", Toast.LENGTH_SHORT).show();
if(intidentifie==1)
{ cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"SmallImageBuffer"); }
// else if(intidentifie==2)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"EventBigImageBuffer"); }
// else if(intidentifie==3)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Institute"); }
// else if(intidentifie==4)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Advertise"); }
}
else
{cacheDir=context.getCacheDir();}
if(!cacheDir.exists())
{cacheDir.mkdirs();}
}
public void DisplayImage(String strImagePath, ImageView imgImageView)
{
if(cache.containsKey(strImagePath))
{
if(Strach){
imgImageView.setBackgroundDrawable(new BitmapDrawable(cache.get(strImagePath)));
}
else{
imgImageView.setImageBitmap(cache.get(strImagePath));
}
}
else
{
queuePhoto(strImagePath, imgImageView);
if(Strach){
imgImageView.setBackgroundResource(defaultimage_id);
}
else{
imgImageView.setImageResource(defaultimage_id);
}
}
}
private void queuePhoto(String strImagePath, ImageView imgImageView)
{
//This ImageView may be used for other images before. So there may be some old tasks in the queue. We need to discard them.
photosQueue.Clean(imgImageView);
PhotoToLoad p=new PhotoToLoad(strImagePath, imgImageView);
synchronized(photosQueue.photosToLoad){
photosQueue.photosToLoad.push(p);
photosQueue.photosToLoad.notifyAll();
}
//start thread if it's not started yet
if(photoLoaderThread.getState()==Thread.State.NEW)
photoLoaderThread.start();
}
private Bitmap getBitmap(String strImagePath)
{
//I identify images by hashcode. Not a perfect solution, good for the demo.
String strFilename=String.valueOf(strImagePath.hashCode());
File mFile=new File(cacheDir, strFilename);
//from SD cache
Bitmap mBmp = CommanClass.DecodeFileGetBitmap(mContext, mFile.getAbsolutePath(),Scale_Width, Scale_Height);
if(mBmp!=null){
return mBmp;
}else{
//from web
try{
if(CommanClass.CheckNetwork(mContext))
{
InputStream mFileInputStream=new URL(strImagePath).openStream();
OutputStream mOutputStream = new FileOutputStream(mFile);
Utility.CopyStream(mFileInputStream, mOutputStream);
mOutputStream.close();
// mBitmap = DecodeFile(mFile);
return CommanClass.DecodeFileGetBitmap(mContext, mFile.getAbsolutePath(),Scale_Width, Scale_Height);
}
else
{
return null;
}
} catch (Exception e){
e.printStackTrace();
return null;
}
}
}
// //decodes image and scales it to reduce memory consumption
// private Bitmap DecodeFile(File mFile){
// try {
// // Get the dimensions of the bitmap
// BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
// bmpFactoryOptions.inJustDecodeBounds=true;
// BitmapFactory.decodeStream(new FileInputStream(mFile),null,bmpFactoryOptions);
//
// if ( checkBitmapFitsInMemory(bmpFactoryOptions.outWidth, bmpFactoryOptions.outHeight, 2)){
//// Log.w("Image Loader","Aborting bitmap load for avoiding memory crash");
//
// // Decode the image file into a Bitmap sized to fill the View
// bmpFactoryOptions.inJustDecodeBounds = false;
// bmpFactoryOptions.inPurgeable = true;
//
// Bitmap bitmapPostScale=ImageShrink(BitmapFactory.decodeStream(new FileInputStream(mFile),null,bmpFactoryOptions));
// return bitmapPostScale;
// }
// else{
// Log.w("Bitmap Load","Memory Crash");
// Runtime.getRuntime().gc();
// return null;
// }
// }
// catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// }
// //this function use for image large to small make
// private Bitmap ImageShrink(Bitmap bitmapPreScale){
// if(bitmapPreScale!=null){
// int oldWidth = bitmapPreScale.getWidth();
// int oldHeight = bitmapPreScale.getHeight();
// int newWidth = Scale_Width; // whatever your desired width and height are
// int newHeight = Scale_Height;
//
// // calculate the scale
// float scaleWidth = ((float) newWidth) / oldWidth;
// float scaleHeight = ((float) newHeight) / oldHeight;
//
// // create a matrix for the manipulation
// Matrix matrix = new Matrix();
// // resize the bit map
// matrix.postScale(scaleWidth, scaleHeight);
//
// // recreate the new Bitmap
// return Bitmap.createBitmap(bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true);
// }
// else{
// return null;
// }
//
// }
private boolean checkBitmapFitsInMemory(long bmpwidth,long bmpheight, int bmpdensity ){
long reqsize=bmpwidth*bmpheight*bmpdensity;
long allocNativeHeap = Debug.getNativeHeapAllocatedSize();
final long heapPad=(long) Math.max(4*1024*1024,Runtime.getRuntime().maxMemory()*0.1);
if ((reqsize + allocNativeHeap + heapPad) >= Runtime.getRuntime().maxMemory())
{
return false;
}
return true;
}
//Task for the queue
private class PhotoToLoad
{
public String strImagePath;
public ImageView mImageView;
public PhotoToLoad(String strImagePath, ImageView mImageView){
this.strImagePath=strImagePath;
this.mImageView=mImageView;
}
}
PhotosQueue photosQueue=new PhotosQueue();
public void stopThread()
{
photoLoaderThread.interrupt();
try {
photoLoaderThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//stores list of photos to download
class PhotosQueue
{
private Stack
//removes all instances of this ImageView
public void Clean(ImageView mImageV)
{
for(int j=0 ;j
if(photosToLoad.get(j).mImageView==mImageV)
photosToLoad.remove(j);
else
++j;
}
}
}
class PhotosLoader extends Thread {
public void run() {
try {
while(true)
{
//thread waits until there are any images to load in the queue
if(photosQueue.photosToLoad.size()==0)
synchronized(photosQueue.photosToLoad){
photosQueue.photosToLoad.wait();
}
if(photosQueue.photosToLoad.size()!=0)
{
PhotoToLoad photoToLoad;
synchronized(photosQueue.photosToLoad){
photoToLoad=photosQueue.photosToLoad.pop();
}
Bitmap bmp=getBitmap(photoToLoad.strImagePath);
cache.put(photoToLoad.strImagePath, bmp);
Object tag=photoToLoad.mImageView.getTag();
if(tag!=null && ((String)tag).equals(photoToLoad.strImagePath)){
BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad.mImageView);
Activity a=(Activity)photoToLoad.mImageView.getContext();
a.runOnUiThread(bd);
}
}
if(Thread.interrupted())
break;
}
} catch (InterruptedException e) {
//allow thread to exit
}
}
}
PhotosLoader photoLoaderThread=new PhotosLoader();
//Used to display bitmap in the UI thread
class BitmapDisplayer implements Runnable
{
Bitmap mBitmap;
ImageView mImageView;
public BitmapDisplayer(Bitmap mBmp, ImageView mImg)
{
this.mBitmap=mBmp;
this.mImageView=mImg;
}
public void run()
{
if(mBitmap!=null)
{
if(Strach){
mImageView.setBackgroundDrawable(new BitmapDrawable(mBitmap));
}
else{
mImageView.setImageBitmap(mBitmap);
}
}
else
{
if(Strach){
mImageView.setBackgroundResource(defaultimage_id);
}
else{
mImageView.setImageResource(defaultimage_id);
}
}
}
}
// public void clearCache() {
// //clear memory cache
//// Iterator it = cache.entrySet().iterator();
//// while (it.hasNext()) {
//// Map.Entry pairs = (Map.Entry)it.next();
//// if(cache.get(pairs.getKey())!=null){
//// cache.get(pairs.getKey()).recycle();
//// Bitmap mBitmap=null;
//// cache.put(pairs.getKey().toString(), mBitmap);
//// }
////// System.out.println(pairs.getKey() + " = " + pairs.getValue());
////// it.remove(); // avoids a ConcurrentModificationException
//// }
//
// cache.clear();
// //clear SD cache
// File[] mFilesArray = cacheDir.listFiles();
// for(File mFile:mFilesArray)
// mFile.delete();
// }
//
public void clearCache() {
try{
if(!cache.isEmpty()){
for (Map.Entry
try{
// Log.i(TAG,"Image Key = " + entry.getKey());
if(entry.getValue()!=null){
if(!entry.getValue().isRecycled()){
entry.getValue().recycle();
// entry.setValue(null);
System.gc();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
finally{
//clear memory cache
cache.clear();
//clear SD cache
DeleteCache();
}
}
private void DeleteCache(){
try{
File[] mFilesArray=cacheDir.listFiles();
for(File mFile:mFilesArray)
mFile.delete();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
package com.app.v3;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Debug;
import android.util.Log;
import android.widget.ImageView;
public class ImageLoader {
//the simplest in-memory cache implementation. This should be replaced with something like SoftReference or BitmapOptions.inPurgeable(since 1.6)
private HashMap
private File cacheDir;
private int defaultimage_id;
private Context mContext=null;
private boolean Strach=false;
private int Scale_Width=0;
private int Scale_Height=0;
public ImageLoader(Context context,int Defaultimage_id,int intidentifie,boolean strach,int Scale_Width,int Scale_Height){
this.mContext=context;
this.defaultimage_id=Defaultimage_id;
this.Strach=strach;
this.Scale_Width=Scale_Width;
this.Scale_Height=Scale_Height;
//Make the background thead low priority. This way it will not affect the UI performance
photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);
//Find the dir to save cached images
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
// Toast.makeText(context, "Mounted", Toast.LENGTH_SHORT).show();
if(intidentifie==1)
{ cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"SmallImageBuffer"); }
// else if(intidentifie==2)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"EventBigImageBuffer"); }
// else if(intidentifie==3)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Institute"); }
// else if(intidentifie==4)
// {cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Advertise"); }
}
else
{cacheDir=context.getCacheDir();}
if(!cacheDir.exists())
{cacheDir.mkdirs();}
}
public void DisplayImage(String strImagePath, ImageView imgImageView)
{
if(cache.containsKey(strImagePath))
{
if(Strach){
imgImageView.setBackgroundDrawable(new BitmapDrawable(cache.get(strImagePath)));
}
else{
imgImageView.setImageBitmap(cache.get(strImagePath));
}
}
else
{
queuePhoto(strImagePath, imgImageView);
if(Strach){
imgImageView.setBackgroundResource(defaultimage_id);
}
else{
imgImageView.setImageResource(defaultimage_id);
}
}
}
private void queuePhoto(String strImagePath, ImageView imgImageView)
{
//This ImageView may be used for other images before. So there may be some old tasks in the queue. We need to discard them.
photosQueue.Clean(imgImageView);
PhotoToLoad p=new PhotoToLoad(strImagePath, imgImageView);
synchronized(photosQueue.photosToLoad){
photosQueue.photosToLoad.push(p);
photosQueue.photosToLoad.notifyAll();
}
//start thread if it's not started yet
if(photoLoaderThread.getState()==Thread.State.NEW)
photoLoaderThread.start();
}
private Bitmap getBitmap(String strImagePath)
{
//I identify images by hashcode. Not a perfect solution, good for the demo.
String strFilename=String.valueOf(strImagePath.hashCode());
File mFile=new File(cacheDir, strFilename);
//from SD cache
Bitmap mBmp = CommanClass.DecodeFileGetBitmap(mContext, mFile.getAbsolutePath(),Scale_Width, Scale_Height);
if(mBmp!=null){
return mBmp;
}else{
//from web
try{
if(CommanClass.CheckNetwork(mContext))
{
InputStream mFileInputStream=new URL(strImagePath).openStream();
OutputStream mOutputStream = new FileOutputStream(mFile);
Utility.CopyStream(mFileInputStream, mOutputStream);
mOutputStream.close();
// mBitmap = DecodeFile(mFile);
return CommanClass.DecodeFileGetBitmap(mContext, mFile.getAbsolutePath(),Scale_Width, Scale_Height);
}
else
{
return null;
}
} catch (Exception e){
e.printStackTrace();
return null;
}
}
}
// //decodes image and scales it to reduce memory consumption
// private Bitmap DecodeFile(File mFile){
// try {
// // Get the dimensions of the bitmap
// BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
// bmpFactoryOptions.inJustDecodeBounds=true;
// BitmapFactory.decodeStream(new FileInputStream(mFile),null,bmpFactoryOptions);
//
// if ( checkBitmapFitsInMemory(bmpFactoryOptions.outWidth, bmpFactoryOptions.outHeight, 2)){
//// Log.w("Image Loader","Aborting bitmap load for avoiding memory crash");
//
// // Decode the image file into a Bitmap sized to fill the View
// bmpFactoryOptions.inJustDecodeBounds = false;
// bmpFactoryOptions.inPurgeable = true;
//
// Bitmap bitmapPostScale=ImageShrink(BitmapFactory.decodeStream(new FileInputStream(mFile),null,bmpFactoryOptions));
// return bitmapPostScale;
// }
// else{
// Log.w("Bitmap Load","Memory Crash");
// Runtime.getRuntime().gc();
// return null;
// }
// }
// catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// }
// //this function use for image large to small make
// private Bitmap ImageShrink(Bitmap bitmapPreScale){
// if(bitmapPreScale!=null){
// int oldWidth = bitmapPreScale.getWidth();
// int oldHeight = bitmapPreScale.getHeight();
// int newWidth = Scale_Width; // whatever your desired width and height are
// int newHeight = Scale_Height;
//
// // calculate the scale
// float scaleWidth = ((float) newWidth) / oldWidth;
// float scaleHeight = ((float) newHeight) / oldHeight;
//
// // create a matrix for the manipulation
// Matrix matrix = new Matrix();
// // resize the bit map
// matrix.postScale(scaleWidth, scaleHeight);
//
// // recreate the new Bitmap
// return Bitmap.createBitmap(bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true);
// }
// else{
// return null;
// }
//
// }
private boolean checkBitmapFitsInMemory(long bmpwidth,long bmpheight, int bmpdensity ){
long reqsize=bmpwidth*bmpheight*bmpdensity;
long allocNativeHeap = Debug.getNativeHeapAllocatedSize();
final long heapPad=(long) Math.max(4*1024*1024,Runtime.getRuntime().maxMemory()*0.1);
if ((reqsize + allocNativeHeap + heapPad) >= Runtime.getRuntime().maxMemory())
{
return false;
}
return true;
}
//Task for the queue
private class PhotoToLoad
{
public String strImagePath;
public ImageView mImageView;
public PhotoToLoad(String strImagePath, ImageView mImageView){
this.strImagePath=strImagePath;
this.mImageView=mImageView;
}
}
PhotosQueue photosQueue=new PhotosQueue();
public void stopThread()
{
photoLoaderThread.interrupt();
try {
photoLoaderThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//stores list of photos to download
class PhotosQueue
{
private Stack
//removes all instances of this ImageView
public void Clean(ImageView mImageV)
{
for(int j=0 ;j
if(photosToLoad.get(j).mImageView==mImageV)
photosToLoad.remove(j);
else
++j;
}
}
}
class PhotosLoader extends Thread {
public void run() {
try {
while(true)
{
//thread waits until there are any images to load in the queue
if(photosQueue.photosToLoad.size()==0)
synchronized(photosQueue.photosToLoad){
photosQueue.photosToLoad.wait();
}
if(photosQueue.photosToLoad.size()!=0)
{
PhotoToLoad photoToLoad;
synchronized(photosQueue.photosToLoad){
photoToLoad=photosQueue.photosToLoad.pop();
}
Bitmap bmp=getBitmap(photoToLoad.strImagePath);
cache.put(photoToLoad.strImagePath, bmp);
Object tag=photoToLoad.mImageView.getTag();
if(tag!=null && ((String)tag).equals(photoToLoad.strImagePath)){
BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad.mImageView);
Activity a=(Activity)photoToLoad.mImageView.getContext();
a.runOnUiThread(bd);
}
}
if(Thread.interrupted())
break;
}
} catch (InterruptedException e) {
//allow thread to exit
}
}
}
PhotosLoader photoLoaderThread=new PhotosLoader();
//Used to display bitmap in the UI thread
class BitmapDisplayer implements Runnable
{
Bitmap mBitmap;
ImageView mImageView;
public BitmapDisplayer(Bitmap mBmp, ImageView mImg)
{
this.mBitmap=mBmp;
this.mImageView=mImg;
}
public void run()
{
if(mBitmap!=null)
{
if(Strach){
mImageView.setBackgroundDrawable(new BitmapDrawable(mBitmap));
}
else{
mImageView.setImageBitmap(mBitmap);
}
}
else
{
if(Strach){
mImageView.setBackgroundResource(defaultimage_id);
}
else{
mImageView.setImageResource(defaultimage_id);
}
}
}
}
// public void clearCache() {
// //clear memory cache
//// Iterator it = cache.entrySet().iterator();
//// while (it.hasNext()) {
//// Map.Entry pairs = (Map.Entry)it.next();
//// if(cache.get(pairs.getKey())!=null){
//// cache.get(pairs.getKey()).recycle();
//// Bitmap mBitmap=null;
//// cache.put(pairs.getKey().toString(), mBitmap);
//// }
////// System.out.println(pairs.getKey() + " = " + pairs.getValue());
////// it.remove(); // avoids a ConcurrentModificationException
//// }
//
// cache.clear();
// //clear SD cache
// File[] mFilesArray = cacheDir.listFiles();
// for(File mFile:mFilesArray)
// mFile.delete();
// }
//
public void clearCache() {
try{
if(!cache.isEmpty()){
for (Map.Entry
try{
// Log.i(TAG,"Image Key = " + entry.getKey());
if(entry.getValue()!=null){
if(!entry.getValue().isRecycled()){
entry.getValue().recycle();
// entry.setValue(null);
System.gc();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
finally{
//clear memory cache
cache.clear();
//clear SD cache
DeleteCache();
}
}
private void DeleteCache(){
try{
File[] mFilesArray=cacheDir.listFiles();
for(File mFile:mFilesArray)
mFile.delete();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
// create another class package com.app.v3;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import com.google.analytics.tracking.android.GAServiceManager;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class List extends ListActivity implements OnClickListener {
String item;
String id;
String img;
int intposition;
private String strFilePath = null;
// private int height;
// private int width;
// static String urrl="http://dev4php.com/uni_fr/fetchall.php";
static String urrl = "http://designer24.ch/kundencenter/uni-fr/webinterface/fetchall.php";
ArrayList
ArrayList
ArrayList
ArrayList
ArrayList
ArrayList
ArrayList
private Button imgDownloadList = null;
private String VIDEO_DOWNLOAD_LIST = "VideoDownloadList";
private String VIDEO_DETAIL_LIST = "VideoDetailList";
private ImageButton imgBack = null;
private int mPosition = -1;
//private int pos = -1;
private LinearLayout lytContent = null;
private LinearLayout lytImage = null;
private GoogleAnalytics GA_instant = null;
private Tracker tracker = null;
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
item = getIntent().getStringExtra("items");
id = getIntent().getStringExtra("id");
img = getIntent().getStringExtra("imgs");
intposition = getIntent().getIntExtra("position", 0);
GA_instant = GoogleAnalytics.getInstance(this);
tracker = GA_instant.getTracker(Constants.GOOGLE_ANALYTICS.GOOGLE_ANALYTICS_ID);
GAServiceManager.getInstance().setDispatchPeriod(30);
GA_instant.setDebug(true);
// item=getIntent().getStringArrayListExtra("items");
// ids=getIntent().getStringArrayListExtra("ids");
// imgs=getIntent().getStringArrayListExtra("imgs");
// position=getIntent().getIntExtra("position", 0);
TextView tvSubHeading = (TextView)findViewById(R.id.tvSubHeading);
tvSubHeading.setText(item);
ImageButton ib = (ImageButton) findViewById(R.id.ImageButton1);
ib.setOnClickListener(this);
imgDownloadList = (Button)findViewById(R.id.ImgDownloadList);
imgDownloadList.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent mIntentDownload = new Intent(List.this,VideoDownloadList.class);
View view = ViewGroupOrganizer.group.getLocalActivityManager().startActivity(VIDEO_DOWNLOAD_LIST,mIntentDownload.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
ViewGroupOrganizer.group.replaceView(view);
}
});
/*
* try{ java.net.URL website=new java.net.URL(fullURL); SAXParserFactory
* spf=SAXParserFactory.newInstance(); SAXParser sp=spf.newSAXParser();
* XMLReader xr=sp.getXMLReader(); Handling work=new Handling();
* work.setid("0"); work.setcatid(id); xr.setContentHandler(work);
* xr.parse(new InputSource(website.openStream())); name=work.getname();
* type=work.gettype(); ans=work.getans(); //tv.setText(ans.toString());
*
* }catch(Exception e2){ tv.setText("Error:"+e2); }
*/
/*
*
* SharedPreferences prefs=getPreferences(MODE_PRIVATE); int
* flag=prefs.getInt("flag_"+id, 0); if(flag==0){ new
* MyAsyncTask().execute(); } else{ for(int
* i=0;i
* name.add(prefs.getString("name_"+id+"_"+i, "")); } for(int
* i=0;i
* type.add(prefs.getString("type_"+id+"_"+i, "")); } for(int
* i=0;i
* ans.add(prefs.getString("ans_"+id+"_"+i, "")); } setListAdapter(new
* CusAd(this)); }
*/
// setListAdapter(new CusAd(this));
}
@Override
protected void onStart() {
tracker.sendView("/Video Play");
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
int flag = prefs.getInt("flag_" + id, 0);
String s = ((MyApplication)this.getApplication()).fl;
if (s.equals("1")) {
SharedPreferences.Editor pref = getPreferences(MODE_PRIVATE).edit();
ids = getIntent().getStringArrayListExtra("ids");
System.out.println("ids=="+ids);
for (int i = 0; i < ids.size(); i++) {
pref.putInt("flag_" + ids.get(i), 0);
}
pref.commit();
new MyAsyncTask().execute();
((MyApplication) this.getApplication()).fl = "0";
} else if (flag == 0) {
new MyAsyncTask().execute();
} else {
for (int i = 0; i < prefs.getInt("name_size_" + id, 0); i++) {
name.add(prefs.getString("name_" + id + "_" + i, ""));
}
for (int i = 0; i < prefs.getInt("type_size_" + id, 0); i++) {
type.add(prefs.getString("type_" + id + "_" + i, ""));
}
for (int i = 0; i < prefs.getInt("ans_size_" + id, 0); i++) {
ans.add(prefs.getString("ans_" + id + "_" + i, ""));
}
for (int i = 0; i < prefs.getInt("anshd_size_" + id, 0); i++) {
anshd.add(prefs.getString("anshd_" + id + "_" + i, ""));
}
for (int i = 0; i < prefs.getInt("imgs_size_" + id, 0); i++) {
imgs.add(prefs.getString("imgs_" + id + "_" + i, ""));
}
for (int i = 0; i < prefs.getInt("imgtext_size_" + id, 0); i++) {
imgtext.add(prefs.getString("imgtext_" + id + "_" + i, null));
}
setListAdapter(new CusAd(this));
}
super.onStart();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
SharedPreferences.Editor prefs = getPreferences(MODE_PRIVATE).edit();
prefs.putInt("flag_" + id, 0);
prefs.commit();
((MyApplication) this.getApplication()).setVariable("1");
super.onRestart();
}
private ProgressDialog mProgressDialogMyAsync = null;
private class MyAsyncTask extends AsyncTask
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressDialogMyAsync = ProgressDialog.show(ViewGroupOrganizer.group, "Loading...","Daten werden geladen...");
mProgressDialogMyAsync.setCancelable(false);
mProgressDialogMyAsync.setCanceledOnTouchOutside(false);
}
@Override
protected Void doInBackground(Void... params) {
String fullURL = urrl.toString();
try {
java.net.URL website = new java.net.URL(fullURL);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
Handling work = new Handling();
work.setid("0");
work.setcatid(id);
xr.setContentHandler(work);
InputSource is = new InputSource(website.openStream());
is.setEncoding("UTF-8");
xr.parse(is);
name = work.getname();
type = work.gettype();
ans = work.getans();
anshd = work.getanshd();
imgs = work.getimgs2();
imgtext = work.getimgtext();
// if(anshd!=null)
// Log.i("log_tag", "anshd is not null "+anshd.size());
// else Log.i("log_tag", "anshd is null ");
for (int i = 0; i < name.size(); i++) {
Log.i("log_tag", "name: "+name.get(i));
Log.i("log_tag", "type: "+type.get(i));
Log.i("log_tag", "ans: "+ans.get(i));
Log.i("log_tag", "anshd: "+anshd.get(i));
Log.i("log_tag", "imgs: "+imgs.get(i));
Log.i("log_tag", "imgtext: "+imgtext.get(i));
}
SharedPreferences.Editor prefs = getPreferences(MODE_PRIVATE)
.edit();
prefs.putInt("flag_" + id, 1);
prefs.putInt("name_size_" + id, name.size());
for (int i = 0; i < name.size(); i++) {
prefs.putString("name_" + id + "_" + i, name.get(i));
}
prefs.putInt("type_size_" + id, type.size());
for (int i = 0; i < type.size(); i++) {
prefs.putString("type_" + id + "_" + i, type.get(i));
}
prefs.putInt("ans_size_" + id, ans.size());
for (int i = 0; i < ans.size(); i++) {
prefs.putString("ans_" + id + "_" + i, ans.get(i));
}
prefs.putInt("anshd_size_" + id, anshd.size());
for (int i = 0; i < anshd.size(); i++) {
prefs.putString("anshd_" + id + "_" + i, anshd.get(i));
}
prefs.putInt("imgs_size_" + id, imgs.size());
for (int i = 0; i < imgs.size(); i++) {
prefs.putString("imgs_" + id + "_" + i, imgs.get(i));
// Log.d("imgs", imgs.get(i));
}
prefs.putInt("imgtext_size_" + id, imgtext.size());
for (int i = 0; i < imgtext.size(); i++) {
prefs.putString("imgtext_" + id + "_" + i, imgtext.get(i));
// Log.d("imgs", imgs.get(i));
}
prefs.commit();
// tv.setText(work.getInfo());
} catch (Exception e2) {
// tv.setText("Error:" + e2);
if(!Internet_Check.checkInternetConnection(ViewGroupOrganizer.group))
{
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(List.this, getResources().getString(R.string.internet_error_msg), Toast.LENGTH_SHORT).show();
}
});
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// a=false;
try
{
mProgressDialogMyAsync.dismiss();
}catch (Exception e) {
// TODO: handle exception
}
try
{
setListAdapter(new List.CusAd(getParent()));
}catch (Exception e) {
}
// setListAdapter(new The.MyAsyncTask.CustAdap(getParent()));
}
}
//Base adapter for show List activity data
private class CusAd extends BaseAdapter {
private LayoutInflater mLayoutInflater;
private int fixWidth,fixHeight;
private Context mContext = null;
public ImageLoader mImageLoader=null;
public CusAd(Context mContext) {
this.mContext = mContext;
this.mLayoutInflater = LayoutInflater.from(mContext);
this.mImageLoader=new ImageLoader(mContext,R.drawable.detailbg_video_ic,1,false,CommanClass.getImageDIP(getApplicationContext(), 85),CommanClass.getImageDIP(getApplicationContext(), 85));
// BitmapFactory.Options bfo = new BitmapFactory.Options();
// bfo.inJustDecodeBounds = true;
// BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher,bfo);
// fixWidth = bfo.outWidth;
// fixHeight = bfo.outHeight;
}
public int getCount() {
// TODO Auto-generated method stub
return name.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
System.out.println("getview "+position+" "+convertView);
ViewHolder holder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.custom_list_row_video, null);
// convertView.setLayoutParams(new LayoutParams(width,
// height/8));
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.title);
holder.image = (ImageView) convertView.findViewById(R.id.image);
holder.descrp = (TextView) convertView.findViewById(R.id.descrp);
holder.lytContent = (LinearLayout)convertView.findViewById(R.id.lyt_content);
holder.lytContent.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//CheckNetworkStatus(position);
//DisplayInfoDialog(position);
Intent mIntentDownload = new Intent(List.this,VideoDetailList.class);
mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_ID, id);
mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_TYPE, type.get(position));
mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_TITLE, name.get(position));
mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_IMG,imgs.get(position));
mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_DESC,imgtext.get(position));
mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_SMALL, ans.get(position));
mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_HD, anshd.get(position));
startActivity(mIntentDownload);
// View view = ViewGroupOrganizer.group.getLocalActivityManager().startActivity(VIDEO_DETAIL_LIST,mIntentDownload.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
//ViewGroupOrganizer.group.replaceView(view);
}
});
// holder.lytImage = (LinearLayout)convertView.findViewById(R.id.lytImage);
// holder.lytImage.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// //CheckNetworkStatus(position);
// //DisplayInfoDialog(position);
// Intent mIntentDownload = new Intent(List.this,VideoDetailList.class);
// mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_ID, id);
// mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_TYPE, type.get(position));
// mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_TITLE, name.get(position));
// mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_IMG,imgs.get(position));
// mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_DESC,imgtext.get(position));
// mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_SMALL, ans.get(position));
// mIntentDownload.putExtra(Constants.DETAIL_VIDEO_INTENT.KEY_VIDEO_HD, anshd.get(position));
// View view = ViewGroupOrganizer.group.getLocalActivityManager().startActivity(VIDEO_DETAIL_LIST,mIntentDownload.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
// ViewGroupOrganizer.group.replaceView(view);
// }
// });
// holder.imgDownload = (ImageView)convertView.findViewById(R.id.imgDownload);
// holder.imgDownload.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
//
// boolean DownloadStatus=false;
//
// OpenDatabase();
// DownloadStatus=mDbHelper.SearchDuplicateDownloadVideo(mSQLiteDatabase, id,name.get(position).toString().trim());
// CloseDataBase();
//
// if(DownloadStatus){
// SearchDuplicateDialog();
// //Toast.makeText(mContext, Html.fromHtml(Constants.DOWNLOAD.RECORD_DUPLICATE_MESSAGE),Toast.LENGTH_LONG).show();
// }
// else{
// if(CommanClass.isTablet(List.this))
// {
// intFileName = anshd.get(position).toString().hashCode();
// System.out.println("strFileName=="+intFileName);
// mPosition = position;
// DownloadVideoDialog();
// }
// else{
// intFileName = ans.get(position).toString().hashCode();
// System.out.println("strFileName=="+intFileName);
// mPosition = position;
// DownloadVideoDialog();
// }
// }
// }
// });
// holder.imgInfo = (ImageView)convertView.findViewById(R.id.imgInfo);
// holder.imgInfo.setOnClickListener(new OnClickListener() {
//
// public void onClick(View v) {
// DisplayInfoDialog(position);
// }
// });
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(Html.fromHtml(name.get(position)==null?"null":name.get(position)).toString());
holder.descrp.setText(Html.fromHtml(imgtext.get(position)==null?"null":imgtext.get(position)).toString());
// holder.image.getLayoutParams().width=fixWidth;
// holder.image.getLayoutParams().height=fixHeight;
holder.image.setTag(imgs.get(position));
if(CommanClass.MemoryCardCheck())
{
mImageLoader.DisplayImage(imgs.get(position), holder.image);
}
holder.image.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
tracker.sendEvent(Constants.GOOGLE_ANALYTICS.PLAY_VIDEO, Constants.GOOGLE_ANALYTICS.PLAY, Constants.GOOGLE_ANALYTICS.VIDEO_DOWNLOAD_LOG, (long) 0);
CheckNetworkStatus(position);
}
});
// holder.image.setImageResource(R.drawable.bg);
// UrlImageViewHelper.setUrlDrawable(holder.image, imgs.get(position));
// Drawable
// d=LoadImageFromWebOperations("http://designer24.ch/kundencenter/uni-fr/webinterface/videos/7.jpg");
// Log.d("List2", imgs.get(position));
// Drawable d=LoadImageFromWebOperations(imgs.get(position));
// holder.image.setImageDrawable(d);
return convertView;
}
// private Drawable LoadImageFromWebOperations(String url) {
// Log.d("List", url);
// try {
// InputStream is = (InputStream) new URL(url).getContent();
// Drawable d = Drawable.createFromStream(is, "src name");
// return d;
// } catch (Exception e) {
// System.out.println("Exc=" + e);
// return null;
// }
// }
public class ViewHolder {
TextView title;
TextView descrp;
ImageView image;
ImageView imgDownload;
ImageView imgInfo;
LinearLayout lytContent;
}
}
/*//******************************************************************************************************************
// Alert dialog for download
private void DownloadVideoDialog() {
AlertDialog mAlertDialog = new AlertDialog.Builder(ViewGroupOrganizer.group).create();
mAlertDialog.setTitle(Constants.DOWNLOAD.DOWNLOAD);
mAlertDialog.setIcon(R.drawable.ic_download);
mAlertDialog.setMessage(Constants.DOWNLOAD.DOWNLOAD_MASSAGE);
mAlertDialog.setButton(Constants.DOWNLOAD.DIALOG_BUTTON_YES, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(CommanClass.isTablet(List.this))
{
new DownloadVideo().execute(anshd.get(mPosition).toString());
}
else
{
new DownloadVideo().execute(ans.get(mPosition).toString());
}
dialog.cancel();
}
});
mAlertDialog.setButton2(Constants.DOWNLOAD.DIALOG_BUTTON_NO, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
mAlertDialog.show();
}
*/
public void onClick(View v) {
if (v.getId() == R.id.ImageButton1) {
// Intent i=new Intent(this,MainActivity.class);
// startActivity(i);
ViewGroupOrganizer.group.back();
}
}
// //******************************************************************************************************************************
// //For Download Video file
// private int intFileName;
// private ProgressDialog mProgressDialog = null;
// int progress = 0;
// private class DownloadVideo extends AsyncTask
// boolean Status=false, inPostExecute = false;
// protected void onPreExecute() {
// Status = true;
// mProgressDialog = new ProgressDialog(ViewGroupOrganizer.group);
// mProgressDialog.setCancelable(true);
// mProgressDialog.setCanceledOnTouchOutside(false);
// mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// mProgressDialog.setMessage(Constants.DOWNLOAD.DOWNLOADING_MESSAGE);
// mProgressDialog.setOnDismissListener(new OnDismissListener() {
// public void onDismiss(DialogInterface dialog) {
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
// if(inPostExecute == false){
// Status = false;
// }
// if (!(DownloadVideo.this.isCancelled())) {
// DownloadVideo.this.cancel(true);
// if(CommanClass.MemoryCardCheck() && Status == false){
// if(new File(Constants.PLAY_VIDEO.VIDEO_PATH + intFileName+".mp4").exists()){
// new File(Constants.PLAY_VIDEO.VIDEO_PATH + intFileName+".mp4").delete();
// }
// }
// }
// }
// });
// mProgressDialog.show();
// //For set screen orientation
// int currentOrientation = getResources().getConfiguration().orientation;
// if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
// }
// else {
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
// }
// super.onPreExecute();
// }
// protected Boolean doInBackground(String... MP3URL) {
// if(CommanClass.MemoryCardCheck())
// {
// int count;
// try{
// URL url = new URL(MP3URL[0]);
// URLConnection conexion = url.openConnection();
// conexion.connect();
//
// File VideoDirectory = new File(Constants.DOWNLOAD.SDCARD_VIDEO_URL);
// if(!VideoDirectory.exists()){
// VideoDirectory.mkdir();
// }
// int lenghtOfFile = conexion.getContentLength();
// InputStream mInputStream=CommanClass.OpenHttpConnectionPost(MP3URL[0]);
// FileOutputStream fos = new FileOutputStream(VideoDirectory + "/video_" + intFileName+".mp4");
// byte data[] = new byte[1024];
// long total = 0;
// while ((count = mInputStream.read(data)) != -1 && Status) {
// total += count;
// publishProgress((int)((total*100)/lenghtOfFile));
// fos.write(data, 0, count);
// }
// fos.close();
// mInputStream.close();
// }
// catch (Exception e) {
// e.printStackTrace();
// Status=false;
// }
// }
// else{
// Status=false;
// }
// return Status;
// }
//
// *//** This callback method is invoked when publishProgress()
// * method is called *//*
// @Override
// protected void onProgressUpdate(Integer... values) {
// super.onProgressUpdate(values);
// mProgressDialog.setProgress(values[0]);
// }
//
// protected void onPostExecute(Boolean result) {
// if(result){
// inPostExecute = true;
// Toast.makeText(List.this,Html.fromHtml(Constants.DOWNLOAD.DOWNLOADING_MESSAGE), Toast.LENGTH_SHORT).show();
//
// if(CommanClass.isTablet(List.this))
// {
// OpenDatabase();
// mDbHelper.INSERT_DOWNLOAD_VIDEO(mSQLiteDatabase, id,name.get(mPosition).toString(),intFileName+".mp4",type.get(mPosition).toString(),imgs.get(mPosition).toString(),imgtext.get(mPosition).toString(),anshd.get(mPosition).toString());
// CloseDataBase();
// }
// else{
// OpenDatabase();
// mDbHelper.INSERT_DOWNLOAD_VIDEO(mSQLiteDatabase, id,name.get(mPosition).toString(),intFileName+".mp4",type.get(mPosition).toString(),imgs.get(mPosition).toString(),imgtext.get(mPosition).toString(),ans.get(mPosition).toString());
// CloseDataBase();
// }
//
// }
// else{
// if(CommanClass.MemoryCardCheck()){
// if(new File(Constants.PLAY_VIDEO.VIDEO_PATH + intFileName+".mp4").exists()){
// new File(Constants.PLAY_VIDEO.VIDEO_PATH + intFileName+".mp4").delete();
// }
// }
// Toast.makeText(List.this,Html.fromHtml(Constants.DOWNLOAD.NOT_DOWNLOAD), Toast.LENGTH_SHORT).show();
// }
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
// mProgressDialog.dismiss();
// super.onPostExecute(result);
// }
// }
// For play Video on click of perticular list item
public void CheckNetworkStatus(int position){
Intent mintent = new Intent(List.this, VideoPlay.class);
mintent.putExtra(Constants.PLAY_VIDEO_INTENT.KEY_ID, id);
mintent.putExtra(Constants.PLAY_VIDEO_INTENT.KEY_VIDEO_TYPE, type.get(position));
mintent.putExtra(Constants.PLAY_VIDEO_INTENT.KEY_VIDEO_TITLE, name.get(position));
mintent.putExtra(Constants.PLAY_VIDEO_INTENT.KEY_VIDEO_IMG, imgs.get(position));
mintent.putExtra(Constants.PLAY_VIDEO_INTENT.KEY_VIDEO_DESC, imgtext.get(position));
mintent.putExtra(Constants.PLAY_VIDEO_INTENT.KEY_VIDEO_SMALL, ans.get(position));
mintent.putExtra(Constants.PLAY_VIDEO_INTENT.KEY_VIDEO_HD, anshd.get(position));
mintent.setAction(Constants.PLAY_VIDEO.PLAY_LIST_VEDIO);
final ConnectivityManager mConnectivityManager = (ConnectivityManager) List.this.getSystemService(Context.CONNECTIVITY_SERVICE);
if(mConnectivityManager!=null){
// final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
// final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
android.net.NetworkInfo mobile = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
android.net.NetworkInfo wifi = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifi.getState() == android.net.NetworkInfo.State.CONNECTED
wifi.getState() == android.net.NetworkInfo.State.CONNECTING) {
if(CommanClass.isTablet(List.this))
{
Log.e("log_tag=", "device is hd.");
Log.e("anshd=", anshd.get(position));
mintent.putExtra(Constants.PLAY_VIDEO.LIST_VIDEO_KEY, anshd.get(position).toString());
startActivity(mintent);
//intent.setDataAndType(Uri.parse(anshd.get(position).toString()), "video/*");
}
else
{
Log.e("log_tag", "device is not hd.");
Log.e("ans=", ans.get(position));
mintent.putExtra(Constants.PLAY_VIDEO.LIST_VIDEO_KEY, ans.get(position).toString());
startActivity(mintent);
// intent.setDataAndType(Uri.parse(ans.get(position).toString()), "video/*");
}
} else{
if(mobile != null){
if (mobile.getState() == android.net.NetworkInfo.State.CONNECTED
mobile.getState() == android.net.NetworkInfo.State.CONNECTING) {
mintent.putExtra(Constants.PLAY_VIDEO.LIST_VIDEO_KEY, ans.get(position).toString());
startActivity(mintent);
}
else{
Toast.makeText(this, "Network connection is not available.", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(this, "Network connection is not available.", Toast.LENGTH_LONG).show();
}
}
}
}
// //custom Dialog for show info dialog
// private Dialog mDialog = null;
// private void DisplayInfoDialog(final int position){
// mDialog = new Dialog(ViewGroupOrganizer.group);
// mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// mDialog.setCancelable(true);
// mDialog.setContentView(R.layout.xinfo_custom_dialog);
// mDialog.setCanceledOnTouchOutside(false);
// TextView txtTitle = (TextView)mDialog.findViewById(R.id.txtTitle);
// txtTitle.setText(name.get(position).toString());
// ImageView imgCancel = (ImageView)mDialog.findViewById(R.id.imgCancel);
// imgCancel.setOnClickListener(new OnClickListener() {
//
// public void onClick(View v) {
// mDialog.dismiss();
// }
// });
// TextView txtInfo = (TextView)mDialog.findViewById(R.id.txtInfo);
// txtInfo.setText(imgtext.get(position).toString());
//
// Button btnPlay = (Button)mDialog.findViewById(R.id.btnPlay);
// btnPlay.setOnClickListener(new OnClickListener() {
//
// public void onClick(View v) {
// CheckNetworkStatus(position);
// }
// });
//
// Button btnDownload = (Button)mDialog.findViewById(R.id.btnDownload);
// btnDownload.setOnClickListener(new OnClickListener() {
//
// public void onClick(View v) {
//
// boolean DownloadStatus=false;
//
// OpenDatabase();
// DownloadStatus=mDbHelper.SearchDuplicateDownloadVideo(mSQLiteDatabase, id,name.get(position).toString().trim());
// CloseDataBase();
//
// if(DownloadStatus){
// SearchDuplicateDialog();
// //Toast.makeText(mContext, Html.fromHtml(Constants.DOWNLOAD.RECORD_DUPLICATE_MESSAGE),Toast.LENGTH_LONG).show();
// }
// else{
// if(CommanClass.isTablet(List.this))
// {
// intFileName = anshd.get(position).toString().hashCode();
// System.out.println("strFileName=="+intFileName);
// mPosition = position;
// DownloadVideoDialog();
// }
// else{
// intFileName = ans.get(position).toString().hashCode();
// System.out.println("strFileName=="+intFileName);
// mPosition = position;
// DownloadVideoDialog();
// }
// }
// }
// });
// mDialog.show();
// }
// //*******************************************************************************************************************************
// public void SearchDuplicateDialog(){
// AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ViewGroupOrganizer.group);
// alertDialogBuilder
// .setMessage(Constants.DOWNLOAD.RECORD_DUPLICATE_MESSAGE)
// .setCancelable(false)
// .setPositiveButton(Constants.WELCOME_MESSAGE.POSITIVE_BUTTON_TEXT,new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog,int id) {
// dialog.cancel();
// }
// });
//
// AlertDialog alertDialog = alertDialogBuilder.create();
// alertDialog.show();
// }
//*******************************************************************************************************************************
// This Is run when key down
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
ViewGroupOrganizer.group.back();
return true;
}
return super.onKeyDown(keyCode, event);
}
/**THIS FUNCTION IS USED FOR OPEN DATABASE */
private DbHelper mDbHelper=null;
private SQLiteDatabase mSQLiteDatabase=null;
private void OpenDatabase()
{
try{
if(mDbHelper==null && mSQLiteDatabase==null){
mDbHelper = new DbHelper(List.this);
mSQLiteDatabase = mDbHelper.getWritableDatabase();
// mSQLiteDatabase.setLockingEnabled(true);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**THIS FUNCTION IS USED FOR CLOSE DATABASE */
private void CloseDataBase()
{
try{
if(mDbHelper!=null && mSQLiteDatabase!=null){
mSQLiteDatabase.close();
mDbHelper.close();
mSQLiteDatabase=null;
mDbHelper=null;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Subscribe to:
Posts (Atom)