package com.nugnux.array;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity{
private static String text = "heheh...";//for use as the tag when logging
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
proses();
Button buttonStart = (Button)findViewById(R.id.buttonStart);
buttonStart.setOnClickListener(startListener); // Register the onClick listener with the implementation above
Button buttonStop = (Button)findViewById(R.id.buttonStop);
buttonStop.setOnClickListener(stopListener); // Register the onClick listener with the implementation above
}
private void proses(){
TextView tulisan = (TextView)findViewById(R.id.tulisan);
tulisan.setText("tadaa...\n");
tulisan.append("this is array\n");
Random r = new Random();
int[]arr = new int[5];
for(int i=0;i<arr.length;i++)
{
arr[i] = Math.abs(r.nextInt()%255) +1;
tulisan.append(arr[i] + "\t\t");
}
}
//Create an anonymous implementation of OnClickListener
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v) {
proses();
Toast.makeText(MainActivity.this, "The Start button was clicked.", Toast.LENGTH_LONG).show();
}
};
// Create an anonymous implementation of OnClickListener
private OnClickListener stopListener = new OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "The Stop button was clicked.", Toast.LENGTH_LONG).show();
TextView tulisan = (TextView)findViewById(R.id.tulisan);
tulisan.setText("tadaa...");
}
};
}
Thursday, June 12, 2014
[Java Android] Array of Pseudo Random Integer on TextView (just for self documentation)
Here the code, the random numbers generated at the creation and at "Start" button click
[Java Android] Create Circle and Line using Canvas on Eclipse with ADT (just for self documentation)
here it is,
I just create new Android app and go straigth to MainActivity.java without setting up the interface, so res/value/strings.xml and res/layout/* is left as is
and my activity is mainly in MainActivity :)
I just create new Android app and go straigth to MainActivity.java without setting up the interface, so res/value/strings.xml and res/layout/* is left as is
and my activity is mainly in MainActivity :)
package com.nugnux.gambar;
import android.app.Activity;
//import android.app.ActionBar;
import android.app.Fragment;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
//import android.os.Build;
import android.widget.Toast;
public class MainActivity extends Activity {
private String tulisan="";
private final int interval = 3000; // 1 Second
private Handler handler = new Handler();
private Runnable runnable = new Runnable(){
public void run() {
Toast.makeText(MainActivity.this, "Tadaa...", Toast.LENGTH_SHORT).show();
}
};
DrawView drawView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tulisan = Long.toString(System.currentTimeMillis());
Toast.makeText(MainActivity.this, "Heheh..."+tulisan, Toast.LENGTH_SHORT).show();
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
//handler.postAtTime(runnable, System.currentTimeMillis()+interval);
handler.postDelayed(runnable, interval);
//handler.postDelayed(r, delayMillis)
}
class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLUE);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawLine(10, 20, 30, 40, paint);
canvas.drawLine(20, 10, 50, 20, paint);
canvas.drawCircle(100, 100, 10, paint);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
...still figuring how to create moveTo lineTo since it'll come handy for drawing curve (sine, cosine, some exotic function) and animating it :)
Wednesday, June 11, 2014
The Impressions
So, after tinkering with Lenovo A3000 for 5 day...
The IPS screen is acceptable
The quadcore processor is doing what it supposed to do, fast enough
Getting used with android onscreen keyboard ( it's my 1st android device, i used iPhone and iPad), no AZERTY layout tough
The Playstore is fairly equal to AppStore. Keep in mind on android open source and open community nature, there's many apps that similar each other, and in some case, apps that has no purpose or simply didn't work.
The treasure (for me) is AIDE, an IDE app to create android app from inside android itself; something that's forbidden in iOS, :)
No home button is definitely problem for me, as it's replacement for my 2 years son's broken iPad. The challenge is how to teach him to use power button to waking up the device. The other solution is set the timeout display to 30 minutes and risk on fast drained battery.
Still give it a chance and time, .....
(My iPad is practically dead brick now, couldn't be charged, got the message like "couldn't charge with this accesories" or "this acessories not support charging" even with new original cable ; it's likely the connector is short circuited and blown away)
(edit: "Charging is not supported with this accessory")
(edit: "Charging is not supported with this accessory")
Create Android Application (Thermometer Converter) on Android Itself, using AIDE
It my early android apps developed using Eclipse and ADT on my Mac and now ported to AIDE on my A3000, which is, say, just copy and paste, :).
The app itself consist of two button, one textview, one edit text and a spinner. The input in edit text is processed based on spinner value and the result is displayed on text edit. The button is just for checking and have fun, :)
That's it, now let's get our hand dirty...
Of course the first step is open AIDE apps, :)
then scroll down until "For Expert" choice appear, I didn't bother to use tutorial, you may like it though, :)
choose "Create new Project here", then choose "New App"
Fill the form
here my main.xml on res/layout

here my strings.xml on res/value
..and my MainActivity.java on src/com/nugnux/thermoaide
and prompt us whether we want to install the built app, of course...
here the result
The app itself consist of two button, one textview, one edit text and a spinner. The input in edit text is processed based on spinner value and the result is displayed on text edit. The button is just for checking and have fun, :)
That's it, now let's get our hand dirty...
Of course the first step is open AIDE apps, :)
then scroll down until "For Expert" choice appear, I didn't bother to use tutorial, you may like it though, :)
choose "Create new Project here", then choose "New App"
Fill the form
here my main.xml on res/layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tulisan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="This is a simple two button app. \r\n \r\n Tell your user what your app does here \r\n \r\n \r\n \r\n"
android:textColor="#005500" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:ems="10" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/sprOperator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/sprSuhu"
/>
<Button
android:id="@+id/buttonStart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start"/>
<Button
android:id="@+id/buttonStop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Stop"/>
</LinearLayout>

here my strings.xml on res/value
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ThermometerPram</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string-array name="sprSuhu">
<item >C</item>
<item >F</item>
<item >R</item>
<item >K</item>
</string-array>
</resources>
..and my MainActivity.java on src/com/nugnux/thermoaide
package com.nugnux.thermoaide;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.view.View.OnClickListener;
public class MainActivity extends Activity
{
private static String logtag = "TwoButtonApp";//for use as the tag when logging
private static String text = "belum di pilih";//for use as the tag when logging
private static int pilihan = 0;//for use as the tag when logging
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.sprOperator);
final String sprSuhu[] = getResources().getStringArray(R.array.sprSuhu);
ArrayAdapteradapter = ArrayAdapter.createFromResource(this,
R.array.sprSuhu, android.R.layout.simple_spinner_item);
spinner.setAdapter(adapter);
// Set the ClickListener for Spinner
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView adapterView, View view, int i, long l) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this,"Anda memilih satuan "
+ sprSuhu[i]+" ",Toast.LENGTH_SHORT).show();
text=sprSuhu[i];
pilihan=i;
hitung();
}
// If no option selected
public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub
}
});
}
//Create an anonymous implementation of OnClickListener
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v) {
//Log.d(logtag,"onClick() called - start button");
Toast.makeText(MainActivity.this, "The Start button was clicked.", Toast.LENGTH_LONG).show();
TextView tulisan = (TextView)findViewById(R.id.tulisan);
hitung();
//Log.d(logtag,"onClick() ended - start button");
}
};
// Create an anonymous implementation of OnClickListener
private OnClickListener stopListener = new OnClickListener() {
public void onClick(View v) {
//Log.d(logtag,"onClick() called - stop button");
Toast.makeText(MainActivity.this, "The Stop button was clicked.", Toast.LENGTH_LONG).show();
TextView tulisan = (TextView)findViewById(R.id.tulisan);
tulisan.setText("tadaa...");
//Log.d(logtag,"onClick() ended - stop button");
}
};
public void hitung(){
double hasil,suhu;
EditText editText1 =(EditText)findViewById(R.id.editText1);
TextView tulisan = (TextView)findViewById(R.id.tulisan);
tulisan.setText("hehehe, akhirnya...");
try {
hasil=Double.parseDouble(editText1.getText().toString());
tulisan.append(" \r\n(angka di bawah ini adalah "+Double.toString(hasil)+" )");
//hasil=Math.pow(hasil, 2);
tulisan.append(" \r\n[pangkatnya adalah "+Double.toString(Math.pow(hasil, 2))+" ] \r\nspinner bernilai "+text);
if (pilihan==0){
suhu=9./5.*hasil+32;
tulisan.append("\r\n Suhu "+Double.toString(hasil)+" C jika dikonversi akan menjadi bernilai:");
tulisan.append("\r\n"+Double.toString(suhu)+" F");
suhu=4./5.*hasil;
tulisan.append("\r\n"+Double.toString(suhu)+" R");
suhu=hasil+273;
tulisan.append("\r\n"+Double.toString(suhu)+" K");
}
if (pilihan==1){
suhu=5./9.*(hasil-32);
tulisan.append("\r\n Suhu "+Double.toString(hasil)+" F jika dikonversi akan menjadi bernilai:");
tulisan.append("\r\n"+Double.toString(suhu)+" C");
suhu=4./9.*(hasil-32);
tulisan.append("\r\n"+Double.toString(suhu)+" R");
suhu=(hasil-32)*5./9.+273;
tulisan.append("\r\n"+Double.toString(suhu)+" K");
}
if (pilihan==2){
suhu=9./4.*hasil+32;
tulisan.append("\r\n Suhu "+Double.toString(hasil)+" R jika dikonversi akan menjadi bernilai:");
tulisan.append("\r\n"+Double.toString(suhu)+" F");
suhu=5./4.*hasil;
tulisan.append("\r\n"+Double.toString(suhu)+" C");
suhu=hasil*5./4.+273;
tulisan.append("\r\n"+Double.toString(suhu)+" K");
}
if (pilihan==3){
suhu=9./5.*(hasil-273)+32;
tulisan.append("\r\n Suhu "+Double.toString(hasil)+" K jika dikonversi akan menjadi bernilai:");
tulisan.append("\r\n"+Double.toString(suhu)+" F");
suhu=4./5.*(hasil-273);
tulisan.append("\r\n"+Double.toString(suhu)+" R");
suhu=hasil-273;
tulisan.append("\r\n"+Double.toString(suhu)+" C");
}
} catch (NumberFormatException e) {
tulisan.setText(e.getMessage()+", masukkan angka");
}
}
}
run it

it will build
and prompt us whether we want to install the built app, of course...
here the result
Tuesday, June 10, 2014
Another AIDE ScreenShot on My Lenovo A3000
Empat Saksi
Akhir-akhir ini ada beberapa kasus gugatan yang ditolak oleh pengadilan
Suami yang digugat istri dengan bukti foto pesta seks dari hap sang suami
Istri yang digugat suami dengan bukti rekaman CCTV di sebuah gedung
...dan gugatan tersebut ditolak
...alasannya tidak ada saksi kejadian tersebut
...agar gugatan diterima maka harus ada dua saksi laki-laki atau empat saksi perempuan yang menyaksikan kejadian (lihat betapa laki-laki dibedakan haknya dengan perempuan)
... dan itu sungguh aneh. Dan saya yakin akan ada lebih banyak perselingkuhan setelah berita ini karena mereka tahu bahwa jika mereka melakukan diam-diam (tentu saja) maka tak akan ada yang bilang bahwa mereka selingkuh, secara hukum, ckckck.
Keanehan berikutnya, bagaimana jika memang benar-benar ada saksi? Jika mereka murni saksi, bukan pelapor, bukankah mereka sama saja dengan menyetujui tindakan si tergugat? Dalam keadaan seperti itu, apakah mereka bersedia bersaksi? Sepertinya tidak.
Jika mereka bersedia bersaksi akan sangat membingungkan, bayangkan pertanyaan jaksa "jadi anda melihat kejadian itu? tidak melarang?" dan pertanyaan berikutnya "apa buktinya jika anda telah melihat kejadian itu?" foto? nah, tadi sudah ditolak kan? repot lagi deh... dan kesaksian tidak sah, :)
Dengan logika, sebenarnya klausul "dua saksi laki-laki atau empat perempuan" yang menyaksikan kejadian itu dapat saja sudah sangat memenuhi syarat. Dengan melihat foto atau video kejadian yang telah terbukti bukan rekayasa sebenarnya dapat disimpulkan bahwa perselingkuhan benar-benar terjadi, bagaimana seseorang bisa tidak melihat hal itu? bahkan membantah bahwa itu tak terjadi, atau kurang saksi, jika video/foto itu disaksikan seratus orang, bukankah mereka juga merupakan saksi
...dan yang lebih aneh lagi, si penggugat kadang malah ganti digugat secara pidana karena "mencemarkan nama baik", dan gugatan dapat diproses, waduh
Suami yang digugat istri dengan bukti foto pesta seks dari hap sang suami
Istri yang digugat suami dengan bukti rekaman CCTV di sebuah gedung
...dan gugatan tersebut ditolak
...alasannya tidak ada saksi kejadian tersebut
...agar gugatan diterima maka harus ada dua saksi laki-laki atau empat saksi perempuan yang menyaksikan kejadian (lihat betapa laki-laki dibedakan haknya dengan perempuan)
... dan itu sungguh aneh. Dan saya yakin akan ada lebih banyak perselingkuhan setelah berita ini karena mereka tahu bahwa jika mereka melakukan diam-diam (tentu saja) maka tak akan ada yang bilang bahwa mereka selingkuh, secara hukum, ckckck.
Keanehan berikutnya, bagaimana jika memang benar-benar ada saksi? Jika mereka murni saksi, bukan pelapor, bukankah mereka sama saja dengan menyetujui tindakan si tergugat? Dalam keadaan seperti itu, apakah mereka bersedia bersaksi? Sepertinya tidak.
Jika mereka bersedia bersaksi akan sangat membingungkan, bayangkan pertanyaan jaksa "jadi anda melihat kejadian itu? tidak melarang?" dan pertanyaan berikutnya "apa buktinya jika anda telah melihat kejadian itu?" foto? nah, tadi sudah ditolak kan? repot lagi deh... dan kesaksian tidak sah, :)
Dengan logika, sebenarnya klausul "dua saksi laki-laki atau empat perempuan" yang menyaksikan kejadian itu dapat saja sudah sangat memenuhi syarat. Dengan melihat foto atau video kejadian yang telah terbukti bukan rekayasa sebenarnya dapat disimpulkan bahwa perselingkuhan benar-benar terjadi, bagaimana seseorang bisa tidak melihat hal itu? bahkan membantah bahwa itu tak terjadi, atau kurang saksi, jika video/foto itu disaksikan seratus orang, bukankah mereka juga merupakan saksi
...dan yang lebih aneh lagi, si penggugat kadang malah ganti digugat secara pidana karena "mencemarkan nama baik", dan gugatan dapat diproses, waduh
Subscribe to:
Posts (Atom)
My sky is high, blue, bright and silent.
Nugroho's (almost like junk) blog
By: Nugroho Adi Pramono
323f
(5)
amp
(1)
android
(12)
apple
(7)
arduino
(18)
art
(1)
assembler
(21)
astina
(4)
ATTiny
(23)
blackberry
(4)
camera
(3)
canon
(2)
cerita
(2)
computer
(106)
crazyness
(11)
debian
(1)
delphi
(39)
diary
(286)
flash
(8)
fortran
(6)
freebsd
(6)
google apps script
(8)
guitar
(2)
HTML5
(10)
IFTTT
(7)
Instagram
(7)
internet
(12)
iOS
(5)
iPad
(6)
iPhone
(5)
java
(1)
javascript
(1)
keynote
(2)
LaTeX
(6)
lazarus
(1)
linux
(29)
lion
(15)
mac
(28)
macbook air
(8)
macbook pro
(3)
macOS
(1)
Math
(3)
mathematica
(1)
maverick
(6)
mazda
(4)
microcontroler
(35)
mountain lion
(2)
music
(37)
netbook
(1)
nugnux
(6)
os x
(36)
php
(1)
Physicist
(29)
Picture
(3)
programming
(189)
Python
(109)
S2
(13)
software
(7)
Soliloquy
(125)
Ubuntu
(5)
unix
(4)
Video
(8)
wayang
(3)
yosemite
(3)