Android Open Source - Coloring-book Main Menu






From Project

Back to project page Coloring-book.

License

The source code is released under:

Apache License

If you think the Android project Coloring-book listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kidsgames.menu;
//w  w w.  ja v a2  s.  com
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;

import com.android.vending.billing.IInAppBillingService;
import com.bugsense.trace.BugSenseHandler;
import com.google.analytics.tracking.android.Fields;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.MapBuilder;
import com.google.analytics.tracking.android.Tracker;
import com.vikinc.coloring.R;

public class MainMenu extends Activity implements OnClickListener {


    private final String ITEM_SKU = "com.pack2";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu);

        Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

        findViewById(R.id.pack1_button).setOnClickListener(this);
        findViewById(R.id.pack2_button).setOnClickListener(this);

        Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-51610813-3");
        tracker.send(MapBuilder.createAppView().set(Fields.SCREEN_NAME, "Home Screen").build());

        BugSenseHandler.initAndStartSession(MainMenu.this, "718d6664");
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.pack1_button:
                Intent intent = new Intent(this, DrawerSliderActivity.class);
                intent.putExtra("pack", "pack1");
                startActivity(intent);
                break;
            case R.id.pack2_button:

                Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-51610813-3");
                tracker.send(MapBuilder
                        .createEvent("Buy", "pack", "try_to_buy", null)
                        .build());

                if (deviceHasGoogleAccount())
                    buyClick(v);
                else {
                    tracker.send(MapBuilder
                            .createEvent("Buy", "pack", "no_account", null)
                            .build());
                }

                break;
        }
    }

    IInAppBillingService mService;

    ServiceConnection mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name,
                                       IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);

        }
    };

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1001) {
            if (resultCode == Activity.RESULT_OK) {
                try {
                    Intent intent = new Intent(this, DrawerSliderActivity.class);
                    intent.putExtra("pack", "pack2");
                    startActivity(intent);

                    Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-51610813-3");
                    tracker.send(MapBuilder
                            .createEvent("Buy", "pack", "item_bouth", null)
                            .build());
                } catch (Exception e) {

                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mServiceConn != null) {
            unbindService(mServiceConn);
        }

    }


    private boolean deviceHasGoogleAccount() {
        AccountManager accMan = AccountManager.get(this);
        Account[] accArray = accMan.getAccountsByType("com.google");
        return accArray.length >= 1 ? true : false;
    }

    public void buyClick(View view) {

        try {

            Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), ITEM_SKU, "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
            int s = buyIntentBundle.getInt("RESPONSE_CODE");
            switch (s) {
                case 0:
                    PendingIntent pendingIntent = buyIntentBundle
                            .getParcelable("BUY_INTENT");
                    startIntentSenderForResult(pendingIntent.getIntentSender(),
                            1001, new Intent(), 0,
                            0, 0);
                    break;
                case 7:
                    Intent intent = new Intent(this, DrawerSliderActivity.class);
                    intent.putExtra("pack", "pack2");
                    startActivity(intent);
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}




Java Source Code List

com.kidsgames.gamebase.DrawerActivity.java
com.kidsgames.gamebase.DrawingView.java
com.kidsgames.menu.DrawerSliderActivity.java
com.kidsgames.menu.FixedSpeedScroller.java
com.kidsgames.menu.FixedSpeedViewPager.java
com.kidsgames.menu.MainMenu.java
com.kidsgames.menu.SlideAdapter.java
com.kidsgames.utils.ResourceId.java
com.plattysoft.leonids.AnimatedParticle.java
com.plattysoft.leonids.ParticleField.java
com.plattysoft.leonids.ParticleSystem.java
com.plattysoft.leonids.Particle.java
com.plattysoft.leonids.initializers.AccelerationInitializer.java
com.plattysoft.leonids.initializers.ParticleInitializer.java
com.plattysoft.leonids.initializers.RotationInitiazer.java
com.plattysoft.leonids.initializers.RotationSpeedInitializer.java
com.plattysoft.leonids.initializers.ScaleInitializer.java
com.plattysoft.leonids.initializers.SpeeddByComponentsInitializer.java
com.plattysoft.leonids.initializers.SpeeddModuleAndRangeInitializer.java
com.plattysoft.leonids.modifiers.AccelerationModifier.java
com.plattysoft.leonids.modifiers.AlphaModifier.java
com.plattysoft.leonids.modifiers.ParticleModifier.java
com.plattysoft.leonids.modifiers.ScaleModifier.java