AndroidGenerateSID: Generador Aleatorio de Nombres de Sistema SAP

[xtrasgu.org]Teniendo en cuenta el gran éxito de GenerateSID: Generador Aleatorio de Nombres de Sistema SAP, y el de su secuela GenerateSID: Generador Aleatorio de Nombres de Sistema SAP (v2.0), era evidente que la saga no podía terminar ahí.

Aprovechando el entorno de desarrollo que estuve configurando en Installing the Android SDK under Debian GNU/LiNUX 5.0 Lenny, he modificado el Generador Aleatorio de Nombres de Sistema SAP para que ahora funcione en Android.

El aspecto de la aplicación, como suele ser habitual, impecable:

AndroidGenerateSID: Generador Aleatorio de Nombres de Sistema SAP

Si te apetece probarlo, lo puedes descargar en AndroidGenerateSID.

Ya por último, y como de costumbre, el código fuente del programa:

/*
 * AndroidGenerateSID - Let Android choose an SAP SID for you. 
 * 
 * Copyright (c) 2010, Pablo López Cienfuegos 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 *   
 */

package org.xtrasgu.generatesid;

import java.util.Arrays;
import android.app.Activity;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class AndroidGenerateSID extends Activity {
	ViewGenerateSID viewgeneratesid;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Set full screen view:
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		// Set full brightness:
		WindowManager.LayoutParams lp = getWindow().getAttributes();
		lp.screenBrightness = 1.0f;
		getWindow().setAttributes(lp);

		viewgeneratesid = new ViewGenerateSID(this);
		setContentView(viewgeneratesid);
	}

	private class ViewGenerateSID extends View {

		public ViewGenerateSID(Context context) {
			super(context);
		}

		@Override
		public boolean onTouchEvent(MotionEvent event){
			invalidate();
			return true;
		}
		
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			// Set background:
			paint.setColor(Color.BLACK);
			paint.setStyle(Paint.Style.FILL);
			canvas.drawPaint(paint);
			
			// Set foreground: 
			paint.setColor(Color.WHITE);
			paint.setStyle(Paint.Style.FILL_AND_STROKE);
			paint.setAntiAlias(true);
			paint.setTextSize(120);
			paint.setTextAlign(Paint.Align.CENTER);
			canvas.drawText(generateSID(), canvas.getWidth()/2, canvas.getHeight()/2, paint);
		}
		
		public String generateSID() {
			int rnd;
			String sid;
			String alfa="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			String alfanum=alfa+"0123456789";
			String[] existingSIDs={};	//Add your existing system landscape SIDs
			String[] exceptionSIDs={"ADD", "ALL", "AND", "ANY", "ASC", "AUX", "COM", "CON", "DBA",
					"END", "EPS", "FOR", "GID", "IBM", "INT", "KEY", "LOG", "LPT",
					"MON", "NIX", "NOT", "NUL", "OFF", "OMS", "PRN", "RAW", "ROW",
					"SAP", "SET", "SGA", "SHG", "SID", "SQL", "SYS", "TMP", "UID",
					"USR", "VAR"}; 
			
			sid="ADD";
			while(Arrays.binarySearch(existingSIDs, sid)>-1 || Arrays.binarySearch(exceptionSIDs, sid)>-1){
				rnd=(int)Math.floor(Math.random()*alfa.length());
				sid=""+alfa.substring(rnd, rnd+1);
				for(int i=0;i<2;i++){
					rnd=(int)Math.floor(Math.random()*alfanum.length());
					sid+=alfanum.substring(rnd, rnd+1);
				}
			}
			return sid;
		}
	}
}

Deja un Comentario