Example usage for android.view View setClickable

List of usage examples for android.view View setClickable

Introduction

In this page you can find the example usage for android.view View setClickable.

Prototype

public void setClickable(boolean clickable) 

Source Link

Document

Enables or disables click events for this view.

Usage

From source file:com.ns.developer.tagview.widget.TagCloudLinkView.java

/**
 * tag draw/*from   ww  w .j a  v  a  2s .  c o m*/
 */
public void drawTags() {

    if (!mInitialized) {
        return;
    }

    // clear all tag
    removeAllViews();

    // layout padding left & layout padding right
    float total = getPaddingLeft() + getPaddingRight();
    // ???index
    int index = 1;
    // ?
    int pindex = index;

    // List Index
    int listIndex = 0;
    for (String item : mTags) {
        final int position = listIndex;
        final String tag = item;

        // inflate tag layout
        View tagLayout = (View) mInflater.inflate(R.layout.tag, null);
        tagLayout.setId(index);
        //            tagLayout.setBackgroundColor(mTagLayoutColor);

        // tag text
        TextView tagView = (TextView) tagLayout.findViewById(R.id.tag_txt);
        tagView.setText(tag);
        tagView.setPadding(INNER_VIEW_PADDING, INNER_VIEW_PADDING, INNER_VIEW_PADDING, INNER_VIEW_PADDING);
        tagView.setTextColor(mTagTextColor);
        tagView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSelectListener != null) {
                    mSelectListener.onTagSelected(tag, position);
                }
            }
        });

        // calculateof tag layout width
        float tagWidth = tagView.getPaint().measureText(tag) + INNER_VIEW_PADDING * 2; // tagView padding (left & right)

        // deletable text
        TextView deletableView = (TextView) tagLayout.findViewById(R.id.delete_txt);
        if (mIsDeletable) {
            deletableView.setVisibility(View.VISIBLE);
            deletableView.setText(DEFAULT_DELETABLE_STRING);
            deletableView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteListener != null) {
                        String targetTag = tag;
                        TagCloudLinkView.this.remove(position);
                        mDeleteListener.onTagDeleted(targetTag, position);
                    }
                }
            });
            tagWidth += deletableView.getPaint().measureText(DEFAULT_DELETABLE_STRING) + INNER_VIEW_PADDING * 2; // deletableView Padding (left & right)
        } else {
            deletableView.setVisibility(View.GONE);
        }

        LayoutParams tagParams = new LayoutParams(HEIGHT_WC, HEIGHT_WC);
        tagParams.setMargins(0, 0, 0, 0);

        if (mWidth <= total + tagWidth + LAYOUT_WIDTH_OFFSET) {
            tagParams.addRule(RelativeLayout.BELOW, pindex);
            tagParams.topMargin = TAG_LAYOUT_TOP_MERGIN;
            // initialize total param (layout padding left & layout padding right)
            total = getPaddingLeft() + getPaddingRight();
            pindex = index;
        } else {
            tagParams.addRule(RelativeLayout.ALIGN_TOP, pindex);
            tagParams.addRule(RelativeLayout.RIGHT_OF, index - 1);
            if (index > 1) {
                tagParams.leftMargin = TAG_LAYOUT_LEFT_MERGIN;
                total += TAG_LAYOUT_LEFT_MERGIN;
            }
        }
        total += tagWidth;
        addView(tagLayout, tagParams);
        index++;
        listIndex++;
    }

    LayoutParams tagParams = new LayoutParams(HEIGHT_WC, HEIGHT_WC);
    tagParams.setMargins(0, 0, 0, 0);

    if (isAutoCompleteMode || !mIsDeletable) {
        return;
    }

    int tagWidth = 50; //25dp

    if (mWidth <= total + tagWidth + LAYOUT_WIDTH_OFFSET) {
        tagParams.addRule(RelativeLayout.BELOW, pindex);
        tagParams.topMargin = TAG_LAYOUT_TOP_MERGIN;
        // initialize total param (layout padding left & layout padding right)
        total = getPaddingLeft() + getPaddingRight();
        pindex = index;
    } else {
        tagParams.addRule(RelativeLayout.ALIGN_TOP, pindex);
        tagParams.addRule(RelativeLayout.RIGHT_OF, index - 1);
        if (index > 1) {
            tagParams.leftMargin = TAG_LAYOUT_LEFT_MERGIN;
            total += TAG_LAYOUT_LEFT_MERGIN;
        }
    }
    total += tagWidth;
    View tagLayout = (View) mInflater.inflate(R.layout.tag, null);
    addView(tagLayout, tagParams);
    tagLayout.findViewById(R.id.add_image_view).setVisibility(VISIBLE);
    tagLayout.findViewById(R.id.tag_txt).setVisibility(GONE);
    tagLayout.setClickable(true);
    tagLayout.setFocusable(true);
    tagLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mAddTagListener != null) {
                mAddTagListener.onAddTag();
            }
        }
    });
    int transparentColor = ContextCompat.getColor(getContext(), android.R.color.transparent);
    tagLayout.setBackgroundColor(transparentColor);

}

From source file:foam.starwisp.StarwispBuilder.java

