1)ImageLoader.java
==============
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<String, Bitmap> cache=new HashMap<String, Bitmap>();
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<PhotoToLoad> photosToLoad=new Stack<PhotoToLoad>();
//removes all instances of this ImageView
public void Clean(ImageView mImageV)
{
for(int j=0 ;j<photosToLoad.size();){
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<String, Bitmap> entry : cache.entrySet()) {
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();
}
}
}
2)commanclass.java
================================
package com.app.v3;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.Toast;
public class CommanClass {
private static final String strTAG="ServerConnection";
public static boolean CheckNetwork(Context mContext) {
ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netinfo= connectivity.getActiveNetworkInfo();
if(netinfo!=null && netinfo.isConnected() == true)
{
//Toast.makeText(this, "Connection Avilable", Toast.LENGTH_LONG).show();
return true;
}
else
{
Toast.makeText(mContext, Constants.NETWORK_NOT_AVAILABLE, Toast.LENGTH_LONG).show();
return false;
}
}
/**This method use for check Network Connectivity withot message
*/
public static boolean CheckNetworkNoMessage(Context mContext) {
ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netinfo= connectivity.getActiveNetworkInfo();
if(netinfo!=null && netinfo.isConnected() == true)
{
return true;
}
else
{
return false;
}
}
/**This method use for OpenHttpConnectionpost
*/
static InputStream OpenHttpConnectionPost(String strUrl)throws IOException
{
InputStream mInputStream = null;
int intResponse = -1;
URL mURL = new URL(strUrl);
URLConnection mURLConnection = mURL.openConnection();
if (!(mURLConnection instanceof HttpURLConnection)) {
//Log.e(strTAG,"Error in HTTP connection Not Connect");
System.out.println("Error in HTTP connection Not Connect");
throw new IOException("Not an HTTP connection");
}
try{
HttpURLConnection mHttpURLConnection = (HttpURLConnection) mURLConnection;
mHttpURLConnection.setAllowUserInteraction(false);
mHttpURLConnection.setInstanceFollowRedirects(true);
mHttpURLConnection.setRequestMethod("POST");
mHttpURLConnection.connect();
intResponse = mHttpURLConnection.getResponseCode();
if (intResponse == HttpURLConnection.HTTP_OK) {
mInputStream = mHttpURLConnection.getInputStream();
}
}
catch (Exception e)
{
//Log.e(strTAG,"Error in Error connecting");
System.out.println("Error in Error connecting");
throw new IOException("Error connecting");
}
return mInputStream;
}
/**This method use to Check Memory Card
*/
public static Boolean MemoryCardCheck() {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
return true;
}
else
{
return false;
}
}
// Getting DIP
public static boolean isTablet(Context context){
int DPI=context.getResources().getDisplayMetrics().densityDpi;
// int width = context.getResources().getDisplayMetrics().widthPixels;
// int height = context.getResources().getDisplayMetrics().heightPixels;
if((DisplayMetrics.DENSITY_MEDIUM == DPI) && (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE){
System.out.println("isTABLET - TRUE");
return true;
}
System.out.println("isTABLET - FALSE");
return false;
}
/**This method use for GetConnectionObject to Server
*/
public String GetConnectionObject(String strUrl) {
InputStream mInputStream = null;
try {
//This is the default apacheconnection.
HttpClient mHttpClient = new DefaultHttpClient();
//Pathe of serverside
HttpGet mHttpGet = new HttpGet(strUrl);
//get the valu from the saerverside as response.
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);
HttpEntity mHttpEntity = mHttpResponse.getEntity();
mInputStream = mHttpEntity.getContent();
}
catch (Exception e) {
// TODO Auto-generated catch block
Log.e(strTAG,"Error in HttpClient,HttpPost,HttpResponse,HttpEntity");
}
String strLine = null;
String strResult = null;
//convert response in to the string.
try {
BufferedReader mBufferedReader = new BufferedReader(new InputStreamReader(mInputStream,"iso-8859-1"), 8);
StringBuilder mStringBuilder = new StringBuilder();
while((strLine = mBufferedReader.readLine()) != null) {
mStringBuilder.append(strLine + "\n");
}
mInputStream.close();
strResult = mStringBuilder.toString();
}
catch (Exception e) {
//System.out.println("Error in BufferedReadering");
Log.e(strTAG,"Error in BufferedReadering");
}
return strResult;
}
/**
* This function use for get Bitmap from Sdcard
*
* @param ImagePath
* for string image path
* @param context
* Application or current activity reference
* @param Width
* for image width set
* @param Height
* for image height set
* @return Bitmap
*/
public static Bitmap DecodeFileGetBitmap(Context context, String ImagePath, int Width, int Height) {
try {
File mFile = new File(ImagePath);
if (mFile.exists()) {
BitmapFactory.Options mBitmapFactoryOptions = new BitmapFactory.Options();
mBitmapFactoryOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(ImagePath, mBitmapFactoryOptions);
int SampleSize = calculateInSampleSize(mBitmapFactoryOptions, Width, Height);
mBitmapFactoryOptions.inJustDecodeBounds = false;
// mBitmapFactoryOptions.inPurgeable = true;
mBitmapFactoryOptions.inScaled = false;
mBitmapFactoryOptions.inSampleSize = SampleSize;
return BitmapFactory.decodeStream(new FileInputStream(mFile), null, mBitmapFactoryOptions);
} else {
Log.w("Comman Class-->", "ImagePath Not Found.");
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* This function use for calculateSampleSize
*
* @param
* @return int
*/
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and
// width
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will
// guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
// this is only for protrait mode
public static int getImageDIP(Context context, int values) {
return (int) ((int)values * context.getResources().getDisplayMetrics().density);
}
}
=====================================================================
in class from where u want to show image
if(CommanClass.MemoryCardCheck())
{
mImageLoader.DisplayImage(alstVideo_imgs.get(position), imgvideo);
}
========================
see below class in which this method used
3)List.java
===========
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 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<String> name = new ArrayList<String>();
ArrayList<String> type = new ArrayList<String>();
ArrayList<String> ans = new ArrayList<String>();
ArrayList<String> anshd = new ArrayList<String>();
ArrayList<String> imgs = new ArrayList<String>();
ArrayList<String> imgtext = new ArrayList<String>();
ArrayList<String> ids = new ArrayList<String>();
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;
@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);
// 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<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, "")); } setListAdapter(new
* CusAd(this)); }
*/
// setListAdapter(new CusAd(this));
}
@Override
protected void onStart() {
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<Void, Void, Void> {
@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("ISO-8859-1");
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));
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(name.get(position)==null?"null":name.get(position));
holder.descrp.setText(imgtext.get(position)==null?"null":imgtext.get(position));
// 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) {
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<String,Integer, Boolean>{
// 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.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();
}
}
}
4)in manifest addd
=============
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
==============
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<String, Bitmap> cache=new HashMap<String, Bitmap>();
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<PhotoToLoad> photosToLoad=new Stack<PhotoToLoad>();
//removes all instances of this ImageView
public void Clean(ImageView mImageV)
{
for(int j=0 ;j<photosToLoad.size();){
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<String, Bitmap> entry : cache.entrySet()) {
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();
}
}
}
2)commanclass.java
================================
package com.app.v3;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.Toast;
public class CommanClass {
private static final String strTAG="ServerConnection";
public static boolean CheckNetwork(Context mContext) {
ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netinfo= connectivity.getActiveNetworkInfo();
if(netinfo!=null && netinfo.isConnected() == true)
{
//Toast.makeText(this, "Connection Avilable", Toast.LENGTH_LONG).show();
return true;
}
else
{
Toast.makeText(mContext, Constants.NETWORK_NOT_AVAILABLE, Toast.LENGTH_LONG).show();
return false;
}
}
/**This method use for check Network Connectivity withot message
*/
public static boolean CheckNetworkNoMessage(Context mContext) {
ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netinfo= connectivity.getActiveNetworkInfo();
if(netinfo!=null && netinfo.isConnected() == true)
{
return true;
}
else
{
return false;
}
}
/**This method use for OpenHttpConnectionpost
*/
static InputStream OpenHttpConnectionPost(String strUrl)throws IOException
{
InputStream mInputStream = null;
int intResponse = -1;
URL mURL = new URL(strUrl);
URLConnection mURLConnection = mURL.openConnection();
if (!(mURLConnection instanceof HttpURLConnection)) {
//Log.e(strTAG,"Error in HTTP connection Not Connect");
System.out.println("Error in HTTP connection Not Connect");
throw new IOException("Not an HTTP connection");
}
try{
HttpURLConnection mHttpURLConnection = (HttpURLConnection) mURLConnection;
mHttpURLConnection.setAllowUserInteraction(false);
mHttpURLConnection.setInstanceFollowRedirects(true);
mHttpURLConnection.setRequestMethod("POST");
mHttpURLConnection.connect();
intResponse = mHttpURLConnection.getResponseCode();
if (intResponse == HttpURLConnection.HTTP_OK) {
mInputStream = mHttpURLConnection.getInputStream();
}
}
catch (Exception e)
{
//Log.e(strTAG,"Error in Error connecting");
System.out.println("Error in Error connecting");
throw new IOException("Error connecting");
}
return mInputStream;
}
/**This method use to Check Memory Card
*/
public static Boolean MemoryCardCheck() {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
return true;
}
else
{
return false;
}
}
// Getting DIP
public static boolean isTablet(Context context){
int DPI=context.getResources().getDisplayMetrics().densityDpi;
// int width = context.getResources().getDisplayMetrics().widthPixels;
// int height = context.getResources().getDisplayMetrics().heightPixels;
if((DisplayMetrics.DENSITY_MEDIUM == DPI) && (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE){
System.out.println("isTABLET - TRUE");
return true;
}
System.out.println("isTABLET - FALSE");
return false;
}
/**This method use for GetConnectionObject to Server
*/
public String GetConnectionObject(String strUrl) {
InputStream mInputStream = null;
try {
//This is the default apacheconnection.
HttpClient mHttpClient = new DefaultHttpClient();
//Pathe of serverside
HttpGet mHttpGet = new HttpGet(strUrl);
//get the valu from the saerverside as response.
HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);
HttpEntity mHttpEntity = mHttpResponse.getEntity();
mInputStream = mHttpEntity.getContent();
}
catch (Exception e) {
// TODO Auto-generated catch block
Log.e(strTAG,"Error in HttpClient,HttpPost,HttpResponse,HttpEntity");
}
String strLine = null;
String strResult = null;
//convert response in to the string.
try {
BufferedReader mBufferedReader = new BufferedReader(new InputStreamReader(mInputStream,"iso-8859-1"), 8);
StringBuilder mStringBuilder = new StringBuilder();
while((strLine = mBufferedReader.readLine()) != null) {
mStringBuilder.append(strLine + "\n");
}
mInputStream.close();
strResult = mStringBuilder.toString();
}
catch (Exception e) {
//System.out.println("Error in BufferedReadering");
Log.e(strTAG,"Error in BufferedReadering");
}
return strResult;
}
/**
* This function use for get Bitmap from Sdcard
*
* @param ImagePath
* for string image path
* @param context
* Application or current activity reference
* @param Width
* for image width set
* @param Height
* for image height set
* @return Bitmap
*/
public static Bitmap DecodeFileGetBitmap(Context context, String ImagePath, int Width, int Height) {
try {
File mFile = new File(ImagePath);
if (mFile.exists()) {
BitmapFactory.Options mBitmapFactoryOptions = new BitmapFactory.Options();
mBitmapFactoryOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(ImagePath, mBitmapFactoryOptions);
int SampleSize = calculateInSampleSize(mBitmapFactoryOptions, Width, Height);
mBitmapFactoryOptions.inJustDecodeBounds = false;
// mBitmapFactoryOptions.inPurgeable = true;
mBitmapFactoryOptions.inScaled = false;
mBitmapFactoryOptions.inSampleSize = SampleSize;
return BitmapFactory.decodeStream(new FileInputStream(mFile), null, mBitmapFactoryOptions);
} else {
Log.w("Comman Class-->", "ImagePath Not Found.");
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* This function use for calculateSampleSize
*
* @param
* @return int
*/
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and
// width
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will
// guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
// this is only for protrait mode
public static int getImageDIP(Context context, int values) {
return (int) ((int)values * context.getResources().getDisplayMetrics().density);
}
}
=====================================================================
in class from where u want to show image
if(CommanClass.MemoryCardCheck())
{
mImageLoader.DisplayImage(alstVideo_imgs.get(position), imgvideo);
}
========================
see below class in which this method used
3)List.java
===========
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 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<String> name = new ArrayList<String>();
ArrayList<String> type = new ArrayList<String>();
ArrayList<String> ans = new ArrayList<String>();
ArrayList<String> anshd = new ArrayList<String>();
ArrayList<String> imgs = new ArrayList<String>();
ArrayList<String> imgtext = new ArrayList<String>();
ArrayList<String> ids = new ArrayList<String>();
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;
@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);
// 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<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, "")); } setListAdapter(new
* CusAd(this)); }
*/
// setListAdapter(new CusAd(this));
}
@Override
protected void onStart() {
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<Void, Void, Void> {
@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("ISO-8859-1");
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));
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(name.get(position)==null?"null":name.get(position));
holder.descrp.setText(imgtext.get(position)==null?"null":imgtext.get(position));
// 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) {
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<String,Integer, Boolean>{
// 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.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();
}
}
}
4)in manifest addd
=============
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
No comments:
Post a Comment