Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
talhahasanzia / Alarm.java
Last active September 6, 2017 08:54
Alarm issue
private void add()
{
AlarmManager am = (AlarmManager) getApplicationContext().getSystemService( Context.ALARM_SERVICE );
Intent intent = new Intent( getApplicationContext(), AlarmReceiver.class );
intent.setAction( "com.actions.alarms" );
intent.putExtra( "id", suppID );
@talhahasanzia
talhahasanzia / ContentAdapter.java
Created July 26, 2017 05:05
RecyclerView Adapter with onClick listener
public class ContentAdapter extends RecyclerView.Adapter<ContentAdapter.ViewHolder> {
public interface OnItemClickListener {
void onItemClick(ContentItem item);
}
private final List<ContentItem> items;
private final OnItemClickListener listener;
public ContentAdapter(List<ContentItem> items, OnItemClickListener listener) {
public class ListAdapter extends ArrayAdapter<Item> {
public ListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public ListAdapter(Context context, int resource, List<Item> items) {
super(context, resource, items);
}
private Handler mHandler = new Handler();
//Make sure you update Seekbar on UI thread
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if(mMediaPlayer != null){
int mCurrentPosition = mMediaPlayer.getCurrentPosition() / 1000;
mSeekBar.setProgress(mCurrentPosition);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mediaplayer">
<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@talhahasanzia
talhahasanzia / info.txt
Created July 6, 2017 09:56
MediaBrowserCompat
https://medium.com/google-developers/mediabrowserservicecompat-and-the-modern-media-playback-app-7959a5196d90
https://developer.android.com/reference/android/media/MediaPlayer.html
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FusedLocationProviderClient client =
LocationServices.getFusedLocationProviderClient(this);
client.requestLocationUpdates(LocationRequest.create(), pendingIntent)
@talhahasanzia
talhahasanzia / LoaderCursor.java
Created June 29, 2017 06:54
Loaders example android
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@talhahasanzia
talhahasanzia / FlipViewAnimation.java
Created June 23, 2017 07:58
Android flip view vertical animation (native).
public class FlipViewAnimation{
public static void flip( View firstView, View secondView, float duration)
{
firstView.animate().rotationX(90).setDuration(duration).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
firstView.setVisibility(View.GONE);
secondView.setRotationX(-90);
@talhahasanzia
talhahasanzia / ExpandableListAdapter.java
Last active June 21, 2017 09:24
Expandable List View boiler plate
public class ExpandableListAdapter extends BaseExpandableListAdapter
{
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {