Tuesday 4 December 2012

Update Table from other DB table

use TV_Guide
update Countries
set  country_FlagIcoLinkEncryptionInfo= d.couFlagIcoLinkEncryptionInfo

from DishesOnline.dbo.Countries d
where country_NameEn = d.couNameEn

Sunday 25 November 2012

the setup routines for the sql server odbc driver could not be found

error "the setup routines for the sql server odbc driver could not be found. please reinstall the driver"

error: "data source name not found and no default driver specified"

The Magic solution is 
windows start>run>regsvr32 odbcconf.dll

everything will be OK In sha' Allah

Tuesday 6 November 2012

Install android Market on android emulator


  1. Create Android Emulator on android 4.1 or greater, assume its name is "Android_JellyBean"
  2. Copy the android tools uri and past it at the end of the environment path key
  3. start the command prompt 
  4. type emulator -avd Android_JellyBeans -partition-size 400 -no-audio -no-boot-anim
  5. wait while the emulator start 
  6. type the following in command prompt 
        adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system
        adb shell chmod 777 /system/app

     7. Download GoogleLoginService.apk 
                         GoogleServicesFramework.apk
                         Vending.apk 
      8.  Run eclipse and open DDMS and open file explorer, go to system folder open it, and open app 
           folder, and push the downloaded files respectively
      9.  Type adb shell rm /system/app/SdkSetup* in the command prompt 
     10. Create android fake account and enjoy 

Wednesday 31 October 2012

Eclipse (Ctrl + Space) Is Not Working

  1. Start Eclipse.
  2. Go to "Window> Preferences > Java > Editor > Content Assist 
  3. Insert this line in "Auto Activation Trigger for Java" box : ._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
  4. You are on Content Assist, open it, and press on advanced Check all check boxes. Look at the figures bellow.


Tuesday 11 September 2012

Android, Create File

How to create Folder on External Memory in Android.

public boolean isExternalStorageWritable() {
  if (Environment.MEDIA_MOUNTED.equals(Environment
                        .getExternalStorageState()))
     return true;
   else
       return false;
   }

File folder;

if (isExternalStorageWritable()) {
      dbFolder = new File(
                    Environment.getExternalStorageDirectory()
                               + File.separator + "Mohammad");                
   }
  boolean success = false;
  if (!dbFolder.exists()) {
      success = dbFolder.mkdir();//one directory
// success = dbFolder.mkdir(); to create more than one directory 
//                        like "Mohammad/kaied/abuhmead"
  }
  if (!success) {
            DB_DIRE=null;
         }
  

Mohammad Abu Hmead

Tuesday 4 September 2012

Android; Read file from Assets into Byte Array

Sometimes you want to place an encrypted file in the assets folder, and you want to read it in correct and unencrypted, so, you want to read it into byte array and edit the byte array to the correct format, here is the way


InputStream is=getAssets().open("fileName.extension");
byte[] fileBytes=new byte[is.available()];
is.read( fileBytes);
is.close();

Now you edit the byte array as you want, and you can create original file with the current bytes if it was encrypted



Mohammad Abu Hmead

Wednesday 29 August 2012

Backup MSSQL Database from Command Prompt

Start the command prompt and type the following:

C:\Users\Administrator>sqlcmd -E -Q "backup database databaseName to disk='C:\backups\ databaseName.bak' with format" > "C:\backups\backUpLog.log"

The text which hi-lighted by green color it is the cmd default 

Hintwith format is used to delete the previous backup and create new one, if you want the current backup to be pushed to the previous one just don't type-write- it.



You can backup more than one database in the same command like the following
"backup database databaseName to disk='C:\backups\ databaseName.bak' with format backup database databaseName to disk='C:\backups\ databaseName.bak' with format" and so on

Backup using Batch file:
You can Create sql query file like"backupDBs.sql" and type in it
backup database databaseName to disk='C:\backups\ databaseName.bak' with format
and call it to be executed from batch file which contains the following command
sqlcmd -s . -i "C:\backupDBs .sql" > "C:\backupDBLog.log"
and you can  Schedule it as you want via Scheduled Tasks

