njajal_admob_di_blog

Pages

Saturday, November 12, 2016

Struk SPBU 57mm [.apk]

hhmm . . .
ternyata posting Struk SPBU lumayan banyak peminatnya. Itu program under Win buat cetak struk di kertas berukuran 75mm. Yang donlot dari 4shared lebih dari 3500 unduhan sejak publikasi... lumayan ya... gak tau juga pada dipake buat apa... gak usah su'uzon [halah, sok alim]
OK... ceritanya, kemaren belajar bikin aplikasi buat android, dan karya pertama adalah Kiblat by Map [buat nyari kiblat ke Mekah dari lokasi "manapun"] pake peta simbah. Trus jadi tertarik buat aplikasi android yg Struk SPBU, ukuran 57mm. Dan ini hasilnya, sementara biar mangkal di 4shared [suwer, lom ada $25 buat bikin akun GD]. Gratis, tapi ada iklannya.. kalo kalian make, jangan lupa klik iklan ya... he he he . . . mksh sebelomnya . . .

loading...

itu ss di android 3,5"

Kalo ada yg minat, ini sebagian source-nya


1. Mulai dari halaman isian data SPBU, dll

Activity.xml

Spoiler Activity.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/mm57"
        android:background="#ff99cc00"
        android:id="@+id/textKop"
        android:gravity="center_horizontal"
        android:textColor="#ffff4444"
        android:textStyle="bold"
        android:textSize="20sp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textKop"
        android:layout_above="@+id/btn_ok">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="12dp">

            <!-- baris 1 : ID SPBU -->
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/id_spbu" />

                <EditText
                    android:id="@+id/id_spbu"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_column="2"
                    android:inputType="textCapCharacters" />

            </TableRow>

            <!-- baris 2 -->

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/header" />

                <EditText
                    android:id="@+id/header"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="text|textMultiLine|textPostalAddress"
                    android:hint="@string/alamat_spbu" />

            </TableRow>

            <!-- baris 3 -->

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/tgl_jam" />

                <EditText
                    android:id="@+id/tgl_jam"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="datetime"
                    android:hint="@string/dmy_hint" />
            </TableRow>

            <!-- baris 4 -->

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/no_nota" />

                <EditText
                    android:id="@+id/no_nota"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="number" />
            </TableRow>

            <!-- baris 5 -->

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/jns_bbm" />

                <EditText
                    android:id="@+id/jns_bbm"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="2"
                    android:inputType="text" />
            </TableRow>

            <!-- baris 6 -->

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/harga_l" />

                <EditText
                    android:id="@+id/harga_liter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="2"
                    android:inputType="numberDecimal" />

            </TableRow>

            <!-- baris 7 -->

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/rp_beli" />

                <EditText
                    android:id="@+id/rp_beli"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="numberDecimal"/>

            </TableRow>

            <!-- baris 8 -->

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/ltr_beli" />

                <EditText
                    android:id="@+id/ltr_beli"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="numberDecimal" />

            </TableRow>

            <!-- baris 9 -->

            <TableRow
                android:layout_marginBottom="5dp">

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:text="@string/footer" />

                <EditText
                    android:id="@+id/kaki"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/footer_hint"
                    android:inputType="text|textMultiLine" />
            </TableRow>
        </TableLayout>
    </ScrollView>

    <!-- baris 10 -->

    <Button
        android:id="@+id/btn_ok"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btn_ok"
        android:textColor="#ffcc0000"
        android:textStyle="bold"

        android:layout_alignParentBottom="true"/>

</RelativeLayout>





ini Activity.java

Spoiler Activity.java:
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;

import android.os.Bundle;
import android.text.InputFilter;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
 

public class MainActivity extends Activity {

    Button btnOK;

    EditText etID_SPBU, et_header, et_tg_jam, et_noNota, et_jnsBBM;
    EditText et_h_ltr, et_RpBeli, et_LtrBeli, et_footer;