public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) {

    String type = "";
    Integer tid = 0;//from w  ww.j  ava2 s .c  om
    String token = "";

    try {

        type = arr.getString(0);
        tid = arr.getInt(1);
        token = arr.getString(2);

    } catch (JSONException e) {
        Log.e("starwisp",
                "Error parsing update arguments for " + ctxname + " " + arr.toString() + e.toString());
    }

    final Integer id = tid;

    //Log.i("starwisp", "Update: "+type+" "+id+" "+token);

    try {

        // non widget commands
        if (token.equals("toast")) {
            Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT);
            LinearLayout linearLayout = (LinearLayout) msg.getView();
            View child = linearLayout.getChildAt(0);
            TextView messageTextView = (TextView) child;
            messageTextView.setTextSize(arr.getInt(4));
            msg.show();
            return;
        }

        if (token.equals("play-sound")) {
            String name = arr.getString(3);

            if (name.equals("ping")) {
                MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping);
                mp.start();
            }
            if (name.equals("active")) {
                MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active);
                mp.start();
            }
        }

        if (token.equals("soundfile-start-recording")) {
            String filename = arr.getString(3);
            m_SoundManager.StartRecording(filename);
        }
        if (token.equals("soundfile-stop-recording")) {
            m_SoundManager.StopRecording();
        }
        if (token.equals("soundfile-start-playback")) {
            String filename = arr.getString(3);
            m_SoundManager.StartPlaying(filename);
        }
        if (token.equals("soundfile-stop-playback")) {
            m_SoundManager.StopPlaying();
        }

        if (token.equals("vibrate")) {
            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(arr.getInt(3));
        }

        if (type.equals("replace-fragment")) {
            int ID = arr.getInt(1);
            String name = arr.getString(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction();

            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

            //ft.setCustomAnimations(  R.animator.fragment_slide_left_enter,
            //             R.animator.fragment_slide_right_exit);

            //ft.setCustomAnimations(
            //    R.animator.card_flip_right_in, R.animator.card_flip_right_out,
            //    R.animator.card_flip_left_in, R.animator.card_flip_left_out);
            ft.replace(ID, fragment);
            ft.addToBackStack(null);
            ft.commit();
            return;
        }

        if (token.equals("dialog-fragment")) {
            FragmentManager fm = ctx.getSupportFragmentManager();
            final int ID = arr.getInt(3);
            final JSONArray lp = arr.getJSONArray(4);
            final String name = arr.getString(5);

            final Dialog dialog = new Dialog(ctx);
            dialog.setTitle("Title...");

            LinearLayout inner = new LinearLayout(ctx);
            inner.setId(ID);
            inner.setLayoutParams(BuildLayoutParams(lp));

            dialog.setContentView(inner);

            //                Fragment fragment = ActivityManager.GetFragment(name);
            //                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            //                fragmentTransaction.add(ID,fragment);
            //                fragmentTransaction.commit();

            dialog.show();

            /*                DialogFragment df = new DialogFragment() {
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                     Bundle savedInstanceState) {
                LinearLayout inner = new LinearLayout(ctx);
                inner.setId(ID);
                inner.setLayoutParams(BuildLayoutParams(lp));
                    
                return inner;
            }
                    
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                Dialog ret = super.onCreateDialog(savedInstanceState);
                Log.i("starwisp","MAKINGDAMNFRAGMENT");
                    
                Fragment fragment = ActivityManager.GetFragment(name);
                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
                fragmentTransaction.add(1,fragment);
                fragmentTransaction.commit();
                return ret;
            }
                            };
                            df.show(ctx.getFragmentManager(), "foo");
            */
        }

        if (token.equals("time-picker-dialog")) {

            final Calendar c = Calendar.getInstance();
            int hour = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            // Create a new instance of TimePickerDialog and return it
            TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true);
            d.show();
            return;
        }
        ;

        if (token.equals("view")) {
            //ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse()));

            File f = new File(arr.getString(3));
            Uri fileUri = Uri.fromFile(f);

            Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
            String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(arr.getString(3));
            String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
            myIntent.setDataAndType(fileUri, mimetype);
            ctx.startActivity(myIntent);
            return;
        }

        if (token.equals("make-directory")) {
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3));
            file.mkdirs();
            return;
        }

        if (token.equals("list-files")) {
            final String name = arr.getString(3);
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5));
            // todo, should probably call callback with empty list
            if (file != null) {
                File list[] = file.listFiles();

                if (list != null) {
                    String code = "(";
                    for (int i = 0; i < list.length; i++) {
                        code += " \"" + list[i].getName() + "\"";
                    }
                    code += ")";

                    DialogCallback(ctx, ctxname, name, code);
                }
            }
            return;
        }

        if (token.equals("gps-start")) {
            final String name = arr.getString(3);

            if (m_LocationManager == null) {
                m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
                m_GPS = new DorisLocationListener(m_LocationManager);
            }

            m_GPS.Start((StarwispActivity) ctx, name, this, arr.getInt(5), arr.getInt(6));
            return;
        }

        if (token.equals("sensors-get")) {
            final String name = arr.getString(3);
            if (m_SensorHandler == null) {
                m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this);
            }
            m_SensorHandler.GetSensors((StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("sensors-start")) {
            final String name = arr.getString(3);
            final JSONArray requested_json = arr.getJSONArray(5);
            ArrayList<Integer> requested = new ArrayList<Integer>();

            try {
                for (int i = 0; i < requested_json.length(); i++) {
                    requested.add(requested_json.getInt(i));
                }
            } catch (JSONException e) {
                Log.e("starwisp", "Error parsing data in sensors start " + e.toString());
            }

            // start it up...
            if (m_SensorHandler == null) {
                m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this);
            }
            m_SensorHandler.StartSensors((StarwispActivity) ctx, name, this, requested);
            return;
        }

        if (token.equals("sensors-stop")) {
            if (m_SensorHandler != null) {
                m_SensorHandler.StopSensors();
            }
            return;
        }

        if (token.equals("walk-draggable")) {
            final String name = arr.getString(3);
            int iid = arr.getInt(5);
            DialogCallback(ctx, ctxname, name, WalkDraggable(ctx, name, ctxname, iid).replace("\\", ""));
            return;
        }

        if (token.equals("delayed")) {
            final String name = arr.getString(3);
            final int d = arr.getInt(5);
            Runnable timerThread = new Runnable() {
                public void run() {
                    DialogCallback(ctx, ctxname, name, "");
                }
            };
            m_Handler.removeCallbacksAndMessages(null);
            m_Handler.postDelayed(timerThread, d);
            return;
        }

        if (token.equals("network-connect")) {
            final String name = arr.getString(3);
            final String ssid = arr.getString(5);
            m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("http-request")) {
            Log.i("starwisp", "http-request called");
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http request");
                final String name = arr.getString(3);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "normal", "", name);
            }
            return;
        }

        if (token.equals("http-post")) {
            Log.i("starwisp", "http-post called");
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http request");
                final String name = arr.getString(3);
                final String url = arr.getString(5);
                final String data = arr.getString(6);
                m_NetworkManager.StartRequestThread(url, "post", data, name);
            }
            return;
        }

        if (token.equals("http-upload")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http ul request");
                final String filename = arr.getString(4);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "upload", "", filename);
            }
            return;
        }

        if (token.equals("http-download")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http dl request");
                final String filename = arr.getString(4);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "download", "", filename);
            }
            return;
        }

        if (token.equals("take-photo")) {
            photo(ctx, arr.getString(3), arr.getInt(4));
        }

        if (token.equals("bluetooth")) {
            final String name = arr.getString(3);
            m_Bluetooth.Start((StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("bluetooth-send")) {
            m_Bluetooth.Write(arr.getString(3));
        }

        if (token.equals("process-image-in-place")) {
            BitmapCache.ProcessInPlace(arr.getString(3));
        }

        if (token.equals("send-mail")) {
            final String to[] = new String[1];
            to[0] = arr.getString(3);
            final String subject = arr.getString(4);
            final String body = arr.getString(5);

            JSONArray attach = arr.getJSONArray(6);
            ArrayList<String> paths = new ArrayList<String>();
            for (int a = 0; a < attach.length(); a++) {
                Log.i("starwisp", attach.getString(a));
                paths.add(attach.getString(a));
            }

            email(ctx, to[0], "", subject, body, paths);
        }

        if (token.equals("date-picker-dialog")) {
            final Calendar c = Calendar.getInstance();
            int day = c.get(Calendar.DAY_OF_MONTH);
            int month = c.get(Calendar.MONTH);
            int year = c.get(Calendar.YEAR);

            final String name = arr.getString(3);

            // Create a new instance of TimePickerDialog and return it
            DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    DialogCallback(ctx, ctxname, name, day + " " + month + " " + year);
                }
            }, year, month, day);
            d.show();
            return;
        }
        ;

        if (token.equals("alert-dialog")) {
            final String name = arr.getString(3);
            final String msg = arr.getString(5);
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int result = 0;
                    if (which == DialogInterface.BUTTON_POSITIVE)
                        result = 1;
                    DialogCallback(ctx, ctxname, name, "" + result);
                }
            };
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();
            return;
        }

        if (token.equals("ok-dialog")) {
            final String name = arr.getString(3);
            final String msg = arr.getString(5);
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int result = 0;
                    if (which == DialogInterface.BUTTON_POSITIVE)
                        result = 1;
                    DialogCallback(ctx, ctxname, name, "" + result);
                }
            };
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setMessage(msg).setPositiveButton("Ok", dialogClickListener).show();
            return;
        }

        if (token.equals("start-activity")) {
            ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5));
            return;
        }

        if (token.equals("start-activity-goto")) {
            ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4));
            return;
        }

        if (token.equals("finish-activity")) {
            ctx.setResult(arr.getInt(3));
            ctx.finish();
            return;
        }

        ///////////////////////////////////////////////////////////

        if (id == 0) {
            Log.i("starwisp", "Zero ID, aborting...");
            return;
        }

        // now try and find the widget
        final View vv = ctx.findViewById(id);
        if (vv == null) {
            Log.i("starwisp", "Can't find widget : " + id);
            return;
        }

        // tokens that work on everything
        if (token.equals("hide")) {
            vv.setVisibility(View.GONE);
            return;
        }

        if (token.equals("show")) {
            vv.setVisibility(View.VISIBLE);
            return;
        }

        // only tested on spinners
        if (token.equals("disabled")) {
            vv.setAlpha(0.3f);
            //vv.getSelectedView().setEnabled(false);
            vv.setEnabled(false);
            return;
        }

        if (token.equals("enabled")) {
            vv.setAlpha(1.0f);
            //vv.getSelectedView().setEnabled(true);
            vv.setEnabled(true);
            return;
        }

        if (token.equals("animate")) {
            JSONArray trans = arr.getJSONArray(3);

            final TranslateAnimation animation = new TranslateAnimation(getPixelsFromDp(ctx, trans.getInt(0)),
                    getPixelsFromDp(ctx, trans.getInt(1)), getPixelsFromDp(ctx, trans.getInt(2)),
                    getPixelsFromDp(ctx, trans.getInt(3)));
            animation.setDuration(1000);
            animation.setFillAfter(false);
            animation.setInterpolator(new AnticipateOvershootInterpolator(1.0f));
            animation.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    vv.clearAnimation();
                    Log.i("starwisp", "animation end");
                    ((ViewManager) vv.getParent()).removeView(vv);

                    //LayoutParams lp = new LayoutParams(imageView.getWidth(), imageView.getHeight());
                    //lp.setMargins(50, 100, 0, 0);
                    //imageView.setLayoutParams(lp);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationStart(Animation animation) {
                    Log.i("starwisp", "animation start");
                }

            });

            vv.startAnimation(animation);
            return;
        }

        // tokens that work on everything
        if (token.equals("set-enabled")) {
            Log.i("starwisp", "set-enabled called...");
            vv.setEnabled(arr.getInt(3) == 1);
            vv.setClickable(arr.getInt(3) == 1);
            if (vv.getBackground() != null) {
                if (arr.getInt(3) == 0) {
                    //vv.setBackgroundColor(0x00000000);
                    vv.getBackground().setColorFilter(0x20000000, PorterDuff.Mode.MULTIPLY);
                } else {
                    vv.getBackground().setColorFilter(null);
                }
            }
            return;
        }

        if (token.equals("background-colour")) {
            JSONArray col = arr.getJSONArray(3);

            if (type.equals("linear-layout")) {
                vv.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            } else {
                //vv.setBackgroundColor();
                vv.getBackground().setColorFilter(
                        Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)),
                        PorterDuff.Mode.MULTIPLY);
            }
            vv.invalidate();
            return;
        }

        // special cases

        if (type.equals("linear-layout")) {
            //Log.i("starwisp","linear-layout update id: "+id);
            StarwispLinearLayout.Update(this, (LinearLayout) vv, token, ctx, ctxname, arr);
            return;
        }

        if (type.equals("relative-layout")) {
            StarwispRelativeLayout.Update(this, (RelativeLayout) vv, token, ctx, ctxname, arr);
            return;
        }

        if (type.equals("draggable")) {
            LinearLayout v = (LinearLayout) vv;
            if (token.equals("contents")) {
                v.removeAllViews();
                JSONArray children = arr.getJSONArray(3);
                for (int i = 0; i < children.length(); i++) {
                    Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
                }
            }

            if (token.equals("contents-add")) {
                JSONArray children = arr.getJSONArray(3);
                for (int i = 0; i < children.length(); i++) {
                    Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
                }
            }
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = (LinearLayout) vv;

            if (token.equals("grid-buttons")) {
                horiz.removeAllViews();

                JSONArray params = arr.getJSONArray(3);
                String buttontype = params.getString(0);
                int height = params.getInt(1);
                int textsize = params.getInt(2);
                LayoutParams lp = BuildLayoutParams(params.getJSONArray(3));
                final JSONArray buttons = params.getJSONArray(4);
                final int count = buttons.length();
                int vertcount = 0;
                LinearLayout vert = null;

                for (int i = 0; i < count; i++) {
                    JSONArray button = buttons.getJSONArray(i);

                    if (vertcount == 0) {
                        vert = new LinearLayout(ctx);
                        vert.setId(0);
                        vert.setOrientation(LinearLayout.VERTICAL);
                        horiz.addView(vert);
                    }
                    vertcount = (vertcount + 1) % height;

                    if (buttontype.equals("button")) {
                        Button b = new Button(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("toggle")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                String arg = "#f";
                                if (((ToggleButton) v).isChecked())
                                    arg = "#t";
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("single")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                try {
                                    for (int i = 0; i < count; i++) {
                                        JSONArray button = buttons.getJSONArray(i);
                                        int bid = button.getInt(0);
                                        if (bid != v.getId()) {
                                            ToggleButton tb = (ToggleButton) ctx.findViewById(bid);
                                            tb.setChecked(false);
                                        }
                                    }
                                } catch (JSONException e) {
                                    Log.e("starwisp", "Error parsing on click data " + e.toString());
                                }

                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    }

                }
            }
        }

        /*
                    if (type.equals("grid-layout")) {
        GridLayout v = (GridLayout)vv;
        if (token.equals("contents")) {
            v.removeAllViews();
            JSONArray children = arr.getJSONArray(3);
            for (int i=0; i<children.length(); i++) {
                Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
            }
        }
                    }
        */
        if (type.equals("view-pager")) {
            ViewPager v = (ViewPager) vv;
            if (token.equals("switch")) {
                v.setCurrentItem(arr.getInt(3));
            }
            if (token.equals("pages")) {
                final JSONArray items = arr.getJSONArray(3);
                v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {
                    @Override
                    public int getCount() {
                        return items.length();
                    }

                    @Override
                    public Fragment getItem(int position) {
                        try {
                            String fragname = items.getString(position);
                            return ActivityManager.GetFragment(fragname);
                        } catch (JSONException e) {
                            Log.e("starwisp", "Error parsing pages data " + e.toString());
                        }
                        return null;
                    }
                });
            }
        }

        if (type.equals("image-view")) {
            ImageView v = (ImageView) vv;
            if (token.equals("image")) {
                int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName());
                v.setImageResource(iid);
            }
            if (token.equals("external-image")) {
                v.setImageBitmap(BitmapCache.Load(arr.getString(3)));
            }
            return;
        }

        if (type.equals("text-view") || type.equals("debug-text-view")) {
            TextView v = (TextView) vv;
            if (token.equals("text")) {
                if (type.equals("debug-text-view")) {
                    //v.setMovementMethod(new ScrollingMovementMethod());
                }
                v.setText(Html.fromHtml(arr.getString(3)), BufferType.SPANNABLE);
                //                    v.invalidate();
            }
            if (token.equals("file")) {
                v.setText(LoadData(arr.getString(3)));
            }

            return;
        }

        if (type.equals("edit-text")) {
            EditText v = (EditText) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }
            if (token.equals("request-focus")) {
                v.requestFocus();
                InputMethodManager imm = (InputMethodManager) ctx
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
            }
            return;
        }

        if (type.equals("button")) {
            Button v = (Button) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = (ToggleButton) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
                return;
            }

            if (token.equals("checked")) {
                if (arr.getInt(3) == 0)
                    v.setChecked(false);
                else
                    v.setChecked(true);
                return;
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = (StarwispCanvas) vv;
            if (token.equals("drawlist")) {
                v.SetDrawList(arr.getJSONArray(3));
            }
            return;
        }

        if (type.equals("camera-preview")) {
            final CameraPreview v = (CameraPreview) vv;

            if (token.equals("take-picture")) {
                final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3);

                v.TakePicture(new PictureCallback() {
                    public void onPictureTaken(byte[] input, Camera camera) {
                        Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length);
                        Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true);
                        ByteArrayOutputStream blob = new ByteArrayOutputStream();
                        resized.compress(Bitmap.CompressFormat.JPEG, 100, blob);

                        String datetime = getDateTime();
                        String filename = path + datetime + ".jpg";
                        SaveData(filename, blob.toByteArray());
                        v.Shutdown();
                        ctx.finish();
                    }
                });
            }

            // don't shut the activity down and use provided path
            if (token.equals("take-picture-cont")) {
                final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3);

                Log.i("starwisp", "take-picture-cont fired");

                v.TakePicture(new PictureCallback() {
                    public void onPictureTaken(byte[] input, Camera camera) {
                        Log.i("starwisp", "on picture taken...");

                        // the version used by the uav app

                        Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length);
                        //Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true);
                        ByteArrayOutputStream blob = new ByteArrayOutputStream();
                        original.compress(Bitmap.CompressFormat.JPEG, 95, blob);
                        original.recycle();
                        String filename = path;
                        Log.i("starwisp", path);
                        SaveData(filename, blob.toByteArray());

                        // burn gps into exif data
                        if (m_GPS.currentLocation != null) {
                            double latitude = m_GPS.currentLocation.getLatitude();
                            double longitude = m_GPS.currentLocation.getLongitude();

                            try {
                                ExifInterface exif = new ExifInterface(filename);
                                exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPS.convert(latitude));
                                exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,
                                        GPS.latitudeRef(latitude));
                                exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPS.convert(longitude));
                                exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,
                                        GPS.longitudeRef(longitude));
                                exif.saveAttributes();
                            } catch (IOException e) {
                                Log.i("starwisp",
                                        "Couldn't open " + filename + " to add exif data: ioexception caught.");
                            }

                        }

                        v.TakenPicture();
                    }
                });
            }

            if (token.equals("shutdown")) {
                v.Shutdown();
            }

            return;
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            if (token.equals("max")) {
                // android seekbar bug workaround
                int p = v.getProgress();
                v.setMax(0);
                v.setProgress(0);
                v.setMax(arr.getInt(3));
                v.setProgress(1000);

                // not working.... :(
            }
        }

        if (type.equals("spinner")) {
            Spinner v = (Spinner) vv;

            if (token.equals("selection")) {
                v.setSelection(arr.getInt(3));
            }

            if (token.equals("array")) {
                final JSONArray items = arr.getJSONArray(3);
                ArrayList<String> spinnerArray = new ArrayList<String>();

                for (int i = 0; i < items.length(); i++) {
                    spinnerArray.add(items.getString(i));
                }

                ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                        spinnerArray) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        View v = super.getView(position, convertView, parent);
                        ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                        return v;
                    }
                };

                spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);
                v.setAdapter(spinnerArrayAdapter);

                final int wid = id;
                // need to update for new values
                v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                        CallbackArgs(ctx, ctxname, wid, "" + pos);
                    }

                    public void onNothingSelected(AdapterView<?> v) {
                    }
                });

            }
            return;
        }

        if (type.equals("draw-map")) {
            DrawableMap v = m_DMaps.get(id);
            if (v != null) {
                if (token.equals("polygons")) {
                    v.UpdateFromJSON(arr.getJSONArray(3));
                }
                if (token.equals("centre")) {
                    JSONArray tokens = arr.getJSONArray(3);
                    v.Centre(tokens.getDouble(0), tokens.getDouble(1), tokens.getInt(2));
                }
                if (token.equals("layout")) {
                    v.m_parent.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
                }
            } else {
                Log.e("starwisp", "Asked to update a drawmap which doesn't exist");
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing builder data " + e.toString());
        Log.e("starwisp", "type:" + type + " id:" + id + " token:" + token);
    }
}

