Skip to content

Instantly share code, notes, and snippets.

View ponnamkarthik's full-sized avatar

Karthik Ponnam ponnamkarthik

View GitHub Profile
@ponnamkarthik
ponnamkarthik / ActivityMain.java
Created January 13, 2018 10:17
HTTP Utility using retrofit2 and okhttp
private void prepareNetwork() {
File httpCacheDirectory = new File(getCacheDir(), "responses");
int cacheSize = 10 * 1024 * 1024; // 10 MiB
Cache cache = new Cache(httpCacheDirectory, cacheSize);
OkHttpClient client = new OkHttpClient.Builder()
.cache(cache)
.addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
.build();
@ponnamkarthik
ponnamkarthik / MainActivity.java
Created November 11, 2017 20:22
In-app billing consume a purchase
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(@BillingResponse int responseCode, String outToken) {
if (responseCode == BillingResponse.OK) {
// Handle the success of the consume operation.
// For example, increase the number of coins inside the user's basket.
}
};
mBillingClient.consumeAsync(purchaseToken, listener);
@ponnamkarthik
ponnamkarthik / MainActivity.java
Created November 11, 2017 20:19
In-app billing purchased Item List
mBillingClient.queryPurchaseHistoryAsync(SkuType.INAPP,
new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(@BillingResponse int responseCode,
List<Purchase> purchasesList) {
if (responseCode == BillingResponse.OK
&& purchasesList != null) {
for (Purchase purchase : purchasesList) {
// Process the result.
}
@ponnamkarthik
ponnamkarthik / MainActivity.java
Last active February 11, 2019 04:20
In-app billing Items available for purchase
List<String> skuList = new ArrayList<>();
skuList.add("product_1");
skuList.add("product_2");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
if (responseCode == BillingClient.BillingResponse.OK
@ponnamkarthik
ponnamkarthik / MainActivity.java
Last active March 26, 2020 07:06
In-app billing Purchase Item / Subscribe
/**
* To purchase an Product
*/
final List<String> skuList = new ArrayList<>();
skuList.add("product_1"); // SKU Id
SkuDetailsParams params = SkuDetailsParams.newBuilder()
.setSkusList(skuList)
.setType(BillingClient.SkuType.INAPP)
@ponnamkarthik
ponnamkarthik / MainActivity.java
Last active July 28, 2018 23:23
In-app Billing Initalise
BillingClient mBillingClient;
mBillingClient = BillingClient.newBuilder(this).setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
for(Purchase purchase: purchases) {
//When every a new purchase is made
}
}
}).build();
@ponnamkarthik
ponnamkarthik / progaurd-android.txt
Created November 3, 2017 14:15
Progaurd android
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
@ponnamkarthik
ponnamkarthik / JustifyTextView.java
Created October 30, 2017 14:00
Justify TextView android
package com.ghm.rtoexam.utils;
/**
* Created by ponna on 16-08-2017.
*/
import android.content.Context;
import android.graphics.Canvas;
import android.support.v7.widget.AppCompatTextView;
import android.text.Layout;
@ponnamkarthik
ponnamkarthik / titlecase.java
Created October 15, 2017 20:00
Convert Text to Titlecase in Java
public static String toTitleCase(String str)
{
String[] words = str.trim().split(" ");
StringBuilder ret = new StringBuilder();
for(int i = 0; i < words.length; i++)
{
if(words[i].trim().length() > 0)
{
Log.e("words[i].trim",""+words[i].trim().charAt(0));
ret.append(Character.toUpperCase(words[i].trim().charAt(0)));
@ponnamkarthik
ponnamkarthik / avd_loading_bar.xml
Created October 2, 2017 13:31 — forked from nickbutcher/avd_loading_bar.xml
A prototype of a loading indicator utilizing repeated gradients. See https://twitter.com/crafty/status/914830571196571648
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 Google Inc.
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 distributed under the License