    AdsController app;
    LinearLayout layAd;
    MyUtils myU;
    Boolean gPlayOK;
    private InterstitialAd interstitial;

    private void saveItemStruk(String item, String isi) {
        SharedPreferences sharedPref = getSharedPreferences(item, MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString(item, isi);
        editor.commit();
    }

    private String getItemStruk(String item) {
        SharedPreferences sharedPref = getSharedPreferences(item, MODE_PRIVATE);
        String mySetting = sharedPref.getString(item, null);
        return mySetting;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        etID_SPBU = (EditText)findViewById(R.id.id_spbu);
        etID_SPBU.setFilters(new InputFilter[]{new InputFilter.AllCaps()});

        et_header = (EditText)findViewById(R.id.header);
        et_tg_jam = (EditText)findViewById(R.id.tgl_jam);
        et_noNota = (EditText)findViewById(R.id.no_nota);
        et_jnsBBM = (EditText)findViewById(R.id.jns_bbm);
        et_h_ltr  = (EditText)findViewById(R.id.harga_liter);
        et_RpBeli = (EditText)findViewById(R.id.rp_beli);
        et_LtrBeli= (EditText)findViewById(R.id.ltr_beli);
        et_footer = (EditText)findViewById(R.id.kaki);

        etID_SPBU.setText(getItemStruk("ID"));
        et_header.setText(getItemStruk("heder"));
        et_tg_jam.setText(getItemStruk("tgl"));
        et_noNota.setText(getItemStruk("nota"));
        et_jnsBBM.setText(getItemStruk("bbm"));
        et_h_ltr.setText(getItemStruk("harga"));
        et_RpBeli.setText(getItemStruk("beli"));
        et_LtrBeli.setText(getItemStruk("liter"));
        et_footer.setText(getItemStruk("f00ter"));

        btnOK = (Button) findViewById(R.id.btn_ok);
        registerForContextMenu(btnOK);

        btnOK.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                openContextMenu(btnOK);
            }
        });
    }

    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
                                    ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle("Lanjut mode cetak");
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.struk_1:
                struk_1();
                break;
            case R.id.struk_2:
                struk_2();
                break;
            case R.id.struk_3:
                struk_3();
                break;
            case R.id.help:
                panduan();
                break;
            default:
                return super.onContextItemSelected(item);
        }
        return true;
    }

    private void posting(Intent intent) {
        intent.putExtra("ID", etID_SPBU.getText().toString());
        intent.putExtra("header", et_header.getText().toString());
        intent.putExtra("tgl_jam", et_tg_jam.getText().toString());
        intent.putExtra("no_nota", et_noNota.getText().toString());
        intent.putExtra("BBM", et_jnsBBM.getText().toString());
        intent.putExtra("harga", et_h_ltr.getText().toString());
        intent.putExtra("rp_beli", et_RpBeli.getText().toString());
        intent.putExtra("ltr_beli", et_LtrBeli.getText().toString());
        intent.putExtra("f00ter", et_footer.getText().toString());
    }

    public void struk_1() {
        Intent intent = new Intent(MainActivity.this, Struk1.class);
        posting(intent);
        startActivity(intent);
    }
 

    public void onDestroy() {
        saveItemStruk("ID",etID_SPBU.getText().toString());
        saveItemStruk("heder",et_header.getText().toString());
        saveItemStruk("tgl",et_tg_jam.getText().toString());
        saveItemStruk("nota",et_noNota.getText().toString());
        saveItemStruk("bbm",et_jnsBBM.getText().toString());
        saveItemStruk("harga",et_h_ltr.getText().toString());
        saveItemStruk("beli",et_RpBeli.getText().toString());
        saveItemStruk("liter",et_LtrBeli.getText().toString());
        saveItemStruk("f00ter",et_footer.getText().toString());

        super.onDestroy();
    }
}



2. Halaman struk


struk1.xml