From source file:com.battlelancer.seriesguide.ui.OverviewFragment.java

@SuppressLint("NewApi")
private void onPopulateEpisodeData(Cursor episode) {
    mCurrentEpisodeCursor = episode;/*from w  ww  . j  a  v  a  2s  . co m*/

    final TextView episodeTitle = (TextView) getView().findViewById(R.id.episodeTitle);
    final TextView episodeTime = (TextView) getView().findViewById(R.id.episodeTime);
    final TextView episodeSeasonAndNumber = (TextView) getView().findViewById(R.id.episodeInfo);
    final View episodemeta = getView().findViewById(R.id.episode_meta_container);
    final View episodePrimaryContainer = getView().findViewById(R.id.episode_primary_container);
    final View buttons = getView().findViewById(R.id.buttonbar);
    final View ratings = getView().findViewById(R.id.ratingbar);

    if (episode != null && episode.moveToFirst()) {
        // some episode properties
        mCurrentEpisodeTvdbId = episode.getInt(EpisodeQuery._ID);

        // title
        episodeTitle.setText(episode.getString(EpisodeQuery.TITLE));

        // number
        StringBuilder infoText = new StringBuilder();
        infoText.append(getString(R.string.season_number, episode.getInt(EpisodeQuery.SEASON)));
        infoText.append(" ");
        int episodeNumber = episode.getInt(EpisodeQuery.NUMBER);
        infoText.append(getString(R.string.episode_number, episodeNumber));
        int episodeAbsoluteNumber = episode.getInt(EpisodeQuery.ABSOLUTE_NUMBER);
        if (episodeAbsoluteNumber > 0 && episodeAbsoluteNumber != episodeNumber) {
            infoText.append(" (").append(episodeAbsoluteNumber).append(")");
        }
        episodeSeasonAndNumber.setText(infoText);

        // air date
        long releaseTime = episode.getLong(EpisodeQuery.FIRST_RELEASE_MS);
        if (releaseTime != -1) {
            Date actualRelease = TimeTools.getEpisodeReleaseTime(getActivity(), releaseTime);
            // "in 14 mins (Fri)"
            episodeTime.setText(getString(R.string.release_date_and_day,
                    TimeTools.formatToRelativeLocalReleaseTime(getActivity(), actualRelease),
                    TimeTools.formatToLocalReleaseDay(actualRelease)));
        } else {
            episodeTime.setText(null);
        }

        // make title and image clickable
        episodePrimaryContainer.setOnClickListener(new OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View view) {
                // display episode details
                Intent intent = new Intent(getActivity(), EpisodesActivity.class);
                intent.putExtra(EpisodesActivity.InitBundle.EPISODE_TVDBID, mCurrentEpisodeTvdbId);

                ActivityCompat.startActivity(getActivity(), intent, ActivityOptionsCompat
                        .makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight()).toBundle());
            }
        });
        episodePrimaryContainer.setFocusable(true);

        // Button bar
        // check-in button
        View checkinButton = buttons.findViewById(R.id.buttonEpisodeCheckin);
        checkinButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onCheckIn();
            }
        });
        CheatSheet.setup(checkinButton);

        // watched button
        View watchedButton = buttons.findViewById(R.id.buttonEpisodeWatched);
        watchedButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable button, will be re-enabled on data reload once action completes
                v.setEnabled(false);
                onEpisodeWatched();
            }
        });
        watchedButton.setEnabled(true);
        CheatSheet.setup(watchedButton);

        // collected button
        boolean isCollected = episode.getInt(EpisodeQuery.COLLECTED) == 1;
        Button collectedButton = (Button) buttons.findViewById(R.id.buttonEpisodeCollected);
        Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(collectedButton, 0,
                isCollected ? R.drawable.ic_collected
                        : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollect),
                0, 0);
        collectedButton
                .setText(isCollected ? R.string.action_collection_remove : R.string.action_collection_add);
        CheatSheet.setup(collectedButton,
                isCollected ? R.string.action_collection_remove : R.string.action_collection_add);
        collectedButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable button, will be re-enabled on data reload once action completes
                v.setEnabled(false);
                onToggleCollected();
            }
        });
        collectedButton.setEnabled(true);

        // skip button
        View skipButton = buttons.findViewById(R.id.buttonEpisodeSkip);
        skipButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable button, will be re-enabled on data reload once action completes
                v.setEnabled(false);
                onEpisodeSkipped();
            }
        });
        skipButton.setEnabled(true);
        CheatSheet.setup(skipButton);

        // ratings
        ratings.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                rateOnTrakt();
            }
        });
        ratings.setFocusable(true);
        CheatSheet.setup(ratings, R.string.action_rate);

        // load all other info
        onLoadEpisodeDetails(episode);

        // episode image
        onLoadImage(episode.getString(EpisodeQuery.IMAGE));

        // episode actions
        loadEpisodeActionsDelayed();

        episodemeta.setVisibility(View.VISIBLE);
    } else {
        // no next episode: display single line info text, remove other
        // views
        episodeTitle.setText(R.string.no_nextepisode);
        episodeTime.setText(null);
        episodeSeasonAndNumber.setText(null);
        episodePrimaryContainer.setOnClickListener(null);
        episodePrimaryContainer.setClickable(false);
        episodePrimaryContainer.setFocusable(false);
        episodemeta.setVisibility(View.GONE);
        ratings.setOnClickListener(null);
        ratings.setClickable(false);
        ratings.setFocusable(false);
        onLoadImage(null);
    }

    // enable/disable applicable menu items
    getActivity().invalidateOptionsMenu();

    // animate view into visibility
    if (mContainerEpisode.getVisibility() == View.GONE) {
        final View progressContainer = getView().findViewById(R.id.progress_container);
        progressContainer.startAnimation(
                AnimationUtils.loadAnimation(episodemeta.getContext(), android.R.anim.fade_out));
        progressContainer.setVisibility(View.GONE);
        mContainerEpisode
                .startAnimation(AnimationUtils.loadAnimation(episodemeta.getContext(), android.R.anim.fade_in));
        mContainerEpisode.setVisibility(View.VISIBLE);
    }
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

