Beranda > Teknologi > Pemrogramman > Source Code WebView untuk toko online AsRo Store

Source Code WebView untuk toko online AsRo Store

Hai Indonesian Coder! AsRo Shoppers juga!

Malam ini saya ingin berbagi source code WebView toko online saya (AsRo Store) untuk kamu para calon Android Developer.

Saya harap kalian sudah mengetahui cara membuat project di Android Studio terlebih dahulu.

Sebelum ke source code saya ingin memperlihatkan tampilan dari aplikasi AsRo Store

Berikut adalah kode sumbernya:

 

java/toko/aseprohimat/com/Pemulai.java

package toko.aseprohimat.com;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class Pemulai extends AppCompatActivity{
public void onAttachedToWindow(){
super.onAttachedToWindow();
Window jendela=getWindow();
jendela.setFormat(PixelFormat.RGBA_8888);
}
Thread penunjuk;
public void onCreate(Bundle bundel){
super.onCreate(bundel);
setContentView(R.layout.pemulai);
MulaiAnimasi();
}
private void MulaiAnimasi(){
Animation animasi=AnimationUtils.loadAnimation(this,R.anim.alfa);
animasi.reset();
LinearLayout tataLetak=(LinearLayout)findViewById(R.id.pemulai);
tataLetak.clearAnimation();
tataLetak.startAnimation(animasi);
animasi=AnimationUtils.loadAnimation(this,R.anim.masuk_dari_atas);
animasi.reset();
ImageView ikon=(ImageView)findViewById(R.id.ikon);
ikon.clearAnimation();
ikon.startAnimation(animasi);
penunjuk=new Thread(){
public void run(){
try{
int menunggu=0;
while(menunggu<3500){
sleep(100);
menunggu+=100;
}
Intent penjelajah = new Intent(Pemulai.this, Penjelajah.class);
startActivity(penjelajah);
Pemulai.this.finish();
}
catch(InterruptedException kesalahan){}
finally{Pemulai.this.finish();}
}
};
penunjuk.start();
}
}

java/toko/aseprohimat/com/Pemulai.java