Spoiler Struk1.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/sv_id1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_above="@+id/linearLayout">

        <LinearLayout
            android:layout_width="57mm"
            android:layout_marginLeft="3mm"
            android:layout_marginRight="3mm"
            android:layout_marginTop="3mm"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/img_kop"
                android:layout_width="wrap_content"
                android:layout_height="100dp"
                android:contentDescription="@string/todo"
                android:src="@drawable/kop_256" />

                <!-- baris 2 ; ID SPBU -->

            <TextView
                android:id="@+id/id_spbu1"
                android:textSize="28sp"
                android:textStyle="bold"
                android:gravity="center_horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/id_spbu" />

            <TextView
                android:id="@+id/header1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/alamat_spbu"
                android:textSize="22sp"
                android:paddingBottom="15dp"
                android:text="@string/alamat_spbu"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/shift1"
                android:text="@string/shift"
                android:textSize="22sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/tgl_jam1"
                android:textSize="22sp"
                android:text="@string/tgl_jam"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/top_line1"
                android:layout_width="wrap_content"
                android:layout_height="12dp"
                android:textSize="22sp"
                android:text="@string/line"
                android:textStyle="bold" />

            <!-- sebelum garis atas -->

            <TableLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:stretchColumns="3">

                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <TextView
                        android:id="@+id/p_pompa11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:text="@string/pulau"
                        android:textSize="22sp" />

                    <TextView
                        android:id="@+id/p_pompa12"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:textSize="22sp"
                        android:text="@string/pompa"
                        android:layout_span="2"
                        android:layout_weight="1" />
                </TableRow>

                <!-- baris 3 ; jenis BBM  -->

                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/jns_bbm11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:text="@string/produk"
                        android:textSize="22sp" />

                    <TextView
                        android:id="@+id/jns_bbm12"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:textSize="22sp"
                        android:layout_weight="1"
                        android:layout_span="2" />
                </TableRow>

                <!-- baris 3 ; harga / liter -->

                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/harga_liter11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:text="@string/harga_l"
                        android:textSize="22sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:text="@string/rp"
                        android:textSize="22sp"
                        android:id="@+id/harga_liter12"
                        android:layout_weight="1"
                        android:layout_span="2" />

                    <TextView
                        android:id="@+id/harga_liter13"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="3"
                        android:text="@string/tmp"
                        android:textSize="22sp"
                        android:paddingRight="66dp"
                        android:gravity="right" />
                </TableRow>

                <!-- baris 5 ; liter beli  -->

                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/ltr_beli11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:text="@string/ltr_beli"
                        android:textSize="22sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:text="@string/n1"
                        android:textSize="22sp"
                        android:id="@+id/ltr_beli12"
                        android:layout_span="2"
                        android:layout_weight="1" />

                    <TextView
                        android:id="@+id/ltr_beli13"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="3"
                        android:text="@string/tmp"
                        android:textSize="22sp"
                        android:paddingRight="66dp"
                        android:gravity="right" />
                </TableRow>

                <!-- baris 6 ; jumlah bayar -->
               
                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <TextView
                        android:id="@+id/rp_beli11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:text="@string/rp_beli"
                        android:textSize="22sp" />

                    <TextView
                        android:id="@+id/rp_beli12"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="2"
                        android:text="@string/rp"
                        android:textSize="22sp"
                        android:layout_span="2"
                        android:layout_weight="1" />

                    <TextView
                        android:id="@+id/rp_beli13"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_column="3"
                        android:text="@string/tmp"
                        android:textSize="21sp"
                        android:layout_weight="1"
                        android:paddingRight="66dp"
                        android:gravity="right" />

                </TableRow>

                <!-- baris 7 ; FOOTER -->

                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="12dp"
                        android:layout_span="3"
                        android:layout_weight="1"
                        android:textSize="22sp"
                        android:text="@string/line"
                        android:textStyle="bold"
                        android:id="@+id/btm_line1"
                        android:layout_column="1" />
                </TableRow>

                <TableRow
                    android:paddingBottom="15dp"
                    android:layout_width="match_parent">
                    <TextView
                        android:id="@+id/f00ter"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="22sp"
                        android:layout_span="3"
                        android:layout_weight="1"
                        android:text="@string/footer"
                        android:gravity="center_horizontal"
                        android:layout_column="1" />
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout"
        android:gravity="center_horizontal"
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/btn_back"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/btn_back" />
        <Button
            android:id="@+id/btn_simpan_jpg"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/btn_jpeg" />
        <Button
            android:id="@+id/btn_print"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/btn_print"  />
    </LinearLayout>