public static void createViewRunnables() {
    viewRunnables = new HashMap<>(30);
    viewRunnables.put("scaleType", new ViewParamRunnable() {
        @Override//from  w  w w  .j  av a  2  s  . co m
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof ImageView) {
                ImageView.ScaleType scaleType = ((ImageView) view).getScaleType();
                switch (value.toLowerCase()) {
                case "center":
                    scaleType = ImageView.ScaleType.CENTER;
                    break;
                case "center_crop":
                    scaleType = ImageView.ScaleType.CENTER_CROP;
                    break;
                case "center_inside":
                    scaleType = ImageView.ScaleType.CENTER_INSIDE;
                    break;
                case "fit_center":
                    scaleType = ImageView.ScaleType.FIT_CENTER;
                    break;
                case "fit_end":
                    scaleType = ImageView.ScaleType.FIT_END;
                    break;
                case "fit_start":
                    scaleType = ImageView.ScaleType.FIT_START;
                    break;
                case "fit_xy":
                    scaleType = ImageView.ScaleType.FIT_XY;
                    break;
                case "matrix":
                    scaleType = ImageView.ScaleType.MATRIX;
                    break;
                }
                ((ImageView) view).setScaleType(scaleType);
            }
        }
    });
    viewRunnables.put("orientation", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof LinearLayout) {
                ((LinearLayout) view).setOrientation(
                        value.equals("vertical") ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);
            }
        }
    });
    viewRunnables.put("text", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setText(value);
            }
        }
    });
    viewRunnables.put("textSize", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX,
                        DimensionConverter.stringToDimension(value, view.getResources().getDisplayMetrics()));
            }
        }
    });
    viewRunnables.put("textColor", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setTextColor(parseColor(view, value));
            }
        }
    });
    viewRunnables.put("textStyle", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                int typeFace = Typeface.NORMAL;
                if (value.contains("bold"))
                    typeFace |= Typeface.BOLD;
                else if (value.contains("italic"))
                    typeFace |= Typeface.ITALIC;
                ((TextView) view).setTypeface(null, typeFace);
            }
        }
    });
    viewRunnables.put("textAlignment", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
                int alignment = View.TEXT_ALIGNMENT_TEXT_START;
                switch (value) {
                case "center":
                    alignment = View.TEXT_ALIGNMENT_CENTER;
                    break;
                case "left":
                case "textStart":
                    break;
                case "right":
                case "textEnd":
                    alignment = View.TEXT_ALIGNMENT_TEXT_END;
                    break;
                }
                view.setTextAlignment(alignment);
            } else {
                int gravity = Gravity.LEFT;
                switch (value) {
                case "center":
                    gravity = Gravity.CENTER;
                    break;
                case "left":
                case "textStart":
                    break;
                case "right":
                case "textEnd":
                    gravity = Gravity.RIGHT;
                    break;
                }
                ((TextView) view).setGravity(gravity);
            }
        }
    });
    viewRunnables.put("ellipsize", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                TextUtils.TruncateAt where = TextUtils.TruncateAt.END;
                switch (value) {
                case "start":
                    where = TextUtils.TruncateAt.START;
                    break;
                case "middle":
                    where = TextUtils.TruncateAt.MIDDLE;
                    break;
                case "marquee":
                    where = TextUtils.TruncateAt.MARQUEE;
                    break;
                case "end":
                    break;
                }
                ((TextView) view).setEllipsize(where);
            }
        }
    });
    viewRunnables.put("singleLine", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                ((TextView) view).setSingleLine();
            }
        }
    });
    viewRunnables.put("hint", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof EditText) {
                ((EditText) view).setHint(value);
            }
        }
    });
    viewRunnables.put("inputType", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof TextView) {
                int inputType = 0;
                switch (value) {
                case "textEmailAddress":
                    inputType |= InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
                    break;
                case "number":
                    inputType |= InputType.TYPE_CLASS_NUMBER;
                    break;
                case "phone":
                    inputType |= InputType.TYPE_CLASS_PHONE;
                    break;
                }
                if (inputType > 0)
                    ((TextView) view).setInputType(inputType);
            }
        }
    });
    viewRunnables.put("gravity", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            int gravity = parseGravity(value);
            if (view instanceof TextView) {
                ((TextView) view).setGravity(gravity);
            } else if (view instanceof LinearLayout) {
                ((LinearLayout) view).setGravity(gravity);
            } else if (view instanceof RelativeLayout) {
                ((RelativeLayout) view).setGravity(gravity);
            }
        }
    });
    viewRunnables.put("src", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            if (view instanceof ImageView) {
                String imageName = value;
                if (imageName.startsWith("//"))
                    imageName = "http:" + imageName;
                if (imageName.startsWith("http")) {
                    if (imageLoader != null) {
                        if (attrs.containsKey("cornerRadius")) {
                            int radius = DimensionConverter.stringToDimensionPixelSize(
                                    attrs.get("cornerRadius"), view.getResources().getDisplayMetrics());
                            imageLoader.loadRoundedImage((ImageView) view, imageName, radius);
                        } else {
                            imageLoader.loadImage((ImageView) view, imageName);
                        }
                    }
                } else if (imageName.startsWith("@drawable/")) {
                    imageName = imageName.substring("@drawable/".length());
                    ((ImageView) view).setImageDrawable(getDrawableByName(view, imageName));
                }
            }
        }
    });
    viewRunnables.put("visibility", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            int visibility = View.VISIBLE;
            String visValue = value.toLowerCase();
            if (visValue.equals("gone"))
                visibility = View.GONE;
            else if (visValue.equals("invisible"))
                visibility = View.INVISIBLE;
            view.setVisibility(visibility);
        }
    });
    viewRunnables.put("clickable", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            view.setClickable(value.equals("true"));
        }
    });
    viewRunnables.put("tag", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            // Sigh, this is dangerous because we use tags for other purposes
            if (view.getTag() == null)
                view.setTag(value);
        }
    });
    viewRunnables.put("onClick", new ViewParamRunnable() {
        @Override
        public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) {
            view.setOnClickListener(getClickListener(parent, value));
        }
    });
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

