Friday, March 1, 2024

Source code Kramaning (com.dedetok.kramaning)

build.gradle.kts (Module: app)

plugins {
    id("com.android.application")
}

android {
    namespace = "com.dedetok.kramaning"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.dedetok.kramaning"
        minSdk = 24
        targetSdk = 34
        versionCode = 202401
        versionName = "2024.01"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

}

dependencies {

    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.11.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    implementation ("com.google.android.gms:play-services-ads:22.6.0")

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <!-- For apps targeting Android 13 or higher & GMA SDK version 20.3.0 or lower -->
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
        <!-- AD App ID: ca-app-pub-0220748109202708~3978959687 -> AndroidManifest.xml -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-0220748109202708~3978959687"/>


    </application>

</manifest>

res -> values -> strings -> strings.xml

<resources>
    <string name="app_name">Kramaning</string>
    <string name="nav_open">Open</string>
    <string name="nav_close">Close</string>
    <string name="t_preparation">Preparation</string>
    <string name="t_trisandya">Trisandya</string>
    <string name="t_kramaning">Kramaning</string>
    <string name="t_metirta" translatable="false">Metirta &amp; Mebije</string>
</resources>

res -> values -> strings -> strings.xml (in)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Kramaning</string>
    <string name="nav_open">Buka</string>
    <string name="nav_close">Tutup</string>
    <string name="t_preparation">Persiapan</string>
    <string name="t_trisandya">Trisandya</string>
    <string name="t_kramaning">Kramaning</string>

</resources>

com.dedetok.kramaning.ScriptHindu.java

package com.dedetok.kramaning;

import java.util.ArrayList;

public class ScriptHindu {

    @SuppressWarnings("SpellCheckingInspection")
    private static final String[] textMantras = {
            "Om Ang Brahma Dupa Danta Ya Namah svaha||", // 0 dupa
            "Om Puspa Danta Ya Namah svaha||", // 1 flower
            "Om Waktra Sudayamam svaha||", // 2 mount
            "Om Sudayamam svaha, Om Ati Sudayamam svaha||", // 3 right hand
            "Om Prasada Stiti Sarira Suci Nirmalaya Namah svaha||", // 4 soul
            "Om Ang Namah, Om Ung Namah, Om Mang Namah||", // 5 pranayama
            "OM Bhur Bhubah Svah|\nTat savitur varenyam|\nBharga devasya dhimahi|\nDhiyo yo nah pracodayat||", // 6 traisandya 1
            "OM Narayana evedwam sarvam|\nYad butham Yac ca Bhavyam|\nNiskalanko niranjano nirvikalpo|\nNirakhyatah suddho deva eko|\nNarayana na dvitiyo asti kascit||", // 7 traisandya 2
            "OM Tvam siwah tvam mahadevah|\nIswarah paramesvarah|\nBrahma Visnuca rudrasca|\nPurusah parikirtitah||", // 8 traisandya 3
            "OM Papoham papokarmaham|\nPapatma papasambhavah|\nTrahi mam pundarikaksa|\nSabahyabyantarah sucih||", // 9 traisandya 4
            "OM Ksamasva mam mahadeva|\nSarvaprani hitangkara|\nMam moca sarva papebyah|\nPalayasva sada siva||", // 10 traisandya 5
            "OM Ksantavyah kayika dosah|\nKsantavyo vaciko mama|\nKsantavyo manasa dosah|\nTat pramadat ksamamsva mam||", // 11 traisandya 6
            "OM Canti Canti Canti||", // 12 traisandya 7
            "OM Atma tattvatma suddha ya mam svaha", // 13 kramaning 1
            "OM Adityah syah param jyoti|\nRakta teja namastute|\nSveta pangkaja madhyastha|\nBhaskara ya na namostute||\n\nOM Pranam ya bhaskaram dewam|\nSarwaklesa winasanam|\nParama ditya siwartam|\nBhukti mukti warapradam||\n\nOM Hrang hring sah parama ciwa raditya ya namah svaha||", // 14 kramaning 2
            "OM Namah deva ya adhista na ya|\nSarvavyapi nasiwaya|\nPadmasana eka pratisthaya|\nArdhanaresvar ya namah svaha||\n\nOM Brahma visnu isvara devam|\nJiwatmanan trilokanam|\nSarva jagat pratisthanam|\nSarva roga vinurcitam|\nSarva roga vinasamam|\nVigna desa vinasanam||\n\nOM Namah siva ya||", // 15 kramaning 3
            "OM Anugraha manoharam|\nDwva data nugrahakam|\nHyarcanam sarva pujanam|\nNamah sava nugrahakam||\n\nDeva devi maha sidhi|\nYajnangga nimalatmaka|\nLaksmi siddhisca dirgahayu|\nNirvigram suka vrdisca|\n\nOM Ggring anugahraha ya namah svaha|\nOM Gring anugraha ya namah svaha||\n\nOm Ayur verdi yaso verdi|\nVredi pradnya suka sriyam|\nDhrama santana verdisca|\nSantute sapta vrdayah||\n\nYata meru sthita devam|\nYawat gangga maha tale|\nCandrakau ganggane tawat|\nTattavatma wijayam bawat||\n\nOM Dhirgahayau tat astu svaha|\nOM Awignam astu tat astu svaha|\nOM Subahamastu tat astu svaha|\nOM Sukham bhavantu sruyam bhavantu purnam bhavantu||\n\nOm Sapta verdhi tat astu svaha|\nAntyestih parama pindam|\nAntyestih dewa mersittah|\nSwarvatih eka stnawa|\nSarwva dewa sukha pradadna|\nYa namo namah svaha||", // 16 kramaning 4
            "OM Maha deva devi suksma paramachintya ya nama svaha||", // 17 kramaning 5
            "Om ang brahma amrtha ya namah, Om ung wisnu amrtha ya namah, Om mang isvara amrtha ya namah||", // 18 tirta 1
            "Om Sarira paripurna ya namah, om ang ung mang sarira sudha, Pramantya ya namah, Om ung ksama sampurna ya namah||", // 19 tirta drink 2
            "Om Siva Amertha ya namah, om sadha siva amertha ya namah, Om parama siva amertha ya namah||", // 20 tirta wash face 3
            "Om çriyam bhawantu, Om sukam bhawantu, Om ksama sampurna ya namah svaha" // 21 Bije
    };

    private static final String[] titleMantrasID = {
            "Penyucian Dupa/Api", // 0 dupa
            "Penyucian Bunga", // 1 flower
            "Penyucian Mulut", // 2 mount
            "Penyucian Tangan", // 3 right hand
            "Penyucian Jiwa", // 4 soul
            "Pranayama", // 5 pranayama
            "Trisandya bait 1", // 6 traisandya 1
            "Trisandya bait 2", // 7 traisandya 2
            "Trisandya bait 3", // 8 traisandya 3
            "Trisandya bait 4", // 9 traisandya 4
            "Trisandya bait 5", // 10 traisandya 5
            "Trisandya bait 6", // 11 traisandya 6
            "Trisandya bait 7", // 12 traisandya 7
            "Kramaning bait 1", // 13 kramaning 1
            "Kramaning bait 2", // 14 kramaning 2
            "Kramaning bait 3", // 15 kramaning 3
            "Kramaning bait 4", // 16 kramaning 4
            "Kramaning bait 5", // 17 kramaning 5
            "Tirta dikepala", // 18 tirta 1
            "Tirta diminum", // 19 tirta drink 2
            "Tirta diraup", // 20 tirta wash face 3
            "Bije didahi, dtenggorokan &dimakan" // 21 Bije
    };

    private static final String[] titleMantrasEN = {
            "Penyucian Dupa/Api", // 0 dupa
            "Penyucian Bunga", // 1 flower
            "Penyucian Mulut", // 2 mount
            "Penyucian Tangan", // 3 right hand
            "Penyucian Jiwa", // 4 soul
            "Pranayama", // 5 pranayama
            "Trisandya bait 1", // 6 traisandya 1
            "Trisandya bait 2", // 7 traisandya 2
            "Trisandya bait 3", // 8 traisandya 3
            "Trisandya bait 4", // 9 traisandya 4
            "Trisandya bait 5", // 10 traisandya 5
            "Trisandya bait 6", // 11 traisandya 6
            "Trisandya bait 7", // 12 traisandya 7
            "Kramaning bait 1", // 13 kramaning 1
            "Kramaning bait 2", // 14 kramaning 2
            "Kramaning bait 3", // 15 kramaning 3
            "Kramaning bait 4", // 16 kramaning 4
            "Kramaning bait 5", // 17 kramaning 5
            "Tirta dikepala", // 18 tirta 1
            "Tirta diminum", // 19 tirta drink 2
            "Tirta diraup", // 20 tirta wash face 3
            "Bije didahi, dtenggorokan &dimakan" // 21 Bije
    };

    public static ArrayList<MantraContainer> getMantras(String myLang) {
        ArrayList<MantraContainer> tmpMantras= new ArrayList<MantraContainer>();
        for (int i=0;i<textMantras.length;i++) {
            MantraContainer tmpContainer = new MantraContainer();
            if (myLang.equalsIgnoreCase("id")) {
                tmpContainer.myTitle = titleMantrasID[i];
            } else {
                tmpContainer.myTitle = titleMantrasEN[i];
            }
            tmpContainer.myMantra = textMantras[i];
            tmpMantras.add(tmpContainer);
        }
        return tmpMantras;
    }
}

com.dedetok.kramaning.MantraContainer.java

package com.dedetok.kramaning;

public class MantraContainer {
    public String myTitle;
    public String myMantra;

}

com.dedetok.kramaning.MyAdapter.java

package com.dedetok.kramaning;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.widget.AppCompatTextView;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class MyAdapter extends RecyclerView.Adapter {

    private ArrayList<MantraContainer> myMantraAll;
    private ArrayList<MantraContainer> myMantraShow;

    public MyAdapter(String myLang) {
        super();
        this.myMantraAll = ScriptHindu.getMantras(myLang);
        this.myMantraShow = this.myMantraAll;

    }

    /*
     * mandatary extends RecyclerView.Adapter
     */
    @NonNull
    @Override
    public MyAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View myView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_viewitem, parent, false);
        return new MyAdapter.MyHolder (myView);
    }

    /*
     * mandatary extends RecyclerView.Adapter
     */
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MantraContainer tmpMantraContainer = myMantraShow.get(position);
        ((MyHolder) holder).tvTitle.setText(tmpMantraContainer.myTitle);
        ((MyHolder) holder).tvMantra.setText(tmpMantraContainer.myMantra);
    }

    /*
     * mandatary extends RecyclerView.Adapter
     */
    @Override
    public int getItemCount() {
        return myMantraShow.size();
    }

    public void updateList(int myMin, int myMax) {
        myMantraShow = new ArrayList<MantraContainer>();
        for (int i=myMin;i<myMax;i++) {
            this.myMantraShow.add(this.myMantraAll.get(i));
        }
        notifyDataSetChanged();
    }

    private class MyHolder extends RecyclerView.ViewHolder {
        //public TextView tvTitle, tvMantra;
        public AppCompatTextView tvTitle, tvMantra;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tv_title);
            tvMantra = itemView.findViewById(R.id.tv_mantra);
            // unnecessary, use android:textSize="24sp"
            // if android sdk api<28 (android 8.0)
            /*
            if (Build.VERSION.SDK_INT<28) {
                tvTitle.setTextSize(24);
                tvMantra.setTextSize(24);
            }
            */
        }
    }
}

com.dedetok.kramaning.FragmentMain.java

package com.dedetok.kramaning;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class FragmentMain extends Fragment {

    private String localLang="id";

    private MyAdapter myAdapter;

    public FragmentMain(String localLang) {
        super(R.layout.layout_fragment_main);
        this.localLang = localLang;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        //recyclerview
        RecyclerView myRecyclerView = view.findViewById(R.id.my_recycler_view);
        LinearLayoutManager myLinearLayout = new LinearLayoutManager(getActivity().getApplicationContext());
        myLinearLayout.setOrientation(LinearLayoutManager.VERTICAL);
        myRecyclerView.setLayoutManager(myLinearLayout);
        myAdapter = new MyAdapter(localLang);
        myRecyclerView.setAdapter(myAdapter);

    }


    public void updateList(int mFirst, int mLast) {
        myAdapter.updateList(mFirst, mLast);
    }


}

com.dedetok.kramaning.MainActivity.java

package com.dedetok.kramaning;

import androidx.annotation.NonNull;

import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import android.os.Bundle;
import android.view.MenuItem;
import com.google.android.material.navigation.NavigationView;

import java.util.Locale;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;


public class MainActivity extends AppCompatActivity {

    private DrawerLayout myDrawerLayout;

    FragmentMain myFragmentMain;

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