</RelativeLayout>



struk1.java

Spoiler Struk1.java:
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.print.PrintHelper;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

public class Struk1 extends Activity {

    Typeface face_txt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.struk1);

        Intent intent = getIntent();
        String ID = intent.getStringExtra("ID");
        String header = intent.getStringExtra("header");
        String tgl_jam = intent.getStringExtra("tgl_jam");
        String no_nota = intent.getStringExtra("no_nota");
        String BBM = intent.getStringExtra("BBM");
        String harga = intent.getStringExtra("harga");
        String rp_beli = intent.getStringExtra("rp_beli");
        String ltr_beli = intent.getStringExtra("ltr_beli");
        String f00ter = intent.getStringExtra("f00ter");

        face_txt = Typeface.createFromAsset(getAssets(), "fonts/telidon_hv.ttf");

        TextView tvID_SPBU1 = (TextView) findViewById(R.id.id_spbu1);
        tvID_SPBU1.setTypeface(face_txt);
        tvID_SPBU1.setText(ID);

        TextView tvHeader1 = (TextView) findViewById(R.id.header1);
        tvHeader1.setTypeface(face_txt);
        tvHeader1.setText(header);

        TextView tvShift1 = (TextView) findViewById(R.id.shift1);
        tvShift1.setTypeface(face_txt);
        tvShift1.setText("Shift: 1 No. Trans.: "+no_nota);

        TextView tvTglJam1= (TextView) findViewById(R.id.tgl_jam1);
        tvTglJam1.setTypeface(face_txt);
        tvTglJam1.setText("Waktu: "+tgl_jam);
 

        TextView no_pp11 = (TextView) findViewById(R.id.p_pompa11);
        no_pp11.setTypeface(face_txt);

        TextView no_pp12 = (TextView) findViewById(R.id.p_pompa12);
        no_pp12.setTypeface(face_txt);

        TextView jns_bbm0 = (TextView) findViewById(R.id.jns_bbm11);
        jns_bbm0.setTypeface(face_txt);

        TextView tvJnsBBM1= (TextView) findViewById(R.id.jns_bbm12);
        tvJnsBBM1.setTypeface(face_txt);
        tvJnsBBM1.setText(" : "+BBM);

        TextView hl11 = (TextView) findViewById(R.id.harga_liter11);
        hl11.setTypeface(face_txt);

        TextView hl12 = (TextView) findViewById(R.id.harga_liter12);
        hl12.setTypeface(face_txt);

        TextView tvHLiter1= (TextView) findViewById(R.id.harga_liter13);
        tvHLiter1.setTypeface(face_txt);
        tvHLiter1.setText(harga);

        TextView lb11 = (TextView) findViewById(R.id.ltr_beli11);
        lb11.setTypeface(face_txt);

        TextView lb12 = (TextView) findViewById(R.id.ltr_beli12);
        lb12.setTypeface(face_txt);

        TextView tvLtrBeli1= (TextView) findViewById(R.id.ltr_beli13);
        tvLtrBeli1.setTypeface(face_txt);
        tvLtrBeli1.setText(ltr_beli);

        TextView rb11 = (TextView) findViewById(R.id.rp_beli11);
        rb11.setTypeface(face_txt);

        TextView rb12 = (TextView) findViewById(R.id.rp_beli12);
        rb12.setTypeface(face_txt);

        TextView tvRpBeli1= (TextView) findViewById(R.id.rp_beli13);
        tvRpBeli1.setTypeface(face_txt);
        tvRpBeli1.setText(rp_beli);

        TextView tvBtmLine= (TextView) findViewById(R.id.btm_line1);
        tvBtmLine.setTypeface(face_txt);

        TextView tvFooter1 = (TextView) findViewById(R.id.f00ter);
        tvFooter1.setTypeface(face_txt);
        tvFooter1.setText(f00ter);

        Button btnBack = (Button)findViewById(R.id.btn_back);
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        Button btnPrint = (Button) findViewById(R.id.btn_print);
        btnPrint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                View u = findViewById(R.id.sv_id1);
                ScrollView z = (ScrollView) findViewById(R.id.sv_id1);
 

                Bitmap bitmap = takeScreenShot(u, z);

                PrintHelper printHelper = new PrintHelper(Struk1.this);
                printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);
                printHelper.printBitmap("Print Bitmap", bitmap);
            }
        });

        Button btn_jpeg = (Button) findViewById(R.id.btn_simpan_jpg);
        btn_jpeg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                View u = findViewById(R.id.sv_id1);
                ScrollView z = (ScrollView) findViewById(R.id.sv_id1);
                Bitmap bitmap = takeScreenShot(u, z);
                String sss = myU.simpanBitmap(bitmap);
                Toast.makeText(Struk1.this, sss, Toast.LENGTH_SHORT).show();
            }
        });
    }


    public Bitmap takeScreenShot(View u, ScrollView z) {
        int totalHeight = z.getChildAt(0).getHeight();
        int totalWidth = z.getChildAt(0).getWidth();

        Bitmap returnedBitmap = Bitmap.createBitmap(totalWidth,totalHeight , Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(returnedBitmap);
        Drawable bgDrawable = u.getBackground();
        if (bgDrawable != null) bgDrawable.draw(canvas);
        else canvas.drawColor(Color.WHITE);
        u.draw(canvas);
        return returnedBitmap;
    }

    public String simpanBitmap(Bitmap b){
        // siapin nama file
        File folder = new File(Environment.getExternalStorageDirectory() + "/StrukSPBU57mm");
        if (!folder.exists()) folder.mkdir();

        final Calendar c = Calendar.getInstance();
        String new_Date = c.get(Calendar.DAY_OF_MONTH) + "-" + ((c.get(Calendar.MONTH)) + 1) + "-"
                + c.get(Calendar.YEAR) + " " + c.get(Calendar.HOUR) + "-"
                + c.get(Calendar.MINUTE) + "-" + c.get(Calendar.SECOND);
        String path  = String.format(Environment.getExternalStorageDirectory() + "/StrukSPBU57mm/%s.png", new_Date);
        File f_struk = new File(path);

        //Save bitmap
        String string = "";
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(f_struk);
            b.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.flush();
            fos.close();
            string = "disimpan: "+path;
        } catch (FileNotFoundException e) {
            string = "Error: FileNotFound Exception";
        } catch (IOException e) {
            string = "Error: IO Exception";
        }
        return string;
    }

}



