24 Aralık 2017 Pazar

Android Test

Uzunca bir aradan sonra Android'de yaptığım birşeyleri paylaşıyorum.


JsonSampleActivity.java olarak saklanması gerekiyor.

package com.test;

import org.json.*;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import java.util.Random;
import java.security.*;




public class JSONSampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


TextView txt = new TextView(this);
setContentView(txt);

Random rn=new Random();

boolean x;

String parola = "I love you my darling";
String ifade = "Cem";
String ifade2 ="";
    int sayii=rn.nextInt();
    int d=0;
    char ch='x';
    char charArray[] = { 'b', 'i', 'r', 't', 'h', ' ', 'd', 'a', 'y' };
    byte byteArray[] = { ( byte ) 'n', ( byte ) 'e',
    ( byte ) 'w', ( byte ) ' ', ( byte ) 'y',
    ( byte ) 'e', ( byte ) 'a', ( byte ) 'r' };
 
    StringBuffer buffer;
    String s, s1, s2, s3, s4, s5, s6;
 
// use String constructors
   s1 = new String();
   s2 = new String( );
   s3 = new String( charArray );
   s4 = new String( charArray, 6, 3 );
   s5 = new String( byteArray, 4, 4 );
   s6 = new String( byteArray );

    x=10*2+1>=4*4+5==5>5-3*2;
         
    for(d=0; d<3; d++) {
    ch =Character.valueOf(ifade(d));
    if (ch=='C') ifade2= ifade2 + 'M';
    if (ch=='e') ifade2= ifade2 + 'a';
    if (ch=='m') ifade2= ifade2 + 's';
    }
   
    if (sayii < 0)  sayii = -1 * sayii;
 
    sayii = sayii / 10000000;
 
 
String str = "{\"csd\":\" C ve Sistem Programcıları Derneği\",\"hoca\":\"Kaan Aslan\",\"yil\":\"1993\",\"uye\":\"Cem Korkmaz 127 nolu\"}";

try {
JSONObject jso = new JSONObject(str);
MessageDigest messageDigestNesnesi = MessageDigest.getInstance("MD5");
        messageDigestNesnesi.update(parola.getBytes());
        byte messageDigestDizisi[] = messageDigestNesnesi.digest();
        StringBuffer sb16 = new StringBuffer();
        StringBuffer sb32 = new StringBuffer();
        for (int i = 0; i < messageDigestDizisi.length; i++) {
        sb16.append(Integer.toString((messageDigestDizisi[i] & 0xff) + 0x100, 16).substring(1));
        sb32.append(Integer.toString((messageDigestDizisi[i] & 0xff) + 0x100, 32));
        }
String text = jso.get("csd").toString() + " "
+ jso.get("hoca").toString() + " tarafından "
+ jso.getInt("yil") + " senesinde kuruldu. "
+ jso.get("uye").toString() + jso.get("csd").toString() + " üyesidir."
+ "\nRastgele Sayı : " + sayii
+ "\nBoolean (x) değeri : " + x
+ s1 + s2 + s3 + s4 + s5 + s6 +"\n"
+ sb16.toString() +"\n" + sb32.toString();


txt.setText(text);

}
catch(NoSuchAlgorithmException ex){
        System.err.println(ex);
    }
catch (JSONException je) {
txt.setText(je.getMessage());

}

}

private char ifade(int d) {
// TODO Auto-generated method stub
return 0;
}
}