package toko.aseprohimat.com;
import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
public class Penjelajah extends AppCompatActivity {
static WebView penjelajah;
private ValueCallback<Uri> mUploadMessage;
public ValueCallback<Uri[]> uploadMessage;
public static final int REQUEST_SELECT_FILE = 100;
private final static int FILECHOOSER_RESULTCODE = 1;
Context kontek;
ProgressBar progress_bar;
LinearLayout progress;
ImageView ikon;
String url,halaman;
@SuppressLint(“SetJavaScriptEnabled”)
@Override
protected void onCreate(Bundle bundel) {
super.onCreate(bundel);
setContentView(R.layout.penjelajah);
kontek = this;
url=””;
halaman=””;
Uri uri = getIntent().getData();
if(uri == null) { halaman = getIntent().getStringExtra(“h”); }
else { halaman = uri.getQueryParameter(“h”); }
if(halaman == null) { url = “https://toko.aseprohimat.com/”; }
else { url = “https://toko.aseprohimat.com/”+halaman; }
penjelajah = (WebView) findViewById(R.id.penjelajah);
progress = (LinearLayout) findViewById(R.id.progress);
progress.setVisibility(View.GONE);
ikon = (ImageView) findViewById(R.id.ikon);
RotateAnimation animasi = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animasi.setInterpolator(new LinearInterpolator());
animasi.setRepeatCount(Animation.INFINITE);
animasi.setFillEnabled(true);
animasi.setFillAfter(true);
animasi.setDuration(3000);
ikon.setAnimation(animasi);
ikon.startAnimation(animasi);
progress_bar = (ProgressBar) findViewById(R.id.progress_bar);
progress_bar.setMax(100);
penjelajah.setWebViewClient(new KlienWebview());
penjelajah.setWebChromeClient(new KlienChrome());
penjelajah.setOverScrollMode(View.OVER_SCROLL_NEVER);
penjelajah.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
penjelajah.setLongClickable(false);
penjelajah.setHapticFeedbackEnabled(false);
WebSettings pengaturan = penjelajah.getSettings();
pengaturan.setAllowFileAccess(true);
pengaturan.setAllowContentAccess(true);
pengaturan.setUserAgentString(“Toko Asep Rohimat (https://toko.aseprohimat.com)”);
pengaturan.setDomStorageEnabled(true);
pengaturan.setPluginState(WebSettings.PluginState.ON);
pengaturan.setJavaScriptEnabled(true);
pengaturan.setLoadsImagesAutomatically(true);
pengaturan.setRenderPriority(WebSettings.RenderPriority.HIGH);
pengaturan.setSupportZoom(false);
pengaturan.setSavePassword(false);
pengaturan.setBlockNetworkImage(false);
pengaturan.setSupportMultipleWindows(false);
pengaturan.setAppCacheEnabled(true);
penjelajah.loadUrl(url);
ConnectivityManager koneksi=(ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo jaringanWiFi = (NetworkInfo) koneksi.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(jaringanWiFi.isConnected()||(koneksi.getActiveNetworkInfo()!=null&&koneksi.getActiveNetworkInfo().isAvailable()&&koneksi.getActiveNetworkInfo().isConnected())) { penjelajah.loadUrl(url); }
else { penjelajah.loadData(kesalahan(),”text/html”,null); }
}
private class KlienWebview extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView tinjauan, String url){
if(url.startsWith(“tel:”)) { Kontak(“Telepon”,url); return true; }
if(url.startsWith(“sms:”)) { Kontak(“SMS”,url); return true; }
if(url.startsWith(“bbmi:”)) { SosMed(“BBM”,url); return true; }
if(url.startsWith(“tg:”)) { SosMed(“Telegram”,url); return true; }
if(url.startsWith(“whatsapp:”)) { SosMed(“WhatsApp”,url); return true; }
if(url.startsWith(“mailto:”)) { Kontak(“Email”,url); return true; }
tinjauan.loadUrl(url);
return false;
}
@Override
public void onPageFinished(WebView tinjauan, String url) {
super.onPageFinished(tinjauan, url);
progress.setVisibility(View.GONE);
progress_bar.setVisibility(View.GONE);
progress_bar.setProgress(100);
}
@Override
public void onPageStarted(WebView tinjauan, String url, Bitmap ikon) {
super.onPageStarted(tinjauan, url, ikon);
progress.setVisibility(View.VISIBLE);
progress_bar.setVisibility(View.VISIBLE);
progress_bar.setProgress(0);
}
public void onReceivedError(WebView tinjauan,int kodeKesalahan,String deskripsi,String alamatTidakBerhasil) { penjelajah.loadData(kesalahan(),”text/html”,null); }
}
private class KlienChrome extends WebChromeClient {
public void onProgressChanged(WebView tinjauan, int kemajuan) {
progress_bar.setProgress(kemajuan);
}
protected void openFileChooser(ValueCallback uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType(“image/*”);
startActivityForResult(Intent.createChooser(i, “Pilih Foto”), FILECHOOSER_RESULTCODE);
}
public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
if (uploadMessage != null) {
uploadMessage.onReceiveValue(null);
uploadMessage = null;
}
uploadMessage = filePathCallback;
Intent intent = fileChooserParams.createIntent();
try {
startActivityForResult(intent, REQUEST_SELECT_FILE);
} catch (ActivityNotFoundException e) {
uploadMessage = null;
Toast.makeText(getApplicationContext(), “Tidak dapat membuka pemilih foto”, Toast.LENGTH_LONG).show();
return false;
}
return true;
}
protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mUploadMessage = uploadMsg;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(“image/*”);
startActivityForResult(Intent.createChooser(intent, “Pilih Foto”), FILECHOOSER_RESULTCODE);
}

protected void openFileChooser(ValueCallback<Uri> uploadMsg)
{
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType(“image/*”);
startActivityForResult(Intent.createChooser(i, “Pilih Foto”), FILECHOOSER_RESULTCODE);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (requestCode == REQUEST_SELECT_FILE) {
if (uploadMessage == null) return;
uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
uploadMessage = null;
}
}
else if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == mUploadMessage) return;
Uri result = intent == null || resultCode != Penjelajah.RESULT_OK ? null : intent.getData();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
else {
Toast.makeText(getApplicationContext(), “Gagal mengunggah foto”, Toast.LENGTH_LONG).show();
}
}
public String kesalahan(){
return “<!doctype html><html><head><style type=\”text/css\”>html,body{position:relative;width:100%;height:100%;}body{background: #8ba6fd;color: #414141;font: 16px arial,helvetica,sans-serif;border: 0px none;margin: 0px;padding: 0px;}img{border: 0px none;margin: 0px;padding: 0px;vertical-align: top;}.latar-bergaris-atas{background:#c9e5ff;color:#000000;border:1px solid #0024e9;padding:10px;margin-bottom:2px;padding:20px}</style><title>Koneksi Internet Terputus</title><meta name=\”viewport\” content=\”user-scalable=no,initial-scale=1,maximum-scale=1\”/></head><body><table width=\”100%\” height=\”100%\” style=\”margin:0;padding:0;border:0 none;border-spacing:0;border-collapse:collapse\”><tr><td align=\”center\” valign=\”middle\”><div style=\”padding:10px\”><div style=\”background:#003fff;color:#e9f0ff;border-top:1px solid #0024e9;border-radius:10px;-moz-border-radius:10px;-webkit-border-radius:10px;padding:0px\”><center><h2 style=\”font-size:16px;margin:0\”><table><tr><td><img src=\”data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQB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BwDEW9yyqjl6qesDNJ2xW0STVuFmJuHcZ6ntLD4mtQL3IVv1iWAdDfwwSGcu33tl64FffnXRTSOh0ZkI9ia6auDsP2wLVcu8zwgn06LU5jhpwqY9n41ScwKky4lC1y7HJ/vOZLLTCOlxQPy4pf3dUKyitaoNfT2bzku6ByLVd838akd8fn9hXY+U8Mm+OQbH8lLrHdGsjwQONaXmq+AOiYp38R0fjygORC2XdEVM4JtjpP/O8HsCvZ3GPQB4pZAMNOAkE5aqWTFvSH19MuumGG4sWcQGZdAEBRoM1mLliqkA9LFs7uLZ3Vdabct26TELA5EFQEzY9k2vPXtPwTzM0XMpVupF4ikGPyt4sdAw5B8PgJcSs9xb7RMM230C0swKmus/p+KF/3f8vwADAI/AMsoFsvSRAAAAAElFTkSuQmCC\” alt=\”Kesalahan\”/></td><td style=\”padding-left:10px\”>Data Tidak Aktif</td></tr></table></h2><div class=\”latar-bergaris-atas\” style=\”border-radius:0 0 10px 10px;-moz-border-radius:0 0 10px 10px;-webkit-border-radius:0 0 10px 10px;\”>Silahkan nyalakan data atau Wi-Fi perangkat Anda.</div></center></div></div></td></tr></table></body></html>”;
}
public void Kontak(String nama_aplikasi, String url){
switch (nama_aplikasi){
case “Telepon”: startActivity(new Intent(Intent.ACTION_CALL, Uri.fromParts(“tel”, url.replace(“tel:”, “”), null))); break;
case “SMS”: startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts(“sms”, url.replace(“tel:”, “”), null))); break;
case “Email”:
Intent kirim_email = new Intent(Intent.ACTION_SEND);
kirim_email.setType(“message/rfc822”);
kirim_email.putExtra(Intent.EXTRA_EMAIL,url.replace(“mailto:”,””));
kirim_email.putExtra(Intent.EXTRA_SUBJECT,””);
kirim_email.putExtra(Intent.EXTRA_TEXT,””);
try { startActivity(Intent.createChooser(kirim_email,”Kirim email…”)); }
catch (android.content.ActivityNotFoundException kesalahan) { Toast.makeText(kontek, “Ups! maaf, sepertinya tidak ada klien email yang diinstal…”, Toast.LENGTH_SHORT).show(); }
break;
}
}
public void SosMed(String nama_aplikasi, String url){
String nama = “”;
switch (nama_aplikasi){
case “WhatsApp”: nama = “com.whatsapp”; break;
case “Telegram”: nama = “org.telegram.messenger”; break;
case “BBM”: nama = “com.bbm”; break;
}
PackageManager aplikasi=kontek.getPackageManager();
try { aplikasi.getPackageInfo(nama, PackageManager.GET_META_DATA); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); }
catch (PackageManager.NameNotFoundException kesalahan){
try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(“market://details?id=”+nama))); }
catch (android.content.ActivityNotFoundException k) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(“http://play.google.com/store/apps/details?id=”+nama))); }
}
}
public boolean onOptionsItemSelected(MenuItem item){
if(penjelajah.canGoBack()){penjelajah.goBack();return(true);}
else{onBackPressed();}
return super.onOptionsItemSelected(item);
}
public boolean onKeyDown(int KodeTombol,KeyEvent kejadian){
if((KodeTombol==KeyEvent.KEYCODE_BACK)&&penjelajah.canGoBack()){penjelajah.goBack();return(true);}
else{return(super.onKeyDown(KodeTombol,kejadian));}
}
}

 

Itulah Source Code WebView¬†AsRo Store untuk Java Native nya untuk lengkapnya dengan Desainnya silahkan download aja ya, kode nya boleh di utak-atik lagi…

Good Job!

Download Source Code Install APK on Play Store

 

 

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

error: Konten terlindungi !!