ini Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.munengan7camp.strukspbu"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="14" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
        <activity
            android:name=".Struk1"
            android:label="@string/app_name">
            <intent-filter >
                <action  android:name="com.munengan7camp.strukspbu.Struk1"/>

                <category  android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

    </application>

</manifest>

File lain : menu.xml dan strings.xml dibuat sendiri aja [kalo mau nyoba mbuat]

[update link 2 juli 2017 via mediafire]

Saturday, October 29, 2016

Kiblat by Map



Kepingin juga ngoding Android, ya belajarlah koding Android. Ternyata diperlukan sumber daya yg bener-2 mumpuni. Terpaksalah ngoding Android ini pake kompi “seadanya” dengan spek core-2-duo, RAM 1GB, Win7. Spek segini nih gak mampu menjalankan simulator Android, jadi musti nyiapin HP buat nge-test hasil koding.


Acara dimulai dengan donlot s/w yang diperlukan: Eclipse dan Android Studio (IDE development), ADT (Android Development Tool) untuk Eclipse. SDK di donlot menyusul dan hanya ndonlot dikit aja: versi 19 (KitKat) dan 23. Google Play service (diperlukan untuk map/peta, tentunya juga AdMob) juga harus di donlot. Lanjut dengan instalasi, semuanya dilakukan sambil jalan dan atas saran mbah G.
Mulai koding Map (peta), ternyata perlu Google Map API key, ndaftar lagi di situs mbah G. Kepalang tanggung, sekalian ndaftar AdMob buat ndapatin Ad-unit ID buat masang iklan AdMob. Buat kalian yang pengin tau 2 item diatas, tanya mbah G aja yah....
Kode program ini gak sepenuhnya saya buat sendiri, “Cuma” nyontek contoh kode program yang dah setengah jadi dari web juga. Di stackoverflow.com nyaris ada semua yang diperlukan.

