Skip to content

Instantly share code, notes, and snippets.

View ccjeng's full-sized avatar

Andy Cheng ccjeng

  • Taiwan
View GitHub Profile
@ccjeng
ccjeng / CustomInfoWindowAdapter.java
Last active February 27, 2024 12:40
Custom InfoWindow Layout for Google Map in Android
public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private Activity context;
public CustomInfoWindowAdapter(Activity context){
this.context = context;
}
@Override
@ccjeng
ccjeng / TheBackupAgent-File.java
Created June 22, 2016 04:39
BackupAgent for Android Backup API
public class TheBackupAgent extends BackupAgentHelper {
private static final String DB_NAME = "test.db"; // db name
@Override
public void onCreate() {
FileBackupHelper dbs = new FileBackupHelper(this, DB_NAME);
addHelper("dbs", dbs);
}
@ccjeng
ccjeng / RealmMigration.java
Created April 9, 2016 13:24
Realm backup / restore
public class RealmMigration {
private final static String TAG = RealmMigration.class.getName();
private Context context;
private Realm realm;
public RealmMigration(Context context) {
this.realm = Realm.getInstance(BaseApplication.realmConfiguration);
this.context = context;
@ccjeng
ccjeng / TabFragment.java
Created December 28, 2015 02:32
Android TabLayout TabFragment
public class TabFragment extends Fragment {
private static final String ARG_POSITION = "position";
private int position;
public static TabFragment newInstance(int position) {
TabFragment f = new TabFragment();
Bundle b = new Bundle();
b.putInt(ARG_POSITION, position);
@ccjeng
ccjeng / TabLayout_ViewPagerAdapter.java
Last active March 24, 2016 05:32
Android TabLayout ViewPagerAdapter
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final String[] tabTitles = { "Tab1", "Tab2", "Tab3" };
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
@ccjeng
ccjeng / TabLayout_onCreate.java
Created December 28, 2015 02:30
Android TabLayout onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
@ccjeng
ccjeng / TabLayout.xml
Created December 28, 2015 02:29
Android TabLayout Layout
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ccjeng
ccjeng / okhttp_callback.java
Last active October 30, 2021 19:40
Okhttp callback sample
OkHttpClient client = new OkHttpClient();
String url = "http://www.google.com";
Request request = new Request.Builder()
.url(url)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
@ccjeng
ccjeng / okhttp.java
Created December 28, 2015 02:23
Okhttp http response sample
OkHttpClient client = new OkHttpClient();
String url = "http://www.google.com";
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
//Response
@ccjeng
ccjeng / Jsoup2.java
Created December 28, 2015 02:21
Android Jsoup sample
String html = "<div>
An <a href='http://example.com/'><b>example</b></a> link.</div>
";
Document doc = Jsoup.parse(html);
Element link = doc.select("div > a").text(); //example
Element link = doc.select("div > a").html(); //<b>example</b>
Element link = doc.select("div > a").get(0).text(); //get first link
Element link = doc.select("div").text(); //example link.