Skip to content

Commit

Permalink
add donation
Browse files Browse the repository at this point in the history
  • Loading branch information
warkiz committed Sep 2, 2018
1 parent 26c45fe commit b73229f
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 14 deletions.
20 changes: 13 additions & 7 deletions app/src/main/java/com/warkiz/indicatorseekbar/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.warkiz.indicatorseekbar;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.warkiz.indicatorseekbar.donation.BaseActivity;
import com.warkiz.indicatorseekbar.donation.DonationFragment;
import com.warkiz.indicatorseekbar.fragment.ContinuousFragment;
import com.warkiz.indicatorseekbar.fragment.CustomFragment;
import com.warkiz.indicatorseekbar.fragment.DiscreteFragment;
Expand All @@ -22,15 +22,19 @@
* created by zhuangguangquan on 2017/9/6
*/

public class MainActivity extends AppCompatActivity {
public class MainActivity extends BaseActivity {

private static String[] sType = new String[]{"continuous", "discrete", "custom", "java", "indicator"};
private static String[] sType = new String[]{"continuous", "discrete", "custom", "java", "indicator", "donation"};
private List<Fragment> mFragmentList = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public int getLayoutResId() {
return R.layout.activity_main;
}

@Override
protected void initCreate() {
super.initCreate();
initFragment();
initViews();
}
Expand All @@ -41,6 +45,7 @@ private void initFragment() {
mFragmentList.add(new CustomFragment());
mFragmentList.add(new JavaBuildFragment());
mFragmentList.add(new IndicatorFragment());
mFragmentList.add(new DonationFragment());
}

private void initViews() {
Expand Down Expand Up @@ -80,4 +85,5 @@ public CharSequence getPageTitle(int position) {
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.warkiz.indicatorseekbar.donation;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.net.URISyntaxException;

/**
* the donation utils , no impact libs
*/
public class AlipayUtil {
private static final String ALIPAY_PACKAGE_NAME = "com.eg.android.AlipayGphone";
private static final String PAY_PATH = "FKX03308HBXT5XSEPAKCBB";

private static final String INTENT_URL_FORMAT = "intent://platformapi/startapp?saId=10000007&" +
"clientVersion=3.7.0.0718&qrcode=https%3A%2F%2Fqr.alipay.com%2F{urlCode}%3F_s" +
"%3Dweb-other&_t=1472443966571#Intent;" +
"scheme=alipayqr;package=com.eg.android.AlipayGphone;end";

public static boolean startAlipayClient(Activity activity, String urlCode) {
return startIntentUrl(activity, INTENT_URL_FORMAT.replace("{urlCode}", urlCode));
}

public static boolean startAlipayClient(Activity activity) {
return startIntentUrl(activity, INTENT_URL_FORMAT.replace("{urlCode}", PAY_PATH));
}

public static boolean startIntentUrl(Activity activity, String intentFullUrl) {
try {
Intent intent = Intent.parseUri(
intentFullUrl,
Intent.URI_INTENT_SCHEME
);
activity.startActivity(intent);
return true;
} catch (URISyntaxException e) {
e.printStackTrace();
return false;
}
}

public static boolean hasInstalledAlipayClient(Context context) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo info = pm.getPackageInfo(ALIPAY_PACKAGE_NAME, 0);
return info != null;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.warkiz.indicatorseekbar.donation;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public abstract class BaseActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResId());
initCreate();
}

protected void initCreate() {

}

public abstract int getLayoutResId();


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.warkiz.indicatorseekbar.donation;

import android.view.View;
import android.widget.Toast;

import com.warkiz.indicatorseekbar.R;
import com.warkiz.indicatorseekbar.fragment.BaseFragment;

/**
* the Fragment for donation, no impact libs
*/

public class DonationFragment extends BaseFragment {

@Override
protected int getLayoutId() {
return R.layout.buy_me_a_coffee;
}

@Override
protected void initView(View root) {
View alipay = root.findViewById(R.id.alipay_container);
alipay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
donation();
}
});
}

private void donation() {
if (AlipayUtil.hasInstalledAlipayClient(getContext())) {
AlipayUtil.startAlipayClient(getActivity());
} else {
Toast.makeText(getContext(), "No found alipay on your phone!", Toast.LENGTH_LONG).show();
}
}

}
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_more.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="1024"
android:viewportWidth="1024">
<path
android:fillColor="#FFFFFF"
android:pathData="M512,158.72c42.42,0 76.8,35.89 76.8,80.16s-34.38,80.16 -76.8,80.16 -76.8,-35.89 -76.8,-80.16S469.58,158.72 512,158.72z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M512,431.91c42.42,0 76.8,35.85 76.8,80.09 0,44.23 -34.38,80.09 -76.8,80.09S435.2,556.23 435.2,512C435.2,467.76 469.58,431.91 512,431.91z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M512,704.96c42.42,0 76.8,35.89 76.8,80.16S554.42,865.28 512,865.28s-76.8,-35.89 -76.8,-80.16S469.58,704.96 512,704.96z" />
</vector>
29 changes: 22 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@
android:orientation="vertical"
tools:context=".MainActivity">

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
app:tabGravity="center"
app:tabMode="scrollable"
app:tabSelectedTextColor="#FF4081"
app:tabTextColor="#FFF" />
android:orientation="vertical">

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorPrimaryDark"
app:tabGravity="center"
app:tabMode="scrollable"
app:tabSelectedTextColor="#FF4081"
app:tabTextColor="#FFF" />

<ImageView
android:visibility="gone"
android:id="@+id/buy_me_a_coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_more" />
</LinearLayout>


<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/res/layout/buy_me_a_coffee.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.warkiz.indicatorseekbar.MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:text="Buy me a coffee by Alipay or WeChatPay"
android:textColor="@color/color_blue"
android:textSize="18sp" />

<LinearLayout
android:id="@+id/alipay_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="40dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="I am clickable! "
android:textColor="@color/color_blue" />

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@mipmap/alipay" />

</LinearLayout>

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="40dp"
android:src="@mipmap/wechat_pay" />

</LinearLayout>

</ScrollView>
Binary file added app/src/main/res/mipmap-xxhdpi/alipay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxhdpi/wechat_pay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b73229f

Please sign in to comment.