Gitu aja prolognya, ini kode program yang saya “jahit” dari berbagai sumber

1.      strings.xml



 <?xml version="1.0" encoding="utf-8"?>  
 <resources>  
   <string name="app_name">Qibla Time</string>  
   <string name="action_peta">Qibla [map]</string>  
   <string name="action_kompas">Qibla [compass]</string>  
   <string name="tgl">Date</string>  
   <string name="lat_lon">Lat / Lon</string>  
   <string name="alamat">Location</string>  
   <string name="hi">Altitude (m asl)</string>  
   <string name="tz">Time zone (GMT+)</string>  
   <string name="subuh">Subuh</string>  
   <string name="terbit">Sunrise</string>  
   <string name="duhur">Zuhur</string>  
   <string name="ashar">Asr</string>  
   <string name="maghrib">Maghrib</string>  
   <string name="isya">Isha</string>  
   <string name="set_asar">Asr\ntime</string>  
   <string name="twilit">Twilight\nangle</string>  
   <string name="cari_almt">Address not found</string>  
   <string name="no_ijin">Permission denied</string>  
   <string name="syafi">Syafi\'i</string>  
   <string name="x_sfafii">Shadow length = object height + 2x long shadow when Duhur</string>  
   <string name="hanafi">Hanafi</string>  
   <string name="x_hanafi">Shadow length = 2x object height + 2x long shadow when Duhur</string>  
   <string name="sudut_if">Dawn angle = </string>  
   <string name="sudut_is">; Isha = </string>  
   <string-array name = "spinner_twilit">  
     <item>Ithna Ashari</item>  
     <item>University of Islamic Sciences, Karachi</item>  
     <item>Islamic Society of North America (ISNA)</item>  
     <item>Muslim World League (MWL)</item>  
     <item>Umm al-Qura, Makkah</item>  
     <item>Egyptian General Authority of Survey</item>  
     <item>Institute of Geophysics, University of Tehran</item>  
     <item>Indoneisan Ministry of Religion</item>  
   </string-array>  
   <string name="kompas_1">Compass sensor accuracy is affected by many things !!!</string>  
   <string name="kompas_2">There is no compass sensor</string>  
   <string name="tab_1">Prayer Time</string>  
   <string name="tab_2">Compass Qibla</string>  
   <string name="tab_3">Map Qibla</string>  
   <string name="google_maps_key"  
     templateMergeStrategy="preserve"  
     translatable="false">AIzaSyBHfJlwDMNPKXzp0qR0WEvb30V9VFCY1PM</string>  
 </resources>  
 
  
Yang warna merah itu unik untuk setiap program, jadi harus disesuaikan dengan ID milik kalian sendiri.
-         google_map_key diperoleh harus sesuai dengan nama project
-         banner_ad_unit_id, boleh pake punya saya dulu kalo mau nyoba, ato hilangin unit iklan di activity.java