public void contextXposedPatch() {
      runWithWait(new Runnable() {
          public void run() {
              try {
                  listAppsFragment.this.runToMain(new Runnable() {
                      public void run() {
                          localArrayList = new ArrayList();
                          Object localObject = null;
                          try {
                              JSONObject localJSONObject = Utils.readXposedParamBoolean();
                              localObject = localJSONObject;
                          } catch (JSONException localJSONException) {
                              for (;;) {
                                  localJSONException.printStackTrace();
                                  localArrayList.add(new CoreItem(Utils.getText(2131165300), true));
                                  localArrayList.add(new CoreItem(Utils.getText(2131165302), true));
                                  localArrayList.add(new CoreItem(Utils.getText(2131165304), true));
                                  localArrayList.add(new CoreItem(Utils.getText(2131165307), true));
                                  localArrayList.add(new CoreItem(Utils.getText(2131165273), false));
                              }// w w  w.jav  a  2s  . com
                          }
                          if (localObject != null) {
                              localArrayList.clear();
                              localArrayList.add(new CoreItem(Utils.getText(2131165300),
                                      ((JSONObject) localObject).optBoolean("patch1", true)));
                              localArrayList.add(new CoreItem(Utils.getText(2131165302),
                                      ((JSONObject) localObject).optBoolean("patch2", true)));
                              localArrayList.add(new CoreItem(Utils.getText(2131165304),
                                      ((JSONObject) localObject).optBoolean("patch3", true)));
                              localArrayList.add(new CoreItem(Utils.getText(2131165307),
                                      ((JSONObject) localObject).optBoolean("patch4", true)));
                              localArrayList.add(new CoreItem(Utils.getText(2131165273),
                                      ((JSONObject) localObject).optBoolean("hide", false)));
                          }
                          if ((listAppsFragment.all_d != null) && (listAppsFragment.all_d.adapter != null)) {
                              listAppsFragment.all_d.adapter.notifyDataSetChanged();
                          }
                          listAppsFragment.removeDialogAll(39);
                          listAppsFragment.showDialogAll(39, new ArrayAdapter(listAppsFragment.this.getContext(),
                                  2130968605, localArrayList) {
                              TextView txtStatus;
                              TextView txtTitle;

                              public View getView(int paramAnonymous3Int, View paramAnonymous3View,
                                      ViewGroup paramAnonymous3ViewGroup) {
                                  CoreItem localCoreItem = (CoreItem) getItem(paramAnonymous3Int);
                                  View localView = ((LayoutInflater) listAppsFragment.getInstance()
                                          .getSystemService("layout_inflater")).inflate(2130968642,
                                                  paramAnonymous3ViewGroup, false);
                                  this.txtTitle = ((TextView) localView.findViewById(2131558483));
                                  this.txtStatus = ((TextView) localView.findViewById(2131558484));
                                  this.txtTitle.setTextAppearance(getContext(), listAppsFragment.getSizeText());
                                  this.txtStatus.setTextAppearance(getContext(), listAppsFragment.getSizeText());
                                  paramAnonymous3View = (CheckBox) localView.findViewById(2131558535);
                                  paramAnonymous3View.setChecked(localCoreItem.Status);
                                  if (!Utils.isXposedEnabled()) {
                                      paramAnonymous3View.setEnabled(false);
                                      paramAnonymous3View.setClickable(false);
                                      this.txtStatus.setTextAppearance(getContext(), 16973894);
                                      this.txtStatus.setTextColor(-7829368);
                                      this.txtTitle.setTextColor(-1);
                                      this.txtTitle.setText(((CoreItem) getItem(paramAnonymous3Int)).Name);
                                      this.txtTitle.setTypeface(null, 1);
                                      paramAnonymous3View = ((CoreItem) getItem(paramAnonymous3Int)).Name;
                                      this.txtTitle.setText(
                                              Utils.getColoredText(paramAnonymous3View, "#ff00ff00", "bold"));
                                      if (paramAnonymous3Int == 0) {
                                          paramAnonymous3View = Utils.getText(2131165301);
                                      }
                                      if (paramAnonymous3Int == 1) {
                                          paramAnonymous3View = Utils.getText(2131165303);
                                      }
                                      if (paramAnonymous3Int == 2) {
                                          paramAnonymous3View = Utils.getText(2131165305) + "\n"
                                                  + Utils.getText(2131165306);
                                      }
                                      if (paramAnonymous3Int == 3) {
                                          paramAnonymous3View = Utils.getText(2131165309);
                                      }
                                      if (paramAnonymous3Int == 4) {
                                          paramAnonymous3View = Utils.getText(2131165274);
                                      }
                                      paramAnonymous3ViewGroup = paramAnonymous3View;
                                      if (Utils.isXposedEnabled()) {
                                          paramAnonymous3ViewGroup = paramAnonymous3View;
                                          if (localCoreItem.Status) {
                                              if (paramAnonymous3Int == 0) {
                                                  if ((!Utils.checkCoreJarPatch11())
                                                          || (!Utils.checkCoreJarPatch12())) {
                                                      break label595;
                                                  }
                                                  this.txtTitle
                                                          .append(Utils.getColoredText(
                                                                  "\n" + Utils.getText(2131165815) + ": "
                                                                          + Utils.getText(2131165814),
                                                                  "#ff008800", ""));
                                              }
                                              label370: if (paramAnonymous3Int == 1) {
                                                  if (!Utils.checkCoreJarPatch20()) {
                                                      break label648;
                                                  }
                                                  this.txtTitle
                                                          .append(Utils.getColoredText(
                                                                  "\n" + Utils.getText(2131165815) + ": "
                                                                          + Utils.getText(2131165814),
                                                                  "#ff008800", ""));
                                              }
                                              label431: if (paramAnonymous3Int == 2) {
                                                  if (!Utils.checkCoreJarPatch30(listAppsFragment.getPkgMng())) {
                                                      break label701;
                                                  }
                                                  this.txtTitle
                                                          .append(Utils.getColoredText(
                                                                  "\n" + Utils.getText(2131165815) + ": "
                                                                          + Utils.getText(2131165814),
                                                                  "#ff008800", ""));
                                              }
                                              label495: if (paramAnonymous3Int == 3) {
                                                  if (!Utils.checkCoreJarPatch40()) {
                                                      break label754;
                                                  }
                                                  this.txtTitle
                                                          .append(Utils.getColoredText(
                                                                  "\n" + Utils.getText(2131165815) + ": "
                                                                          + Utils.getText(2131165814),
                                                                  "#ff008800", ""));
                                              }
                                          }
                                      }
                                  }
                                  for (;;) {
                                      paramAnonymous3ViewGroup = paramAnonymous3View;
                                      if (paramAnonymous3Int == 4) {
                                          paramAnonymous3ViewGroup = Utils.getText(2131165274);
                                      }
                                      this.txtStatus.append(Utils.getColoredText(paramAnonymous3ViewGroup,
                                              "#ff888888", "italic"));
                                      return localView;
                                      paramAnonymous3View.setEnabled(true);
                                      break;
                                      label595: this.txtTitle.append(Utils.getColoredText(
                                              "\n" + Utils.getText(2131165815) + ": " + Utils.getText(2131165806),
                                              "#ff880000", ""));
                                      break label370;
                                      label648: this.txtTitle.append(Utils.getColoredText(
                                              "\n" + Utils.getText(2131165815) + ": " + Utils.getText(2131165806),
                                              "#ff880000", ""));
                                      break label431;
                                      label701: this.txtTitle.append(Utils.getColoredText(
                                              "\n" + Utils.getText(2131165815) + ": " + Utils.getText(2131165806),
                                              "#ff880000", ""));
                                      break label495;
                                      label754: this.txtTitle.append(Utils.getColoredText(
                                              "\n" + Utils.getText(2131165815) + ": " + Utils.getText(2131165806),
                                              "#ff880000", ""));
                                  }
                              }
                          });
                          listAppsFragment.removeDialogLP(11);
                      }
                  });
                  return;
              } catch (Exception localException) {
                  System.out.println("LuckyPatcher: handler Null.");
              }
          }
      });
      System.out.println("LuckyPatcher: Start core.jar test!");
  }

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

public void contextCorePatch() {
      runWithWait(new Runnable() {
          public void run() {
              listAppsFragment.xposedNotify = true;
              if (((!Utils.checkCoreJarPatch11()) || (!Utils.checkCoreJarPatch12()))
                      && ((Utils.exists("/system/framework/core.jar.jex"))
                              || (Utils.exists("/system/framework/core-libart.jar.jex"))
                              || (Utils.exists("/system/framework/services.jar.jex")))) {
                  listAppsFragment.this.showMessage(Utils.getText(2131165748), Utils.getText(2131165819));
                  return;
              }// ww  w  .  j a  va 2 s .c o  m
              try {
                  listAppsFragment.fileNotSpace = Utils.exists("/system/framework/not.space");
                  listAppsFragment.filePatch3 = Utils.exists("/system/framework/patch3.done");
                  listAppsFragment.this.runToMain(new Runnable() {
                      public void run() {
                          ArrayList localArrayList = new ArrayList();
                          localArrayList.add(new CoreItem(Utils.getText(2131165300), false));
                          localArrayList.add(new CoreItem(Utils.getText(2131165302), false));
                          localArrayList.add(new CoreItem(Utils.getText(2131165304), false));
                          localArrayList.add(new CoreItem(Utils.getText(2131165307), false));
                          localArrayList.add(new CoreItem(Utils.getText(2131165311), false));
                          localArrayList.add(new CoreItem(Utils.getText(2131165312), false));
                          if ((listAppsFragment.all_d != null) && (listAppsFragment.all_d.adapter != null)) {
                              listAppsFragment.all_d.adapter.notifyDataSetChanged();
                          }
                          listAppsFragment.removeDialogAll(24);
                          listAppsFragment.showDialogAll(24, new ArrayAdapter(listAppsFragment.this.getContext(),
                                  2130968605, localArrayList) {
                              TextView txtStatus;
                              TextView txtStatusPatch;
                              TextView txtTitle;

                              public View getView(int paramAnonymous3Int, View paramAnonymous3View,
                                      ViewGroup paramAnonymous3ViewGroup) {
                                  if (listAppsFragment.xposedNotify) {
                                      paramAnonymous3View = listAppsFragment.frag;
                                      listAppsFragment.patchAct.runOnUiThread(new Runnable() {
                                          public void run() {
                                              if (Utils.hasXposed()) {
                                                  listAppsFragment.frag.showMessage(Utils.getText(2131165748),
                                                          Utils.getText(2131165751));
                                              }
                                          }
                                      });
                                      listAppsFragment.xposedNotify = false;
                                  }
                                  Object localObject = (CoreItem) getItem(paramAnonymous3Int);
                                  paramAnonymous3ViewGroup = ((LayoutInflater) listAppsFragment.getInstance()
                                          .getSystemService("layout_inflater")).inflate(2130968607,
                                                  paramAnonymous3ViewGroup, false);
                                  this.txtTitle = ((TextView) paramAnonymous3ViewGroup.findViewById(2131558483));
                                  this.txtStatus = ((TextView) paramAnonymous3ViewGroup.findViewById(2131558484));
                                  this.txtStatusPatch = ((TextView) paramAnonymous3ViewGroup
                                          .findViewById(2131558536));
                                  this.txtTitle.setTextAppearance(getContext(), listAppsFragment.getSizeText());
                                  this.txtStatus.setTextAppearance(getContext(), listAppsFragment.getSizeText());
                                  this.txtStatusPatch.setTextAppearance(getContext(),
                                          listAppsFragment.getSizeText());
                                  paramAnonymous3View = (CheckBox) paramAnonymous3ViewGroup
                                          .findViewById(2131558535);
                                  paramAnonymous3View.setChecked(((CoreItem) localObject).Status);
                                  if (paramAnonymous3Int == 3) {
                                      paramAnonymous3View.setVisibility(8);
                                      paramAnonymous3View.setChecked(false);
                                  }
                                  if (paramAnonymous3Int == 0) {
                                      if (!Utils.checkCoreJarPatch11()) {
                                          break label716;
                                      }
                                      int i = 0;
                                      if (Utils.checkCoreJarPatch11()) {
                                          i = 0 + 1;
                                      }
                                      int j = i;
                                      if (Utils.checkCoreJarPatch12()) {
                                          j = i + 1;
                                      }
                                      if (j == 2) {
                                          paramAnonymous3View.setEnabled(false);
                                          ((CoreItem) localObject).disabled = true;
                                          this.txtStatusPatch.setText("2/2 " + Utils.getText(2131165372));
                                      }
                                      if (j == 1) {
                                          this.txtStatusPatch.setText("1/2 " + Utils.getText(2131165372));
                                      }
                                  }
                                  if (paramAnonymous3Int == 1) {
                                      if (Utils.checkCoreJarPatch20()) {
                                          paramAnonymous3View.setEnabled(false);
                                          ((CoreItem) localObject).disabled = true;
                                          this.txtStatusPatch.setText(Utils.getText(2131165372));
                                      }
                                  } else {
                                      label330: if (paramAnonymous3Int == 2) {
                                          if ((!listAppsFragment.filePatch3)
                                                  && (!Utils.checkCoreJarPatch30(listAppsFragment.getPkgMng()))) {
                                              break label788;
                                          }
                                          paramAnonymous3View.setEnabled(false);
                                          ((CoreItem) localObject).disabled = true;
                                          this.txtStatusPatch.setText(Utils.getText(2131165372));
                                      }
                                      label373: if (paramAnonymous3Int == 3) {
                                          paramAnonymous3View.setEnabled(false);
                                          if ((!listAppsFragment.filePatch3) && (!Utils.checkCoreJarPatch40())) {
                                              break label824;
                                          }
                                          paramAnonymous3View.setEnabled(false);
                                          paramAnonymous3ViewGroup.setEnabled(false);
                                          ((CoreItem) localObject).disabled = true;
                                          this.txtStatusPatch.setText(Utils.getText(2131165372));
                                          label423: this.txtStatusPatch.append(Utils.getColoredText(
                                                  "\n" + Utils.getText(2131165310), "#FF0000", "normal"));
                                      }
                                      if (paramAnonymous3Int == 4) {
                                          localObject = Utils.getText(2131165314);
                                          this.txtStatusPatch.setText(Utils.getColoredText((String) localObject,
                                                  "#ff888888", "italic"));
                                      }
                                      if (paramAnonymous3Int == 5) {
                                          localObject = Utils.getText(2131165313);
                                          this.txtStatusPatch.setText(Utils.getColoredText((String) localObject,
                                                  "#ff888888", "italic"));
                                      }
                                      paramAnonymous3View.setClickable(false);
                                      this.txtStatus.setTextAppearance(getContext(), 16973894);
                                      this.txtStatus.setTextColor(-7829368);
                                      this.txtTitle.setTextColor(-1);
                                      this.txtTitle.setText(((CoreItem) getItem(paramAnonymous3Int)).Name);
                                      this.txtTitle.setTypeface(null, 1);
                                      paramAnonymous3View = ((CoreItem) getItem(paramAnonymous3Int)).Name;
                                      if ((paramAnonymous3Int != 0) && (paramAnonymous3Int != 1)) {
                                          break label860;
                                      }
                                      this.txtTitle.setText(
                                              Utils.getColoredText(paramAnonymous3View, "#ff00ff00", "bold"));
                                  }
                                  for (;;) {
                                      if (paramAnonymous3Int == 0) {
                                          paramAnonymous3View = Utils.getText(2131165301);
                                      }
                                      if (paramAnonymous3Int == 1) {
                                          paramAnonymous3View = Utils.getText(2131165303);
                                      }
                                      if (paramAnonymous3Int == 2) {
                                          paramAnonymous3View = Utils.getText(2131165305) + "\n"
                                                  + Utils.getText(2131165306);
                                      }
                                      if (paramAnonymous3Int == 3) {
                                          paramAnonymous3View = Utils.getText(2131165308);
                                      }
                                      if (paramAnonymous3Int == 4) {
                                          paramAnonymous3View = "";
                                      }
                                      if (paramAnonymous3Int == 5) {
                                          paramAnonymous3View = "";
                                      }
                                      this.txtStatus.append(
                                              Utils.getColoredText(paramAnonymous3View, "#ff888888", "italic"));
                                      return paramAnonymous3ViewGroup;
                                      label716: if (listAppsFragment.fileNotSpace) {
                                          this.txtStatusPatch.setText(Utils.getText(2131165374));
                                          break;
                                      }
                                      this.txtStatusPatch.setText(Utils.getText(2131165373));
                                      break;
                                      if (listAppsFragment.fileNotSpace) {
                                          this.txtStatusPatch.setText(Utils.getText(2131165374));
                                          break label330;
                                      }
                                      this.txtStatusPatch.setText(Utils.getText(2131165373));
                                      break label330;
                                      label788: if (listAppsFragment.fileNotSpace) {
                                          this.txtStatusPatch.setText(Utils.getText(2131165374));
                                          break label373;
                                      }
                                      this.txtStatusPatch.setText(Utils.getText(2131165373));
                                      break label373;
                                      label824: if (listAppsFragment.fileNotSpace) {
                                          this.txtStatusPatch.setText(Utils.getText(2131165374));
                                          break label423;
                                      }
                                      this.txtStatusPatch.setText(Utils.getText(2131165373));
                                      break label423;
                                      label860: if ((paramAnonymous3Int == 4) || (paramAnonymous3Int == 5)) {
                                          this.txtTitle.setText(
                                                  Utils.getColoredText(paramAnonymous3View, "#ffff0000", "bold"));
                                      } else {
                                          this.txtTitle.setText(
                                                  Utils.getColoredText(paramAnonymous3View, "#ff00ff00", "bold"));
                                      }
                                  }
                              }
                          });
                          listAppsFragment.removeDialogLP(11);
                      }
                  });
                  return;
              } catch (Exception localException) {
                  System.out.println("LuckyPatcher: handler Null.");
              }
          }
      });
      System.out.println("LuckyPatcher: Start core.jar test!");
  }