        // get locale language
        String langLocale = Locale.getDefault().getLanguage();
        //Log.e("dedetok", langLocale); //debug

        // TODO change admob id before publish, put back to edit
        // This CODE make slow down startup
        /*
        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(@NonNull InitializationStatus initializationStatus) {

            }
        });
        */
        // AD Unit ID: ca-app-pub-0220748109202708/9185950681 -> AdView in Layout
        // AD App ID: ca-app-pub-0220748109202708~3978959687 -> AndroidManifest.xml

        AdView mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        Toolbar myToolbar = findViewById(R.id.my_toolbar);
        setSupportActionBar(myToolbar);

        myDrawerLayout = findViewById(R.id.my_drawerlayout);
        ActionBarDrawerToggle myActionBarDrawerToggle = new ActionBarDrawerToggle(this, myDrawerLayout, myToolbar, R.string.nav_open, R.string.nav_close);
        myDrawerLayout.addDrawerListener(myActionBarDrawerToggle);
        myActionBarDrawerToggle.syncState();

        NavigationView myNavigationView = findViewById(R.id.my_navigationview);
        myNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                if (myFragmentMain==null) {
                    //Log.e("dedetok", "null create new"); //debug
                    myFragmentMain = new FragmentMain(langLocale);
                }
                //Log.e("dedetok", item.getTitle().toString()); //debug
                int idItem = item.getItemId();
                if (idItem == R.id.preparation) {
                    //Log.e("dedetok", "Preparation"); //debug
                    myFragmentMain.updateList(0,5);
                } else if (idItem == R.id.trisandya) {
                    myFragmentMain.updateList(6,12);
                } else if (idItem == R.id.kramaning) {
                    myFragmentMain.updateList(13,17);
                } else if (idItem == R.id.metirta) {
                    myFragmentMain.updateList(18,21);
                }
                // close drawer if open
                if (myDrawerLayout.isDrawerOpen(GravityCompat.START)) {
                    myDrawerLayout.close();
                }
                return false;
            }
        });

        myFragmentMain = new FragmentMain(langLocale);
        getSupportFragmentManager().beginTransaction().
                add(R.id.my_fragmentcontainerview, myFragmentMain, null).
                commit();
        //Log.e("dedetok", "create fragment end"); // debug will execute after commit
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (myFragmentMain!=null) {
            myFragmentMain.updateList(0,5);
        }
        //Log.e("dedetok", Integer.toString(Build.VERSION.SDK_INT)); // debug version android 7.0 level api 24
    }
}


No comments:

Post a Comment