2.      activity_maps.xml
Spolier activity_maps.xml:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.munengan7camp.kiblatbymap.MapsActivity">

    <fragment
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#222222"
        android:background="#ffffff"
        android:layout_marginTop="16dp"
        android:layout_centerHorizontal="true"
        android:textSize="18sp"
        android:text="@string/txt_init" />

    <ImageButton
        android:id="@+id/buttonKabah"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        android:layout_marginLeft="12dp"
        android:layout_marginStart="12dp"
        android:src="@drawable/kabah"
        android:contentDescription="@string/img_kabah" />

    <!-- view for AdMob Banner Ad -->
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id" />

</RelativeLayout>


-         Yang warna merah adalah nama project, sesuaikan dengan project kalian
-         Yang warna biru, gambar Ka’bah di folder drawable (ganti dengan gambar lain juga bisa, nama file harus disesuaikan tentunya) akan jadi tombol untuk “menuju” ke Ka’bah di google map.


3.      manifest.xml


 <?xml version="1.0" encoding="utf-8"?>  
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.munengan7camp.kiblatbymap"  
   android:installLocation="preferExternal"  
   android:versionCode="2"  
   android:versionName="1.1" >  
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  
   <uses-permission android:name="android.permission.INTERNET" />  
   <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />  
   <!--  
   <uses-feature  
     android:glEsVersion="0x00020000"  
     android:required="true" />  
   -->  
   <uses-sdk  
     android:minSdkVersion="15"  
     android:targetSdkVersion="26" />  
   <application  
     android:allowBackup="true"  
     android:icon="@drawable/ic_launcher"  
     android:label="Waktu Kiblat"  
     android:theme="@style/AppTheme" >  
     <activity  
       android:name=".MainActivity"  
       android:label="@string/app_name"  
       android:theme="@android:style/Theme.Holo.Light.NoActionBar" >  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
     <activity  
       android:name=".WaktuActivity" >  
     </activity>  
     <activity  
       android:name=".KompasActivity" >  
     </activity>  
     <activity  
       android:name=".PetaActivity" >  
     </activity>  
     <meta-data  
       android:name="com.google.android.gms.version"  
       android:value="@integer/google_play_services_version" />  
     <meta-data  
       android:name="com.google.android.geo.API_KEY"  
       android:value="@string/google_maps_key" />  
     <activity  
       android:name="com.google.android.gms.ads.AdActivity"  
       android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"  
       android:theme="@android:style/Theme.Translucent" />  
   </application>  
 </manifest>  


Yang warna ungu, cuma buat aplikasi jadi full-screen, hapus bagian itu juga boleh


4.      activity.java

