Webhosting in Pakistan
Page 1 of 2 12 LastLast
Results 1 to 12 of 13

Thread: Android app/game tutorial in Urdu noob friendly (with source code)part3

  1. #1
    Hawk82 is offline Member
    Last Online
    22nd November 2014 @ 10:08 AM
    Join Date
    14 Oct 2014
    Gender
    Male
    Posts
    256
    Threads
    18
    Thanked
    29

    Default Android app/game tutorial in Urdu noob friendly (with source code)part3

    Webhosting in Pakistan
    Ab aap asal class yani PlayActivity ki class

    usi tarha jis traha aap nay baki classes bnaen

    Code:
    package com.example.hang;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.Random;
    
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.support.v4.app.NavUtils;
    import android.text.Spannable;
    import android.text.SpannableString;
    import android.text.style.ForegroundColorSpan;
    import android.util.Log;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    import android.widget.TextView.BufferType;
    
    public class PlayActivity extends Activity {
    	private Random randomGenerator = new Random();
    	private final String[] easylist = {"cat", "sun", "cup","ghost","pie","cow","banana",
    	        "bug","book","jar",
    	        "snake","light","tree",
    	        "lips","apple","slide",
    	        "socks","smile","swing",
    	        "coat","shoe","water",
    	        "heart","hat","ocean",
    	        "kite","dog","mouth",
    	        "milk","duck","eyes", "bird","boy",
    	        "apple","person","girl",
    	        "mouse","ball","house",
    	        "star","nose","bed",
    	        "whale","jacket","shirt",
    	        "beach","egg",
    	        "face","cookie","cheese",
    	        "dance", "skip", "jumping", "jack",
    	        "shark", "chicken", "alligator",
    	        "chair", "robot", "head",
    	        "smile", "baseball", "bird",
    	        "happy", "scissors", "cheek",
    	        "back", "jump", "drink",
    	        "ice", "cream", "cone", "car", "airplane",
    	        "clap", "circle", "pillow",
    	        "pinch", "kick", "dog",
    	        "basketball", "sleep", "camera",
    	        "prayer", "elephant", "blink",
    	        "doll", "spider", "point",
    	        "kite", "homework", "ladybug",
    	        "bed", "bird", "gum",
    	        "book", "dress", "queen",
    	        "puppy", "happy", "doctor"
    	    };
    
     
            private final String[] hardlist = {
            		"vision","loiterer" ,"observatory",
                    "century", "kilogram",
                    "neutron", "stowaway", "psychologist",
                    "exponential", "aristocrat" ,"eureka",
                    "parody" ,"cartography",
                    "philosopher" ,"tinting", "overture",
                    "opaque", "ironic",
                    "zero", "landfill", "implode",
                    "czar" ,"armada" ,"crisp",
                    "stockholder", "inquisition", "mooch",
                    "gallop", "archaeologist" ,"blacksmith",
                    "addendum", "upgrade",
                    "acre", "twang", "mine",
                    "protestant", "brunette", "stout",
                    "quarantine", "tutor", "positive",
                    "champion", "pastry", "tournament",
                    "rainwater", "random",
                    "lyrics", "ice", "clue",
                     "slump", "ligament",
                     "siesta", "pomp",
                    "mine", "shaft", "dismantle", "weed", "killer",
                    "tachometer", "unemployed", "portfolio",
                    "pomp", "evolution", "apathy",
                    "advertise", "roundabout", "sandbox",
                    "conversation", "negotiate",
                    "silhouette", "aisle", "pendulum",
                    "retaliate", "mascot",
                    "shipwreck", "comfort", "zone",
                    "alphabetize", "application", "college",
                    "lifestyle", "level", "invitation",
                    "applesauce", "crumb", "loyalty",
                    "corduroy",  "shrink", "ray"};
     
     
        private final ArrayList<String> easyWords = new ArrayList<String>(Arrays.asList(easylist));
        private final ArrayList<String> hardWords = new ArrayList<String>(Arrays.asList(hardlist));
    	private int curlevel = 0;
    	private int curMan = 0;
    	private ArrayList<Boolean> curAnswer;
    	private String key;
    	
    	private void inputLetter(char c){
    		boolean isContain = false;
    		for(int i =0; i < key.length();++i){
    			char ans = key.charAt(i);
    			if(c == ans){
    				isContain = true;
    				curAnswer.set(i, true);
    			}
    		}
    		if(curMan > 0 &&isContain){
    			curMan--;
    		}
    		disableLetter(c);
    	}
    	
    	private void disableLetter(char c){
    		char C = Character.toUpperCase(c);
    		String buttonID = "button" + C;
    	    int resID = getResources().getIdentifier(buttonID, "id", "com.example.hangu");
    	    Button b = (Button) findViewById(resID);
    	    b.setEnabled(false);
    	}
    	
    	private String getCurAnser(){
    		String result = new String();
    		for(int i=0;i<curAnswer.size();++i){
    			if(curAnswer.get(i)){
    				result += (key.charAt(i)+" ");
    			}
    			else{
    				result += "_ ";
    			}
    		}
            Log.d("test",result);
            
    		return result;
    	}
    	private void selectKey(){
    		int numOfBlanks = curlevel + 3;
    		switch (curlevel)
    		{
    		    case 0:
    		    	key = easyWords.get(randomGenerator.nextInt(easyWords.size()));
    		    break;
    		    case 1:
    		    	key = easyWords.get(randomGenerator.nextInt(easyWords.size()));
    		    break;
    		    case 2:
    		    	key = hardWords.get(randomGenerator.nextInt(hardWords.size()));
    			break;
    		 }
    		
    		Log.d("test",key);
            
    		curAnswer = new ArrayList<Boolean>();
    		for (int i = 0; i < key.length(); i++) {
    			curAnswer.add(false);
    		}
    		HashSet<Character> letterSet = new HashSet<Character>();
    		for(int i=0;i<key.length();++i){
    			letterSet.add(key.charAt(i));
    		}
    		
    		int numOfLetters = letterSet.size();
    		int numOfShow = 0;
    		if(numOfLetters > numOfBlanks){
    			curMan = 0;
    			numOfShow = numOfLetters - numOfBlanks;
    		}
    		else if(numOfLetters < numOfBlanks){
    			curMan = numOfBlanks - numOfLetters ; 
    			numOfShow = 0;
    		}
    
    
            Log.d("test","curMan"+curMan);
    
            Log.d("test","numOfShow"+numOfShow);
            
    		for(int i=0;i<numOfShow;++i){
    			int itemIndex = randomGenerator.nextInt(letterSet.size());
    			int j = 0;
    			for(Character c : letterSet)
    			{
    			    if (j == itemIndex){
    			        inputLetter(c);
    			        letterSet.remove(c);
    			        break;
    			    }
    			    ++j;
    			}
    		}		
    	}
    	
    	private void checkResult(){
    		boolean isComplete = true;
    		for(boolean b:curAnswer){
    			if(!b){
    				isComplete = false;
    				break;
    			}
    		}
    		
    		ImageView imageHanging = (ImageView)findViewById(R.id.imageHanging);
            TextView textFill = (TextView)findViewById(R.id.textFill);
            
            if(isComplete){
            	imageHanging.setImageResource(R.drawable.hanggood);
            	for(int i=0;i<26;i++){
            		char c = (char) ('a' + i);
            		disableLetter(c);
            	}
            	textFill.setText(getCurAnser());
            	return;
    		}
           
            //not complete
            if(curMan < 8){
            	textFill.setText(getCurAnser());
            }
    		switch (curMan)
    		{
    		    case 0:
    		    	imageHanging.setImageResource(R.drawable.hang0);
    		    	break;
    		    case 1:
    		    	imageHanging.setImageResource(R.drawable.hang1);
    		    	break;
    		    case 2:
    		    	imageHanging.setImageResource(R.drawable.hang2);
    		    	break;
    		    case 3:
    		    	imageHanging.setImageResource(R.drawable.hang3);
    		    	break;
    		    case 4:
    		    	imageHanging.setImageResource(R.drawable.hang4);
    		    	break;
    		    case 5:
    		    	imageHanging.setImageResource(R.drawable.hang5);
    		    	break;
    		    case 6:
    		    	imageHanging.setImageResource(R.drawable.hang6);
    		    	break;
    		    case 7:
    		    	imageHanging.setImageResource(R.drawable.hang7);
    		    	break;
    		    case 8:
    		    	imageHanging.setImageResource(R.drawable.hang8);
    		    	for(int i=0;i<26;i++){
    	        		char c = (char) ('a' + i);
    	        		disableLetter(c);
    	        	} //game over
    		    	String rightAnswer = new String("");
    		    	for(int i=0;i<curAnswer.size();++i){
    		    		rightAnswer += key.charAt(i)+" ";
    		    	}
    		    	SpannableString text = new SpannableString(rightAnswer);  
    		    	
    		    	for(int i=0;i<curAnswer.size();++i){
    					if(!curAnswer.get(i)){
    						text.setSpan(new ForegroundColorSpan(Color.GRAY), 2*i, 2*i+1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);  
    					}
    				}
    		    	textFill.setText(text, BufferType.SPANNABLE);
    		    	break;		    
    		 }
    	}
    	
    	@SuppressLint("NewApi")
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		Intent intent = getIntent();
    		curlevel = intent.getIntExtra("level",0);
    		setContentView(R.layout.activity_play);
    
    		TextView textLevel=(TextView)findViewById(R.id.textLevel);
    		TextView textFill = (TextView)findViewById(R.id.textFill);
    
    		selectKey();
    		switch (curlevel)
    		{
    		    case 0:
    		    	textLevel.setText("Easy");
    		    break;
    		    case 1:
    		    	textLevel.setText("Hard");
    		    break;
    		    case 2:
    		    	textLevel.setText("Expert");
    			break;
    		 }
        	textFill.setText(getCurAnser());
        	
        	checkResult();
    	}
    
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		switch (item.getItemId()) {
    		case android.R.id.home:
    			// This ID represents the Home or Up button. In the case of this
    			// activity, the Up button is shown. Use NavUtils to allow users
    			// to navigate up one level in the application structure. For
    			// more details, see the Navigation pattern on Android Design:
    			//
    			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
    			//
    			NavUtils.navigateUpFromSameTask(this);
    			return true;
    		}
    		return super.onOptionsItemSelected(item);
    	}
    	
    	public void clickLetter(View view) {   
    		curMan++;
    		switch (view.getId())
    		  {
    		    case R.id.buttonA:  inputLetter('a');
    		                        break;
    		    case R.id.buttonB:  inputLetter('b');
                                    break;
    		    case R.id.buttonC:  inputLetter('c');
                                    break;
                case R.id.buttonD:  inputLetter('d');
                                    break;
    		    case R.id.buttonE:  inputLetter('e');
                                    break;
                case R.id.buttonF:  inputLetter('f');
                                    break;
                case R.id.buttonG:  inputLetter('g');
                                     break;
                case R.id.buttonH:  inputLetter('h');
                                     break;
    		    case R.id.buttonI:  inputLetter('i');
                                     break;
                case R.id.buttonJ:  inputLetter('j');
                                      break;
                case R.id.buttonK:  inputLetter('k');
                                      break;
                case R.id.buttonL:  inputLetter('l');
                                     break;
                case R.id.buttonM:  inputLetter('m');
                                     break;
                case R.id.buttonN:  inputLetter('n');
                                      break;
                case R.id.buttonO:  inputLetter('o');
                                      break;
                case R.id.buttonP:  inputLetter('p');
                                     break;
                 case R.id.buttonQ:  inputLetter('q');
                                     break;
                 case R.id.buttonR:  inputLetter('r');
                                      break;
                  case R.id.buttonS:  inputLetter('s');
                                     break;
                  case R.id.buttonT:  inputLetter('t');
                                     break;
                  case R.id.buttonU:  inputLetter('u');
                                    break;
                  case R.id.buttonV:  inputLetter('v');
                                       break;
                  case R.id.buttonW:  inputLetter('w');
                                       break;
                   case R.id.buttonX:  inputLetter('x');
                                     break;
                   case R.id.buttonY:  inputLetter('y');
                                       break;
                   case R.id.buttonZ:  inputLetter('z');
                                         break;
    		  }
    		
        	checkResult();
    	}
    	
    	public void goHome(View view) {   
    	       Intent intent = new Intent(this, MainActivity.class);
    	       startActivity(intent);
    	}
    	
    	public void nextOne(View view) {   
    	       Intent intent = new Intent(this, PlayActivity.class);
    	       intent.putExtra("level", curlevel);
    	       startActivity(intent);
    	}
    
    	@Override
    	public void onBackPressed() {
    		Intent intent = new Intent(Intent.ACTION_MAIN);
    		intent.addCategory(Intent.CATEGORY_HOME);
    		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    		startActivity(intent);
    	}
    	
    }
    ab aap apni androidmanifest main usi trha </activity> aur </application> k beech main yeh paste krain

    Code:
      <activity
                android:name="com.example.hang.PlayActivity"
                android:label="@string/title_activity_play"
                android:parentActivityName="com.example.hang.LevelSelectActivity" >
                <meta-data
                    android:name="android.support.PARENT_ACTIVITY"
                    android:value="com.example.hang.LevelSelectActivity" />
            </activity>
    Ab tak aap jo kuch kar kuchay hain yeh important cheez thi aap almost coding sari kar chukay hain ab aap k pas apnay resources /res folder ka kaam baki hai waisay to yeh pehlay kia jata hai magar main aap ko yeh end main islye sikha raha hun k aap isay khud dekhain aur apnay aanay walay projects k lye bnaen.

    /res folder par right click krain aur New--> Folder
    name it drawable



    dobara /res folder par right click krain aur New--> Folder
    name it menu

    aik bar phr /res folder right click New-->Folder
    name it values-sw600dp

    aur last time /res folder right click New-->Folder
    name it values-sw720dp-land

    drawable folder main jo kuch jaega woh sab ki details yeh hain

    Code:
    buttonletterstyle.xml
    buttonletterstyle1.xml
    buttonnextonestyle.xml
    buttonstartstyle.xml
    hang0.png
    hang1.png
    hang2.png
    hang3.png
    hang4.png
    hang5.png
    hang6.png
    hang7.png
    hang8.png
    hanggood.png
    ic_launcher.png
    index.jpg
    lettercolor.xml
    lettercolor1.xml
    nextonecolor.xml
    startcolor.xml
    (note: yeh aglay chapter main source code main ab sab ko dy dunga)

    Aap ny dekha k jo b cheez hum nay drawable main rkhi hai woh app main chalay ge

    Ab aap project par jaen right click karain aur build project par click karain.

    ab aap ka project chalnay k lye ready hai

    isay chalanay k lye aap click karain agr avd par chalana chahtay hain to project right click run as android application

    agr aap nay apna cell phone usb debugging par activate kia hai to run as android application . choose your device and then it will run in your phone

    next class main apko apk file bana kr usay apnay cell phone main chalana sikhaonga.


    Last edited by Hawk82; 17th October 2014 at 12:46 PM.

  2. The Following 2 Users Say Thank You to Hawk82 For This Useful Post:

    i am back (16th October 2014), shanig (16th February 2015)

  3. #2
    aazish hunain's Avatar
    aazish hunain is offline Senior Member+
    Last Online
    13th July 2017 @ 11:04 AM
    Join Date
    24 Nov 2009
    Location
    iN PRayeRS!!!!!
    Gender
    Male
    Posts
    694
    Threads
    107
    Credits
    58
    Thanked
    34

    Default

    Bohat afsos hoa members ka attitude dekh k. as a nation humye Free ki value nhi or yehi course hamra college 9500/m may karwa raha hy or waha seats available nhi.
    anyhow nice effort sir. Aapka 1 fan or student pakka ho gaya. thanks a lot.

  4. The Following User Says Thank You to aazish hunain For This Useful Post:

    Hawk82 (16th October 2014)

  5. #3
    Hawk82 is offline Member
    Last Online
    22nd November 2014 @ 10:08 AM
    Join Date
    14 Oct 2014
    Gender
    Male
    Posts
    256
    Threads
    18
    Credits
    0
    Thanked
    29

    Default

    Quote aazish hunain said: View Post
    Bohat afsos hoa members ka attitude dekh k. as a nation humye Free ki value nhi or yehi course hamra college 9500/m may karwa raha hy or waha seats available nhi.
    anyhow nice effort sir. Aapka 1 fan or student pakka ho gaya. thanks a lot.
    Well appreciated ,actually mainay yeh pura tutorial apnay pass likh lia hai aur mjhy 24 hours main 2 he threads allow hain wrna main yeh pura kr daita aaj.
    kal yeh complete kardunga aur aap log apna game bna skaingay, mera yahan join krnay ka maqsad he yeh tha k main jo seekh chuka hun woh apnay logo ko sikhaon.

  6. The Following User Says Thank You to Hawk82 For This Useful Post:

    i am back (16th October 2014)

  7. #4
    i am back's Avatar
    i am back is offline Advance Member
    Last Online
    27th May 2018 @ 07:10 PM
    Join Date
    28 Apr 2014
    Location
    Karachi
    Age
    20
    Gender
    Male
    Posts
    4,501
    Threads
    146
    Credits
    292
    Thanked
    522

    Default

    I really apreciate your sharing mere pas pc ni hai ni to apki zarur madad karta

  8. #5
    aazish hunain's Avatar
    aazish hunain is offline Senior Member+
    Last Online
    13th July 2017 @ 11:04 AM
    Join Date
    24 Nov 2009
    Location
    iN PRayeRS!!!!!
    Gender
    Male
    Posts
    694
    Threads
    107
    Credits
    58
    Thanked
    34

    Default

    Quote Hawk82 said: View Post
    Well appreciated ,actually mainay yeh pura tutorial apnay pass likh lia hai aur mjhy 24 hours main 2 he threads allow hain wrna main yeh pura kr daita aaj.
    kal yeh complete kardunga aur aap log apna game bna skaingay, mera yahan join krnay ka maqsad he yeh tha k main jo seekh chuka hun woh apnay logo ko sikhaon.
    Sir, 1 kaam or ki jiye ga, jessye hi ye course complete ho jaaye, aap aik separate thread may saarye lessons k links post kar dena es tarah users ko ease ho jaaye ga k lessons 1 jaga pe hi available hn gye.

  9. #6
    Hawk82 is offline Member
    Last Online
    22nd November 2014 @ 10:08 AM
    Join Date
    14 Oct 2014
    Gender
    Male
    Posts
    256
    Threads
    18
    Credits
    0
    Thanked
    29

    Default

    Quote aazish hunain said: View Post
    Sir, 1 kaam or ki jiye ga, jessye hi ye course complete ho jaaye, aap aik separate thread may saarye lessons k links post kar dena es tarah users ko ease ho jaaye ga k lessons 1 jaga pe hi available hn gye.
    G mainay yehi kia but unfortunately aik thread bn chuka tha is naam sy ab na he thread delete ka option hai user k pass na he thread title edit krnay ka
    yeh hai woh thread

  10. #7
    aazish hunain's Avatar
    aazish hunain is offline Senior Member+
    Last Online
    13th July 2017 @ 11:04 AM
    Join Date
    24 Nov 2009
    Location
    iN PRayeRS!!!!!
    Gender
    Male
    Posts
    694
    Threads
    107
    Credits
    58
    Thanked
    34

    Default

    Quote Hawk82 said: View Post
    G mainay yehi kia but unfortunately aik thread bn chuka tha is naam sy ab na he thread delete ka option hai user k pass na he thread title edit krnay ka
    yeh hai woh thread
    Ye aap ny part5 k title ko change karnye ki try ki hy aapko chahaiye tha k aap es kaam k liye 1 seprate thread banaatye or uska name lesson 5 wala copy paste na kartye. . Anyhow let me try to do something.

  11. #8
    Sameer78's Avatar
    Sameer78 is offline Gunahgaar
    Last Online
    17th June 2018 @ 10:13 AM
    Join Date
    10 Apr 2014
    Location
    ال&
    Gender
    Male
    Posts
    1,113
    Threads
    11
    Credits
    557
    Thanked
    68

    Default

    Attachement Show nahe ho rahe//

  12. #9
    Hawk82 is offline Member
    Last Online
    22nd November 2014 @ 10:08 AM
    Join Date
    14 Oct 2014
    Gender
    Male
    Posts
    256
    Threads
    18
    Credits
    0
    Thanked
    29

    Default

    Quote Fire Sail said: View Post
    Attachement Show nahe ho rahe//
    woh sari is thread k end main hain Yahan Click krain

  13. #10
    mat21 is offline Senior Member+
    Last Online
    21st December 2017 @ 10:13 PM
    Join Date
    02 Nov 2017
    Age
    37
    Gender
    Male
    Posts
    54
    Threads
    1
    Credits
    265
    Thanked
    2

    Default

    please also share screen shot of game play

  14. #11
    TAJAMUL PANWAR's Avatar
    TAJAMUL PANWAR is offline Junior Member
    Last Online
    11th November 2017 @ 12:11 PM
    Join Date
    11 Nov 2017
    Age
    31
    Gender
    Male
    Posts
    2
    Threads
    1
    Credits
    115
    Thanked
    0

    Default

    slam bhai jan main new hon r is ki importance janta hon. jaisa k ap ko btaya hai k main new hon is liy complete sekhna chahta hon r ap ki help bht importance rkhti hai so please ap mjhy sikha dain

  15. #12
    hinaraja960 is offline Member
    Last Online
    7th February 2018 @ 12:19 AM
    Join Date
    25 Jan 2018
    Age
    22
    Gender
    Female
    Posts
    52
    Threads
    2
    Credits
    308
    Thanked
    0

    Default wow great

    Webhosting in Pakistan
    wow great

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 25
    Last Post: 8th November 2015, 01:32 AM
  2. Android Urdu Review, (Android Urdu Article)
    By Afridi in forum Android Zone
    Replies: 106
    Last Post: 17th June 2013, 02:51 PM
  3. Urdu Best Websites Needed
    By mudasar786 in forum Ask an Expert
    Replies: 10
    Last Post: 11th November 2011, 12:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •