Showing posts with label of. Show all posts
Showing posts with label of. Show all posts

Wednesday, April 2, 2014

Set name of Thread

We can assign a name to a thread by calling its setName(String threadName) method. Inside the thread, we can get the name with: Thread.currentThread().getName().

name of Thread



package com.example.androidthread;

import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;

public class MainActivity extends Activity {

Button buttonStartA, buttonStart, buttonRun;
TextView textInfo;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonStartA = (Button)findViewById(R.id.buttonstarta);
buttonStart = (Button)findViewById(R.id.buttonstart);
buttonRun = (Button)findViewById(R.id.buttonrun);
textInfo = (TextView)findViewById(R.id.info);

buttonStartA.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
//start a thread with name
Thread thread = new Thread(new MyRunnable());
thread.setName("Thread A");
thread.start(); //in background thread
}});

buttonStart.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
Thread thread = new Thread(new MyRunnable());
thread.start(); //in background thread
}});

buttonRun.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
Thread thread = new Thread(new MyRunnable());
thread.setName("another main");
thread.run(); //in current thread
}});
}

private class MyRunnable implements Runnable {

@Override
public void run() {

final String myThreadName = Thread.currentThread().getName();

// check if its run in main thread, or background thread
if(Looper.getMainLooper().getThread()==Thread.currentThread()){
//in main thread
textInfo.setText("in main thread: " + myThreadName);
}else{
//in background thread

runOnUiThread(new Runnable(){

@Override
public void run() {
textInfo.setText("in background thread: " + myThreadName);
}

});
}
}

}

}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />
<Button
android:id="@+id/buttonstarta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="start() with name" />
<Button
android:id="@+id/buttonstart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="start()" />
<Button
android:id="@+id/buttonrun"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="run()" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>


- When button "start() with name" pressed, it show thread name of "Thread A".
- When button "start()" pressed, without name assigned, it show something like "Thread-10807".
- When button "run()" pressed, even a name is assigned to the thread, but the run() method is called in main thread actually. So it show name of "main"



- More example about Thread

Read More..

John Conways Game of Life in Python v1 0

I wont put a description because I think that the video that Ill post is enough. Only the source code!


Read More..

Monday, March 31, 2014

App in C that calculates the coordinates of an array in canonical base

The screenshot is not very relevant because I use as B1the I3 who is an orthonormal base but the coordinates of the array will be the same. I didnt have time to take another base to see the diference...
----------------------------------------------------------------------------------

main.c


1 /* App that calculates the coordinates of an array V from base B1 to canonical base B if B1 is an orthonormal base.
2 B1= base that user input
3 V= the array with coordinates in base B1
4 C= the array V with coordinates in B base
5 A= the orthogonal matrix if B1 is an orthonormal base ( transition matrix from B to B1)
6 B2=the transposed matrix A ( transition matrix from B1 to B)
7 */
8 #include <stdio.h>
9 #include<stdlib.h>
10 #include <math.h>
11 #include "def.c"
12 #include "functii.c"
13 int main()
14 {printf("Numarul de vectori si de elemente ale vectorilor din B1 este:");scanf("%d %d",&B1.lin,&B1.col);
15 printf("Nr de elemente ale vectorului este:");scanf("%d",&V.elem);
16 B2.lin=B1.lin;
17 B2.col=B1.col;
18 A.lin=B1.lin;
19 A.col=B1.col;
20 C.elem=V.elem;
21 A.matr=(double **)malloc(A.lin*sizeof(double*));
22 B1.matr=(double **)malloc(B1.lin*sizeof(double*));
23 B2.matr=(double **)malloc(B2.lin*sizeof(double*));
24 V.vector=(double *)malloc(V.elem*sizeof(double));
25 C.vector=(double *)malloc(C.elem*sizeof(double));
26 for(i=0;i<B1.lin;i++) // aloca memorie pt elem din linia i
27 if((B1.matr[i]=(double *)malloc(B1.col*sizeof(double)))==NULL || (B2.matr[i]=(double *)malloc(B2.col*sizeof(double)))==NULL || (A.matr[i]=(double *)malloc(A.col*sizeof(double)))==NULL)
28 {
29 printf("
memorie insuficienta"
);
30 exit(1) ;
31 }
32 else
33 if(V.vector==NULL || C.vector==NULL)
34 {
35 printf("
memorie insuficienta"
);
36 exit(1) ;
37 }
38 printf("Elementele bazei sunt:
"
);
39 citire_matrice(B1);
40 printf("Elementele vectorului sunt:
"
);
41 citire_vector(V);
42 printf("Baza este:
"
);
43 afisare_matrice(B1);printf("
"
);
44 printf("vectorul este:
"
);
45 afisare_vector(V);printf("
"
);
46 matrice_ortogonala(A,B1);
47 transpunere(A,B2);
48 vector_matrice(V,C,B2);
49
50 free(A.matr);
51 free(B1.matr);
52 free(B2.matr);
53 free(V.vector);
54 free(C.vector);
55 system("pause");
56 return 0;
57 }

----------------------------------------------------------------------------------

def.c


 1 typedef struct{
2 double **matr;
3 int lin;
4 int col;
5 }Matrice;
6 Matrice A,B1,B2;
7 typedef struct{
8 double *vector;
9 int elem;
10 }Array;
11 Array V,C;
12 int i,j;
13
14

----------------------------------------------------------------------------------

functii.c

 1 // citire matrice
2 void citire_matrice(Matrice A){
3 for(i=0;i<A.lin;i++)
4 for(j=0;j<A.col;j++)
5 scanf("%lf",&A.matr[j][i]);
6 }
7 //afisare matrice
8 void afisare_matrice(Matrice A){
9 for(i=0;i<A.lin;i++)
10 {for(j=0;j<A.col;j++)
11 printf(" %.2lf",A.matr[i][j]);
12 printf("

"
);
13 }
14 printf("
"
);
15 }
16
17 //test produs scalar=0
18 int produs_scalar(Matrice B){double suma=0;
19 for(i=0;i<B.lin;i++)
20 for(j=0;j<B.col;j++)
21 suma+=B.matr[i][j]*B.matr[i][j+1];
22 if(abs(suma)==0)
23 return 1;
24 else
25 return 0;
26 }
27 //test norma=1
28 int test_norma(Matrice B1){double norma=0;
29 for(i=0;i<B1.lin;i++)
30 {for(j=0;j<B1.col;j++)
31 norma+=pow(B1.matr[j][i],2);
32 if(sqrt(norma)==0)
33 return 0;
34
35 }
36 return 1;
37
38 }
39
40 //alcatuire matrice ortogonala
41 void matrice_ortogonala(Matrice A, Matrice B1){
42 if(produs_scalar(B1)==1 && test_norma(B1)==1)
43 {for(i=0;i<A.lin;i++)
44 for(j=0;j<A.col;j++)
45 A.matr[i][j]=B1.matr[i][j];
46 printf("matricea ortogonala este:
"
);
47 afisare_matrice(A);
48 }
49 else
50 printf("Matricea nu este ortogonala!");
51 }
52 // citire vector
53 void citire_vector(Array V){
54 for(i=0;i<V.elem;i++)
55 scanf("%lf",&V.vector[i]);
56 }
57 //afisare vector
58 void afisare_vector(Array V){
59 for(i=0;i<V.elem;i++)
60 printf(" %.2lf ",V.vector[i]);
61 printf("
"
);
62 }
63 //transpunere
64 void transpunere(Matrice A,Matrice B2){
65 for(i=0;i<A.lin;i++)
66 {for(j=0;j<A.col;j++)
67 B2.matr[i][j]=A.matr[j][i];
68
69 }
70 printf("
"
);
71 }
72
73
74 //coordonatele unui vector
75 void vector_matrice(Array V,Array C,Matrice B2){
76 if(V.elem!=B2.col)
77 printf("Inmultirea dintre vector si matrice nu se poate realiza!");
78 else{
79 for(i=0;i<B2.lin;i++)
80 for(j=0;j<B2.col;j++)
81 C.vector[i]+=B2.matr[i][j]*V.vector[j];
82 printf("Vectorul in noile coordonate este:");
83 afisare_vector(C);
84 }
85 }
----------------------------------------------------------------------------------
Read More..

Tuesday, March 25, 2014

CamGun Camera Call of Duty 2 21 v2 21 Android Apk App

CamGun (Camera Call of Duty) v2.21
Requirements: Android OS 1.5+
Overview: CamGun is a fun way to use the camera on your phone like a first person shooter - Call of Duty style.

Shoot your friends like an agent with a fully automatic M4 or a SPAS12 and post it on Facebook. Also includes the SOCOM Mark23 a blue Light Saber (star wars), a MiniGun, a GRENADE EASTER EGG and a SR25 sniper rifle with a THERMAL SCOPE -- Headshot!
Start by tapping the gun icon in the upper left corner -- this chooses the gun and it will appear on the screen. Then, tap the screen to fire. Tap the crosshairs icon to sight the gun. You can cycle through the guns any time. Press the camera icon to take a photo vignette of your kill. Simple, but very fun!!! Press the menu button for optional settings for blood, shooter name and target name to be included in the photo. Also records GPS position for Geotagging. Great tool for Humans VS Zombies or other assassin like games. Use foursquare or Google Latititude to find your target and document the shot. Lots of camera fun like picsay except with weapons. Has not been tested on all phones. Photos are stored on the SD card root directory.
Whats in this version:
MAJOR UPGRADE-- Added M249 Light Machine Gun (SAW)
Added Paintball Gun! SPLAT!
Fixed "half-screen" issue on phones with Gingerbread by putting the title-bar back in
ADDED TACTICAL KNIFE!
Added full auto to AK74u
Added a CROSSBOW!!!! BOOYAH! (updated the sound)
Added special Ak74u with a red dot sight and Tiger Camo!!!
Cleaned up light saber and minigun graphics
Allow for moving to SD card.
Longpress on M23 Pistol for DUAL WIELDING
Longpress light saber for double bladed red saber!
Download Instructions:
http://www.filesonic.com/file/1727888084
Mirror:
http://www.wupload.com/file/115437503
http://www.multiupload.com/9PNORPFSK7
Read More..