Skip to content

Instantly share code, notes, and snippets.

View rakaadinugroho's full-sized avatar
✍️
Writing a Book

Raka Adi Nugroho rakaadinugroho

✍️
Writing a Book
View GitHub Profile
@rakaadinugroho
rakaadinugroho / newActivityFromSearchView.md
Created May 23, 2018 08:09 — forked from vxhviet/newActivityFromSearchView.md
Start new activity from SearchView

Source: StackOverflow

This answer is a little late but I feel it'll be useful for future viewers. The dilemma seems to come from the ambiguity of the Android SearchView tutorial. The scenario they cover assumes you will be displaying the results in the same Activity the SearchView resides. In such a scenario, the Activity tag in the AndroidManifest.xml file would look something like this:

<activity
    android:name=".MainActivity"
    android:label="@string/main_activity_label"
    android:launchMode="singleTop">
        <intent-filter>
@rakaadinugroho
rakaadinugroho / CurrencyUtils.java
Created April 25, 2018 05:25
Currency Utils EditText
package id.privy.reimbusment.utils;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import java.text.DecimalFormat;
import java.text.ParseException;
/**
@rakaadinugroho
rakaadinugroho / ImageCompressor.java
Created April 18, 2018 05:38
Image Compressor Java
public class ImageCompressor {
String TAG = "ImageCompressor";
Context context;
public ImageCompressor(Context context) {
this.context = context;
}
public String compressImage(Uri imageUri) {
File originalSize = FileUtils.getFile(context, imageUri);
@rakaadinugroho
rakaadinugroho / FileUtils.java
Created April 18, 2018 05:37
File Utils (Uri)
public class FileUtils {
public static boolean isLocal(String url) {
if (url != null && !url.startsWith("http://") && !url.startsWith("https://")) {
return true;
}
return false;
}
/**
* @param uri The Uri to check.
package com.rakaadinugroho.privyid.utils;
import android.util.Log;
import org.apache.commons.codec.binary.Base64;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@rakaadinugroho
rakaadinugroho / ItemClick
Created November 19, 2017 08:52
ItemClick
String rawDetail = new Gson().toJson(items.get(position));
Intent intent = new Intent(DashboardActivity.this, DetailActivity.class);
intent.putExtra("detail_book", rawDetail);
startActivity(intent);
@rakaadinugroho
rakaadinugroho / InitViews
Created November 19, 2017 08:49
InitViews Punyanya Detail Activity
private void initViews() {
detail_writer = (TextView) findViewById(R.id.detail_writer);
detail_desc = (TextView) findViewById(R.id.detail_desc);
detail_pict = (ImageView) findViewById(R.id.detail_pict);
String rawDetail = getIntent().getStringExtra("detail_book");
detail = new Gson().fromJson(rawDetail, Item.class);
Picasso.with(this)
.load(detail.getVolumeInfo().getImageLinks().getSmallThumbnail())
@rakaadinugroho
rakaadinugroho / Anotasi
Created November 19, 2017 07:52
Anotasi
compile 'javax.annotation:javax.annotation-api:1.2'
@rakaadinugroho
rakaadinugroho / RecyclerItemClickListener.java
Created November 19, 2017 07:49
Recycler Item Click Listener
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
private GestureDetector mGestureDetector;
public interface OnItemClickListener{
void onItemClick(View view, int position);
void onLongItemClick(View view, int position);
}
public RecyclerItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener){
mListener = listener;
@rakaadinugroho
rakaadinugroho / loaddata
Created November 19, 2017 06:53
Load Data
private void loadData() {
NetworkStores api = NetworkClient.getRetrofit().create(NetworkStores.class);
Call<ResponseBooks> response = api.getBooks("Machine Learning");
response.enqueue(new Callback<ResponseBooks>() {
@Override
public void onResponse(Call<ResponseBooks> call, Response<ResponseBooks> response) {
items.addAll(response.body().getItems());
adapter.notifyDataSetChanged();
}