or you can place sqlcmd -E -Q "backup database databaseName to disk='C:\backups\ databaseName.bak' with format" > "C:\backups\backUpLog.log" in the batch file

1- Navigate to Control Panel, Scheduled Tasks, Add New Task, and select Command Prompt
2- Change the task path to backupdb.bat, start path to C:\ and set how often you want to backup


Mohammad Abu Hmead

Thursday 9 August 2012

الأحرف العربية تظهر بعلامات سؤال




أنا جهازي عليه Windows XP SP3 في ملفات اسماءها بالعربي 


بعرض اسماءها á¬dƒOñ ƒT¬Of¬ ƒT¬nƒaní áƒTp¬án

وملفات أخرى بيكون بداخلها نصوص عربي بيعرضها ???????


شو الحل؟

go to:

control panel> lang settings> advanced tab...

select Arabic as "language for non-unicode programs"

and mark as much as you can Arabic-related codes 

from the list; 

Mohammad Abu Hmead

Sunday 29 July 2012

How To download an image and save to the memory card


/First create a new URL object 
URL url = new URL("http://www.google.co.uk/logos/holiday09_2.gif")
//Next create a file, the example below will save to the SDCARD using JPEG
// format
File file = new File("/sdcard/example.jpg");
//Next create a Bitmap object and download the image to bitmap
Bitmap bitmap = BitmapFactory.decodeStream(url.openStream());
//Finally compress the bitmap, saving to the file previously created
bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(file));

Don't forget to add the Internet permission to your manifest:
 android:name="android.permission.INTERNET" />

Mohammad Abu Hmead

Saturday 23 June 2012

I updated the java and eclipse does not work



I updated the JRE today 23.06.2012, and after that the eclipse does not work, when I double click on eclipse it makes like the camera flash.

What is the solution?

Here is it

I just added this line to the eclipse.ini file
 -vm
C:\Program Files\Java\jdk1.7.0_03\bin\javaw.exe
And it is now running successfully.
Mohammad Abu Hmead

Sunday 20 May 2012

Install apk on android emulator

To install android application (.apk) on an emulator follow these steps:

1- run the target emulator
2- copy the .apk file into platform-tools folder
3- cd into platform-tools folder
ex: E:\>cd \Android Full Development Platform (SDK+Eclipse)\android-sdk-windows\platform-tools
4- adb install theApkFileName.apk

if you launched more than one emulator, use the following code

adb -s emulator-5556 install  theApkFileName.apk


Hint: make sure adb.exe in the platform-tools folder


Mohammad Abu Hmead

Thursday 17 May 2012

Reset Identity column in SQL Server


Just use the following code and run it, your identity columns will be reset to the value you use 

DBCC CHECKIDENT('TableName', RESEED, 0)


Mohammad Abu Hmead

Wednesday 16 May 2012

Android Shape



xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="40dp" />
    <padding
        android:left="20dp"
        android:right="20dp" />
shape>


<gradient
        android:centerColor="#FF0000"
        android:endColor="#00FF00"
        android:startColor="#0000FF"
        android:type="sweep"
        android:useLevel="false" />




<gradient       
        android:centerColor="#FF0000"
        android:endColor="#00FF00"
        android:gradientRadius="150"
        android:startColor="#0000FF"
        android:type="radial"
        android:useLevel="false" />



<gradient
        android:centerColor="#FF0000"
        android:endColor="#00FF00"
        android:startColor="#0000FF"
        android:type="linear"
        android:useLevel="false" />




<gradient
        android:angle="135"
        android:centerColor="#FF0000"
        android:endColor="#00FF00"
        android:gradientRadius="20"
        android:startColor="#0000FF"
        android:type="linear"
        android:useLevel="false" />


Gradient Angles (0,45,90,180,135,225,270)



<stroke
        android:dashGap="5dp"
        android:dashWidth="10dp"
        android:width="10dp"
        android:color="#ABCDEF" >
    stroke>




Mohammad Abu Hmead

Wednesday 2 May 2012

Image get be zoomed in Android

I had a problem, when I'm using a list of icons and texts in android app, when i press on the list item, the icon must be shown in another activity with size larger than the current(on the list item), when I press back to back to the list activity, i saw the image get zoomed. I solved the issue by creating new object from the current Drawable via the code bellow
Bitmap bitmap = ((BitmapDrawable)listItemIconDrawableObject).getBitmap();   
BitmapDrawable d = new BitmapDrawable(bitmap);
//use d whenever you want


Mohammad Abu Hmead

Tuesday 3 April 2012

Android Byte Array to Drawble

You can use this method to convert a byte array (which is in the original an image) to Android Drawable


public Drawable getDrwableFromBytes(byte[] imageBytes) {

if (imageBytes != null)
return new BitmapDrawable(BitmapFactory.decodeByteArray(imageBytes,
0, imageBytes.length));
else
return null;
}


Mohammad Abu Hmead

Friday 23 March 2012

String in Switch statement in JAVA JDK 1.7

See this article http://netbeans.org/kb/docs/java/javase-jdk7.html

And Do the following

** set the Sources/Binary Format to JDK 7. You can do this in the bottom right of the Sources section of the Project Properties window.





Mohammad Abu Hmead

Wednesday 21 March 2012

Replace in MSSQL

Replace in MSSQL

use Satellites
Declare @ss as nvarchar(400)
set @ss ='.png'
Update dbo.Frequencies_Owners
Set logoLink = REPLACE(cast(logoLink as nvarchar(max)), @ss, '')

Tuesday 6 March 2012

Import Excel Sheet to MySqlTable

Sometimes you want to import excel sheet to your MySQL DB table which contains Data for this table, the way bellow guide you how to do that:

1- Create Microsoft Excel 97-2003 Worksheet.
2- Place the table fields names in the first row.
3- Rename the sheet to your table name.
4- Go to your MySQL Admin page and open your DB and open your table.
5- Press on the Import tab and point on your document location.
6- Set the charset to UTF8.
7- Pick Excel 97-2003 XLS Workbook.
8- Check Column names in the first row.
9- Press "Go".

Mohammad Abu Hmead

Tuesday 28 February 2012

Write into or create Text File on android internal or External Storage


