Android Open Source - Kite Calc Fragment






From Project

Back to project page Kite.

License

The source code is released under:

Apache License

If you think the Android project Kite 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 org.kite.sample;
/*w  ww  . j av a  2s  . c o m*/
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import org.kite.annotations.AsyncResult;
import org.kite.annotations.Wired;
import org.kite.wire.Wire;


public class CalcFragment extends Fragment {

    private Wire wire;

    @Wired
    private Substractor substractor;

    @AsyncResult(Substractor.ADD_RESULT)
    public void onAdd(Integer result){
        Toast.makeText(getActivity(), " 7 + 8 = " + result, Toast.LENGTH_SHORT).show();
    }

    private View.OnClickListener btnListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.btn_five_sub_three:
                    int two = substractor.sub(5, 3);
                    Toast.makeText(getActivity(), "5 - 3 = " + two, Toast.LENGTH_SHORT).show();
                    break;
                case R.id.btn_add_async:
                    substractor.asyncAdd(7, 8);
                    break;
            }
        }
    };


    public CalcFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent serviceIntent = new Intent(getActivity(), SampleService.class)
                .setAction(SampleService.ACTION_BIND_SUBSTRACTOR);
        wire = Wire.with(getActivity())
                .from(serviceIntent)
                .to(this);
    }

    @Override
    public void onStart() {
        super.onStart();
        wire.connect();
    }

    @Override
    public void onStop() {
        super.onStop();
        wire.disconnect();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_calc, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        view.findViewById(R.id.btn_five_sub_three)
                .setOnClickListener(btnListener);
        view.findViewById(R.id.btn_add_async)
                .setOnClickListener(btnListener);
        super.onViewCreated(view, savedInstanceState);
    }

}




Java Source Code List

org.kite.annotations.AsyncMethod.java
org.kite.annotations.AsyncResult.java
org.kite.annotations.Provided.java
org.kite.annotations.Wired.java
org.kite.async.AsyncHandler.java
org.kite.async.AsyncType.java
org.kite.async.MethodResult.java
org.kite.async.ResultQueue.java
org.kite.sample.CalcFragment.java
org.kite.sample.CalcInterface.java
org.kite.sample.Calculator.java
org.kite.sample.MainActivity.java
org.kite.sample.SampleService.java
org.kite.sample.Substractor.java
org.kite.services.CommandService.java
org.kite.services.MainThreadExecutor.java
org.kite.wire.ClientFacade.java
org.kite.wire.InterfaceFinder.java
org.kite.wire.ServiceFacade.java
org.kite.wire.WireBinder.java
org.kite.wire.WireCallback.java
org.kite.wire.Wire.java
org.kite.wire.WiredService.java
org.kite.wire.package-info.java