Android Open Source - UniTracker J S Interface






From Project

Back to project page UniTracker.

License

The source code is released under:

MIT License

If you think the Android project UniTracker 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.connorroberts.unitracker.helpers;
//w w  w . j  av a 2 s .c  om
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.connorroberts.unitracker.R;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class JSInterface {
    Context mContext;
    View rootView;
    Activity activity;


    int[] layoutIDs = {
            R.id.choice1,
            R.id.choice2,
            R.id.choice3,
            R.id.choice4,
            R.id.choice5
    };

    int[] universityIDs = {
            R.id.name1,
            R.id.name2,
            R.id.name3,
            R.id.name4,
            R.id.name5
    };

    int[] courseIDs = {
            R.id.course1,
            R.id.course2,
            R.id.course3,
            R.id.course4,
            R.id.course5,
    };

    int[] statusIDs = {
            R.id.status1,
            R.id.status2,
            R.id.status3,
            R.id.status4,
            R.id.status5,
    };

    /** Instantiate the interface and set the context */
    public JSInterface(Context c, View v, Activity a) {

        mContext = c;
        rootView = v;
        activity = a;

    }

    @JavascriptInterface
    public void passData(final String choiceID, final String jsonStr) {

        activity.runOnUiThread(new Runnable() {

            @Override
            public void run() {

                int id = Integer.parseInt(choiceID) - 1;

                JsonObject json = new JsonParser().parse(jsonStr).getAsJsonObject();

                Log.e("", "University Name: " + json.get("universityName").toString());

                TextView universityName = (TextView) rootView.findViewById(universityIDs[id]);
                universityName.setText(json.get("universityName").getAsString() + " (" + json.get("universityCode").getAsString() + ")");

                TextView courseName = (TextView) rootView.findViewById(courseIDs[id]);
                courseName.setText(json.get("courseName").getAsString() + " (" + json.get("courseCode").getAsString() + ")");

                String status = json.get("status").getAsString();
                TextView statusView = (TextView) rootView.findViewById(statusIDs[id]);
                statusView.setText(status);

                if (status.equals("The university or college has offered you a place subject to conditions.")) {

                    statusView.setBackgroundColor(mContext.getResources().getColor(R.color.holo_green));

                }

                RelativeLayout progress = (RelativeLayout) rootView.findViewById(R.id.progress);
                if (progress.getVisibility() != View.GONE) {

                    progress.setVisibility(View.GONE);

                }

                RelativeLayout layout = (RelativeLayout) rootView.findViewById(layoutIDs[id]);
                layout.setVisibility(View.VISIBLE);

            }
        });

    }

}




Java Source Code List

com.connorroberts.unitracker.MainActivity.java
com.connorroberts.unitracker.fragments.LoginFragment.java
com.connorroberts.unitracker.fragments.MainFragment.java
com.connorroberts.unitracker.helpers.JSInterface.java
com.connorroberts.unitracker.helpers.SecurePreferences.java