try {
if (writeFile("sdcard/strs.txt", "My string runs here"))
Log.i("WriteFil", "Success");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Here the method:



/**
* This method to create text file or append to a text file
*
* @param fullFileLocationBathWithNameAndExten
* like "sdcard/strs.txt"
* @param text
* : the text which will be written in the file
* @return: sucess if the process finished successfully
* @throws IOException
* : error in creating the file
*/
public boolean writeFile(String fullFileLocationBathWithNameAndExten,
String text) throws IOException {
File file = new File(fullFileLocationBathWithNameAndExten);
if (!file.exists()) {

file.createNewFile();

}

// BufferedWriter for performance, true to set append to file flag
BufferedWriter buf = new BufferedWriter(new FileWriter(file, true));
buf.append(text);
buf.newLine();
buf.close();

return true;

}

Sunday 26 February 2012

Catch Mutliple ListViews events in the same activity

Dears,

Maybe you want to create many ListViews Dynamically, and you want to catch their events in single listener, you can do that in both ways: if you know the list adapter object name or list object name in
let us assume we have 3 listViews
lv1,lv2,lv3 and 3 lists adapters
la1, la2, la3

we want to set the list item adpaterslike this
lv1.setAdapter(la1);
lv2.setAdapter(la2);
lv3.setAdapter(la3);

and listeners
lv1.setOnItemClickListener(this);
lv2.setOnItemClickListener(this);
lv3.setOnItemClickListener(this);

public void onItemClick(AdapterView parent, View selectedView,
int selectedViewPos, long rowId) {
MyListAdapter myListAdapter = (MyListAdapter) ((ListView) selectedView
.getParent()).getAdapter();
if(myListAdapter==la1){
//write each list item event here or write your code for list1
}else if(myListAdapter==la2){
//write each list item event here or write your code for list2
}else if(myListAdapter==la3){
//write each list item event here or write your code for list3
}

//or

public void onItemClick(AdapterView parent, View selectedView,
int selectedViewPos, long rowId) {
ListView myListView =((ListView) selectedView.getParent());
if(myListView ==lv1){
//write each list item here event or write your code for list1
}else if(myListView ==lv2){
//write each list item here event or write your code for list2
}else if(myListView ==lv3){
//write each list item here event or write your code for list3
}




Mohammad Abu Hmead

Wednesday 22 February 2012

Android add Tabs from other xml Layouts

The big question which made fire my crazy is: how to add tabs to the TabHost from other xml layouts?

I searched and searched much times and finally I tried something and I had succeed.

The Step to have tabs from other xml layouts:
1- Add tab host to your layout -main_window-
2- Create your separate XML layout file
3- Inflate it to view in java code.
4- Override createTabContent and return the inflated view.
5- Add the view to the TabSpec.
Look @ the code bellow

setContentView(R.layout.main_window);
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View row = layoutInflater.inflate(R.layout.mySeperatedXMLLayout,null);
ListView leftList = (ListView) row.findViewById(R.id.leftList);
leftList .setAdapter(new IconAndTextListAdapter(getBaseContext(),
R.layout.icon_and_text, new Contents()
.getCountriesFlagsLinks("en"), new Contents()
.getCountriesNames("en"), R.id.icon_view,
R.id.text_view));

ListView categoriesList = (ListView) row.findViewById(R.id.rightList);
categoriesList.setAdapter(new IconAndTextListAdapter(getBaseContext(),
R.layout.icon_and_text, new Contents()
.getCountriesFlagsLinks("en"), new Contents()
.getCountriesNames("en"), R.id.icon_view,
R.id.text_view));

TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
TabSpec setContent = tabHost.newTabSpec("Tab1")
.setIndicator("Countries").setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
return row;
}});
tabHost.addTab(setContent);


double_lists_holder.xml
// Comment

android:id="@+id/doubList_tbL"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/rock_bg"
android:stretchColumns="0" >



android:id="@+id/leftList"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_weight=".50"
android:cacheColorHint="#00000000"
android:divider="@drawable/list_divider"
android:dividerHeight="10dp"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/free_ico_color5"
android:scrollbars="vertical"
android:soundEffectsEnabled="true" />

android:id="@+id/rightList"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_weight=".50"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/paid_ico_color3"
android:scrollbars="vertical"
android:soundEffectsEnabled="true" />





main_window.xml
// Comment

android:layout_width="fill_parent"
android:layout_height="fill_parent" >

android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/googlAd_view"
android:layout_alignParentTop="true" >

android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >


android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >






Mohammad Abu Hmead

IconAndTextListAdapter

// Comment
public class IconAndTextListAdapter extends ArrayAdapter {

private final Context context;
private final String[] strings;
private final int[] iconsIDs;
private final int rowLayoutID, iconViewID, textViewID;
private View rowView ;


/**
* @param context
* @param rowLayoutID
* @param iconsIDs
* @param strings
* @param iconViewID
* @param textViewID
*/
public IconAndTextListAdapter(Context context, int rowLayoutID,
int[] iconsIDs, String[] strings, int iconViewID, int textViewID) {
super(context, rowLayoutID, strings);
this.context = context;
this.strings = strings;
this.iconsIDs = iconsIDs;
this.rowLayoutID = rowLayoutID;
this.iconViewID = iconViewID;
this.textViewID = textViewID;
// TODO Auto-generated constructor stub
}
static class ViewHolder {
public TextView text;
public ImageView image;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(rowLayoutID, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(textViewID);
viewHolder.image = (ImageView) rowView.findViewById(iconViewID);
rowView.setTag(viewHolder);

}

ViewHolder holder = (ViewHolder) rowView.getTag();

holder.text.setText(strings[position]);

holder.image.setImageResource(iconsIDs[position]);

return rowView;
}

}



Mohammad Abu Hmead

Tuesday 10 January 2012

Select random rows in SQL server


USE [DBName]

SELECT TOP 1 ID,targetLink,addPath,add_type

