Skip to content

Instantly share code, notes, and snippets.

View Isabellle's full-sized avatar

Isabelle Lepez Isabellle

View GitHub Profile
public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.example.yourpackagename", PackageManager.GET_SIGNATURES); //Your package name here
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
@Isabellle
Isabellle / BaseActivity.java
Last active November 10, 2017 21:57
Android - BroadCast Receiver - Check Connectivity
public class BaseActivity extends Activity implements OnConnectivityChangedListener {
private ConnectivityChangeReceiver connectivityChangeReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
connectivityChangeReceiver = new ConnectivityChangeReceiver(this);
IntentFilter filter = new IntentFilter();
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
registerReceiver(connectivityChangeReceiver, filter);
Make button move up when softkeyboard is shown
<activity android:windowSoftInputMode="adjustPan"> </activity>
Put next or done on SoftKeyboard
android:imeOptions="actionNext"
android:imeOptions="actionSend"
Empty states in Android, best practices
https://www.reddit.com/r/androiddev/comments/3bjnxi/best_way_to_handle_recyclerview_empty_state/https://www.reddit.com/r/androiddev/comments/3bjnxi/best_way_to_handle_recyclerview_empty_state/
@Isabellle
Isabellle / Activity.java
Created May 11, 2016 19:04
Android - Give Focus to EditText
itemTitle.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(itemTitle, InputMethodManager.SHOW_IMPLICIT);
@Isabellle
Isabellle / Picasso.java
Created May 12, 2016 08:05
Android - Picasso Loading & Cache Images
Picasso.with(context)
.load(item.getFrontImage())
.into(itemFrontImage);
@Isabellle
Isabellle / RecyclerViewListener.java
Created May 13, 2016 09:41
Get clicked item and its position in RecyclerView
//Based on the link: Why doesn't RecyclerView have onItemClickListener()? and How RecyclerView is different from Listview?, and also @Duncan's general idea, I give my solution here:
//define one interface 'RecyclerViewClickListener' for passing message from adapter to Activity/Fragment:
public interface RecyclerViewClickListener
{
public void recyclerViewListClicked(View v, int position);
}
//In Activity/Fragment implement the interface, and also pass listener to adapter:
@Override
@Isabellle
Isabellle / RequestPermission.java
Created May 23, 2016 09:28
Request one permission on Android
package isabelle.com.requestpermissiondemo;
import android.Manifest;
import android.annotation.TargetApi;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Isabellle
Isabellle / ChatMessage.java
Created June 4, 2016 16:33 — forked from puf/ChatMessage.java
Zero to App: Develop with Firebase (for Android - Google I/O 2016)
package com.google.firebase.zerotoapp;
public class ChatMessage {
public String name;
public String message;
public ChatMessage() {
}
public ChatMessage(String name, String message) {
@Isabellle
Isabellle / ClickableRecyclerViewAdapter.java
Last active July 2, 2016 11:49
RecyclerView + Viewholder
package com.yatoo.adapter.recyclerView;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
/**
* Created by student5303 on 4/04/16.
*/
public abstract class ClickableRecyclerViewAdapter<VH extends com.yatoo.adapter.recyclerView.ClickableViewHolder> extends RecyclerView.Adapter implements com.yatoo.adapter.recyclerView.ClickableViewHolder.ClickableViewHolderListener {
@Isabellle
Isabellle / ItemListingActivity.java
Created July 2, 2016 13:51
Simple Recyclerview + Viewholder
package com.yatoo.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;