Spoiler Activity.java:
package com.munengan7camp.kiblatbymap;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback ,
        GoogleMap.OnMapLongClickListener {

    private GoogleMap mMap;
    private AdView adView;
    private Polyline garis;
    private TextView txtView;
    private ImageButton btnKaabah;
    private InterstitialAd interstitial;
    public LocationManager locationManager;

    private static final LatLng mecca = new LatLng(21.422487 , 39.826206);
    double jarak;
    String provider;

    private double hitungJarak(double lat1, double lon1, double lat2, double lon2){
        return (
                (
                        ( Math.acos(Math.sin(lat1 * Math.PI / 180) *
                                Math.sin(lat2 * Math.PI / 180) +
                                Math.cos(lat1 * Math.PI / 180) *
                                        Math.cos(lat2 * Math.PI / 180) *
                                        Math.cos((lon1 - lon2) * Math.PI / 180)) *
                                180 / Math.PI
                        ) * 60 * 1.1515
                ) *  1.609344
        );
    }

    private void getLokasi() {

        Criteria kriteria = new Criteria();
        String prov = locationManager.getBestProvider (kriteria,true);
        if (prov != provider) {
            provider = prov; //locationManager.getBestProvider (kriteria,true);
            Toast.makeText(this, "Provider : " + provider, Toast.LENGTH_SHORT).show();
        }
        Location location = locationManager.getLastKnownLocation(provider);

        if (location != null) {
            double lat_pos=location.getLatitude();
            double lng_pos=location.getLongitude();

            LatLng lokasi = new LatLng(lat_pos, lng_pos);

            float zoomVal = mMap.getCameraPosition().zoom;
            if (zoomVal < 9) zoomVal=16;
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(lokasi,zoomVal));
            garis = mMap.addPolyline(new PolylineOptions().add(mecca,lokasi).width(3).color(Color.BLUE).geodesic(true));

            jarak = hitungJarak(mecca.latitude,mecca.longitude,lat_pos,lng_pos);
            txtView.setText(" "+String.format("%.2f",jarak)+" Km ");
        } else {
            txtView.setText(" Location fail ");
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        // TextView init
        txtView = (TextView) findViewById(R.id.textView);

        btnKaabah = (ImageButton) findViewById(R.id.buttonKabah);

        // Map init
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

         // Mecca button act
        btnKaabah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                float zoomVal = mMap.getCameraPosition().zoom;
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mecca, zoomVal));
            }
        });

        // Ads [banner] init
        adView = (AdView) findViewById(R.id.adView);

        // Ads [interstitial] init
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId(getString(R.string.interstitial_ad_unit_id));

        // Ads proceed
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

        interstitial.loadAd(adRequest);
        interstitial.setAdListener(new AdListener() {
            public void onAdLoaded() {
                displayInterstitial();
            }
        });

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    }

    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setPadding(0,0,0,62);
        mMap.setMyLocationEnabled(true);
        mMap.getUiSettings().setZoomControlsEnabled(true);
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        getLokasi();
        mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener(){
            @Override
            public boolean onMyLocationButtonClick() {
                if (garis != null) {
                    garis.remove();
                }
                getLokasi();
                return false;
            }
        });

        mMap.setOnMapLongClickListener(this);
    }

    @Override
    public void onMapLongClick(LatLng point) {
        if (garis != null) {
            garis.remove();
        }
        garis = this.mMap.addPolyline(new PolylineOptions().add(mecca,point).width(2).color(Color.RED).geodesic(true));

        // tampilkan jarak
        jarak = hitungJarak(mecca.latitude,mecca.longitude,point.latitude,point.longitude);
        txtView.setText(" "+String.format("%.2f",jarak)+" Km ");
    }

    @Override
    protected void onPause() {
        if (adView != null){
            adView.pause();
        }
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (adView != null){
            adView.resume();
        }
    }

    @Override
    protected void onDestroy()  {
        if (adView != null){
            adView.destroy();
        }
        super.onDestroy();
    }

}



5.      gradle


apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.munengan7camp.kiblatbymap"
        minSdkVersion 8
        targetSdkVersion 19
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
}

Yang penting dari gradle ini adalah bagian multiDexEnabled true, karna kebanyakan program Android yang menggunakan google play service, bagian header program akan melar melebihi 65Kbyte. Kalo mau cari info lebih lanjut tentang hal ini, tanya mbah G dengan keyword Dalvik.

Yang gak sempet ngoding sendiri, donlot aja Kiblat by Map.apk yang dah jadi liwat link ini. Belom sempet ngaplod ke google play store karna lom ada modal $25 yang musti pake CC buat mbuka kapling di sono.
Link itu masih file kompresi 7z, donlot dulu, uncompress dan copy ke Android-mu, trus install.

SKRIN-SOT
kbm_satelitkbm_road
Njalanin program mudah ko:
1. klik gambar Kaabah di kiri atas untuk menuju Ka'bah
2. Klik MyLocation di kanan atas untuk menuju lokasi kalian
3. Long-klik di peta untuk nggambar garis kiblat dari tempat itu ke Kaabah
4. ganti jenis peta cuma ada di apk yg bisa di dinlot di link diata


[update link 2 juli 2017 via mediafire

[ update 13 juli 2018 via playstore ]