from dbo.advertisements

where targetDevices=@targetDevices

ORDER BY newid()


Mohammad Abu Hmead

Split method, for java and j2me and android

public Vector split(String stringToBeSplitted, String delimiter) {
Vector vector = new Vector();
StringBuffer sb = new StringBuffer();
int delimiterIndex = stringToBeSplitted.indexOf(delimiter), delemitterLength = delimiter
.length();
if (delimiterIndex != -1) {
while (delimiterIndex != -1) {
sb.append(stringToBeSplitted.substring(0, delimiterIndex));
stringToBeSplitted = stringToBeSplitted.substring(sb.length()
+ delemitterLength, stringToBeSplitted.length());
vector.addElement(sb.toString());
// System.out.println(sb.toString());
sb.delete(0, sb.length());
delimiterIndex = stringToBeSplitted.indexOf(delimiter);
}
vector.addElement(stringToBeSplitted);
// System.out.println((String)vector.elementAt((vector.size()-1)));
} else {
vector.addElement(stringToBeSplitted);
}
sb = null;
stringToBeSplitted = null;
delimiter = null;
delemitterLength = 0;
delimiterIndex = 0;
return vector;
}

Mohammad Abu Hmead

Send text to servlet and get response code from servlet

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.Vector;

public class MidletServlet extends MIDlet implements CommandListener {
Display display = null;
Form form = null;
TextField tb = null;
String str = null;
String url = "http://localhost:8080/servlets-examples/servlet/getText";
Command backCommand = new Command("Back", Command.BACK, 0);
Command submitCommand = new Command("Submit", Command.OK, 2);
Command exitCommand = new Command("Exit", Command.STOP, 3);
private Test test;

public MidletServlet() {}

public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
form = new Form("Request Servlet");
tb = new TextField("Please input text: ","",30,TextField.ANY );
form.append(tb);
form.addCommand(submitCommand);
form.addCommand(exitCommand);
form.setCommandListener(this);
display.setCurrent(form);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();
} else if (c == backCommand) {
display.setCurrent(form);
} else if (c == submitCommand) {
str = tb.getString();
test = new Test(this);
test.start();
test.getServlet(str);
}
}


class Test implements Runnable {
MidletServlet midlet;
private Display display;
String text;

public Test(MidletServlet midlet) {
this.midlet = midlet;
display = Display.getDisplay(midlet);
}

public void start() {
Thread t = new Thread(this);
t.start();
}

public void run() {
StringBuffer sb = new StringBuffer();
try {
HttpConnection c = (HttpConnection) Connector.open(url);
c.setRequestProperty(
"User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");

c.setRequestProperty("Content-Language","en-US");
c.setRequestMethod(HttpConnection.POST);

DataOutputStream os =
(DataOutputStream)c.openDataOutputStream();

os.writeUTF(text.trim());
os.flush();
os.close();

// Get the response from the servlet page.
DataInputStream is =(DataInputStream)c.openDataInputStream();
//is = c.openInputStream();
int ch;
sb = new StringBuffer();
while ((ch = is.read()) != -1) {
sb.append((char)ch);
}
showAlert(sb.toString());
is.close();
c.close();
} catch (Exception e) {
showAlert(e.getMessage());
}
}
/* This method takes input from user like text and pass
to servlet */
public void getServlet(String text) {
this.text = text;
}

/* Display Error On screen*/
private void showAlert(String err) {
Alert a = new Alert("");
a.setString(err);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a);
}
};
}
import java.io.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class getText extends HttpServlet {

public void init() {
}

public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {

DataInputStream in =
new DataInputStream((InputStream)request.getInputStream());

String text = in.readUTF();
String message;
try {
message = "100 ok";
} catch (Throwable t) {
message = "200 " + t.toString();
}
response.setContentType("text/plain");
response.setContentLength(message.length());
PrintWriter out = response.getWriter();
out.println(message);
in.close();
out.close();
out.flush();
}

public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {

doPost(request,response);
}
}


Mohammad Abu Hmead
10.01.2012 11:08 AM